Skip to content

Commit 5a8176e

Browse files
Merge remote-tracking branch 'origin/master' into release-3.4
2 parents 60df864 + 0f598db commit 5a8176e

File tree

69 files changed

+629
-155
lines changed

Some content is hidden

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

69 files changed

+629
-155
lines changed

src/compiler/builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ namespace ts {
980980
backupState: noop,
981981
restoreState: noop,
982982
getProgram: notImplemented,
983-
getProgramOrUndefined: () => undefined,
983+
getProgramOrUndefined: returnUndefined,
984984
releaseProgram: noop,
985985
getCompilerOptions: () => state.compilerOptions,
986986
getSourceFile: notImplemented,

src/compiler/checker.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16936,6 +16936,7 @@ namespace ts {
1693616936
function checkNestedBlockScopedBinding(node: Identifier, symbol: Symbol): void {
1693716937
if (languageVersion >= ScriptTarget.ES2015 ||
1693816938
(symbol.flags & (SymbolFlags.BlockScopedVariable | SymbolFlags.Class)) === 0 ||
16939+
isSourceFile(symbol.valueDeclaration) ||
1693916940
symbol.valueDeclaration.parent.kind === SyntaxKind.CatchClause) {
1694016941
return;
1694116942
}
@@ -26911,7 +26912,7 @@ namespace ts {
2691126912
// If the function has a return type, but promisedType is
2691226913
// undefined, an error will be reported in checkAsyncFunctionReturnType
2691326914
// so we don't need to report one here.
26914-
checkTypeAssignableTo(awaitedType, promisedType, node);
26915+
checkTypeAssignableToAndOptionallyElaborate(awaitedType, promisedType, node, node.expression);
2691526916
}
2691626917
}
2691726918
else {
@@ -29594,7 +29595,7 @@ namespace ts {
2959429595
}
2959529596

2959629597
function isSymbolOfDeclarationWithCollidingName(symbol: Symbol): boolean {
29597-
if (symbol.flags & SymbolFlags.BlockScoped) {
29598+
if (symbol.flags & SymbolFlags.BlockScoped && !isSourceFile(symbol.valueDeclaration)) {
2959829599
const links = getSymbolLinks(symbol);
2959929600
if (links.isDeclarationWithCollidingName === undefined) {
2960029601
const container = getEnclosingBlockScopeContainer(symbol.valueDeclaration);

src/compiler/core.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,6 +1614,9 @@ namespace ts {
16141614
/** Do nothing and return true */
16151615
export function returnTrue(): true { return true; }
16161616

1617+
/** Do nothing and return undefined */
1618+
export function returnUndefined(): undefined { return undefined; }
1619+
16171620
/** Returns its argument. */
16181621
export function identity<T>(x: T) { return x; }
16191622

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4927,7 +4927,7 @@
49274927
"category": "Message",
49284928
"code": 95074
49294929
},
4930-
"Convert to named parameters": {
4930+
"Convert parameters to destructured object": {
49314931
"category": "Message",
49324932
"code": 95075
49334933
}

src/compiler/emitter.ts

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,23 +135,34 @@ namespace ts {
135135
return configFile.options.rootDir || getDirectoryPath(Debug.assertDefined(configFile.options.configFilePath));
136136
}
137137

138+
function getOutputPathWithoutChangingExt(inputFileName: string, configFile: ParsedCommandLine, ignoreCase: boolean, outputDir: string | undefined) {
139+
return outputDir ?
140+
resolvePath(
141+
outputDir,
142+
getRelativePathFromDirectory(rootDirOfOptions(configFile), inputFileName, ignoreCase)
143+
) :
144+
inputFileName;
145+
}
146+
138147
/* @internal */
139148
export function getOutputDeclarationFileName(inputFileName: string, configFile: ParsedCommandLine, ignoreCase: boolean) {
140149
Debug.assert(!fileExtensionIs(inputFileName, Extension.Dts) && hasTSFileExtension(inputFileName));
141-
const relativePath = getRelativePathFromDirectory(rootDirOfOptions(configFile), inputFileName, ignoreCase);
142-
const outputPath = resolvePath(configFile.options.declarationDir || configFile.options.outDir || getDirectoryPath(Debug.assertDefined(configFile.options.configFilePath)), relativePath);
143-
return changeExtension(outputPath, Extension.Dts);
150+
return changeExtension(
151+
getOutputPathWithoutChangingExt(inputFileName, configFile, ignoreCase, configFile.options.declarationDir || configFile.options.outDir),
152+
Extension.Dts
153+
);
144154
}
145155

146156
function getOutputJSFileName(inputFileName: string, configFile: ParsedCommandLine, ignoreCase: boolean) {
147-
const relativePath = getRelativePathFromDirectory(rootDirOfOptions(configFile), inputFileName, ignoreCase);
148-
const outputPath = resolvePath(configFile.options.outDir || getDirectoryPath(Debug.assertDefined(configFile.options.configFilePath)), relativePath);
149157
const isJsonFile = fileExtensionIs(inputFileName, Extension.Json);
150-
const outputFileName = changeExtension(outputPath, isJsonFile ?
151-
Extension.Json :
152-
fileExtensionIs(inputFileName, Extension.Tsx) && configFile.options.jsx === JsxEmit.Preserve ?
153-
Extension.Jsx :
154-
Extension.Js);
158+
const outputFileName = changeExtension(
159+
getOutputPathWithoutChangingExt(inputFileName, configFile, ignoreCase, configFile.options.outDir),
160+
isJsonFile ?
161+
Extension.Json :
162+
fileExtensionIs(inputFileName, Extension.Tsx) && configFile.options.jsx === JsxEmit.Preserve ?
163+
Extension.Jsx :
164+
Extension.Js
165+
);
155166
return !isJsonFile || comparePaths(inputFileName, outputFileName, Debug.assertDefined(configFile.options.configFilePath), ignoreCase) !== Comparison.EqualTo ?
156167
outputFileName :
157168
undefined;
@@ -203,6 +214,8 @@ namespace ts {
203214
const jsFilePath = getOutputJSFileName(inputFileName, configFile, ignoreCase);
204215
if (jsFilePath) return jsFilePath;
205216
}
217+
const buildInfoPath = getOutputPathForBuildInfo(configFile.options);
218+
if (buildInfoPath) return buildInfoPath;
206219
return Debug.fail(`project ${configFile.options.configFilePath} expected to have at least one output`);
207220
}
208221

@@ -665,11 +678,12 @@ namespace ts {
665678
getCompilerOptions: () => config.options,
666679
getCurrentDirectory: () => host.getCurrentDirectory(),
667680
getNewLine: () => host.getNewLine(),
668-
getSourceFile: () => undefined,
669-
getSourceFileByPath: () => undefined,
681+
getSourceFile: returnUndefined,
682+
getSourceFileByPath: returnUndefined,
670683
getSourceFiles: () => sourceFilesForJsEmit,
671684
getLibFileFromReference: notImplemented,
672685
isSourceFileFromExternalLibrary: returnFalse,
686+
getResolvedProjectReferenceToRedirect: returnUndefined,
673687
writeFile: (name, text, writeByteOrderMark) => {
674688
switch (name) {
675689
case jsFilePath:
@@ -706,7 +720,7 @@ namespace ts {
706720
fileExists: f => host.fileExists(f),
707721
directoryExists: host.directoryExists && (f => host.directoryExists!(f)),
708722
useCaseSensitiveFileNames: () => host.useCaseSensitiveFileNames(),
709-
getProgramBuildInfo: () => undefined
723+
getProgramBuildInfo: returnUndefined
710724
};
711725
emitFiles(notImplementedResolver, emitHost, /*targetSourceFile*/ undefined, /*emitOnlyDtsFiles*/ false, getTransformers(config.options));
712726
return outputFiles;

src/compiler/factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3405,7 +3405,7 @@ namespace ts {
34053405
export const nullTransformationContext: TransformationContext = {
34063406
enableEmitNotification: noop,
34073407
enableSubstitution: noop,
3408-
endLexicalEnvironment: () => undefined,
3408+
endLexicalEnvironment: returnUndefined,
34093409
getCompilerOptions: notImplemented,
34103410
getEmitHost: notImplemented,
34113411
getEmitResolver: notImplemented,

src/compiler/program.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ namespace ts {
979979

980980
function getCommonSourceDirectory() {
981981
if (commonSourceDirectory === undefined) {
982-
const emittedFiles = filter(files, file => sourceFileMayBeEmitted(file, options, isSourceFileFromExternalLibrary));
982+
const emittedFiles = filter(files, file => sourceFileMayBeEmitted(file, options, isSourceFileFromExternalLibrary, getResolvedProjectReferenceToRedirect));
983983
if (options.rootDir && checkSourceFilesBelongToPath(emittedFiles, options.rootDir)) {
984984
// If a rootDir is specified use it as the commonSourceDirectory
985985
commonSourceDirectory = getNormalizedAbsolutePath(options.rootDir, currentDirectory);
@@ -1425,6 +1425,7 @@ namespace ts {
14251425
getSourceFiles: program.getSourceFiles,
14261426
getLibFileFromReference: program.getLibFileFromReference,
14271427
isSourceFileFromExternalLibrary,
1428+
getResolvedProjectReferenceToRedirect,
14281429
writeFile: writeFileCallback || (
14291430
(fileName, data, writeByteOrderMark, onError, sourceFiles) => host.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles)),
14301431
isEmitBlocked,
@@ -2740,13 +2741,14 @@ namespace ts {
27402741

27412742
// List of collected files is complete; validate exhautiveness if this is a project with a file list
27422743
if (options.composite) {
2743-
const sourceFiles = files.filter(f => !f.isDeclarationFile);
2744-
if (rootNames.length < sourceFiles.length) {
2745-
const normalizedRootNames = rootNames.map(r => normalizePath(r).toLowerCase());
2746-
for (const file of sourceFiles.map(f => normalizePath(f.path).toLowerCase())) {
2747-
if (normalizedRootNames.indexOf(file) === -1) {
2748-
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.File_0_is_not_in_project_file_list_Projects_must_list_all_files_or_use_an_include_pattern, file));
2749-
}
2744+
const rootPaths = rootNames.map(toPath);
2745+
for (const file of files) {
2746+
// Ignore declaration files
2747+
if (file.isDeclarationFile) continue;
2748+
// Ignore json file thats from project reference
2749+
if (isJsonSourceFile(file) && getResolvedProjectReferenceToRedirect(file.fileName)) continue;
2750+
if (rootPaths.indexOf(file.path) === -1) {
2751+
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.File_0_is_not_in_project_file_list_Projects_must_list_all_files_or_use_an_include_pattern, file.fileName));
27502752
}
27512753
}
27522754
}
@@ -3158,7 +3160,7 @@ namespace ts {
31583160
readFile: f => directoryStructureHost.readFile(f),
31593161
useCaseSensitiveFileNames: host.useCaseSensitiveFileNames(),
31603162
getCurrentDirectory: () => host.getCurrentDirectory(),
3161-
onUnRecoverableConfigFileDiagnostic: host.onUnRecoverableConfigFileDiagnostic || (() => undefined),
3163+
onUnRecoverableConfigFileDiagnostic: host.onUnRecoverableConfigFileDiagnostic || returnUndefined,
31623164
trace: host.trace ? (s) => host.trace!(s) : undefined
31633165
};
31643166
}

src/compiler/tsbuild.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ namespace ts {
339339

340340
function createSolutionBuilderHostBase<T extends BuilderProgram>(system: System, createProgram: CreateProgram<T> | undefined, reportDiagnostic?: DiagnosticReporter, reportSolutionBuilderStatus?: DiagnosticReporter) {
341341
const host = createProgramHost(system, createProgram) as SolutionBuilderHostBase<T>;
342-
host.getModifiedTime = system.getModifiedTime ? path => system.getModifiedTime!(path) : () => undefined;
342+
host.getModifiedTime = system.getModifiedTime ? path => system.getModifiedTime!(path) : returnUndefined;
343343
host.setModifiedTime = system.setModifiedTime ? (path, date) => system.setModifiedTime!(path, date) : noop;
344344
host.deleteFile = system.deleteFile ? path => system.deleteFile!(path) : noop;
345345
host.reportDiagnostic = reportDiagnostic || createDiagnosticReporter(system);
@@ -660,15 +660,16 @@ namespace ts {
660660
}
661661
}
662662

663-
// Collect the expected outputs of this project
664-
const outputs = getAllProjectOutputs(project, !host.useCaseSensitiveFileNames());
665-
666-
if (outputs.length === 0) {
663+
// Container if no files are specified in the project
664+
if (!project.fileNames.length && !canJsonReportNoInutFiles(project.raw)) {
667665
return {
668666
type: UpToDateStatusType.ContainerOnly
669667
};
670668
}
671669

670+
// Collect the expected outputs of this project
671+
const outputs = getAllProjectOutputs(project, !host.useCaseSensitiveFileNames());
672+
672673
// Now see if all outputs are newer than the newest input
673674
let oldestOutputFileName = "(none)";
674675
let oldestOutputFileTime = maximumDate;

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5337,6 +5337,7 @@ namespace ts {
53375337
getCurrentDirectory(): string;
53385338

53395339
isSourceFileFromExternalLibrary(file: SourceFile): boolean;
5340+
getResolvedProjectReferenceToRedirect(fileName: string): ResolvedProjectReference | undefined;
53405341
getLibFileFromReference(ref: FileReference): SourceFile | undefined;
53415342

53425343
getCommonSourceDirectory(): string;

src/compiler/utilities.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3422,22 +3422,31 @@ namespace ts {
34223422
export function getSourceFilesToEmit(host: EmitHost, targetSourceFile?: SourceFile): ReadonlyArray<SourceFile> {
34233423
const options = host.getCompilerOptions();
34243424
const isSourceFileFromExternalLibrary = (file: SourceFile) => host.isSourceFileFromExternalLibrary(file);
3425+
const getResolvedProjectReferenceToRedirect = (fileName: string) => host.getResolvedProjectReferenceToRedirect(fileName);
34253426
if (options.outFile || options.out) {
34263427
const moduleKind = getEmitModuleKind(options);
34273428
const moduleEmitEnabled = options.emitDeclarationOnly || moduleKind === ModuleKind.AMD || moduleKind === ModuleKind.System;
34283429
// Can emit only sources that are not declaration file and are either non module code or module with --module or --target es6 specified
34293430
return filter(host.getSourceFiles(), sourceFile =>
3430-
(moduleEmitEnabled || !isExternalModule(sourceFile)) && sourceFileMayBeEmitted(sourceFile, options, isSourceFileFromExternalLibrary));
3431+
(moduleEmitEnabled || !isExternalModule(sourceFile)) && sourceFileMayBeEmitted(sourceFile, options, isSourceFileFromExternalLibrary, getResolvedProjectReferenceToRedirect));
34313432
}
34323433
else {
34333434
const sourceFiles = targetSourceFile === undefined ? host.getSourceFiles() : [targetSourceFile];
3434-
return filter(sourceFiles, sourceFile => sourceFileMayBeEmitted(sourceFile, options, isSourceFileFromExternalLibrary));
3435+
return filter(sourceFiles, sourceFile => sourceFileMayBeEmitted(sourceFile, options, isSourceFileFromExternalLibrary, getResolvedProjectReferenceToRedirect));
34353436
}
34363437
}
34373438

34383439
/** Don't call this for `--outFile`, just for `--outDir` or plain emit. `--outFile` needs additional checks. */
3439-
export function sourceFileMayBeEmitted(sourceFile: SourceFile, options: CompilerOptions, isSourceFileFromExternalLibrary: (file: SourceFile) => boolean) {
3440-
return !(options.noEmitForJsFiles && isSourceFileJS(sourceFile)) && !sourceFile.isDeclarationFile && !isSourceFileFromExternalLibrary(sourceFile);
3440+
export function sourceFileMayBeEmitted(
3441+
sourceFile: SourceFile,
3442+
options: CompilerOptions,
3443+
isSourceFileFromExternalLibrary: (file: SourceFile) => boolean,
3444+
getResolvedProjectReferenceToRedirect: (fileName: string) => ResolvedProjectReference | undefined
3445+
) {
3446+
return !(options.noEmitForJsFiles && isSourceFileJS(sourceFile)) &&
3447+
!sourceFile.isDeclarationFile &&
3448+
!isSourceFileFromExternalLibrary(sourceFile) &&
3449+
!(isJsonSourceFile(sourceFile) && getResolvedProjectReferenceToRedirect(sourceFile.fileName));
34413450
}
34423451

34433452
export function getSourceFilePathInNewDir(fileName: string, host: EmitHost, newDirPath: string): string {

src/harness/fakes.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,9 @@ namespace fakes {
476476
assertDiagnosticMessages(...expectedDiagnostics: ExpectedDiagnostic[]) {
477477
const actual = this.diagnostics.slice().map(d => d.messageText as string);
478478
const expected = expectedDiagnostics.map(expectedDiagnosticToText);
479-
assert.deepEqual(actual, expected, "Diagnostic arrays did not match");
479+
assert.deepEqual(actual, expected, `Diagnostic arrays did not match:
480+
Actual: ${JSON.stringify(actual, /*replacer*/ undefined, " ")}
481+
Expected: ${JSON.stringify(expected, /*replacer*/ undefined, " ")}`);
480482
}
481483

482484
printDiagnostics(header = "== Diagnostics ==") {

src/services/refactors/convertToNamedParameters.ts renamed to src/services/refactors/convertParamsToDestructuredObject.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* @internal */
2-
namespace ts.refactor.convertToNamedParameters {
3-
const refactorName = "Convert to named parameters";
2+
namespace ts.refactor.convertParamsToDestructuredObject {
3+
const refactorName = "Convert parameters to destructured object";
44
const minimumParameterLength = 2;
55
registerRefactor(refactorName, { getEditsForAction, getAvailableActions });
66

@@ -12,7 +12,7 @@ namespace ts.refactor.convertToNamedParameters {
1212
const functionDeclaration = getFunctionDeclarationAtPosition(file, startPosition, context.program.getTypeChecker());
1313
if (!functionDeclaration) return emptyArray;
1414

15-
const description = getLocaleSpecificMessage(Diagnostics.Convert_to_named_parameters);
15+
const description = getLocaleSpecificMessage(Diagnostics.Convert_parameters_to_destructured_object);
1616
return [{
1717
name: refactorName,
1818
description,

src/services/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"refactors/generateGetAccessorAndSetAccessor.ts",
8585
"refactors/moveToNewFile.ts",
8686
"refactors/addOrRemoveBracesToArrowFunction.ts",
87-
"refactors/convertToNamedParameters.ts",
87+
"refactors/convertParamsToDestructuredObject.ts",
8888
"services.ts",
8989
"breakpoints.ts",
9090
"transform.ts",

0 commit comments

Comments
 (0)