Skip to content

Commit 17d1a7e

Browse files
committed
Merge branch 'master' into infer-from-usage/similarity-to-builtins
2 parents 383286f + f41472b commit 17d1a7e

File tree

94 files changed

+3528
-1156
lines changed

Some content is hidden

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

94 files changed

+3528
-1156
lines changed

src/compiler/builder.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ namespace ts {
137137
*/
138138
emittedBuildInfo?: boolean;
139139
/**
140-
* Already seen affected files
140+
* Already seen emitted files
141141
*/
142142
seenEmittedFiles: Map<true> | undefined;
143143
/**
@@ -329,7 +329,6 @@ namespace ts {
329329
handleDtsMayChangeOfAffectedFile(state, affectedFile, cancellationToken, computeHash);
330330
return affectedFile;
331331
}
332-
seenAffectedFiles.set(affectedFile.path, true);
333332
affectedFilesIndex++;
334333
}
335334

@@ -549,7 +548,7 @@ namespace ts {
549548
* This is called after completing operation on the next affected file.
550549
* The operations here are postponed to ensure that cancellation during the iteration is handled correctly
551550
*/
552-
function doneWithAffectedFile(state: BuilderProgramState, affected: SourceFile | Program, isPendingEmit?: boolean, isBuildInfoEmit?: boolean) {
551+
function doneWithAffectedFile(state: BuilderProgramState, affected: SourceFile | Program, isPendingEmit?: boolean, isBuildInfoEmit?: boolean, isEmitResult?: boolean) {
553552
if (isBuildInfoEmit) {
554553
state.emittedBuildInfo = true;
555554
}
@@ -559,6 +558,9 @@ namespace ts {
559558
}
560559
else {
561560
state.seenAffectedFiles!.set((affected as SourceFile).path, true);
561+
if (isEmitResult) {
562+
(state.seenEmittedFiles || (state.seenEmittedFiles = createMap())).set((affected as SourceFile).path, true);
563+
}
562564
if (isPendingEmit) {
563565
state.affectedFilesPendingEmitIndex!++;
564566
}
@@ -576,6 +578,14 @@ namespace ts {
576578
return { result, affected };
577579
}
578580

581+
/**
582+
* Returns the result with affected file
583+
*/
584+
function toAffectedFileEmitResult(state: BuilderProgramState, result: EmitResult, affected: SourceFile | Program, isPendingEmit?: boolean, isBuildInfoEmit?: boolean): AffectedFileResult<EmitResult> {
585+
doneWithAffectedFile(state, affected, isPendingEmit, isBuildInfoEmit, /*isEmitResult*/ true);
586+
return { result, affected };
587+
}
588+
579589
/**
580590
* Gets the semantic diagnostics either from cache if present, or otherwise from program and caches it
581591
* Note that it is assumed that the when asked about semantic diagnostics, the file has been taken out of affected files/changed file set
@@ -849,7 +859,7 @@ namespace ts {
849859
}
850860

851861
const affected = Debug.assertDefined(state.program);
852-
return toAffectedFileResult(
862+
return toAffectedFileEmitResult(
853863
state,
854864
// When whole program is affected, do emit only once (eg when --out or --outFile is specified)
855865
// Otherwise just affected file
@@ -872,14 +882,14 @@ namespace ts {
872882
}
873883
}
874884

875-
return toAffectedFileResult(
885+
return toAffectedFileEmitResult(
876886
state,
877887
// When whole program is affected, do emit only once (eg when --out or --outFile is specified)
878888
// Otherwise just affected file
879889
Debug.assertDefined(state.program).emit(affected === state.program ? undefined : affected as SourceFile, writeFile || maybeBind(host, host.writeFile), cancellationToken, emitOnlyDtsFiles, customTransformers),
880890
affected,
881-
isPendingEmitFile
882-
);
891+
isPendingEmitFile,
892+
);
883893
}
884894

885895
/**
@@ -1036,7 +1046,7 @@ namespace ts {
10361046
compilerOptions: convertFromReusableCompilerOptions(program.options, toAbsolutePath),
10371047
referencedMap: getMapOfReferencedSet(program.referencedMap, toPath),
10381048
exportedModulesMap: getMapOfReferencedSet(program.exportedModulesMap, toPath),
1039-
semanticDiagnosticsPerFile: program.semanticDiagnosticsPerFile && arrayToMap(program.semanticDiagnosticsPerFile, value => isString(value) ? value : value[0], value => isString(value) ? emptyArray : value[1]),
1049+
semanticDiagnosticsPerFile: program.semanticDiagnosticsPerFile && arrayToMap(program.semanticDiagnosticsPerFile, value => toPath(isString(value) ? value : value[0]), value => isString(value) ? emptyArray : value[1]),
10401050
hasReusableDiagnostic: true
10411051
};
10421052
return {

src/compiler/builderState.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,13 @@ namespace ts.BuilderState {
345345
}
346346
else {
347347
const emitOutput = getFileEmitOutput(programOfThisState, sourceFile, /*emitOnlyDtsFiles*/ true, cancellationToken);
348-
if (emitOutput.outputFiles && emitOutput.outputFiles.length > 0) {
349-
latestSignature = computeHash(emitOutput.outputFiles[0].text);
348+
const firstDts = emitOutput.outputFiles &&
349+
programOfThisState.getCompilerOptions().declarationMap ?
350+
emitOutput.outputFiles.length > 1 ? emitOutput.outputFiles[1] : undefined :
351+
emitOutput.outputFiles.length > 0 ? emitOutput.outputFiles[0] : undefined;
352+
if (firstDts) {
353+
Debug.assert(fileExtensionIs(firstDts.name, Extension.Dts), "File extension for signature expected to be dts", () => `Found: ${getAnyExtensionFromPath(firstDts.name)} for ${firstDts.name}:: All output files: ${JSON.stringify(emitOutput.outputFiles.map(f => f.name))}`);
354+
latestSignature = computeHash(firstDts.text);
350355
if (exportedModulesMapCache && latestSignature !== prevSignature) {
351356
updateExportedModules(sourceFile, emitOutput.exportedModulesFromDeclarationEmit, exportedModulesMapCache);
352357
}

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3525,7 +3525,7 @@ namespace ts {
35253525
const sig = nodeBuilder.signatureToSignatureDeclaration(signature, sigOutput, enclosingDeclaration, toNodeBuilderFlags(flags) | NodeBuilderFlags.IgnoreErrors | NodeBuilderFlags.WriteTypeParametersInQualifiedName);
35263526
const printer = createPrinter({ removeComments: true, omitTrailingSemicolon: true });
35273527
const sourceFile = enclosingDeclaration && getSourceFileOfNode(enclosingDeclaration);
3528-
printer.writeNode(EmitHint.Unspecified, sig!, /*sourceFile*/ sourceFile, getTrailingSemicolonOmittingWriter(writer)); // TODO: GH#18217
3528+
printer.writeNode(EmitHint.Unspecified, sig!, /*sourceFile*/ sourceFile, getTrailingSemicolonDeferringWriter(writer)); // TODO: GH#18217
35293529
return writer;
35303530
}
35313531
}

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5120,6 +5120,10 @@
51205120
"category": "Message",
51215121
"code": 95089
51225122
},
5123+
"Extract to interface": {
5124+
"category": "Message",
5125+
"code": 95090
5126+
},
51235127

51245128
"No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": {
51255129
"category": "Error",

src/compiler/emitter.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ namespace ts {
155155
}
156156

157157
function getOutputJSFileName(inputFileName: string, configFile: ParsedCommandLine, ignoreCase: boolean) {
158+
if (configFile.options.emitDeclarationOnly) return undefined;
158159
const isJsonFile = fileExtensionIs(inputFileName, Extension.Json);
159160
const outputFileName = changeExtension(
160161
getOutputPathWithoutChangingExt(inputFileName, configFile, ignoreCase, configFile.options.outDir),
@@ -187,7 +188,7 @@ namespace ts {
187188
const js = getOutputJSFileName(inputFileName, configFile, ignoreCase);
188189
addOutput(js);
189190
if (fileExtensionIs(inputFileName, Extension.Json)) continue;
190-
if (configFile.options.sourceMap) {
191+
if (js && configFile.options.sourceMap) {
191192
addOutput(`${js}.map`);
192193
}
193194
if (getEmitDeclarations(configFile.options) && hasTSFileExtension(inputFileName)) {
@@ -214,6 +215,10 @@ namespace ts {
214215
if (fileExtensionIs(inputFileName, Extension.Dts)) continue;
215216
const jsFilePath = getOutputJSFileName(inputFileName, configFile, ignoreCase);
216217
if (jsFilePath) return jsFilePath;
218+
if (fileExtensionIs(inputFileName, Extension.Json)) continue;
219+
if (getEmitDeclarations(configFile.options) && hasTSFileExtension(inputFileName)) {
220+
return getOutputDeclarationFileName(inputFileName, configFile, ignoreCase);
221+
}
217222
}
218223
const buildInfoPath = getOutputPathForBuildInfo(configFile.options);
219224
if (buildInfoPath) return buildInfoPath;
@@ -1053,7 +1058,7 @@ namespace ts {
10531058

10541059
function setWriter(_writer: EmitTextWriter | undefined, _sourceMapGenerator: SourceMapGenerator | undefined) {
10551060
if (_writer && printerOptions.omitTrailingSemicolon) {
1056-
_writer = getTrailingSemicolonOmittingWriter(_writer);
1061+
_writer = getTrailingSemicolonDeferringWriter(_writer);
10571062
}
10581063

10591064
writer = _writer!; // TODO: GH#18217
@@ -2511,7 +2516,7 @@ namespace ts {
25112516
}
25122517

25132518
emitWhileClause(node, node.statement.end);
2514-
writePunctuation(";");
2519+
writeTrailingSemicolon();
25152520
}
25162521

25172522
function emitWhileStatement(node: WhileStatement) {

src/compiler/utilities.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3374,7 +3374,11 @@ namespace ts {
33743374
};
33753375
}
33763376

3377-
export function getTrailingSemicolonOmittingWriter(writer: EmitTextWriter): EmitTextWriter {
3377+
export interface TrailingSemicolonDeferringWriter extends EmitTextWriter {
3378+
resetPendingTrailingSemicolon(): void;
3379+
}
3380+
3381+
export function getTrailingSemicolonDeferringWriter(writer: EmitTextWriter): TrailingSemicolonDeferringWriter {
33783382
let pendingTrailingSemicolon = false;
33793383

33803384
function commitPendingTrailingSemicolon() {
@@ -3440,10 +3444,24 @@ namespace ts {
34403444
decreaseIndent() {
34413445
commitPendingTrailingSemicolon();
34423446
writer.decreaseIndent();
3447+
},
3448+
resetPendingTrailingSemicolon() {
3449+
pendingTrailingSemicolon = false;
34433450
}
34443451
};
34453452
}
34463453

3454+
export function getTrailingSemicolonOmittingWriter(writer: EmitTextWriter): EmitTextWriter {
3455+
const deferringWriter = getTrailingSemicolonDeferringWriter(writer);
3456+
return {
3457+
...deferringWriter,
3458+
writeLine() {
3459+
deferringWriter.resetPendingTrailingSemicolon();
3460+
writer.writeLine();
3461+
},
3462+
};
3463+
}
3464+
34473465
export function getResolvedExternalModuleName(host: EmitHost, file: SourceFile, referenceFile?: SourceFile): string {
34483466
return file.moduleName || getExternalModuleNameFromPath(host, file.fileName, referenceFile && referenceFile.fileName);
34493467
}

src/harness/fakes.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,10 @@ ${indentText}${text}`;
545545
super.writeFile(fileName, ts.getBuildInfoText(buildInfo), writeByteOrderMark);
546546
}
547547

548+
createHash(data: string) {
549+
return `${ts.generateDjb2Hash(data)}-${data}`;
550+
}
551+
548552
now() {
549553
return new Date(this.sys.vfs.time());
550554
}
@@ -571,6 +575,15 @@ Actual: ${JSON.stringify(actual, /*replacer*/ undefined, " ")}
571575
Expected: ${JSON.stringify(expected, /*replacer*/ undefined, " ")}`);
572576
}
573577

578+
assertErrors(...expectedDiagnostics: ExpectedErrorDiagnostic[]) {
579+
const actual = this.diagnostics.filter(d => d.kind === DiagnosticKind.Error).map(diagnosticToText);
580+
const expected = expectedDiagnostics.map(expectedDiagnosticToText);
581+
assert.deepEqual(actual, expected, `Diagnostics arrays did not match:
582+
Actual: ${JSON.stringify(actual, /*replacer*/ undefined, " ")}
583+
Expected: ${JSON.stringify(expected, /*replacer*/ undefined, " ")}
584+
Actual All:: ${JSON.stringify(this.diagnostics.slice().map(diagnosticToText), /*replacer*/ undefined, " ")}`);
585+
}
586+
574587
printDiagnostics(header = "== Diagnostics ==") {
575588
const out = ts.createDiagnosticReporter(ts.sys);
576589
ts.sys.write(header + "\r\n");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8197,7 +8197,7 @@
81978197
<Str Cat="Text">
81988198
<Val><![CDATA[The type argument for type parameter '{0}' cannot be inferred from the usage. Consider specifying the type arguments explicitly.]]></Val>
81998199
<Tgt Cat="Text" Stat="Loc" Orig="New">
8200-
<Val><![CDATA[형식 매개 변수 '{0}'의 형식 인수를 유추할 수 없습니다. 형식 인수를 명시적으로 지정하세요.]]></Val>
8200+
<Val><![CDATA[사용량에서 형식 매개 변수 '{0}'의 형식 인수를 유추할 수 없습니다. 형식 인수를 명시적으로 지정하세요.]]></Val>
82018201
</Tgt>
82028202
</Str>
82038203
<Disp Icon="Str" />

src/services/formatting/smartIndenter.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,10 +539,14 @@ namespace ts.formatting {
539539
return true;
540540
case SyntaxKind.VariableDeclaration:
541541
case SyntaxKind.PropertyAssignment:
542+
case SyntaxKind.BinaryExpression:
542543
if (!settings.indentMultiLineObjectLiteralBeginningOnBlankLine && sourceFile && childKind === SyntaxKind.ObjectLiteralExpression) { // TODO: GH#18217
543544
return rangeIsOnOneLine(sourceFile, child!);
544545
}
545-
return true;
546+
if (parent.kind !== SyntaxKind.BinaryExpression) {
547+
return true;
548+
}
549+
break;
546550
case SyntaxKind.DoStatement:
547551
case SyntaxKind.WhileStatement:
548552
case SyntaxKind.ForInStatement:

src/services/goToDefinition.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace ts.GoToDefinition {
3939
return [sigInfo];
4040
}
4141
else {
42-
const defs = getDefinitionFromSymbol(typeChecker, symbol, node) || emptyArray;
42+
const defs = getDefinitionFromSymbol(typeChecker, symbol, node, calledDeclaration) || emptyArray;
4343
// For a 'super()' call, put the signature first, else put the variable first.
4444
return node.kind === SyntaxKind.SuperKeyword ? [sigInfo, ...defs] : [...defs, sigInfo];
4545
}
@@ -232,10 +232,11 @@ namespace ts.GoToDefinition {
232232
}
233233
}
234234

235-
function getDefinitionFromSymbol(typeChecker: TypeChecker, symbol: Symbol, node: Node): DefinitionInfo[] | undefined {
235+
function getDefinitionFromSymbol(typeChecker: TypeChecker, symbol: Symbol, node: Node, declarationNode?: Node): DefinitionInfo[] | undefined {
236236
// There are cases when you extend a function by adding properties to it afterwards,
237-
// we want to strip those extra properties
238-
const filteredDeclarations = filter(symbol.declarations, d => !isAssignmentDeclaration(d) || d === symbol.valueDeclaration) || undefined;
237+
// we want to strip those extra properties.
238+
// For deduping purposes, we also want to exclude any declarationNodes if provided.
239+
const filteredDeclarations = filter(symbol.declarations, d => d !== declarationNode && (!isAssignmentDeclaration(d) || d === symbol.valueDeclaration)) || undefined;
239240
return getConstructSignatureDefinition() || getCallSignatureDefinition() || map(filteredDeclarations, declaration => createDefinitionInfo(declaration, typeChecker, symbol, node));
240241

241242
function getConstructSignatureDefinition(): DefinitionInfo[] | undefined {
@@ -258,8 +259,13 @@ namespace ts.GoToDefinition {
258259
return undefined;
259260
}
260261
const declarations = signatureDeclarations.filter(selectConstructors ? isConstructorDeclaration : isFunctionLike);
262+
const declarationsWithBody = declarations.filter(d => !!(<FunctionLikeDeclaration>d).body);
263+
264+
// declarations defined on the global scope can be defined on multiple files. Get all of them.
261265
return declarations.length
262-
? [createDefinitionInfo(find(declarations, d => !!(<FunctionLikeDeclaration>d).body) || last(declarations), typeChecker, symbol, node)]
266+
? declarationsWithBody.length !== 0
267+
? declarationsWithBody.map(x => createDefinitionInfo(x, typeChecker, symbol, node))
268+
: [createDefinitionInfo(last(declarations), typeChecker, symbol, node)]
263269
: undefined;
264270
}
265271
}

0 commit comments

Comments
 (0)