@babel/plugin-transform-classes
Advanced tools
Comparing version 7.0.0-beta.47 to 7.0.0-beta.48
@@ -11,3 +11,3 @@ "use strict"; | ||
_helperPluginUtils = function _helperPluginUtils() { | ||
_helperPluginUtils = function () { | ||
return data; | ||
@@ -22,3 +22,3 @@ }; | ||
_helperAnnotateAsPure = function _helperAnnotateAsPure() { | ||
_helperAnnotateAsPure = function () { | ||
return data; | ||
@@ -33,3 +33,3 @@ }; | ||
_helperFunctionName = function _helperFunctionName() { | ||
_helperFunctionName = function () { | ||
return data; | ||
@@ -44,3 +44,3 @@ }; | ||
_helperSplitExportDeclaration = function _helperSplitExportDeclaration() { | ||
_helperSplitExportDeclaration = function () { | ||
return data; | ||
@@ -55,3 +55,3 @@ }; | ||
_core = function _core() { | ||
_core = function () { | ||
return data; | ||
@@ -66,3 +66,3 @@ }; | ||
_globals = function _globals() { | ||
_globals = function () { | ||
return data; | ||
@@ -84,3 +84,5 @@ }; | ||
api.assertVersion(7); | ||
const loose = options.loose; | ||
const { | ||
loose | ||
} = options; | ||
const VISITED = Symbol(); | ||
@@ -95,3 +97,5 @@ return { | ||
ClassDeclaration(path) { | ||
const node = path.node; | ||
const { | ||
node | ||
} = path; | ||
const ref = node.id || path.scope.generateUidIdentifier("class"); | ||
@@ -102,3 +106,5 @@ path.replaceWith(_core().types.variableDeclaration("let", [_core().types.variableDeclarator(ref, _core().types.toExpression(node))])); | ||
ClassExpression(path, state) { | ||
const node = path.node; | ||
const { | ||
node | ||
} = path; | ||
if (node[VISITED]) return; | ||
@@ -105,0 +111,0 @@ const inferred = (0, _helperFunctionName().default)(path); |
@@ -11,3 +11,3 @@ "use strict"; | ||
_core = function _core() { | ||
_core = function () { | ||
return data; | ||
@@ -20,15 +20,3 @@ }; | ||
function _default(decorators, scope) { | ||
for (var _iterator = decorators, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
const decorator = _ref; | ||
for (const decorator of decorators) { | ||
const expression = decorator.expression; | ||
@@ -35,0 +23,0 @@ if (!_core().types.isMemberExpression(expression)) continue; |
@@ -11,3 +11,3 @@ "use strict"; | ||
_helperFunctionName = function _helperFunctionName() { | ||
_helperFunctionName = function () { | ||
return data; | ||
@@ -22,3 +22,3 @@ }; | ||
_helperReplaceSupers = function _helperReplaceSupers() { | ||
_helperReplaceSupers = function () { | ||
return data; | ||
@@ -33,3 +33,3 @@ }; | ||
_helperOptimiseCallExpression = function _helperOptimiseCallExpression() { | ||
_helperOptimiseCallExpression = function () { | ||
return data; | ||
@@ -44,3 +44,3 @@ }; | ||
defineMap = function defineMap() { | ||
defineMap = function () { | ||
return data; | ||
@@ -55,3 +55,3 @@ }; | ||
_core = function _core() { | ||
_core = function () { | ||
return data; | ||
@@ -78,4 +78,6 @@ }; | ||
if (state.isDerived) return; | ||
const node = path.node, | ||
parentPath = path.parentPath; | ||
const { | ||
node, | ||
parentPath | ||
} = path; | ||
@@ -91,4 +93,6 @@ if (parentPath.isCallExpression({ | ||
if (!state.isDerived) return; | ||
const node = path.node, | ||
parentPath = path.parentPath; | ||
const { | ||
node, | ||
parentPath | ||
} = path; | ||
@@ -182,15 +186,3 @@ if (parentPath.isMemberExpression({ | ||
for (var _iterator = paths, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
const path = _ref; | ||
for (const path of paths) { | ||
hasConstructor = path.equals("kind", "constructor"); | ||
@@ -225,5 +217,7 @@ if (hasConstructor) break; | ||
if (classState.userConstructor) { | ||
const constructorBody = classState.constructorBody, | ||
userConstructor = classState.userConstructor, | ||
construct = classState.construct; | ||
const { | ||
constructorBody, | ||
userConstructor, | ||
construct | ||
} = classState; | ||
constructorBody.body = constructorBody.body.concat(userConstructor.body.body); | ||
@@ -237,3 +231,2 @@ | ||
pushDescriptors(); | ||
pushInheritsToBody(); | ||
} | ||
@@ -244,15 +237,3 @@ | ||
for (var _iterator2 = classBodyPaths, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref2; | ||
if (_isArray2) { | ||
if (_i2 >= _iterator2.length) break; | ||
_ref2 = _iterator2[_i2++]; | ||
} else { | ||
_i2 = _iterator2.next(); | ||
if (_i2.done) break; | ||
_ref2 = _i2.value; | ||
} | ||
const path = _ref2; | ||
for (const path of classBodyPaths) { | ||
const node = path.node; | ||
@@ -298,4 +279,6 @@ | ||
Super(path, state) { | ||
const node = path.node, | ||
parentPath = path.parentPath; | ||
const { | ||
node, | ||
parentPath | ||
} = path; | ||
@@ -330,3 +313,6 @@ if (parentPath.isCallExpression({ | ||
function pushDescriptors() { | ||
const body = classState.body; | ||
pushInheritsToBody(); | ||
const { | ||
body | ||
} = classState; | ||
let instanceProps; | ||
@@ -408,6 +394,6 @@ let staticProps; | ||
let _thisRef = function thisRef() { | ||
let thisRef = function () { | ||
const ref = path.scope.generateDeclaredUidIdentifier("this"); | ||
_thisRef = () => _core().types.cloneNode(ref); | ||
thisRef = () => _core().types.cloneNode(ref); | ||
@@ -417,17 +403,5 @@ return ref; | ||
for (var _iterator3 = classState.bareSupers, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) { | ||
var _ref3; | ||
for (const bareSuper of classState.bareSupers) { | ||
wrapSuperCall(bareSuper, classState.superName, thisRef, body); | ||
if (_isArray3) { | ||
if (_i3 >= _iterator3.length) break; | ||
_ref3 = _iterator3[_i3++]; | ||
} else { | ||
_i3 = _iterator3.next(); | ||
if (_i3.done) break; | ||
_ref3 = _i3.value; | ||
} | ||
const bareSuper = _ref3; | ||
wrapSuperCall(bareSuper, classState.superName, _thisRef, body); | ||
if (guaranteedSuperBeforeFinish) { | ||
@@ -447,26 +421,16 @@ bareSuper.find(function (parentPath) { | ||
for (var _iterator4 = classState.superThises, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) { | ||
var _ref4; | ||
for (const thisPath of classState.superThises) { | ||
const { | ||
node, | ||
parentPath | ||
} = thisPath; | ||
if (_isArray4) { | ||
if (_i4 >= _iterator4.length) break; | ||
_ref4 = _iterator4[_i4++]; | ||
} else { | ||
_i4 = _iterator4.next(); | ||
if (_i4.done) break; | ||
_ref4 = _i4.value; | ||
} | ||
const thisPath = _ref4; | ||
const node = thisPath.node, | ||
parentPath = thisPath.parentPath; | ||
if (parentPath.isMemberExpression({ | ||
object: node | ||
})) { | ||
thisPath.replaceWith(_thisRef()); | ||
thisPath.replaceWith(thisRef()); | ||
continue; | ||
} | ||
thisPath.replaceWith(_core().types.callExpression(classState.file.addHelper("assertThisInitialized"), [_thisRef()])); | ||
thisPath.replaceWith(_core().types.callExpression(classState.file.addHelper("assertThisInitialized"), [thisRef()])); | ||
} | ||
@@ -478,3 +442,3 @@ | ||
wrapReturn = returnArg => { | ||
const thisExpr = _core().types.callExpression(classState.file.addHelper("assertThisInitialized"), [_thisRef()]); | ||
const thisExpr = _core().types.callExpression(classState.file.addHelper("assertThisInitialized"), [thisRef()]); | ||
@@ -484,3 +448,3 @@ return returnArg ? _core().types.logicalExpression("||", returnArg, thisExpr) : thisExpr; | ||
} else { | ||
wrapReturn = returnArg => _core().types.callExpression(classState.file.addHelper("possibleConstructorReturn"), [_thisRef()].concat(returnArg || [])); | ||
wrapReturn = returnArg => _core().types.callExpression(classState.file.addHelper("possibleConstructorReturn"), [thisRef()].concat(returnArg || [])); | ||
} | ||
@@ -491,18 +455,6 @@ | ||
if (!bodyPaths.length || !bodyPaths.pop().isReturnStatement()) { | ||
body.pushContainer("body", _core().types.returnStatement(guaranteedSuperBeforeFinish ? _thisRef() : wrapReturn())); | ||
body.pushContainer("body", _core().types.returnStatement(guaranteedSuperBeforeFinish ? thisRef() : wrapReturn())); | ||
} | ||
for (var _iterator5 = classState.superReturns, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) { | ||
var _ref5; | ||
if (_isArray5) { | ||
if (_i5 >= _iterator5.length) break; | ||
_ref5 = _iterator5[_i5++]; | ||
} else { | ||
_i5 = _iterator5.next(); | ||
if (_i5.done) break; | ||
_ref5 = _i5.value; | ||
} | ||
const returnPath = _ref5; | ||
for (const returnPath of classState.superReturns) { | ||
returnPath.get("argument").replaceWith(wrapReturn(returnPath.node.argument)); | ||
@@ -524,3 +476,5 @@ } | ||
if (classState.isLoose && !node.decorators) { | ||
let classRef = classState.classRef; | ||
let { | ||
classRef | ||
} = classState; | ||
@@ -585,3 +539,5 @@ if (!node.static) { | ||
}); | ||
const construct = classState.construct; | ||
const { | ||
construct | ||
} = classState; | ||
@@ -607,2 +563,3 @@ _core().types.inheritsComments(construct, method); | ||
classState.body.push(classState.construct); | ||
pushInheritsToBody(); | ||
} | ||
@@ -615,7 +572,9 @@ | ||
}); | ||
classState.body.push(_core().types.expressionStatement(_core().types.callExpression(classState.file.addHelper(classState.isLoose ? "inheritsLoose" : "inherits"), [_core().types.cloneNode(classState.classRef), _core().types.cloneNode(classState.superName)]))); | ||
classState.body.unshift(_core().types.expressionStatement(_core().types.callExpression(classState.file.addHelper(classState.isLoose ? "inheritsLoose" : "inherits"), [_core().types.cloneNode(classState.classRef), _core().types.cloneNode(classState.superName)]))); | ||
} | ||
function setupClosureParamsArgs() { | ||
const superName = classState.superName; | ||
const { | ||
superName | ||
} = classState; | ||
const closureParams = []; | ||
@@ -659,14 +618,17 @@ const closureArgs = []; | ||
}); | ||
const classRef = classState.classRef, | ||
node = classState.node, | ||
constructorBody = classState.constructorBody; | ||
const { | ||
classRef, | ||
node, | ||
constructorBody | ||
} = classState; | ||
setState({ | ||
construct: buildConstructor(classRef, constructorBody, node) | ||
}); | ||
let body = classState.body; | ||
const _setupClosureParamsAr = setupClosureParamsArgs(), | ||
closureParams = _setupClosureParamsAr.closureParams, | ||
closureArgs = _setupClosureParamsAr.closureArgs; | ||
let { | ||
body | ||
} = classState; | ||
const { | ||
closureParams, | ||
closureArgs | ||
} = setupClosureParamsArgs(); | ||
buildBody(); | ||
@@ -683,16 +645,3 @@ | ||
if (constructorOnly && !isStrict) { | ||
for (var _iterator6 = classState.construct.params, _isArray6 = Array.isArray(_iterator6), _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) { | ||
var _ref6; | ||
if (_isArray6) { | ||
if (_i6 >= _iterator6.length) break; | ||
_ref6 = _iterator6[_i6++]; | ||
} else { | ||
_i6 = _iterator6.next(); | ||
if (_i6.done) break; | ||
_ref6 = _i6.value; | ||
} | ||
const param = _ref6; | ||
for (const param of classState.construct.params) { | ||
if (!_core().types.isIdentifier(param)) { | ||
@@ -699,0 +648,0 @@ constructorOnly = false; |
{ | ||
"name": "@babel/plugin-transform-classes", | ||
"version": "7.0.0-beta.47", | ||
"version": "7.0.0-beta.48", | ||
"description": "Compile ES2015 classes to ES5", | ||
@@ -9,9 +9,9 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-classes", | ||
"dependencies": { | ||
"@babel/helper-annotate-as-pure": "7.0.0-beta.47", | ||
"@babel/helper-define-map": "7.0.0-beta.47", | ||
"@babel/helper-function-name": "7.0.0-beta.47", | ||
"@babel/helper-optimise-call-expression": "7.0.0-beta.47", | ||
"@babel/helper-plugin-utils": "7.0.0-beta.47", | ||
"@babel/helper-replace-supers": "7.0.0-beta.47", | ||
"@babel/helper-split-export-declaration": "7.0.0-beta.47", | ||
"@babel/helper-annotate-as-pure": "7.0.0-beta.48", | ||
"@babel/helper-define-map": "7.0.0-beta.48", | ||
"@babel/helper-function-name": "7.0.0-beta.48", | ||
"@babel/helper-optimise-call-expression": "7.0.0-beta.48", | ||
"@babel/helper-plugin-utils": "7.0.0-beta.48", | ||
"@babel/helper-replace-supers": "7.0.0-beta.48", | ||
"@babel/helper-split-export-declaration": "7.0.0-beta.48", | ||
"globals": "^11.1.0" | ||
@@ -23,8 +23,8 @@ }, | ||
"peerDependencies": { | ||
"@babel/core": "7.0.0-beta.47" | ||
"@babel/core": "7.0.0-beta.48" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "7.0.0-beta.47", | ||
"@babel/helper-plugin-test-runner": "7.0.0-beta.47" | ||
"@babel/core": "7.0.0-beta.48", | ||
"@babel/helper-plugin-test-runner": "7.0.0-beta.48" | ||
} | ||
} |
26590
640
+ Added@babel/code-frame@7.0.0-beta.48(transitive)
+ Added@babel/core@7.0.0-beta.48(transitive)
+ Added@babel/generator@7.0.0-beta.48(transitive)
+ Added@babel/helper-annotate-as-pure@7.0.0-beta.48(transitive)
+ Added@babel/helper-define-map@7.0.0-beta.48(transitive)
+ Added@babel/helper-function-name@7.0.0-beta.48(transitive)
+ Added@babel/helper-get-function-arity@7.0.0-beta.48(transitive)
+ Added@babel/helper-member-expression-to-functions@7.0.0-beta.48(transitive)
+ Added@babel/helper-optimise-call-expression@7.0.0-beta.48(transitive)
+ Added@babel/helper-plugin-utils@7.0.0-beta.48(transitive)
+ Added@babel/helper-replace-supers@7.0.0-beta.48(transitive)
+ Added@babel/helper-split-export-declaration@7.0.0-beta.48(transitive)
+ Added@babel/helpers@7.0.0-beta.48(transitive)
+ Added@babel/highlight@7.0.0-beta.48(transitive)
+ Added@babel/parser@7.0.0-beta.48(transitive)
+ Added@babel/template@7.0.0-beta.48(transitive)
+ Added@babel/traverse@7.0.0-beta.48(transitive)
+ Added@babel/types@7.0.0-beta.48(transitive)
- Removed@babel/code-frame@7.0.0-beta.47(transitive)
- Removed@babel/core@7.0.0-beta.47(transitive)
- Removed@babel/generator@7.0.0-beta.47(transitive)
- Removed@babel/helper-annotate-as-pure@7.0.0-beta.47(transitive)
- Removed@babel/helper-define-map@7.0.0-beta.47(transitive)
- Removed@babel/helper-function-name@7.0.0-beta.47(transitive)
- Removed@babel/helper-get-function-arity@7.0.0-beta.47(transitive)
- Removed@babel/helper-member-expression-to-functions@7.0.0-beta.47(transitive)
- Removed@babel/helper-optimise-call-expression@7.0.0-beta.47(transitive)
- Removed@babel/helper-plugin-utils@7.0.0-beta.47(transitive)
- Removed@babel/helper-replace-supers@7.0.0-beta.47(transitive)
- Removed@babel/helper-split-export-declaration@7.0.0-beta.47(transitive)
- Removed@babel/helpers@7.0.0-beta.47(transitive)
- Removed@babel/highlight@7.0.0-beta.47(transitive)
- Removed@babel/template@7.0.0-beta.47(transitive)
- Removed@babel/traverse@7.0.0-beta.47(transitive)
- Removed@babel/types@7.0.0-beta.47(transitive)
- Removedbabylon@7.0.0-beta.47(transitive)