Skip to content

Commit 75286c1

Browse files
committed
unit test for absolute windows paths in source map
1 parent bcc77fb commit 75286c1

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed

internal/bundler_tests/bundler_loader_test.go

+86
Original file line numberDiff line numberDiff line change
@@ -1786,3 +1786,89 @@ func TestLoaderTextUTF8BOM(t *testing.T) {
17861786
},
17871787
})
17881788
}
1789+
1790+
// See: https://github.com/evanw/esbuild/issues/4075
1791+
func TestLoaderInlineSourceMapAbsolutePathIssue4075Unix(t *testing.T) {
1792+
urlEncodedUnix := "%22file%3A%2F%2F%2Fout%2Fsrc%2Fstyles1.scss%22" // file:///out/src/styles1.scss
1793+
pathEncodedUnix := "%22%2Fout%2Fsrc%2Fstyles2.scss%22" // /out/src/styles2.scss
1794+
1795+
loader_suite.expectBundledUnix(t, bundled{
1796+
files: map[string]string{
1797+
"/home/user/project/src/entry.css": `
1798+
@import "./styles1.css";
1799+
@import "./styles2.css";
1800+
`,
1801+
"/home/user/project/src/styles1.css": `/* You can add global styles to this file, and also import other style files */
1802+
* {
1803+
content: "foo";
1804+
}
1805+
1806+
/*# sourceMappingURL=data:application/json;charset=utf-8,%7B%22version%22:3,` +
1807+
`%22sourceRoot%22:%22%22,%22sources%22:%5B` + urlEncodedUnix + `%5D,%22n` +
1808+
`ames%22:%5B%5D,%22mappings%22:%22AAAA;AACA;EACE,SAAS%22,%22file%22:%22o` +
1809+
`ut%22,%22sourcesContent%22:%5B%22/*%20You%20can%20add%20global%20styles` +
1810+
`%20to%20this%20file,%20and%20also%20import%20other%20style%20files%20%2` +
1811+
`A/%5Cn*%20%7B%5Cn%20%20content:%20%5C%22foo%5C%22%5Cn%7D%5Cn%22%5D%7D */`,
1812+
"/home/user/project/src/styles2.css": `/* You can add global styles to this file, and also import other style files */
1813+
* {
1814+
content: "bar";
1815+
}
1816+
1817+
/*# sourceMappingURL=data:application/json;charset=utf-8,%7B%22version%22:3,` +
1818+
`%22sourceRoot%22:%22%22,%22sources%22:%5B` + pathEncodedUnix + `%5D,%22` +
1819+
`names%22:%5B%5D,%22mappings%22:%22AAAA;AACA;EACE,SAAS%22,%22file%22:%22` +
1820+
`out%22,%22sourcesContent%22:%5B%22/*%20You%20can%20add%20global%20style` +
1821+
`s%20to%20this%20file,%20and%20also%20import%20other%20style%20files%20%` +
1822+
`2A/%5Cn*%20%7B%5Cn%20%20content:%20%5C%22bar%5C%22%5Cn%7D%5Cn%22%5D%7D */`,
1823+
},
1824+
entryPaths: []string{"/home/user/project/src/entry.css"},
1825+
options: config.Options{
1826+
Mode: config.ModeBundle,
1827+
SourceMap: config.SourceMapLinkedWithComment,
1828+
AbsOutputDir: "/out",
1829+
},
1830+
})
1831+
}
1832+
1833+
// See: https://github.com/evanw/esbuild/issues/4075
1834+
func TestLoaderInlineSourceMapAbsolutePathIssue4075Windows(t *testing.T) {
1835+
urlEncodedWin := "%22file%3A%2F%2F%2FC%3A%2Fout%2Fsrc%2Fstyles1.scss%22" // file:///C:/out/src/styles1.scss
1836+
pathEncodedWin := "%22C%3A%5C%5Cout%5C%5Csrc%5C%5Cstyles2.scss%22" // C:\out\src\styles2.scss
1837+
1838+
loader_suite.expectBundledWindows(t, bundled{
1839+
files: map[string]string{
1840+
"/home/user/project/src/entry.css": `
1841+
@import "./styles1.css";
1842+
@import "./styles2.css";
1843+
`,
1844+
"/home/user/project/src/styles1.css": `/* You can add global styles to this file, and also import other style files */
1845+
* {
1846+
content: "foo";
1847+
}
1848+
1849+
/*# sourceMappingURL=data:application/json;charset=utf-8,%7B%22version%22:3,` +
1850+
`%22sourceRoot%22:%22%22,%22sources%22:%5B` + urlEncodedWin + `%5D,%22n` +
1851+
`ames%22:%5B%5D,%22mappings%22:%22AAAA;AACA;EACE,SAAS%22,%22file%22:%22o` +
1852+
`ut%22,%22sourcesContent%22:%5B%22/*%20You%20can%20add%20global%20styles` +
1853+
`%20to%20this%20file,%20and%20also%20import%20other%20style%20files%20%2` +
1854+
`A/%5Cn*%20%7B%5Cn%20%20content:%20%5C%22foo%5C%22%5Cn%7D%5Cn%22%5D%7D */`,
1855+
"/home/user/project/src/styles2.css": `/* You can add global styles to this file, and also import other style files */
1856+
* {
1857+
content: "bar";
1858+
}
1859+
1860+
/*# sourceMappingURL=data:application/json;charset=utf-8,%7B%22version%22:3,` +
1861+
`%22sourceRoot%22:%22%22,%22sources%22:%5B` + pathEncodedWin + `%5D,%22` +
1862+
`names%22:%5B%5D,%22mappings%22:%22AAAA;AACA;EACE,SAAS%22,%22file%22:%22` +
1863+
`out%22,%22sourcesContent%22:%5B%22/*%20You%20can%20add%20global%20style` +
1864+
`s%20to%20this%20file,%20and%20also%20import%20other%20style%20files%20%` +
1865+
`2A/%5Cn*%20%7B%5Cn%20%20content:%20%5C%22bar%5C%22%5Cn%7D%5Cn%22%5D%7D */`,
1866+
},
1867+
entryPaths: []string{"/home/user/project/src/entry.css"},
1868+
options: config.Options{
1869+
Mode: config.ModeBundle,
1870+
SourceMap: config.SourceMapLinkedWithComment,
1871+
AbsOutputDir: "/out",
1872+
},
1873+
})
1874+
}

