Skip to content

Commit c4ad151

Browse files
committed
Merge branch 'master' into ownJsonParsing
2 parents d680720 + c179d9a commit c4ad151

File tree

207 files changed

+883
-5495
lines changed

Some content is hidden

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

207 files changed

+883
-5495
lines changed

scripts/tslint/nextLineRule.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class Rule extends Lint.Rules.AbstractRule {
1818

1919
function walk(ctx: Lint.WalkContext<void>, checkCatch: boolean, checkElse: boolean): void {
2020
const { sourceFile } = ctx;
21-
function recur(node: ts.Node): void {
21+
ts.forEachChild(sourceFile, function recur(node) {
2222
switch (node.kind) {
2323
case ts.SyntaxKind.IfStatement:
2424
checkIf(node as ts.IfStatement);
@@ -28,7 +28,7 @@ function walk(ctx: Lint.WalkContext<void>, checkCatch: boolean, checkElse: boole
2828
break;
2929
}
3030
ts.forEachChild(node, recur);
31-
}
31+
});
3232

3333
function checkIf(node: ts.IfStatement): void {
3434
const { thenStatement, elseStatement } = node;

src/compiler/binder.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2333,7 +2333,7 @@ namespace ts {
23332333
// A common practice in node modules is to set 'export = module.exports = {}', this ensures that 'exports'
23342334
// is still pointing to 'module.exports'.
23352335
// We do not want to consider this as 'export=' since a module can have only one of these.
2336-
// Similarly we do not want to treat 'module.exports = exports' as an 'export='.
2336+
// Similarlly we do not want to treat 'module.exports = exports' as an 'export='.
23372337
const assignedExpression = getRightMostAssignedExpression(node.right);
23382338
if (isEmptyObjectLiteral(assignedExpression) || isExportsOrModuleExportsOrAlias(assignedExpression)) {
23392339
// Mark it as a module in case there are no other exports in the file
@@ -2741,10 +2741,6 @@ namespace ts {
27412741
transformFlags |= TransformFlags.AssertES2015;
27422742
}
27432743

2744-
if (expression.kind === SyntaxKind.ImportKeyword) {
2745-
transformFlags |= TransformFlags.ContainsDynamicImport;
2746-
}
2747-
27482744
node.transformFlags = transformFlags | TransformFlags.HasComputedFlags;
27492745
return transformFlags & ~TransformFlags.ArrayLiteralOrCallOrNewExcludes;
27502746
}

src/compiler/checker.ts

Lines changed: 23 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ namespace ts {
216216
getSuggestionForNonexistentProperty,
217217
getSuggestionForNonexistentSymbol,
218218
getBaseConstraintOfType,
219+
getJsxNamespace,
220+
resolveNameAtLocation(location: Node, name: string, meaning: SymbolFlags): Symbol | undefined {
221+
location = getParseTreeNode(location);
222+
return resolveName(location, name, meaning, /*nameNotFoundMessage*/ undefined, name);
223+
},
219224
};
220225

221226
const tupleTypes: GenericType[] = [];
@@ -741,6 +746,7 @@ namespace ts {
741746
if (declarationFile !== useFile) {
742747
if ((modulekind && (declarationFile.externalModuleIndicator || useFile.externalModuleIndicator)) ||
743748
(!compilerOptions.outFile && !compilerOptions.out) ||
749+
isInTypeQuery(usage) ||
744750
isInAmbientContext(declaration)) {
745751
// nodes are in different files and order cannot be determined
746752
return true;
@@ -853,7 +859,7 @@ namespace ts {
853859
location: Node | undefined,
854860
name: string,
855861
meaning: SymbolFlags,
856-
nameNotFoundMessage: DiagnosticMessage,
862+
nameNotFoundMessage: DiagnosticMessage | undefined,
857863
nameArg: string | Identifier,
858864
suggestedNameNotFoundMessage?: DiagnosticMessage): Symbol {
859865
return resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, getSymbol, suggestedNameNotFoundMessage);
@@ -1370,6 +1376,9 @@ namespace ts {
13701376
// An 'import { Point } from "graphics"' needs to create a symbol that combines the value side 'Point'
13711377
// property with the type/namespace side interface 'Point'.
13721378
function combineValueAndTypeSymbols(valueSymbol: Symbol, typeSymbol: Symbol): Symbol {
1379+
if (valueSymbol === unknownSymbol && typeSymbol === unknownSymbol) {
1380+
return unknownSymbol;
1381+
}
13731382
if (valueSymbol.flags & (SymbolFlags.Type | SymbolFlags.Namespace)) {
13741383
return valueSymbol;
13751384
}
@@ -2288,7 +2297,7 @@ namespace ts {
22882297

22892298
function typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string {
22902299
const typeNode = nodeBuilder.typeToTypeNode(type, enclosingDeclaration, toNodeBuilderFlags(flags) | NodeBuilderFlags.IgnoreErrors | NodeBuilderFlags.WriteTypeParametersInQualifiedName);
2291-
Debug.assert(typeNode !== undefined, "should always get typenode?");
2300+
Debug.assert(typeNode !== undefined, "should always get typenode");
22922301
const options = { removeComments: true };
22932302
const writer = createTextWriter("");
22942303
const printer = createPrinter(options);
@@ -5847,7 +5856,8 @@ namespace ts {
58475856
}
58485857
}
58495858
return arrayFrom(props.values());
5850-
} else {
5859+
}
5860+
else {
58515861
return getPropertiesOfType(type);
58525862
}
58535863
}
@@ -8362,12 +8372,6 @@ namespace ts {
83628372
/**
83638373
* This is *not* a bi-directional relationship.
83648374
* If one needs to check both directions for comparability, use a second call to this function or 'checkTypeComparableTo'.
8365-
*
8366-
* A type S is comparable to a type T if some (but not necessarily all) of the possible values of S are also possible values of T.
8367-
* It is used to check following cases:
8368-
* - the types of the left and right sides of equality/inequality operators (`===`, `!==`, `==`, `!=`).
8369-
* - the types of `case` clause expressions and their respective `switch` expressions.
8370-
* - the type of an expression in a type assertion with the type being asserted.
83718375
*/
83728376
function isTypeComparableTo(source: Type, target: Type): boolean {
83738377
return isTypeRelatedTo(source, target, comparableRelation);
@@ -14163,7 +14167,7 @@ namespace ts {
1416314167
checkJsxPreconditions(node);
1416414168
// The reactNamespace/jsxFactory's root symbol should be marked as 'used' so we don't incorrectly elide its import.
1416514169
// And if there is no reactNamespace/jsxFactory's symbol in scope when targeting React emit, we should issue an error.
14166-
const reactRefErr = compilerOptions.jsx === JsxEmit.React ? Diagnostics.Cannot_find_name_0 : undefined;
14170+
const reactRefErr = diagnostics && compilerOptions.jsx === JsxEmit.React ? Diagnostics.Cannot_find_name_0 : undefined;
1416714171
const reactNamespace = getJsxNamespace();
1416814172
const reactSym = resolveName(node.tagName, reactNamespace, SymbolFlags.Value, reactRefErr, reactNamespace);
1416914173
if (reactSym) {
@@ -14534,6 +14538,7 @@ namespace ts {
1453414538
const maximumLengthDifference = Math.min(3, name.length * 0.34);
1453514539
let bestDistance = Number.MAX_VALUE;
1453614540
let bestCandidate = undefined;
14541+
let justCheckExactMatches = false;
1453714542
if (name.length > 30) {
1453814543
return undefined;
1453914544
}
@@ -14546,6 +14551,9 @@ namespace ts {
1454614551
if (candidateName === name) {
1454714552
return candidate;
1454814553
}
14554+
if (justCheckExactMatches) {
14555+
continue;
14556+
}
1454914557
if (candidateName.length < 3 ||
1455014558
name.length < 3 ||
1455114559
candidateName === "eval" ||
@@ -14561,7 +14569,8 @@ namespace ts {
1456114569
continue;
1456214570
}
1456314571
if (distance < 3) {
14564-
return candidate;
14572+
justCheckExactMatches = true;
14573+
bestCandidate = candidate;
1456514574
}
1456614575
else if (distance < bestDistance) {
1456714576
bestDistance = distance;
@@ -16170,35 +16179,6 @@ namespace ts {
1617016179
return getReturnTypeOfSignature(signature);
1617116180
}
1617216181

16173-
function checkImportCallExpression(node: ImportCall): Type {
16174-
// Check grammar of dynamic import
16175-
checkGrammarArguments(node, node.arguments) || checkGrammarImportCallExpression(node);
16176-
16177-
if (node.arguments.length === 0) {
16178-
return createPromiseReturnType(node, anyType);
16179-
}
16180-
const specifier = node.arguments[0];
16181-
const specifierType = checkExpressionCached(specifier);
16182-
// Even though multiple arugments is grammatically incorrect, type-check extra arguments for completion
16183-
for (let i = 1; i < node.arguments.length; ++i) {
16184-
checkExpressionCached(node.arguments[i]);
16185-
}
16186-
16187-
if (specifierType.flags & TypeFlags.Undefined || specifierType.flags & TypeFlags.Null || !isTypeAssignableTo(specifierType, stringType)) {
16188-
error(specifier, Diagnostics.Dynamic_import_s_specifier_must_be_of_type_string_but_here_has_type_0, typeToString(specifierType));
16189-
}
16190-
16191-
// resolveExternalModuleName will return undefined if the moduleReferenceExpression is not a string literal
16192-
const moduleSymbol = resolveExternalModuleName(node, specifier);
16193-
if (moduleSymbol) {
16194-
const esModuleSymbol = resolveESModuleSymbol(moduleSymbol, specifier, /*dontRecursivelyResolve*/ true);
16195-
if (esModuleSymbol) {
16196-
return createPromiseReturnType(node, getTypeOfSymbol(esModuleSymbol));
16197-
}
16198-
}
16199-
return createPromiseReturnType(node, anyType);
16200-
}
16201-
1620216182
function isCommonJsRequire(node: Node) {
1620316183
if (!isRequireCall(node, /*checkArgumentIsStringLiteral*/ true)) {
1620416184
return false;
@@ -16405,18 +16385,14 @@ namespace ts {
1640516385
return emptyObjectType;
1640616386
}
1640716387

16408-
function createPromiseReturnType(func: FunctionLikeDeclaration | ImportCall, promisedType: Type) {
16388+
function createPromiseReturnType(func: FunctionLikeDeclaration, promisedType: Type) {
1640916389
const promiseType = createPromiseType(promisedType);
1641016390
if (promiseType === emptyObjectType) {
16411-
error(func, isImportCall(func) ?
16412-
Diagnostics.A_dynamic_import_call_returns_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option :
16413-
Diagnostics.An_async_function_or_method_must_return_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option);
16391+
error(func, Diagnostics.An_async_function_or_method_must_return_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option);
1641416392
return unknownType;
1641516393
}
1641616394
else if (!getGlobalPromiseConstructorSymbol(/*reportErrors*/ true)) {
16417-
error(func, isImportCall(func) ?
16418-
Diagnostics.A_dynamic_import_call_in_ES5_SlashES3_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option :
16419-
Diagnostics.An_async_function_or_method_in_ES5_SlashES3_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option);
16395+
error(func, Diagnostics.An_async_function_or_method_in_ES5_SlashES3_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option);
1642016396
}
1642116397

1642216398
return promiseType;
@@ -17775,10 +17751,6 @@ namespace ts {
1777517751
case SyntaxKind.ElementAccessExpression:
1777617752
return checkIndexedAccess(<ElementAccessExpression>node);
1777717753
case SyntaxKind.CallExpression:
17778-
if ((<CallExpression>node).expression.kind === SyntaxKind.ImportKeyword) {
17779-
return checkImportCallExpression(<ImportCall>node);
17780-
}
17781-
/* falls through */
1778217754
case SyntaxKind.NewExpression:
1778317755
return checkCallExpression(<CallExpression>node);
1778417756
case SyntaxKind.TaggedTemplateExpression:
@@ -24704,27 +24676,6 @@ namespace ts {
2470424676
});
2470524677
return result;
2470624678
}
24707-
24708-
function checkGrammarImportCallExpression(node: ImportCall): boolean {
24709-
if (modulekind === ModuleKind.ES2015) {
24710-
return grammarErrorOnNode(node, Diagnostics.Dynamic_import_cannot_be_used_when_targeting_ECMAScript_2015_modules);
24711-
}
24712-
24713-
if (node.typeArguments) {
24714-
return grammarErrorOnNode(node, Diagnostics.Dynamic_import_cannot_have_type_arguments);
24715-
}
24716-
24717-
const arguments = node.arguments;
24718-
if (arguments.length !== 1) {
24719-
return grammarErrorOnNode(node, Diagnostics.Dynamic_import_must_have_one_specifier_as_an_argument);
24720-
}
24721-
24722-
// see: parseArgumentOrArrayLiteralElement...we use this function which parse arguments of callExpression to parse specifier for dynamic import.
24723-
// parseArgumentOrArrayLiteralElement allows spread element to be in an argument list which is not allowed as specifier in dynamic import.
24724-
if (isSpreadElement(arguments[0])) {
24725-
return grammarErrorOnNode(arguments[0], Diagnostics.Specifier_of_dynamic_import_cannot_be_spread_element);
24726-
}
24727-
}
2472824679
}
2472924680

2473024681
/** Like 'isDeclarationName', but returns true for LHS of `import { x as y }` or `export { x as y }`. */

src/compiler/commandLineParser.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,11 @@ namespace ts {
100100
"umd": ModuleKind.UMD,
101101
"es6": ModuleKind.ES2015,
102102
"es2015": ModuleKind.ES2015,
103-
"esnext": ModuleKind.ESNext
104103
}),
105104
paramType: Diagnostics.KIND,
106105
showInSimplifiedHelpView: true,
107106
category: Diagnostics.Basic_Options,
108-
description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_umd_es2015_or_ESNext,
107+
description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es2015,
109108
},
110109
{
111110
name: "lib",

src/compiler/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ namespace ts {
473473
* @param array The array to map.
474474
* @param mapfn The callback used to map the result into one or more values.
475475
*/
476-
export function flatMap<T, U>(array: T[], mapfn: (x: T, i: number) => U | U[]): U[] {
476+
export function flatMap<T, U>(array: T[] | undefined, mapfn: (x: T, i: number) => U | U[] | undefined): U[] | undefined {
477477
let result: U[];
478478
if (array) {
479479
result = [];

src/compiler/diagnosticMessages.json

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -883,31 +883,14 @@
883883
"category": "Error",
884884
"code": 1322
885885
},
886-
"Dynamic import cannot be used when targeting ECMAScript 2015 modules.": {
887-
"category": "Error",
888-
"code": 1323
889-
},
890-
"Dynamic import must have one specifier as an argument.": {
891-
"category": "Error",
892-
"code": 1324
893-
},
894-
"Specifier of dynamic import cannot be spread element.": {
895-
"category": "Error",
896-
"code": 1325
897-
},
898-
"Dynamic import cannot have type arguments": {
899-
"category": "Error",
900-
"code": 1326
901-
},
902886
"String literal with double quotes expected.": {
903887
"category": "Error",
904-
"code": 1327
888+
"code": 1323
905889
},
906890
"Property value can only be string literal, numeric literal, 'true', 'false', 'null', object literal or array literal.": {
907891
"category": "Error",
908-
"code": 1328
892+
"code": 1324
909893
},
910-
911894
"Duplicate identifier '{0}'.": {
912895
"category": "Error",
913896
"code": 2300
@@ -1952,6 +1935,10 @@
19521935
"category": "Error",
19531936
"code": 2649
19541937
},
1938+
"Cannot emit namespaced JSX elements in React.": {
1939+
"category": "Error",
1940+
"code": 2650
1941+
},
19551942
"A member initializer in a enum declaration cannot reference members declared after it, including members defined in other enums.": {
19561943
"category": "Error",
19571944
"code": 2651
@@ -2184,14 +2171,6 @@
21842171
"category": "Error",
21852172
"code": 2710
21862173
},
2187-
"A dynamic import call returns a 'Promise'. Make sure you have a declaration for 'Promise' or include 'ES2015' in your `--lib` option.": {
2188-
"category": "Error",
2189-
"code": 2711
2190-
},
2191-
"A dynamic import call in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your `--lib` option.": {
2192-
"category": "Error",
2193-
"code": 2712
2194-
},
21952174

21962175
"Import declaration '{0}' is using private name '{1}'.": {
21972176
"category": "Error",
@@ -2658,7 +2637,7 @@
26582637
"category": "Message",
26592638
"code": 6015
26602639
},
2661-
"Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'.": {
2640+
"Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'.": {
26622641
"category": "Message",
26632642
"code": 6016
26642643
},
@@ -3394,11 +3373,6 @@
33943373
"category": "Error",
33953374
"code": 7035
33963375
},
3397-
"Dynamic import's specifier must be of type 'string', but here has type '{0}'.": {
3398-
"category": "Error",
3399-
"code": 7036
3400-
},
3401-
34023376
"You cannot rename this element.": {
34033377
"category": "Error",
34043378
"code": 8000
@@ -3593,11 +3567,11 @@
35933567
"category": "Message",
35943568
"code": 90015
35953569
},
3596-
"Add declaration for missing property '{0}'.": {
3570+
"Declare property '{0}'.": {
35973571
"category": "Message",
35983572
"code": 90016
35993573
},
3600-
"Add index signature for missing property '{0}'.": {
3574+
"Add index signature for property '{0}'.": {
36013575
"category": "Message",
36023576
"code": 90017
36033577
},
@@ -3621,7 +3595,15 @@
36213595
"category": "Message",
36223596
"code": 90022
36233597
},
3624-
3598+
"Declare method '{0}'.": {
3599+
"category": "Message",
3600+
"code": 90023
3601+
},
3602+
"Declare static method '{0}'.": {
3603+
"category": "Message",
3604+
"code": 90024
3605+
},
3606+
36253607
"Convert function to an ES2015 class": {
36263608
"category": "Message",
36273609
"code": 95001

src/compiler/emitter.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,6 @@ namespace ts {
740740
case SyntaxKind.SuperKeyword:
741741
case SyntaxKind.TrueKeyword:
742742
case SyntaxKind.ThisKeyword:
743-
case SyntaxKind.ImportKeyword:
744743
writeTokenNode(node);
745744
return;
746745

src/compiler/factory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,8 +2495,8 @@ namespace ts {
24952495
helpers
24962496
} = sourceEmitNode;
24972497
if (!destEmitNode) destEmitNode = {};
2498-
if (leadingComments) destEmitNode.leadingComments = addRange(leadingComments.slice(), destEmitNode.leadingComments);
2499-
if (trailingComments) destEmitNode.trailingComments = addRange(trailingComments.slice(), destEmitNode.trailingComments);
2498+
if (leadingComments) destEmitNode.leadingComments = concatenate(leadingComments, destEmitNode.leadingComments);
2499+
if (trailingComments) destEmitNode.trailingComments = concatenate(trailingComments, destEmitNode.trailingComments);
25002500
if (flags) destEmitNode.flags = flags;
25012501
if (commentRange) destEmitNode.commentRange = commentRange;
25022502
if (sourceMapRange) destEmitNode.sourceMapRange = sourceMapRange;

0 commit comments

Comments
 (0)