Skip to content

Commit 39bf3d3

Browse files
Fix whitespace removal caused by re-parsing at-rules (#400)
* Tweak test example * Add failing test * Pass in shallow copy of parse options when re-parsing at-rule params * Update test case
1 parent 919349c commit 39bf3d3

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,12 @@ function transformCss(ast: any, { env }: TransformerContext) {
735735
// based on postcss-value parser.
736736
try {
737737
let parser = base.parsers.css
738-
let root = parser.parse(`@import ${params};`, env.options)
738+
739+
let root = parser.parse(`@import ${params};`, {
740+
// We can't pass env.options directly because css.parse overwrites
741+
// options.originalText which is used during the printing phase
742+
...env.options,
743+
})
739744

740745
return root.nodes[0].params
741746
} catch (err) {

tests/tests.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,20 @@ let css: TestEntry[] = [
4646
[`@config "./file.js";`, `@config './file.js';`],
4747
[`@source "./file.js";`, `@source './file.js';`],
4848
[`@source not "./file.js";`, `@source not './file.js';`],
49-
[`@source inline("./file.js");`, `@source inline('./file.js');`],
49+
[`@source inline("flex");`, `@source inline('flex');`],
50+
51+
[
52+
`@import "tailwindcss";\n\n@import "./theme.css";\n\n@source "./file.js";\n\n.foo {\n color: red;\n}`,
53+
`@import 'tailwindcss';\n\n@import './theme.css';\n\n@source './file.js';\n\n.foo {\n color: red;\n}`,
54+
],
55+
[
56+
`@import "tailwindcss";\n\n@import "./theme.css";\n\n@plugin "./file.js";\n\n.foo {\n color: red;\n}`,
57+
`@import 'tailwindcss';\n\n@import './theme.css';\n\n@plugin './file.js';\n\n.foo {\n color: red;\n}`,
58+
],
59+
[
60+
`@import "tailwindcss";\n\n@import "./theme.css";\n\n@config "./file.js";\n\n.foo {\n color: red;\n}`,
61+
`@import 'tailwindcss';\n\n@import './theme.css';\n\n@config './file.js';\n\n.foo {\n color: red;\n}`,
62+
],
5063
]
5164

5265
export let javascript: TestEntry[] = [

0 commit comments

Comments
 (0)