@vigla/svelte 0.0.0-stage → 5.57.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/action.d.ts +2 -0
- package/animate.d.ts +2 -0
- package/compiler/index.js +43266 -0
- package/compiler/index.js.map +1 -0
- package/compiler/package.json +3 -0
- package/compiler.d.ts +2 -0
- package/dist/compiler/diagnostics.d.ts +70 -0
- package/dist/compiler/diagnostics.d.ts.map +1 -0
- package/dist/compiler/diagnostics.js +166 -0
- package/dist/compiler/diagnostics.js.map +1 -0
- package/dist/compiler/index.d.ts +72 -0
- package/dist/compiler/index.d.ts.map +1 -0
- package/dist/compiler/index.js +178 -0
- package/dist/compiler/index.js.map +1 -0
- package/dist/compiler/options.d.ts +7 -0
- package/dist/compiler/options.d.ts.map +1 -0
- package/dist/compiler/options.js +126 -0
- package/dist/compiler/options.js.map +1 -0
- package/dist/compiler/preprocess/decode.d.ts +3 -0
- package/dist/compiler/preprocess/decode.d.ts.map +1 -0
- package/dist/compiler/preprocess/decode.js +60 -0
- package/dist/compiler/preprocess/decode.js.map +1 -0
- package/dist/compiler/preprocess/index.d.ts +27 -0
- package/dist/compiler/preprocess/index.d.ts.map +1 -0
- package/dist/compiler/preprocess/index.js +208 -0
- package/dist/compiler/preprocess/index.js.map +1 -0
- package/dist/compiler/preprocess/mapped.d.ts +25 -0
- package/dist/compiler/preprocess/mapped.d.ts.map +1 -0
- package/dist/compiler/preprocess/mapped.js +129 -0
- package/dist/compiler/preprocess/mapped.js.map +1 -0
- package/dist/compiler/proxy.d.ts +3 -0
- package/dist/compiler/proxy.d.ts.map +1 -0
- package/dist/compiler/proxy.js +133 -0
- package/dist/compiler/proxy.js.map +1 -0
- package/dist/entries/action.d.ts +2 -0
- package/dist/entries/action.d.ts.map +1 -0
- package/dist/entries/action.js +1 -0
- package/dist/entries/action.js.map +1 -0
- package/dist/entries/animate.d.ts +2 -0
- package/dist/entries/animate.d.ts.map +1 -0
- package/dist/entries/animate.js +2 -0
- package/dist/entries/animate.js.map +1 -0
- package/dist/entries/attachments.d.ts +2 -0
- package/dist/entries/attachments.d.ts.map +1 -0
- package/dist/entries/attachments.js +2 -0
- package/dist/entries/attachments.js.map +1 -0
- package/dist/entries/context.d.ts +15 -0
- package/dist/entries/context.d.ts.map +1 -0
- package/dist/entries/context.js +32 -0
- package/dist/entries/context.js.map +1 -0
- package/dist/entries/easing.d.ts +2 -0
- package/dist/entries/easing.d.ts.map +1 -0
- package/dist/entries/easing.js +2 -0
- package/dist/entries/easing.js.map +1 -0
- package/dist/entries/events.d.ts +2 -0
- package/dist/entries/events.d.ts.map +1 -0
- package/dist/entries/events.js +2 -0
- package/dist/entries/events.js.map +1 -0
- package/dist/entries/index-server.d.ts +4 -0
- package/dist/entries/index-server.d.ts.map +1 -0
- package/dist/entries/index-server.js +11 -0
- package/dist/entries/index-server.js.map +1 -0
- package/dist/entries/index.d.ts +10 -0
- package/dist/entries/index.d.ts.map +1 -0
- package/dist/entries/index.js +24 -0
- package/dist/entries/index.js.map +1 -0
- package/dist/entries/internal/client.d.ts +4 -0
- package/dist/entries/internal/client.d.ts.map +1 -0
- package/dist/entries/internal/client.js +9 -0
- package/dist/entries/internal/client.js.map +1 -0
- package/dist/entries/internal/disclose-version.d.ts +2 -0
- package/dist/entries/internal/disclose-version.d.ts.map +1 -0
- package/dist/entries/internal/disclose-version.js +4 -0
- package/dist/entries/internal/disclose-version.js.map +1 -0
- package/dist/entries/internal/index.d.ts +2 -0
- package/dist/entries/internal/index.d.ts.map +1 -0
- package/dist/entries/internal/index.js +2 -0
- package/dist/entries/internal/index.js.map +1 -0
- package/dist/entries/internal/server.d.ts +2 -0
- package/dist/entries/internal/server.d.ts.map +1 -0
- package/dist/entries/internal/server.js +7 -0
- package/dist/entries/internal/server.js.map +1 -0
- package/dist/entries/internal/tracing.d.ts +2 -0
- package/dist/entries/internal/tracing.d.ts.map +1 -0
- package/dist/entries/internal/tracing.js +2 -0
- package/dist/entries/internal/tracing.js.map +1 -0
- package/dist/entries/motion-server.d.ts +2 -0
- package/dist/entries/motion-server.d.ts.map +1 -0
- package/dist/entries/motion-server.js +2 -0
- package/dist/entries/motion-server.js.map +1 -0
- package/dist/entries/motion.d.ts +2 -0
- package/dist/entries/motion.d.ts.map +1 -0
- package/dist/entries/motion.js +2 -0
- package/dist/entries/motion.js.map +1 -0
- package/dist/entries/proxy.d.ts +6 -0
- package/dist/entries/proxy.d.ts.map +1 -0
- package/dist/entries/proxy.js +77 -0
- package/dist/entries/proxy.js.map +1 -0
- package/dist/entries/reactivity-server.d.ts +2 -0
- package/dist/entries/reactivity-server.d.ts.map +1 -0
- package/dist/entries/reactivity-server.js +2 -0
- package/dist/entries/reactivity-server.js.map +1 -0
- package/dist/entries/reactivity.d.ts +2 -0
- package/dist/entries/reactivity.d.ts.map +1 -0
- package/dist/entries/reactivity.js +2 -0
- package/dist/entries/reactivity.js.map +1 -0
- package/dist/entries/report.d.ts +3 -0
- package/dist/entries/report.d.ts.map +1 -0
- package/dist/entries/report.js +66 -0
- package/dist/entries/report.js.map +1 -0
- package/dist/entries/server.d.ts +8 -0
- package/dist/entries/server.d.ts.map +1 -0
- package/dist/entries/server.js +48 -0
- package/dist/entries/server.js.map +1 -0
- package/dist/entries/store-client.d.ts +12 -0
- package/dist/entries/store-client.d.ts.map +1 -0
- package/dist/entries/store-client.js +63 -0
- package/dist/entries/store-client.js.map +1 -0
- package/dist/entries/store-server.d.ts +12 -0
- package/dist/entries/store-server.d.ts.map +1 -0
- package/dist/entries/store-server.js +30 -0
- package/dist/entries/store-server.js.map +1 -0
- package/dist/entries/store.d.ts +25 -0
- package/dist/entries/store.d.ts.map +1 -0
- package/dist/entries/store.js +139 -0
- package/dist/entries/store.js.map +1 -0
- package/dist/entries/transition.d.ts +2 -0
- package/dist/entries/transition.d.ts.map +1 -0
- package/dist/entries/transition.js +2 -0
- package/dist/entries/transition.js.map +1 -0
- package/dist/entries/window-server.d.ts +2 -0
- package/dist/entries/window-server.d.ts.map +1 -0
- package/dist/entries/window-server.js +2 -0
- package/dist/entries/window-server.js.map +1 -0
- package/dist/entries/window.d.ts +2 -0
- package/dist/entries/window.d.ts.map +1 -0
- package/dist/entries/window.js +2 -0
- package/dist/entries/window.js.map +1 -0
- package/dist/front/ast.d.ts +290 -0
- package/dist/front/ast.d.ts.map +1 -0
- package/dist/front/ast.js +1 -0
- package/dist/front/ast.js.map +1 -0
- package/dist/front/diagnostics.d.ts +13 -0
- package/dist/front/diagnostics.d.ts.map +1 -0
- package/dist/front/diagnostics.js +38 -0
- package/dist/front/diagnostics.js.map +1 -0
- package/dist/front/ignores.d.ts +12 -0
- package/dist/front/ignores.d.ts.map +1 -0
- package/dist/front/ignores.js +75 -0
- package/dist/front/ignores.js.map +1 -0
- package/dist/front/index.d.ts +17 -0
- package/dist/front/index.d.ts.map +1 -0
- package/dist/front/index.js +65 -0
- package/dist/front/index.js.map +1 -0
- package/dist/front/legacy.d.ts +5 -0
- package/dist/front/legacy.d.ts.map +1 -0
- package/dist/front/legacy.js +408 -0
- package/dist/front/legacy.js.map +1 -0
- package/dist/front/locate.d.ts +4 -0
- package/dist/front/locate.d.ts.map +1 -0
- package/dist/front/locate.js +19 -0
- package/dist/front/locate.js.map +1 -0
- package/dist/front/lower.d.ts +39 -0
- package/dist/front/lower.d.ts.map +1 -0
- package/dist/front/lower.js +470 -0
- package/dist/front/lower.js.map +1 -0
- package/dist/front/parse/attribute.d.ts +12 -0
- package/dist/front/parse/attribute.d.ts.map +1 -0
- package/dist/front/parse/attribute.js +288 -0
- package/dist/front/parse/attribute.js.map +1 -0
- package/dist/front/parse/bracket.d.ts +3 -0
- package/dist/front/parse/bracket.d.ts.map +1 -0
- package/dist/front/parse/bracket.js +102 -0
- package/dist/front/parse/bracket.js.map +1 -0
- package/dist/front/parse/characters.d.ts +4 -0
- package/dist/front/parse/characters.d.ts.map +1 -0
- package/dist/front/parse/characters.js +6 -0
- package/dist/front/parse/characters.js.map +1 -0
- package/dist/front/parse/decode.d.ts +2 -0
- package/dist/front/parse/decode.d.ts.map +1 -0
- package/dist/front/parse/decode.js +89 -0
- package/dist/front/parse/decode.js.map +1 -0
- package/dist/front/parse/element.d.ts +3 -0
- package/dist/front/parse/element.d.ts.map +1 -0
- package/dist/front/parse/element.js +311 -0
- package/dist/front/parse/element.js.map +1 -0
- package/dist/front/parse/entities.d.ts +2 -0
- package/dist/front/parse/entities.d.ts.map +1 -0
- package/dist/front/parse/entities.js +2234 -0
- package/dist/front/parse/entities.js.map +1 -0
- package/dist/front/parse/expression.d.ts +5 -0
- package/dist/front/parse/expression.d.ts.map +1 -0
- package/dist/front/parse/expression.js +86 -0
- package/dist/front/parse/expression.js.map +1 -0
- package/dist/front/parse/html.d.ts +8 -0
- package/dist/front/parse/html.d.ts.map +1 -0
- package/dist/front/parse/html.js +146 -0
- package/dist/front/parse/html.js.map +1 -0
- package/dist/front/parse/identifier.d.ts +4 -0
- package/dist/front/parse/identifier.d.ts.map +1 -0
- package/dist/front/parse/identifier.js +24 -0
- package/dist/front/parse/identifier.js.map +1 -0
- package/dist/front/parse/index.d.ts +13 -0
- package/dist/front/parse/index.d.ts.map +1 -0
- package/dist/front/parse/index.js +74 -0
- package/dist/front/parse/index.js.map +1 -0
- package/dist/front/parse/js.d.ts +27 -0
- package/dist/front/parse/js.d.ts.map +1 -0
- package/dist/front/parse/js.js +241 -0
- package/dist/front/parse/js.js.map +1 -0
- package/dist/front/parse/options.d.ts +3 -0
- package/dist/front/parse/options.d.ts.map +1 -0
- package/dist/front/parse/options.js +198 -0
- package/dist/front/parse/options.js.map +1 -0
- package/dist/front/parse/parser.d.ts +50 -0
- package/dist/front/parse/parser.d.ts.map +1 -0
- package/dist/front/parse/parser.js +157 -0
- package/dist/front/parse/parser.js.map +1 -0
- package/dist/front/parse/pattern.d.ts +4 -0
- package/dist/front/parse/pattern.d.ts.map +1 -0
- package/dist/front/parse/pattern.js +53 -0
- package/dist/front/parse/pattern.js.map +1 -0
- package/dist/front/parse/script.d.ts +4 -0
- package/dist/front/parse/script.d.ts.map +1 -0
- package/dist/front/parse/script.js +60 -0
- package/dist/front/parse/script.js.map +1 -0
- package/dist/front/parse/style.d.ts +7 -0
- package/dist/front/parse/style.d.ts.map +1 -0
- package/dist/front/parse/style.js +397 -0
- package/dist/front/parse/style.js.map +1 -0
- package/dist/front/parse/tag.d.ts +3 -0
- package/dist/front/parse/tag.d.ts.map +1 -0
- package/dist/front/parse/tag.js +591 -0
- package/dist/front/parse/tag.js.map +1 -0
- package/dist/front/print/css.d.ts +5 -0
- package/dist/front/print/css.d.ts.map +1 -0
- package/dist/front/print/css.js +234 -0
- package/dist/front/print/css.js.map +1 -0
- package/dist/front/print/index.d.ts +18 -0
- package/dist/front/print/index.d.ts.map +1 -0
- package/dist/front/print/index.js +24 -0
- package/dist/front/print/index.js.map +1 -0
- package/dist/front/print/layout.d.ts +11 -0
- package/dist/front/print/layout.d.ts.map +1 -0
- package/dist/front/print/layout.js +73 -0
- package/dist/front/print/layout.js.map +1 -0
- package/dist/front/print/template.d.ts +5 -0
- package/dist/front/print/template.d.ts.map +1 -0
- package/dist/front/print/template.js +455 -0
- package/dist/front/print/template.js.map +1 -0
- package/dist/front/runes.d.ts +13 -0
- package/dist/front/runes.d.ts.map +1 -0
- package/dist/front/runes.js +253 -0
- package/dist/front/runes.js.map +1 -0
- package/dist/front/stores.d.ts +5 -0
- package/dist/front/stores.d.ts.map +1 -0
- package/dist/front/stores.js +84 -0
- package/dist/front/stores.js.map +1 -0
- package/dist/front/typescript.d.ts +2 -0
- package/dist/front/typescript.d.ts.map +1 -0
- package/dist/front/typescript.js +182 -0
- package/dist/front/typescript.js.map +1 -0
- package/dist/front/validate/anchors.d.ts +15 -0
- package/dist/front/validate/anchors.d.ts.map +1 -0
- package/dist/front/validate/anchors.js +43 -0
- package/dist/front/validate/anchors.js.map +1 -0
- package/dist/front/validate/index.d.ts +16 -0
- package/dist/front/validate/index.d.ts.map +1 -0
- package/dist/front/validate/index.js +139 -0
- package/dist/front/validate/index.js.map +1 -0
- package/dist/front/validate/legacy.d.ts +9 -0
- package/dist/front/validate/legacy.d.ts.map +1 -0
- package/dist/front/validate/legacy.js +102 -0
- package/dist/front/validate/legacy.js.map +1 -0
- package/dist/front/validate/report.d.ts +14 -0
- package/dist/front/validate/report.d.ts.map +1 -0
- package/dist/front/validate/report.js +29 -0
- package/dist/front/validate/report.js.map +1 -0
- package/dist/front/validate/template.d.ts +31 -0
- package/dist/front/validate/template.d.ts.map +1 -0
- package/dist/front/validate/template.js +507 -0
- package/dist/front/validate/template.js.map +1 -0
- package/dist/front/wording.d.ts +4 -0
- package/dist/front/wording.d.ts.map +1 -0
- package/dist/front/wording.js +110 -0
- package/dist/front/wording.js.map +1 -0
- package/dist/shared/format.d.ts +3 -0
- package/dist/shared/format.d.ts.map +1 -0
- package/dist/shared/format.js +7 -0
- package/dist/shared/format.js.map +1 -0
- package/easing.d.ts +2 -0
- package/elements.d.ts +1220 -0
- package/index.d.ts +2 -0
- package/motion.d.ts +2 -0
- package/package.json +128 -5
- package/src/compiler/diagnostics.ts +233 -0
- package/src/compiler/index.ts +292 -0
- package/src/compiler/options.ts +140 -0
- package/src/compiler/preprocess/decode.ts +85 -0
- package/src/compiler/preprocess/index.ts +299 -0
- package/src/compiler/preprocess/mapped.ts +146 -0
- package/src/compiler/proxy.ts +154 -0
- package/src/entries/action.ts +1 -0
- package/src/entries/animate.ts +1 -0
- package/src/entries/attachments.ts +1 -0
- package/src/entries/context.ts +50 -0
- package/src/entries/easing.ts +1 -0
- package/src/entries/events.ts +1 -0
- package/src/entries/index-server.ts +17 -0
- package/src/entries/index.ts +41 -0
- package/src/entries/internal/client.ts +15 -0
- package/src/entries/internal/disclose-version.ts +4 -0
- package/src/entries/internal/index.ts +3 -0
- package/src/entries/internal/server.ts +8 -0
- package/src/entries/internal/tracing.ts +1 -0
- package/src/entries/motion-server.ts +1 -0
- package/src/entries/motion.ts +1 -0
- package/src/entries/proxy.ts +86 -0
- package/src/entries/reactivity-server.ts +9 -0
- package/src/entries/reactivity.ts +9 -0
- package/src/entries/report.ts +81 -0
- package/src/entries/server.ts +76 -0
- package/src/entries/store-client.ts +80 -0
- package/src/entries/store-server.ts +44 -0
- package/src/entries/store.ts +201 -0
- package/src/entries/transition.ts +1 -0
- package/src/entries/window-server.ts +1 -0
- package/src/entries/window.ts +1 -0
- package/src/front/ast.ts +369 -0
- package/src/front/diagnostics.ts +53 -0
- package/src/front/ignores.ts +84 -0
- package/src/front/index.ts +86 -0
- package/src/front/legacy.ts +414 -0
- package/src/front/locate.ts +20 -0
- package/src/front/lower.ts +509 -0
- package/src/front/parse/attribute.ts +319 -0
- package/src/front/parse/bracket.ts +99 -0
- package/src/front/parse/characters.ts +19 -0
- package/src/front/parse/decode.ts +87 -0
- package/src/front/parse/element.ts +354 -0
- package/src/front/parse/entities.ts +2233 -0
- package/src/front/parse/expression.ts +85 -0
- package/src/front/parse/html.ts +158 -0
- package/src/front/parse/identifier.ts +29 -0
- package/src/front/parse/index.ts +88 -0
- package/src/front/parse/js.ts +284 -0
- package/src/front/parse/options.ts +194 -0
- package/src/front/parse/parser.ts +189 -0
- package/src/front/parse/pattern.ts +57 -0
- package/src/front/parse/script.ts +74 -0
- package/src/front/parse/style.ts +399 -0
- package/src/front/parse/tag.ts +601 -0
- package/src/front/print/css.ts +239 -0
- package/src/front/print/index.ts +40 -0
- package/src/front/print/layout.ts +87 -0
- package/src/front/print/template.ts +448 -0
- package/src/front/runes.ts +267 -0
- package/src/front/stores.ts +98 -0
- package/src/front/typescript.ts +178 -0
- package/src/front/validate/anchors.ts +54 -0
- package/src/front/validate/index.ts +174 -0
- package/src/front/validate/legacy.ts +119 -0
- package/src/front/validate/report.ts +38 -0
- package/src/front/validate/template.ts +549 -0
- package/src/front/wording.ts +112 -0
- package/src/shared/format.ts +8 -0
- package/store.d.ts +2 -0
- package/svelte-html.d.ts +53 -0
- package/transition.d.ts +2 -0
- package/types/compiler/interfaces.d.ts +2 -0
- package/types/compiler/preprocess.d.ts +2 -0
- package/types/index.d.ts +1453 -0
- package/README.md +0 -3
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import type * as AST from '../ast.ts';
|
|
2
|
+
import { fail } from '../diagnostics.ts';
|
|
3
|
+
import {
|
|
4
|
+
attributeExpression,
|
|
5
|
+
isExpressionAttribute,
|
|
6
|
+
readAttribute,
|
|
7
|
+
readSequence,
|
|
8
|
+
readStaticAttribute,
|
|
9
|
+
readTag,
|
|
10
|
+
readTagName
|
|
11
|
+
} from './attribute.ts';
|
|
12
|
+
import { closingTagOmitted, isVoid, validComponentName, validElementName } from './html.ts';
|
|
13
|
+
import { fragment, type Open, type Parser } from './parser.ts';
|
|
14
|
+
import { readScript } from './script.ts';
|
|
15
|
+
import { readStyle } from './style.ts';
|
|
16
|
+
|
|
17
|
+
const textareaEnd = /<\/textarea(\s[^>]*)?>/iy;
|
|
18
|
+
|
|
19
|
+
const rootOnly = new Map<string, AST.ElementType>([
|
|
20
|
+
['svelte:head', 'SvelteHead'],
|
|
21
|
+
['svelte:options', 'SvelteOptions'],
|
|
22
|
+
['svelte:window', 'SvelteWindow'],
|
|
23
|
+
['svelte:document', 'SvelteDocument'],
|
|
24
|
+
['svelte:body', 'SvelteBody']
|
|
25
|
+
]);
|
|
26
|
+
|
|
27
|
+
const metaTags = new Map<string, AST.ElementType>([
|
|
28
|
+
...rootOnly,
|
|
29
|
+
['svelte:element', 'SvelteElement'],
|
|
30
|
+
['svelte:component', 'SvelteComponent'],
|
|
31
|
+
['svelte:self', 'SvelteSelf'],
|
|
32
|
+
['svelte:fragment', 'SvelteFragment'],
|
|
33
|
+
['svelte:boundary', 'SvelteBoundary']
|
|
34
|
+
]);
|
|
35
|
+
|
|
36
|
+
const metaList = (() => {
|
|
37
|
+
const names = [...metaTags.keys()];
|
|
38
|
+
return `${names.slice(0, -1).join(', ')} or ${names.at(-1)}`;
|
|
39
|
+
})();
|
|
40
|
+
|
|
41
|
+
const elementNodes = new Set([
|
|
42
|
+
'SvelteElement',
|
|
43
|
+
'RegularElement',
|
|
44
|
+
'SvelteFragment',
|
|
45
|
+
'Component',
|
|
46
|
+
'SvelteComponent',
|
|
47
|
+
'SvelteSelf',
|
|
48
|
+
'SlotElement'
|
|
49
|
+
]);
|
|
50
|
+
|
|
51
|
+
function isElement(node: Open): node is AST.ElementLike {
|
|
52
|
+
return elementNodes.has(node.type);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function element(parser: Parser): void {
|
|
56
|
+
const start = parser.index++;
|
|
57
|
+
const parent = parser.current();
|
|
58
|
+
|
|
59
|
+
if (parser.eat('!--')) {
|
|
60
|
+
const data = parser.readUntil('-->');
|
|
61
|
+
parser.eat('-->', true);
|
|
62
|
+
parser.append({ type: 'Comment', start, end: parser.index, data });
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (parser.eat('/')) {
|
|
67
|
+
closeElement(parser, start, parent);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const tag = readTag(parser);
|
|
72
|
+
if (tag.name.startsWith('svelte:') && !metaTags.has(tag.name)) {
|
|
73
|
+
fail(
|
|
74
|
+
'svelte_meta_invalid_tag',
|
|
75
|
+
{ start: start + 1, end: start + 1 + tag.name.length },
|
|
76
|
+
{ list: metaList }
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
if (!validElementName(tag.name) && !validComponentName.test(tag.name)) {
|
|
80
|
+
if (!parser.loose || !tag.name.endsWith('.')) {
|
|
81
|
+
fail('tag_invalid_name', { start: start + 1, end: start + 1 + tag.name.length });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (rootOnly.has(tag.name)) {
|
|
85
|
+
if (parser.meta.has(tag.name)) fail('svelte_meta_duplicate', start, { name: tag.name });
|
|
86
|
+
if (parent.type !== 'Root') fail('svelte_meta_invalid_placement', start, { name: tag.name });
|
|
87
|
+
parser.meta.add(tag.name);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const type: AST.ElementType =
|
|
91
|
+
metaTags.get(tag.name) ??
|
|
92
|
+
(validComponentName.test(tag.name) || (parser.loose && tag.name.endsWith('.'))
|
|
93
|
+
? 'Component'
|
|
94
|
+
: tag.name === 'title' && insideHead(parser.stack)
|
|
95
|
+
? 'TitleElement'
|
|
96
|
+
: tag.name === 'slot' && !insideShadowRoot(parser.stack)
|
|
97
|
+
? 'SlotElement'
|
|
98
|
+
: 'RegularElement');
|
|
99
|
+
|
|
100
|
+
const node: AST.ElementLike = {
|
|
101
|
+
type,
|
|
102
|
+
start,
|
|
103
|
+
end: -1,
|
|
104
|
+
name: tag.name,
|
|
105
|
+
name_loc: tag.loc,
|
|
106
|
+
attributes: [],
|
|
107
|
+
fragment: fragment()
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
parser.allowWhitespace();
|
|
111
|
+
|
|
112
|
+
if (parent.type === 'RegularElement' && closingTagOmitted(parent.name, tag.name)) {
|
|
113
|
+
const end = parent.fragment.nodes[0]?.start ?? start;
|
|
114
|
+
parser.warn(
|
|
115
|
+
'element_implicitly_closed',
|
|
116
|
+
{ start: parent.start, end },
|
|
117
|
+
{ tag: `<${tag.name}>`, closing: `</${parent.name}>` }
|
|
118
|
+
);
|
|
119
|
+
parent.end = start;
|
|
120
|
+
parser.pop();
|
|
121
|
+
parser.lastAutoClosed = { tag: parent.name, reason: tag.name, depth: parser.stack.length };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const current = parser.current();
|
|
125
|
+
const topLevel = (tag.name === 'script' || tag.name === 'style') && current.type === 'Root';
|
|
126
|
+
readAttributes(parser, node, topLevel);
|
|
127
|
+
thisAttribute(parser, node, start);
|
|
128
|
+
|
|
129
|
+
if (topLevel) {
|
|
130
|
+
parser.eat('>', true);
|
|
131
|
+
topLevelContent(parser, current as AST.Root, node, start);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
parser.append(node);
|
|
136
|
+
content(parser, node);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function readAttributes(parser: Parser, node: AST.ElementLike, topLevel: boolean): void {
|
|
140
|
+
const unique = new Set<string>();
|
|
141
|
+
for (;;) {
|
|
142
|
+
const attribute = topLevel ? readStaticAttribute(parser) : readAttribute(parser);
|
|
143
|
+
if (attribute === null) return;
|
|
144
|
+
if (
|
|
145
|
+
attribute.type === 'Attribute' ||
|
|
146
|
+
attribute.type === 'BindDirective' ||
|
|
147
|
+
attribute.type === 'StyleDirective' ||
|
|
148
|
+
attribute.type === 'ClassDirective'
|
|
149
|
+
) {
|
|
150
|
+
const kind = attribute.type === 'BindDirective' ? 'Attribute' : attribute.type;
|
|
151
|
+
const key = `${kind}${attribute.name}`;
|
|
152
|
+
if (unique.has(key)) fail('attribute_duplicate', attribute);
|
|
153
|
+
else if (attribute.name !== 'this') unique.add(key);
|
|
154
|
+
}
|
|
155
|
+
node.attributes.push(attribute);
|
|
156
|
+
parser.allowWhitespace();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function takeThis(node: AST.ElementLike): AST.Attribute | null {
|
|
161
|
+
const index = node.attributes.findIndex(
|
|
162
|
+
(attribute) => attribute.type === 'Attribute' && attribute.name === 'this'
|
|
163
|
+
);
|
|
164
|
+
return index === -1 ? null : (node.attributes.splice(index, 1)[0] as AST.Attribute);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function thisAttribute(parser: Parser, node: AST.ElementLike, start: number): void {
|
|
168
|
+
if (node.type === 'SvelteComponent') {
|
|
169
|
+
const definition = takeThis(node);
|
|
170
|
+
if (definition === null) fail('svelte_component_missing_this', start);
|
|
171
|
+
if (!isExpressionAttribute(definition)) fail('svelte_component_invalid_this', definition.start);
|
|
172
|
+
node.expression = attributeExpression(definition);
|
|
173
|
+
}
|
|
174
|
+
if (node.type === 'SvelteElement') {
|
|
175
|
+
const definition = takeThis(node);
|
|
176
|
+
if (definition === null) fail('svelte_element_missing_this', start);
|
|
177
|
+
if (definition.value === true) fail('svelte_element_missing_this', definition);
|
|
178
|
+
if (isExpressionAttribute(definition)) {
|
|
179
|
+
node.tag = attributeExpression(definition);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
parser.warn('svelte_element_invalid_this', definition);
|
|
183
|
+
const chunk = (definition.value as (AST.Text | AST.ExpressionTag)[])[0] as
|
|
184
|
+
| AST.Text
|
|
185
|
+
| AST.ExpressionTag;
|
|
186
|
+
node.tag =
|
|
187
|
+
chunk.type === 'Text'
|
|
188
|
+
? ({
|
|
189
|
+
type: 'Literal',
|
|
190
|
+
value: chunk.data,
|
|
191
|
+
raw: `'${chunk.raw}'`,
|
|
192
|
+
start: chunk.start,
|
|
193
|
+
end: chunk.end
|
|
194
|
+
} as AST.Expression)
|
|
195
|
+
: chunk.expression;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function topLevelContent(
|
|
200
|
+
parser: Parser,
|
|
201
|
+
root: AST.Root,
|
|
202
|
+
node: AST.ElementLike,
|
|
203
|
+
start: number
|
|
204
|
+
): void {
|
|
205
|
+
const comment = precedingComment(root, start);
|
|
206
|
+
if (node.name === 'script') {
|
|
207
|
+
const script = readScript(parser, start, node.attributes);
|
|
208
|
+
if (comment !== null) {
|
|
209
|
+
(script.content as unknown as { leadingComments: unknown[] }).leadingComments = [
|
|
210
|
+
{ type: 'Line', value: comment.data }
|
|
211
|
+
];
|
|
212
|
+
}
|
|
213
|
+
if (script.context === 'module') {
|
|
214
|
+
if (root.module !== undefined) fail('script_duplicate', start);
|
|
215
|
+
root.module = script;
|
|
216
|
+
} else {
|
|
217
|
+
if (root.instance !== undefined) fail('script_duplicate', start);
|
|
218
|
+
root.instance = script;
|
|
219
|
+
}
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
const style = readStyle(parser, start, node.attributes);
|
|
223
|
+
style.content.comment = comment;
|
|
224
|
+
if (root.css !== null) fail('style_duplicate', start);
|
|
225
|
+
root.css = style;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function content(parser: Parser, node: AST.ElementLike): void {
|
|
229
|
+
const selfClosing = parser.eat('/') || isVoid(node.name);
|
|
230
|
+
const closed = parser.eat('>', true, false);
|
|
231
|
+
|
|
232
|
+
if (!closed) {
|
|
233
|
+
const last = node.attributes.at(-1);
|
|
234
|
+
if (last?.type === 'Attribute' && last.name === '<') {
|
|
235
|
+
parser.index = last.start;
|
|
236
|
+
node.attributes.pop();
|
|
237
|
+
} else {
|
|
238
|
+
const before = parser.template[parser.index - 1];
|
|
239
|
+
const twoBefore = parser.template[parser.index - 2];
|
|
240
|
+
const here = parser.template[parser.index];
|
|
241
|
+
if (twoBefore === '{' && before === '/') parser.index -= 2;
|
|
242
|
+
else if (before === '{' && (here === '#' || here === '@' || here === ':')) parser.index -= 1;
|
|
243
|
+
else parser.allowWhitespace();
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (selfClosing || !closed) {
|
|
248
|
+
node.end = parser.index;
|
|
249
|
+
} else if (node.name === 'textarea') {
|
|
250
|
+
node.fragment.nodes = readSequence(
|
|
251
|
+
parser,
|
|
252
|
+
() => {
|
|
253
|
+
textareaEnd.lastIndex = parser.index;
|
|
254
|
+
return textareaEnd.test(parser.template);
|
|
255
|
+
},
|
|
256
|
+
'inside <textarea>'
|
|
257
|
+
);
|
|
258
|
+
parser.read(textareaEnd);
|
|
259
|
+
node.end = parser.index;
|
|
260
|
+
} else if (node.name === 'script' || node.name === 'style') {
|
|
261
|
+
const from = parser.index;
|
|
262
|
+
const closing = `</${node.name}>`;
|
|
263
|
+
const found = parser.template.indexOf(closing, parser.index);
|
|
264
|
+
const to = found === -1 ? parser.template.length : found;
|
|
265
|
+
const data = parser.template.slice(from, to);
|
|
266
|
+
parser.index = to;
|
|
267
|
+
node.fragment.nodes.push({ start: from, end: to, type: 'Text', data, raw: data });
|
|
268
|
+
parser.eat(closing, true);
|
|
269
|
+
node.end = parser.index;
|
|
270
|
+
} else {
|
|
271
|
+
parser.push(node, node.fragment);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function closeElement(parser: Parser, start: number, from: Open): void {
|
|
276
|
+
let parent = from;
|
|
277
|
+
const name = readTagName(parser);
|
|
278
|
+
parser.allowWhitespace();
|
|
279
|
+
parser.eat('>', true);
|
|
280
|
+
if (isVoid(name)) fail('void_element_invalid_content', start);
|
|
281
|
+
|
|
282
|
+
while ((parent as AST.ElementLike).name !== name) {
|
|
283
|
+
if (parser.loose && isElement(parent)) {
|
|
284
|
+
const last = parent.attributes.at(-1);
|
|
285
|
+
if (last?.type === 'Attribute' && last.name === `<${name}`) {
|
|
286
|
+
parser.index = last.start;
|
|
287
|
+
parent.attributes.pop();
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
if (parent.type === 'RegularElement') {
|
|
292
|
+
if (parser.lastAutoClosed === undefined || parser.lastAutoClosed.tag !== name) {
|
|
293
|
+
const end = parent.fragment.nodes[0]?.start ?? start;
|
|
294
|
+
parser.warn(
|
|
295
|
+
'element_implicitly_closed',
|
|
296
|
+
{ start: parent.start, end },
|
|
297
|
+
{ tag: `</${name}>`, closing: `</${parent.name}>` }
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
} else if (!parser.loose) {
|
|
301
|
+
if (parser.lastAutoClosed !== undefined && parser.lastAutoClosed.tag === name) {
|
|
302
|
+
fail('element_invalid_closing_tag_autoclosed', start, {
|
|
303
|
+
name,
|
|
304
|
+
reason: parser.lastAutoClosed.reason
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
fail('element_invalid_closing_tag', start, { name });
|
|
308
|
+
}
|
|
309
|
+
parent.end = start;
|
|
310
|
+
parser.pop();
|
|
311
|
+
parent = parser.current();
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
parent.end = parser.index;
|
|
315
|
+
parser.pop();
|
|
316
|
+
if (parser.lastAutoClosed !== undefined && parser.stack.length < parser.lastAutoClosed.depth) {
|
|
317
|
+
parser.lastAutoClosed = undefined;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function precedingComment(root: AST.Root, start: number): AST.Comment | null {
|
|
322
|
+
const nodes = root.fragment.nodes;
|
|
323
|
+
for (let index = nodes.length - 1; index >= 0; index--) {
|
|
324
|
+
const node = nodes[index] as AST.TemplateNode;
|
|
325
|
+
if (index === nodes.length - 1 && node.end !== start) return null;
|
|
326
|
+
if (node.type === 'Comment') return node;
|
|
327
|
+
if (node.type !== 'Text' || node.data.trim()) return null;
|
|
328
|
+
}
|
|
329
|
+
return null;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function insideHead(stack: readonly Open[]): boolean {
|
|
333
|
+
for (let index = stack.length - 1; index >= 0; index--) {
|
|
334
|
+
const type = (stack[index] as Open).type;
|
|
335
|
+
if (type === 'SvelteHead') return true;
|
|
336
|
+
if (type === 'RegularElement' || type === 'Component') return false;
|
|
337
|
+
}
|
|
338
|
+
return false;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function insideShadowRoot(stack: readonly Open[]): boolean {
|
|
342
|
+
for (let index = stack.length - 1; index >= 0; index--) {
|
|
343
|
+
const node = stack[index] as Open;
|
|
344
|
+
if (
|
|
345
|
+
node.type === 'RegularElement' &&
|
|
346
|
+
node.attributes.some(
|
|
347
|
+
(attribute) => attribute.type === 'Attribute' && attribute.name === 'shadowrootmode'
|
|
348
|
+
)
|
|
349
|
+
) {
|
|
350
|
+
return true;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return false;
|
|
354
|
+
}
|