Skip to content

Commit ba2f9e4

Browse files
authored
Merge pull request mrdoob#19982 from ianpurvis/fix-buble-cleanup
Fix bubleCleanup es6 class unwrapping
2 parents 7353094 + af0a199 commit ba2f9e4

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

utils/build/rollup.config.js

+17-14
Original file line numberDiff line numberDiff line change
@@ -203,26 +203,29 @@ function glsl() {
203203

204204
function bubleCleanup() {
205205

206-
const begin1 = /var (\w+) = \/\*@__PURE__*\*\/\(function \((\w+)\) {\n/;
207-
const end1 = /if \( (\w+) \) (\w+)\.__proto__ = (\w+);\s+(\w+)\.prototype = Object\.create\( (\w+) && (\w+)\.prototype \);\s+(\w+)\.prototype\.constructor = (\w+);\s+return (\w+);\s+}\((\w+)\)\)/;
206+
const danglingTabs = /(^\t+$\n)|(\n^\t+$)/gm;
207+
const wrappedClass = /(var (\w+) = \/\*@__PURE__*\*\/\(function \((\w+)\) {\n).*(return \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

Comments
 (0)