-
-
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
Changes from all commits
c1d64b7
d866d91
904ecd0
4adf1b7
ffee270
39dbe05
6156452
00a865a
c07f62a
2f5fd63
95d8a62
0c8b07f
a8624d2
1a79d9c
8bf75fb
4e92d59
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,38 @@ | ||
import { type AST } from 'svelte/compiler'; | ||
import { Walker, type AstTypes } from '@svelte-cli/ast-tooling'; | ||
import MagicString from 'magic-string'; | ||
import { areNodesEqual } from './common.ts'; | ||
import { dedent } from '../../index.ts'; | ||
|
||
export function addEmpty(ast: AstTypes.Program, importFrom: string): void { | ||
const expectedImportDeclaration: AstTypes.ImportDeclaration = { | ||
type: 'ImportDeclaration', | ||
source: { | ||
type: 'Literal', | ||
value: importFrom | ||
}, | ||
specifiers: [] | ||
}; | ||
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') | ||
); | ||
Comment on lines
+7
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 name: () => 'foo.js',
content: ({ content }) => {
const { ast, generateCode } = parseScript(content);
const ms = new MagicString(content);
imports.addEmpty(ast, ms, '../app.css');
return ms.toString();
} |
||
} | ||
|
||
export function addDefault(ast: AstTypes.Program, importFrom: string, importAs: string): void { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import MagicString from 'magic-string'; | ||
import { type AST, parse } from 'svelte/compiler'; | ||
|
||
export function svelteMagicAst(content: string): { ast: AST.Root; source: MagicString } { | ||
const ast = parse(content, { modern: true }); | ||
const source = new MagicString(content); | ||
return { ast, source }; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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