-
-
Notifications
You must be signed in to change notification settings - Fork 946
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
custom-property-empty-line-before
test case by using custom syntax
- Loading branch information
1 parent
0d6af14
commit b1e2007
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const postcss = require('postcss'); | ||
|
||
/** | ||
* @type {postcss.Parser<postcss.Document>} | ||
*/ | ||
function parse(css) { | ||
const source = typeof css === 'string' ? css : css.toString(); | ||
|
||
const document = postcss.document({ | ||
source: { | ||
input: new postcss.Input(source), | ||
}, | ||
}); | ||
|
||
// E.g. "css` color: red; `;" | ||
for (const match of source.matchAll(/\bcss`([^`]+)`;/g)) { | ||
document.append(postcss.parse(match[1])); | ||
} | ||
|
||
return document; | ||
} | ||
|
||
/** | ||
* @type {postcss.Stringifier} | ||
*/ | ||
function stringify(node, builder) { | ||
if (node.type === 'document') { | ||
node.each((root) => { | ||
builder(`css\`${root}\`;`, root); | ||
}); | ||
} | ||
} | ||
|
||
module.exports = { parse, stringify }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters