Skip to content

Commit 0c526fd

Browse files
Merge branch 'master' into release-4.1
2 parents f330161 + 7db9118 commit 0c526fd

File tree

51 files changed

+1707
-275
lines changed

Some content is hidden

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

51 files changed

+1707
-275
lines changed

package-lock.json

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

src/compiler/binder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2810,8 +2810,8 @@ namespace ts {
28102810
if (symbol) {
28112811
const isAlias = isAliasableExpression(node.right) && (isExportsIdentifier(node.left.expression) || isModuleExportsAccessExpression(node.left.expression));
28122812
const flags = isAlias ? SymbolFlags.Alias : SymbolFlags.Property | SymbolFlags.ExportValue;
2813-
const excludeFlags = isAlias ? SymbolFlags.AliasExcludes : SymbolFlags.None;
2814-
declareSymbol(symbol.exports!, symbol, node.left, flags, excludeFlags);
2813+
setParent(node.left, node);
2814+
declareSymbol(symbol.exports!, symbol, node.left, flags, SymbolFlags.None);
28152815
}
28162816
}
28172817

src/compiler/checker.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4311,6 +4311,9 @@ namespace ts {
43114311
approximateLength: 0
43124312
};
43134313
const resultingNode = cb(context);
4314+
if (context.truncating && context.flags & NodeBuilderFlags.NoTruncation) {
4315+
context.tracker?.reportTruncationError?.();
4316+
}
43144317
return context.encounteredError ? undefined : resultingNode;
43154318
}
43164319

