Skip to content

Commit ca4185a

Browse files
authoredJun 9, 2024··
improve ESTree compatibility (#5836)
closes #5834 closes #5835
1 parent e7b9b4a commit ca4185a

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed
 

‎.github/workflows/moz.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: ESTree
2+
on:
3+
pull_request:
4+
push:
5+
branches: [ master ]
6+
jobs:
7+
test:
8+
name: fuzzing
9+
runs-on: ubuntu-latest
10+
env:
11+
NODE: latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Perform tests
15+
shell: bash
16+
run: |
17+
. ./test/release/install.sh
18+
node test/mozilla-ast.js 5000

‎lib/mozilla-ast.js

+34-6
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@
125125
body: normalize_directives(from_moz(M.body).body),
126126
});
127127
},
128+
CallExpression: function(M) {
129+
return new AST_Call({
130+
start: my_start_token(M),
131+
end: my_end_token(M),
132+
expression: from_moz(M.callee),
133+
args: M.arguments.map(from_moz),
134+
optional: M.optional,
135+
pure: M.pure,
136+
});
137+
},
128138
ClassDeclaration: function(M) {
129139
return new AST_DefClass({
130140
start: my_start_token(M),
@@ -458,7 +468,7 @@
458468
end: my_end_token(M),
459469
};
460470
if (M.bigint) {
461-
args.value = M.bigint.toLowerCase() + "n";
471+
args.value = M.bigint.toLowerCase();
462472
return new AST_BigInt(args);
463473
}
464474
var val = M.value;
@@ -631,7 +641,6 @@
631641
map("AssignmentPattern", AST_DefaultValue, "left>name, right>value");
632642
map("ConditionalExpression", AST_Conditional, "test>condition, consequent>consequent, alternate>alternative");
633643
map("NewExpression", AST_New, "callee>expression, arguments@args, pure=pure");
634-
map("CallExpression", AST_Call, "callee>expression, arguments@args, optional=optional, pure=pure");
635644
map("SequenceExpression", AST_Sequence, "expressions@expressions");
636645
map("SpreadElement", AST_Spread, "argument>expression");
637646
map("ObjectExpression", AST_Object, "properties@properties");
@@ -668,6 +677,7 @@
668677
type: "ArrowFunctionExpression",
669678
async: is_async(M),
670679
params: params,
680+
expression: !!M.value,
671681
body: M.value ? to_moz(M.value) : to_moz_scope("BlockStatement", M),
672682
};
673683
return {
@@ -680,6 +690,21 @@
680690
};
681691
});
682692

693+
def_to_moz(AST_Call, function To_Moz_CallExpression(M) {
694+
var expr = M.expression;
695+
if (M.args.length == 1 && expr instanceof AST_SymbolRef && expr.name == "import") return {
696+
type: "ImportExpression",
697+
source: to_moz(M.args[0]),
698+
};
699+
return {
700+
type: "CallExpression",
701+
callee: to_moz(expr),
702+
arguments: M.args.map(to_moz),
703+
optional: M.optional,
704+
pure: M.pure,
705+
};
706+
});
707+
683708
def_to_moz(AST_DefClass, function To_Moz_ClassDeclaration(M) {
684709
return {
685710
type: "ClassDeclaration",
@@ -767,6 +792,7 @@
767792
def_to_moz(AST_Directive, function To_Moz_Directive(M) {
768793
return {
769794
type: "ExpressionStatement",
795+
directive: M.value,
770796
expression: set_moz_loc(M, {
771797
type: "Literal",
772798
value: M.value,
@@ -787,7 +813,6 @@
787813
type: "TryStatement",
788814
block: to_moz_block(M),
789815
handler: to_moz(M.bcatch),
790-
guardedHandlers: [],
791816
finalizer: to_moz(M.bfinally),
792817
};
793818
});
@@ -796,7 +821,6 @@
796821
return {
797822
type: "CatchClause",
798823
param: to_moz(M.argname),
799-
guard: null,
800824
body: to_moz_block(M),
801825
};
802826
});
@@ -805,6 +829,7 @@
805829
return {
806830
type: "ExportNamedDeclaration",
807831
declaration: to_moz(M.body),
832+
specifiers: [],
808833
};
809834
});
810835

@@ -954,6 +979,8 @@
954979
type: "Property",
955980
kind: "init",
956981
computed: computed,
982+
method: false,
983+
shorthand: false,
957984
key: key,
958985
value: to_moz(M.value),
959986
};
@@ -990,6 +1017,7 @@
9901017
kind: kind,
9911018
computed: computed,
9921019
method: M instanceof AST_ObjectMethod,
1020+
shorthand: false,
9931021
key: key,
9941022
value: to_moz(M.value),
9951023
};
@@ -1043,8 +1071,8 @@
10431071
var value = M.value;
10441072
return {
10451073
type: "Literal",
1046-
bigint: value.slice(0, -1),
1047-
raw: value,
1074+
bigint: value,
1075+
raw: value + "n",
10481076
};
10491077
});
10501078

0 commit comments

Comments
 (0)
Please sign in to comment.