support arrow function (#4385)

This commit is contained in:
Alex Lam S.L
2020-12-17 10:23:41 +00:00
committed by GitHub
parent 75e9fd8417
commit a96f087ac3
11 changed files with 732 additions and 117 deletions

View File

@@ -212,7 +212,11 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
argname.walk(tw);
});
in_arg.pop();
walk_body(node, tw);
if (node instanceof AST_Arrow && node.value) {
node.value.walk(tw);
} else {
walk_body(node, tw);
}
return true;
}
if (node instanceof AST_LoopControl) {
@@ -249,7 +253,9 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
}
if (!sym) {
sym = self.def_global(node);
} else if (name == "arguments" && sym.scope instanceof AST_Lambda) {
} else if (name == "arguments"
&& sym.orig[0] instanceof AST_SymbolFunarg
&& !(sym.scope instanceof AST_Arrow)) {
if (!(tw.parent() instanceof AST_PropAccess)) {
sym.scope.uses_arguments = "d";
} else if (!sym.scope.uses_arguments) {
@@ -360,6 +366,9 @@ AST_BlockScope.DEFMETHOD("init_vars", function(parent_scope) {
AST_Scope.DEFMETHOD("init_vars", function(parent_scope) {
init_scope_vars(this, parent_scope);
});
AST_Arrow.DEFMETHOD("init_vars", function(parent_scope) {
init_scope_vars(this, parent_scope);
});
AST_Lambda.DEFMETHOD("init_vars", function(parent_scope) {
init_scope_vars(this, parent_scope);
this.uses_arguments = false;