Implement LS on string-literal of dynamic import

This commit is contained in:
Kanchalai Tanglertsampan 2017-06-09 10:01:17 -07:00
parent cae1286b72
commit 2e55b6ae16
4 changed files with 28 additions and 7 deletions

View File

@ -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) &&
(<ImportDeclaration>node.parent).moduleSpecifier === node)) {
// import x = require("./mo/*gotToDefinitionHere*/d")
if (isExternalModuleImportEqualsDeclaration(node.parent.parent) && getExternalModuleImportEqualsDeclarationExpression(node.parent.parent) === node) {
return resolveExternalModuleName(node, <LiteralExpression>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) && (<ImportDeclaration>node.parent).moduleSpecifier === node) {
return resolveExternalModuleName(node, <LiteralExpression>node);
}
if ((isInJavaScriptFile(node) && isRequireCall(node.parent, /*checkArgumentIsStringLiteral*/ false)) ||
isImportCall(node.parent)) {
return resolveExternalModuleName(node, <LiteralExpression>node);
}
// falls through

View File

@ -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;
}

View File

@ -0,0 +1,9 @@
/// <reference path='fourslash.ts' />
// @Filename: foo.ts
//// export function foo() { return "foo"; }
//// import("[|./foo|]")
//// var x = import("[|./foo|]")
verify.rangesReferenceEachOther();

View File

@ -0,0 +1,10 @@
/// <reference path='fourslash.ts' />
// @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");