Rename all proposal plugins to -proposal- from -transform- (#6570)

This commit is contained in:
Henry Zhu
2017-10-27 15:26:38 -04:00
committed by GitHub
parent a94aa54230
commit c41abd79a1
599 changed files with 372 additions and 372 deletions

View File

@@ -0,0 +1,56 @@
import syntaxFunctionSent from "@babel/plugin-syntax-function-sent";
import wrapFunction from "@babel/helper-wrap-function";
export default function({ types: t }) {
const isFunctionSent = node =>
t.isIdentifier(node.meta, { name: "function" }) &&
t.isIdentifier(node.property, { name: "sent" });
const yieldVisitor = {
Function(path) {
path.skip();
},
YieldExpression(path) {
const replaced = t.isAssignmentExpression(path.parent, {
left: this.sentId,
});
if (!replaced) {
path.replaceWith(t.assignmentExpression("=", this.sentId, path.node));
}
},
MetaProperty(path) {
if (isFunctionSent(path.node)) {
path.replaceWith(this.sentId);
}
},
};
return {
inherits: syntaxFunctionSent,
visitor: {
MetaProperty(path, state) {
if (!isFunctionSent(path.node)) return;
const fnPath = path.getFunctionParent();
if (!fnPath.node.generator) {
throw new Error("Parent generator function not found");
}
const sentId = path.scope.generateUidIdentifier("function.sent");
fnPath.traverse(yieldVisitor, { sentId });
fnPath.node.body.body.unshift(
t.variableDeclaration("let", [
t.variableDeclarator(sentId, t.yieldExpression()),
]),
);
wrapFunction(fnPath, state.addHelper("skipFirstGeneratorNext"));
},
},
};
}