aboutsummaryrefslogtreecommitdiff
path: root/lib/mozilla-ast.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2018-03-23 03:43:52 +0800
committerGitHub <noreply@github.com>2018-03-23 03:43:52 +0800
commit49bfc6b555ca3be3084c0819391eabf2839e6f1b (patch)
tree12dda86d5f4feeb1a643e169e5daccdabc35112d /lib/mozilla-ast.js
parentd1c6bb8c7c4cc491c4bb52e14ac2127a2496fbb8 (diff)
downloadtracifyjs-49bfc6b555ca3be3084c0819391eabf2839e6f1b.tar.gz
tracifyjs-49bfc6b555ca3be3084c0819391eabf2839e6f1b.zip
improve performance (#3020)
- replace `find_if()` with `all()` wherever possible - move ESTree-specific logic out of `figure_out_scope()`
Diffstat (limited to 'lib/mozilla-ast.js')
-rw-r--r--lib/mozilla-ast.js15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/mozilla-ast.js b/lib/mozilla-ast.js
index 8d7ee4b8..b80afbbb 100644
--- a/lib/mozilla-ast.js
+++ b/lib/mozilla-ast.js
@@ -564,6 +564,21 @@
FROM_MOZ_STACK = [];
var ast = from_moz(node);
FROM_MOZ_STACK = save_stack;
+ ast.walk(new TreeWalker(function(node) {
+ if (node instanceof AST_LabelRef) {
+ for (var level = 0, parent; parent = this.parent(level); level++) {
+ if (parent instanceof AST_Scope) break;
+ if (parent instanceof AST_LabeledStatement && parent.label.name == node.name) {
+ node.thedef = parent.label;
+ break;
+ }
+ }
+ if (!node.thedef) {
+ var s = node.start;
+ js_error("Undefined label " + node.name, s.file, s.line, s.col, s.pos);
+ }
+ }
+ }));
return ast;
};