@@ -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 }`. */
0 commit comments