Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb2498d2

Browse files
mdjermanovicilyavolodin
authored andcommitted
Update: Fix handling of property names in no-self-assign (#12105)
1 parent1ee61b0 commitb2498d2

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

‎lib/rules/no-self-assign.js‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,14 @@ function eachSelfAssignment(left, right, props, report) {
152152
}elseif(
153153
left.type==="Property"&&
154154
right.type==="Property"&&
155-
!left.computed&&
156-
!right.computed&&
157155
right.kind==="init"&&
158-
!right.method&&
159-
left.key.name===right.key.name
156+
!right.method
160157
){
161-
eachSelfAssignment(left.value,right.value,props,report);
158+
constleftName=astUtils.getStaticPropertyName(left);
159+
160+
if(leftName!==null&&leftName===astUtils.getStaticPropertyName(right)){
161+
eachSelfAssignment(left.value,right.value,props,report);
162+
}
162163
}elseif(
163164
props&&
164165
left.type==="MemberExpression"&&

‎tests/lib/rules/no-self-assign.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ ruleTester.run("no-self-assign", rule, {
4141
{code:"({a} = {a: b})",parserOptions:{ecmaVersion:6}},
4242
{code:"({a} = {a() {}})",parserOptions:{ecmaVersion:6}},
4343
{code:"({a} = {[a]: a})",parserOptions:{ecmaVersion:6}},
44+
{code:"({[a]: b} = {[a]: b})",parserOptions:{ecmaVersion:6}},
45+
{code:"({'foo': a, 1: a} = {'bar': a, 2: a})",parserOptions:{ecmaVersion:6}},
4446
{code:"({a, ...b} = {a, ...b})",parserOptions:{ecmaVersion:2018}},
4547
{code:"a.b = a.c",options:[{props:true}]},
4648
{code:"a.b = c.b",options:[{props:true}]},
@@ -80,6 +82,15 @@ ruleTester.run("no-self-assign", rule, {
8082
{code:"[[a], {b}] = [[a], {b}]",parserOptions:{ecmaVersion:6},errors:["'a' is assigned to itself.","'b' is assigned to itself."]},
8183
{code:"({a} = {a})",parserOptions:{ecmaVersion:6},errors:["'a' is assigned to itself."]},
8284
{code:"({a: b} = {a: b})",parserOptions:{ecmaVersion:6},errors:["'b' is assigned to itself."]},
85+
{code:"({'a': b} = {'a': b})",parserOptions:{ecmaVersion:6},errors:["'b' is assigned to itself."]},
86+
{code:"({a: b} = {'a': b})",parserOptions:{ecmaVersion:6},errors:["'b' is assigned to itself."]},
87+
{code:"({'a': b} = {a: b})",parserOptions:{ecmaVersion:6},errors:["'b' is assigned to itself."]},
88+
{code:"({1: b} = {1: b})",parserOptions:{ecmaVersion:6},errors:["'b' is assigned to itself."]},
89+
{code:"({1: b} = {'1': b})",parserOptions:{ecmaVersion:6},errors:["'b' is assigned to itself."]},
90+
{code:"({'1': b} = {1: b})",parserOptions:{ecmaVersion:6},errors:["'b' is assigned to itself."]},
91+
{code:"({['a']: b} = {a: b})",parserOptions:{ecmaVersion:6},errors:["'b' is assigned to itself."]},
92+
{code:"({'a': b} = {[`a`]: b})",parserOptions:{ecmaVersion:6},errors:["'b' is assigned to itself."]},
93+
{code:"({1: b} = {[1]: b})",parserOptions:{ecmaVersion:6},errors:["'b' is assigned to itself."]},
8394
{code:"({a, b} = {a, b})",parserOptions:{ecmaVersion:6},errors:["'a' is assigned to itself.","'b' is assigned to itself."]},
8495
{code:"({a, b} = {b, a})",parserOptions:{ecmaVersion:6},errors:["'b' is assigned to itself.","'a' is assigned to itself."]},
8596
{code:"({a, b} = {c, a})",parserOptions:{ecmaVersion:6},errors:["'a' is assigned to itself."]},

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp