From d8280d88072f2694df39f112eb8b60f1a6be1c0f Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 5 Oct 2016 17:19:38 -0700 Subject: [PATCH] Handle the require call in javascript file for getSymbolAtLocation This helps in getting the alias symbol so that it can go to the definition of external module Fixes #9251 --- src/compiler/checker.ts | 3 +++ tests/cases/fourslash/goToDefinitionJsModuleName.ts | 12 ++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 tests/cases/fourslash/goToDefinitionJsModuleName.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0ba65d6e61a..03d8259bcfc 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -18167,6 +18167,9 @@ namespace ts { (node.parent).moduleSpecifier === node)) { return resolveExternalModuleName(node, node); } + if (isInJavaScriptFile(node) && isRequireCall(node.parent, /*checkArgumentIsStringLiteral*/ false)) { + return resolveExternalModuleName(node, node); + } // Fall through case SyntaxKind.NumericLiteral: diff --git a/tests/cases/fourslash/goToDefinitionJsModuleName.ts b/tests/cases/fourslash/goToDefinitionJsModuleName.ts new file mode 100644 index 00000000000..eac4bc8053d --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionJsModuleName.ts @@ -0,0 +1,12 @@ +/// + +// @allowJs: true +// @Filename: foo.js +/////*2*/module.exports = {}; + +// @Filename: bar.js +////var x = require(/*1*/"./foo"); + +goTo.marker("1"); +goTo.definition(); +verify.caretAtMarker("2"); \ No newline at end of file