remove ShadowFunctionExpression

This commit is contained in:
Sebastian McKenzie 2015-03-22 04:07:00 +11:00
parent 9c3493e02f
commit 3e26511fb2
8 changed files with 18 additions and 21 deletions

View File

@ -6,7 +6,8 @@ export function ArrowFunctionExpression(node) {
t.ensureBlock(node);
node.expression = false;
node.type = "ShadowFunctionExpression";
node.type = "FunctionExpression";
node.shadow = true;
return node;
}

View File

@ -354,7 +354,8 @@ class BlockScoping {
var params = values(outsideRefs);
// build the closure that we're going to wrap the block with
var fn = t.shadowFunctionExpression(null, params, t.blockStatement(block.body));
var fn = t.functionExpression(null, params, t.blockStatement(block.body));
fn.shadow = true;
// replace the current block body with the one we're going to build
block.body = this.body;

View File

@ -91,7 +91,8 @@ exports.Function = function (node, parent, scope, file) {
node.params = node.params.slice(0, lastNonDefaultParam);
if (state.iife) {
var container = t.shadowFunctionExpression(null, [], node.body, node.generator);
var container = t.functionExpression(null, [], node.body, node.generator);
container.shadow = true;
body.push(t.returnStatement(t.callExpression(container, [])));

View File

@ -16,7 +16,8 @@ export function ComprehensionExpression(node, parent, scope, file) {
function generator(node) {
var body = [];
var container = t.shadowFunctionExpression(null, [], t.blockStatement(body), true);
var container = t.functionExpression(null, [], t.blockStatement(body), true);
container.shadow = true;
body.push(buildComprehension(node, function () {
return t.expressionStatement(t.yieldExpression(node.body));
@ -31,7 +32,7 @@ function array(node, parent, scope, file) {
var container = util.template("array-comprehension-container", {
KEY: uid
});
container.callee.type = "ShadowFunctionExpression";
container.callee.shadow = true;
var block = container.callee.body;
var body = block.body;

View File

@ -2,7 +2,7 @@ import * as t from "../../../types";
var functionChildrenVisitor = {
enter(node, parent, scope, state) {
if (this.isFunction()) {
if (this.isFunction() && !node.shadow) {
return this.skip();
}
@ -24,17 +24,19 @@ var functionChildrenVisitor = {
var functionVisitor = {
enter(node, parent, scope, state) {
if (this.isFunction()) {
// stop traversal of this node as it'll be hit again by this transformer
return this.skip();
} else if (!this.isShadowFunctionExpression()) {
return;
if (!node.shadow) {
if (this.isFunction()) {
// stop traversal of this node as it'll be hit again by this transformer
return this.skip();
} else {
return;
}
}
// traverse all child nodes of this function and find `arguments` and `this`
this.traverse(functionChildrenVisitor, state);
node.type = "FunctionExpression";
node.shadow = false;
return this.skip();
}

View File

@ -53,7 +53,6 @@
"ArrayExpression": ["Expression"],
"AssignmentExpression": ["Expression"],
"AwaitExpression": ["Expression"],
"ShadowFunctionExpression": ["Expression"],
"CallExpression": ["Expression"],
"ComprehensionExpression": ["Expression", "Scopable"],
"ConditionalExpression": ["Expression"],

View File

@ -45,13 +45,6 @@
"tokens": null
},
"ShadowFunctionExpression": {
"id": null,
"params": null,
"body": null,
"generator": false
},
"FunctionExpression": {
"id": null,
"params": null,

View File

@ -32,7 +32,6 @@
"ForStatement": ["init", "test", "update", "body"],
"FunctionDeclaration": ["id", "params", "defaults", "rest", "body", "returnType", "typeParameters"],
"FunctionExpression": ["id", "params", "defaults", "rest", "body", "returnType", "typeParameters"],
"ShadowFunctionExpression": ["id", "params", "defaults", "rest", "body", "returnType", "typeParameters"],
"Identifier": ["typeAnnotation"],
"IfStatement": ["test", "consequent", "alternate"],
"ImportDefaultSpecifier": ["local"],