aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-04-28 21:13:42 +0100
committerGitHub <noreply@github.com>2021-04-29 04:13:42 +0800
commitd576495e5a696302340580e999bc0446a1d4c1ca (patch)
tree7d07b009f8777a25a916faa4c1efbdfe2a1ebde8 /lib
parenta06e20304b042ab5cd2ad051fb60cf50a7934bb7 (diff)
downloadtracifyjs-d576495e5a696302340580e999bc0446a1d4c1ca.tar.gz
tracifyjs-d576495e5a696302340580e999bc0446a1d4c1ca.zip
support `#__PURE__` in ESTree (#4879)
Diffstat (limited to 'lib')
-rw-r--r--lib/mozilla-ast.js30
-rw-r--r--lib/output.js2
2 files changed, 27 insertions, 5 deletions
diff --git a/lib/mozilla-ast.js b/lib/mozilla-ast.js
index 028441b7..bfc6ac31 100644
--- a/lib/mozilla-ast.js
+++ b/lib/mozilla-ast.js
@@ -446,8 +446,22 @@
args.value = val;
return new AST_String(args);
case "number":
- args.value = val;
- return new AST_Number(args);
+ if (isNaN(val)) return new AST_NaN(args);
+ var negate, node;
+ if (isFinite(val)) {
+ negate = 1 / val < 0;
+ args.value = negate ? -val : val;
+ node = new AST_Number(args);
+ } else {
+ negate = val < 0;
+ node = new AST_Infinity(args);
+ }
+ return negate ? new AST_UnaryPrefix({
+ start: args.start,
+ end: args.end,
+ operator: "-",
+ expression: node,
+ }) : node;
case "boolean":
return new (val ? AST_True : AST_False)(args);
}
@@ -532,6 +546,14 @@
name: "this",
});
},
+ ParenthesizedExpression: function(M) {
+ var node = from_moz(M.expression);
+ if (!node.start.parens) node.start.parens = [];
+ node.start.parens.push(my_start_token(M));
+ if (!node.end.parens) node.end.parens = [];
+ node.end.parens.push(my_end_token(M));
+ return node;
+ },
};
MOZ_TO_ME.UpdateExpression =
@@ -570,8 +592,8 @@
map("AssignmentExpression", AST_Assign, "operator=operator, left>left, right>right");
map("AssignmentPattern", AST_DefaultValue, "left>name, right>value");
map("ConditionalExpression", AST_Conditional, "test>condition, consequent>consequent, alternate>alternative");
- map("NewExpression", AST_New, "callee>expression, arguments@args");
- map("CallExpression", AST_Call, "callee>expression, arguments@args");
+ map("NewExpression", AST_New, "callee>expression, arguments@args, pure=pure");
+ map("CallExpression", AST_Call, "callee>expression, arguments@args, pure=pure");
map("SequenceExpression", AST_Sequence, "expressions@expressions");
map("SpreadElement", AST_Spread, "argument>expression");
map("ObjectExpression", AST_Object, "properties@properties");
diff --git a/lib/output.js b/lib/output.js
index 43512606..75ccca2d 100644
--- a/lib/output.js
+++ b/lib/output.js
@@ -1456,7 +1456,7 @@ function OutputStream(options) {
parent = output.parent(level++);
if (parent instanceof AST_Call && parent.expression === node) return;
} while (parent instanceof AST_PropAccess && parent.expression === node);
- output.print("/*" + self.pure + "*/");
+ output.print(typeof self.pure == "string" ? "/*" + self.pure + "*/" : "/*@__PURE__*/");
}
function print_call_args(self, output) {
if (self.expression instanceof AST_Call || self.expression instanceof AST_Lambda) {
exec_SCRIPTS): Remove. (nodist_pkglibexec_SCRIPTS): New variable. * nix/nix-daemon/guix-daemon.cc (main): Remove 'setenv' call for "PATH". * nix/libstore/local-store.cc (runAuthenticationProgram): New function. (LocalStore::exportPath, LocalStore::importPath): Use it instead of 'runProgram' and OPENSSL_PATH.