Skip to content

Commit 6842520

Browse files
author
Kanchalai Tanglertsampan
committed
Implement LS on string-literal of dynamic import
1 parent 985682d commit 6842520

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22645,14 +22645,16 @@ namespace ts {
2264522645
return undefined;
2264622646

2264722647
case SyntaxKind.StringLiteral:
22648+
// import x = require("./mo/*gotToDefinitionHere*/d")
22649+
if (isExternalModuleImportEqualsDeclaration(node.parent.parent) && getExternalModuleImportEqualsDeclarationExpression(node.parent.parent) === node) {
22650+
return resolveExternalModuleName(node, <LiteralExpression>node);
22651+
}
2264822652
// External module name in an import declaration
22649-
if ((isExternalModuleImportEqualsDeclaration(node.parent.parent) &&
22650-
getExternalModuleImportEqualsDeclarationExpression(node.parent.parent) === node) ||
22651-
((node.parent.kind === SyntaxKind.ImportDeclaration || node.parent.kind === SyntaxKind.ExportDeclaration) &&
22652-
(<ImportDeclaration>node.parent).moduleSpecifier === node)) {
22653+
if ((node.parent.kind === SyntaxKind.ImportDeclaration || node.parent.kind === SyntaxKind.ExportDeclaration) && (<ImportDeclaration>node.parent).moduleSpecifier === node) {
2265322654
return resolveExternalModuleName(node, <LiteralExpression>node);
2265422655
}
22655-
if (isInJavaScriptFile(node) && isRequireCall(node.parent, /*checkArgumentIsStringLiteral*/ false)) {
22656+
if ((isInJavaScriptFile(node) && isRequireCall(node.parent, /*checkArgumentIsStringLiteral*/ false)) ||
22657+
isImportCall(node.parent)) {
2265622658
return resolveExternalModuleName(node, <LiteralExpression>node);
2265722659
}
2265822660
// falls through

src/services/findAllReferences.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ namespace ts.FindAllReferences.Core {
307307
case SyntaxKind.ExportDeclaration:
308308
return true;
309309
case SyntaxKind.CallExpression:
310-
return isRequireCall(node.parent as CallExpression, /*checkArgumentIsStringLiteral*/ false);
310+
return isRequireCall(node.parent as CallExpression, /*checkArgumentIsStringLiteral*/ false) || isImportCall(node.parent as CallExpression);
311311
default:
312312
return false;
313313
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @Filename: foo.ts
4+
//// export function foo() { return "foo"; }
5+
6+
//// import("[|./foo|]")
7+
//// var x = import("[|./foo|]")
8+
9+
verify.rangesReferenceEachOther();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @Filename: foo.ts
4+
//// /*Destination*/export function foo() { return "foo"; }
5+
6+
//// import("./f/*1*/oo")
7+
//// var x = import("./fo/*2*/o")
8+
9+
verify.goToDefinition("1", "Destination");
10+
verify.goToDefinition("2", "Destination");

0 commit comments

Comments
 (0)