improve ESTree compatibility (#5836)

closes #5834
closes #5835
This commit is contained in:
Alex Lam S.L
2024-06-10 01:37:24 +03:00
committed by GitHub
parent e7b9b4aafb
commit ca4185a0fd
2 changed files with 52 additions and 6 deletions

18
.github/workflows/moz.yml vendored Normal file
View File

@@ -0,0 +1,18 @@
name: ESTree
on:
pull_request:
push:
branches: [ master ]
jobs:
test:
name: fuzzing
runs-on: ubuntu-latest
env:
NODE: latest
steps:
- uses: actions/checkout@v4
- name: Perform tests
shell: bash
run: |
. ./test/release/install.sh
node test/mozilla-ast.js 5000

View File

@@ -125,6 +125,16 @@
body: normalize_directives(from_moz(M.body).body), body: normalize_directives(from_moz(M.body).body),
}); });
}, },
CallExpression: function(M) {
return new AST_Call({
start: my_start_token(M),
end: my_end_token(M),
expression: from_moz(M.callee),
args: M.arguments.map(from_moz),
optional: M.optional,
pure: M.pure,
});
},
ClassDeclaration: function(M) { ClassDeclaration: function(M) {
return new AST_DefClass({ return new AST_DefClass({
start: my_start_token(M), start: my_start_token(M),
@@ -458,7 +468,7 @@
end: my_end_token(M), end: my_end_token(M),
}; };
if (M.bigint) { if (M.bigint) {
args.value = M.bigint.toLowerCase() + "n"; args.value = M.bigint.toLowerCase();
return new AST_BigInt(args); return new AST_BigInt(args);
} }
var val = M.value; var val = M.value;
@@ -631,7 +641,6 @@
map("AssignmentPattern", AST_DefaultValue, "left>name, right>value"); map("AssignmentPattern", AST_DefaultValue, "left>name, right>value");
map("ConditionalExpression", AST_Conditional, "test>condition, consequent>consequent, alternate>alternative"); map("ConditionalExpression", AST_Conditional, "test>condition, consequent>consequent, alternate>alternative");
map("NewExpression", AST_New, "callee>expression, arguments@args, pure=pure"); map("NewExpression", AST_New, "callee>expression, arguments@args, pure=pure");
map("CallExpression", AST_Call, "callee>expression, arguments@args, optional=optional, pure=pure");
map("SequenceExpression", AST_Sequence, "expressions@expressions"); map("SequenceExpression", AST_Sequence, "expressions@expressions");
map("SpreadElement", AST_Spread, "argument>expression"); map("SpreadElement", AST_Spread, "argument>expression");
map("ObjectExpression", AST_Object, "properties@properties"); map("ObjectExpression", AST_Object, "properties@properties");
@@ -668,6 +677,7 @@
type: "ArrowFunctionExpression", type: "ArrowFunctionExpression",
async: is_async(M), async: is_async(M),
params: params, params: params,
expression: !!M.value,
body: M.value ? to_moz(M.value) : to_moz_scope("BlockStatement", M), body: M.value ? to_moz(M.value) : to_moz_scope("BlockStatement", M),
}; };
return { return {
@@ -680,6 +690,21 @@
}; };
}); });
def_to_moz(AST_Call, function To_Moz_CallExpression(M) {
var expr = M.expression;
if (M.args.length == 1 && expr instanceof AST_SymbolRef && expr.name == "import") return {
type: "ImportExpression",
source: to_moz(M.args[0]),
};
return {
type: "CallExpression",
callee: to_moz(expr),
arguments: M.args.map(to_moz),
optional: M.optional,
pure: M.pure,
};
});
def_to_moz(AST_DefClass, function To_Moz_ClassDeclaration(M) { def_to_moz(AST_DefClass, function To_Moz_ClassDeclaration(M) {
return { return {
type: "ClassDeclaration", type: "ClassDeclaration",
@@ -767,6 +792,7 @@
def_to_moz(AST_Directive, function To_Moz_Directive(M) { def_to_moz(AST_Directive, function To_Moz_Directive(M) {
return { return {
type: "ExpressionStatement", type: "ExpressionStatement",
directive: M.value,
expression: set_moz_loc(M, { expression: set_moz_loc(M, {
type: "Literal", type: "Literal",
value: M.value, value: M.value,
@@ -787,7 +813,6 @@
type: "TryStatement", type: "TryStatement",
block: to_moz_block(M), block: to_moz_block(M),
handler: to_moz(M.bcatch), handler: to_moz(M.bcatch),
guardedHandlers: [],
finalizer: to_moz(M.bfinally), finalizer: to_moz(M.bfinally),
}; };
}); });
@@ -796,7 +821,6 @@
return { return {
type: "CatchClause", type: "CatchClause",
param: to_moz(M.argname), param: to_moz(M.argname),
guard: null,
body: to_moz_block(M), body: to_moz_block(M),
}; };
}); });
@@ -805,6 +829,7 @@
return { return {
type: "ExportNamedDeclaration", type: "ExportNamedDeclaration",
declaration: to_moz(M.body), declaration: to_moz(M.body),
specifiers: [],
}; };
}); });
@@ -954,6 +979,8 @@
type: "Property", type: "Property",
kind: "init", kind: "init",
computed: computed, computed: computed,
method: false,
shorthand: false,
key: key, key: key,
value: to_moz(M.value), value: to_moz(M.value),
}; };
@@ -990,6 +1017,7 @@
kind: kind, kind: kind,
computed: computed, computed: computed,
method: M instanceof AST_ObjectMethod, method: M instanceof AST_ObjectMethod,
shorthand: false,
key: key, key: key,
value: to_moz(M.value), value: to_moz(M.value),
}; };
@@ -1043,8 +1071,8 @@
var value = M.value; var value = M.value;
return { return {
type: "Literal", type: "Literal",
bigint: value.slice(0, -1), bigint: value,
raw: value, raw: value + "n",
}; };
}); });