Kill the "shadow-functions.js" internal plugin in favor of an explicit helper (#5677)

* Handle arrow function processing via shared API rather than default plugin.

* Fix a few small PR comments.

* Preserve existing spec arrow 'this' rewrites, and support spec in subclass constructors.
This commit is contained in:
Logan Smyth
2017-05-05 13:27:18 -07:00
committed by GitHub
parent d5aa6d3ff8
commit 14584c218c
33 changed files with 1089 additions and 342 deletions

View File

@@ -46,6 +46,10 @@ export default function ({ types: t }) {
if (state.opts.loose) Constructor = LooseTransformer;
path.replaceWith(new Constructor(path, state.file).run());
if (path.isCallExpression() && path.get("callee").isArrowFunctionExpression()) {
path.get("callee").arrowFunctionToExpression();
}
},
},
};

View File

@@ -14,9 +14,7 @@ const buildDerivedConstructor = template(`
const noMethodVisitor = {
"FunctionExpression|FunctionDeclaration"(path) {
if (!path.is("shadow")) {
path.skip();
}
path.skip();
},
Method(path) {
@@ -48,7 +46,9 @@ const verifyConstructorVisitor = visitors.merge([noMethodVisitor, {
ThisExpression(path) {
if (this.isDerived && !this.hasBareSuper) {
if (!path.inShadow("this")) {
const fn = path.find((p) => p.isFunction());
if (!fn || !fn.isArrowFunctionExpression()) {
throw path.buildCodeFrameError("'this' is not allowed before super()");
}
}
@@ -142,8 +142,7 @@ export default class ClassTransformer {
//
body.push(t.returnStatement(this.classRef));
const container = t.functionExpression(null, closureParams, t.blockStatement(body));
container.shadow = true;
const container = t.arrowFunctionExpression(closureParams, t.blockStatement(body));
return t.callExpression(container, closureArgs);
}