Skip to content

Commit f5572e5

Browse files
manuel3108jycouet
andauthored
chore: drop html deps (#840)
Co-authored-by: jycouet <[email protected]>
1 parent 9a374d2 commit f5572e5

File tree

17 files changed

+107
-165
lines changed

17 files changed

+107
-165
lines changed

packages/sv/lib/addons/_tests/all-addons/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import process from 'node:process';
22
import { expect } from '@playwright/test';
33
import { setupTest } from '../_setup/suite.ts';
44
import { officialAddons } from '../../index.ts';
5-
import type { AddonMap, OptionMap } from 'sv';
5+
import type { AddonMap, OptionMap } from '../../../addons/install.ts';
66

77
const windowsCI = process.env.CI && process.platform === 'win32';
88
const addons = Object.values(officialAddons).reduce<AddonMap>((addonMap, addon) => {

packages/sv/lib/addons/_tests/mdsvex/test.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { expect } from '@playwright/test';
44
import { parseSvelte } from '../../../core/tooling/parsers.ts';
55
import { imports } from '../../../core/tooling/js/index.ts';
66
import * as svelte from '../../../core/tooling/svelte/index.ts';
7+
import * as html from '../../../core/tooling/html/index.ts';
78
import { setupTest } from '../_setup/suite.ts';
89
import { svxFile } from './fixtures.ts';
910
import mdsvex from '../../mdsvex/index.ts';
@@ -44,25 +45,8 @@ function addFixture(cwd: string, variant: string) {
4445
const scriptAst = svelte.ensureScript(ast);
4546
imports.addDefault(scriptAst, { from: './Demo.svx', as: 'Demo' });
4647

47-
ast.fragment.nodes.push({
48-
type: 'RegularElement',
49-
name: 'div',
50-
attributes: [
51-
{
52-
type: 'Attribute',
53-
name: 'class',
54-
value: [{ type: 'Text', data: 'mdsvex', raw: 'mdsvex', start: 0, end: 0 }],
55-
start: 0,
56-
end: 0
57-
}
58-
],
59-
fragment: {
60-
type: 'Fragment',
61-
nodes: svelte.toFragment('<Demo />')
62-
},
63-
start: 0,
64-
end: 0
65-
});
48+
const div = html.createElement('div', { class: 'mdsvex' });
49+
div.fragment.nodes = svelte.toFragment('<Demo />');
6650

6751
const content = generateCode();
6852

packages/sv/lib/addons/paraglide/index.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,24 +152,21 @@ export default defineAddon({
152152
return generateCode();
153153
});
154154

155-
// add the text-direction and lang attribute placeholders to app.html
155+
// add the lang attribute placeholder to app.html
156156
sv.file('src/app.html', (content) => {
157157
const { ast, generateCode } = parseHtml(content);
158158

159-
const htmlNode = ast.children.find(
160-
(child): child is html.HtmlElement =>
161-
child.type === html.HtmlElementType.Tag && child.name === 'html'
159+
const htmlNode = ast.nodes.find(
160+
(child): child is html.SvelteAst.RegularElement =>
161+
child.type === 'RegularElement' && child.name === 'html'
162162
);
163163
if (!htmlNode) {
164164
log.warn(
165165
"Could not find <html> node in app.html. You'll need to add the language placeholder manually"
166166
);
167167
return generateCode();
168168
}
169-
htmlNode.attribs = {
170-
...htmlNode.attribs,
171-
lang: '%paraglide.lang%'
172-
};
169+
html.addAttribute(htmlNode, 'lang', '%paraglide.lang%');
173170

174171
return generateCode();
175172
});

packages/sv/lib/cli/tests/snapshots/create-with-all-addons/src/app.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
<html lang="%paraglide.lang%">
33
<head>
44
<meta charset="utf-8" />
5-
<meta name="viewport" content="width=device-width, initial-scale=1" />
5+
<meta
6+
name="viewport"
7+
content="width=device-width, initial-scale=1"
8+
/>
69
%sveltekit.head%
710
</head>
811
<body data-sveltekit-preload-data="hover">
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div></div>

packages/sv/lib/core/tests/html/common/create-div/input.html renamed to packages/sv/lib/core/tests/html/common/add-attribute/output.html

File renamed without changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { addAttribute, type SvelteAst } from '../../../../tooling/html/index.ts';
2+
3+
export function run(ast: SvelteAst.Fragment): void {
4+
const element = ast.nodes[0] as SvelteAst.RegularElement;
5+
addAttribute(element, 'class', 'foo');
6+
}

packages/sv/lib/core/tests/html/common/create-div/output.html

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/sv/lib/core/tests/html/common/create-div/run.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/sv/lib/core/tests/html/common/create-element/run.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import {
22
createElement,
33
appendElement,
44
insertElement,
5-
type HtmlDocument
5+
type SvelteAst
66
} from '../../../../tooling/html/index.ts';
77

8-
export function run(ast: HtmlDocument): void {
8+
export function run(ast: SvelteAst.Fragment): void {
99
const emptySpan = createElement('span');
10-
insertElement(ast.childNodes, emptySpan);
11-
appendElement(ast.childNodes, emptySpan);
10+
insertElement(ast, emptySpan);
11+
appendElement(ast, emptySpan);
1212
}

0 commit comments

Comments
 (0)