upgrade AST<->ESTree translation (#5554)

This commit is contained in:
Alex Lam S.L
2022-07-11 07:18:25 +08:00
committed by GitHub
parent 38bd4f65d0
commit 4778cf88e2
4 changed files with 40 additions and 11 deletions

View File

@@ -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 {

View File

@@ -23,7 +23,7 @@
"LICENSE"
],
"devDependencies": {
"acorn": "~8.2.1",
"acorn": "~8.7.1",
"semver": "~6.3.0"
},
"scripts": {

View File

@@ -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, {
if (!beautified.error) {
var verify = UglifyJS.minify(beautified.code, {
compress: false,
mangle: false,
output: {
ast: true,
},
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,
},

View File

@@ -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;