Skip to content

Commit 45227ee

Browse files
authored
Merge branch 'master' into allow_running_in_web
2 parents 206de25 + 8ca36f3 commit 45227ee

File tree

89 files changed

+2156
-891
lines changed

Some content is hidden

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

89 files changed

+2156
-891
lines changed

src/compiler/binder.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1827,7 +1827,23 @@ namespace ts {
18271827
bindPotentiallyMissingNamespaces(file.symbol, declName.parent, isTopLevel,
18281828
!!findAncestor(declName, d => isPropertyAccessExpression(d) && d.name.escapedText === "prototype"), /*containerIsClass*/ false);
18291829
const oldContainer = container;
1830-
container = isPropertyAccessExpression(declName.parent.expression) ? declName.parent.expression.name : declName.parent.expression;
1830+
switch (getAssignmentDeclarationPropertyAccessKind(declName.parent)) {
1831+
case AssignmentDeclarationKind.ExportsProperty:
1832+
case AssignmentDeclarationKind.ModuleExports:
1833+
container = file;
1834+
break;
1835+
case AssignmentDeclarationKind.ThisProperty:
1836+
container = declName.parent.expression;
1837+
break;
1838+
case AssignmentDeclarationKind.PrototypeProperty:
1839+
container = (declName.parent.expression as PropertyAccessExpression).name;
1840+
break;
1841+
case AssignmentDeclarationKind.Property:
1842+
container = isPropertyAccessExpression(declName.parent.expression) ? declName.parent.expression.name : declName.parent.expression;
1843+
break;
1844+
case AssignmentDeclarationKind.None:
1845+
return Debug.fail("Shouldn't have detected typedef or enum on non-assignment declaration");
1846+
}
18311847
declareModuleMember(typeAlias, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes);
18321848
container = oldContainer;
18331849
}

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: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12885,7 +12885,7 @@ namespace ts {
1288512885
// and we need to handle "each" relations before "some" relations for the same kind of type.
1288612886
if (source.flags & TypeFlags.Union) {
1288712887
result = relation === comparableRelation ?
12888-
someTypeRelatedToType(source as UnionType, target, reportErrors && !(source.flags & TypeFlags.Primitive)) :
12888+
someTypeRelatedToType(source as UnionType, target, reportErrors && !(source.flags & TypeFlags.Primitive), isIntersectionConstituent) :
1288912889
eachTypeRelatedToType(source as UnionType, target, reportErrors && !(source.flags & TypeFlags.Primitive));
1289012890
}
1289112891
else {
@@ -12923,7 +12923,7 @@ namespace ts {
1292312923
//
1292412924
// - For a primitive type or type parameter (such as 'number = A & B') there is no point in
1292512925
// breaking the intersection apart.
12926-
result = someTypeRelatedToType(<IntersectionType>source, target, /*reportErrors*/ false);
12926+
result = someTypeRelatedToType(<IntersectionType>source, target, /*reportErrors*/ false, /*isIntersectionConstituent*/ true);
1292712927
}
1292812928
if (!result && (source.flags & TypeFlags.StructuredOrInstantiable || target.flags & TypeFlags.StructuredOrInstantiable)) {
1292912929
if (result = recursiveTypeRelatedTo(source, target, reportErrors, isIntersectionConstituent)) {
@@ -13202,14 +13202,14 @@ namespace ts {
1320213202
return result;
1320313203
}
1320413204

13205-
function someTypeRelatedToType(source: UnionOrIntersectionType, target: Type, reportErrors: boolean): Ternary {
13205+
function someTypeRelatedToType(source: UnionOrIntersectionType, target: Type, reportErrors: boolean, isIntersectionConstituent: boolean): Ternary {
1320613206
const sourceTypes = source.types;
1320713207
if (source.flags & TypeFlags.Union && containsType(sourceTypes, target)) {
1320813208
return Ternary.True;
1320913209
}
1321013210
const len = sourceTypes.length;
1321113211
for (let i = 0; i < len; i++) {
13212-
const related = isRelatedTo(sourceTypes[i], target, reportErrors && i === len - 1);
13212+
const related = isRelatedTo(sourceTypes[i], target, reportErrors && i === len - 1, /*headMessage*/ undefined, isIntersectionConstituent);
1321313213
if (related) {
1321413214
return related;
1321513215
}
@@ -21578,13 +21578,13 @@ namespace ts {
2157821578
checkMode: CheckMode,
2157921579
reportErrors: boolean,
2158021580
containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined,
21581-
) {
21581+
): ReadonlyArray<Diagnostic> | undefined {
2158221582

2158321583
const errorOutputContainer: { errors?: Diagnostic[], skipLogging?: boolean } = { errors: undefined, skipLogging: true };
2158421584
if (isJsxOpeningLikeElement(node)) {
2158521585
if (!checkApplicableSignatureForJsxOpeningLikeElement(node, signature, relation, checkMode, reportErrors, containingMessageChain, errorOutputContainer)) {
2158621586
Debug.assert(!reportErrors || !!errorOutputContainer.errors, "jsx should have errors when reporting errors");
21587-
return errorOutputContainer.errors || [];
21587+
return errorOutputContainer.errors || emptyArray;
2158821588
}
2158921589
return undefined;
2159021590
}
@@ -21599,7 +21599,7 @@ namespace ts {
2159921599
const headMessage = Diagnostics.The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1;
2160021600
if (!checkTypeRelatedTo(thisArgumentType, thisType, relation, errorNode, headMessage, containingMessageChain, errorOutputContainer)) {
2160121601
Debug.assert(!reportErrors || !!errorOutputContainer.errors, "this parameter should have errors when reporting errors");
21602-
return errorOutputContainer.errors || [];
21602+
return errorOutputContainer.errors || emptyArray;
2160321603
}
2160421604
}
2160521605
const headMessage = Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1;
@@ -21617,7 +21617,7 @@ namespace ts {
2161721617
if (!checkTypeRelatedToAndOptionallyElaborate(checkArgType, paramType, relation, reportErrors ? arg : undefined, arg, headMessage, containingMessageChain, errorOutputContainer)) {
2161821618
Debug.assert(!reportErrors || !!errorOutputContainer.errors, "parameter should have errors when reporting errors");
2161921619
maybeAddMissingAwaitInfo(arg, checkArgType, paramType);
21620-
return errorOutputContainer.errors || [];
21620+
return errorOutputContainer.errors || emptyArray;
2162121621
}
2162221622
}
2162321623
}
@@ -21627,7 +21627,7 @@ namespace ts {
2162721627
if (!checkTypeRelatedTo(spreadType, restType, relation, errorNode, headMessage, /*containingMessageChain*/ undefined, errorOutputContainer)) {
2162821628
Debug.assert(!reportErrors || !!errorOutputContainer.errors, "rest parameter should have errors when reporting errors");
2162921629
maybeAddMissingAwaitInfo(errorNode, spreadType, restType);
21630-
return errorOutputContainer.errors || [];
21630+
return errorOutputContainer.errors || emptyArray;
2163121631
}
2163221632
}
2163321633
return undefined;
@@ -22018,7 +22018,7 @@ namespace ts {
2201822018
}
2201922019
}
2202022020
else {
22021-
const allDiagnostics: DiagnosticRelatedInformation[][] = [];
22021+
const allDiagnostics: (readonly DiagnosticRelatedInformation[])[] = [];
2202222022
let max = 0;
2202322023
let min = Number.MAX_VALUE;
2202422024
let minIndex = 0;

0 commit comments

Comments
 (0)