Visitar URL original
fix: `no-restricted-globals` crash on global objects as property valu… · eslint/eslint@827a8f3 · GitHub
Skip to content

Commit 827a8f3

Browse files
authored
fix: no-restricted-globals crash on global objects as property values (#21449)
1 parent 97431f8 commit 827a8f3

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

‎lib/rules/no-restricted-globals.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ module.exports = {
239239
parent = parent.parent;
240240
}
241241

242+
if (parent.type !== "MemberExpression") {
243+
return;
244+
}
245+
242246
const propertyName =
243247
astUtils.getStaticPropertyName(parent);
244248
if (propertyName && isRestricted(propertyName)) {

‎tests/lib/rules/no-restricted-globals.js‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,15 @@ ruleTester.run("no-restricted-globals", rule, {
249249
],
250250
languageOptions: { globals: { myGlobal: "readonly" } },
251251
},
252+
{
253+
code: "const obj = { foo: window };",
254+
options: [{ globals: ["foo"], checkGlobalObject: true }],
255+
languageOptions: { globals: globals.browser },
256+
},
257+
{
258+
code: "class C { foo = globalThis; }",
259+
options: [{ globals: ["foo"], checkGlobalObject: true }],
260+
},
252261
],
253262
invalid: [
254263
{
@@ -1106,6 +1115,21 @@ ruleTester.run("no-restricted-globals", rule, {
11061115
},
11071116
],
11081117
},
1118+
{
1119+
code: "const obj = { self };",
1120+
options: [{ globals: ["self"], checkGlobalObject: true }],
1121+
languageOptions: { globals: globals.browser },
1122+
errors: [
1123+
{
1124+
messageId: "defaultMessage",
1125+
data: { name: "self" },
1126+
line: 1,
1127+
column: 15,
1128+
endLine: 1,
1129+
endColumn: 19,
1130+
},
1131+
],
1132+
},
11091133
],
11101134
});
11111135

0 commit comments

Comments
 (0)