Skip to content

Commit dc19f47

Browse files
committed
Merge remote-tracking branch 'origin/main' into fix/string-completions-include-source-inferences
2 parents 39ddd44 + eadb9e1 commit dc19f47

File tree

50 files changed

+732
-104
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+732
-104
lines changed

.github/workflows/codeql.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646

4747
# Initializes the CodeQL tools for scanning.
4848
- name: Initialize CodeQL
49-
uses: github/codeql-action/init@429e1977040da7a23b6822b13c129cd1ba93dbb2 # v3.26.2
49+
uses: github/codeql-action/init@2c779ab0d087cd7fe7b826087247c2c81f27bfa6 # v3.26.5
5050
with:
5151
config-file: ./.github/codeql/codeql-configuration.yml
5252
# Override language selection by uncommenting this and choosing your languages
@@ -56,7 +56,7 @@ jobs:
5656
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
5757
# If this step fails, then you should remove it and run the build manually (see below).
5858
- name: Autobuild
59-
uses: github/codeql-action/autobuild@429e1977040da7a23b6822b13c129cd1ba93dbb2 # v3.26.2
59+
uses: github/codeql-action/autobuild@2c779ab0d087cd7fe7b826087247c2c81f27bfa6 # v3.26.5
6060

6161
# ℹ️ Command-line programs to run using the OS shell.
6262
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
@@ -70,4 +70,4 @@ jobs:
7070
# make release
7171

7272
- name: Perform CodeQL Analysis
73-
uses: github/codeql-action/analyze@429e1977040da7a23b6822b13c129cd1ba93dbb2 # v3.26.2
73+
uses: github/codeql-action/analyze@2c779ab0d087cd7fe7b826087247c2c81f27bfa6 # v3.26.5

.github/workflows/scorecard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ jobs:
5555

5656
# Upload the results to GitHub's code scanning dashboard.
5757
- name: 'Upload to code-scanning'
58-
uses: github/codeql-action/upload-sarif@429e1977040da7a23b6822b13c129cd1ba93dbb2 # v3.26.2
58+
uses: github/codeql-action/upload-sarif@2c779ab0d087cd7fe7b826087247c2c81f27bfa6 # v3.26.5
5959
with:
6060
sarif_file: results.sarif

