From 73573eaa39e4f09b35b35b29826b1fdc4a39f5f1 Mon Sep 17 00:00:00 2001 From: Evan Wallace Date: Fri, 16 Oct 2020 10:21:21 -0700 Subject: [PATCH] fix #463: use forward slashes in source maps --- CHANGELOG.md | 6 ++++++ internal/bundler/linker.go | 6 ++++-- scripts/uglify-tests.js | 2 +- scripts/verify-source-map.js | 4 +--- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9ebf8c6315..39a6c754bfb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +* Fix backward slashes in source maps on Windows ([#463](https://github.com/evanw/esbuild/issues/463)) + + The relative path fix in the previous release caused a regression where paths in source maps contained `\` instead of `/` on Windows. That is incorrect because source map paths are URLs, not file system paths. This release replaces `\` with `/` for consistency on Windows. + ## 0.7.15 * Lower `export * as` syntax for ES2019 and below diff --git a/internal/bundler/linker.go b/internal/bundler/linker.go index 0342fd901a9..9f544bc84f3 100644 --- a/internal/bundler/linker.go +++ b/internal/bundler/linker.go @@ -3028,7 +3028,8 @@ func (c *linkerContext) generateCodeForFileInChunkJS( for i, oldRelPath := range sourceMapClone.Sources { absPath := c.fs.Join(sourceAbsDir, oldRelPath) if relPath, ok := c.fs.Rel(chunkAbsDir, absPath); ok { - sourceMapClone.Sources[i] = relPath + // Make sure to always use forward slashes, even on Windows + sourceMapClone.Sources[i] = strings.ReplaceAll(relPath, "\\", "/") } } } @@ -3038,7 +3039,8 @@ func (c *linkerContext) generateCodeForFileInChunkJS( // containing the output file if sourceClone.KeyPath.Namespace == "file" { if relPath, ok := c.fs.Rel(chunkAbsDir, sourceClone.KeyPath.Text); ok { - sourceClone.PrettyPath = relPath + // Make sure to always use forward slashes, even on Windows + sourceClone.PrettyPath = strings.ReplaceAll(relPath, "\\", "/") } } } diff --git a/scripts/uglify-tests.js b/scripts/uglify-tests.js index d9284df40ae..442aa0e619f 100644 --- a/scripts/uglify-tests.js +++ b/scripts/uglify-tests.js @@ -156,7 +156,7 @@ async function test_case(service, test) { ].join("\n"), { input: input_formatted, output: output, - error: ex, + error: ex && ex.stack || ex, }); } diff --git a/scripts/verify-source-map.js b/scripts/verify-source-map.js index cd78f595bb5..c54404bf4e6 100644 --- a/scripts/verify-source-map.js +++ b/scripts/verify-source-map.js @@ -256,9 +256,7 @@ async function check(kind, testCase, toSearch, { flags, entryPoints, crlf }) { const { source, line, column } = map.originalPositionFor({ line: outLine, column: outColumn }) const inSource = isStdin ? '' : files.find(x => path.basename(x).startsWith(id[0])) - const expectedSource = path.relative(__dirname, path.join(relativeTo, inSource).replace(/\\/g, '/')) - const observedSource = path.relative(__dirname, path.join(relativeTo, source).replace(/\\/g, '/')) - recordCheck(observedSource === expectedSource, `expected: ${expectedSource} observed: ${observedSource}`) + recordCheck(source === inSource, `expected: ${inSource} observed: ${source}`) const inJs = map.sourceContentFor(source) const inIndex = inJs.indexOf(`"${id}"`)