Skip to content

Commit 59ceddb

Browse files
committed
Merge branch 'master' into narrow-unknown-with-triple-equals
2 parents 2df6bd1 + f2a1a42 commit 59ceddb

File tree

503 files changed

+7887
-1433
lines changed

Some content is hidden

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

503 files changed

+7887
-1433
lines changed

src/compiler/binder.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,8 @@ namespace ts {
735735
return isNarrowingBinaryExpression(<BinaryExpression>expr);
736736
case SyntaxKind.PrefixUnaryExpression:
737737
return (<PrefixUnaryExpression>expr).operator === SyntaxKind.ExclamationToken && isNarrowingExpression((<PrefixUnaryExpression>expr).operand);
738+
case SyntaxKind.TypeOfExpression:
739+
return isNarrowingExpression((<TypeOfExpression>expr).expression);
738740
}
739741
return false;
740742
}

src/compiler/checker.ts

Lines changed: 299 additions & 43 deletions
Large diffs are not rendered by default.

src/compiler/commandLineParser.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,8 +1843,21 @@ namespace ts {
18431843
if (hasProperty(raw, "files") && !isNullOrUndefined(raw.files)) {
18441844
if (isArray(raw.files)) {
18451845
filesSpecs = <ReadonlyArray<string>>raw.files;
1846-
if (filesSpecs.length === 0) {
1847-
createCompilerDiagnosticOnlyIfJson(Diagnostics.The_files_list_in_config_file_0_is_empty, configFileName || "tsconfig.json");
1846+
const hasReferences = hasProperty(raw, "references") && !isNullOrUndefined(raw.references);
1847+
const hasZeroOrNoReferences = !hasReferences || raw.references.length === 0;
1848+
if (filesSpecs.length === 0 && hasZeroOrNoReferences) {
1849+
if (sourceFile) {
1850+
const fileName = configFileName || "tsconfig.json";
1851+
const diagnosticMessage = Diagnostics.The_files_list_in_config_file_0_is_empty;
1852+
const nodeValue = firstDefined(getTsConfigPropArray(sourceFile, "files"), property => property.initializer);
1853+
const error = nodeValue
1854+
? createDiagnosticForNodeInSourceFile(sourceFile, nodeValue, diagnosticMessage, fileName)
1855+
: createCompilerDiagnostic(diagnosticMessage, fileName);
1856+
errors.push(error);
1857+
}
1858+
else {
1859+
createCompilerDiagnosticOnlyIfJson(Diagnostics.The_files_list_in_config_file_0_is_empty, configFileName || "tsconfig.json");
1860+
}
18481861
}
18491862
}
18501863
else {
@@ -2067,11 +2080,6 @@ namespace ts {
20672080
createDiagnosticForNodeInSourceFile(sourceFile, valueNode, message, arg0)
20682081
);
20692082
return;
2070-
case "files":
2071-
if ((<ReadonlyArray<string>>value).length === 0) {
2072-
errors.push(createDiagnosticForNodeInSourceFile(sourceFile, valueNode, Diagnostics.The_files_list_in_config_file_0_is_empty, configFileName || "tsconfig.json"));
2073-
}
2074-
return;
20752083
}
20762084
},
20772085
onSetUnknownOptionKeyValueInRoot(key: string, keyNode: PropertyName, _value: CompilerOptionsValue, _valueNode: Expression) {
@@ -2081,6 +2089,7 @@ namespace ts {
20812089
}
20822090
};
20832091
const json = convertToObjectWorker(sourceFile, errors, /*returnValue*/ true, getTsconfigRootOptionsMap(), optionsIterator);
2092+
20842093
if (!typeAcquisition) {
20852094
if (typingOptionstypeAcquisition) {
20862095
typeAcquisition = (typingOptionstypeAcquisition.enableAutoDiscovery !== undefined) ?

src/compiler/core.ts

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

6666
/* @internal */
6767
namespace ts {
68+
export const emptyArray: never[] = [] as never[];
6869

6970
/** Create a MapLike with good performance. */
7071
function createDictionaryObject<T>(): MapLike<T> {

src/compiler/diagnosticMessages.json

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@
835835
"category": "Error",
836836
"code": 1253
837837
},
838-
"A 'const' initializer in an ambient context must be a string or numeric literal.": {
838+
"A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.": {
839839
"category": "Error",
840840
"code": 1254
841841
},
@@ -2088,6 +2088,30 @@
20882088
"category": "Error",
20892089
"code": 2577
20902090
},
2091+
"Cannot find name '{0}'. Do you need to install type definitions for node? Try `npm i @types/node`.": {
2092+
"category": "Error",
2093+
"code": 2580
2094+
},
2095+
"Cannot find name '{0}'. Do you need to install type definitions for jQuery? Try `npm i @types/jquery`.": {
2096+
"category": "Error",
2097+
"code": 2581
2098+
},
2099+
"Cannot find name '{0}'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.": {
2100+
"category": "Error",
2101+
"code": 2582
2102+
},
2103+
"Cannot find name '{0}'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.": {
2104+
"category": "Error",
2105+
"code": 2583
2106+
},
2107+
"Cannot find name '{0}'. Do you need to change your target library? Try changing the `lib` compiler option to include 'dom'.": {
2108+
"category": "Error",
2109+
"code": 2584
2110+
},
2111+
"'{0}' only refers to a type, but is being used as a value here. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.": {
2112+
"category": "Error",
2113+
"code": 2585
2114+
},
20912115
"JSX element attributes type '{0}' may not be a union type.": {
20922116
"category": "Error",
20932117
"code": 2600
@@ -2457,6 +2481,10 @@
24572481
"category": "Error",
24582482
"code": 2733
24592483
},
2484+
"It is highly likely that you are missing a semicolon.": {
2485+
"category": "Error",
2486+
"code": 2734
2487+
},
24602488

24612489
"Import declaration '{0}' is using private name '{1}'.": {
24622490
"category": "Error",
@@ -2912,7 +2940,7 @@
29122940
"category": "Error",
29132941
"code": 5070
29142942
},
2915-
"Option '--resolveJsonModule' can only be specified when module code generation is 'commonjs'.": {
2943+
"Option '--resolveJsonModule' can only be specified when module code generation is 'commonjs', 'amd', 'es2015' or 'esNext'.": {
29162944
"category": "Error",
29172945
"code": 5071
29182946
},
@@ -3294,7 +3322,7 @@
32943322
"category": "Message",
32953323
"code": 6104
32963324
},
3297-
"Expected type of '{0}' field in 'package.json' to be 'string', got '{1}'.": {
3325+
"Expected type of '{0}' field in 'package.json' to be '{1}', got '{2}'.": {
32983326
"category": "Message",
32993327
"code": 6105
33003328
},
@@ -3692,6 +3720,38 @@
36923720
"category": "Error",
36933721
"code": 6205
36943722
},
3723+
"'package.json' has a 'typesVersions' field with version-specific path mappings.": {
3724+
"category": "Message",
3725+
"code": 6206
3726+
},
3727+
"'package.json' does not have a 'typesVersions' entry that matches version '{0}'.": {
3728+
"category": "Message",
3729+
"code": 6207
3730+
},
3731+
"'package.json' has a 'typesVersions' entry '{0}' that matches compiler version '{1}', looking for a pattern to match module name '{2}'.": {
3732+
"category": "Message",
3733+
"code": 6208
3734+
},
3735+
"'package.json' has a 'typesVersions' entry '{0}' that is not a valid semver range.": {
3736+
"category": "Message",
3737+
"code": 6209
3738+
},
3739+
"An argument for '{0}' was not provided.": {
3740+
"category": "Message",
3741+
"code": 6210
3742+
},
3743+
"An argument matching this binding pattern was not provided.": {
3744+
"category": "Message",
3745+
"code": 6211
3746+
},
3747+
"Did you mean to call this expression?": {
3748+
"category": "Message",
3749+
"code": 6212
3750+
},
3751+
"Did you mean to use `new` with this expression?": {
3752+
"category": "Message",
3753+
"code": 6213
3754+
},
36953755

36963756
"Projects to reference": {
36973757
"category": "Message",

src/compiler/emitter.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,7 +1780,9 @@ namespace ts {
17801780

17811781
function emitExpressionStatement(node: ExpressionStatement) {
17821782
emitExpression(node.expression);
1783-
if (!isJsonSourceFile(currentSourceFile)) {
1783+
// Emit semicolon in non json files
1784+
// or if json file that created synthesized expression(eg.define expression statement when --out and amd code generation)
1785+
if (!isJsonSourceFile(currentSourceFile) || nodeIsSynthesized(node.expression)) {
17841786
writeSemicolon();
17851787
}
17861788
}
@@ -2816,7 +2818,8 @@ namespace ts {
28162818
const parameter = singleOrUndefined(parameters);
28172819
return parameter
28182820
&& parameter.pos === parentNode.pos // may not have parsed tokens between parent and parameter
2819-
&& !(isArrowFunction(parentNode) && parentNode.type) // arrow function may not have return type annotation
2821+
&& isArrowFunction(parentNode) // only arrow functions may have simple arrow head
2822+
&& !parentNode.type // arrow function may not have return type annotation
28202823
&& !some(parentNode.decorators) // parent may not have decorators
28212824
&& !some(parentNode.modifiers) // parent may not have modifiers
28222825
&& !some(parentNode.typeParameters) // parent may not have type parameters

0 commit comments

Comments
 (0)