@@ -216,6 +216,11 @@ namespace ts {
216
216
getSuggestionForNonexistentProperty,
217
217
getSuggestionForNonexistentSymbol,
218
218
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
+ },
219
224
};
220
225
221
226
const tupleTypes: GenericType[] = [];
@@ -741,6 +746,7 @@ namespace ts {
741
746
if (declarationFile !== useFile) {
742
747
if ((modulekind && (declarationFile.externalModuleIndicator || useFile.externalModuleIndicator)) ||
743
748
(!compilerOptions.outFile && !compilerOptions.out) ||
749
+ isInTypeQuery(usage) ||
744
750
isInAmbientContext(declaration)) {
745
751
// nodes are in different files and order cannot be determined
746
752
return true;
@@ -853,7 +859,7 @@ namespace ts {
853
859
location: Node | undefined,
854
860
name: string,
855
861
meaning: SymbolFlags,
856
- nameNotFoundMessage: DiagnosticMessage,
862
+ nameNotFoundMessage: DiagnosticMessage | undefined ,
857
863
nameArg: string | Identifier,
858
864
suggestedNameNotFoundMessage?: DiagnosticMessage): Symbol {
859
865
return resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, getSymbol, suggestedNameNotFoundMessage);
@@ -1370,6 +1376,9 @@ namespace ts {
1370
1376
// An 'import { Point } from "graphics"' needs to create a symbol that combines the value side 'Point'
1371
1377
// property with the type/namespace side interface 'Point'.
1372
1378
function combineValueAndTypeSymbols(valueSymbol: Symbol, typeSymbol: Symbol): Symbol {
1379
+ if (valueSymbol === unknownSymbol && typeSymbol === unknownSymbol) {
1380
+ return unknownSymbol;
1381
+ }
1373
1382
if (valueSymbol.flags & (SymbolFlags.Type | SymbolFlags.Namespace)) {
1374
1383
return valueSymbol;
1375
1384
}
@@ -2288,7 +2297,7 @@ namespace ts {
2288
2297
2289
2298
function typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string {
2290
2299
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");
2292
2301
const options = { removeComments: true };
2293
2302
const writer = createTextWriter("");
2294
2303
const printer = createPrinter(options);
@@ -5847,7 +5856,8 @@ namespace ts {
5847
5856
}
5848
5857
}
5849
5858
return arrayFrom(props.values());
5850
- } else {
5859
+ }
5860
+ else {
5851
5861
return getPropertiesOfType(type);
5852
5862
}
5853
5863
}
@@ -8362,12 +8372,6 @@ namespace ts {
8362
8372
/**
8363
8373
* This is *not* a bi-directional relationship.
8364
8374
* 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.
8371
8375
*/
8372
8376
function isTypeComparableTo(source: Type, target: Type): boolean {
8373
8377
return isTypeRelatedTo(source, target, comparableRelation);
@@ -14163,7 +14167,7 @@ namespace ts {
14163
14167
checkJsxPreconditions(node);
14164
14168
// The reactNamespace/jsxFactory's root symbol should be marked as 'used' so we don't incorrectly elide its import.
14165
14169
// 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;
14167
14171
const reactNamespace = getJsxNamespace();
14168
14172
const reactSym = resolveName(node.tagName, reactNamespace, SymbolFlags.Value, reactRefErr, reactNamespace);
14169
14173
if (reactSym) {
@@ -14534,6 +14538,7 @@ namespace ts {
14534
14538
const maximumLengthDifference = Math.min(3, name.length * 0.34);
14535
14539
let bestDistance = Number.MAX_VALUE;
14536
14540
let bestCandidate = undefined;
14541
+ let justCheckExactMatches = false;
14537
14542
if (name.length > 30) {
14538
14543
return undefined;
14539
14544
}
@@ -14546,6 +14551,9 @@ namespace ts {
14546
14551
if (candidateName === name) {
14547
14552
return candidate;
14548
14553
}
14554
+ if (justCheckExactMatches) {
14555
+ continue;
14556
+ }
14549
14557
if (candidateName.length < 3 ||
14550
14558
name.length < 3 ||
14551
14559
candidateName === "eval" ||
@@ -14561,7 +14569,8 @@ namespace ts {
14561
14569
continue;
14562
14570
}
14563
14571
if (distance < 3) {
14564
- return candidate;
14572
+ justCheckExactMatches = true;
14573
+ bestCandidate = candidate;
14565
14574
}
14566
14575
else if (distance < bestDistance) {
14567
14576
bestDistance = distance;
@@ -16170,35 +16179,6 @@ namespace ts {
16170
16179
return getReturnTypeOfSignature(signature);
16171
16180
}
16172
16181
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
-
16202
16182
function isCommonJsRequire(node: Node) {
16203
16183
if (!isRequireCall(node, /*checkArgumentIsStringLiteral*/ true)) {
16204
16184
return false;
@@ -16405,18 +16385,14 @@ namespace ts {
16405
16385
return emptyObjectType;
16406
16386
}
16407
16387
16408
- function createPromiseReturnType(func: FunctionLikeDeclaration | ImportCall , promisedType: Type) {
16388
+ function createPromiseReturnType(func: FunctionLikeDeclaration, promisedType: Type) {
16409
16389
const promiseType = createPromiseType(promisedType);
16410
16390
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);
16414
16392
return unknownType;
16415
16393
}
16416
16394
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);
16420
16396
}
16421
16397
16422
16398
return promiseType;
@@ -17775,10 +17751,6 @@ namespace ts {
17775
17751
case SyntaxKind.ElementAccessExpression:
17776
17752
return checkIndexedAccess(<ElementAccessExpression>node);
17777
17753
case SyntaxKind.CallExpression:
17778
- if ((<CallExpression>node).expression.kind === SyntaxKind.ImportKeyword) {
17779
- return checkImportCallExpression(<ImportCall>node);
17780
- }
17781
- /* falls through */
17782
17754
case SyntaxKind.NewExpression:
17783
17755
return checkCallExpression(<CallExpression>node);
17784
17756
case SyntaxKind.TaggedTemplateExpression:
@@ -24704,27 +24676,6 @@ namespace ts {
24704
24676
});
24705
24677
return result;
24706
24678
}
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
- }
24728
24679
}
24729
24680
24730
24681
/** Like 'isDeclarationName', but returns true for LHS of `import { x as y }` or `export { x as y }`. */
0 commit comments