src/compiler/checker.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22056,8 +22056,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2205622056
const [sourceType, targetType] = getTypeNamesForErrorDisplay(source, target);
2205722057
let generalizedSource = source;
2205822058
let generalizedSourceType = sourceType;
22059-
22060-
if (isLiteralType(source) && !typeCouldHaveTopLevelSingletonTypes(target)) {
22059+
22060+
// Don't generalize on 'never' - we really want the original type
22061+
// to be displayed for use-cases like 'assertNever'.
22062+
if (!(target.flags & TypeFlags.Never) && isLiteralType(source) && !typeCouldHaveTopLevelSingletonTypes(target)) {
2206122063
generalizedSource = getBaseTypeOfLiteralType(source);
2206222064
Debug.assert(!isTypeAssignableTo(generalizedSource, target), "generalized source shouldn't be assignable");
2206322065
generalizedSourceType = getTypeNameForErrorDisplay(generalizedSource);

src/compiler/commandLineParser.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3071,7 +3071,6 @@ function parseJsonConfigFileContentWorker(
30713071
validatedFilesSpecBeforeSubstitution,
30723072
validatedIncludeSpecsBeforeSubstitution,
30733073
validatedExcludeSpecsBeforeSubstitution,
3074-
pathPatterns: undefined, // Initialized on first use
30753074
isDefaultIncludeSpec,
30763075
};
30773076
}

src/compiler/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2414,7 +2414,7 @@ export function findBestPatternMatch<T>(values: readonly T[], getPattern: (value
24142414
for (let i = 0; i < values.length; i++) {
24152415
const v = values[i];
24162416
const pattern = getPattern(v);
2417-
if (isPatternMatch(pattern, candidate) && pattern.prefix.length > longestMatchPrefixLength) {
2417+
if (pattern.prefix.length > longestMatchPrefixLength && isPatternMatch(pattern, candidate)) {
24182418
longestMatchPrefixLength = pattern.prefix.length;
24192419
matchedValue = v;
24202420
}

src/compiler/moduleNameResolver.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ import {
7979
normalizeSlashes,
8080
PackageId,
8181
packageIdToString,
82+
ParsedPatterns,
8283
Path,
8384
pathIsRelative,
84-
Pattern,
8585
patternText,
8686
readJson,
8787
removeExtension,
@@ -1558,7 +1558,7 @@ function tryLoadModuleUsingOptionalResolutionSettings(extensions: Extensions, mo
15581558
}
15591559

15601560
function tryLoadModuleUsingPathsIfEligible(extensions: Extensions, moduleName: string, loader: ResolutionKindSpecificLoader, state: ModuleResolutionState) {
1561-
const { baseUrl, paths, configFile } = state.compilerOptions;
1561+
const { baseUrl, paths } = state.compilerOptions;
15621562
if (paths && !pathIsRelative(moduleName)) {
15631563
if (state.traceEnabled) {
15641564
if (baseUrl) {
@@ -1567,7 +1567,7 @@ function tryLoadModuleUsingPathsIfEligible(extensions: Extensions, moduleName: s
15671567
trace(state.host, Diagnostics.paths_option_is_specified_looking_for_a_pattern_to_match_module_name_0, moduleName);
15681568
}
15691569
const baseDirectory = getPathsBasePath(state.compilerOptions, state.host)!; // Always defined when 'paths' is defined
1570-
const pathPatterns = configFile?.configFileSpecs ? configFile.configFileSpecs.pathPatterns ||= tryParsePatterns(paths) : undefined;
1570+
const pathPatterns = tryParsePatterns(paths);
15711571
return tryLoadModuleUsingPaths(extensions, moduleName, baseDirectory, paths, pathPatterns, loader, /*onlyRecordFailures*/ false, state);
15721572
}
15731573
}
@@ -2518,7 +2518,8 @@ function loadNodeModuleFromDirectoryWorker(extensions: Extensions, candidate: st
25182518
if (state.traceEnabled) {
25192519
trace(state.host, Diagnostics.package_json_has_a_typesVersions_entry_0_that_matches_compiler_version_1_looking_for_a_pattern_to_match_module_name_2, versionPaths.version, version, moduleName);
25202520
}
2521-
const result = tryLoadModuleUsingPaths(extensions, moduleName, candidate, versionPaths.paths, /*pathPatterns*/ undefined, loader, onlyRecordFailuresForPackageFile || onlyRecordFailuresForIndex, state);
2521+
const pathPatterns = tryParsePatterns(versionPaths.paths);
2522+
const result = tryLoadModuleUsingPaths(extensions, moduleName, candidate, versionPaths.paths, pathPatterns, loader, onlyRecordFailuresForPackageFile || onlyRecordFailuresForIndex, state);
25222523
if (result) {
25232524
return removeIgnoredPackageId(result.value);
25242525
}
@@ -3112,16 +3113,16 @@ function loadModuleFromSpecificNodeModulesDirectory(extensions: Extensions, modu
31123113
trace(state.host, Diagnostics.package_json_has_a_typesVersions_entry_0_that_matches_compiler_version_1_looking_for_a_pattern_to_match_module_name_2, versionPaths.version, version, rest);
31133114
}
31143115
const packageDirectoryExists = nodeModulesDirectoryExists && directoryProbablyExists(packageDirectory, state.host);
3115-
const fromPaths = tryLoadModuleUsingPaths(extensions, rest, packageDirectory, versionPaths.paths, /*pathPatterns*/ undefined, loader, !packageDirectoryExists, state);
3116+
const pathPatterns = tryParsePatterns(versionPaths.paths);
3117+
const fromPaths = tryLoadModuleUsingPaths(extensions, rest, packageDirectory, versionPaths.paths, pathPatterns, loader, !packageDirectoryExists, state);
31163118
if (fromPaths) {
31173119
return fromPaths.value;
31183120
}
31193121
}
31203122
return loader(extensions, candidate, !nodeModulesDirectoryExists, state);
31213123
}
31223124

3123-
function tryLoadModuleUsingPaths(extensions: Extensions, moduleName: string, baseDirectory: string, paths: MapLike<string[]>, pathPatterns: readonly (string | Pattern)[] | undefined, loader: ResolutionKindSpecificLoader, onlyRecordFailures: boolean, state: ModuleResolutionState): SearchResult<Resolved> {
3124-
pathPatterns ||= tryParsePatterns(paths);
3125+
function tryLoadModuleUsingPaths(extensions: Extensions, moduleName: string, baseDirectory: string, paths: MapLike<string[]>, pathPatterns: ParsedPatterns, loader: ResolutionKindSpecificLoader, onlyRecordFailures: boolean, state: ModuleResolutionState): SearchResult<Resolved> {
31253126
const matchedPattern = matchPatternOrExact(pathPatterns, moduleName);
31263127
if (matchedPattern) {
31273128
const matchedStar = isString(matchedPattern) ? undefined : matchedText(matchedPattern, moduleName);

src/compiler/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7628,7 +7628,6 @@ export interface ConfigFileSpecs {
76287628
validatedFilesSpecBeforeSubstitution: readonly string[] | undefined;
76297629
validatedIncludeSpecsBeforeSubstitution: readonly string[] | undefined;
76307630
validatedExcludeSpecsBeforeSubstitution: readonly string[] | undefined;
7631-
pathPatterns: readonly (string | Pattern)[] | undefined;
76327631
isDefaultIncludeSpec: boolean;
76337632
}
76347633

src/compiler/utilities.ts

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9972,8 +9972,51 @@ export function tryParsePattern(pattern: string): string | Pattern | undefined {
99729972
}
99739973

99749974
/** @internal */
9975-
export function tryParsePatterns(paths: MapLike<string[]>): (string | Pattern)[] {
9976-
return mapDefined(getOwnKeys(paths), path => tryParsePattern(path));
9975+
export interface ParsedPatterns {
9976+
matchableStringSet: ReadonlySet<string> | undefined;
9977+
patterns: (readonly Pattern[]) | undefined;
9978+
}
9979+
9980+
const parsedPatternsCache = new WeakMap<MapLike<string[]>, ParsedPatterns>();
9981+
9982+
/**
9983+
* Divides patterns into a set of exact specifiers and patterns.
9984+
* NOTE that this function caches the result based on object identity.
9985+
*
9986+
* @internal
9987+
*/
9988+
export function tryParsePatterns(paths: MapLike<string[]>): ParsedPatterns {
9989+
let result = parsedPatternsCache.get(paths);
9990+
if (result !== undefined) {
9991+
return result;
9992+
}
9993+
9994+
let matchableStringSet: Set<string> | undefined;
9995+
let patterns: Pattern[] | undefined;
9996+
9997+
const pathList = getOwnKeys(paths);
9998+
for (const path of pathList) {
9999+
const patternOrStr = tryParsePattern(path);
10000+
if (patternOrStr === undefined) {
10001+
continue;
10002+
}
10003+
else if (typeof patternOrStr === "string") {
10004+
(matchableStringSet ??= new Set()).add(patternOrStr);
10005+
}
10006+
else {
10007+
(patterns ??= []).push(patternOrStr);
10008+
}
10009+
}
10010+
10011+
parsedPatternsCache.set(
10012+
paths,
10013+
result = {
10014+
matchableStringSet,
10015+
patterns,
10016+
},
10017+
);
10018+
10019+
return result;
997710020
}
997810021

997910022
/** @internal */
@@ -10030,22 +10073,21 @@ export const emptyFileSystemEntries: FileSystemEntries = {
1003010073
};
1003110074

1003210075
/**
10033-
* patternOrStrings contains both patterns (containing "*") and regular strings.
10076+
* `parsedPatterns` contains both patterns (containing "*") and regular strings.
1003410077
* Return an exact match if possible, or a pattern match, or undefined.
1003510078
* (These are verified by verifyCompilerOptions to have 0 or 1 "*" characters.)
1003610079
*
1003710080
* @internal
1003810081
*/
10039-
export function matchPatternOrExact(patternOrStrings: readonly (string | Pattern)[], candidate: string): string | Pattern | undefined {
10040-
const patterns: Pattern[] = [];
10041-
for (const patternOrString of patternOrStrings) {
10042-
if (patternOrString === candidate) {
10043-
return candidate;
10044-
}
10082+
export function matchPatternOrExact(parsedPatterns: ParsedPatterns, candidate: string): string | Pattern | undefined {
10083+
const { matchableStringSet, patterns } = parsedPatterns;
1004510084

10046-
if (!isString(patternOrString)) {
10047-
patterns.push(patternOrString);
10048-
}
10085+
if (matchableStringSet?.has(candidate)) {
10086+
return candidate;
10087+
}
10088+
10089+
if (patterns === undefined || patterns.length === 0) {
10090+
return undefined;
1004910091
}
1005010092

1005110093
return findBestPatternMatch(patterns, _ => _, candidate);

src/loc/lcl/chs/diagnosticMessages/diagnosticMessages.generated.json.lcl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,6 +1668,24 @@
16681668
</Str>
16691669
<Disp Icon="Str" />
16701670
</Item>
1671+
<Item ItemId=";Add_resolution_mode_import_attribute_95196" ItemType="0" PsrId="306" Leaf="true">
1672+
<Str Cat="Text">
1673+
<Val><![CDATA[Add 'resolution-mode' import attribute]]></Val>
1674+
<Tgt Cat="Text" Stat="Loc" Orig="New">
1675+
<Val><![CDATA[添加 "resolution-mode" 导入属性]]></Val>
1676+
</Tgt>
1677+
</Str>
1678+
<Disp Icon="Str" />
1679+
</Item>
1680+
<Item ItemId=";Add_resolution_mode_import_attribute_to_all_type_only_imports_that_need_it_95197" ItemType="0" PsrId="306" Leaf="true">
1681+
<Str Cat="Text">
1682+
<Val><![CDATA[Add 'resolution-mode' import attribute to all type-only imports that need it]]></Val>
1683+
<Tgt Cat="Text" Stat="Loc" Orig="New">
1684+
<Val><![CDATA[向所有需要 "resolution-mode" 导入属性的仅类型导入添加该属性]]></Val>
1685+
</Tgt>
1686+
</Str>
1687+
<Disp Icon="Str" />
1688+
</Item>
16711689
<Item ItemId=";Add_return_type_0_90063" ItemType="0" PsrId="306" Leaf="true">
16721690
<Str Cat="Text">
16731691
<Val><![CDATA[Add return type '{0}']]></Val>
@@ -16122,6 +16140,15 @@
1612216140
</Str>
1612316141
<Disp Icon="Str" />
1612416142
</Item>
16143+
<Item ItemId=";Type_import_of_an_ECMAScript_module_from_a_CommonJS_module_must_have_a_resolution_mode_attribute_1542" ItemType="0" PsrId="306" Leaf="true">
16144+
<Str Cat="Text">
16145+
<Val><![CDATA[Type import of an ECMAScript module from a CommonJS module must have a 'resolution-mode' attribute.]]></Val>
16146+
<Tgt Cat="Text" Stat="Loc" Orig="New">
16147+
<Val><![CDATA[从 CommonJS 模块导入 ECMAScript 模块的类型导入必须具有 "resolution-mode" 属性。]]></Val>
16148+
</Tgt>
16149+
</Str>
16150+
<Disp Icon="Str" />
16151+
</Item>
1612516152
<Item ItemId=";Type_instantiation_is_excessively_deep_and_possibly_infinite_2589" ItemType="0" PsrId="306" Leaf="true">
1612616153
<Str Cat="Text">
1612716154
<Val><![CDATA[Type instantiation is excessively deep and possibly infinite.]]></Val>
@@ -16212,6 +16239,15 @@
1621216239
</Str>
1621316240
<Disp Icon="Str" />
1621416241
</Item>
16242+
<Item ItemId=";Type_only_import_of_an_ECMAScript_module_from_a_CommonJS_module_must_have_a_resolution_mode_attribut_1541" ItemType="0" PsrId="306" Leaf="true">
16243+
<Str Cat="Text">
16244+
<Val><![CDATA[Type-only import of an ECMAScript module from a CommonJS module must have a 'resolution-mode' attribute.]]></Val>
16245+
<Tgt Cat="Text" Stat="Loc" Orig="New">
16246+
<Val><![CDATA[从 CommonJS 模块导入 ECMAScript 模块的仅类型导入必须具有 "resolution-mode" 属性。]]></Val>
16247+
</Tgt>
16248+
</Str>
16249+
<Disp Icon="Str" />
16250+
</Item>
1621516251
<Item ItemId=";Type_originates_at_this_import_A_namespace_style_import_cannot_be_called_or_constructed_and_will_cau_7038" ItemType="0" PsrId="306" Leaf="true">
1621616252
<Str Cat="Text">
1621716253
<Val><![CDATA[Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import require here instead.]]></Val>

src/loc/lcl/cht/diagnosticMessages/diagnosticMessages.generated.json.lcl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,6 +1668,24 @@
16681668
</Str>
16691669
<Disp Icon="Str" />
16701670
</Item>
1671+
<Item ItemId=";Add_resolution_mode_import_attribute_95196" ItemType="0" PsrId="306" Leaf="true">
1672+
<Str Cat="Text">
1673+
<Val><![CDATA[Add 'resolution-mode' import attribute]]></Val>
1674+
<Tgt Cat="Text" Stat="Loc" Orig="New">
1675+
<Val><![CDATA[新增 'resolution-mode' 匯入屬性]]></Val>
1676+
</Tgt>
1677+
</Str>
1678+
<Disp Icon="Str" />
1679+
</Item>
1680+
<Item ItemId=";Add_resolution_mode_import_attribute_to_all_type_only_imports_that_need_it_95197" ItemType="0" PsrId="306" Leaf="true">
1681+
<Str Cat="Text">
1682+
<Val><![CDATA[Add 'resolution-mode' import attribute to all type-only imports that need it]]></Val>
1683+
<Tgt Cat="Text" Stat="Loc" Orig="New">
1684+
<Val><![CDATA[將 'resolution-mode' 匯入屬性新增至所有需要該屬性的僅限類型匯入]]></Val>
1685+
</Tgt>
1686+
</Str>
1687+
<Disp Icon="Str" />
1688+
</Item>
16711689
<Item ItemId=";Add_return_type_0_90063" ItemType="0" PsrId="306" Leaf="true">
16721690
<Str Cat="Text">
16731691
<Val><![CDATA[Add return type '{0}']]></Val>
@@ -16122,6 +16140,15 @@
1612216140
</Str>
1612316141
<Disp Icon="Str" />
1612416142
</Item>
16143+
<Item ItemId=";Type_import_of_an_ECMAScript_module_from_a_CommonJS_module_must_have_a_resolution_mode_attribute_1542" ItemType="0" PsrId="306" Leaf="true">
16144+
<Str Cat="Text">
16145+
<Val><![CDATA[Type import of an ECMAScript module from a CommonJS module must have a 'resolution-mode' attribute.]]></Val>
16146+
<Tgt Cat="Text" Stat="Loc" Orig="New">
16147+
<Val><![CDATA[從 CommonJS 模組匯入 ECMAScript 模組的類型必須有 'resolution-mode' 屬性。]]></Val>
16148+
</Tgt>
16149+
</Str>
16150+
<Disp Icon="Str" />
16151+
</Item>
1612516152
<Item ItemId=";Type_instantiation_is_excessively_deep_and_possibly_infinite_2589" ItemType="0" PsrId="306" Leaf="true">
1612616153
<Str Cat="Text">
1612716154
<Val><![CDATA[Type instantiation is excessively deep and possibly infinite.]]></Val>
@@ -16212,6 +16239,15 @@
1621216239
</Str>
1621316240
<Disp Icon="Str" />
1621416241
</Item>
16242+
<Item ItemId=";Type_only_import_of_an_ECMAScript_module_from_a_CommonJS_module_must_have_a_resolution_mode_attribut_1541" ItemType="0" PsrId="306" Leaf="true">
16243+
<Str Cat="Text">
16244+
<Val><![CDATA[Type-only import of an ECMAScript module from a CommonJS module must have a 'resolution-mode' attribute.]]></Val>
16245+
<Tgt Cat="Text" Stat="Loc" Orig="New">
16246+
<Val><![CDATA[從 CommonJS 模組進行僅限類型匯入 ECMAScript 模組時,必須有 'resolution-mode' 屬性。]]></Val>
16247+
</Tgt>
16248+
</Str>
16249+
<Disp Icon="Str" />
16250+
</Item>
1621516251
<Item ItemId=";Type_originates_at_this_import_A_namespace_style_import_cannot_be_called_or_constructed_and_will_cau_7038" ItemType="0" PsrId="306" Leaf="true">
1621616252
<Str Cat="Text">
1621716253
<Val><![CDATA[Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import require here instead.]]></Val>

0 commit comments

Comments
 (0)