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

Commit87ec3c4

Browse files
authored
fix: do not throw when defining a global named__defineSetter__ (#18898)
1 parent60a1267 commit87ec3c4

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

‎lib/linter/linter.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ function createLanguageOptions({ globals: configuredGlobals, parser, parserOptio
733733
*/
734734
functionresolveGlobals(providedGlobals,enabledEnvironments){
735735
returnObject.assign(
736-
{},
736+
Object.create(null),
737737
...enabledEnvironments.filter(env=>env.globals).map(env=>env.globals),
738738
providedGlobals
739739
);

‎lib/source-code/source-code.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ class SourceCode extends TokenStore {
934934
* https://github.com/eslint/eslint/issues/16302
935935
*/
936936
constconfigGlobals=Object.assign(
937-
{},
937+
Object.create(null),// https://github.com/eslint/eslint/issues/18363
938938
getGlobalsForEcmaVersion(languageOptions.ecmaVersion),
939939
languageOptions.sourceType==="commonjs" ?globals.commonjs :void0,
940940
languageOptions.globals

‎tests/lib/linter/linter.js‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12510,6 +12510,48 @@ describe("Linter with FlatConfigArray", () => {
1251012510

1251112511
describe("when evaluating code containing /*global */ and /*globals */ blocks", () => {
1251212512

12513+
/**
12514+
* Asserts the global variables in the provided code using the specified language options and data.
12515+
* @param {string} code The code to verify.
12516+
* @param {Object} languageOptions The language options to use.
12517+
* @param {Object} [data={}] Additional data for the assertion.
12518+
* @returns {void}
12519+
*/
12520+
function assertGlobalVariable(code, languageOptions, data = {}) {
12521+
let spy;
12522+
12523+
const config = {
12524+
plugins: {
12525+
test: {
12526+
rules: {
12527+
checker: {
12528+
create(context) {
12529+
spy = sinon.spy(node => {
12530+
const scope = context.sourceCode.getScope(node);
12531+
const g = getVariable(scope, data.name);
12532+
12533+
assert.strictEqual(g.name, data.name);
12534+
assert.strictEqual(g.writeable, data.writeable);
12535+
});
12536+
12537+
return { Program: spy };
12538+
}
12539+
}
12540+
}
12541+
}
12542+
},
12543+
rules: { "test/checker": "error" }
12544+
};
12545+
12546+
if (languageOptions !== void 0) {
12547+
config.languageOptions = languageOptions;
12548+
}
12549+
12550+
linter.verify(code, config);
12551+
assert(spy && spy.calledOnce);
12552+
12553+
}
12554+
1251312555
it("variables should be available in global scope", () => {
1251412556
const code = `
1251512557
/*global a b:true c:false d:readable e:writeable Math:off */
@@ -12570,6 +12612,15 @@ describe("Linter with FlatConfigArray", () => {
1257012612
linter.verify(code, config);
1257112613
assert(spy && spy.calledOnce);
1257212614
});
12615+
12616+
// https://github.com/eslint/eslint/issues/18363
12617+
it("not throw when defining a global named __defineSetter__", () => {
12618+
assertGlobalVariable("/*global __defineSetter__ */", {}, { name: "__defineSetter__", writeable: false });
12619+
assertGlobalVariable("/*global __defineSetter__ */", void 0, { name: "__defineSetter__", writeable: false });
12620+
assertGlobalVariable("/*global __defineSetter__ */", { globals: { __defineSetter__: "off" } }, { name: "__defineSetter__", writeable: false });
12621+
assertGlobalVariable("/*global __defineSetter__ */", { globals: { __defineSetter__: "writeable" } }, { name: "__defineSetter__", writeable: false });
12622+
assertGlobalVariable("/*global __defineSetter__:writeable */", {}, { name: "__defineSetter__", writeable: true });
12623+
});
1257312624
});
1257412625

1257512626
describe("when evaluating code containing a /*global */ block with sloppy whitespace", () => {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp