From 18969b024d45287d421e32736dc91511723b72be Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 4 Oct 2016 16:29:51 -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 | 11 +++++++++++ 2 files changed, 14 insertions(+) create mode 100644 tests/cases/fourslash/goToDefinitionJsModuleName.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 422f2a70dcc..29f2a874926 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -18436,6 +18436,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..1480aa2c5a1 --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionJsModuleName.ts @@ -0,0 +1,11 @@ +/// + +// @allowJs: true +// @Filename: foo.js +/////*2*/module.exports = {}; + +// @Filename: bar.js +////var x = require(/*1*/"./foo"); + +debugger; +verify.goToDefinition("1", "2");