diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2019-05-04 20:25:52 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-04 20:25:52 +0800 |
commit | 354fec8a9c3c8540d7e964ecbfcb38deaae86a3e (patch) | |
tree | fed20f61e163195ad4d8eb632e79212e6dcb5587 /lib/ast.js | |
parent | 11cdab745d29313a4e1799c65d13f7d6d5a45938 (diff) | |
download | tracifyjs-354fec8a9c3c8540d7e964ecbfcb38deaae86a3e.tar.gz tracifyjs-354fec8a9c3c8540d7e964ecbfcb38deaae86a3e.zip |
make `enclose` & `wrap` work with `sourceMap` (#3396)
fixes #3313
Diffstat (limited to 'lib/ast.js')
-rw-r--r-- | lib/ast.js | 23 |
1 files changed, 16 insertions, 7 deletions
@@ -337,18 +337,25 @@ var AST_Toplevel = DEFNODE("Toplevel", "globals", { $propdoc: { globals: "[Object/S] a map of name -> SymbolDef for all undeclared names", }, - wrap_commonjs: function(name) { + wrap: function(name) { var body = this.body; - var wrapped_tl = "(function(exports){'$ORIG';})(typeof " + name + "=='undefined'?(" + name + "={}):" + name + ");"; - wrapped_tl = parse(wrapped_tl); - wrapped_tl = wrapped_tl.transform(new TreeTransformer(function(node) { + return parse([ + "(function(exports){'$ORIG';})(typeof ", + name, + "=='undefined'?(", + name, + "={}):", + name, + ");" + ].join(""), { + filename: "wrap=" + JSON.stringify(name) + }).transform(new TreeTransformer(function(node) { if (node instanceof AST_Directive && node.value == "$ORIG") { return MAP.splice(body); } })); - return wrapped_tl; }, - wrap_enclose: function(args_values) { + enclose: function(args_values) { if (typeof args_values != "string") args_values = ""; var index = args_values.indexOf(":"); if (index < 0) index = args_values.length; @@ -359,7 +366,9 @@ var AST_Toplevel = DEFNODE("Toplevel", "globals", { '){"$ORIG"})(', args_values.slice(index + 1), ")" - ].join("")).transform(new TreeTransformer(function(node) { + ].join(""), { + filename: "enclose=" + JSON.stringify(args_values) + }).transform(new TreeTransformer(function(node) { if (node instanceof AST_Directive && node.value == "$ORIG") { return MAP.splice(body); } |