Skip to content

Commit 2e55b6a

Browse files
author
Kanchalai Tanglertsampan
committed
Implement LS on string-literal of dynamic import
1 parent cae1286 commit 2e55b6a

4 files changed

Lines changed: 27 additions & 6 deletions

File tree

src/compiler/checker.ts

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

2266722667
case SyntaxKind.StringLiteral:
22668+
// import x = require("./mo/*gotToDefinitionHere*/d")
22669+
if (isExternalModuleImportEqualsDeclaration(node.parent.parent) && getExternalModuleImportEqualsDeclarationExpression(node.parent.parent) === node) {
22670+
return resolveExternalModuleName(node, <LiteralExpression>node);
22671+
}
2266822672
// External module name in an import declaration
22669-
if ((isExternalModuleImportEqualsDeclaration(node.parent.parent) &&
22670-
getExternalModuleImportEqualsDeclarationExpression(node.parent.parent) === node) ||
22671-
((node.parent.kind === SyntaxKind.ImportDeclaration || node.parent.kind === SyntaxKind.ExportDeclaration) &&
22672-
(<ImportDeclaration>node.parent).moduleSpecifier === node)) {
22673+
if ((node.parent.kind === SyntaxKind.ImportDeclaration || node.parent.kind === SyntaxKind.ExportDeclaration) && (<ImportDeclaration>node.parent).moduleSpecifier === node) {
2267322674
return resolveExternalModuleName(node, <LiteralExpression>node);
2267422675
}
22675-
if (isInJavaScriptFile(node) && isRequireCall(node.parent, /*checkArgumentIsStringLiteral*/ false)) {
22676+
if ((isInJavaScriptFile(node) && isRequireCall(node.parent, /*checkArgumentIsStringLiteral*/ false)) ||
22677+
isImportCall(node.parent)) {
2267622678
return resolveExternalModuleName(node, <LiteralExpression>node);
2267722679
}
2267822680
// 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)