Skip to content

Commit 966824e

Browse files
authored
Merge pull request #31 from estools/es2025
Support ES2025 grammar
2 parents 067643e + 3b82baf commit 966824e

File tree

4 files changed

+126
-1
lines changed

4 files changed

+126
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Leaves properties defined in [The ESTree Spec](https://github.com/estree/estree)
3333
- [ES2022](https://github.com/estree/estree/blob/master/es2022.md)
3434
- ES2023
3535
- ES2024
36+
- [ES2025](https://github.com/estree/estree/blob/master/es2025.md)
3637

3738

3839
### const customizedCloneFunctionWithAllowList = espurify.cloneWithAllowlist(allowList)
@@ -90,7 +91,7 @@ Configuration options. If not passed, default options will be used.
9091
|:---------------------|:--------------|
9192
| `string` or `number` | `2022` |
9293
93-
Indicates the ECMAScript version to clone. Must be either 5, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024.
94+
Indicates the ECMAScript version to clone. Must be either 5, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025.
9495
9596
9697
#### options.extra

lib/ast-properties/es2025.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// see: https://github.com/estree/estree/blob/master/es2025.md
2+
module.exports = {
3+
ArrayExpression: ['type', 'elements'],
4+
ArrayPattern: ['type', 'elements'],
5+
ArrowFunctionExpression: ['type', 'id', 'params', 'body', 'generator', 'expression', 'async'],
6+
AssignmentExpression: ['type', 'operator', 'left', 'right'],
7+
AssignmentPattern: ['type', 'left', 'right'],
8+
AwaitExpression: ['type', 'argument'],
9+
BinaryExpression: ['type', 'operator', 'left', 'right'],
10+
BlockStatement: ['type', 'body'],
11+
BreakStatement: ['type', 'label'],
12+
CallExpression: ['type', 'callee', 'arguments', 'optional'],
13+
CatchClause: ['type', 'param', 'body'],
14+
ChainExpression: ['type', 'expression'],
15+
ClassBody: ['type', 'body'],
16+
ClassDeclaration: ['type', 'id', 'superClass', 'body'],
17+
ClassExpression: ['type', 'id', 'superClass', 'body'],
18+
ConditionalExpression: ['type', 'test', 'consequent', 'alternate'],
19+
ContinueStatement: ['type', 'label'],
20+
DebuggerStatement: ['type'],
21+
DoWhileStatement: ['type', 'body', 'test'],
22+
EmptyStatement: ['type'],
23+
ExportAllDeclaration: ['type', 'source', 'exported', 'attributes'],
24+
ExportDefaultDeclaration: ['type', 'declaration'],
25+
ExportNamedDeclaration: ['type', 'declaration', 'specifiers', 'source', 'attributes'],
26+
ExportSpecifier: ['type', 'exported', 'local'],
27+
ExpressionStatement: ['type', 'expression', 'directive'],
28+
ForInStatement: ['type', 'left', 'right', 'body'],
29+
ForOfStatement: ['type', 'left', 'right', 'body', 'await'],
30+
ForStatement: ['type', 'init', 'test', 'update', 'body'],
31+
FunctionDeclaration: ['type', 'id', 'params', 'body', 'generator', 'async'],
32+
FunctionExpression: ['type', 'id', 'params', 'body', 'generator', 'async'],
33+
Identifier: ['type', 'name'],
34+
IfStatement: ['type', 'test', 'consequent', 'alternate'],
35+
ImportAttribute: ['type', 'key', 'value'],
36+
ImportDeclaration: ['type', 'specifiers', 'source', 'attributes'],
37+
ImportDefaultSpecifier: ['type', 'local'],
38+
ImportExpression: ['type', 'source', 'options'],
39+
ImportNamespaceSpecifier: ['type', 'local'],
40+
ImportSpecifier: ['type', 'imported', 'local'],
41+
LabeledStatement: ['type', 'label', 'body'],
42+
Literal: ['type', 'value', 'regex', 'bigint'],
43+
LogicalExpression: ['type', 'operator', 'left', 'right'],
44+
MemberExpression: ['type', 'object', 'property', 'computed', 'optional'],
45+
MetaProperty: ['type', 'meta', 'property'],
46+
MethodDefinition: ['type', 'key', 'value', 'kind', 'computed', 'static'],
47+
NewExpression: ['type', 'callee', 'arguments'],
48+
ObjectExpression: ['type', 'properties'],
49+
ObjectPattern: ['type', 'properties'],
50+
PrivateIdentifier: ['type', 'name'],
51+
Program: ['type', 'body', 'sourceType'],
52+
Property: ['type', 'key', 'value', 'kind', 'method', 'shorthand', 'computed'],
53+
PropertyDefinition: ['type', 'key', 'value', 'computed', 'static'],
54+
RestElement: ['type', 'argument'],
55+
ReturnStatement: ['type', 'argument'],
56+
SequenceExpression: ['type', 'expressions'],
57+
SpreadElement: ['type', 'argument'],
58+
StaticBlock: ['type', 'body'],
59+
Super: ['type'],
60+
SwitchCase: ['type', 'test', 'consequent'],
61+
SwitchStatement: ['type', 'discriminant', 'cases'],
62+
TaggedTemplateExpression: ['type', 'tag', 'quasi'],
63+
TemplateElement: ['type', 'tail', 'value'],
64+
TemplateLiteral: ['type', 'quasis', 'expressions'],
65+
ThisExpression: ['type'],
66+
ThrowStatement: ['type', 'argument'],
67+
TryStatement: ['type', 'block', 'handler', 'finalizer'],
68+
UnaryExpression: ['type', 'operator', 'prefix', 'argument'],
69+
UpdateExpression: ['type', 'operator', 'argument', 'prefix'],
70+
VariableDeclaration: ['type', 'declarations', 'kind'],
71+
VariableDeclarator: ['type', 'id', 'init'],
72+
WhileStatement: ['type', 'test', 'body'],
73+
WithStatement: ['type', 'object', 'body'],
74+
YieldExpression: ['type', 'argument', 'delegate']
75+
};

lib/ast-properties/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const ecmaVersions = {
2+
2025: require('./es2025'),
23
2024: require('./es2022'), // no change in AST Node level
34
2023: require('./es2022'), // no change in AST Node level
45
2022: require('./es2022'),

test/ecmaversion_test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,54 @@ const acorn = require('acorn');
44
const { describe, it } = require('node:test');
55

66
describe('ecmaVersion option', function () {
7+
describe('es2025', function () {
8+
it('ImportAttributes', function () {
9+
const clone = espurify.customize({ ecmaVersion: 2025 });
10+
const code = `
11+
import foo from "./foo.json" with { type: "json" }
12+
`;
13+
const ast = acorn.parse(code, { locations: true, ranges: true, ecmaVersion: 2025, sourceType: 'module' });
14+
const expected = {
15+
type: 'Program',
16+
body: [
17+
{
18+
type: 'ImportDeclaration',
19+
source: {
20+
type: 'Literal',
21+
value: './foo.json'
22+
},
23+
specifiers: [
24+
{
25+
type: 'ImportDefaultSpecifier',
26+
local: {
27+
type: 'Identifier',
28+
name: 'foo'
29+
}
30+
}
31+
],
32+
attributes: [
33+
{
34+
type: 'ImportAttribute',
35+
key: {
36+
type: 'Identifier',
37+
name: 'type'
38+
},
39+
value: {
40+
type: 'Literal',
41+
value: 'json'
42+
}
43+
}
44+
]
45+
}
46+
],
47+
sourceType: 'module'
48+
};
49+
assert.deepEqual(clone(ast), expected);
50+
const clone2024 = espurify.customize({ ecmaVersion: 2024 });
51+
assert.notDeepEqual(clone2024(ast), expected);
52+
});
53+
});
54+
755
describe('es2022', function () {
856
it('PropertyDefinition, PrivateIdentifier and StaticBlock', function () {
957
const clone = espurify.customize({ ecmaVersion: 2022 });

0 commit comments

Comments
 (0)