diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-03-07 18:38:27 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-07 18:38:27 +0800 |
commit | 8a8a94a596f57981e2cc65ac37921b154a9992b7 (patch) | |
tree | e5c9557bb57e12a2c3155fb0ab3d7ed0e3105c7a /lib | |
parent | 8153b7bd8a70ad94666904bd41f12ebd6be684c8 (diff) | |
download | tracifyjs-8a8a94a596f57981e2cc65ac37921b154a9992b7.tar.gz tracifyjs-8a8a94a596f57981e2cc65ac37921b154a9992b7.zip |
fix deep cloning of labels (#1565)
`AST_Label.references` get `.initialize()` to `[]` every time after `.clone()`
So walk down the tree to pick up the cloned `AST_LoopControl` pieces and put it back together.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ast.js | 19 |
1 files changed, 18 insertions, 1 deletions
@@ -91,7 +91,7 @@ var AST_Token = DEFNODE("Token", "type value line col pos endline endcol endpos }, null); var AST_Node = DEFNODE("Node", "start end", { - clone: function(deep) { + _clone: function(deep) { if (deep) { var self = this.clone(); return self.transform(new TreeTransformer(function(node) { @@ -102,6 +102,9 @@ var AST_Node = DEFNODE("Node", "start end", { } return new this.CTOR(this); }, + clone: function(deep) { + return this._clone(deep); + }, $documentation: "Base class of all AST nodes", $propdoc: { start: "[AST_Token] The first token of this node", @@ -207,6 +210,20 @@ var AST_LabeledStatement = DEFNODE("LabeledStatement", "label", { this.label._walk(visitor); this.body._walk(visitor); }); + }, + clone: function(deep) { + var node = this._clone(deep); + if (deep) { + var refs = node.label.references; + var label = this.label; + node.walk(new TreeWalker(function(node) { + if (node instanceof AST_LoopControl + && node.label && node.label.thedef === label) { + refs.push(node); + } + })); + } + return node; } }, AST_StatementWithBody); |