diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 846f7692a0c..c8a99b0bbb2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -22665,14 +22665,16 @@ namespace ts { return undefined; case SyntaxKind.StringLiteral: - // External module name in an import declaration - if ((isExternalModuleImportEqualsDeclaration(node.parent.parent) && - getExternalModuleImportEqualsDeclarationExpression(node.parent.parent) === node) || - ((node.parent.kind === SyntaxKind.ImportDeclaration || node.parent.kind === SyntaxKind.ExportDeclaration) && - (node.parent).moduleSpecifier === node)) { + // import x = require("./mo/*gotToDefinitionHere*/d") + if (isExternalModuleImportEqualsDeclaration(node.parent.parent) && getExternalModuleImportEqualsDeclarationExpression(node.parent.parent) === node) { return resolveExternalModuleName(node, node); } - if (isInJavaScriptFile(node) && isRequireCall(node.parent, /*checkArgumentIsStringLiteral*/ false)) { + // External module name in an import declaration + if ((node.parent.kind === SyntaxKind.ImportDeclaration || node.parent.kind === SyntaxKind.ExportDeclaration) && (node.parent).moduleSpecifier === node) { + return resolveExternalModuleName(node, node); + } + if ((isInJavaScriptFile(node) && isRequireCall(node.parent, /*checkArgumentIsStringLiteral*/ false)) || + isImportCall(node.parent)) { return resolveExternalModuleName(node, node); } // falls through diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index 67a967ec8b9..b312aa064f9 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -307,7 +307,7 @@ namespace ts.FindAllReferences.Core { case SyntaxKind.ExportDeclaration: return true; case SyntaxKind.CallExpression: - return isRequireCall(node.parent as CallExpression, /*checkArgumentIsStringLiteral*/ false); + return isRequireCall(node.parent as CallExpression, /*checkArgumentIsStringLiteral*/ false) || isImportCall(node.parent as CallExpression); default: return false; } diff --git a/tests/cases/fourslash/findAllReferencesDynamicImport1.ts b/tests/cases/fourslash/findAllReferencesDynamicImport1.ts new file mode 100644 index 00000000000..ad0f261388d --- /dev/null +++ b/tests/cases/fourslash/findAllReferencesDynamicImport1.ts @@ -0,0 +1,9 @@ +/// + +// @Filename: foo.ts +//// export function foo() { return "foo"; } + +//// import("[|./foo|]") +//// var x = import("[|./foo|]") + +verify.rangesReferenceEachOther(); \ No newline at end of file diff --git a/tests/cases/fourslash/goToDefinitionDynamicImport1.ts b/tests/cases/fourslash/goToDefinitionDynamicImport1.ts new file mode 100644 index 00000000000..2e93534496a --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionDynamicImport1.ts @@ -0,0 +1,10 @@ +/// + +// @Filename: foo.ts +//// /*Destination*/export function foo() { return "foo"; } + +//// import("./f/*1*/oo") +//// var x = import("./fo/*2*/o") + +verify.goToDefinition("1", "Destination"); +verify.goToDefinition("2", "Destination"); \ No newline at end of file