Skip to content

Commit c0eb742

Browse files
committed
Merge branch 'master' into fixEmptyObjectFalsiness
2 parents 17080eb + 83fe1ea commit c0eb742

File tree

123 files changed

+13320
-10830
lines changed

Some content is hidden

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

123 files changed

+13320
-10830
lines changed

src/compiler/binder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2465,7 +2465,7 @@ namespace ts {
24652465
node.left.parent = node;
24662466
node.right.parent = node;
24672467
const lhs = node.left as PropertyAccessEntityNameExpression;
2468-
bindPropertyAssignment(lhs, lhs, /*isPrototypeProperty*/ false);
2468+
bindPropertyAssignment(lhs.expression, lhs, /*isPrototypeProperty*/ false);
24692469
}
24702470

24712471
/**
@@ -2522,7 +2522,7 @@ namespace ts {
25222522
const isToplevel = isBinaryExpression(propertyAccess.parent)
25232523
? getParentOfBinaryExpression(propertyAccess.parent).parent.kind === SyntaxKind.SourceFile
25242524
: propertyAccess.parent.parent.kind === SyntaxKind.SourceFile;
2525-
if (!isPrototypeProperty && (!namespaceSymbol || !(namespaceSymbol.flags & SymbolFlags.Namespace)) && isToplevel) {
2525+
if (isToplevel && !isPrototypeProperty && (!namespaceSymbol || !(namespaceSymbol.flags & SymbolFlags.Namespace))) {
25262526
// make symbols or add declarations for intermediate containers
25272527
const flags = SymbolFlags.Module | SymbolFlags.Assignment;
25282528
const excludeFlags = SymbolFlags.ValueModuleExcludes & ~SymbolFlags.Assignment;

src/compiler/builderState.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ namespace ts.BuilderState {
8888
function getReferencedFileFromImportedModuleSymbol(symbol: Symbol) {
8989
if (symbol.declarations && symbol.declarations[0]) {
9090
const declarationSourceFile = getSourceFileOfNode(symbol.declarations[0]);
91-
return declarationSourceFile && declarationSourceFile.path;
91+
return declarationSourceFile && (declarationSourceFile.resolvedPath || declarationSourceFile.path);
9292
}
9393
}
9494

@@ -100,6 +100,13 @@ namespace ts.BuilderState {
100100
return symbol && getReferencedFileFromImportedModuleSymbol(symbol);
101101
}
102102

103+
/**
104+
* Gets the path to reference file from file name, it could be resolvedPath if present otherwise path
105+
*/
106+
function getReferencedFileFromFileName(program: Program, fileName: string, sourceFileDirectory: Path, getCanonicalFileName: GetCanonicalFileName): Path {
107+
return toPath(program.getProjectReferenceRedirect(fileName) || fileName, sourceFileDirectory, getCanonicalFileName);
108+
}
109+
103110
/**
104111
* Gets the referenced files for a file from the program with values for the keys as referenced file's path to be true
105112
*/
@@ -123,7 +130,7 @@ namespace ts.BuilderState {
123130
// Handle triple slash references
124131
if (sourceFile.referencedFiles && sourceFile.referencedFiles.length > 0) {
125132
for (const referencedFile of sourceFile.referencedFiles) {
126-
const referencedPath = toPath(referencedFile.fileName, sourceFileDirectory, getCanonicalFileName);
133+
const referencedPath = getReferencedFileFromFileName(program, referencedFile.fileName, sourceFileDirectory, getCanonicalFileName);
127134
addReferencedFile(referencedPath);
128135
}
129136
}
@@ -136,7 +143,7 @@ namespace ts.BuilderState {
136143
}
137144

138145
const fileName = resolvedTypeReferenceDirective.resolvedFileName!; // TODO: GH#18217
139-
const typeFilePath = toPath(fileName, sourceFileDirectory, getCanonicalFileName);
146+
const typeFilePath = getReferencedFileFromFileName(program, fileName, sourceFileDirectory, getCanonicalFileName);
140147
addReferencedFile(typeFilePath);
141148
});
142149
}

src/compiler/checker.ts

Lines changed: 119 additions & 36 deletions
Large diffs are not rendered by default.

