aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorFábio Santos <fabiosantosart@gmail.com>2018-03-26 19:22:01 +0100
committerAlex Lam S.L <alexlamsl@gmail.com>2018-03-27 03:22:01 +0900
commit9a5e2052c4860256021ede7c2c5d529fa0f320ed (patch)
treeed3ede8fa663feffd2f0e19ea0857d78a1350715 /lib
parentb1410be443e5ebce98a0a4438da9a8c9618e18fc (diff)
downloadtracifyjs-9a5e2052c4860256021ede7c2c5d529fa0f320ed.tar.gz
tracifyjs-9a5e2052c4860256021ede7c2c5d529fa0f320ed.zip
fix extra regex slash when going through mozilla AST I/O (#3025)
This relates to #1929, but in the context of mozilla AST input/output.
Diffstat (limited to 'lib')
-rw-r--r--lib/mozilla-ast.js30
1 files changed, 16 insertions, 14 deletions
diff --git a/lib/mozilla-ast.js b/lib/mozilla-ast.js
index b80afbbb..8e66c916 100644
--- a/lib/mozilla-ast.js
+++ b/lib/mozilla-ast.js
@@ -180,6 +180,17 @@
end : my_end_token(M)
};
if (val === null) return new AST_Null(args);
+ var rx = M.regex;
+ if (rx && rx.pattern) {
+ // RegExpLiteral as per ESTree AST spec
+ args.value = new RegExp(rx.pattern, rx.flags);
+ args.value.raw_source = rx.pattern;
+ return new AST_RegExp(args);
+ } else if (rx) {
+ // support legacy RegExp
+ args.value = M.regex && M.raw ? M.raw : val;
+ return new AST_RegExp(args);
+ }
switch (typeof val) {
case "string":
args.value = val;
@@ -189,16 +200,6 @@
return new AST_Number(args);
case "boolean":
return new (val ? AST_True : AST_False)(args);
- default:
- var rx = M.regex;
- if (rx && rx.pattern) {
- // RegExpLiteral as per ESTree AST spec
- args.value = new RegExp(rx.pattern, rx.flags).toString();
- } else {
- // support legacy RegExp
- args.value = M.regex && M.raw ? M.raw : val;
- }
- return new AST_RegExp(args);
}
},
Identifier: function(M) {
@@ -410,14 +411,15 @@
});
def_to_moz(AST_RegExp, function To_Moz_RegExpLiteral(M) {
- var value = M.value;
+ var flags = M.value.toString().match(/[gimuy]*$/)[0];
+ var value = "/" + M.value.raw_source + "/" + flags;
return {
type: "Literal",
value: value,
- raw: value.toString(),
+ raw: value,
regex: {
- pattern: value.source,
- flags: value.toString().match(/[gimuy]*$/)[0]
+ pattern: M.value.raw_source,
+ flags: flags
}
};
});