Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

source macro: preserve new lines #1372

Merged
merged 4 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/red-melons-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@braid-design-system/source.macro': patch
---

Preserve newlines in the output code
mrm007 marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 3 additions & 1 deletion packages/source.macro/source.macro.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ module.exports = createMacro(

references.default.forEach(({ parentPath }) => {
const value = parentPath.node.arguments[0] || t.identifier('undefined');
const code = t.stringLiteral(generate(value).code);
const code = t.stringLiteral(
generate(value, { retainLines: true }).code.replace(/^\n+/, ''),
);

return parentPath.replaceWith(
codeOnly
Expand Down