aboutsummaryrefslogtreecommitdiff
path: root/node_modules/uglify-js/lib/mozilla-ast.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-05-24 15:10:37 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-05-24 15:11:17 +0200
commit7a3df06eb573d36142bd1a8e03c5ce8752d300b3 (patch)
tree70bfaea8884c374876f607774850a3a51c0cb381 /node_modules/uglify-js/lib/mozilla-ast.js
parentaca1143cb9eed16cf37f04e475e4257418dd18ac (diff)
fix build issues and add typedoc
Diffstat (limited to 'node_modules/uglify-js/lib/mozilla-ast.js')
-rw-r--r--node_modules/uglify-js/lib/mozilla-ast.js52
1 files changed, 27 insertions, 25 deletions
diff --git a/node_modules/uglify-js/lib/mozilla-ast.js b/node_modules/uglify-js/lib/mozilla-ast.js
index 12b55dc5b..88a2eb59f 100644
--- a/node_modules/uglify-js/lib/mozilla-ast.js
+++ b/node_modules/uglify-js/lib/mozilla-ast.js
@@ -111,23 +111,19 @@
},
Property: function(M) {
var key = M.key;
- var name = key.type == "Identifier" ? key.name : key.value;
var args = {
start : my_start_token(key),
end : my_end_token(M.value),
- key : name,
+ key : key.type == "Identifier" ? key.name : key.value,
value : from_moz(M.value)
};
- switch (M.kind) {
- case "init":
- return new AST_ObjectKeyVal(args);
- case "set":
- args.value.name = from_moz(key);
- return new AST_ObjectSetter(args);
- case "get":
- args.value.name = from_moz(key);
- return new AST_ObjectGetter(args);
- }
+ if (M.kind == "init") return new AST_ObjectKeyVal(args);
+ args.key = new AST_SymbolAccessor({
+ name: args.key
+ });
+ args.value = new AST_Accessor(args.value);
+ if (M.kind == "get") return new AST_ObjectGetter(args);
+ if (M.kind == "set") return new AST_ObjectSetter(args);
},
ArrayExpression: function(M) {
return new AST_Array({
@@ -256,10 +252,7 @@
map("CallExpression", AST_Call, "callee>expression, arguments@args");
def_to_moz(AST_Toplevel, function To_Moz_Program(M) {
- return {
- type: "Program",
- body: M.body.map(to_moz)
- };
+ return to_moz_scope("Program", M);
});
def_to_moz(AST_Defun, function To_Moz_FunctionDeclaration(M) {
@@ -267,7 +260,7 @@
type: "FunctionDeclaration",
id: to_moz(M.name),
params: M.argnames.map(to_moz),
- body: to_moz_block(M)
+ body: to_moz_scope("BlockStatement", M)
}
});
@@ -276,7 +269,7 @@
type: "FunctionExpression",
id: to_moz(M.name),
params: M.argnames.map(to_moz),
- body: to_moz_block(M)
+ body: to_moz_scope("BlockStatement", M)
}
});
@@ -382,11 +375,10 @@
});
def_to_moz(AST_ObjectProperty, function To_Moz_Property(M) {
- var key = (
- is_identifier(M.key)
- ? {type: "Identifier", name: M.key}
- : {type: "Literal", value: M.key}
- );
+ var key = {
+ type: "Literal",
+ value: M.key instanceof AST_SymbolAccessor ? M.key.name : M.key
+ };
var kind;
if (M instanceof AST_ObjectKeyVal) {
kind = "init";
@@ -547,8 +539,8 @@
moz_to_me = new Function("U2", "my_start_token", "my_end_token", "from_moz", "return(" + moz_to_me + ")")(
exports, my_start_token, my_end_token, from_moz
);
- me_to_moz = new Function("to_moz", "to_moz_block", "return(" + me_to_moz + ")")(
- to_moz, to_moz_block
+ me_to_moz = new Function("to_moz", "to_moz_block", "to_moz_scope", "return(" + me_to_moz + ")")(
+ to_moz, to_moz_block, to_moz_scope
);
MOZ_TO_ME[moztype] = moz_to_me;
def_to_moz(mytype, me_to_moz);
@@ -606,4 +598,14 @@
};
};
+ function to_moz_scope(type, node) {
+ var body = node.body.map(to_moz);
+ if (node.body[0] instanceof AST_SimpleStatement && node.body[0].body instanceof AST_String) {
+ body.unshift(to_moz(new AST_EmptyStatement(node.body[0])));
+ }
+ return {
+ type: type,
+ body: body
+ };
+ };
})();