diff options
author | Mihai Bazon <mihai@bazon.net> | 2012-10-10 11:28:05 +0300 |
---|---|---|
committer | Mihai Bazon <mihai@bazon.net> | 2012-10-10 11:28:05 +0300 |
commit | f26f3b44bc238c5ea9772ccea5a21c9c928b6fd9 (patch) | |
tree | 7a8994055c58337b425c9d1fcf2c7a24106cf0c4 | |
parent | c5ecbfc756a4ed0aa736a82a062441b97effa7f5 (diff) | |
download | tracifyjs-f26f3b44bc238c5ea9772ccea5a21c9c928b6fd9.tar.gz tracifyjs-f26f3b44bc238c5ea9772ccea5a21c9c928b6fd9.zip |
small improvements in wrap_commonjs:
- use MAP.splice instead of a BlockStatement to inject code (avoids some
warnings in the linter)
- use the original symbol in exports, so that we get the proper source mapping
-rw-r--r-- | lib/ast.js | 13 |
1 files changed, 7 insertions, 6 deletions
@@ -295,7 +295,8 @@ var AST_Toplevel = DEFNODE("Toplevel", "globals", { var to_export = []; self.walk(new TreeWalker(function(node){ if (node instanceof AST_SymbolDeclaration && node.definition().global) { - to_export.push(node.name); + if (!find_if(function(n){ return n.name == node.name }, to_export)) + to_export.push(node); } })); } @@ -306,22 +307,22 @@ var AST_Toplevel = DEFNODE("Toplevel", "globals", { node = node.body; if (node instanceof AST_String) switch (node.getValue()) { case "$ORIG": - return new AST_BlockStatement(self); + return MAP.splice(self.body); case "$EXPORTS": var body = []; - to_export.forEach(function(name){ + to_export.forEach(function(sym){ body.push(new AST_SimpleStatement({ body: new AST_Assign({ left: new AST_Sub({ expression: new AST_SymbolRef({ name: "exports" }), - property: new AST_String({ value: name }), + property: new AST_String({ value: sym.name }), }), operator: "=", - right: new AST_SymbolRef({ name: name }), + right: new AST_SymbolRef(sym), }), })); }); - return new AST_BlockStatement({ body: body }); + return MAP.splice(body); } } })); |