Skip to content
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
69 changes: 69 additions & 0 deletions packages/eslint-scope/tests/using-scope.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* @fileoverview Tests for ES2026 `using` and `await using`.
* @author Yosuke Ota
*/

import { expect } from "chai";
import * as espree from "espree";
import { analyze } from "../lib/index.js";

describe("`using` and `await using` block scope", () => {
it("`using` in block scope", () => {
const ast = espree.parse(`
{
using i = 42;
i;
}
`, { ecmaVersion: 2026 });

const scopeManager = analyze(ast, { ecmaVersion: 2026 });

expect(scopeManager.scopes).to.have.length(2); // Program and BlockStatement scope.

let scope = scopeManager.scopes[0];

expect(scope.type).to.be.equal("global");
expect(scope.variables).to.have.length(0);

scope = scopeManager.scopes[1];
expect(scope.type).to.be.equal("block");
expect(scope.variables).to.have.length(1);
expect(scope.variables[0].name).to.be.equal("i");
expect(scope.references).to.have.length(2);
expect(scope.references[0].identifier.name).to.be.equal("i");
expect(scope.references[1].identifier.name).to.be.equal("i");
});
it("`await using` in block scope", () => {
const ast = espree.parse(`
async function fn() {
{
await using i = 42;
i;
}
}
`, { ecmaVersion: 2026 });

const scopeManager = analyze(ast, { ecmaVersion: 2026 });

expect(scopeManager.scopes).to.have.length(3); // Program, Function, and BlockStatement scope.

let scope = scopeManager.scopes[0];

expect(scope.type).to.be.equal("global");
expect(scope.variables).to.have.length(1);
expect(scope.variables[0].name).to.be.equal("fn");

scope = scopeManager.scopes[1];
expect(scope.type).to.be.equal("function");
expect(scope.variables).to.have.length(1);
expect(scope.variables[0].name).to.be.equal("arguments");

scope = scopeManager.scopes[2];
expect(scope.type).to.be.equal("block");
expect(scope.variables).to.have.length(1);
expect(scope.variables[0].name).to.be.equal("i");
expect(scope.references).to.have.length(2);
expect(scope.references[0].identifier.name).to.be.equal("i");
expect(scope.references[1].identifier.name).to.be.equal("i");
});
});
12 changes: 5 additions & 7 deletions packages/espree/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ const options = {
// create a top-level tokens array containing all tokens
tokens: false,

// 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.
// 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.
// 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.
// 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.
// You can also set "latest" to use the most recently supported version.
ecmaVersion: 3,

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

### What ECMAScript features do you support?

Espree supports all ECMAScript 2024 features and partially supports ECMAScript 2025 features.
Espree supports all ECMAScript 2025 features and partially supports ECMAScript 2026 features.

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

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

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

Expand Down
12 changes: 5 additions & 7 deletions packages/espree/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ const options = {
// create a top-level tokens array containing all tokens
tokens: false,

// 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.
// 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.
// 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.
// 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.
// You can also set "latest" to use the most recently supported version.
ecmaVersion: 3,

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

### What ECMAScript features do you support?

Espree supports all ECMAScript 2024 features and partially supports ECMAScript 2025 features.
Espree supports all ECMAScript 2025 features and partially supports ECMAScript 2026 features.

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

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

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

Expand Down
3 changes: 2 additions & 1 deletion packages/espree/lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const SUPPORTED_VERSIONS = [
13, // 2022
14, // 2023
15, // 2024
16 // 2025
16, // 2025
17 // 2026
];

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/espree/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"funding": "https://opencollective.com/eslint",
"license": "BSD-2-Clause",
"dependencies": {
"acorn": "^8.14.0",
"acorn": "^8.15.0",
"acorn-jsx": "^5.3.2",
"eslint-visitor-keys": "^4.2.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default {
],
"value": 0b0101n,
"raw": "0b0101n",
"bigint": "0b0101"
"bigint": "5"
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default {
],
"value": 0x80n,
"raw": "0x80n",
"bigint": "0x80"
"bigint": "128"
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default {
],
"value": 0o755n,
"raw": "0o755n",
"bigint": "0o755"
"bigint": "493"
}
}
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
"index": 7,
"lineNumber": 1,
"column": 8,
"message": "Unexpected token using"
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
"index": 0,
"lineNumber": 1,
"column": 1,
"message": "'import' and 'export' may appear only with 'sourceType: module'"
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export using x = foo();
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
"index": 8,
"lineNumber": 1,
"column": 9,
"message": "The keyword 'let' is reserved"
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
"index": 8,
"lineNumber": 1,
"column": 9,
"message": "let is disallowed as a lexically bound name"
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ using let = x; }
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
"index": 8,
"lineNumber": 1,
"column": 9,
"message": "Unexpected token {"
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ using {x} = obj; }
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
"index": 20,
"lineNumber": 1,
"column": 21,
"message": "Missing initializer in using declaration"
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ using x = foo(), y; }
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
"index": 9,
"lineNumber": 1,
"column": 10,
"message": "Missing initializer in using declaration"
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ using x; }
Loading