Skip to content
Permalink
Browse files
Fix: keyword-spacing private name compat (refs #14857) (#14946)
* Fix: keyword-spacing private name compat (refs #14857)

* Update tests/lib/rules/keyword-spacing.js

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
  • Loading branch information
nzakas and mdjermanovic committed Aug 20, 2021
1 parent 58840ac commit ee1b54f31fa840e6ec72a313aa4090fdd3e985cd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
@@ -403,7 +403,15 @@ module.exports = {
*/
function checkSpacingForForInStatement(node) {
checkSpacingAroundFirstToken(node);
checkSpacingAroundTokenBefore(node.right);

const inToken = sourceCode.getTokenBefore(node.right, astUtils.isNotOpeningParenToken);
const previousToken = sourceCode.getTokenBefore(inToken);

if (previousToken.type !== "PrivateIdentifier") {
checkSpacingBefore(inToken);
}

checkSpacingAfter(inToken);
}

/**
@@ -419,7 +427,15 @@ module.exports = {
} else {
checkSpacingAroundFirstToken(node);
}
checkSpacingAround(sourceCode.getTokenBefore(node.right, astUtils.isNotOpeningParenToken));

const ofToken = sourceCode.getTokenBefore(node.right, astUtils.isNotOpeningParenToken);
const previousToken = sourceCode.getTokenBefore(ofToken);

if (previousToken.type !== "PrivateIdentifier") {
checkSpacingBefore(ofToken);
}

checkSpacingAfter(ofToken);
}

/**
@@ -379,6 +379,10 @@ ruleTester.run("keyword-spacing", rule, {
{ code: "<Foo onClick={class {}} />", parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } },
{ code: "<Foo onClick={ class{}} />", options: [NEITHER], parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } },

// private names
{ code: "class C {\n#x;\nfoo() {\nfor (this.#x of bar){}}}", options: [{ before: false }], parserOptions: { ecmaVersion: 2022 } },
{ code: "class C {\n#x;\nfoo() {\nfor (this.#x in bar){}}}", options: [{ before: false }], parserOptions: { ecmaVersion: 2022 } },

//----------------------------------------------------------------------
// const
//----------------------------------------------------------------------

0 comments on commit ee1b54f

Please sign in to comment.