mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge branch 'master' into dtsSignatureChange
This commit is contained in:
@@ -236,10 +236,7 @@ namespace ts {
|
||||
}
|
||||
});
|
||||
|
||||
if (oldCompilerOptions &&
|
||||
(oldCompilerOptions.outDir !== compilerOptions.outDir ||
|
||||
oldCompilerOptions.declarationDir !== compilerOptions.declarationDir ||
|
||||
(oldCompilerOptions.outFile || oldCompilerOptions.out) !== (compilerOptions.outFile || compilerOptions.out))) {
|
||||
if (oldCompilerOptions && compilerOptionsAffectEmit(compilerOptions, oldCompilerOptions)) {
|
||||
// Add all files to affectedFilesPendingEmit since emit changed
|
||||
addToAffectedFilesPendingEmit(state, newProgram.getSourceFiles().map(f => f.path));
|
||||
Debug.assert(state.seenAffectedFiles === undefined);
|
||||
|
||||
+69
-48
@@ -114,6 +114,11 @@ namespace ts {
|
||||
getIdentifierCount: () => sum(host.getSourceFiles(), "identifierCount"),
|
||||
getSymbolCount: () => sum(host.getSourceFiles(), "symbolCount") + symbolCount,
|
||||
getTypeCount: () => typeCount,
|
||||
getRelationCacheSizes: () => ({
|
||||
assignable: assignableRelation.size,
|
||||
identity: identityRelation.size,
|
||||
subtype: subtypeRelation.size,
|
||||
}),
|
||||
isUndefinedSymbol: symbol => symbol === undefinedSymbol,
|
||||
isArgumentsSymbol: symbol => symbol === argumentsSymbol,
|
||||
isUnknownSymbol: symbol => symbol === unknownSymbol,
|
||||
@@ -6709,11 +6714,12 @@ namespace ts {
|
||||
const links = getSymbolLinks(symbol);
|
||||
if (!links.lateSymbol && some(symbol.declarations, hasLateBindableName)) {
|
||||
// force late binding of members/exports. This will set the late-bound symbol
|
||||
const parent = getMergedSymbol(symbol.parent)!;
|
||||
if (some(symbol.declarations, hasStaticModifier)) {
|
||||
getExportsOfSymbol(symbol.parent!);
|
||||
getExportsOfSymbol(parent);
|
||||
}
|
||||
else {
|
||||
getMembersOfSymbol(symbol.parent!);
|
||||
getMembersOfSymbol(parent);
|
||||
}
|
||||
}
|
||||
return links.lateSymbol || (links.lateSymbol = symbol);
|
||||
@@ -7473,6 +7479,25 @@ namespace ts {
|
||||
return type.resolvedProperties;
|
||||
}
|
||||
|
||||
function getPossiblePropertiesOfUnionType(type: UnionType): Symbol[] {
|
||||
if (type.possiblePropertyCache) {
|
||||
return type.possiblePropertyCache.size ? arrayFrom(type.possiblePropertyCache.values()) : emptyArray;
|
||||
}
|
||||
type.possiblePropertyCache = createSymbolTable();
|
||||
for (const t of type.types) {
|
||||
for (const p of getPropertiesOfType(t)) {
|
||||
if (!type.possiblePropertyCache.has(p.escapedName)) {
|
||||
const prop = getUnionOrIntersectionProperty(type, p.escapedName);
|
||||
if (prop) {
|
||||
type.possiblePropertyCache.set(p.escapedName, prop);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// We can't simply use the normal property cache here, since that will contain cached apparent type members :(
|
||||
return type.possiblePropertyCache.size ? arrayFrom(type.possiblePropertyCache.values()) : emptyArray;
|
||||
}
|
||||
|
||||
function getPropertiesOfType(type: Type): Symbol[] {
|
||||
type = getApparentType(type);
|
||||
return type.flags & TypeFlags.UnionOrIntersection ?
|
||||
@@ -7830,7 +7855,7 @@ namespace ts {
|
||||
const isUnion = containingType.flags & TypeFlags.Union;
|
||||
const excludeModifiers = isUnion ? ModifierFlags.NonPublicAccessibilityModifier : 0;
|
||||
// Flags we want to propagate to the result if they exist in all source symbols
|
||||
let commonFlags = isUnion ? SymbolFlags.None : SymbolFlags.Optional;
|
||||
let optionalFlag = isUnion ? SymbolFlags.None : SymbolFlags.Optional;
|
||||
let syntheticFlag = CheckFlags.SyntheticMethod;
|
||||
let checkFlags = 0;
|
||||
for (const current of containingType.types) {
|
||||
@@ -7839,7 +7864,12 @@ namespace ts {
|
||||
const prop = getPropertyOfType(type, name);
|
||||
const modifiers = prop ? getDeclarationModifierFlagsFromSymbol(prop) : 0;
|
||||
if (prop && !(modifiers & excludeModifiers)) {
|
||||
commonFlags &= prop.flags;
|
||||
if (isUnion) {
|
||||
optionalFlag |= (prop.flags & SymbolFlags.Optional);
|
||||
}
|
||||
else {
|
||||
optionalFlag &= prop.flags;
|
||||
}
|
||||
const id = "" + getSymbolId(prop);
|
||||
if (!propSet.has(id)) {
|
||||
propSet.set(id, prop);
|
||||
@@ -7857,10 +7887,11 @@ namespace ts {
|
||||
const indexInfo = !isLateBoundName(name) && (isNumericLiteralName(name) && getIndexInfoOfType(type, IndexKind.Number) || getIndexInfoOfType(type, IndexKind.String));
|
||||
if (indexInfo) {
|
||||
checkFlags |= indexInfo.isReadonly ? CheckFlags.Readonly : 0;
|
||||
checkFlags |= CheckFlags.WritePartial;
|
||||
indexTypes = append(indexTypes, isTupleType(type) ? getRestTypeOfTupleType(type) || undefinedType : indexInfo.type);
|
||||
}
|
||||
else {
|
||||
checkFlags |= CheckFlags.Partial;
|
||||
checkFlags |= CheckFlags.ReadPartial;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7869,7 +7900,7 @@ namespace ts {
|
||||
return undefined;
|
||||
}
|
||||
const props = arrayFrom(propSet.values());
|
||||
if (props.length === 1 && !(checkFlags & CheckFlags.Partial) && !indexTypes) {
|
||||
if (props.length === 1 && !(checkFlags & CheckFlags.ReadPartial) && !indexTypes) {
|
||||
return props[0];
|
||||
}
|
||||
let declarations: Declaration[] | undefined;
|
||||
@@ -7900,7 +7931,7 @@ namespace ts {
|
||||
propTypes.push(type);
|
||||
}
|
||||
addRange(propTypes, indexTypes);
|
||||
const result = createSymbol(SymbolFlags.Property | commonFlags, name, syntheticFlag | checkFlags);
|
||||
const result = createSymbol(SymbolFlags.Property | optionalFlag, name, syntheticFlag | checkFlags);
|
||||
result.containingType = containingType;
|
||||
if (!hasNonUniformValueDeclaration && firstValueDeclaration) {
|
||||
result.valueDeclaration = firstValueDeclaration;
|
||||
@@ -7937,7 +7968,7 @@ namespace ts {
|
||||
function getPropertyOfUnionOrIntersectionType(type: UnionOrIntersectionType, name: __String): Symbol | undefined {
|
||||
const property = getUnionOrIntersectionProperty(type, name);
|
||||
// We need to filter out partial properties in union types
|
||||
return property && !(getCheckFlags(property) & CheckFlags.Partial) ? property : undefined;
|
||||
return property && !(getCheckFlags(property) & CheckFlags.ReadPartial) ? property : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -12276,25 +12307,6 @@ namespace ts {
|
||||
return true;
|
||||
}
|
||||
|
||||
function isUnionOrIntersectionTypeWithoutNullableConstituents(type: Type): boolean {
|
||||
if (!(type.flags & TypeFlags.UnionOrIntersection)) {
|
||||
return false;
|
||||
}
|
||||
// at this point we know that this is union or intersection type possibly with nullable constituents.
|
||||
// check if we still will have compound type if we ignore nullable components.
|
||||
let seenNonNullable = false;
|
||||
for (const t of (<UnionOrIntersectionType>type).types) {
|
||||
if (t.flags & TypeFlags.Nullable) {
|
||||
continue;
|
||||
}
|
||||
if (seenNonNullable) {
|
||||
return true;
|
||||
}
|
||||
seenNonNullable = true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two types and return
|
||||
* * Ternary.True if they are related with no assumptions,
|
||||
@@ -12349,7 +12361,8 @@ namespace ts {
|
||||
isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined)) return Ternary.True;
|
||||
|
||||
const isComparingJsxAttributes = !!(getObjectFlags(source) & ObjectFlags.JsxAttributes);
|
||||
if (isObjectLiteralType(source) && getObjectFlags(source) & ObjectFlags.FreshLiteral) {
|
||||
const isPerformingExcessPropertyChecks = (isObjectLiteralType(source) && getObjectFlags(source) & ObjectFlags.FreshLiteral);
|
||||
if (isPerformingExcessPropertyChecks) {
|
||||
const discriminantType = target.flags & TypeFlags.Union ? findMatchingDiscriminantType(source, target as UnionType) : undefined;
|
||||
if (hasExcessProperties(<FreshObjectLiteralType>source, target, discriminantType, reportErrors)) {
|
||||
if (reportErrors) {
|
||||
@@ -12357,13 +12370,6 @@ namespace ts {
|
||||
}
|
||||
return Ternary.False;
|
||||
}
|
||||
// Above we check for excess properties with respect to the entire target type. When union
|
||||
// and intersection types are further deconstructed on the target side, we don't want to
|
||||
// make the check again (as it might fail for a partial target type). Therefore we obtain
|
||||
// the regular source type and proceed with that.
|
||||
if (isUnionOrIntersectionTypeWithoutNullableConstituents(target) && !discriminantType) {
|
||||
source = getRegularTypeOfObjectLiteral(source);
|
||||
}
|
||||
}
|
||||
|
||||
if (relation !== comparableRelation && !isApparentIntersectionConstituent &&
|
||||
@@ -12399,11 +12405,24 @@ namespace ts {
|
||||
}
|
||||
else {
|
||||
if (target.flags & TypeFlags.Union) {
|
||||
result = typeRelatedToSomeType(source, <UnionType>target, reportErrors && !(source.flags & TypeFlags.Primitive) && !(target.flags & TypeFlags.Primitive));
|
||||
result = typeRelatedToSomeType(getRegularTypeOfObjectLiteral(source), <UnionType>target, reportErrors && !(source.flags & TypeFlags.Primitive) && !(target.flags & TypeFlags.Primitive));
|
||||
if (result && isPerformingExcessPropertyChecks) {
|
||||
// Validate against excess props using the original `source`
|
||||
const discriminantType = target.flags & TypeFlags.Union ? findMatchingDiscriminantType(source, target as UnionType) : undefined;
|
||||
if (!propertiesRelatedTo(source, discriminantType || target, reportErrors)) {
|
||||
return Ternary.False;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (target.flags & TypeFlags.Intersection) {
|
||||
isIntersectionConstituent = true; // set here to affect the following trio of checks
|
||||
result = typeRelatedToEachType(source, target as IntersectionType, reportErrors);
|
||||
result = typeRelatedToEachType(getRegularTypeOfObjectLiteral(source), target as IntersectionType, reportErrors);
|
||||
if (result && isPerformingExcessPropertyChecks) {
|
||||
// Validate against excess props using the original `source`
|
||||
if (!propertiesRelatedTo(source, target, reportErrors)) {
|
||||
return Ternary.False;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (source.flags & TypeFlags.Intersection) {
|
||||
// Check to see if any constituents of the intersection are immediately related to the target.
|
||||
@@ -12506,7 +12525,7 @@ namespace ts {
|
||||
// check excess properties against discriminant type only, not the entire union
|
||||
return hasExcessProperties(source, discriminant, /*discriminant*/ undefined, reportErrors);
|
||||
}
|
||||
for (const prop of getPropertiesOfObjectType(source)) {
|
||||
for (const prop of getPropertiesOfType(source)) {
|
||||
if (shouldCheckAsExcessProperty(prop, source.symbol) && !isKnownProperty(target, prop.escapedName, isComparingJsxAttributes)) {
|
||||
if (reportErrors) {
|
||||
// Report error in terms of object types in the target as those are the only ones
|
||||
@@ -13233,7 +13252,9 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
}
|
||||
const properties = getPropertiesOfObjectType(target);
|
||||
// We only call this for union target types when we're attempting to do excess property checking - in those cases, we want to get _all possible props_
|
||||
// from the target union, across all members
|
||||
const properties = target.flags & TypeFlags.Union ? getPossiblePropertiesOfUnionType(target as UnionType) : getPropertiesOfType(target);
|
||||
for (const targetProp of properties) {
|
||||
if (!(targetProp.flags & SymbolFlags.Prototype)) {
|
||||
const sourceProp = getPropertyOfType(source, targetProp.escapedName);
|
||||
@@ -13281,7 +13302,8 @@ namespace ts {
|
||||
}
|
||||
return Ternary.False;
|
||||
}
|
||||
const related = isRelatedTo(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors);
|
||||
// If the target comes from a partial union prop, allow `undefined` in the target type
|
||||
const related = isRelatedTo(getTypeOfSymbol(sourceProp), addOptionality(getTypeOfSymbol(targetProp), !!(getCheckFlags(targetProp) & CheckFlags.Partial)), reportErrors);
|
||||
if (!related) {
|
||||
if (reportErrors) {
|
||||
reportError(Diagnostics.Types_of_property_0_are_incompatible, symbolToString(targetProp));
|
||||
@@ -14627,9 +14649,9 @@ namespace ts {
|
||||
}
|
||||
|
||||
function* getUnmatchedProperties(source: Type, target: Type, requireOptionalProperties: boolean, matchDiscriminantProperties: boolean) {
|
||||
const properties = target.flags & TypeFlags.Intersection ? getPropertiesOfUnionOrIntersectionType(<IntersectionType>target) : getPropertiesOfObjectType(target);
|
||||
const properties = target.flags & TypeFlags.Union ? getPossiblePropertiesOfUnionType(target as UnionType) : getPropertiesOfType(target);
|
||||
for (const targetProp of properties) {
|
||||
if (requireOptionalProperties || !(targetProp.flags & SymbolFlags.Optional)) {
|
||||
if (requireOptionalProperties || !(targetProp.flags & SymbolFlags.Optional || getCheckFlags(targetProp) & CheckFlags.Partial)) {
|
||||
const sourceProp = getPropertyOfType(source, targetProp.escapedName);
|
||||
if (!sourceProp) {
|
||||
yield targetProp;
|
||||
@@ -15000,12 +15022,11 @@ namespace ts {
|
||||
}
|
||||
// If no inferences can be made to K's constraint, infer from a union of the property types
|
||||
// in the source to the template type X.
|
||||
const valueTypes = compact([
|
||||
getIndexTypeOfType(source, IndexKind.String),
|
||||
getIndexTypeOfType(source, IndexKind.Number),
|
||||
...map(getPropertiesOfType(source), getTypeOfSymbol)
|
||||
]);
|
||||
inferFromTypes(getUnionType(valueTypes), getTemplateTypeFromMappedType(target));
|
||||
const propTypes = map(getPropertiesOfType(source), getTypeOfSymbol);
|
||||
const stringIndexType = getIndexTypeOfType(source, IndexKind.String);
|
||||
const numberIndexInfo = getNonEnumNumberIndexInfo(source);
|
||||
const numberIndexType = numberIndexInfo && numberIndexInfo.type;
|
||||
inferFromTypes(getUnionType(append(append(propTypes, stringIndexType), numberIndexType)), getTemplateTypeFromMappedType(target));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -281,6 +281,7 @@ namespace ts {
|
||||
name: "declaration",
|
||||
shortName: "d",
|
||||
type: "boolean",
|
||||
affectsEmit: true,
|
||||
showInSimplifiedHelpView: true,
|
||||
category: Diagnostics.Basic_Options,
|
||||
description: Diagnostics.Generates_corresponding_d_ts_file,
|
||||
@@ -288,6 +289,7 @@ namespace ts {
|
||||
{
|
||||
name: "declarationMap",
|
||||
type: "boolean",
|
||||
affectsEmit: true,
|
||||
showInSimplifiedHelpView: true,
|
||||
category: Diagnostics.Basic_Options,
|
||||
description: Diagnostics.Generates_a_sourcemap_for_each_corresponding_d_ts_file,
|
||||
@@ -295,12 +297,14 @@ namespace ts {
|
||||
{
|
||||
name: "emitDeclarationOnly",
|
||||
type: "boolean",
|
||||
affectsEmit: true,
|
||||
category: Diagnostics.Advanced_Options,
|
||||
description: Diagnostics.Only_emit_d_ts_declaration_files,
|
||||
},
|
||||
{
|
||||
name: "sourceMap",
|
||||
type: "boolean",
|
||||
affectsEmit: true,
|
||||
showInSimplifiedHelpView: true,
|
||||
category: Diagnostics.Basic_Options,
|
||||
description: Diagnostics.Generates_corresponding_map_file,
|
||||
@@ -308,6 +312,7 @@ namespace ts {
|
||||
{
|
||||
name: "outFile",
|
||||
type: "string",
|
||||
affectsEmit: true,
|
||||
isFilePath: true,
|
||||
paramType: Diagnostics.FILE,
|
||||
showInSimplifiedHelpView: true,
|
||||
@@ -317,6 +322,7 @@ namespace ts {
|
||||
{
|
||||
name: "outDir",
|
||||
type: "string",
|
||||
affectsEmit: true,
|
||||
isFilePath: true,
|
||||
paramType: Diagnostics.DIRECTORY,
|
||||
showInSimplifiedHelpView: true,
|
||||
@@ -326,6 +332,7 @@ namespace ts {
|
||||
{
|
||||
name: "rootDir",
|
||||
type: "string",
|
||||
affectsEmit: true,
|
||||
isFilePath: true,
|
||||
paramType: Diagnostics.LOCATION,
|
||||
category: Diagnostics.Basic_Options,
|
||||
@@ -334,6 +341,7 @@ namespace ts {
|
||||
{
|
||||
name: "composite",
|
||||
type: "boolean",
|
||||
affectsEmit: true,
|
||||
isTSConfigOnly: true,
|
||||
category: Diagnostics.Basic_Options,
|
||||
description: Diagnostics.Enable_project_compilation,
|
||||
@@ -341,6 +349,7 @@ namespace ts {
|
||||
{
|
||||
name: "tsBuildInfoFile",
|
||||
type: "string",
|
||||
affectsEmit: true,
|
||||
isFilePath: true,
|
||||
paramType: Diagnostics.FILE,
|
||||
category: Diagnostics.Basic_Options,
|
||||
@@ -349,6 +358,7 @@ namespace ts {
|
||||
{
|
||||
name: "removeComments",
|
||||
type: "boolean",
|
||||
affectsEmit: true,
|
||||
showInSimplifiedHelpView: true,
|
||||
category: Diagnostics.Basic_Options,
|
||||
description: Diagnostics.Do_not_emit_comments_to_output,
|
||||
@@ -356,6 +366,7 @@ namespace ts {
|
||||
{
|
||||
name: "noEmit",
|
||||
type: "boolean",
|
||||
affectsEmit: true,
|
||||
showInSimplifiedHelpView: true,
|
||||
category: Diagnostics.Basic_Options,
|
||||
description: Diagnostics.Do_not_emit_outputs,
|
||||
@@ -363,12 +374,14 @@ namespace ts {
|
||||
{
|
||||
name: "importHelpers",
|
||||
type: "boolean",
|
||||
affectsEmit: true,
|
||||
category: Diagnostics.Basic_Options,
|
||||
description: Diagnostics.Import_emit_helpers_from_tslib
|
||||
},
|
||||
{
|
||||
name: "downlevelIteration",
|
||||
type: "boolean",
|
||||
affectsEmit: true,
|
||||
category: Diagnostics.Basic_Options,
|
||||
description: Diagnostics.Provide_full_support_for_iterables_in_for_of_spread_and_destructuring_when_targeting_ES5_or_ES3
|
||||
},
|
||||
@@ -580,6 +593,7 @@ namespace ts {
|
||||
{
|
||||
name: "sourceRoot",
|
||||
type: "string",
|
||||
affectsEmit: true,
|
||||
paramType: Diagnostics.LOCATION,
|
||||
category: Diagnostics.Source_Map_Options,
|
||||
description: Diagnostics.Specify_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations,
|
||||
@@ -587,6 +601,7 @@ namespace ts {
|
||||
{
|
||||
name: "mapRoot",
|
||||
type: "string",
|
||||
affectsEmit: true,
|
||||
paramType: Diagnostics.LOCATION,
|
||||
category: Diagnostics.Source_Map_Options,
|
||||
description: Diagnostics.Specify_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations,
|
||||
@@ -594,12 +609,14 @@ namespace ts {
|
||||
{
|
||||
name: "inlineSourceMap",
|
||||
type: "boolean",
|
||||
affectsEmit: true,
|
||||
category: Diagnostics.Source_Map_Options,
|
||||
description: Diagnostics.Emit_a_single_file_with_source_maps_instead_of_having_a_separate_file
|
||||
},
|
||||
{
|
||||
name: "inlineSources",
|
||||
type: "boolean",
|
||||
affectsEmit: true,
|
||||
category: Diagnostics.Source_Map_Options,
|
||||
description: Diagnostics.Emit_the_source_alongside_the_sourcemaps_within_a_single_file_requires_inlineSourceMap_or_sourceMap_to_be_set
|
||||
},
|
||||
@@ -635,6 +652,7 @@ namespace ts {
|
||||
{
|
||||
name: "out",
|
||||
type: "string",
|
||||
affectsEmit: true,
|
||||
isFilePath: false, // This is intentionally broken to support compatability with existing tsconfig files
|
||||
// for correct behaviour, please use outFile
|
||||
category: Diagnostics.Advanced_Options,
|
||||
@@ -644,6 +662,7 @@ namespace ts {
|
||||
{
|
||||
name: "reactNamespace",
|
||||
type: "string",
|
||||
affectsEmit: true,
|
||||
category: Diagnostics.Advanced_Options,
|
||||
description: Diagnostics.Deprecated_Use_jsxFactory_instead_Specify_the_object_invoked_for_createElement_when_targeting_react_JSX_emit
|
||||
},
|
||||
@@ -662,6 +681,7 @@ namespace ts {
|
||||
{
|
||||
name: "emitBOM",
|
||||
type: "boolean",
|
||||
affectsEmit: true,
|
||||
category: Diagnostics.Advanced_Options,
|
||||
description: Diagnostics.Emit_a_UTF_8_Byte_Order_Mark_BOM_in_the_beginning_of_output_files
|
||||
},
|
||||
@@ -677,6 +697,7 @@ namespace ts {
|
||||
crlf: NewLineKind.CarriageReturnLineFeed,
|
||||
lf: NewLineKind.LineFeed
|
||||
}),
|
||||
affectsEmit: true,
|
||||
paramType: Diagnostics.NEWLINE,
|
||||
category: Diagnostics.Advanced_Options,
|
||||
description: Diagnostics.Specify_the_end_of_line_sequence_to_be_used_when_emitting_files_Colon_CRLF_dos_or_LF_unix,
|
||||
@@ -704,6 +725,7 @@ namespace ts {
|
||||
{
|
||||
name: "stripInternal",
|
||||
type: "boolean",
|
||||
affectsEmit: true,
|
||||
category: Diagnostics.Advanced_Options,
|
||||
description: Diagnostics.Do_not_emit_declarations_for_code_that_has_an_internal_annotation,
|
||||
},
|
||||
@@ -724,24 +746,28 @@ namespace ts {
|
||||
{
|
||||
name: "noEmitHelpers",
|
||||
type: "boolean",
|
||||
affectsEmit: true,
|
||||
category: Diagnostics.Advanced_Options,
|
||||
description: Diagnostics.Do_not_generate_custom_helper_functions_like_extends_in_compiled_output
|
||||
},
|
||||
{
|
||||
name: "noEmitOnError",
|
||||
type: "boolean",
|
||||
affectsEmit: true,
|
||||
category: Diagnostics.Advanced_Options,
|
||||
description: Diagnostics.Do_not_emit_outputs_if_any_errors_were_reported,
|
||||
},
|
||||
{
|
||||
name: "preserveConstEnums",
|
||||
type: "boolean",
|
||||
affectsEmit: true,
|
||||
category: Diagnostics.Advanced_Options,
|
||||
description: Diagnostics.Do_not_erase_const_enum_declarations_in_generated_code
|
||||
},
|
||||
{
|
||||
name: "declarationDir",
|
||||
type: "string",
|
||||
affectsEmit: true,
|
||||
isFilePath: true,
|
||||
paramType: Diagnostics.DIRECTORY,
|
||||
category: Diagnostics.Advanced_Options,
|
||||
@@ -826,6 +852,10 @@ namespace ts {
|
||||
export const semanticDiagnosticsOptionDeclarations: ReadonlyArray<CommandLineOption> =
|
||||
optionDeclarations.filter(option => !!option.affectsSemanticDiagnostics);
|
||||
|
||||
/* @internal */
|
||||
export const affectsEmitOptionDeclarations: ReadonlyArray<CommandLineOption> =
|
||||
optionDeclarations.filter(option => !!option.affectsEmit);
|
||||
|
||||
/* @internal */
|
||||
export const moduleResolutionOptionDeclarations: ReadonlyArray<CommandLineOption> =
|
||||
optionDeclarations.filter(option => !!option.affectsModuleResolution);
|
||||
|
||||
@@ -927,6 +927,7 @@ namespace ts {
|
||||
getIdentifierCount: () => getDiagnosticsProducingTypeChecker().getIdentifierCount(),
|
||||
getSymbolCount: () => getDiagnosticsProducingTypeChecker().getSymbolCount(),
|
||||
getTypeCount: () => getDiagnosticsProducingTypeChecker().getTypeCount(),
|
||||
getRelationCacheSizes: () => getDiagnosticsProducingTypeChecker().getRelationCacheSizes(),
|
||||
getFileProcessingDiagnostics: () => fileProcessingDiagnostics,
|
||||
getResolvedTypeReferenceDirectives: () => resolvedTypeReferenceDirectives,
|
||||
isSourceFileFromExternalLibrary,
|
||||
|
||||
+19
-12
@@ -2961,6 +2961,7 @@ namespace ts {
|
||||
/* @internal */ getIdentifierCount(): number;
|
||||
/* @internal */ getSymbolCount(): number;
|
||||
/* @internal */ getTypeCount(): number;
|
||||
/* @internal */ getRelationCacheSizes(): { assignable: number, identity: number, subtype: number };
|
||||
|
||||
/* @internal */ getFileProcessingDiagnostics(): DiagnosticCollection;
|
||||
/* @internal */ getResolvedTypeReferenceDirectives(): Map<ResolvedTypeReferenceDirective | undefined>;
|
||||
@@ -3246,6 +3247,7 @@ namespace ts {
|
||||
/* @internal */ getIdentifierCount(): number;
|
||||
/* @internal */ getSymbolCount(): number;
|
||||
/* @internal */ getTypeCount(): number;
|
||||
/* @internal */ getRelationCacheSizes(): { assignable: number, identity: number, subtype: number };
|
||||
|
||||
/* @internal */ isArrayType(type: Type): boolean;
|
||||
/* @internal */ isTupleType(type: Type): boolean;
|
||||
@@ -3746,19 +3748,21 @@ namespace ts {
|
||||
SyntheticProperty = 1 << 1, // Property in union or intersection type
|
||||
SyntheticMethod = 1 << 2, // Method in union or intersection type
|
||||
Readonly = 1 << 3, // Readonly transient symbol
|
||||
Partial = 1 << 4, // Synthetic property present in some but not all constituents
|
||||
HasNonUniformType = 1 << 5, // Synthetic property with non-uniform type in constituents
|
||||
HasLiteralType = 1 << 6, // Synthetic property with at least one literal type in constituents
|
||||
ContainsPublic = 1 << 7, // Synthetic property with public constituent(s)
|
||||
ContainsProtected = 1 << 8, // Synthetic property with protected constituent(s)
|
||||
ContainsPrivate = 1 << 9, // Synthetic property with private constituent(s)
|
||||
ContainsStatic = 1 << 10, // Synthetic property with static constituent(s)
|
||||
Late = 1 << 11, // Late-bound symbol for a computed property with a dynamic name
|
||||
ReverseMapped = 1 << 12, // Property of reverse-inferred homomorphic mapped type
|
||||
OptionalParameter = 1 << 13, // Optional parameter
|
||||
RestParameter = 1 << 14, // Rest parameter
|
||||
ReadPartial = 1 << 4, // Synthetic property present in some but not all constituents
|
||||
WritePartial = 1 << 5, // Synthetic property present in some but only satisfied by an index signature in others
|
||||
HasNonUniformType = 1 << 6, // Synthetic property with non-uniform type in constituents
|
||||
HasLiteralType = 1 << 7, // Synthetic property with at least one literal type in constituents
|
||||
ContainsPublic = 1 << 8, // Synthetic property with public constituent(s)
|
||||
ContainsProtected = 1 << 9, // Synthetic property with protected constituent(s)
|
||||
ContainsPrivate = 1 << 10, // Synthetic property with private constituent(s)
|
||||
ContainsStatic = 1 << 11, // Synthetic property with static constituent(s)
|
||||
Late = 1 << 12, // Late-bound symbol for a computed property with a dynamic name
|
||||
ReverseMapped = 1 << 13, // Property of reverse-inferred homomorphic mapped type
|
||||
OptionalParameter = 1 << 14, // Optional parameter
|
||||
RestParameter = 1 << 15, // Rest parameter
|
||||
Synthetic = SyntheticProperty | SyntheticMethod,
|
||||
Discriminant = HasNonUniformType | HasLiteralType
|
||||
Discriminant = HasNonUniformType | HasLiteralType,
|
||||
Partial = ReadPartial | WritePartial
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
@@ -4171,6 +4175,8 @@ namespace ts {
|
||||
}
|
||||
|
||||
export interface UnionType extends UnionOrIntersectionType {
|
||||
/* @internal */
|
||||
possiblePropertyCache?: SymbolTable; // Cache of _all_ resolved properties less any from aparent members
|
||||
}
|
||||
|
||||
export interface IntersectionType extends UnionOrIntersectionType {
|
||||
@@ -4823,6 +4829,7 @@ namespace ts {
|
||||
affectsModuleResolution?: true; // currently same effect as `affectsSourceFile`
|
||||
affectsBindDiagnostics?: true; // true if this affects binding (currently same effect as `affectsSourceFile`)
|
||||
affectsSemanticDiagnostics?: true; // true if option affects semantic diagnostics
|
||||
affectsEmit?: true; // true if the options affects emit
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
|
||||
@@ -7320,6 +7320,11 @@ namespace ts {
|
||||
semanticDiagnosticsOptionDeclarations.some(option => !isJsonEqual(getCompilerOptionValue(oldOptions, option), getCompilerOptionValue(newOptions, option)));
|
||||
}
|
||||
|
||||
export function compilerOptionsAffectEmit(newOptions: CompilerOptions, oldOptions: CompilerOptions): boolean {
|
||||
return oldOptions !== newOptions &&
|
||||
affectsEmitOptionDeclarations.some(option => !isJsonEqual(getCompilerOptionValue(oldOptions, option), getCompilerOptionValue(newOptions, option)));
|
||||
}
|
||||
|
||||
export function getCompilerOptionValue(options: CompilerOptions, option: CommandLineOption): unknown {
|
||||
return option.strictFlag ? getStrictOptionValue(options, option.name as StrictOptionName) : options[option.name];
|
||||
}
|
||||
|
||||
@@ -397,19 +397,6 @@ namespace fakes {
|
||||
const value = super.readFile(path);
|
||||
if (!value || !ts.isBuildInfoFile(path)) return value;
|
||||
const buildInfo = ts.getBuildInfo(value);
|
||||
if (buildInfo.program) {
|
||||
// Fix lib signatures
|
||||
for (const path of ts.getOwnKeys(buildInfo.program.fileInfos)) {
|
||||
if (ts.startsWith(path, "/lib/")) {
|
||||
const currentValue = buildInfo.program.fileInfos[path];
|
||||
ts.Debug.assert(currentValue.signature === path);
|
||||
ts.Debug.assert(currentValue.signature === currentValue.version);
|
||||
const text = super.readFile(path)!;
|
||||
const signature = ts.generateDjb2Hash(text);
|
||||
buildInfo.program.fileInfos[path] = { version: signature, signature };
|
||||
}
|
||||
}
|
||||
}
|
||||
ts.Debug.assert(buildInfo.version === version);
|
||||
buildInfo.version = ts.version;
|
||||
return ts.getBuildInfoText(buildInfo);
|
||||
@@ -419,15 +406,6 @@ namespace fakes {
|
||||
if (!ts.isBuildInfoFile(fileName)) return super.writeFile(fileName, content, writeByteOrderMark);
|
||||
const buildInfo = ts.getBuildInfo(content);
|
||||
if (buildInfo.program) {
|
||||
// Fix lib signatures
|
||||
for (const path of ts.getOwnKeys(buildInfo.program.fileInfos)) {
|
||||
if (ts.startsWith(path, "/lib/")) {
|
||||
const currentValue = buildInfo.program.fileInfos[path];
|
||||
ts.Debug.assert(currentValue.signature === currentValue.version);
|
||||
buildInfo.program.fileInfos[path] = { version: path, signature: path };
|
||||
}
|
||||
}
|
||||
|
||||
// reference Map
|
||||
if (buildInfo.program.referencedMap) {
|
||||
const referencedMap: ts.MapLike<string[]> = {};
|
||||
|
||||
@@ -93,6 +93,7 @@
|
||||
"unittests/tsbuild/emptyFiles.ts",
|
||||
"unittests/tsbuild/graphOrdering.ts",
|
||||
"unittests/tsbuild/inferredTypeFromTransitiveModule.ts",
|
||||
"unittests/tsbuild/lateBoundSymbol.ts",
|
||||
"unittests/tsbuild/missingExtendedFile.ts",
|
||||
"unittests/tsbuild/outFile.ts",
|
||||
"unittests/tsbuild/referencesWithRootDirInParent.ts",
|
||||
|
||||
@@ -62,31 +62,26 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
const libContent = `${TestFSWithWatch.libFile.content}
|
||||
interface ReadonlyArray<T> {}
|
||||
declare const console: { log(msg: any): void; };`;
|
||||
|
||||
export function loadProjectFromDisk(root: string, time?: vfs.FileSystemOptions["time"]): vfs.FileSystem {
|
||||
const resolver = vfs.createResolver(Harness.IO);
|
||||
const fs = new vfs.FileSystem(/*ignoreCase*/ true, {
|
||||
files: {
|
||||
["/lib"]: new vfs.Mount(vpath.resolve(Harness.IO.getWorkspaceRoot(), "built/local"), resolver),
|
||||
["/src"]: new vfs.Mount(vpath.resolve(Harness.IO.getWorkspaceRoot(), root), resolver)
|
||||
},
|
||||
cwd: "/",
|
||||
meta: { defaultLibLocation: "/lib" },
|
||||
time
|
||||
});
|
||||
fs.mkdirSync("/lib");
|
||||
fs.writeFileSync("/lib/lib.d.ts", libContent);
|
||||
fs.makeReadonly();
|
||||
return fs;
|
||||
}
|
||||
|
||||
export function getLibs() {
|
||||
return [
|
||||
"/lib/lib.d.ts",
|
||||
"/lib/lib.es5.d.ts",
|
||||
"/lib/lib.dom.d.ts",
|
||||
"/lib/lib.webworker.importscripts.d.ts",
|
||||
"/lib/lib.scripthost.d.ts"
|
||||
];
|
||||
}
|
||||
|
||||
function generateSourceMapBaselineFiles(fs: vfs.FileSystem, mapFileNames: ReadonlyArray<string>) {
|
||||
for (const mapFile of mapFileNames) {
|
||||
if (!fs.existsSync(mapFile)) continue;
|
||||
@@ -285,8 +280,10 @@ Mismatch Actual(path, actual, expected): ${JSON.stringify(arrayFrom(mapDefinedIt
|
||||
let newFs: vfs.FileSystem;
|
||||
let actualReadFileMap: Map<number>;
|
||||
let host: fakes.SolutionBuilderHost;
|
||||
let beforeBuildTime: number;
|
||||
let afterBuildTime: number;
|
||||
before(() => {
|
||||
assert.equal(fs.statSync(lastProjectOutputJs).mtimeMs, firstBuildTime, "First build timestamp is correct");
|
||||
beforeBuildTime = fs.statSync(lastProjectOutputJs).mtimeMs;
|
||||
tick();
|
||||
newFs = fs.shadow();
|
||||
tick();
|
||||
@@ -298,13 +295,17 @@ Mismatch Actual(path, actual, expected): ${JSON.stringify(arrayFrom(mapDefinedIt
|
||||
expectedBuildInfoFilesForSectionBaselines,
|
||||
modifyFs: incrementalModifyFs,
|
||||
}));
|
||||
assert.equal(newFs.statSync(lastProjectOutputJs).mtimeMs, time(), "Second build timestamp is correct");
|
||||
afterBuildTime = newFs.statSync(lastProjectOutputJs).mtimeMs;
|
||||
});
|
||||
after(() => {
|
||||
newFs = undefined!;
|
||||
actualReadFileMap = undefined!;
|
||||
host = undefined!;
|
||||
});
|
||||
it("verify build output times", () => {
|
||||
assert.equal(beforeBuildTime, firstBuildTime, "First build timestamp is correct");
|
||||
assert.equal(afterBuildTime, time(), "Second build timestamp is correct");
|
||||
});
|
||||
if (!baselineOnly || verifyDiagnostics) {
|
||||
it(`verify diagnostics`, () => {
|
||||
host.assertDiagnosticMessages(...(incrementalExpectedDiagnostics || emptyArray));
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
namespace ts {
|
||||
describe("unittests:: tsbuild:: lateBoundSymbol:: interface is merged and contains late bound member", () => {
|
||||
let projFs: vfs.FileSystem;
|
||||
const { time, tick } = getTime();
|
||||
before(() => {
|
||||
projFs = loadProjectFromDisk("tests/projects/lateBoundSymbol", time);
|
||||
});
|
||||
after(() => {
|
||||
projFs = undefined!; // Release the contents
|
||||
});
|
||||
|
||||
verifyTsbuildOutput({
|
||||
scenario: "interface is merged and contains late bound member",
|
||||
projFs: () => projFs,
|
||||
time,
|
||||
tick,
|
||||
proj: "lateBoundSymbol",
|
||||
rootNames: ["/src/tsconfig.json"],
|
||||
expectedMapFileNames: emptyArray,
|
||||
lastProjectOutputJs: "/src/src/main.js",
|
||||
outputFiles: [
|
||||
"/src/src/hkt.js",
|
||||
"/src/src/main.js",
|
||||
"/src/tsconfig.tsbuildinfo",
|
||||
],
|
||||
initialBuild: {
|
||||
modifyFs: noop,
|
||||
expectedDiagnostics: [
|
||||
getExpectedDiagnosticForProjectsInBuild("src/tsconfig.json"),
|
||||
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/tsconfig.json", "src/src/hkt.js"],
|
||||
[Diagnostics.Building_project_0, "/src/tsconfig.json"]
|
||||
]
|
||||
},
|
||||
incrementalDtsUnchangedBuild: {
|
||||
modifyFs: fs => replaceText(fs, "/src/src/main.ts", "const x = 10;", ""),
|
||||
expectedDiagnostics: [
|
||||
getExpectedDiagnosticForProjectsInBuild("src/tsconfig.json"),
|
||||
[Diagnostics.Project_0_is_out_of_date_because_oldest_output_1_is_older_than_newest_input_2, "src/tsconfig.json", "src/src/hkt.js", "src/src/main.ts"],
|
||||
[Diagnostics.Building_project_0, "/src/tsconfig.json"],
|
||||
[Diagnostics.Updating_unchanged_output_timestamps_of_project_0, "/src/tsconfig.json"]
|
||||
]
|
||||
},
|
||||
baselineOnly: true,
|
||||
verifyDiagnostics: true
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -399,14 +399,14 @@ export class cNew {}`);
|
||||
const builder = createSolutionBuilder(host, ["/src/tests"], { listFiles: true });
|
||||
builder.buildAllProjects();
|
||||
assert.deepEqual(host.traces, [
|
||||
...getLibs(),
|
||||
"/lib/lib.d.ts",
|
||||
"/src/core/anotherModule.ts",
|
||||
"/src/core/index.ts",
|
||||
"/src/core/some_decl.d.ts",
|
||||
...getLibs(),
|
||||
"/lib/lib.d.ts",
|
||||
...getCoreOutputs(),
|
||||
"/src/logic/index.ts",
|
||||
...getLibs(),
|
||||
"/lib/lib.d.ts",
|
||||
...getCoreOutputs(),
|
||||
"/src/logic/index.d.ts",
|
||||
"/src/tests/index.ts"
|
||||
@@ -720,6 +720,47 @@ class someClass { }`),
|
||||
"/src/tests/tsconfig.tsbuildinfo",
|
||||
]
|
||||
});
|
||||
|
||||
verifyTsbuildOutput({
|
||||
scenario: "when declaration option changes",
|
||||
projFs: () => projFs,
|
||||
time,
|
||||
tick,
|
||||
proj: "sample1",
|
||||
rootNames: ["/src/core"],
|
||||
expectedMapFileNames: emptyArray,
|
||||
lastProjectOutputJs: "/src/core/index.js",
|
||||
initialBuild: {
|
||||
modifyFs: fs => fs.writeFileSync("/src/core/tsconfig.json", `{
|
||||
"compilerOptions": {
|
||||
"incremental": true,
|
||||
"skipDefaultLibCheck": true
|
||||
}
|
||||
}`),
|
||||
expectedDiagnostics: [
|
||||
getExpectedDiagnosticForProjectsInBuild("src/core/tsconfig.json"),
|
||||
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/core/tsconfig.json", "src/core/anotherModule.js"],
|
||||
[Diagnostics.Building_project_0, "/src/core/tsconfig.json"],
|
||||
]
|
||||
},
|
||||
incrementalDtsChangedBuild: {
|
||||
modifyFs: fs => replaceText(fs, "/src/core/tsconfig.json", `"incremental": true,`, `"incremental": true, "declaration": true,`),
|
||||
expectedDiagnostics: [
|
||||
getExpectedDiagnosticForProjectsInBuild("src/core/tsconfig.json"),
|
||||
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/core/tsconfig.json", "src/core/anotherModule.d.ts"],
|
||||
[Diagnostics.Building_project_0, "/src/core/tsconfig.json"]
|
||||
]
|
||||
},
|
||||
outputFiles: [
|
||||
"/src/core/anotherModule.js",
|
||||
"/src/core/anotherModule.d.ts",
|
||||
"/src/core/index.js",
|
||||
"/src/core/index.d.ts",
|
||||
"/src/core/tsconfig.tsbuildinfo",
|
||||
],
|
||||
baselineOnly: true,
|
||||
verifyDiagnostics: true
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,12 +7,12 @@ namespace ts {
|
||||
"/src/c.js"
|
||||
];
|
||||
const expectedFileTraces = [
|
||||
...getLibs(),
|
||||
"/lib/lib.d.ts",
|
||||
"/src/a.ts",
|
||||
...getLibs(),
|
||||
"/lib/lib.d.ts",
|
||||
"/src/a.d.ts",
|
||||
"/src/b.ts",
|
||||
...getLibs(),
|
||||
"/lib/lib.d.ts",
|
||||
"/src/a.d.ts",
|
||||
"/src/b.d.ts",
|
||||
"/src/refs/a.d.ts",
|
||||
@@ -63,9 +63,9 @@ export const b = new A();`);
|
||||
// Error in b build only a
|
||||
const allExpectedOutputs = ["/src/a.js", "/src/a.d.ts"];
|
||||
const expectedFileTraces = [
|
||||
...getLibs(),
|
||||
"/lib/lib.d.ts",
|
||||
"/src/a.ts",
|
||||
...getLibs(),
|
||||
"/lib/lib.d.ts",
|
||||
"/src/b.ts"
|
||||
];
|
||||
verifyBuild(fs => modifyFsBTsToNonRelativeImport(fs, "node"),
|
||||
|
||||
@@ -340,6 +340,10 @@ namespace ts {
|
||||
const checkTime = performance.getDuration("Check");
|
||||
const emitTime = performance.getDuration("Emit");
|
||||
if (compilerOptions.extendedDiagnostics) {
|
||||
const caches = program.getRelationCacheSizes();
|
||||
reportCountStatistic("Assignability cache size", caches.assignable);
|
||||
reportCountStatistic("Identity cache size", caches.identity);
|
||||
reportCountStatistic("Subtype cache size", caches.subtype);
|
||||
performance.forEachMeasure((name, duration) => reportTimeStatistic(`${name} time`, duration));
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user