Skip to content

Commit 2dc23b8

Browse files
mdjermanovicplatinumazure
authored andcommitted
Update: fix no-dupe-keys false negatives on empty string names (#12069)
1 parent 19ab666 commit 2dc23b8

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/rules/no-dupe-keys.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ module.exports = {
120120
}
121121

122122
// Skip if the name is not static.
123-
if (!name) {
123+
if (name === null) {
124124
return;
125125
}
126126

tests/lib/rules/no-dupe-keys.js

+7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ ruleTester.run("no-dupe-keys", rule, {
2222
valid: [
2323
"var foo = { __proto__: 1, two: 2};",
2424
"var x = { foo: 1, bar: 2 };",
25+
"var x = { '': 1, bar: 2 };",
26+
"var x = { '': 1, ' ': 2 };",
27+
{ code: "var x = { '': 1, [null]: 2 };", parserOptions: { ecmaVersion: 6 } },
28+
{ code: "var x = { '': 1, [a]: 2 };", parserOptions: { ecmaVersion: 6 } },
29+
{ code: "var x = { [a]: 1, [a]: 2 };", parserOptions: { ecmaVersion: 6 } },
2530
"+{ get a() { }, set a(b) { } };",
2631
{ code: "var x = { a: b, [a]: b };", parserOptions: { ecmaVersion: 6 } },
2732
{ code: "var x = { a: b, ...c }", parserOptions: { ecmaVersion: 2018 } },
@@ -32,6 +37,8 @@ ruleTester.run("no-dupe-keys", rule, {
3237
invalid: [
3338
{ code: "var x = { a: b, ['a']: b };", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "a" }, type: "ObjectExpression" }] },
3439
{ code: "var x = { y: 1, y: 2 };", errors: [{ messageId: "unexpected", data: { name: "y" }, type: "ObjectExpression" }] },
40+
{ code: "var x = { '': 1, '': 2 };", errors: [{ messageId: "unexpected", data: { name: "" }, type: "ObjectExpression" }] },
41+
{ code: "var x = { '': 1, [``]: 2 };", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "" }, type: "ObjectExpression" }] },
3542
{ code: "var foo = { 0x1: 1, 1: 2};", errors: [{ messageId: "unexpected", data: { name: "1" }, type: "ObjectExpression" }] },
3643
{ code: "var x = { \"z\": 1, z: 2 };", errors: [{ messageId: "unexpected", data: { name: "z" }, type: "ObjectExpression" }] },
3744
{ code: "var foo = {\n bar: 1,\n bar: 1,\n}", errors: [{ messageId: "unexpected", data: { name: "bar" }, line: 3, column: 3 }] },

0 commit comments

Comments
 (0)