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

fix(scope-manager): reconcile type-value distinction for implicit globals across libs#11715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
lilnasy wants to merge2 commits intotypescript-eslint:main
base:main
Choose a base branch
Loading
fromlilnasy:main
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletionspackages/scope-manager/src/scope/ScopeBase.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,6 +21,7 @@ import {
} from '../referencer/Reference';
import { Variable } from '../variable';
import { ScopeType } from './ScopeType';
import { ImplicitLibVariable } from '../variable/ImplicitLibVariable';

/**
* Test if scope is strict
Expand DownExpand Up@@ -325,6 +326,11 @@ export abstract class ScopeBase<
}
// variable exists on the scope

// implicit lib variables should always be resolved statically
if (variable instanceof ImplicitLibVariable) {
return true;
}

// in module mode, we can statically resolve everything, regardless of its decl type
if (scopeManager.isModule()) {
return true;
Expand DownExpand Up@@ -390,6 +396,12 @@ export abstract class ScopeBase<
: nameOrVariable;
set.set(name, variable);
variables.push(variable);
} else if (
variable instanceof ImplicitLibVariable &&
nameOrVariable instanceof ImplicitLibVariable
) {
variable.isTypeVariable ||= nameOrVariable.isTypeVariable;
variable.isValueVariable ||= nameOrVariable.isValueVariable;
}

if (def) {
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,12 +25,12 @@ export class ImplicitLibVariable
/**
* `true` if the variable is valid in a type context, false otherwise
*/
publicreadonlyisTypeVariable: boolean;
public isTypeVariable: boolean;

/**
* `true` if the variable is valid in a value context, false otherwise
*/
publicreadonlyisValueVariable: boolean;
public isValueVariable: boolean;

public constructor(
scope: Scope,
Expand Down
28 changes: 28 additions & 0 deletionspackages/scope-manager/tests/lib.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -126,4 +126,32 @@ describe('implicit lib definitions', () => {
});
}).toThrow('invalid+lib');
});

it('should merge duplicate variable definitions with different properties', () => {
// taken from https://github.com/eslint/eslint/pull/19695/files#diff-a82bd73f60a34f613614f30df6bbb802c8d9294735b8f9ffe8e7a8ce5d51629aR3841
const { scopeManager } = parseAndAnalyze(
'Object; Boolean; String; Math; Date; Array; Map; Set;',
{
lib: ['es2015'],
},
);

const variables = scopeManager.variables;
const globalVariables = variables.filter(
v =>
v.name === 'Object' ||
v.name === 'Boolean' ||
v.name === 'String' ||
v.name === 'Math' ||
v.name === 'Date' ||
v.name === 'Array' ||
v.name === 'Map' ||
v.name === 'Set',
);
expect(globalVariables).toHaveLength(8);

for (const globalVariable of globalVariables) {
expect(globalVariable.references).toHaveLength(1);
}
});
});
Loading

[8]ページ先頭

©2009-2025 Movatter.jp