Skip to content

Commit 0a037d0

Browse files
committed
Merge remote-tracking branch 'upstream/master' into narrow-non-declared-union
2 parents 1925a6c + ea4e6b3 commit 0a037d0

File tree

209 files changed

+5733
-736
lines changed

Some content is hidden

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

209 files changed

+5733
-736
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ tests/cases/user/TypeScript-React-Native-Starter/TypeScript-React-Native-Starter
9090
tests/cases/user/TypeScript-Vue-Starter/TypeScript-Vue-Starter
9191
tests/cases/user/TypeScript-WeChat-Starter/TypeScript-WeChat-Starter
9292
tests/cases/user/create-react-app/create-react-app
93+
tests/cases/user/fp-ts/fp-ts
9394
tests/cases/user/webpack/webpack
9495
tests/cases/user/puppeteer/puppeteer
9596
tests/cases/user/axios-src/axios-src

scripts/build/options.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const os = require("os");
44

55
/** @type {CommandLineOptions} */
66
module.exports = minimist(process.argv.slice(2), {
7-
boolean: ["debug", "dirty", "inspect", "light", "colors", "lint", "lkg", "soft", "fix", "failed", "keepFailed", "force", "built"],
8-
string: ["browser", "tests", "host", "reporter", "stackTraceLimit", "timeout", "shards", "shardId"],
7+
boolean: ["debug", "dirty", "light", "colors", "lint", "lkg", "soft", "fix", "failed", "keepFailed", "force", "built"],
8+
string: ["browser", "tests", "inspect", "host", "reporter", "stackTraceLimit", "timeout", "shards", "shardId"],
99
alias: {
1010
"b": "browser",
1111
"d": "debug", "debug-brk": "debug",
@@ -49,7 +49,6 @@ if (module.exports.built) {
4949
* @typedef TypedOptions
5050
* @property {boolean} debug
5151
* @property {boolean} dirty
52-
* @property {boolean} inspect
5352
* @property {boolean} light
5453
* @property {boolean} colors
5554
* @property {boolean} lint
@@ -59,6 +58,7 @@ if (module.exports.built) {
5958
* @property {boolean} fix
6059
* @property {string} browser
6160
* @property {string} tests
61+
* @property {string} inspect
6262
* @property {string} runners
6363
* @property {string|number} workers
6464
* @property {string} host

scripts/build/tests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ async function runConsoleTests(runJs, defaultReporter, runInParallel, watchMode,
8989
else {
9090
args.push("--no-colors");
9191
}
92-
if (inspect) {
93-
args.unshift("--inspect-brk");
92+
if (inspect !== undefined) {
93+
args.unshift(inspect == "" ? "--inspect-brk" : "--inspect-brk="+inspect);
9494
}
9595
else if (debug) {
9696
args.unshift("--debug-brk");

src/compiler/binder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2752,7 +2752,7 @@ namespace ts {
27522752

27532753
function bindObjectDefinePrototypeProperty(node: BindableObjectDefinePropertyCall) {
27542754
const namespaceSymbol = lookupSymbolForPropertyAccess((node.arguments[0] as PropertyAccessExpression).expression as EntityNameExpression);
2755-
if (namespaceSymbol) {
2755+
if (namespaceSymbol && namespaceSymbol.valueDeclaration) {
27562756
// Ensure the namespace symbol becomes class-like
27572757
addDeclarationToSymbol(namespaceSymbol, namespaceSymbol.valueDeclaration, SymbolFlags.Class);
27582758
}
@@ -3643,7 +3643,7 @@ namespace ts {
36433643
let transformFlags = subtreeFlags | TransformFlags.ContainsClassFields;
36443644

36453645
// Decorators, TypeScript-specific modifiers, and type annotations are TypeScript syntax.
3646-
if (some(node.decorators) || hasModifier(node, ModifierFlags.TypeScriptModifier) || node.type || node.questionToken) {
3646+
if (some(node.decorators) || hasModifier(node, ModifierFlags.TypeScriptModifier) || node.type || node.questionToken || node.exclamationToken) {
36473647
transformFlags |= TransformFlags.AssertTypeScript;
36483648
}
36493649

@@ -3807,7 +3807,7 @@ namespace ts {
38073807
}
38083808

38093809
// Type annotations are TypeScript syntax.
3810-
if (node.type) {
3810+
if (node.type || node.exclamationToken) {
38113811
transformFlags |= TransformFlags.AssertTypeScript;
38123812
}
38133813

src/compiler/checker.ts

Lines changed: 166 additions & 67 deletions
Large diffs are not rendered by default.

src/compiler/commandLineParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1539,7 +1539,7 @@ namespace ts {
15391539
}
15401540

15411541
if (element.questionToken) {
1542-
errors.push(createDiagnosticForNodeInSourceFile(sourceFile, element.questionToken, Diagnostics._0_can_only_be_used_in_a_ts_file, "?"));
1542+
errors.push(createDiagnosticForNodeInSourceFile(sourceFile, element.questionToken, Diagnostics.The_0_modifier_can_only_be_used_in_TypeScript_files, "?"));
15431543
}
15441544
if (!isDoubleQuotedString(element.name)) {
15451545
errors.push(createDiagnosticForNodeInSourceFile(sourceFile, element.name, Diagnostics.String_literal_with_double_quotes_expected));

src/compiler/diagnosticMessages.json

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3241,7 +3241,7 @@
32413241
"category": "Error",
32423242
"code": 5061
32433243
},
3244-
"Substitution '{0}' in pattern '{1}' in can have at most one '*' character.": {
3244+
"Substitution '{0}' in pattern '{1}' can have at most one '*' character.": {
32453245
"category": "Error",
32463246
"code": 5062
32473247
},
@@ -4543,59 +4543,51 @@
45434543
"category": "Error",
45444544
"code": 8001
45454545
},
4546-
"'import ... =' can only be used in a .ts file.": {
4546+
"'import ... =' can only be used in TypeScript files.": {
45474547
"category": "Error",
45484548
"code": 8002
45494549
},
4550-
"'export=' can only be used in a .ts file.": {
4550+
"'export =' can only be used in TypeScript files.": {
45514551
"category": "Error",
45524552
"code": 8003
45534553
},
4554-
"'type parameter declarations' can only be used in a .ts file.": {
4554+
"Type parameter declarations can only be used in TypeScript files.": {
45554555
"category": "Error",
45564556
"code": 8004
45574557
},
4558-
"'implements clauses' can only be used in a .ts file.": {
4558+
"'implements' clauses can only be used in TypeScript files.": {
45594559
"category": "Error",
45604560
"code": 8005
45614561
},
4562-
"'interface declarations' can only be used in a .ts file.": {
4562+
"'{0}' declarations can only be used in TypeScript files.": {
45634563
"category": "Error",
45644564
"code": 8006
45654565
},
4566-
"'module declarations' can only be used in a .ts file.": {
4567-
"category": "Error",
4568-
"code": 8007
4569-
},
4570-
"'type aliases' can only be used in a .ts file.": {
4566+
"Type aliases can only be used in TypeScript files.": {
45714567
"category": "Error",
45724568
"code": 8008
45734569
},
4574-
"'{0}' can only be used in a .ts file.": {
4570+
"The '{0}' modifier can only be used in TypeScript files.": {
45754571
"category": "Error",
45764572
"code": 8009
45774573
},
4578-
"'types' can only be used in a .ts file.": {
4574+
"Type annotations can only be used in TypeScript files.": {
45794575
"category": "Error",
45804576
"code": 8010
45814577
},
4582-
"'type arguments' can only be used in a .ts file.": {
4578+
"Type arguments can only be used in TypeScript files.": {
45834579
"category": "Error",
45844580
"code": 8011
45854581
},
4586-
"'parameter modifiers' can only be used in a .ts file.": {
4582+
"Parameter modifiers can only be used in TypeScript files.": {
45874583
"category": "Error",
45884584
"code": 8012
45894585
},
4590-
"'non-null assertions' can only be used in a .ts file.": {
4586+
"Non-null assertions can only be used in TypeScript files.": {
45914587
"category": "Error",
45924588
"code": 8013
45934589
},
4594-
"'enum declarations' can only be used in a .ts file.": {
4595-
"category": "Error",
4596-
"code": 8015
4597-
},
4598-
"'type assertion expressions' can only be used in a .ts file.": {
4590+
"Type assertion expressions can only be used in TypeScript files.": {
45994591
"category": "Error",
46004592
"code": 8016
46014593
},

src/compiler/emitter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2741,6 +2741,7 @@ namespace ts {
27412741

27422742
function emitVariableDeclaration(node: VariableDeclaration) {
27432743
emit(node.name);
2744+
emit(node.exclamationToken);
27442745
emitTypeAnnotation(node.type);
27452746
emitInitializer(node.initializer, node.type ? node.type.end : node.name.end, node);
27462747
}

src/compiler/factory.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,6 +1937,7 @@ namespace ts {
19371937
}
19381938

19391939
export function createVariableDeclaration(name: string | BindingName, type?: TypeNode, initializer?: Expression) {
1940+
/* Internally, one should probably use createTypeScriptVariableDeclaration instead and handle definite assignment assertions */
19401941
const node = <VariableDeclaration>createSynthesizedNode(SyntaxKind.VariableDeclaration);
19411942
node.name = asName(name);
19421943
node.type = type;
@@ -1945,13 +1946,34 @@ namespace ts {
19451946
}
19461947

19471948
export function updateVariableDeclaration(node: VariableDeclaration, name: BindingName, type: TypeNode | undefined, initializer: Expression | undefined) {
1949+
/* Internally, one should probably use updateTypeScriptVariableDeclaration instead and handle definite assignment assertions */
19481950
return node.name !== name
19491951
|| node.type !== type
19501952
|| node.initializer !== initializer
19511953
? updateNode(createVariableDeclaration(name, type, initializer), node)
19521954
: node;
19531955
}
19541956

1957+
/* @internal */
1958+
export function createTypeScriptVariableDeclaration(name: string | BindingName, exclaimationToken?: Token<SyntaxKind.ExclamationToken>, type?: TypeNode, initializer?: Expression) {
1959+
const node = <VariableDeclaration>createSynthesizedNode(SyntaxKind.VariableDeclaration);
1960+
node.name = asName(name);
1961+
node.type = type;
1962+
node.initializer = initializer !== undefined ? parenthesizeExpressionForList(initializer) : undefined;
1963+
node.exclamationToken = exclaimationToken;
1964+
return node;
1965+
}
1966+
1967+
/* @internal */
1968+
export function updateTypeScriptVariableDeclaration(node: VariableDeclaration, name: BindingName, exclaimationToken: Token<SyntaxKind.ExclamationToken> | undefined, type: TypeNode | undefined, initializer: Expression | undefined) {
1969+
return node.name !== name
1970+
|| node.type !== type
1971+
|| node.initializer !== initializer
1972+
|| node.exclamationToken !== exclaimationToken
1973+
? updateNode(createTypeScriptVariableDeclaration(name, exclaimationToken, type, initializer), node)
1974+
: node;
1975+
}
1976+
19551977
export function createVariableDeclarationList(declarations: readonly VariableDeclaration[], flags = NodeFlags.None) {
19561978
const node = <VariableDeclarationList>createSynthesizedNode(SyntaxKind.VariableDeclarationList);
19571979
node.flags |= flags & NodeFlags.BlockScoped;

src/compiler/program.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,7 +1797,7 @@ namespace ts {
17971797
case SyntaxKind.PropertyDeclaration:
17981798
case SyntaxKind.MethodDeclaration:
17991799
if ((<ParameterDeclaration | PropertyDeclaration | MethodDeclaration>parent).questionToken === node) {
1800-
diagnostics.push(createDiagnosticForNode(node, Diagnostics._0_can_only_be_used_in_a_ts_file, "?"));
1800+
diagnostics.push(createDiagnosticForNode(node, Diagnostics.The_0_modifier_can_only_be_used_in_TypeScript_files, "?"));
18011801
return;
18021802
}
18031803
// falls through
@@ -1811,45 +1811,48 @@ namespace ts {
18111811
case SyntaxKind.VariableDeclaration:
18121812
// type annotation
18131813
if ((<FunctionLikeDeclaration | VariableDeclaration | ParameterDeclaration | PropertyDeclaration>parent).type === node) {
1814-
diagnostics.push(createDiagnosticForNode(node, Diagnostics.types_can_only_be_used_in_a_ts_file));
1814+
diagnostics.push(createDiagnosticForNode(node, Diagnostics.Type_annotations_can_only_be_used_in_TypeScript_files));
18151815
return;
18161816
}
18171817
}
18181818

18191819
switch (node.kind) {
18201820
case SyntaxKind.ImportEqualsDeclaration:
1821-
diagnostics.push(createDiagnosticForNode(node, Diagnostics.import_can_only_be_used_in_a_ts_file));
1821+
diagnostics.push(createDiagnosticForNode(node, Diagnostics.import_can_only_be_used_in_TypeScript_files));
18221822
return;
18231823
case SyntaxKind.ExportAssignment:
18241824
if ((<ExportAssignment>node).isExportEquals) {
1825-
diagnostics.push(createDiagnosticForNode(node, Diagnostics.export_can_only_be_used_in_a_ts_file));
1825+
diagnostics.push(createDiagnosticForNode(node, Diagnostics.export_can_only_be_used_in_TypeScript_files));
18261826
return;
18271827
}
18281828
break;
18291829
case SyntaxKind.HeritageClause:
18301830
const heritageClause = <HeritageClause>node;
18311831
if (heritageClause.token === SyntaxKind.ImplementsKeyword) {
1832-
diagnostics.push(createDiagnosticForNode(node, Diagnostics.implements_clauses_can_only_be_used_in_a_ts_file));
1832+
diagnostics.push(createDiagnosticForNode(node, Diagnostics.implements_clauses_can_only_be_used_in_TypeScript_files));
18331833
return;
18341834
}
18351835
break;
18361836
case SyntaxKind.InterfaceDeclaration:
1837-
diagnostics.push(createDiagnosticForNode(node, Diagnostics.interface_declarations_can_only_be_used_in_a_ts_file));
1837+
diagnostics.push(createDiagnosticForNode(node, Diagnostics.Interface_declaration_cannot_have_implements_clause));
18381838
return;
18391839
case SyntaxKind.ModuleDeclaration:
1840-
diagnostics.push(createDiagnosticForNode(node, Diagnostics.module_declarations_can_only_be_used_in_a_ts_file));
1840+
const moduleKeyword = node.flags & NodeFlags.Namespace ? tokenToString(SyntaxKind.NamespaceKeyword) : tokenToString(SyntaxKind.ModuleKeyword);
1841+
Debug.assertDefined(moduleKeyword);
1842+
diagnostics.push(createDiagnosticForNode(node, Diagnostics._0_declarations_can_only_be_used_in_TypeScript_files, moduleKeyword));
18411843
return;
18421844
case SyntaxKind.TypeAliasDeclaration:
1843-
diagnostics.push(createDiagnosticForNode(node, Diagnostics.type_aliases_can_only_be_used_in_a_ts_file));
1845+
diagnostics.push(createDiagnosticForNode(node, Diagnostics.Type_aliases_can_only_be_used_in_TypeScript_files));
18441846
return;
18451847
case SyntaxKind.EnumDeclaration:
1846-
diagnostics.push(createDiagnosticForNode(node, Diagnostics.enum_declarations_can_only_be_used_in_a_ts_file));
1848+
const enumKeyword = Debug.assertDefined(tokenToString(SyntaxKind.EnumKeyword));
1849+
diagnostics.push(createDiagnosticForNode(node, Diagnostics._0_declarations_can_only_be_used_in_TypeScript_files, enumKeyword));
18471850
return;
18481851
case SyntaxKind.NonNullExpression:
1849-
diagnostics.push(createDiagnosticForNode(node, Diagnostics.non_null_assertions_can_only_be_used_in_a_ts_file));
1852+
diagnostics.push(createDiagnosticForNode(node, Diagnostics.Non_null_assertions_can_only_be_used_in_TypeScript_files));
18501853
return;
18511854
case SyntaxKind.AsExpression:
1852-
diagnostics.push(createDiagnosticForNode((node as AsExpression).type, Diagnostics.type_assertion_expressions_can_only_be_used_in_a_ts_file));
1855+
diagnostics.push(createDiagnosticForNode((node as AsExpression).type, Diagnostics.Type_assertion_expressions_can_only_be_used_in_TypeScript_files));
18531856
return;
18541857
case SyntaxKind.TypeAssertionExpression:
18551858
Debug.fail(); // Won't parse these in a JS file anyway, as they are interpreted as JSX.
@@ -1878,7 +1881,7 @@ namespace ts {
18781881
case SyntaxKind.ArrowFunction:
18791882
// Check type parameters
18801883
if (nodes === (<DeclarationWithTypeParameterChildren>parent).typeParameters) {
1881-
diagnostics.push(createDiagnosticForNodeArray(nodes, Diagnostics.type_parameter_declarations_can_only_be_used_in_a_ts_file));
1884+
diagnostics.push(createDiagnosticForNodeArray(nodes, Diagnostics.Type_parameter_declarations_can_only_be_used_in_TypeScript_files));
18821885
return;
18831886
}
18841887
// falls through
@@ -1894,7 +1897,7 @@ namespace ts {
18941897
if (nodes === (<PropertyDeclaration>parent).modifiers) {
18951898
for (const modifier of <NodeArray<Modifier>>nodes) {
18961899
if (modifier.kind !== SyntaxKind.StaticKeyword) {
1897-
diagnostics.push(createDiagnosticForNode(modifier, Diagnostics._0_can_only_be_used_in_a_ts_file, tokenToString(modifier.kind)));
1900+
diagnostics.push(createDiagnosticForNode(modifier, Diagnostics.The_0_modifier_can_only_be_used_in_TypeScript_files, tokenToString(modifier.kind)));
18981901
}
18991902
}
19001903
return;
@@ -1903,7 +1906,7 @@ namespace ts {
19031906
case SyntaxKind.Parameter:
19041907
// Check modifiers of parameter declaration
19051908
if (nodes === (<ParameterDeclaration>parent).modifiers) {
1906-
diagnostics.push(createDiagnosticForNodeArray(nodes, Diagnostics.parameter_modifiers_can_only_be_used_in_a_ts_file));
1909+
diagnostics.push(createDiagnosticForNodeArray(nodes, Diagnostics.Parameter_modifiers_can_only_be_used_in_TypeScript_files));
19071910
return;
19081911
}
19091912
break;
@@ -1915,7 +1918,7 @@ namespace ts {
19151918
case SyntaxKind.TaggedTemplateExpression:
19161919
// Check type arguments
19171920
if (nodes === (<NodeWithTypeArguments>parent).typeArguments) {
1918-
diagnostics.push(createDiagnosticForNodeArray(nodes, Diagnostics.type_arguments_can_only_be_used_in_a_ts_file));
1921+
diagnostics.push(createDiagnosticForNodeArray(nodes, Diagnostics.Type_arguments_can_only_be_used_in_TypeScript_files));
19191922
return;
19201923
}
19211924
break;
@@ -1941,7 +1944,7 @@ namespace ts {
19411944
case SyntaxKind.ReadonlyKeyword:
19421945
case SyntaxKind.DeclareKeyword:
19431946
case SyntaxKind.AbstractKeyword:
1944-
diagnostics.push(createDiagnosticForNode(modifier, Diagnostics._0_can_only_be_used_in_a_ts_file, tokenToString(modifier.kind)));
1947+
diagnostics.push(createDiagnosticForNode(modifier, Diagnostics.The_0_modifier_can_only_be_used_in_TypeScript_files, tokenToString(modifier.kind)));
19451948
break;
19461949

19471950
// These are all legal modifiers.
@@ -2980,7 +2983,7 @@ namespace ts {
29802983
const typeOfSubst = typeof subst;
29812984
if (typeOfSubst === "string") {
29822985
if (!hasZeroOrOneAsteriskCharacter(subst)) {
2983-
createDiagnosticForOptionPathKeyValue(key, i, Diagnostics.Substitution_0_in_pattern_1_in_can_have_at_most_one_Asterisk_character, subst, key);
2986+
createDiagnosticForOptionPathKeyValue(key, i, Diagnostics.Substitution_0_in_pattern_1_can_have_at_most_one_Asterisk_character, subst, key);
29842987
}
29852988
}
29862989
else {

0 commit comments

Comments
 (0)