diff --git a/src/print-ast.ts b/src/print-ast.ts
index 838db38..5d1f056 100644
--- a/src/print-ast.ts
+++ b/src/print-ast.ts
@@ -1,31 +1,9 @@
-import type { AST } from 'svelte/src/compiler/types/template.js';
+import type { AST } from 'svelte/src/compiler/types/template.js';
import { DefaultPrinterIdentOptions, PrinterIdentOptions, printHtml, printScript } from './index.js';
-export interface PrintAstParams {
- ast: AST.Root;
- indent?: PrinterIdentOptions;
-}
-
-export default function printAst(params: PrintAstParams): string {
- const { ast } = params;
- const ident = {
- ...DefaultPrinterIdentOptions,
- ...params.indent
- };
-
- const markup = printHtml({
- rootNode: ast.html,
- ident
- });
-
- const scriptInstance = ast.instance ? printScript({ script: ast.instance, ident }) : '';
- const scriptModule = ast.module ? printScript({ script: ast.module, ident }) : '';
-
- let result = '';
-
- result += scriptModule + ident.lineEnd;
- result += scriptInstance + ident.lineEnd;
- result += markup;
+export default function printAst(root: AST.Root, indent: PrinterIdentOptions = DefaultPrinterIdentOptions): string {
+ const markup = printHtml(root, indent);
+ const script = printScript(root, indent);
- return result;
+ return script + indent.lineEnd + markup;
}
diff --git a/src/tests/print-ast.test.ts_ b/src/tests/print-ast.test.ts
similarity index 63%
rename from src/tests/print-ast.test.ts_
rename to src/tests/print-ast.test.ts
index dede3fe..7e74a7d 100644
--- a/src/tests/print-ast.test.ts_
+++ b/src/tests/print-ast.test.ts
@@ -3,13 +3,10 @@ import { describe, expect, test } from 'vitest';
import printAst from '../print-ast';
function testPrintAst(code: string, expectedResult?: string) {
- const ast = parse(code, { modern: false });
- const result = printAst({
- ast,
- indent: {
- indent: '',
- lineEnd: ''
- }
+ const root = parse(code, { modern: true });
+ const result = printAst(root, {
+ indent: '',
+ lineEnd: ''
});
expect(result).toBe(expectedResult ?? code);
parse(result);
@@ -21,6 +18,6 @@ describe('print-ast', () => {
});
test('with module', () => {
- testPrintAst('Hello,World');
+ testPrintAst('Hello,World');
});
});