@vigla/svelte 0.0.0-stage → 5.57.3
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 +123 -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,194 @@
|
|
|
1
|
+
import type * as ES from 'estree';
|
|
2
|
+
import type * as AST from '../ast.ts';
|
|
3
|
+
import { fail, type At } from '../diagnostics.ts';
|
|
4
|
+
|
|
5
|
+
const svgNamespace = 'http://www.w3.org/2000/svg';
|
|
6
|
+
const mathmlNamespace = 'http://www.w3.org/1998/Math/MathML';
|
|
7
|
+
|
|
8
|
+
const tagChar =
|
|
9
|
+
'[a-z0-9_.\xB7\xC0-\xD6\xD8-\xF6\xF8-\u037D\u037F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u{10000}-\u{EFFFF}-]';
|
|
10
|
+
const customTag = new RegExp(`^[a-z]${tagChar}*-${tagChar}*$`, 'u');
|
|
11
|
+
const reservedTags = new Set([
|
|
12
|
+
'annotation-xml',
|
|
13
|
+
'color-profile',
|
|
14
|
+
'font-face',
|
|
15
|
+
'font-face-src',
|
|
16
|
+
'font-face-uri',
|
|
17
|
+
'font-face-format',
|
|
18
|
+
'font-face-name',
|
|
19
|
+
'missing-glyph'
|
|
20
|
+
]);
|
|
21
|
+
|
|
22
|
+
const propTypes = new Set(['String', 'Number', 'Boolean', 'Array', 'Object']);
|
|
23
|
+
|
|
24
|
+
type Static = string | number | boolean | RegExp | bigint | null | undefined;
|
|
25
|
+
|
|
26
|
+
function staticValue(attribute: AST.Attribute): Static {
|
|
27
|
+
const { value } = attribute;
|
|
28
|
+
if (value === true) return true;
|
|
29
|
+
const chunk = Array.isArray(value) ? value[0] : value;
|
|
30
|
+
if (chunk === undefined) return true;
|
|
31
|
+
if (Array.isArray(value) && value.length > 1) return null;
|
|
32
|
+
if (chunk.type === 'Text') return chunk.data;
|
|
33
|
+
if (chunk.expression.type !== 'Literal') return null;
|
|
34
|
+
return chunk.expression.value;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function booleanValue(attribute: AST.Attribute): boolean {
|
|
38
|
+
const value = staticValue(attribute);
|
|
39
|
+
if (typeof value !== 'boolean') {
|
|
40
|
+
fail('svelte_options_invalid_attribute_value', attribute, { list: 'true or false' });
|
|
41
|
+
}
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function validateTag(at: At, tag: unknown): asserts tag is string {
|
|
46
|
+
if (typeof tag !== 'string') fail('svelte_options_invalid_tagname', at);
|
|
47
|
+
if (tag) {
|
|
48
|
+
if (!customTag.test(tag)) fail('svelte_options_invalid_tagname', at);
|
|
49
|
+
if (reservedTags.has(tag)) fail('svelte_options_reserved_tagname', at);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function plainKey(property: ES.Property | ES.SpreadElement): property is ES.Property & {
|
|
54
|
+
key: ES.Identifier;
|
|
55
|
+
} {
|
|
56
|
+
return property.type === 'Property' && !property.computed && property.key.type === 'Identifier';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function customElement(attribute: AST.Attribute): AST.CustomElementOptions | undefined {
|
|
60
|
+
const options: AST.CustomElementOptions = {};
|
|
61
|
+
const raw = attribute.value;
|
|
62
|
+
if (raw === true) fail('svelte_options_invalid_customelement', attribute);
|
|
63
|
+
const value = Array.isArray(raw) ? raw : [raw];
|
|
64
|
+
const first = value[0] as AST.Text | AST.ExpressionTag;
|
|
65
|
+
if (first.type === 'Text') {
|
|
66
|
+
const tag = staticValue(attribute);
|
|
67
|
+
validateTag(attribute, tag);
|
|
68
|
+
options.tag = tag;
|
|
69
|
+
return options;
|
|
70
|
+
}
|
|
71
|
+
const expression = first.expression;
|
|
72
|
+
if (expression.type !== 'ObjectExpression') {
|
|
73
|
+
if (expression.type === 'Literal' && expression.value === null) return undefined;
|
|
74
|
+
fail('svelte_options_invalid_customelement', attribute);
|
|
75
|
+
}
|
|
76
|
+
const properties: [string, ES.Node][] = [];
|
|
77
|
+
for (const property of expression.properties) {
|
|
78
|
+
if (!plainKey(property)) fail('svelte_options_invalid_customelement', attribute);
|
|
79
|
+
properties.push([property.key.name, property.value]);
|
|
80
|
+
}
|
|
81
|
+
const find = (name: string): ES.Node | undefined => properties.find(([key]) => key === name)?.[1];
|
|
82
|
+
|
|
83
|
+
const tag = properties.find(([name]) => name === 'tag');
|
|
84
|
+
if (tag !== undefined) {
|
|
85
|
+
const tagValue = (tag[1] as ES.Literal | undefined)?.value;
|
|
86
|
+
validateTag(tag as unknown as At, tagValue);
|
|
87
|
+
options.tag = tagValue;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const props = find('props');
|
|
91
|
+
if (props !== undefined) {
|
|
92
|
+
if (props.type !== 'ObjectExpression')
|
|
93
|
+
fail('svelte_options_invalid_customelement_props', attribute);
|
|
94
|
+
options.props = {};
|
|
95
|
+
for (const property of props.properties) {
|
|
96
|
+
if (!plainKey(property) || property.value.type !== 'ObjectExpression') {
|
|
97
|
+
fail('svelte_options_invalid_customelement_props', attribute);
|
|
98
|
+
}
|
|
99
|
+
const prop: AST.CustomElementProp = {};
|
|
100
|
+
options.props[property.key.name] = prop;
|
|
101
|
+
for (const entry of property.value.properties) {
|
|
102
|
+
if (!plainKey(entry) || entry.value.type !== 'Literal') {
|
|
103
|
+
fail('svelte_options_invalid_customelement_props', attribute);
|
|
104
|
+
}
|
|
105
|
+
const literal = entry.value.value;
|
|
106
|
+
if (entry.key.name === 'type') {
|
|
107
|
+
if (!propTypes.has(literal as string)) {
|
|
108
|
+
fail('svelte_options_invalid_customelement_props', attribute);
|
|
109
|
+
}
|
|
110
|
+
prop.type = literal as AST.CustomElementProp['type'];
|
|
111
|
+
} else if (entry.key.name === 'reflect') {
|
|
112
|
+
if (typeof literal !== 'boolean')
|
|
113
|
+
fail('svelte_options_invalid_customelement_props', attribute);
|
|
114
|
+
prop.reflect = literal;
|
|
115
|
+
} else if (entry.key.name === 'attribute') {
|
|
116
|
+
if (typeof literal !== 'string')
|
|
117
|
+
fail('svelte_options_invalid_customelement_props', attribute);
|
|
118
|
+
prop.attribute = literal;
|
|
119
|
+
} else {
|
|
120
|
+
fail('svelte_options_invalid_customelement_props', attribute);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const shadow = find('shadow');
|
|
127
|
+
if (shadow) {
|
|
128
|
+
if (shadow.type === 'Literal' && (shadow.value === 'open' || shadow.value === 'none')) {
|
|
129
|
+
options.shadow = shadow.value;
|
|
130
|
+
} else if (shadow.type === 'ObjectExpression') {
|
|
131
|
+
options.shadow = shadow;
|
|
132
|
+
} else {
|
|
133
|
+
fail('svelte_options_invalid_customelement_shadow', attribute);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const extend = find('extend');
|
|
138
|
+
if (extend) options.extend = extend as AST.Expression;
|
|
139
|
+
return options;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function readOptions(node: AST.ElementLike): AST.SvelteOptions {
|
|
143
|
+
const options: AST.SvelteOptions = {
|
|
144
|
+
start: node.start,
|
|
145
|
+
end: node.end,
|
|
146
|
+
attributes: node.attributes
|
|
147
|
+
};
|
|
148
|
+
for (const attribute of node.attributes) {
|
|
149
|
+
if (attribute.type !== 'Attribute') fail('svelte_options_invalid_attribute', attribute);
|
|
150
|
+
const { name } = attribute;
|
|
151
|
+
switch (name) {
|
|
152
|
+
case 'runes':
|
|
153
|
+
options.runes = booleanValue(attribute);
|
|
154
|
+
break;
|
|
155
|
+
case 'tag':
|
|
156
|
+
fail('svelte_options_deprecated_tag', attribute);
|
|
157
|
+
case 'customElement': {
|
|
158
|
+
const element = customElement(attribute);
|
|
159
|
+
if (element !== undefined) options.customElement = element;
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
case 'namespace': {
|
|
163
|
+
const value = staticValue(attribute);
|
|
164
|
+
if (value === svgNamespace) options.namespace = 'svg';
|
|
165
|
+
else if (value === mathmlNamespace) options.namespace = 'mathml';
|
|
166
|
+
else if (value === 'html' || value === 'mathml' || value === 'svg')
|
|
167
|
+
options.namespace = value;
|
|
168
|
+
else {
|
|
169
|
+
fail('svelte_options_invalid_attribute_value', attribute, {
|
|
170
|
+
list: '"html", "mathml" or "svg"'
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
case 'css': {
|
|
176
|
+
if (staticValue(attribute) === 'injected') options.css = 'injected';
|
|
177
|
+
else fail('svelte_options_invalid_attribute_value', attribute, { list: '"injected"' });
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
case 'immutable':
|
|
181
|
+
options.immutable = booleanValue(attribute);
|
|
182
|
+
break;
|
|
183
|
+
case 'preserveWhitespace':
|
|
184
|
+
options.preserveWhitespace = booleanValue(attribute);
|
|
185
|
+
break;
|
|
186
|
+
case 'accessors':
|
|
187
|
+
options.accessors = booleanValue(attribute);
|
|
188
|
+
break;
|
|
189
|
+
default:
|
|
190
|
+
fail('svelte_options_unknown_attribute', attribute, { name });
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return options;
|
|
194
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import type * as ES from 'estree';
|
|
2
|
+
import type { Diagnostic } from 'vigla/compiler';
|
|
3
|
+
import type * as AST from '../ast.ts';
|
|
4
|
+
import { fail, warning, type Args, type At } from '../diagnostics.ts';
|
|
5
|
+
import type { Locator } from '../locate.ts';
|
|
6
|
+
import { isReserved, isWhitespace } from './html.ts';
|
|
7
|
+
import { identifierEnd } from './identifier.ts';
|
|
8
|
+
import type { Context } from './js.ts';
|
|
9
|
+
|
|
10
|
+
export type Open = AST.Root | AST.ElementLike | AST.Block;
|
|
11
|
+
|
|
12
|
+
export interface AutoClosed {
|
|
13
|
+
readonly tag: string;
|
|
14
|
+
readonly reason: string;
|
|
15
|
+
readonly depth: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type Identifier = ES.Identifier & AST.Located & { loc: AST.NameLocation };
|
|
19
|
+
|
|
20
|
+
const scriptLang =
|
|
21
|
+
/<!--[^]*?-->|<script\s+(?:[^>]*|(?:[^=>'"/]+=(?:"[^"]*"|'[^']*'|[^>\s]+)\s+)*)lang=(["'])?([^"' >]+)\1[^>]*>/g;
|
|
22
|
+
|
|
23
|
+
function typescript(source: string): boolean {
|
|
24
|
+
scriptLang.lastIndex = 0;
|
|
25
|
+
let match: RegExpExecArray | null;
|
|
26
|
+
do match = scriptLang.exec(source);
|
|
27
|
+
while (match !== null && match[0][1] !== 's');
|
|
28
|
+
scriptLang.lastIndex = 0;
|
|
29
|
+
return match?.[2] === 'ts';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class Scanner {
|
|
33
|
+
template: string;
|
|
34
|
+
readonly loose: boolean;
|
|
35
|
+
cssComments: AST.Css.Comment[] = [];
|
|
36
|
+
index = 0;
|
|
37
|
+
|
|
38
|
+
constructor(template: string, loose: boolean) {
|
|
39
|
+
this.template = template;
|
|
40
|
+
this.loose = loose;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
match(text: string): boolean {
|
|
44
|
+
return text.length === 1
|
|
45
|
+
? this.template[this.index] === text
|
|
46
|
+
: this.template.startsWith(text, this.index);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
eat(text: string, required = false, requiredInLoose = true): boolean {
|
|
50
|
+
if (this.match(text)) {
|
|
51
|
+
this.index += text.length;
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
if (required && (!this.loose || requiredInLoose))
|
|
55
|
+
fail('expected_token', this.index, { token: text });
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
matchRegex(pattern: RegExp): string | null {
|
|
60
|
+
pattern.lastIndex = this.index;
|
|
61
|
+
const match = pattern.exec(this.template);
|
|
62
|
+
if (match === null || match.index !== this.index) return null;
|
|
63
|
+
return match[0];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
read(pattern: RegExp): string | null {
|
|
67
|
+
const result = this.matchRegex(pattern);
|
|
68
|
+
if (result) this.index += result.length;
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
allowWhitespace(): void {
|
|
73
|
+
while (
|
|
74
|
+
this.index < this.template.length &&
|
|
75
|
+
isWhitespace(this.template.charCodeAt(this.index))
|
|
76
|
+
) {
|
|
77
|
+
this.index++;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
readUntil(delimiter: string): string {
|
|
82
|
+
if (this.index >= this.template.length) {
|
|
83
|
+
if (this.loose) return '';
|
|
84
|
+
fail('unexpected_eof', this.template.length);
|
|
85
|
+
}
|
|
86
|
+
const start = this.index;
|
|
87
|
+
const found = this.template.indexOf(delimiter, start);
|
|
88
|
+
this.index = found === -1 ? this.template.length : found;
|
|
89
|
+
return this.template.slice(start, this.index);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
readUntilRegex(pattern: RegExp): string {
|
|
93
|
+
if (this.index >= this.template.length) {
|
|
94
|
+
if (this.loose) return '';
|
|
95
|
+
fail('unexpected_eof', this.template.length);
|
|
96
|
+
}
|
|
97
|
+
const start = this.index;
|
|
98
|
+
const match = pattern.exec(this.template.slice(start));
|
|
99
|
+
this.index = match === null ? this.template.length : start + match.index;
|
|
100
|
+
return this.template.slice(start, this.index);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export class Parser extends Scanner implements Context {
|
|
105
|
+
readonly ts: boolean;
|
|
106
|
+
readonly locate: Locator;
|
|
107
|
+
readonly root: AST.Root;
|
|
108
|
+
readonly stack: Open[] = [];
|
|
109
|
+
readonly fragments: AST.Fragment[] = [];
|
|
110
|
+
readonly meta = new Set<string>();
|
|
111
|
+
readonly warnings: Diagnostic[] = [];
|
|
112
|
+
lastAutoClosed: AutoClosed | undefined;
|
|
113
|
+
|
|
114
|
+
constructor(source: string, loose: boolean, locate: Locator) {
|
|
115
|
+
super(source.trimEnd(), loose);
|
|
116
|
+
this.locate = locate;
|
|
117
|
+
this.ts = typescript(source);
|
|
118
|
+
this.root = {
|
|
119
|
+
css: null,
|
|
120
|
+
js: [],
|
|
121
|
+
start: 0,
|
|
122
|
+
end: source.length,
|
|
123
|
+
type: 'Root',
|
|
124
|
+
fragment: { type: 'Fragment', nodes: [] },
|
|
125
|
+
options: null,
|
|
126
|
+
comments: []
|
|
127
|
+
};
|
|
128
|
+
this.stack.push(this.root);
|
|
129
|
+
this.fragments.push(this.root.fragment);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
get comments(): AST.JSComment[] {
|
|
133
|
+
return this.root.comments;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
current(): Open {
|
|
137
|
+
return this.stack[this.stack.length - 1] as Open;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
warn(code: string, at: At, args?: Args): void {
|
|
141
|
+
this.warnings.push(warning(code, at, args));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
requireWhitespace(): void {
|
|
145
|
+
if (!isWhitespace(this.template.charCodeAt(this.index)))
|
|
146
|
+
fail('expected_whitespace', this.index);
|
|
147
|
+
this.index++;
|
|
148
|
+
this.allowWhitespace();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
readIdentifier(): Identifier {
|
|
152
|
+
const start = this.index;
|
|
153
|
+
let end = identifierEnd(this.template, start);
|
|
154
|
+
let name = '';
|
|
155
|
+
if (end === -1) {
|
|
156
|
+
end = start;
|
|
157
|
+
} else {
|
|
158
|
+
name = this.template.slice(start, end);
|
|
159
|
+
this.index = end;
|
|
160
|
+
if (isReserved(name)) fail('unexpected_reserved_word', start, { word: name });
|
|
161
|
+
}
|
|
162
|
+
return {
|
|
163
|
+
type: 'Identifier',
|
|
164
|
+
name,
|
|
165
|
+
start,
|
|
166
|
+
end,
|
|
167
|
+
loc: { start: this.locate(start), end: this.locate(end) }
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
push(node: Open, fragment: AST.Fragment): void {
|
|
172
|
+
this.stack.push(node);
|
|
173
|
+
this.fragments.push(fragment);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
pop(): Open | undefined {
|
|
177
|
+
this.fragments.pop();
|
|
178
|
+
return this.stack.pop();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
append<T extends AST.TemplateNode>(node: T): T {
|
|
182
|
+
this.fragments.at(-1)?.nodes.push(node);
|
|
183
|
+
return node;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function fragment(): AST.Fragment {
|
|
188
|
+
return { type: 'Fragment', nodes: [] };
|
|
189
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type * as AST from '../ast.ts';
|
|
2
|
+
import { fail } from '../diagnostics.ts';
|
|
3
|
+
import { matchBracket } from './bracket.ts';
|
|
4
|
+
import { parseExpressionAt, removeParens, type Node } from './js.ts';
|
|
5
|
+
import type { Parser } from './parser.ts';
|
|
6
|
+
|
|
7
|
+
export function readPattern(parser: Parser): AST.Pattern {
|
|
8
|
+
const start = parser.index;
|
|
9
|
+
const id = parser.readIdentifier();
|
|
10
|
+
if (id.name !== '') {
|
|
11
|
+
return { ...id, typeAnnotation: readTypeAnnotation(parser) } as AST.Pattern;
|
|
12
|
+
}
|
|
13
|
+
const char = parser.template[start];
|
|
14
|
+
if (char !== '{' && char !== '[') fail('expected_pattern', start);
|
|
15
|
+
const end = matchBracket(parser.template, start);
|
|
16
|
+
parser.index = end;
|
|
17
|
+
const assignment = removeParens(
|
|
18
|
+
parseExpressionAt(parser, `${parser.template.slice(0, end)} = 1`, start)
|
|
19
|
+
);
|
|
20
|
+
const pattern = assignment.left as Node;
|
|
21
|
+
pattern.typeAnnotation = readTypeAnnotation(parser);
|
|
22
|
+
if (pattern.typeAnnotation) pattern.end = (pattern.typeAnnotation as Node).end;
|
|
23
|
+
return pattern as unknown as AST.Pattern;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const optionalColon = /\?\s*:/g;
|
|
27
|
+
|
|
28
|
+
function readTypeAnnotation(parser: Parser): Node | undefined {
|
|
29
|
+
const start = parser.index;
|
|
30
|
+
parser.allowWhitespace();
|
|
31
|
+
if (!parser.eat(':')) {
|
|
32
|
+
parser.index = start;
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
const insert = '_ as ';
|
|
36
|
+
const from = parser.index - insert.length;
|
|
37
|
+
const template =
|
|
38
|
+
parser.template.slice(0, from) +
|
|
39
|
+
insert +
|
|
40
|
+
parser.template.slice(parser.index).replace(optionalColon, ':');
|
|
41
|
+
let expression = removeParens(parseExpressionAt(parser, template, from));
|
|
42
|
+
if (expression.type === 'AssignmentExpression') {
|
|
43
|
+
let equals = (expression.right as Node).start;
|
|
44
|
+
while (template[equals] !== '=') equals -= 1;
|
|
45
|
+
expression = removeParens(parseExpressionAt(parser, template.slice(0, equals), from));
|
|
46
|
+
}
|
|
47
|
+
if (expression.type === 'SequenceExpression') {
|
|
48
|
+
expression = (expression.expressions as Node[])[0] as Node;
|
|
49
|
+
}
|
|
50
|
+
parser.index = expression.end;
|
|
51
|
+
return {
|
|
52
|
+
type: 'TSTypeAnnotation',
|
|
53
|
+
start,
|
|
54
|
+
end: parser.index,
|
|
55
|
+
typeAnnotation: expression.typeAnnotation
|
|
56
|
+
} as unknown as Node;
|
|
57
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type * as AST from '../ast.ts';
|
|
2
|
+
import { fail } from '../diagnostics.ts';
|
|
3
|
+
import { parseScript } from './js.ts';
|
|
4
|
+
import type { Parser } from './parser.ts';
|
|
5
|
+
|
|
6
|
+
const closing = /<\/script\s*>/;
|
|
7
|
+
const closingHere = /<\/script\s*>/y;
|
|
8
|
+
const notNewline = /[^\n]/g;
|
|
9
|
+
|
|
10
|
+
const reserved = new Set(['server', 'client', 'worker', 'test', 'default']);
|
|
11
|
+
const allowed = new Set(['context', 'generics', 'lang', 'module']);
|
|
12
|
+
|
|
13
|
+
export function readScript(
|
|
14
|
+
parser: Parser,
|
|
15
|
+
start: number,
|
|
16
|
+
attributes: AST.AttributeLike[]
|
|
17
|
+
): AST.Script {
|
|
18
|
+
const contentStart = parser.index;
|
|
19
|
+
const data = parser.readUntilRegex(closing);
|
|
20
|
+
if (parser.index >= parser.template.length) {
|
|
21
|
+
fail('element_unclosed', parser.template.length, { name: 'script' });
|
|
22
|
+
}
|
|
23
|
+
const source = parser.template.slice(0, contentStart).replace(notNewline, ' ') + data;
|
|
24
|
+
parser.read(closingHere);
|
|
25
|
+
|
|
26
|
+
const ast = parseScript(source, parser.comments, parser.ts);
|
|
27
|
+
ast.start = contentStart;
|
|
28
|
+
const loc = ast.loc as {
|
|
29
|
+
start: { line: number; column: number };
|
|
30
|
+
end: { line: number; column: number };
|
|
31
|
+
};
|
|
32
|
+
const from = parser.locate(start);
|
|
33
|
+
const to = parser.locate(parser.index);
|
|
34
|
+
loc.start.line = from.line;
|
|
35
|
+
loc.start.column = from.column;
|
|
36
|
+
loc.end.line = to.line;
|
|
37
|
+
loc.end.column = to.column;
|
|
38
|
+
|
|
39
|
+
let context: 'default' | 'module' = 'default';
|
|
40
|
+
for (const attribute of attributes as AST.Attribute[]) {
|
|
41
|
+
if (reserved.has(attribute.name)) {
|
|
42
|
+
fail('script_reserved_attribute', attribute, { name: attribute.name });
|
|
43
|
+
}
|
|
44
|
+
if (!allowed.has(attribute.name)) parser.warn('script_unknown_attribute', attribute);
|
|
45
|
+
if (attribute.name === 'module') {
|
|
46
|
+
if (attribute.value !== true) {
|
|
47
|
+
fail('script_invalid_attribute_value', attribute, { name: attribute.name });
|
|
48
|
+
}
|
|
49
|
+
context = 'module';
|
|
50
|
+
}
|
|
51
|
+
if (attribute.name === 'context') {
|
|
52
|
+
const value = attribute.value;
|
|
53
|
+
if (
|
|
54
|
+
value === true ||
|
|
55
|
+
!Array.isArray(value) ||
|
|
56
|
+
value.length !== 1 ||
|
|
57
|
+
value[0]?.type !== 'Text'
|
|
58
|
+
) {
|
|
59
|
+
fail('script_invalid_context', attribute);
|
|
60
|
+
}
|
|
61
|
+
if (value[0].data !== 'module') fail('script_invalid_context', attribute);
|
|
62
|
+
context = 'module';
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
type: 'Script',
|
|
68
|
+
start,
|
|
69
|
+
end: parser.index,
|
|
70
|
+
context,
|
|
71
|
+
content: ast as unknown as AST.Script['content'],
|
|
72
|
+
attributes
|
|
73
|
+
};
|
|
74
|
+
}
|