@@ -6828,6 +6831,7 @@ namespace ts {
68286831
break;
68296832
case SyntaxKind.BinaryExpression:
68306833
case SyntaxKind.PropertyAccessExpression:
6834+
case SyntaxKind.ElementAccessExpression:
68316835
// Could be best encoded as though an export specifier or as though an export assignment
68326836
// If name is default or export=, do an export assignment
68336837
// Otherwise do an export specifier
@@ -13643,7 +13647,7 @@ namespace ts {
1364313647
return undefined;
1364413648
}
1364513649
const shouldIncludeUndefined =
13646-
compilerOptions.noUncheckedIndexSignatures &&
13650+
compilerOptions.noUncheckedIndexedAccess &&
1364713651
(accessFlags & (AccessFlags.Writing | AccessFlags.ExpressionPosition)) === AccessFlags.ExpressionPosition;
1364813652
if (accessNode && !isTypeAssignableToKind(indexType, TypeFlags.String | TypeFlags.Number)) {
1364913653
const indexNode = getIndexNodeForAccessExpression(accessNode);

src/compiler/core.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2272,4 +2272,14 @@ namespace ts {
22722272
export function padRight(s: string, length: number, padString: " " = " ") {
22732273
return length <= s.length ? s : s + padString.repeat(length - s.length);
22742274
}
2275+
2276+
export function takeWhile<T, U extends T>(array: readonly T[], predicate: (element: T) => element is U): U[];
2277+
export function takeWhile<T>(array: readonly T[], predicate: (element: T) => boolean): T[] {
2278+
const len = array.length;
2279+
let index = 0;
2280+
while (index < len && predicate(array[index])) {
2281+
index++;
2282+
}
2283+
return array.slice(0, index);
2284+
}
22752285
}

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4920,6 +4920,10 @@
49204920
"category": "Error",
49214921
"code": 7055
49224922
},
4923+
"The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.": {
4924+
"category": "Error",
4925+
"code": 7056
4926+
},
49234927

49244928
"You cannot rename this element.": {
49254929
"category": "Error",

src/compiler/moduleNameResolver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,15 +788,15 @@ namespace ts {
788788
}
789789

790790
function tryLoadModuleUsingPathsIfEligible(extensions: Extensions, moduleName: string, loader: ResolutionKindSpecificLoader, state: ModuleResolutionState) {
791-
const { baseUrl, paths, pathsBasePath } = state.compilerOptions;
791+
const { baseUrl, paths } = state.compilerOptions;
792792
if (paths && !pathIsRelative(moduleName)) {
793793
if (state.traceEnabled) {
794794
if (baseUrl) {
795795
trace(state.host, Diagnostics.baseUrl_option_is_set_to_0_using_this_value_to_resolve_non_relative_module_name_1, baseUrl, moduleName);
796796
}
797797
trace(state.host, Diagnostics.paths_option_is_specified_looking_for_a_pattern_to_match_module_name_0, moduleName);
798798
}
799-
const baseDirectory = baseUrl ?? Debug.checkDefined(pathsBasePath || state.host.getCurrentDirectory?.(), "Encountered 'paths' without a 'baseUrl', config file, or host 'getCurrentDirectory'.");
799+
const baseDirectory = getPathsBasePath(state.compilerOptions, state.host)!; // Always defined when 'paths' is defined
800800
return tryLoadModuleUsingPaths(extensions, moduleName, baseDirectory, paths, loader, /*onlyRecordFailures*/ false, state);
801801
}
802802
}

src/compiler/moduleSpecifiers.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ namespace ts.moduleSpecifiers {
8282
const info = getInfo(importingSourceFileName, host);
8383
const modulePaths = getAllModulePaths(importingSourceFileName, toFileName, host);
8484
return firstDefined(modulePaths, modulePath => tryGetModuleNameAsNodeModule(modulePath, info, host, compilerOptions)) ||
85-
getLocalModuleSpecifier(toFileName, info, compilerOptions, preferences);
85+
getLocalModuleSpecifier(toFileName, info, compilerOptions, host, preferences);
8686
}
8787

8888
/** Returns an import for each symlink and for the realpath. */
@@ -121,7 +121,7 @@ namespace ts.moduleSpecifiers {
121121
}
122122

123123
if (!specifier && !modulePath.isRedirect) {
124-
const local = getLocalModuleSpecifier(modulePath.path, info, compilerOptions, preferences);
124+
const local = getLocalModuleSpecifier(modulePath.path, info, compilerOptions, host, preferences);
125125
if (pathIsBareSpecifier(local)) {
126126
pathsSpecifiers = append(pathsSpecifiers, local);
127127
}
@@ -156,16 +156,17 @@ namespace ts.moduleSpecifiers {
156156
return { getCanonicalFileName, sourceDirectory };
157157
}
158158

159-
function getLocalModuleSpecifier(moduleFileName: string, { getCanonicalFileName, sourceDirectory }: Info, compilerOptions: CompilerOptions, { ending, relativePreference }: Preferences): string {
159+
function getLocalModuleSpecifier(moduleFileName: string, { getCanonicalFileName, sourceDirectory }: Info, compilerOptions: CompilerOptions, host: ModuleSpecifierResolutionHost, { ending, relativePreference }: Preferences): string {
160160
const { baseUrl, paths, rootDirs, bundledPackageName } = compilerOptions;
161161

162162
const relativePath = rootDirs && tryGetModuleNameFromRootDirs(rootDirs, moduleFileName, sourceDirectory, getCanonicalFileName, ending, compilerOptions) ||
163163
removeExtensionAndIndexPostFix(ensurePathIsNonModuleName(getRelativePathFromDirectory(sourceDirectory, moduleFileName, getCanonicalFileName)), ending, compilerOptions);
164-
if (!baseUrl || relativePreference === RelativePreference.Relative) {
164+
if (!baseUrl && !paths || relativePreference === RelativePreference.Relative) {
165165
return relativePath;
166166
}
167167

168-
const relativeToBaseUrl = getRelativePathIfInDirectory(moduleFileName, baseUrl, getCanonicalFileName);
168+
const baseDirectory = getPathsBasePath(compilerOptions, host) || baseUrl!;
169+
const relativeToBaseUrl = getRelativePathIfInDirectory(moduleFileName, baseDirectory, getCanonicalFileName);
169170
if (!relativeToBaseUrl) {
170171
return relativePath;
171172
}

src/compiler/transformers/declarations.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ namespace ts {
7373
reportCyclicStructureError,
7474
reportPrivateInBaseOfClassExpression,
7575
reportLikelyUnsafeImportRequiredError,
76+
reportTruncationError,
7677
moduleResolverHost: host,
7778
trackReferencedAmbientModule,
7879
trackExternalModuleSymbolOfImportTypeNode,
@@ -197,6 +198,12 @@ namespace ts {
197198
}
198199
}
199200

201+
function reportTruncationError() {
202+
if (errorNameNode) {
203+
context.addDiagnostic(createDiagnosticForNode(errorNameNode, Diagnostics.The_inferred_type_of_this_node_exceeds_the_maximum_length_the_compiler_will_serialize_An_explicit_type_annotation_is_needed));
204+
}
205+
}
206+
200207
function reportNonlocalAugmentation(containingFile: SourceFile, parentSymbol: Symbol, symbol: Symbol) {
201208
const primaryDeclaration = find(parentSymbol.declarations, d => getSourceFileOfNode(d) === containingFile)!;
202209
const augmentingDeclarations = filter(symbol.declarations, d => getSourceFileOfNode(d) !== containingFile);

src/compiler/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5783,7 +5783,7 @@ namespace ts {
57835783
assumeChangesOnlyAffectDirectDependencies?: boolean;
57845784
noLib?: boolean;
57855785
noResolve?: boolean;
5786-
noUncheckedIndexSignatures?: boolean;
5786+
noUncheckedIndexedAccess?: boolean;
57875787
out?: string;
57885788
outDir?: string;
57895789
outFile?: string;
@@ -7867,6 +7867,7 @@ namespace ts {
78677867
reportInaccessibleUniqueSymbolError?(): void;
78687868
reportCyclicStructureError?(): void;
78697869
reportLikelyUnsafeImportRequiredError?(specifier: string): void;
7870+
reportTruncationError?(): void;
78707871
moduleResolverHost?: ModuleSpecifierResolutionHost & { getCommonSourceDirectory(): string };
78717872
trackReferencedAmbientModule?(decl: ModuleDeclaration, symbol: Symbol): void;
78727873
trackExternalModuleSymbolOfImportTypeNode?(symbol: Symbol): void;

src/compiler/utilities.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4087,6 +4087,12 @@ namespace ts {
40874087
return options.outFile || options.out;
40884088
}
40894089

4090+
/** Returns 'undefined' if and only if 'options.paths' is undefined. */
4091+
export function getPathsBasePath(options: CompilerOptions, host: { getCurrentDirectory?(): string }) {
4092+
if (!options.paths) return undefined;
4093+
return options.baseUrl ?? Debug.checkDefined(options.pathsBasePath || host.getCurrentDirectory?.(), "Encountered 'paths' without a 'baseUrl', config file, or host 'getCurrentDirectory'.");
4094+
}
4095+
40904096
export interface EmitFileNames {
40914097
jsFilePath?: string | undefined;
40924098
sourceMapFilePath?: string | undefined;

0 commit comments

Comments
 (0)