switch some node-parent based stuff to path-based
This commit is contained in:
parent
d0ac65a934
commit
ba4550c953
@ -25,11 +25,13 @@ var referenceVisitor = {
|
||||
}
|
||||
};
|
||||
|
||||
export default function (node, callId, scope) {
|
||||
export default function (path, callId) {
|
||||
var node = path.node;
|
||||
|
||||
node.async = false;
|
||||
node.generator = true;
|
||||
|
||||
scope.traverse(node, awaitVisitor, state);
|
||||
path.traverse(awaitVisitor, state);
|
||||
|
||||
var call = t.callExpression(callId, [node]);
|
||||
|
||||
@ -44,11 +46,11 @@ export default function (node, callId, scope) {
|
||||
return declar;
|
||||
} else {
|
||||
if (id) {
|
||||
var state = { id: id };
|
||||
scope.traverse(node, referenceVisitor, state);
|
||||
var state = { id };
|
||||
path.traverse(referenceVisitor, state);
|
||||
|
||||
if (state.ref) {
|
||||
scope.parent.push({ id: state.ref });
|
||||
path.scope.parent.push({ id: state.ref });
|
||||
return t.assignmentExpression("=", state.ref, call);
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,15 +56,22 @@ export function ForOfStatement(node, parent, scope, file) {
|
||||
export { ForOfStatement as ForInStatement };
|
||||
|
||||
export function Func/*tion*/(node, parent, scope, file) {
|
||||
var hasDestructuring = false;
|
||||
for (let pattern of (node.params: Array)) {
|
||||
if (t.isPattern(pattern)) {
|
||||
hasDestructuring = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!hasDestructuring) return;
|
||||
|
||||
var nodes = [];
|
||||
|
||||
var hasDestructuring = false;
|
||||
for (var i = 0; i < node.params.length; i++) {
|
||||
let pattern = node.params[i];
|
||||
if (!t.isPattern(pattern)) continue;
|
||||
|
||||
node.params = node.params.map(function (pattern, i) {
|
||||
if (!t.isPattern(pattern)) return pattern;
|
||||
|
||||
hasDestructuring = true;
|
||||
var ref = scope.generateUidIdentifier("ref");
|
||||
var ref = node.params[i] = scope.generateUidIdentifier("ref");
|
||||
t.inherits(ref, pattern);
|
||||
|
||||
var destructuring = new DestructuringTransformer({
|
||||
@ -74,12 +81,9 @@ export function Func/*tion*/(node, parent, scope, file) {
|
||||
file: file,
|
||||
kind: "let"
|
||||
});
|
||||
|
||||
destructuring.init(pattern, ref);
|
||||
|
||||
return ref;
|
||||
});
|
||||
|
||||
if (!hasDestructuring) return;
|
||||
}
|
||||
|
||||
t.ensureBlock(node);
|
||||
|
||||
@ -216,8 +220,8 @@ function hasRest(pattern) {
|
||||
}
|
||||
|
||||
var arrayUnpackVisitor = {
|
||||
enter(node, parent, scope, state) {
|
||||
if (this.isReferencedIdentifier() && state.bindings[node.name]) {
|
||||
ReferencedIdentifier(node, parent, scope, state) {
|
||||
if (state.bindings[node.name]) {
|
||||
state.deopt = true;
|
||||
this.stop();
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
function getSpreadLiteral(spread, scope) {
|
||||
if (scope.file.isLoose("es6.spread")) {
|
||||
if (scope.hub.file.isLoose("es6.spread")) {
|
||||
return spread.argument;
|
||||
} else {
|
||||
return scope.toArray(spread.argument, true);
|
||||
|
||||
@ -83,7 +83,7 @@ export function ExportNamedDeclaration(node, parent, scope) {
|
||||
export var Program = {
|
||||
enter(node) {
|
||||
var imports = [];
|
||||
var rest = [];
|
||||
var rest = [];
|
||||
|
||||
for (var i = 0; i < node.body.length; i++) {
|
||||
var bodyNode = node.body[i];
|
||||
|
||||
@ -10,5 +10,5 @@ export var metadata = {
|
||||
export function Func/*tion*/(node, parent, scope, file) {
|
||||
if (!node.async || node.generator) return;
|
||||
|
||||
return remapAsyncToGenerator(node, file.addHelper("async-to-generator"), scope);
|
||||
return remapAsyncToGenerator(this, file.addHelper("async-to-generator"));
|
||||
}
|
||||
|
||||
@ -14,8 +14,7 @@ export function Func/*tion*/(node, parent, scope, file) {
|
||||
if (!node.async || node.generator) return;
|
||||
|
||||
return remapAsyncToGenerator(
|
||||
node,
|
||||
t.memberExpression(file.addImport("bluebird", null, "absolute"), t.identifier("coroutine")),
|
||||
scope
|
||||
this,
|
||||
t.memberExpression(file.addImport("bluebird", null, "absolute"), t.identifier("coroutine"))
|
||||
);
|
||||
}
|
||||
|
||||
@ -151,7 +151,7 @@ export function isCompletionRecord(allowInsideFunction?) {
|
||||
*/
|
||||
|
||||
export function isStatementOrBlock() {
|
||||
if (t.isLabeledStatement(this.parent) || t.isBlockStatement(this.container)) {
|
||||
if (this.parentPath.isLabeledStatement() || t.isBlockStatement(this.container)) {
|
||||
return false;
|
||||
} else {
|
||||
return includes(t.STATEMENT_OR_BLOCK_KEYS, this.key);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user