Skip to content

Commit 9f008c5

Browse files
committed
fix #4070: file namespace for sourceMappingURL
1 parent cbd5eb8 commit 9f008c5

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
* Fix incorrect paths in inline source maps ([#4070](https://github.com/evanw/esbuild/issues/4070), [#4105](https://github.com/evanw/esbuild/issues/4105))
6+
7+
This fixes a regression from version 0.25.0 where esbuild didn't correctly resolve relative paths contained within source maps in inline `sourceMappingURL` data URLs. The paths were incorrectly being passed through as-is instead of being resolved relative to the source file containing the `sourceMappingURL` comment, which was due to the data URL not being a file URL. This regression has been fixed, and this case now has test coverage.
8+
59
* Fix invalid generated source maps ([#4080](https://github.com/evanw/esbuild/issues/4080), [#4082](https://github.com/evanw/esbuild/issues/4082), [#4107](https://github.com/evanw/esbuild/issues/4107))
610

711
This release fixes a regression from version 0.24.1 that could cause esbuild to generate invalid source maps. Specifically under certain conditions, esbuild could generate a mapping with an out-of-bounds source index. It was introduced by code that attempted to improve esbuild's handling of "null" entries in source maps (i.e. mappings with a generated position but no original position). This regression has been fixed.

internal/bundler/bundler.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,9 @@ func extractSourceMapFromComment(
816816
fmt.Sprintf("Unsupported source map comment: %s", err.Error()))
817817
return logger.Path{}, nil
818818
}
819-
return logger.Path{Text: source.PrettyPath, IgnoredSuffix: "#sourceMappingURL"}, &contents
819+
path := source.KeyPath
820+
path.IgnoredSuffix = "#sourceMappingURL"
821+
return path, &contents
820822
}
821823

822824
// Support file URLs of two forms:

internal/js_parser/sourcemap_parser.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import (
1313
"github.com/evanw/esbuild/internal/sourcemap"
1414
)
1515

16-
// Specification: https://sourcemaps.info/spec.html
16+
// New specification: https://tc39.es/ecma426/
17+
// Old specification: https://sourcemaps.info/spec.html
1718
func ParseSourceMap(log logger.Log, source logger.Source) *sourcemap.SourceMap {
1819
expr, ok := ParseJSON(log, source, JSONOptions{ErrorSuffix: " in source map"})
1920
if !ok {

scripts/verify-source-map.js

+27
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,27 @@ const toSearchNullMappingIssue4080 = {
552552
'lib!': 'src/lib.js',
553553
}
554554

555+
const testCaseNestedFoldersIssue4070 = {
556+
'src/main.js': `import { appConfig } from "./app/app.config";
557+
appConfig("foo");
558+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKIC` +
559+
`Aic291cmNlcyI6IFsibWFpbi5qcyJdLAogICJzb3VyY2VzQ29udGVudCI6IFsiaW1wb3J0I` +
560+
`HsgYXBwQ29uZmlnIH0gZnJvbSBcIi4vYXBwL2FwcC5jb25maWdcIjtcbmFwcENvbmZpZyhc` +
561+
`ImZvb1wiKTsiXSwKICAibWFwcGluZ3MiOiAiQUFBQSxTQUFTLGlCQUFpQjtBQUMxQixVQUF` +
562+
`VLEtBQUs7IiwKICAibmFtZXMiOiBbXQp9Cg==`,
563+
'src/app/app.config.js': `export const appConfig = (x) => console.log(x, "bar");
564+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKIC` +
565+
`Aic291cmNlcyI6IFsiYXBwLmNvbmZpZy5qcyJdLAogICJzb3VyY2VzQ29udGVudCI6IFsiZ` +
566+
`Xhwb3J0IGNvbnN0IGFwcENvbmZpZyA9IHggPT4gY29uc29sZS5sb2coeCwgXCJiYXJcIik7` +
567+
`Il0sCiAgIm1hcHBpbmdzIjogIkFBQU8sYUFBTSxZQUFZLE9BQUssUUFBUSxJQUFJLEdBQUc` +
568+
`sS0FBSzsiLAogICJuYW1lcyI6IFtdCn0K`,
569+
}
570+
571+
const toSearchNestedFoldersIssue4070 = {
572+
'foo': 'src/main.js',
573+
'bar': 'src/app/app.config.js',
574+
}
575+
555576
async function check(kind, testCase, toSearch, { outfile, flags, entryPoints, crlf, followUpFlags = [], checkFirstChunk }) {
556577
let failed = 0
557578

@@ -1015,6 +1036,12 @@ async function main() {
10151036
entryPoints: ['entry.js'],
10161037
crlf,
10171038
}),
1039+
check('issue-4048' + suffix, testCaseNestedFoldersIssue4070, toSearchNestedFoldersIssue4070, {
1040+
outfile: 'out.js',
1041+
flags: flags.concat('--bundle'),
1042+
entryPoints: ['src/main.js'],
1043+
crlf,
1044+
}),
10181045
check('issue-4048' + suffix, testCaseNullMappingIssue4080, toSearchNullMappingIssue4080, {
10191046
outfile: 'out.js',
10201047
flags: flags.concat('--bundle', '--format=esm'),

0 commit comments

Comments
 (0)