more versatile scope pushing

This commit is contained in:
Sebastian McKenzie 2015-03-10 06:13:32 +11:00
parent f5db53cebe
commit 58d7a5e069
4 changed files with 11 additions and 18 deletions

View File

@ -135,10 +135,7 @@ export function AssignmentExpression(node, parent, scope, file) {
if (!t.isPattern(node.left)) return;
var ref = scope.generateUidIdentifier("temp");
scope.push({
key: ref.name,
id: ref
});
scope.push({ id: ref });
var nodes = [];
nodes.push(t.assignmentExpression("=", ref, node.right));

View File

@ -40,10 +40,7 @@ export function ObjectExpression(node, parent, scope, file) {
}
if (objectRef) {
scope.push({
id: objectRef
});
scope.push({ id: objectRef });
return t.assignmentExpression("=", objectRef, node);
}
}

View File

@ -581,16 +581,16 @@ export default class Scope {
block = block.body;
}
if (t.isBlockStatement(block) || t.isProgram(block)) {
block._declarations ||= {};
block._declarations[opts.key || opts.id.name] = {
kind: opts.kind || "var",
id: opts.id,
init: opts.init
};
} else {
throw new TypeError(`cannot add a declaration here in node type ${block.type}`);
if (!t.isBlockStatement(block) && !t.isProgram(block)) {
block = this.getBlockParent().block;
}
block._declarations ||= {};
block._declarations[opts.key || opts.id.name] = {
kind: opts.kind || "var",
id: opts.id,
init: opts.init
};
}
/**

View File

@ -154,7 +154,6 @@ t.toSequenceExpression = function (nodes: Array<Object>, scope: Scope): Object {
each(node.declarations, function (declar) {
scope.push({
kind: node.kind,
key: declar.id.name,
id: declar.id
});
exprs.push(t.assignmentExpression("=", declar.id, declar.init));