src/compiler/commandLineParser.ts

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ namespace ts {
172172
es2018: ScriptTarget.ES2018,
173173
esnext: ScriptTarget.ESNext,
174174
}),
175+
affectsSourceFile: true,
176+
affectsModuleResolution: true,
175177
paramType: Diagnostics.VERSION,
176178
showInSimplifiedHelpView: true,
177179
category: Diagnostics.Basic_Options,
@@ -190,6 +192,7 @@ namespace ts {
190192
es2015: ModuleKind.ES2015,
191193
esnext: ModuleKind.ESNext
192194
}),
195+
affectsModuleResolution: true,
193196
paramType: Diagnostics.KIND,
194197
showInSimplifiedHelpView: true,
195198
category: Diagnostics.Basic_Options,
@@ -202,13 +205,15 @@ namespace ts {
202205
name: "lib",
203206
type: libMap
204207
},
208+
affectsModuleResolution: true,
205209
showInSimplifiedHelpView: true,
206210
category: Diagnostics.Basic_Options,
207211
description: Diagnostics.Specify_library_files_to_be_included_in_the_compilation
208212
},
209213
{
210214
name: "allowJs",
211215
type: "boolean",
216+
affectsModuleResolution: true,
212217
showInSimplifiedHelpView: true,
213218
category: Diagnostics.Basic_Options,
214219
description: Diagnostics.Allow_javascript_files_to_be_compiled
@@ -226,6 +231,7 @@ namespace ts {
226231
"react-native": JsxEmit.ReactNative,
227232
"react": JsxEmit.React
228233
}),
234+
affectsSourceFile: true,
229235
paramType: Diagnostics.KIND,
230236
showInSimplifiedHelpView: true,
231237
category: Diagnostics.Basic_Options,
@@ -336,6 +342,7 @@ namespace ts {
336342
{
337343
name: "noImplicitAny",
338344
type: "boolean",
345+
affectsSemanticDiagnostics: true,
339346
strictFlag: true,
340347
showInSimplifiedHelpView: true,
341348
category: Diagnostics.Strict_Type_Checking_Options,
@@ -344,6 +351,7 @@ namespace ts {
344351
{
345352
name: "strictNullChecks",
346353
type: "boolean",
354+
affectsSemanticDiagnostics: true,
347355
strictFlag: true,
348356
showInSimplifiedHelpView: true,
349357
category: Diagnostics.Strict_Type_Checking_Options,
@@ -352,6 +360,7 @@ namespace ts {
352360
{
353361
name: "strictFunctionTypes",
354362
type: "boolean",
363+
affectsSemanticDiagnostics: true,
355364
strictFlag: true,
356365
showInSimplifiedHelpView: true,
357366
category: Diagnostics.Strict_Type_Checking_Options,
@@ -360,6 +369,7 @@ namespace ts {
360369
{
361370
name: "strictPropertyInitialization",
362371
type: "boolean",
372+
affectsSemanticDiagnostics: true,
363373
strictFlag: true,
364374
showInSimplifiedHelpView: true,
365375
category: Diagnostics.Strict_Type_Checking_Options,
@@ -368,6 +378,7 @@ namespace ts {
368378
{
369379
name: "noImplicitThis",
370380
type: "boolean",
381+
affectsSemanticDiagnostics: true,
371382
strictFlag: true,
372383
showInSimplifiedHelpView: true,
373384
category: Diagnostics.Strict_Type_Checking_Options,
@@ -376,6 +387,7 @@ namespace ts {
376387
{
377388
name: "alwaysStrict",
378389
type: "boolean",
390+
affectsSourceFile: true,
379391
strictFlag: true,
380392
showInSimplifiedHelpView: true,
381393
category: Diagnostics.Strict_Type_Checking_Options,
@@ -410,6 +422,7 @@ namespace ts {
410422
{
411423
name: "noFallthroughCasesInSwitch",
412424
type: "boolean",
425+
affectsBindDiagnostics: true,
413426
affectsSemanticDiagnostics: true,
414427
showInSimplifiedHelpView: true,
415428
category: Diagnostics.Additional_Checks,
@@ -423,13 +436,15 @@ namespace ts {
423436
node: ModuleResolutionKind.NodeJs,
424437
classic: ModuleResolutionKind.Classic,
425438
}),
439+
affectsModuleResolution: true,
426440
paramType: Diagnostics.STRATEGY,
427441
category: Diagnostics.Module_Resolution_Options,
428442
description: Diagnostics.Specify_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6,
429443
},
430444
{
431445
name: "baseUrl",
432446
type: "string",
447+
affectsModuleResolution: true,
433448
isFilePath: true,
434449
category: Diagnostics.Module_Resolution_Options,
435450
description: Diagnostics.Base_directory_to_resolve_non_absolute_module_names
@@ -439,6 +454,7 @@ namespace ts {
439454
// use type = object to copy the value as-is
440455
name: "paths",
441456
type: "object",
457+
affectsModuleResolution: true,
442458
isTSConfigOnly: true,
443459
category: Diagnostics.Module_Resolution_Options,
444460
description: Diagnostics.A_series_of_entries_which_re_map_imports_to_lookup_locations_relative_to_the_baseUrl
@@ -454,6 +470,7 @@ namespace ts {
454470
type: "string",
455471
isFilePath: true
456472
},
473+
affectsModuleResolution: true,
457474
category: Diagnostics.Module_Resolution_Options,
458475
description: Diagnostics.List_of_root_folders_whose_combined_content_represents_the_structure_of_the_project_at_runtime
459476
},
@@ -465,6 +482,7 @@ namespace ts {
465482
type: "string",
466483
isFilePath: true
467484
},
485+
affectsModuleResolution: true,
468486
category: Diagnostics.Module_Resolution_Options,
469487
description: Diagnostics.List_of_folders_to_include_type_definitions_from
470488
},
@@ -475,6 +493,7 @@ namespace ts {
475493
name: "types",
476494
type: "string"
477495
},
496+
affectsModuleResolution: true,
478497
showInSimplifiedHelpView: true,
479498
category: Diagnostics.Module_Resolution_Options,
480499
description: Diagnostics.Type_declaration_files_to_be_included_in_compilation
@@ -633,12 +652,14 @@ namespace ts {
633652
{
634653
name: "noLib",
635654
type: "boolean",
655+
affectsModuleResolution: true,
636656
category: Diagnostics.Advanced_Options,
637657
description: Diagnostics.Do_not_include_the_default_library_file_lib_d_ts
638658
},
639659
{
640660
name: "noResolve",
641661
type: "boolean",
662+
affectsModuleResolution: true,
642663
category: Diagnostics.Advanced_Options,
643664
description: Diagnostics.Do_not_add_triple_slash_references_or_imported_modules_to_the_list_of_compiled_files
644665
},
@@ -651,6 +672,7 @@ namespace ts {
651672
{
652673
name: "disableSizeLimit",
653674
type: "boolean",
675+
affectsSourceFile: true,
654676
category: Diagnostics.Advanced_Options,
655677
description: Diagnostics.Disable_size_limitations_on_JavaScript_projects
656678
},
@@ -696,13 +718,15 @@ namespace ts {
696718
{
697719
name: "allowUnusedLabels",
698720
type: "boolean",
721+
affectsBindDiagnostics: true,
699722
affectsSemanticDiagnostics: true,
700723
category: Diagnostics.Advanced_Options,
701724
description: Diagnostics.Do_not_report_errors_on_unused_labels
702725
},
703726
{
704727
name: "allowUnreachableCode",
705728
type: "boolean",
729+
affectsBindDiagnostics: true,
706730
affectsSemanticDiagnostics: true,
707731
category: Diagnostics.Advanced_Options,
708732
description: Diagnostics.Do_not_report_errors_on_unreachable_code
@@ -730,6 +754,7 @@ namespace ts {
730754
{
731755
name: "maxNodeModuleJsDepth",
732756
type: "number",
757+
// TODO: GH#27108 affectsModuleResolution: true,
733758
category: Diagnostics.Advanced_Options,
734759
description: Diagnostics.The_maximum_dependency_depth_to_search_under_node_modules_and_load_JavaScript_files
735760
},
@@ -759,6 +784,18 @@ namespace ts {
759784
}
760785
];
761786

787+
/* @internal */
788+
export const semanticDiagnosticsOptionDeclarations: ReadonlyArray<CommandLineOption> =
789+
optionDeclarations.filter(option => !!option.affectsSemanticDiagnostics);
790+
791+
/* @internal */
792+
export const moduleResolutionOptionDeclarations: ReadonlyArray<CommandLineOption> =
793+
optionDeclarations.filter(option => !!option.affectsModuleResolution);
794+
795+
/* @internal */
796+
export const sourceFileAffectingCompilerOptions: ReadonlyArray<CommandLineOption> = optionDeclarations.filter(option =>
797+
!!option.affectsSourceFile || !!option.affectsModuleResolution || !!option.affectsBindDiagnostics);
798+
762799
/* @internal */
763800
export const buildOpts: CommandLineOption[] = [
764801
...commonOptionsWithBuild,
@@ -1993,7 +2030,7 @@ namespace ts {
19932030
if (ownConfig.extendedConfigPath) {
19942031
// copy the resolution stack so it is never reused between branches in potential diamond-problem scenarios.
19952032
resolutionStack = resolutionStack.concat([resolvedPath]);
1996-
const extendedConfig = getExtendedConfig(sourceFile!, ownConfig.extendedConfigPath, host, basePath, resolutionStack, errors);
2033+
const extendedConfig = getExtendedConfig(sourceFile, ownConfig.extendedConfigPath, host, basePath, resolutionStack, errors);
19972034
if (extendedConfig && isSuccessfulParsedTsconfig(extendedConfig)) {
19982035
const baseRaw = extendedConfig.raw;
19992036
const raw = ownConfig.raw;
@@ -2134,7 +2171,7 @@ namespace ts {
21342171
}
21352172

21362173
function getExtendedConfig(
2137-
sourceFile: TsConfigSourceFile,
2174+
sourceFile: TsConfigSourceFile | undefined,
21382175
extendedConfigPath: string,
21392176
host: ParseConfigHost,
21402177
basePath: string,
@@ -2143,7 +2180,7 @@ namespace ts {
21432180
): ParsedTsconfig | undefined {
21442181
const extendedResult = readJsonConfigFile(extendedConfigPath, path => host.readFile(path));
21452182
if (sourceFile) {
2146-
(sourceFile.extendedSourceFiles || (sourceFile.extendedSourceFiles = [])).push(extendedResult.fileName);
2183+
sourceFile.extendedSourceFiles = [extendedResult.fileName];
21472184
}
21482185
if (extendedResult.parseDiagnostics.length) {
21492186
errors.push(...extendedResult.parseDiagnostics);
@@ -2153,8 +2190,8 @@ namespace ts {
21532190
const extendedDirname = getDirectoryPath(extendedConfigPath);
21542191
const extendedConfig = parseConfig(/*json*/ undefined, extendedResult, host, extendedDirname,
21552192
getBaseFileName(extendedConfigPath), resolutionStack, errors);
2156-
if (sourceFile) {
2157-
sourceFile.extendedSourceFiles!.push(...extendedResult.extendedSourceFiles!);
2193+
if (sourceFile && extendedResult.extendedSourceFiles) {
2194+
sourceFile.extendedSourceFiles!.push(...extendedResult.extendedSourceFiles);
21582195
}
21592196

21602197
if (isSuccessfulParsedTsconfig(extendedConfig)) {

src/compiler/core.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ namespace ts {
842842
return deduplicateSorted(sort(array, comparer), equalityComparer || comparer);
843843
}
844844

845-
export function arrayIsEqualTo<T>(array1: ReadonlyArray<T> | undefined, array2: ReadonlyArray<T> | undefined, equalityComparer: (a: T, b: T) => boolean = equateValues): boolean {
845+
export function arrayIsEqualTo<T>(array1: ReadonlyArray<T> | undefined, array2: ReadonlyArray<T> | undefined, equalityComparer: (a: T, b: T, index: number) => boolean = equateValues): boolean {
846846
if (!array1 || !array2) {
847847
return array1 === array2;
848848
}
@@ -852,7 +852,7 @@ namespace ts {
852852
}
853853

854854
for (let i = 0; i < array1.length; i++) {
855-
if (!equalityComparer(array1[i], array2[i])) {
855+
if (!equalityComparer(array1[i], array2[i], i)) {
856856
return false;
857857
}
858858
}

src/compiler/diagnosticMessages.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,6 +2112,10 @@
21122112
"category": "Error",
21132113
"code": 2585
21142114
},
2115+
"Enum type '{0}' circularly references itself.": {
2116+
"category": "Error",
2117+
"code": 2586
2118+
},
21152119
"JSX element attributes type '{0}' may not be a union type.": {
21162120
"category": "Error",
21172121
"code": 2600
@@ -3886,6 +3890,10 @@
38863890
"category": "Message",
38873891
"code": 6501
38883892
},
3893+
"The expected type comes from the return type of this signature.": {
3894+
"category": "Message",
3895+
"code": 6502
3896+
},
38893897

38903898
"Variable '{0}' implicitly has an '{1}' type.": {
38913899
"category": "Error",
@@ -4145,6 +4153,10 @@
41454153
"category": "Error",
41464154
"code": 8030
41474155
},
4156+
"You cannot rename a module via a global import.": {
4157+
"category": "Error",
4158+
"code": 8031
4159+
},
41484160
"Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clause.": {
41494161
"category": "Error",
41504162
"code": 9002

0 commit comments

Comments
 (0)