absolute sourcemaps have source content

This commit is contained in:
Rene Haas
2022-10-12 08:59:50 +02:00
parent 8ee738b578
commit 6b2709bd03
3 changed files with 6606 additions and 4 deletions
+11 -4
View File
@@ -97,10 +97,17 @@ class MapGenerator {
let from = node.source.input.from
if (from && !already[from]) {
already[from] = true
this.map.setSourceContent(
this.toUrl(this.path(from)),
node.source.input.css
)
let fromUrl = this.toUrl(this.path(from))
if (this.mapOpts.absolute) {
if (pathToFileURL) {
fromUrl = pathToFileURL(from).toString()
} else {
throw new Error(
'`map.absolute` option is not available in this PostCSS build'
)
}
}
this.map.setSourceContent(fromUrl, node.source.input.css)
}
}
})
+6584
View File
File diff suppressed because it is too large Load Diff
+11
View File
@@ -722,4 +722,15 @@ test('supports previous inline map with empty processor', () => {
match((root3.source?.input.origin(1, 0) as any).file, 'a.css')
})
test('absolute sourcemaps have source contents', () => {
let result = postcss([() => {}]).process('a{}', {
from: '/dir/to/a.css',
map: {
inline: false,
absolute: true
}
})
equal(result.map.toJSON().sourcesContent, ['a{}'])
})
test.run()