Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve ESTree compatibility #5836

Merged
merged 1 commit into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/moz.yml
Original file line number Diff line number Diff line change
@@ -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
40 changes: 34 additions & 6 deletions lib/mozilla-ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@
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) {
return new AST_DefClass({
start: my_start_token(M),
Expand Down Expand Up @@ -458,7 +468,7 @@
end: my_end_token(M),
};
if (M.bigint) {
args.value = M.bigint.toLowerCase() + "n";
args.value = M.bigint.toLowerCase();
return new AST_BigInt(args);
}
var val = M.value;
Expand Down Expand Up @@ -631,7 +641,6 @@
map("AssignmentPattern", AST_DefaultValue, "left>name, right>value");
map("ConditionalExpression", AST_Conditional, "test>condition, consequent>consequent, alternate>alternative");
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("SpreadElement", AST_Spread, "argument>expression");
map("ObjectExpression", AST_Object, "properties@properties");
Expand Down Expand Up @@ -668,6 +677,7 @@
type: "ArrowFunctionExpression",
async: is_async(M),
params: params,
expression: !!M.value,
body: M.value ? to_moz(M.value) : to_moz_scope("BlockStatement", M),
};
return {
Expand All @@ -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) {
return {
type: "ClassDeclaration",
Expand Down Expand Up @@ -767,6 +792,7 @@
def_to_moz(AST_Directive, function To_Moz_Directive(M) {
return {
type: "ExpressionStatement",
directive: M.value,
expression: set_moz_loc(M, {
type: "Literal",
value: M.value,
Expand All @@ -787,7 +813,6 @@
type: "TryStatement",
block: to_moz_block(M),
handler: to_moz(M.bcatch),
guardedHandlers: [],
finalizer: to_moz(M.bfinally),
};
});
Expand All @@ -796,7 +821,6 @@
return {
type: "CatchClause",
param: to_moz(M.argname),
guard: null,
body: to_moz_block(M),
};
});
Expand All @@ -805,6 +829,7 @@
return {
type: "ExportNamedDeclaration",
declaration: to_moz(M.body),
specifiers: [],
};
});

Expand Down Expand Up @@ -954,6 +979,8 @@
type: "Property",
kind: "init",
computed: computed,
method: false,
shorthand: false,
key: key,
value: to_moz(M.value),
};
Expand Down Expand Up @@ -990,6 +1017,7 @@
kind: kind,
computed: computed,
method: M instanceof AST_ObjectMethod,
shorthand: false,
key: key,
value: to_moz(M.value),
};
Expand Down Expand Up @@ -1043,8 +1071,8 @@
var value = M.value;
return {
type: "Literal",
bigint: value.slice(0, -1),
raw: value,
bigint: value,
raw: value + "n",
};
});

Expand Down