Skip to content

Commit 449b6e6

Browse files
committed
Fix Go To Source Definition in --moduleResolution bundler
1 parent 710e7d9 commit 449b6e6

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

src/compiler/checker.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -4149,7 +4149,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
41494149
if (!isIdentifier(name)) {
41504150
return undefined;
41514151
}
4152-
const suppressInteropError = name.escapedText === InternalSymbolName.Default && !!(compilerOptions.allowSyntheticDefaultImports || getESModuleInterop(compilerOptions));
4152+
const suppressInteropError = name.escapedText === InternalSymbolName.Default && !!(getAllowSyntheticDefaultImports(compilerOptions));
41534153
const targetSymbol = resolveESModuleSymbol(moduleSymbol, moduleSpecifier, /*dontResolveAlias*/ false, suppressInteropError);
41544154
if (targetSymbol) {
41554155
if (name.escapedText) {
@@ -9204,7 +9204,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
92049204
// If `target` refers to a shorthand module symbol, the name we're trying to pull out isn;t recoverable from the target symbol
92059205
// In such a scenario, we must fall back to looking for an alias declaration on `symbol` and pulling the target name from that
92069206
let verbatimTargetName = isShorthandAmbientModuleSymbol(target) && getSomeTargetNameFromDeclarations(symbol.declarations) || unescapeLeadingUnderscores(target.escapedName);
9207-
if (verbatimTargetName === InternalSymbolName.ExportEquals && (getESModuleInterop(compilerOptions) || compilerOptions.allowSyntheticDefaultImports)) {
9207+
if (verbatimTargetName === InternalSymbolName.ExportEquals && getAllowSyntheticDefaultImports(compilerOptions)) {
92089208
// target refers to an `export=` symbol that was hoisted into a synthetic default - rename here to match
92099209
verbatimTargetName = InternalSymbolName.Default;
92109210
}
@@ -34163,7 +34163,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3416334163
}
3416434164

3416534165
// In JavaScript files, calls to any identifier 'require' are treated as external module imports
34166-
if (isInJSFile(node) && getEmitModuleResolutionKind(compilerOptions) !== ModuleResolutionKind.Bundler && isCommonJsRequire(node)) {
34166+
if (isInJSFile(node) && (getEmitModuleResolutionKind(compilerOptions) !== ModuleResolutionKind.Bundler || compilerOptions.noDtsResolution) && isCommonJsRequire(node)) {
34167+
// `bundler` doesn't support resolving `require`, but needs to in `noDtsResolution` to support Find Source Definition
3416734168
return resolveExternalModuleTypeByLiteral(node.arguments![0] as StringLiteral);
3416834169
}
3416934170

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/// <reference path="../fourslash.ts" />
2+
3+
// @Filename: /tsconfig.json
4+
//// { "compilerOptions": { "module": "esnext", "moduleResolution": "bundler" } }
5+
6+
// @Filename: /node_modules/react/package.json
7+
//// { "name": "react", "version": "16.8.6", "main": "index.js" }
8+
9+
// @Filename: /node_modules/react/index.js
10+
//// 'use strict';
11+
////
12+
//// if (process.env.NODE_ENV === 'production') {
13+
//// module.exports = require('./cjs/react.production.min.js');
14+
//// } else {
15+
//// module.exports = require('./cjs/react.development.js');
16+
//// }
17+
18+
// @Filename: /node_modules/react/cjs/react.production.min.js
19+
//// 'use strict';exports./*production*/useState=function(a){};exports.version='16.8.6';
20+
21+
// @Filename: /node_modules/react/cjs/react.development.js
22+
//// 'use strict';
23+
//// if (process.env.NODE_ENV !== 'production') {
24+
//// (function() {
25+
//// function useState(initialState) {}
26+
//// exports./*development*/useState = useState;
27+
//// exports.version = '16.8.6';
28+
//// }());
29+
//// }
30+
31+
// @Filename: /index.ts
32+
//// import { [|/*start*/useState|] } from 'react';
33+
34+
verify.baselineGoToSourceDefinition("start");

0 commit comments

Comments
 (0)