@@ -203,26 +203,29 @@ function glsl() {
203203
204204function bubleCleanup ( ) {
205205
206- const begin1 = / v a r ( \w + ) = \/ \* @ _ _ P U R E _ _ * \* \/ \( f u n c t i o n \( ( \w + ) \) { \n / ;
207- const end1 = / i f \( ( \w + ) \) ( \w + ) \. _ _ p r o t o _ _ = ( \w + ) ; \s + ( \w + ) \. p r o t o t y p e = O b j e c t \. c r e a t e \( ( \w + ) & & ( \w + ) \. p r o t o t y p e \) ; \s + ( \w + ) \. p r o t o t y p e \. c o n s t r u c t o r = ( \w + ) ; \s + r e t u r n ( \w + ) ; \s + } \( ( \w + ) \) \) / ;
206+ const danglingTabs = / ( ^ \t + $ \n ) | ( \n ^ \t + $ ) / gm;
207+ const wrappedClass = / ( v a r ( \w + ) = \/ \* @ _ _ P U R E _ _ * \* \/ \( f u n c t i o n \( ( \w + ) \) { \n ) .* ( r e t u r n \2; \s + } \( \3\) \) ; \n ) / s;
208+ const unwrap = function ( match , wrapperStart , klass , parentClass , wrapperEnd ) {
209+
210+ return match
211+ . replace ( wrapperStart , '' )
212+ . replace ( `if ( ${ parentClass } ) ${ klass } .__proto__ = ${ parentClass } ;` , '' )
213+ . replace (
214+ `${ klass } .prototype = Object.create( ${ parentClass } && ${ parentClass } .prototype );` ,
215+ `${ klass } .prototype = Object.create( ${ parentClass } .prototype );`
216+ )
217+ . replace ( wrapperEnd , '' )
218+ . replace ( danglingTabs , '' ) ;
219+
220+ } ;
208221
209222 return {
210223
211224 transform ( code ) {
212225
213- while ( begin1 . test ( code ) ) {
214-
215- code = code . replace ( begin1 , function ( ) {
216-
217- return '' ;
218-
219- } ) ;
220-
221- code = code . replace ( end1 , function ( match , p1 , p2 ) {
222-
223- return `${ p2 } .prototype = Object.create( ${ p1 } .prototype );\n\t${ p2 } .prototype.constructor = ${ p2 } ;\n` ;
226+ while ( wrappedClass . test ( code ) ) {
224227
225- } ) ;
228+ code = code . replace ( wrappedClass , unwrap ) ;
226229
227230 }
228231
0 commit comments