Skip to content

Commit 086c90e

Browse files
committed
Patches from emscripten
1 parent 504b967 commit 086c90e

3 files changed

Lines changed: 60 additions & 1 deletion

File tree

lib/ast.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,21 @@ var AST_SimpleStatement = DEFNODE("SimpleStatement", "body", {
165165
}
166166
}, AST_Statement);
167167

168+
// XXX Emscripten localmod: Add a node type for a parenthesized expression so that we can retain
169+
// Closure annotations that need a form "/**annotation*/(expression)"
170+
var AST_ParenthesizedExpression = DEFNODE("ParenthesizedExpression", "body", {
171+
$documentation: "An explicitly parenthesized expression, i.e. a = (1 + 2)",
172+
$propdoc: {
173+
body: "[AST_Node] an expression node (should not be instanceof AST_Statement)"
174+
},
175+
_walk: function(visitor) {
176+
return visitor._visit(this, function() {
177+
this.body._walk(visitor);
178+
});
179+
}
180+
}, AST_Statement);
181+
// XXX End of Emscripten localmod
182+
168183
function walk_body(node, visitor) {
169184
const body = node.body;
170185
for (var i = 0, len = body.length; i < len; i++) {
@@ -1663,6 +1678,7 @@ export {
16631678
AST_ObjectKeyVal,
16641679
AST_ObjectProperty,
16651680
AST_ObjectSetter,
1681+
AST_ParenthesizedExpression,
16661682
AST_PrefixedTemplateString,
16671683
AST_PropAccess,
16681684
AST_RegExp,
@@ -1723,3 +1739,6 @@ export {
17231739
_NOINLINE,
17241740
_PURE,
17251741
};
1742+
1743+
// XXX Emscripten: export TreeWalker for walking through AST in acorn-optimizer.js.
1744+
exports.TreeWalker = TreeWalker;

lib/mozilla-ast.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ import {
105105
AST_ObjectKeyVal,
106106
AST_ObjectProperty,
107107
AST_ObjectSetter,
108+
AST_ParenthesizedExpression,
108109
AST_PrefixedTemplateString,
109110
AST_PropAccess,
110111
AST_RegExp,
@@ -295,6 +296,16 @@ import {
295296
body: from_moz(M.expression)
296297
});
297298
},
299+
// XXX Emscripten localmod: Add a node type for a parenthesized expression so that we can retain
300+
// Closure annotations that need a form "/**annotation*/(expression)"
301+
ParenthesizedExpression: function(M) {
302+
return new AST_ParenthesizedExpression({
303+
start: my_start_token(M),
304+
end: my_end_token(M),
305+
body: from_moz(M.expression)
306+
});
307+
},
308+
// XXX End Emscripten localmod
298309
TryStatement: function(M) {
299310
var handlers = M.handlers || [M.handler];
300311
if (handlers.length > 1 || M.guardedHandlers && M.guardedHandlers.length) {
@@ -402,7 +413,14 @@ import {
402413
return from_moz(prop);
403414
}
404415
prop.type = "Property";
405-
return from_moz(prop);
416+
// XXX EMSCRIPTEN preserve quoted properties
417+
// https://github.com/mishoo/UglifyJS2/pull/3323
418+
var ret = from_moz(prop);
419+
if (prop.key.type === "Literal" &&
420+
(prop.key.raw[0] === '"' || prop.key.raw[0] === "'")) {
421+
ret.quote = true;
422+
}
423+
return ret;
406424
})
407425
});
408426
},
@@ -575,6 +593,19 @@ import {
575593
end : my_end_token(M),
576594
value : M.value
577595
});
596+
},
597+
ImportExpression: function(M) {
598+
let import_token = my_start_token(M);
599+
return new AST_Call({
600+
start : import_token,
601+
end : my_end_token(M),
602+
expression : new AST_SymbolRef({
603+
start : import_token,
604+
end : import_token,
605+
name : "import"
606+
}),
607+
args : [from_moz(M.source)]
608+
});
578609
}
579610
};
580611

lib/output.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ import {
109109
AST_ObjectKeyVal,
110110
AST_ObjectProperty,
111111
AST_ObjectSetter,
112+
AST_ParenthesizedExpression,
112113
AST_PrefixedTemplateString,
113114
AST_PropAccess,
114115
AST_RegExp,
@@ -1168,6 +1169,14 @@ function OutputStream(options) {
11681169
self.body.print(output);
11691170
output.semicolon();
11701171
});
1172+
// XXX Emscripten localmod: Add a node type for a parenthesized expression so that we can retain
1173+
// Closure annotations that need a form "/**annotation*/(expression)"
1174+
DEFPRINT(AST_ParenthesizedExpression, function(self, output) {
1175+
output.print('(');
1176+
self.body.print(output);
1177+
output.print(')');
1178+
});
1179+
// XXX End Emscripten localmod
11711180
function print_braced_empty(self, output) {
11721181
output.print("{");
11731182
output.with_indent(output.next_indent(), function() {

0 commit comments

Comments
 (0)