aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
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
}
};
});