Skip to content

Commit 045a87f

Browse files
committed
fix #3887: omit dead export warning for default
1 parent 6e049b8 commit 045a87f

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

internal/bundler_tests/bundler_packagejson_test.go

+33
Original file line numberDiff line numberDiff line change
@@ -3002,3 +3002,36 @@ node_modules/foo/package.json: NOTE: The "default" condition comes earlier and w
30023002
`,
30033003
})
30043004
}
3005+
3006+
// See: https://github.com/evanw/esbuild/issues/3887
3007+
func TestPackageJsonExportsDefaultWarningIssue3887(t *testing.T) {
3008+
packagejson_suite.expectBundled(t, bundled{
3009+
files: map[string]string{
3010+
"/entry.js": `
3011+
import "foo"
3012+
`,
3013+
"/node_modules/foo/dist/index.js": `
3014+
success()
3015+
`,
3016+
"/node_modules/foo/package.json": `
3017+
{
3018+
"exports": {
3019+
".": {
3020+
"node": "./dist/index.js",
3021+
"require": "./dist/index.js",
3022+
"import": "./dist/index.esm.js",
3023+
"default": "./dist/index.esm.js"
3024+
}
3025+
}
3026+
}
3027+
`,
3028+
},
3029+
entryPaths: []string{"/entry.js"},
3030+
options: config.Options{
3031+
Mode: config.ModeBundle,
3032+
Platform: config.PlatformNode,
3033+
AbsOutputFile: "/out.js",
3034+
},
3035+
debugLogs: true,
3036+
})
3037+
}

internal/bundler_tests/snapshots/snapshots_packagejson.txt

+6
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,12 @@ TestPackageJsonExportsDefaultOverImportAndRequire
585585
// Users/user/project/node_modules/pkg/default.js
586586
console.log("SUCCESS");
587587

588+
================================================================================
589+
TestPackageJsonExportsDefaultWarningIssue3887
590+
---------- /out.js ----------
591+
// node_modules/foo/dist/index.js
592+
success();
593+
588594
================================================================================
589595
TestPackageJsonExportsEntryPointImportOverRequire
590596
---------- /out.js ----------

internal/resolver/package_json.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,8 @@ func parseImportsExportsMap(source logger.Source, log logger.Log, json js_ast.Ex
710710
// Track "dead" conditional branches that can never be reached
711711
if foundDefault.Len != 0 || (foundImport.Len != 0 && foundRequire.Len != 0) {
712712
deadCondition.ranges = append(deadCondition.ranges, keyRange)
713-
if deadCondition.reason == "" {
713+
// Note: Don't warn about the "default" condition as it's supposed to be a catch-all condition
714+
if deadCondition.reason == "" && key != "default" {
714715
if foundDefault.Len != 0 {
715716
deadCondition.reason = "\"default\""
716717
deadCondition.notes = []logger.MsgData{

0 commit comments

Comments
 (0)