Skip to content

Commit

Permalink
feat: support for private-in syntax (fixes #14811) (#15060)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Nov 21, 2021
1 parent 34bc8d7 commit e2fe7ef
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/rules/utils/ast-utils.js
Expand Up @@ -1833,6 +1833,10 @@ module.exports = {
return true;
}

if (rightToken.type === "PrivateIdentifier") {
return true;
}

return false;
},

Expand Down
18 changes: 18 additions & 0 deletions tests/lib/rules/space-unary-ops.js
Expand Up @@ -250,6 +250,11 @@ ruleTester.run("space-unary-ops", rule, {
code: "function *foo () { yield(0) }",
options: [{ words: false, overrides: { yield: false } }],
parserOptions: { ecmaVersion: 6 }
},
{
code: "class C { #x; *foo(bar) { yield#x in bar; } }",
options: [{ words: false }],
parserOptions: { ecmaVersion: 2022 }
}
],

Expand Down Expand Up @@ -805,6 +810,19 @@ ruleTester.run("space-unary-ops", rule, {
line: 1,
column: 24
}]
},
{
code: "class C { #x; *foo(bar) { yield #x in bar; } }",
output: "class C { #x; *foo(bar) { yield#x in bar; } }",
options: [{ words: false }],
parserOptions: { ecmaVersion: 2022 },
errors: [{
messageId: "unexpectedAfterWord",
data: { word: "yield" },
type: "YieldExpression",
line: 1,
column: 27
}]
}
]
});
5 changes: 4 additions & 1 deletion tests/lib/rules/utils/ast-utils.js
Expand Up @@ -1495,7 +1495,10 @@ describe("ast-utils", () => {
[["(", "123invalidtoken"], false],
[["(", "1n"], true],
[["1n", "+"], true],
[["1n", "in"], false]
[["1n", "in"], false],
[["return", "#x"], true],
[["yield", "#x"], true],
[["get", "#x"], true]
]);

CASES.forEach((expectedResult, tokenStrings) => {
Expand Down

0 comments on commit e2fe7ef

Please sign in to comment.