Skip to content

Commit 39e0865

Browse files
feat: Add support for ES2026 using and await using declarations (#658)
* feat: Add support for ES2026 `using` and `await using` declarations * Update packages/espree/README.md Co-authored-by: Milos Djermanovic <[email protected]> * docs: update --------- Co-authored-by: Milos Djermanovic <[email protected]>
1 parent 796a48c commit 39e0865

31 files changed

+4499
-21
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* @fileoverview Tests for ES2026 `using` and `await using`.
3+
* @author Yosuke Ota
4+
*/
5+
6+
import { expect } from "chai";
7+
import * as espree from "espree";
8+
import { analyze } from "../lib/index.js";
9+
10+
describe("`using` and `await using` block scope", () => {
11+
it("`using` in block scope", () => {
12+
const ast = espree.parse(`
13+
{
14+
using i = 42;
15+
i;
16+
}
17+
`, { ecmaVersion: 2026 });
18+
19+
const scopeManager = analyze(ast, { ecmaVersion: 2026 });
20+
21+
expect(scopeManager.scopes).to.have.length(2); // Program and BlockStatement scope.
22+
23+
let scope = scopeManager.scopes[0];
24+
25+
expect(scope.type).to.be.equal("global");
26+
expect(scope.variables).to.have.length(0);
27+
28+
scope = scopeManager.scopes[1];
29+
expect(scope.type).to.be.equal("block");
30+
expect(scope.variables).to.have.length(1);
31+
expect(scope.variables[0].name).to.be.equal("i");
32+
expect(scope.references).to.have.length(2);
33+
expect(scope.references[0].identifier.name).to.be.equal("i");
34+
expect(scope.references[1].identifier.name).to.be.equal("i");
35+
});
36+
it("`await using` in block scope", () => {
37+
const ast = espree.parse(`
38+
async function fn() {
39+
{
40+
await using i = 42;
41+
i;
42+
}
43+
}
44+
`, { ecmaVersion: 2026 });
45+
46+
const scopeManager = analyze(ast, { ecmaVersion: 2026 });
47+
48+
expect(scopeManager.scopes).to.have.length(3); // Program, Function, and BlockStatement scope.
49+
50+
let scope = scopeManager.scopes[0];
51+
52+
expect(scope.type).to.be.equal("global");
53+
expect(scope.variables).to.have.length(1);
54+
expect(scope.variables[0].name).to.be.equal("fn");
55+
56+
scope = scopeManager.scopes[1];
57+
expect(scope.type).to.be.equal("function");
58+
expect(scope.variables).to.have.length(1);
59+
expect(scope.variables[0].name).to.be.equal("arguments");
60+
61+
scope = scopeManager.scopes[2];
62+
expect(scope.type).to.be.equal("block");
63+
expect(scope.variables).to.have.length(1);
64+
expect(scope.variables[0].name).to.be.equal("i");
65+
expect(scope.references).to.have.length(2);
66+
expect(scope.references[0].identifier.name).to.be.equal("i");
67+
expect(scope.references[1].identifier.name).to.be.equal("i");
68+
});
69+
});

packages/espree/README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ const options = {
140140
// create a top-level tokens array containing all tokens
141141
tokens: false,
142142

143-
// Set to 3, 5 (the default), 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 or 16 to specify the version of ECMAScript syntax you want to use.
144-
// You can also set to 2015 (same as 6), 2016 (same as 7), 2017 (same as 8), 2018 (same as 9), 2019 (same as 10), 2020 (same as 11), 2021 (same as 12), 2022 (same as 13), 2023 (same as 14), 2024 (same as 15) or 2025 (same as 16) to use the year-based naming.
143+
// Set to 3, 5 (the default), 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 or 17 to specify the version of ECMAScript syntax you want to use.
144+
// You can also set to 2015 (same as 6), 2016 (same as 7), 2017 (same as 8), 2018 (same as 9), 2019 (same as 10), 2020 (same as 11), 2021 (same as 12), 2022 (same as 13), 2023 (same as 14), 2024 (same as 15), 2025 (same as 16) or 2026 (same as 17) to use the year-based naming.
145145
// You can also set "latest" to use the most recently supported version.
146146
ecmaVersion: 3,
147147

@@ -231,13 +231,11 @@ We are building on top of Acorn, however, so that we can contribute back and hel
231231

232232
### What ECMAScript features do you support?
233233

234-
Espree supports all ECMAScript 2024 features and partially supports ECMAScript 2025 features.
234+
Espree supports all ECMAScript 2025 features and partially supports ECMAScript 2026 features.
235235

236-
Because ECMAScript 2025 is still under development, we are implementing features as they are finalized. Currently, Espree supports:
236+
Because ECMAScript 2026 is still under development, we are implementing features as they are finalized. Currently, Espree supports:
237237

238-
* [RegExp Duplicate named capturing groups](https://github.com/tc39/proposal-duplicate-named-capturing-groups)
239-
* [RegExp Pattern modifiers](https://github.com/tc39/proposal-regexp-modifiers)
240-
* [Import Attributes](https://github.com/tc39/proposal-import-attributes)
238+
* [Explicit Resource Management](https://github.com/tc39/proposal-explicit-resource-management)
241239

242240
See [finished-proposals.md](https://github.com/tc39/proposals/blob/master/finished-proposals.md) to know what features are finalized.
243241

packages/espree/docs/README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ const options = {
140140
// create a top-level tokens array containing all tokens
141141
tokens: false,
142142

143-
// Set to 3, 5 (the default), 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 or 16 to specify the version of ECMAScript syntax you want to use.
144-
// You can also set to 2015 (same as 6), 2016 (same as 7), 2017 (same as 8), 2018 (same as 9), 2019 (same as 10), 2020 (same as 11), 2021 (same as 12), 2022 (same as 13), 2023 (same as 14), 2024 (same as 15) or 2025 (same as 16) to use the year-based naming.
143+
// Set to 3, 5 (the default), 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 or 17 to specify the version of ECMAScript syntax you want to use.
144+
// You can also set to 2015 (same as 6), 2016 (same as 7), 2017 (same as 8), 2018 (same as 9), 2019 (same as 10), 2020 (same as 11), 2021 (same as 12), 2022 (same as 13), 2023 (same as 14), 2024 (same as 15), 2025 (same as 16) or 2026 (same as 17) to use the year-based naming.
145145
// You can also set "latest" to use the most recently supported version.
146146
ecmaVersion: 3,
147147

@@ -231,13 +231,11 @@ We are building on top of Acorn, however, so that we can contribute back and hel
231231

232232
### What ECMAScript features do you support?
233233

234-
Espree supports all ECMAScript 2024 features and partially supports ECMAScript 2025 features.
234+
Espree supports all ECMAScript 2025 features and partially supports ECMAScript 2026 features.
235235

236-
Because ECMAScript 2025 is still under development, we are implementing features as they are finalized. Currently, Espree supports:
236+
Because ECMAScript 2026 is still under development, we are implementing features as they are finalized. Currently, Espree supports:
237237

238-
* [RegExp Duplicate named capturing groups](https://github.com/tc39/proposal-duplicate-named-capturing-groups)
239-
* [RegExp Pattern modifiers](https://github.com/tc39/proposal-regexp-modifiers)
240-
* [Import Attributes](https://github.com/tc39/proposal-import-attributes)
238+
* [Explicit Resource Management](https://github.com/tc39/proposal-explicit-resource-management)
241239

242240
See [finished-proposals.md](https://github.com/tc39/proposals/blob/master/finished-proposals.md) to know what features are finalized.
243241

packages/espree/lib/options.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ const SUPPORTED_VERSIONS = [
2020
13, // 2022
2121
14, // 2023
2222
15, // 2024
23-
16 // 2025
23+
16, // 2025
24+
17 // 2026
2425
];
2526

2627
/**

packages/espree/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"funding": "https://opencollective.com/eslint",
3737
"license": "BSD-2-Clause",
3838
"dependencies": {
39-
"acorn": "^8.14.0",
39+
"acorn": "^8.15.0",
4040
"acorn-jsx": "^5.3.2",
4141
"eslint-visitor-keys": "^4.2.0"
4242
},

packages/espree/tests/fixtures/ecma-version/11/bigint/binary.result.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default {
4949
],
5050
"value": 0b0101n,
5151
"raw": "0b0101n",
52-
"bigint": "0b0101"
52+
"bigint": "5"
5353
}
5454
}
5555
],

packages/espree/tests/fixtures/ecma-version/11/bigint/hex.result.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default {
4949
],
5050
"value": 0x80n,
5151
"raw": "0x80n",
52-
"bigint": "0x80"
52+
"bigint": "128"
5353
}
5454
}
5555
],

packages/espree/tests/fixtures/ecma-version/11/bigint/octal.result.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default {
4949
],
5050
"value": 0o755n,
5151
"raw": "0o755n",
52-
"bigint": "0o755"
52+
"bigint": "493"
5353
}
5454
}
5555
],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
"index": 7,
3+
"lineNumber": 1,
4+
"column": 8,
5+
"message": "Unexpected token using"
6+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
"index": 0,
3+
"lineNumber": 1,
4+
"column": 1,
5+
"message": "'import' and 'export' may appear only with 'sourceType: module'"
6+
};

0 commit comments

Comments
 (0)