From 94c4daaf9ea67875ab1b720d1d7bceef7c690552 Mon Sep 17 00:00:00 2001 From: kzc Date: Mon, 2 Nov 2015 12:24:09 -0500 Subject: Have mozilla AST RegExpLiteral parser use regex.pattern and regex.flags rather than non-standard `raw` property. --- lib/mozilla-ast.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/mozilla-ast.js b/lib/mozilla-ast.js index 15be4581..7ce6e78d 100644 --- a/lib/mozilla-ast.js +++ b/lib/mozilla-ast.js @@ -146,7 +146,17 @@ case "boolean": return new (val ? AST_True : AST_False)(args); default: - args.value = M.regex && M.raw ? M.raw : val; + var rx = M.regex; + if (rx && rx.pattern) { + // RegExpLiteral as per ESTree AST spec + args.value = "/" + rx.pattern + "/"; + if (rx.flags) { + args.value += rx.flags; + } + } else { + // support legacy RegExp + args.value = M.regex && M.raw ? M.raw : val; + } return new AST_RegExp(args); } }, @@ -334,7 +344,7 @@ }; }); - def_to_moz(AST_RegExp, function To_Moz_RegExp(M) { + def_to_moz(AST_RegExp, function To_Moz_RegExpLiteral(M) { var value = M.value; return { type: "Literal", -- cgit v1.2.3