Skip to content

Commit

Permalink
fix #463: use forward slashes in source maps
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Oct 16, 2020
1 parent 7c84029 commit 73573ea
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 4 additions & 2 deletions internal/bundler/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "\\", "/")
}
}
}
Expand All @@ -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, "\\", "/")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/uglify-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ async function test_case(service, test) {
].join("\n"), {
input: input_formatted,
output: output,
error: ex,
error: ex && ex.stack || ex,
});
}

Expand Down
4 changes: 1 addition & 3 deletions scripts/verify-source-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? '<stdin>' : 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}"`)
Expand Down

0 comments on commit 73573ea

Please sign in to comment.