Skip to content

Commit c2b709a

Browse files
committed
Merge branch 'master' of https://github.com/Microsoft/TypeScript into bug/36989
2 parents fb7fd42 + 60f50e2 commit c2b709a

File tree

105 files changed

+1931
-94
lines changed

Some content is hidden

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

105 files changed

+1931
-94
lines changed

src/compiler/checker.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ namespace ts {
298298
let typeCount = 0;
299299
let symbolCount = 0;
300300
let enumCount = 0;
301+
let totalInstantiationCount = 0;
301302
let instantiationCount = 0;
302303
let instantiationDepth = 0;
303304
let constraintDepth = 0;
@@ -348,6 +349,7 @@ namespace ts {
348349
getIdentifierCount: () => sum(host.getSourceFiles(), "identifierCount"),
349350
getSymbolCount: () => sum(host.getSourceFiles(), "symbolCount") + symbolCount,
350351
getTypeCount: () => typeCount,
352+
getInstantiationCount: () => totalInstantiationCount,
351353
getRelationCacheSizes: () => ({
352354
assignable: assignableRelation.size,
353355
identity: identityRelation.size,
@@ -13775,6 +13777,7 @@ namespace ts {
1377513777
error(currentNode, Diagnostics.Type_instantiation_is_excessively_deep_and_possibly_infinite);
1377613778
return errorType;
1377713779
}
13780+
totalInstantiationCount++;
1377813781
instantiationCount++;
1377913782
instantiationDepth++;
1378013783
const result = instantiateTypeWorker(type, mapper);
@@ -20519,12 +20522,20 @@ namespace ts {
2051920522

2052020523
/** remove undefined from the annotated type of a parameter when there is an initializer (that doesn't include undefined) */
2052120524
function removeOptionalityFromDeclaredType(declaredType: Type, declaration: VariableLikeDeclaration): Type {
20522-
const annotationIncludesUndefined = strictNullChecks &&
20523-
declaration.kind === SyntaxKind.Parameter &&
20524-
declaration.initializer &&
20525-
getFalsyFlags(declaredType) & TypeFlags.Undefined &&
20526-
!(getFalsyFlags(checkExpression(declaration.initializer)) & TypeFlags.Undefined);
20527-
return annotationIncludesUndefined ? getTypeWithFacts(declaredType, TypeFacts.NEUndefined) : declaredType;
20525+
if (pushTypeResolution(declaration.symbol, TypeSystemPropertyName.DeclaredType)) {
20526+
const annotationIncludesUndefined = strictNullChecks &&
20527+
declaration.kind === SyntaxKind.Parameter &&
20528+
declaration.initializer &&
20529+
getFalsyFlags(declaredType) & TypeFlags.Undefined &&
20530+
!(getFalsyFlags(checkExpression(declaration.initializer)) & TypeFlags.Undefined);
20531+
popTypeResolution();
20532+
20533+
return annotationIncludesUndefined ? getTypeWithFacts(declaredType, TypeFacts.NEUndefined) : declaredType;
20534+
}
20535+
else {
20536+
reportCircularityError(declaration.symbol);
20537+
return declaredType;
20538+
}
2052820539
}
2052920540

2053020541
function isConstraintPosition(node: Node) {
@@ -20947,7 +20958,7 @@ namespace ts {
2094720958
break;
2094820959
case SyntaxKind.PropertyDeclaration:
2094920960
case SyntaxKind.PropertySignature:
20950-
if (hasModifier(container, ModifierFlags.Static)) {
20961+
if (hasModifier(container, ModifierFlags.Static) && !(compilerOptions.target === ScriptTarget.ESNext && compilerOptions.useDefineForClassFields)) {
2095120962
error(node, Diagnostics.this_cannot_be_referenced_in_a_static_property_initializer);
2095220963
// do not return here so in case if lexical this is captured - it will be reflected in flags on NodeLinks
2095320964
}

src/compiler/commandLineParser.ts

Lines changed: 62 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,11 +1164,13 @@ namespace ts {
11641164
}
11651165
}
11661166

1167-
interface OptionsBase {
1167+
/*@internal*/
1168+
export interface OptionsBase {
11681169
[option: string]: CompilerOptionsValue | TsConfigSourceFile | undefined;
11691170
}
11701171

1171-
interface ParseCommandLineWorkerDiagnostics extends DidYouMeanOptionsDiagnostics {
1172+
/*@internal*/
1173+
export interface ParseCommandLineWorkerDiagnostics extends DidYouMeanOptionsDiagnostics {
11721174
getOptionsNameMap: () => OptionsNameMap;
11731175
optionTypeMismatchDiagnostic: DiagnosticMessage;
11741176
}
@@ -1189,7 +1191,8 @@ namespace ts {
11891191
createDiagnostics(diagnostics.unknownOptionDiagnostic, unknownOptionErrorText || unknownOption);
11901192
}
11911193

1192-
function parseCommandLineWorker(
1194+
/*@internal*/
1195+
export function parseCommandLineWorker(
11931196
diagnostics: ParseCommandLineWorkerDiagnostics,
11941197
commandLine: readonly string[],
11951198
readFile?: (path: string) => string | undefined) {
@@ -1279,50 +1282,75 @@ namespace ts {
12791282
errors: Diagnostic[]
12801283
) {
12811284
if (opt.isTSConfigOnly) {
1282-
errors.push(createCompilerDiagnostic(Diagnostics.Option_0_can_only_be_specified_in_tsconfig_json_file, opt.name));
1285+
const optValue = args[i];
1286+
if (optValue === "null") {
1287+
options[opt.name] = undefined;
1288+
i++;
1289+
}
1290+
else if (opt.type === "boolean") {
1291+
if (optValue === "false") {
1292+
options[opt.name] = false;
1293+
i++;
1294+
}
1295+
else {
1296+
if (optValue === "true") i++;
1297+
errors.push(createCompilerDiagnostic(Diagnostics.Option_0_can_only_be_specified_in_tsconfig_json_file_or_set_to_false_or_null_on_command_line, opt.name));
1298+
}
1299+
}
1300+
else {
1301+
errors.push(createCompilerDiagnostic(Diagnostics.Option_0_can_only_be_specified_in_tsconfig_json_file_or_set_to_null_on_command_line, opt.name));
1302+
if (optValue && !startsWith(optValue, "-")) i++;
1303+
}
12831304
}
12841305
else {
12851306
// Check to see if no argument was provided (e.g. "--locale" is the last command-line argument).
12861307
if (!args[i] && opt.type !== "boolean") {
12871308
errors.push(createCompilerDiagnostic(diagnostics.optionTypeMismatchDiagnostic, opt.name, getCompilerOptionValueTypeString(opt)));
12881309
}
12891310

1290-
switch (opt.type) {
1291-
case "number":
1292-
options[opt.name] = parseInt(args[i]);
1293-
i++;
1294-
break;
1295-
case "boolean":
1296-
// boolean flag has optional value true, false, others
1297-
const optValue = args[i];
1298-
options[opt.name] = optValue !== "false";
1299-
// consume next argument as boolean flag value
1300-
if (optValue === "false" || optValue === "true") {
1311+
if (args[i] !== "null") {
1312+
switch (opt.type) {
1313+
case "number":
1314+
options[opt.name] = parseInt(args[i]);
13011315
i++;
1302-
}
1303-
break;
1304-
case "string":
1305-
options[opt.name] = args[i] || "";
1306-
i++;
1307-
break;
1308-
case "list":
1309-
const result = parseListTypeOption(opt, args[i], errors);
1310-
options[opt.name] = result || [];
1311-
if (result) {
1316+
break;
1317+
case "boolean":
1318+
// boolean flag has optional value true, false, others
1319+
const optValue = args[i];
1320+
options[opt.name] = optValue !== "false";
1321+
// consume next argument as boolean flag value
1322+
if (optValue === "false" || optValue === "true") {
1323+
i++;
1324+
}
1325+
break;
1326+
case "string":
1327+
options[opt.name] = args[i] || "";
13121328
i++;
1313-
}
1314-
break;
1315-
// If not a primitive, the possible types are specified in what is effectively a map of options.
1316-
default:
1317-
options[opt.name] = parseCustomTypeOption(<CommandLineOptionOfCustomType>opt, args[i], errors);
1318-
i++;
1319-
break;
1329+
break;
1330+
case "list":
1331+
const result = parseListTypeOption(opt, args[i], errors);
1332+
options[opt.name] = result || [];
1333+
if (result) {
1334+
i++;
1335+
}
1336+
break;
1337+
// If not a primitive, the possible types are specified in what is effectively a map of options.
1338+
default:
1339+
options[opt.name] = parseCustomTypeOption(<CommandLineOptionOfCustomType>opt, args[i], errors);
1340+
i++;
1341+
break;
1342+
}
1343+
}
1344+
else {
1345+
options[opt.name] = undefined;
1346+
i++;
13201347
}
13211348
}
13221349
return i;
13231350
}
13241351

1325-
const compilerOptionsDidYouMeanDiagnostics: ParseCommandLineWorkerDiagnostics = {
1352+
/*@internal*/
1353+
export const compilerOptionsDidYouMeanDiagnostics: ParseCommandLineWorkerDiagnostics = {
13261354
getOptionsNameMap,
13271355
optionDeclarations,
13281356
unknownOptionDiagnostic: Diagnostics.Unknown_compiler_option_0,
@@ -2170,7 +2198,7 @@ namespace ts {
21702198
}
21712199

21722200
function convertToOptionValueWithAbsolutePaths(option: CommandLineOption | undefined, value: CompilerOptionsValue, toAbsolutePath: (path: string) => string) {
2173-
if (option) {
2201+
if (option && !isNullOrUndefined(value)) {
21742202
if (option.type === "list") {
21752203
const values = value as readonly (string | number)[];
21762204
if (option.element.isFilePath && values.length) {

src/compiler/diagnosticMessages.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3642,7 +3642,7 @@
36423642
"category": "Message",
36433643
"code": 6061
36443644
},
3645-
"Option '{0}' can only be specified in 'tsconfig.json' file.": {
3645+
"Option '{0}' can only be specified in 'tsconfig.json' file or set to 'null' on command line.": {
36463646
"category": "Error",
36473647
"code": 6064
36483648
},
@@ -4296,6 +4296,10 @@
42964296
"category": "Error",
42974297
"code": 6229
42984298
},
4299+
"Option '{0}' can only be specified in 'tsconfig.json' file or set to 'false' or 'null' on command line.": {
4300+
"category": "Error",
4301+
"code": 6230
4302+
},
42994303

43004304
"Projects to reference": {
43014305
"category": "Message",

src/compiler/program.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,7 @@ namespace ts {
946946
getIdentifierCount: () => getDiagnosticsProducingTypeChecker().getIdentifierCount(),
947947
getSymbolCount: () => getDiagnosticsProducingTypeChecker().getSymbolCount(),
948948
getTypeCount: () => getDiagnosticsProducingTypeChecker().getTypeCount(),
949+
getInstantiationCount: () => getDiagnosticsProducingTypeChecker().getInstantiationCount(),
949950
getRelationCacheSizes: () => getDiagnosticsProducingTypeChecker().getRelationCacheSizes(),
950951
getFileProcessingDiagnostics: () => fileProcessingDiagnostics,
951952
getResolvedTypeReferenceDirectives: () => resolvedTypeReferenceDirectives,

src/compiler/transformers/module/module.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,6 @@ namespace ts {
11801180
let modifiers: NodeArray<Modifier> | undefined;
11811181

11821182
// If we're exporting these variables, then these just become assignments to 'exports.x'.
1183-
// We only want to emit assignments for variables with initializers.
11841183
for (const variable of node.declarationList.declarations) {
11851184
if (isIdentifier(variable.name) && isLocalName(variable.name)) {
11861185
if (!modifiers) {
@@ -1189,7 +1188,7 @@ namespace ts {
11891188

11901189
variables = append(variables, variable);
11911190
}
1192-
else if (variable.initializer) {
1191+
else {
11931192
expressions = append(expressions, transformInitializedVariable(variable));
11941193
}
11951194
}
@@ -1259,7 +1258,7 @@ namespace ts {
12591258
),
12601259
/*location*/ node.name
12611260
),
1262-
visitNode(node.initializer, moduleExpressionElementVisitor)
1261+
node.initializer ? visitNode(node.initializer, moduleExpressionElementVisitor) : createVoidZero()
12631262
);
12641263
}
12651264
}

src/compiler/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3235,6 +3235,7 @@ namespace ts {
32353235
getIdentifierCount(): number;
32363236
getSymbolCount(): number;
32373237
getTypeCount(): number;
3238+
getInstantiationCount(): number;
32383239
getRelationCacheSizes(): { assignable: number, identity: number, subtype: number, strictSubtype: number };
32393240

32403241
/* @internal */ getFileProcessingDiagnostics(): DiagnosticCollection;
@@ -3557,6 +3558,7 @@ namespace ts {
35573558
/* @internal */ getIdentifierCount(): number;
35583559
/* @internal */ getSymbolCount(): number;
35593560
/* @internal */ getTypeCount(): number;
3561+
/* @internal */ getInstantiationCount(): number;
35603562
/* @internal */ getRelationCacheSizes(): { assignable: number, identity: number, subtype: number, strictSubtype: number };
35613563

35623564
/* @internal */ isArrayType(type: Type): boolean;

src/executeCommandLine/executeCommandLine.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ namespace ts {
639639
reportCountStatistic("Identifiers", program.getIdentifierCount());
640640
reportCountStatistic("Symbols", program.getSymbolCount());
641641
reportCountStatistic("Types", program.getTypeCount());
642+
reportCountStatistic("Instantiations", program.getInstantiationCount());
642643

643644
if (memoryUsed >= 0) {
644645
reportStatisticalValue("Memory used", Math.round(memoryUsed / 1000) + "K");

0 commit comments

Comments
 (0)