internal/bundler_tests/snapshots/snapshots_loader.txt

+50
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,56 @@ var file_default = "This should not be base64 encoded";
902902
// entry.js
903903
console.log(file_default);
904904

905+
================================================================================
906+
TestLoaderInlineSourceMapAbsolutePathIssue4075Unix
907+
---------- /out/entry.css.map ----------
908+
{
909+
"version": 3,
910+
"sources": ["src/styles1.scss", "src/styles2.scss"],
911+
"sourcesContent": ["/* You can add global styles to this file, and also import other style files */\n* {\n content: \"foo\"\n}\n", "/* You can add global styles to this file, and also import other style files */\n* {\n content: \"bar\"\n}\n"],
912+
"mappings": ";AACA;AACE,WAAS;;;;ACDX;AACE,WAAS;;",
913+
"names": []
914+
}
915+
916+
---------- /out/entry.css ----------
917+
/* home/user/project/src/styles1.css */
918+
* {
919+
content: "foo";
920+
}
921+
922+
/* home/user/project/src/styles2.css */
923+
* {
924+
content: "bar";
925+
}
926+
927+
/* home/user/project/src/entry.css */
928+
/*# sourceMappingURL=entry.css.map */
929+
930+
================================================================================
931+
TestLoaderInlineSourceMapAbsolutePathIssue4075Windows
932+
---------- /out/entry.css.map ----------
933+
{
934+
"version": 3,
935+
"sources": ["src/styles1.scss", "src/styles2.scss"],
936+
"sourcesContent": ["/* You can add global styles to this file, and also import other style files */\n* {\n content: \"foo\"\n}\n", "/* You can add global styles to this file, and also import other style files */\n* {\n content: \"bar\"\n}\n"],
937+
"mappings": ";AACA;AACE,WAAS;;;;ACDX;AACE,WAAS;;",
938+
"names": []
939+
}
940+
941+
---------- /out/entry.css ----------
942+
/* home/user/project/src/styles1.css */
943+
* {
944+
content: "foo";
945+
}
946+
947+
/* home/user/project/src/styles2.css */
948+
* {
949+
content: "bar";
950+
}
951+
952+
/* home/user/project/src/entry.css */
953+
/*# sourceMappingURL=entry.css.map */
954+
905955
================================================================================
906956
TestLoaderJSONCommonJSAndES6
907957
---------- /out.js ----------

0 commit comments

Comments
 (0)