From 4778cf88e2d281976397b2c1cde613c23a02fa3c Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Mon, 11 Jul 2022 07:18:25 +0800 Subject: [PATCH] upgrade AST<->ESTree translation (#5554) --- lib/mozilla-ast.js | 17 +++++++++++++++++ package.json | 2 +- test/mozilla-ast.js | 26 +++++++++++++++++--------- test/ufuzz/index.js | 6 +++++- 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/lib/mozilla-ast.js b/lib/mozilla-ast.js index 8cb32319..749bb3be 100644 --- a/lib/mozilla-ast.js +++ b/lib/mozilla-ast.js @@ -192,6 +192,19 @@ value: from_moz(M.value), }); }, + StaticBlock: function(M) { + var start = my_start_token(M); + var end = my_end_token(M); + return new AST_ClassInit({ + start: start, + end: end, + value: new AST_ClassInitBlock({ + start: start, + end: end, + body: normalize_directives(M.body.map(from_moz)), + }), + }); + }, ForOfStatement: function(M) { return new (M.await ? AST_ForAwaitOf : AST_ForOf)({ start: my_start_token(M), @@ -714,6 +727,10 @@ }; }); + def_to_moz(AST_ClassInit, function To_Moz_StaticBlock(M) { + return to_moz_scope("StaticBlock", M.value); + }); + function To_Moz_ForOfStatement(is_await) { return function(M) { return { diff --git a/package.json b/package.json index bb96929e..66fe71da 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "LICENSE" ], "devDependencies": { - "acorn": "~8.2.1", + "acorn": "~8.7.1", "semver": "~6.3.0" }, "scripts": { diff --git a/test/mozilla-ast.js b/test/mozilla-ast.js index c10c679a..04695140 100644 --- a/test/mozilla-ast.js +++ b/test/mozilla-ast.js @@ -9,19 +9,22 @@ function beautify(ast) { var beautified = UglifyJS.minify(ast, { compress: false, mangle: false, + module: ufuzz.module, output: { + ast: true, beautify: true, braces: true, }, }); - if (beautified.error) return beautified; - return UglifyJS.minify(beautified.code, { - compress: false, - mangle: false, - output: { - ast: true, - }, - }); + if (!beautified.error) { + var verify = UglifyJS.minify(beautified.code, { + compress: false, + mangle: false, + module: ufuzz.module, + }); + if (verify.error) return verify; + } + return beautified; } function validate(ast) { @@ -35,6 +38,7 @@ function validate(ast) { return UglifyJS.minify(ast, { compress: false, mangle: false, + module: ufuzz.module, output: { ast: true, }, @@ -115,9 +119,13 @@ for (var round = 1; round <= num_iterations; round++) { var code = ufuzz.createTopLevelCode(); minify_options.forEach(function(options) { var ok = true; - var input = UglifyJS.minify(options ? UglifyJS.minify(code, JSON.parse(options)).code : code, { + var input = UglifyJS.minify(options ? function(options) { + options.module = ufuzz.module; + return UglifyJS.minify(code, options).code; + }(JSON.parse(options)) : code, { compress: false, mangle: false, + module: ufuzz.module, output: { ast: true, }, diff --git a/test/ufuzz/index.js b/test/ufuzz/index.js index 162209ef..b081daa4 100644 --- a/test/ufuzz/index.js +++ b/test/ufuzz/index.js @@ -2095,7 +2095,11 @@ function createVarName(maybe, dontStore) { } if (require.main !== module) { - exports.createTopLevelCode = createTopLevelCode; + exports.createTopLevelCode = function() { + var code = createTopLevelCode(); + exports.module = async && has_await; + return code; + }; exports.num_iterations = num_iterations; exports.verbose = verbose; return;