@babel/plugin-transform-classes
Advanced tools
Comparing version 7.23.8 to 7.24.1
@@ -38,3 +38,2 @@ "use strict"; | ||
superThises: [], | ||
pushedConstructor: false, | ||
pushedInherits: false, | ||
@@ -173,3 +172,3 @@ pushedCreateClass: false, | ||
args = args.slice(0, lastNonNullIndex + 1); | ||
body.push(_core.types.expressionStatement(createClassHelper(args))); | ||
body.push(_core.types.returnStatement(createClassHelper(args))); | ||
classState.pushedCreateClass = true; | ||
@@ -220,21 +219,14 @@ } | ||
const body = path.get("body"); | ||
const constructorBody = path.get("body"); | ||
let maxGuaranteedSuperBeforeIndex = constructorBody.node.body.length; | ||
path.traverse(findThisesVisitor); | ||
let thisRef = function () { | ||
const ref = path.scope.generateDeclaredUidIdentifier("this"); | ||
maxGuaranteedSuperBeforeIndex++; | ||
thisRef = () => _core.types.cloneNode(ref); | ||
return ref; | ||
}; | ||
for (const thisPath of classState.superThises) { | ||
const { | ||
node, | ||
parentPath | ||
} = thisPath; | ||
if (parentPath.isMemberExpression({ | ||
object: node | ||
})) { | ||
thisPath.replaceWith(thisRef()); | ||
continue; | ||
} | ||
thisPath.replaceWith(_core.types.callExpression(classState.file.addHelper("assertThisInitialized"), [thisRef()])); | ||
} | ||
const buildAssertThisInitialized = function () { | ||
return _core.types.callExpression(classState.file.addHelper("assertThisInitialized"), [thisRef()]); | ||
}; | ||
const bareSupers = []; | ||
@@ -254,21 +246,47 @@ path.traverse(_core.traverse.visitors.merge([_helperEnvironmentVisitor.default, { | ||
}])); | ||
let guaranteedSuperBeforeFinish = !!bareSupers.length; | ||
for (const bareSuper of bareSupers) { | ||
wrapSuperCall(bareSuper, classState.superName, thisRef, body); | ||
if (guaranteedSuperBeforeFinish) { | ||
if (maxGuaranteedSuperBeforeIndex >= 0) { | ||
let lastParentPath; | ||
bareSuper.find(function (parentPath) { | ||
if (parentPath === path) { | ||
if (parentPath === constructorBody) { | ||
maxGuaranteedSuperBeforeIndex = Math.min(maxGuaranteedSuperBeforeIndex, lastParentPath.key); | ||
return true; | ||
} | ||
if (parentPath.isLoop() || parentPath.isConditional() || parentPath.isArrowFunctionExpression()) { | ||
guaranteedSuperBeforeFinish = false; | ||
maxGuaranteedSuperBeforeIndex = -1; | ||
return true; | ||
} | ||
lastParentPath = parentPath; | ||
}); | ||
} | ||
} | ||
for (const thisPath of classState.superThises) { | ||
const { | ||
node, | ||
parentPath | ||
} = thisPath; | ||
if (parentPath.isMemberExpression({ | ||
object: node | ||
})) { | ||
thisPath.replaceWith(thisRef()); | ||
continue; | ||
} | ||
let thisIndex; | ||
thisPath.find(function (parentPath) { | ||
if (parentPath.parentPath === constructorBody) { | ||
thisIndex = parentPath.key; | ||
return true; | ||
} | ||
}); | ||
if (maxGuaranteedSuperBeforeIndex != -1 && thisIndex > maxGuaranteedSuperBeforeIndex) { | ||
thisPath.replaceWith(thisRef()); | ||
} else { | ||
thisPath.replaceWith(buildAssertThisInitialized()); | ||
} | ||
} | ||
let wrapReturn; | ||
if (classState.isLoose) { | ||
wrapReturn = returnArg => { | ||
const thisExpr = _core.types.callExpression(classState.file.addHelper("assertThisInitialized"), [thisRef()]); | ||
const thisExpr = buildAssertThisInitialized(); | ||
return returnArg ? _core.types.logicalExpression("||", returnArg, thisExpr) : thisExpr; | ||
@@ -286,4 +304,5 @@ }; | ||
const bodyPaths = body.get("body"); | ||
const guaranteedSuperBeforeFinish = maxGuaranteedSuperBeforeIndex !== -1 && maxGuaranteedSuperBeforeIndex < bodyPaths.length; | ||
if (!bodyPaths.length || !bodyPaths.pop().isReturnStatement()) { | ||
body.pushContainer("body", _core.types.returnStatement(guaranteedSuperBeforeFinish ? thisRef() : wrapReturn())); | ||
body.pushContainer("body", _core.types.returnStatement(guaranteedSuperBeforeFinish ? thisRef() : buildAssertThisInitialized())); | ||
} | ||
@@ -389,11 +408,5 @@ for (const returnPath of classState.superReturns) { | ||
construct.body.directives = method.body.directives; | ||
pushConstructorToBody(); | ||
} | ||
function pushConstructorToBody() { | ||
if (classState.pushedConstructor) return; | ||
classState.pushedConstructor = true; | ||
if (classState.hasInstanceDescriptors || classState.hasStaticDescriptors) { | ||
pushDescriptors(); | ||
} | ||
classState.body.push(classState.construct); | ||
pushInheritsToBody(); | ||
@@ -489,3 +502,3 @@ } | ||
const isStrict = path.isInStrictMode(); | ||
let constructorOnly = classState.classId && body.length === 1; | ||
let constructorOnly = classState.classId && body.length === 0; | ||
if (constructorOnly && !isStrict) { | ||
@@ -499,3 +512,3 @@ for (const param of classState.construct.params) { | ||
} | ||
const directives = constructorOnly ? body[0].body.directives : []; | ||
const directives = constructorOnly ? classState.construct.body.directives : []; | ||
if (!isStrict) { | ||
@@ -505,10 +518,9 @@ directives.push(_core.types.directive(_core.types.directiveLiteral("use strict"))); | ||
if (constructorOnly) { | ||
const expr = _core.types.toExpression(body[0]); | ||
const expr = _core.types.toExpression(classState.construct); | ||
return classState.isLoose ? expr : createClassHelper([expr]); | ||
} | ||
let returnArg = _core.types.cloneNode(classState.classRef); | ||
if (!classState.pushedCreateClass && !classState.isLoose) { | ||
returnArg = createClassHelper([returnArg]); | ||
if (!classState.pushedCreateClass) { | ||
body.push(_core.types.returnStatement(classState.isLoose ? _core.types.cloneNode(classState.classRef) : createClassHelper([_core.types.cloneNode(classState.classRef)]))); | ||
} | ||
body.push(_core.types.returnStatement(returnArg)); | ||
body.unshift(classState.construct); | ||
const container = _core.types.arrowFunctionExpression(closureParams, _core.types.blockStatement(body, directives)); | ||
@@ -515,0 +527,0 @@ return _core.types.callExpression(container, closureArgs); |
{ | ||
"name": "@babel/plugin-transform-classes", | ||
"version": "7.23.8", | ||
"version": "7.24.1", | ||
"description": "Compile ES2015 classes to ES5", | ||
@@ -21,4 +21,4 @@ "repository": { | ||
"@babel/helper-function-name": "^7.23.0", | ||
"@babel/helper-plugin-utils": "^7.22.5", | ||
"@babel/helper-replace-supers": "^7.22.20", | ||
"@babel/helper-plugin-utils": "^7.24.0", | ||
"@babel/helper-replace-supers": "^7.24.1", | ||
"@babel/helper-split-export-declaration": "^7.22.6", | ||
@@ -34,5 +34,5 @@ "globals": "^11.1.0" | ||
"devDependencies": { | ||
"@babel/core": "^7.23.7", | ||
"@babel/helper-plugin-test-runner": "^7.22.5", | ||
"@babel/traverse": "^7.23.7" | ||
"@babel/core": "^7.24.1", | ||
"@babel/helper-plugin-test-runner": "^7.24.1", | ||
"@babel/traverse": "^7.24.1" | ||
}, | ||
@@ -39,0 +39,0 @@ "engines": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
87366
658
+ Addedelectron-to-chromium@1.4.748(transitive)
- Removedelectron-to-chromium@1.4.750(transitive)