more versatile scope pushing
This commit is contained in:
parent
f5db53cebe
commit
58d7a5e069
@ -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));
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user