@babel/plugin-transform-classes
Advanced tools
Comparing version 8.0.0-alpha.11 to 8.0.0-alpha.12
@@ -6,4 +6,4 @@ import * as _babel_core from '@babel/core'; | ||
} | ||
declare const _default: (api: _babel_core.PluginAPI, options: Options, dirname: string) => _babel_core.PluginObject<_babel_core.PluginPass<{}>>; | ||
declare const _default: (api: _babel_core.PluginAPI, options: Options, dirname: string) => _babel_core.PluginObject<object & _babel_core.PluginPass>; | ||
export { type Options, _default as default }; |
import { declare } from '@babel/helper-plugin-utils'; | ||
import { isRequired } from '@babel/helper-compilation-targets'; | ||
import annotateAsPure from '@babel/helper-annotate-as-pure'; | ||
import nameFunction from '@babel/helper-function-name'; | ||
import splitExportDeclaration from '@babel/helper-split-export-declaration'; | ||
import { template, types, traverse } from '@babel/core'; | ||
import { template, types } from '@babel/core'; | ||
import globals from 'globals'; | ||
import ReplaceSupers from '@babel/helper-replace-supers'; | ||
import environmentVisitor from '@babel/helper-environment-visitor'; | ||
import { visitors } from '@babel/traverse'; | ||
@@ -122,7 +120,7 @@ const helper = template.statement` | ||
}; | ||
const findThisesVisitor = traverse.visitors.merge([environmentVisitor, { | ||
const findThisesVisitor = visitors.environmentVisitor({ | ||
ThisExpression(path) { | ||
classState.superThises.push(path); | ||
} | ||
}]); | ||
}); | ||
function createClassHelper(args) { | ||
@@ -191,3 +189,3 @@ return types.callExpression(classState.file.addHelper("createClass"), args); | ||
const superReturns = []; | ||
path.traverse(traverse.visitors.merge([environmentVisitor, { | ||
path.traverse(visitors.environmentVisitor({ | ||
ReturnStatement(path) { | ||
@@ -198,7 +196,13 @@ if (!path.getFunctionParent().isArrowFunctionExpression()) { | ||
} | ||
}])); | ||
})); | ||
if (isConstructor) { | ||
pushConstructor(superReturns, node, path); | ||
} else { | ||
pushMethod(node, path); | ||
path.ensureFunctionName(supportUnicodeId); | ||
let wrapped; | ||
if (node !== path.node) { | ||
wrapped = path.node; | ||
path.replaceWith(node); | ||
} | ||
pushMethod(node, wrapped); | ||
} | ||
@@ -295,3 +299,3 @@ } | ||
const bareSupers = []; | ||
path.traverse(traverse.visitors.merge([environmentVisitor, { | ||
path.traverse(visitors.environmentVisitor({ | ||
Super(path) { | ||
@@ -308,3 +312,3 @@ const { | ||
} | ||
}])); | ||
})); | ||
for (const bareSuper of bareSupers) { | ||
@@ -327,2 +331,3 @@ wrapSuperCall(bareSuper, classState.superName, thisRef, body); | ||
} | ||
const guaranteedCalls = new Set(); | ||
for (const thisPath of classState.superThises) { | ||
@@ -346,5 +351,14 @@ const { | ||
}); | ||
if (maxGuaranteedSuperBeforeIndex !== -1 && thisIndex > maxGuaranteedSuperBeforeIndex) { | ||
let exprPath = thisPath.parentPath.isSequenceExpression() ? thisPath.parentPath : thisPath; | ||
if (exprPath.listKey === "arguments" && (exprPath.parentPath.isCallExpression() || exprPath.parentPath.isOptionalCallExpression())) { | ||
exprPath = exprPath.parentPath; | ||
} else { | ||
exprPath = null; | ||
} | ||
if (maxGuaranteedSuperBeforeIndex !== -1 && thisIndex > maxGuaranteedSuperBeforeIndex || guaranteedCalls.has(exprPath)) { | ||
thisPath.replaceWith(thisRef()); | ||
} else { | ||
if (exprPath) { | ||
guaranteedCalls.add(exprPath); | ||
} | ||
thisPath.replaceWith(buildAssertThisInitialized()); | ||
@@ -377,6 +391,5 @@ } | ||
} | ||
function pushMethod(node, path) { | ||
const scope = path ? path.scope : classState.scope; | ||
function pushMethod(node, wrapped) { | ||
if (node.kind === "method") { | ||
if (processMethod(node, scope)) return; | ||
if (processMethod(node)) return; | ||
} | ||
@@ -387,14 +400,4 @@ const placement = node.static ? "static" : "instance"; | ||
const key = types.isNumericLiteral(node.key) || types.isBigIntLiteral(node.key) ? types.stringLiteral(String(node.key.value)) : types.toComputedKey(node); | ||
let fn = types.toExpression(node); | ||
if (types.isStringLiteral(key)) { | ||
if (node.kind === "method") { | ||
fn = nameFunction({ | ||
id: key, | ||
node: node, | ||
scope | ||
}, undefined, supportUnicodeId) ?? fn; | ||
} | ||
} else { | ||
methods.hasComputed = true; | ||
} | ||
methods.hasComputed = !types.isStringLiteral(key); | ||
const fn = wrapped ?? types.toExpression(node); | ||
let descriptor; | ||
@@ -421,3 +424,3 @@ if (!methods.hasComputed && methods.map.has(key.value)) { | ||
} | ||
function processMethod(node, scope) { | ||
function processMethod(node) { | ||
if (assumptions.setClassMethods && !node.decorators) { | ||
@@ -432,12 +435,4 @@ let { | ||
const methodName = types.memberExpression(types.cloneNode(classRef), node.key, node.computed || types.isLiteral(node.key)); | ||
let func = types.functionExpression(null, node.params, node.body, node.generator, node.async); | ||
const func = types.functionExpression(node.id, node.params, node.body, node.generator, node.async); | ||
types.inherits(func, node); | ||
const key = types.toComputedKey(node, node.key); | ||
if (types.isStringLiteral(key)) { | ||
func = nameFunction({ | ||
node: func, | ||
id: key, | ||
scope | ||
}, undefined, supportUnicodeId) ?? func; | ||
} | ||
const expr = types.expressionStatement(types.assignmentExpression("=", methodName, func)); | ||
@@ -567,3 +562,3 @@ types.inheritsComments(expr, node); | ||
const isStrict = path.isInStrictMode(); | ||
let constructorOnly = classState.classId && body.length === 0; | ||
let constructorOnly = body.length === 0; | ||
if (constructorOnly && !isStrict) { | ||
@@ -598,3 +593,3 @@ for (const param of classState.construct.params) { | ||
var index = declare((api, options) => { | ||
api.assertVersion("8.0.0-alpha.11"); | ||
api.assertVersion("8.0.0-alpha.12"); | ||
const { | ||
@@ -614,3 +609,3 @@ loose = false | ||
if (!path.get("declaration").isClassDeclaration()) return; | ||
splitExportDeclaration(path); | ||
path.splitExportDeclaration(); | ||
}, | ||
@@ -629,7 +624,4 @@ ClassDeclaration(path) { | ||
if (VISITED.has(node)) return; | ||
const inferred = nameFunction(path, undefined, supportUnicodeId); | ||
if (inferred && inferred !== node) { | ||
path.replaceWith(inferred); | ||
return; | ||
} | ||
const replacement = path.ensureFunctionName(supportUnicodeId); | ||
if (replacement && replacement.node !== node) return; | ||
VISITED.add(node); | ||
@@ -636,0 +628,0 @@ const [replacedPath] = path.replaceWith(transformClass(path, state.file, builtinClasses, loose, { |
{ | ||
"name": "@babel/plugin-transform-classes", | ||
"version": "8.0.0-alpha.11", | ||
"version": "8.0.0-alpha.12", | ||
"description": "Compile ES2015 classes to ES5", | ||
@@ -17,10 +17,8 @@ "repository": { | ||
"dependencies": { | ||
"@babel/helper-annotate-as-pure": "^8.0.0-alpha.11", | ||
"@babel/helper-compilation-targets": "^8.0.0-alpha.11", | ||
"@babel/helper-environment-visitor": "^8.0.0-alpha.11", | ||
"@babel/helper-function-name": "^8.0.0-alpha.11", | ||
"@babel/helper-plugin-utils": "^8.0.0-alpha.11", | ||
"@babel/helper-replace-supers": "^8.0.0-alpha.11", | ||
"@babel/helper-split-export-declaration": "^8.0.0-alpha.11", | ||
"globals": "^13.5.0" | ||
"@babel/helper-annotate-as-pure": "^8.0.0-alpha.12", | ||
"@babel/helper-compilation-targets": "^8.0.0-alpha.12", | ||
"@babel/helper-plugin-utils": "^8.0.0-alpha.12", | ||
"@babel/helper-replace-supers": "^8.0.0-alpha.12", | ||
"@babel/traverse": "^8.0.0-alpha.12", | ||
"globals": "^15.6.0" | ||
}, | ||
@@ -31,8 +29,7 @@ "keywords": [ | ||
"peerDependencies": { | ||
"@babel/core": "^8.0.0-alpha.11" | ||
"@babel/core": "^8.0.0-alpha.12" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^8.0.0-alpha.11", | ||
"@babel/helper-plugin-test-runner": "^8.0.0-alpha.11", | ||
"@babel/traverse": "^8.0.0-alpha.11" | ||
"@babel/core": "^8.0.0-alpha.12", | ||
"@babel/helper-plugin-test-runner": "^8.0.0-alpha.12" | ||
}, | ||
@@ -39,0 +36,0 @@ "engines": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7
2
150273
652
- Removed@babel/helper-split-export-declaration@^8.0.0-alpha.11
- Removed@babel/helper-environment-visitor@8.0.0-alpha.11(transitive)
- Removed@babel/helper-function-name@8.0.0-alpha.11(transitive)
- Removed@babel/helper-split-export-declaration@8.0.0-alpha.11(transitive)
- Removedglobals@13.24.0(transitive)
- Removedtype-fest@0.20.2(transitive)
Updatedglobals@^15.6.0