Skip to content

Commit

Permalink
fix #2041: add text loader data to source maps
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Jun 26, 2023
1 parent 9ed47f5 commit 7e10dd6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions internal/bundler_tests/bundler_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1318,12 +1318,16 @@ func TestSourceMap(t *testing.T) {
files: map[string]string{
"/Users/user/project/src/entry.js": `
import {bar} from './bar'
import data from './data.txt'
function foo() { bar() }
foo()
console.log(data)
`,
"/Users/user/project/src/bar.js": `
export function bar() { throw new Error('test') }
`,
// Someone wanted data from the text loader to show up in the source map: https://github.com/evanw/esbuild/issues/2041
"/Users/user/project/src/data.txt": `#2041`,
},
entryPaths: []string{"/Users/user/project/src/entry.js"},
options: config.Options{
Expand Down
10 changes: 7 additions & 3 deletions internal/bundler_tests/snapshots/snapshots_default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5350,9 +5350,9 @@ TestSourceMap
---------- /Users/user/project/out.js.map ----------
{
"version": 3,
"sources": ["src/bar.js", "src/entry.js"],
"sourcesContent": ["\n\t\t\t\texport function bar() { throw new Error('test') }\n\t\t\t", "\n\t\t\t\timport {bar} from './bar'\n\t\t\t\tfunction foo() { bar() }\n\t\t\t\tfoo()\n\t\t\t"],
"mappings": ";AACW,SAAS,MAAM;AAAE,QAAM,IAAI,MAAM,MAAM;AAAE;;;ACChD,SAAS,MAAM;AAAE,MAAI;AAAE;AACvB,IAAI;",
"sources": ["src/bar.js", "src/data.txt", "src/entry.js"],
"sourcesContent": ["\n\t\t\t\texport function bar() { throw new Error('test') }\n\t\t\t", "#2041", "\n\t\t\t\timport {bar} from './bar'\n\t\t\t\timport data from './data.txt'\n\t\t\t\tfunction foo() { bar() }\n\t\t\t\tfoo()\n\t\t\t\tconsole.log(data)\n\t\t\t"],
"mappings": ";AACW,SAAS,MAAM;AAAE,QAAM,IAAI,MAAM,MAAM;AAAE;;;ACDpD;;;ACGI,SAAS,MAAM;AAAE,MAAI;AAAE;AACvB,IAAI;AACJ,QAAQ,IAAI,YAAI;",
"names": []
}

Expand All @@ -5362,11 +5362,15 @@ function bar() {
throw new Error("test");
}

// Users/user/project/src/data.txt
var data_default = "#2041";

// Users/user/project/src/entry.js
function foo() {
bar();
}
foo();
console.log(data_default);
//# sourceMappingURL=out.js.map

================================================================================
Expand Down
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (loader Loader) IsTypeScript() bool {

func (loader Loader) CanHaveSourceMap() bool {
switch loader {
case LoaderJS, LoaderJSX, LoaderTS, LoaderTSNoAmbiguousLessThan, LoaderTSX, LoaderCSS, LoaderJSON:
case LoaderJS, LoaderJSX, LoaderTS, LoaderTSNoAmbiguousLessThan, LoaderTSX, LoaderCSS, LoaderJSON, LoaderText:
return true
default:
return false
Expand Down

0 comments on commit 7e10dd6

Please sign in to comment.