Skip to content

Commit a26f634

Browse files
Merge remote-tracking branch 'origin/main' into release-4.9
2 parents 98652a3 + a455955 commit a26f634

File tree

45 files changed

+2417
-163
lines changed

Some content is hidden

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

45 files changed

+2417
-163
lines changed

.github/tsc.json

Lines changed: 0 additions & 18 deletions
This file was deleted.

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/compiler/checker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7280,6 +7280,7 @@ namespace ts {
72807280
&& symbol.escapedName !== InternalSymbolName.ExportEquals
72817281
&& !(symbol.flags & SymbolFlags.Prototype)
72827282
&& !(symbol.flags & SymbolFlags.Class)
7283+
&& !(symbol.flags & SymbolFlags.Method)
72837284
&& !isConstMergedWithNSPrintableAsSignatureMerge) {
72847285
if (propertyAsAlias) {
72857286
const createdExport = serializeMaybeAliasAssignment(symbol);

src/compiler/moduleNameResolver.ts

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2437,12 +2437,7 @@ namespace ts {
24372437
}
24382438
}
24392439

2440-
const { packageName, rest } = parsePackageName(moduleName);
24412440
const loader: ResolutionKindSpecificLoader = (extensions, candidate, onlyRecordFailures, state) => {
2442-
// package exports are higher priority than file/directory lookups (and, if there's exports present, blocks them)
2443-
if (packageInfo && packageInfo.contents.packageJsonContent.exports && state.features & NodeResolutionFeatures.Exports) {
2444-
return loadModuleFromExports(packageInfo, extensions, combinePaths(".", rest), state, cache, redirectedReference)?.value;
2445-
}
24462441
let pathAndExtension =
24472442
loadModuleFromFile(extensions, candidate, onlyRecordFailures, state) ||
24482443
loadNodeModuleFromDirectoryWorker(
@@ -2466,20 +2461,24 @@ namespace ts {
24662461
return withPackageId(packageInfo, pathAndExtension);
24672462
};
24682463

2469-
if (rest !== "") { // If "rest" is empty, we just did this search above.
2470-
const packageDirectory = combinePaths(nodeModulesDirectory, packageName);
2471-
2472-
// Don't use a "types" or "main" from here because we're not loading the root, but a subdirectory -- just here for the packageId and path mappings.
2464+
const { packageName, rest } = parsePackageName(moduleName);
2465+
const packageDirectory = combinePaths(nodeModulesDirectory, packageName);
2466+
if (rest !== "") {
2467+
// Previous `packageInfo` may have been from a nested package.json; ensure we have the one from the package root now.
24732468
packageInfo = getPackageJsonInfo(packageDirectory, !nodeModulesDirectoryExists, state);
2474-
if (packageInfo && packageInfo.contents.versionPaths) {
2475-
if (state.traceEnabled) {
2476-
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, packageInfo.contents.versionPaths.version, version, rest);
2477-
}
2478-
const packageDirectoryExists = nodeModulesDirectoryExists && directoryProbablyExists(packageDirectory, state.host);
2479-
const fromPaths = tryLoadModuleUsingPaths(extensions, rest, packageDirectory, packageInfo.contents.versionPaths.paths, /*pathPatterns*/ undefined, loader, !packageDirectoryExists, state);
2480-
if (fromPaths) {
2481-
return fromPaths.value;
2482-
}
2469+
}
2470+
// package exports are higher priority than file/directory/typesVersions lookups and (and, if there's exports present, blocks them)
2471+
if (packageInfo && packageInfo.contents.packageJsonContent.exports && state.features & NodeResolutionFeatures.Exports) {
2472+
return loadModuleFromExports(packageInfo, extensions, combinePaths(".", rest), state, cache, redirectedReference)?.value;
2473+
}
2474+
if (rest !== "" && packageInfo && packageInfo.contents.versionPaths) {
2475+
if (state.traceEnabled) {
2476+
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, packageInfo.contents.versionPaths.version, version, rest);
2477+
}
2478+
const packageDirectoryExists = nodeModulesDirectoryExists && directoryProbablyExists(packageDirectory, state.host);
2479+
const fromPaths = tryLoadModuleUsingPaths(extensions, rest, packageDirectory, packageInfo.contents.versionPaths.paths, /*pathPatterns*/ undefined, loader, !packageDirectoryExists, state);
2480+
if (fromPaths) {
2481+
return fromPaths.value;
24832482
}
24842483
}
24852484

src/compiler/resolutionCache.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace ts {
1414
removeResolutionsOfFile(filePath: Path): void;
1515
removeResolutionsFromProjectReferenceRedirects(filePath: Path): void;
1616
setFilesWithInvalidatedNonRelativeUnresolvedImports(filesWithUnresolvedImports: ESMap<Path, readonly string[]>): void;
17-
createHasInvalidatedResolution(forceAllFilesAsInvalidated?: boolean): HasInvalidatedResolution;
17+
createHasInvalidatedResolution(customHasInvalidatedResolution: HasInvalidatedResolution): HasInvalidatedResolution;
1818
hasChangedAutomaticTypeDirectiveNames(): boolean;
1919
isFileWithInvalidatedNonRelativeUnresolvedImports(path: Path): boolean;
2020

@@ -300,17 +300,13 @@ namespace ts {
300300
return !!value && !!value.length;
301301
}
302302

303-
function createHasInvalidatedResolution(forceAllFilesAsInvalidated?: boolean): HasInvalidatedResolution {
303+
function createHasInvalidatedResolution(customHasInvalidatedResolution: HasInvalidatedResolution): HasInvalidatedResolution {
304304
// Ensure pending resolutions are applied
305305
invalidateResolutionsOfFailedLookupLocations();
306-
if (forceAllFilesAsInvalidated) {
307-
// Any file asked would have invalidated resolution
308-
filesWithInvalidatedResolutions = undefined;
309-
return returnTrue;
310-
}
311306
const collected = filesWithInvalidatedResolutions;
312307
filesWithInvalidatedResolutions = undefined;
313-
return path => (!!collected && collected.has(path)) ||
308+
return path => customHasInvalidatedResolution(path) ||
309+
!!collected?.has(path) ||
314310
isFileWithInvalidatedNonRelativeUnresolvedImports(path);
315311
}
316312

src/compiler/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7215,7 +7215,8 @@ namespace ts {
72157215
getEnvironmentVariable?(name: string): string | undefined;
72167216
/* @internal */ onReleaseOldSourceFile?(oldSourceFile: SourceFile, oldOptions: CompilerOptions, hasSourceFileByPath: boolean): void;
72177217
/* @internal */ onReleaseParsedCommandLine?(configFileName: string, oldResolvedRef: ResolvedProjectReference | undefined, optionOptions: CompilerOptions): void;
7218-
/* @internal */ hasInvalidatedResolution?: HasInvalidatedResolution;
7218+
/** If provided along with custom resolveModuleNames or resolveTypeReferenceDirectives, used to determine if unchanged file path needs to re-resolve modules/type reference directives */
7219+
hasInvalidatedResolution?(filePath: Path): boolean;
72197220
/* @internal */ hasChangedAutomaticTypeDirectiveNames?: HasChangedAutomaticTypeDirectiveNames;
72207221
createHash?(data: string): string;
72217222
getParsedCommandLine?(fileName: string): ParsedCommandLine | undefined;

src/compiler/watchPublic.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ namespace ts {
112112
resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingSourceFile?: SourceFile): (ResolvedModule | undefined)[];
113113
/** If provided, used to resolve type reference directives, otherwise typescript's default resolution */
114114
resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[] | readonly FileReference[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingFileMode?: SourceFile["impliedNodeFormat"] | undefined): (ResolvedTypeReferenceDirective | undefined)[];
115+
/** If provided along with custom resolveModuleNames or resolveTypeReferenceDirectives, used to determine if unchanged file path needs to re-resolve modules/type reference directives */
116+
hasInvalidatedResolution?(filePath: Path): boolean;
115117
/**
116118
* Returns the module resolution cache used by a provided `resolveModuleNames` implementation so that any non-name module resolution operations (eg, package.json lookup) can reuse it
117119
*/
@@ -371,6 +373,10 @@ namespace ts {
371373
maybeBind(host, host.getModuleResolutionCache) :
372374
(() => resolutionCache.getModuleResolutionCache());
373375
const userProvidedResolution = !!host.resolveModuleNames || !!host.resolveTypeReferenceDirectives;
376+
// All resolutions are invalid if user provided resolutions and didnt supply hasInvalidatedResolution
377+
const customHasInvalidatedResolution = userProvidedResolution ?
378+
maybeBind(host, host.hasInvalidatedResolution) || returnTrue :
379+
returnFalse;
374380

375381
builderProgram = readBuilderProgram(compilerOptions, compilerHost) as any as T;
376382
synchronizeProgram();
@@ -443,8 +449,7 @@ namespace ts {
443449
}
444450
}
445451

446-
// All resolutions are invalid if user provided resolutions
447-
const hasInvalidatedResolution = resolutionCache.createHasInvalidatedResolution(userProvidedResolution);
452+
const hasInvalidatedResolution = resolutionCache.createHasInvalidatedResolution(customHasInvalidatedResolution);
448453
const {
449454
originalReadFile, originalFileExists, originalDirectoryExists,
450455
originalCreateDirectory, originalWriteFile,

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

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13227,15 +13227,6 @@
1322713227
</Str>
1322813228
<Disp Icon="Str" />
1322913229
</Item>
13230-
<Item ItemId=";The_left_hand_side_of_an_in_expression_must_be_a_private_identifier_or_of_type_any_string_number_or__2360" ItemType="0" PsrId="306" Leaf="true">
13231-
<Str Cat="Text">
13232-
<Val><![CDATA[The left-hand side of an 'in' expression must be a private identifier or of type 'any', 'string', 'number', or 'symbol'.]]></Val>
13233-
<Tgt Cat="Text" Stat="Loc" Orig="New">
13234-
<Val><![CDATA["in" 表达式的左侧必须是专用标识符或其类型必须为 "any"、"string"、"number" 或 "symbol"。]]></Val>
13235-
</Tgt>
13236-
</Str>
13237-
<Disp Icon="Str" />
13238-
</Item>
1323913230
<Item ItemId=";The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_paramete_2358" ItemType="0" PsrId="306" Leaf="true">
1324013231
<Str Cat="Text">
1324113232
<Val><![CDATA[The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter.]]></Val>
@@ -13425,15 +13416,6 @@
1342513416
</Str>
1342613417
<Disp Icon="Str" />
1342713418
</Item>
13428-
<Item ItemId=";The_right_hand_side_of_an_in_expression_must_not_be_a_primitive_2361" ItemType="0" PsrId="306" Leaf="true">
13429-
<Str Cat="Text">
13430-
<Val><![CDATA[The right-hand side of an 'in' expression must not be a primitive.]]></Val>
13431-
<Tgt Cat="Text" Stat="Loc" Orig="New">
13432-
<Val><![CDATA["in" 表达式的右侧不得是基元。]]></Val>
13433-
</Tgt>
13434-
</Str>
13435-
<Disp Icon="Str" />
13436-
</Item>
1343713419
<Item ItemId=";The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_F_2359" ItemType="0" PsrId="306" Leaf="true">
1343813420
<Str Cat="Text">
1343913421
<Val><![CDATA[The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type.]]></Val>
@@ -13680,6 +13662,15 @@
1368013662
</Str>
1368113663
<Disp Icon="Str" />
1368213664
</Item>
13665+
<Item ItemId=";This_condition_will_always_return_0_2845" ItemType="0" PsrId="306" Leaf="true">
13666+
<Str Cat="Text">
13667+
<Val><![CDATA[This condition will always return '{0}'.]]></Val>
13668+
<Tgt Cat="Text" Stat="Loc" Orig="New">
13669+
<Val><![CDATA[此条件将始终返回“{0}”。]]></Val>
13670+
</Tgt>
13671+
</Str>
13672+
<Disp Icon="Str" />
13673+
</Item>
1368313674
<Item ItemId=";This_condition_will_always_return_0_since_JavaScript_compares_objects_by_reference_not_value_2839" ItemType="0" PsrId="306" Leaf="true">
1368413675
<Str Cat="Text">
1368513676
<Val><![CDATA[This condition will always return '{0}' since JavaScript compares objects by reference, not value.]]></Val>
@@ -14358,6 +14349,15 @@
1435814349
</Str>
1435914350
<Disp Icon="Str" />
1436014351
</Item>
14352+
<Item ItemId=";Type_0_may_represent_a_primitive_value_which_is_not_permitted_as_the_right_operand_of_the_in_operato_2638" ItemType="0" PsrId="306" Leaf="true">
14353+
<Str Cat="Text">
14354+
<Val><![CDATA[Type '{0}' may represent a primitive value, which is not permitted as the right operand of the 'in' operator.]]></Val>
14355+
<Tgt Cat="Text" Stat="Loc" Orig="New">
14356+
<Val><![CDATA[类型 "{0}" 可以表示基元值,该值不允许作为“in”运算符的右操作数。]]></Val>
14357+
</Tgt>
14358+
</Str>
14359+
<Disp Icon="Str" />
14360+
</Item>
1436114361
<Item ItemId=";Type_0_must_have_a_Symbol_asyncIterator_method_that_returns_an_async_iterator_2504" ItemType="0" PsrId="306" Leaf="true">
1436214362
<Str Cat="Text">
1436314363
<Val><![CDATA[Type '{0}' must have a '[Symbol.asyncIterator]5D;()' method that returns an async iterator.]]></Val>
@@ -15249,6 +15249,24 @@
1524915249
</Str>
1525015250
<Disp Icon="Str" />
1525115251
</Item>
15252+
<Item ItemId=";Use_0_95174" ItemType="0" PsrId="306" Leaf="true">
15253+
<Str Cat="Text">
15254+
<Val><![CDATA[Use `{0}`.]]></Val>
15255+
<Tgt Cat="Text" Stat="Loc" Orig="New">
15256+
<Val><![CDATA[使用 `{0}`]]></Val>
15257+
</Tgt>
15258+
</Str>
15259+
<Disp Icon="Str" />
15260+
</Item>
15261+
<Item ItemId=";Use_Number_isNaN_in_all_conditions_95175" ItemType="0" PsrId="306" Leaf="true">
15262+
<Str Cat="Text">
15263+
<Val><![CDATA[Use `Number.isNaN` in all conditions.]]></Val>
15264+
<Tgt Cat="Text" Stat="Loc" Orig="New">
15265+
<Val><![CDATA[在所有条件下使用 `Number.isNaN`。]]></Val>
15266+
</Tgt>
15267+
</Str>
15268+
<Disp Icon="Str" />
15269+
</Item>
1525215270
<Item ItemId=";Use_element_access_for_0_95145" ItemType="0" PsrId="306" Leaf="true">
1525315271
<Str Cat="Text">
1525415272
<Val><![CDATA[Use element access for '{0}']]></Val>

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13662,6 +13662,15 @@
1366213662
</Str>
1366313663
<Disp Icon="Str" />
1366413664
</Item>
13665+
<Item ItemId=";This_condition_will_always_return_0_2845" ItemType="0" PsrId="306" Leaf="true">
13666+
<Str Cat="Text">
13667+
<Val><![CDATA[This condition will always return '{0}'.]]></Val>
13668+
<Tgt Cat="Text" Stat="Loc" Orig="New">
13669+
<Val><![CDATA[此條件一律傳回 '{0}'。]]></Val>
13670+
</Tgt>
13671+
</Str>
13672+
<Disp Icon="Str" />
13673+
</Item>
1366513674
<Item ItemId=";This_condition_will_always_return_0_since_JavaScript_compares_objects_by_reference_not_value_2839" ItemType="0" PsrId="306" Leaf="true">
1366613675
<Str Cat="Text">
1366713676
<Val><![CDATA[This condition will always return '{0}' since JavaScript compares objects by reference, not value.]]></Val>
@@ -15240,6 +15249,24 @@
1524015249
</Str>
1524115250
<Disp Icon="Str" />
1524215251
</Item>
15252+
<Item ItemId=";Use_0_95174" ItemType="0" PsrId="306" Leaf="true">
15253+
<Str Cat="Text">
15254+
<Val><![CDATA[Use `{0}`.]]></Val>
15255+
<Tgt Cat="Text" Stat="Loc" Orig="New">
15256+
<Val><![CDATA[使用 `{0}`。]]></Val>
15257+
</Tgt>
15258+
</Str>
15259+
<Disp Icon="Str" />
15260+
</Item>
15261+
<Item ItemId=";Use_Number_isNaN_in_all_conditions_95175" ItemType="0" PsrId="306" Leaf="true">
15262+
<Str Cat="Text">
15263+
<Val><![CDATA[Use `Number.isNaN` in all conditions.]]></Val>
15264+
<Tgt Cat="Text" Stat="Loc" Orig="New">
15265+
<Val><![CDATA[在所有條件中都使用 'Number.isNaN'。]]></Val>
15266+
</Tgt>
15267+
</Str>
15268+
<Disp Icon="Str" />
15269+
</Item>
1524315270
<Item ItemId=";Use_element_access_for_0_95145" ItemType="0" PsrId="306" Leaf="true">
1524415271
<Str Cat="Text">
1524515272
<Val><![CDATA[Use element access for '{0}']]></Val>

0 commit comments

Comments
 (0)