-
-
Notifications
You must be signed in to change notification settings - Fork 36
fix(tailwind): update layout without altering formatting #74
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
Conversation
commit: |
export function addEmpty(ast: AST.Root, contents: MagicString, importFrom: string): void { | ||
const body = ast.instance?.content?.body || []; | ||
|
||
addImportIfNecessary(ast, expectedImportDeclaration); | ||
if (!body.length) { | ||
contents.prepend(dedent` | ||
<script> | ||
import '${importFrom}'; | ||
</script> | ||
|
||
`); | ||
return; | ||
} | ||
|
||
// check if already imported | ||
for (const statement of body) { | ||
if (statement.type === 'ImportDeclaration' && statement.source.value === importFrom) { | ||
return; | ||
} | ||
} | ||
|
||
const first_statement = body[0]; | ||
if (!first_statement.range) { | ||
throw new Error(`${JSON.stringify(first_statement)} is missing range information.}`); | ||
} | ||
const is_first_line_import = first_statement.type === 'ImportDeclaration'; | ||
contents.prependLeft( | ||
first_statement.range[0], | ||
`import '${importFrom}';` + (is_first_line_import ? '\n\t' : '\n\n\t') | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one issue with this implementation is that it's not really focused on applying the import to JS modules. for instance, it's injecting the <script>
tags when there's no body.
this would break if we were to run addEmpty
to a JS file like:
name: () => 'foo.js',
content: ({ content }) => {
const { ast, generateCode } = parseScript(content);
const ms = new MagicString(content);
imports.addEmpty(ast, ms, '../app.css');
return ms.toString();
}
content: ({ content }) => { | ||
content ||= '<slot />'; | ||
const { ast, source } = svelteMagicAst(content); | ||
imports.addEmpty(ast, source, '../app.css'); | ||
return source.toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about this as an alternate approach? https://github.com/sveltejs/cli/pull/75/files#diff-225d2ebe1d2b9c148fe3d2d9cf3030b09ed48c73824c51ce3f7dbf8a02ea878eR122-R129
I might be missing something, but now that #75 is in, do we still need this? |
I'll close it for now. This is a more fine-grained approach, but there's not time to pursue it before launch |
This just uses the Svelte 4
slot
for now. #69 was attempting to tackle thatSome other items we should do:
guessIndentString
and guess single vs double quoteaddEmpty
. We don't necessarily want to pass in theAst
,MagicString
, andworkspace
as separate items