Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'tools/node_modules/eslint/lib/rules/no-extra-parens.js')
-rw-r--r--tools/node_modules/eslint/lib/rules/no-extra-parens.js50
1 files changed, 27 insertions, 23 deletions
diff --git a/tools/node_modules/eslint/lib/rules/no-extra-parens.js b/tools/node_modules/eslint/lib/rules/no-extra-parens.js
index 19c6fced79d..307e340c958 100644
--- a/tools/node_modules/eslint/lib/rules/no-extra-parens.js
+++ b/tools/node_modules/eslint/lib/rules/no-extra-parens.js
@@ -844,45 +844,49 @@ module.exports = {
ExportDefaultDeclaration: node => checkExpressionOrExportStatement(node.declaration),
ExpressionStatement: node => checkExpressionOrExportStatement(node.expression),
- "ForInStatement, ForOfStatement"(node) {
- if (node.left.type !== "VariableDeclarator") {
+ ForInStatement(node) {
+ if (node.left.type !== "VariableDeclaration") {
const firstLeftToken = sourceCode.getFirstToken(node.left, astUtils.isNotOpeningParenToken);
if (
- firstLeftToken.value === "let" && (
-
- /*
- * If `let` is the only thing on the left side of the loop, it's the loop variable: `for ((let) of foo);`
- * Removing it will cause a syntax error, because it will be parsed as the start of a VariableDeclarator.
- */
- (firstLeftToken.range[1] === node.left.range[1] || /*
- * If `let` is followed by a `[` token, it's a property access on the `let` value: `for ((let[foo]) of bar);`
- * Removing it will cause the property access to be parsed as a destructuring declaration of `foo` instead.
- */
- astUtils.isOpeningBracketToken(
- sourceCode.getTokenAfter(firstLeftToken, astUtils.isNotClosingParenToken)
- ))
+ firstLeftToken.value === "let" &&
+ astUtils.isOpeningBracketToken(
+ sourceCode.getTokenAfter(firstLeftToken, astUtils.isNotClosingParenToken)
)
) {
+
+ // ForInStatement#left expression cannot start with `let[`.
tokensToIgnore.add(firstLeftToken);
}
}
- if (node.type === "ForOfStatement") {
- const hasExtraParens = node.right.type === "SequenceExpression"
- ? hasDoubleExcessParens(node.right)
- : hasExcessParens(node.right);
+ if (hasExcessParens(node.left)) {
+ report(node.left);
+ }
- if (hasExtraParens) {
- report(node.right);
- }
- } else if (hasExcessParens(node.right)) {
+ if (hasExcessParens(node.right)) {
report(node.right);
}
+ },
+
+ ForOfStatement(node) {
+ if (node.left.type !== "VariableDeclaration") {
+ const firstLeftToken = sourceCode.getFirstToken(node.left, astUtils.isNotOpeningParenToken);
+
+ if (firstLeftToken.value === "let") {
+
+ // ForOfStatement#left expression cannot start with `let`.
+ tokensToIgnore.add(firstLeftToken);
+ }
+ }
if (hasExcessParens(node.left)) {
report(node.left);
}
+
+ if (hasExcessParensWithPrecedence(node.right, PRECEDENCE_OF_ASSIGNMENT_EXPR)) {
+ report(node.right);
+ }
},
ForStatement(node) {