@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,319 @@
|
|
|
1
|
+
import type * as AST from '../ast.ts';
|
|
2
|
+
import { fail } from '../diagnostics.ts';
|
|
3
|
+
import { decode } from './decode.ts';
|
|
4
|
+
import { readExpression } from './expression.ts';
|
|
5
|
+
import { isWhitespace } from './html.ts';
|
|
6
|
+
import type { Identifier, Parser } from './parser.ts';
|
|
7
|
+
|
|
8
|
+
const unquotedEnd = /(\/>|[\s"'=<>`])/y;
|
|
9
|
+
const quote = /["']/y;
|
|
10
|
+
const staticValue = /(?:"([^"]*)"|'([^'])*'|([^>\s]+))/y;
|
|
11
|
+
|
|
12
|
+
export function isExpressionAttribute(
|
|
13
|
+
attribute: AST.Attribute
|
|
14
|
+
): attribute is AST.Attribute & { value: AST.ExpressionTag | [AST.ExpressionTag] } {
|
|
15
|
+
const value = attribute.value;
|
|
16
|
+
return (
|
|
17
|
+
value !== true &&
|
|
18
|
+
(!Array.isArray(value) || (value.length === 1 && value[0]?.type === 'ExpressionTag'))
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function attributeExpression(attribute: AST.Attribute): AST.Expression {
|
|
23
|
+
const value = attribute.value as AST.ExpressionTag | AST.ExpressionTag[];
|
|
24
|
+
return Array.isArray(value) ? (value[0] as AST.ExpressionTag).expression : value.expression;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function attribute(
|
|
28
|
+
name: string,
|
|
29
|
+
loc: AST.NameLocation | null,
|
|
30
|
+
start: number,
|
|
31
|
+
end: number,
|
|
32
|
+
value: AST.AttributeValue
|
|
33
|
+
): AST.Attribute {
|
|
34
|
+
return { type: 'Attribute', start, end, name, name_loc: loc, value };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function readStaticAttribute(parser: Parser): AST.Attribute | null {
|
|
38
|
+
const start = parser.index;
|
|
39
|
+
const tag = readTag(parser, true);
|
|
40
|
+
if (!tag.name) return null;
|
|
41
|
+
let value: AST.AttributeValue = true;
|
|
42
|
+
if (parser.eat('=')) {
|
|
43
|
+
parser.allowWhitespace();
|
|
44
|
+
let raw = parser.matchRegex(staticValue);
|
|
45
|
+
if (!raw) fail('expected_attribute_value', parser.index);
|
|
46
|
+
parser.index += raw.length;
|
|
47
|
+
const quoted = raw[0] === '"' || raw[0] === "'";
|
|
48
|
+
if (quoted) raw = raw.slice(1, -1);
|
|
49
|
+
value = [
|
|
50
|
+
{
|
|
51
|
+
start: parser.index - raw.length - (quoted ? 1 : 0),
|
|
52
|
+
end: quoted ? parser.index - 1 : parser.index,
|
|
53
|
+
type: 'Text',
|
|
54
|
+
raw,
|
|
55
|
+
data: decode(raw, true)
|
|
56
|
+
}
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
if (parser.matchRegex(quote)) fail('expected_token', parser.index, { token: '=' });
|
|
60
|
+
return attribute(tag.name, tag.loc, start, parser.index, value);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function readComment(parser: Parser): AST.JSComment | null {
|
|
64
|
+
const start = parser.index;
|
|
65
|
+
if (parser.eat('//')) {
|
|
66
|
+
const value = parser.readUntil('\n');
|
|
67
|
+
const end = parser.index;
|
|
68
|
+
return { type: 'Line', start, end, value, loc: location(parser, start, end) };
|
|
69
|
+
}
|
|
70
|
+
if (parser.eat('/*')) {
|
|
71
|
+
const value = parser.readUntil('*/');
|
|
72
|
+
parser.eat('*/');
|
|
73
|
+
const end = parser.index;
|
|
74
|
+
return { type: 'Block', start, end, value, loc: location(parser, start, end) };
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function location(parser: Parser, start: number, end: number): AST.NameLocation {
|
|
80
|
+
return { start: parser.locate(start), end: parser.locate(end) };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const directives: Readonly<Record<string, AST.DirectiveType>> = {
|
|
84
|
+
use: 'UseDirective',
|
|
85
|
+
animate: 'AnimateDirective',
|
|
86
|
+
bind: 'BindDirective',
|
|
87
|
+
class: 'ClassDirective',
|
|
88
|
+
on: 'OnDirective',
|
|
89
|
+
let: 'LetDirective',
|
|
90
|
+
in: 'TransitionDirective',
|
|
91
|
+
out: 'TransitionDirective',
|
|
92
|
+
transition: 'TransitionDirective'
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
function directiveType(prefix: string): AST.DirectiveType | 'StyleDirective' | null {
|
|
96
|
+
if (prefix === 'style') return 'StyleDirective';
|
|
97
|
+
return Object.hasOwn(directives, prefix) ? (directives[prefix] as AST.DirectiveType) : null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function readAttribute(parser: Parser): AST.AttributeLike | null {
|
|
101
|
+
for (let comment = readComment(parser); comment !== null; comment = readComment(parser)) {
|
|
102
|
+
parser.comments.push(comment);
|
|
103
|
+
parser.allowWhitespace();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const start = parser.index;
|
|
107
|
+
|
|
108
|
+
if (parser.eat('{')) {
|
|
109
|
+
parser.allowWhitespace();
|
|
110
|
+
if (parser.eat('@attach')) {
|
|
111
|
+
parser.requireWhitespace();
|
|
112
|
+
const expression = readExpression(parser);
|
|
113
|
+
parser.allowWhitespace();
|
|
114
|
+
parser.eat('}', true);
|
|
115
|
+
return { type: 'AttachTag', start, end: parser.index, expression };
|
|
116
|
+
}
|
|
117
|
+
if (parser.eat('...')) {
|
|
118
|
+
const expression = readExpression(parser);
|
|
119
|
+
parser.allowWhitespace();
|
|
120
|
+
parser.eat('}', true);
|
|
121
|
+
return { type: 'SpreadAttribute', start, end: parser.index, expression };
|
|
122
|
+
}
|
|
123
|
+
const id = parser.readIdentifier();
|
|
124
|
+
if (id.name === '') {
|
|
125
|
+
if (
|
|
126
|
+
parser.loose &&
|
|
127
|
+
(parser.match('#') || parser.match('/') || parser.match('@') || parser.match(':'))
|
|
128
|
+
) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
if (!(parser.loose && parser.match('}'))) fail('attribute_empty_shorthand', start);
|
|
132
|
+
}
|
|
133
|
+
parser.allowWhitespace();
|
|
134
|
+
parser.eat('}', true);
|
|
135
|
+
const expression: AST.ExpressionTag = {
|
|
136
|
+
type: 'ExpressionTag',
|
|
137
|
+
start: id.start,
|
|
138
|
+
end: id.end,
|
|
139
|
+
expression: id as AST.Expression
|
|
140
|
+
};
|
|
141
|
+
return attribute(id.name, id.loc, start, parser.index, expression);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const tag = readTag(parser, true);
|
|
145
|
+
if (!tag.name) return null;
|
|
146
|
+
|
|
147
|
+
let end = parser.index;
|
|
148
|
+
parser.allowWhitespace();
|
|
149
|
+
|
|
150
|
+
const colon = tag.name.indexOf(':');
|
|
151
|
+
const type = colon === -1 ? null : directiveType(tag.name.slice(0, colon));
|
|
152
|
+
|
|
153
|
+
let value: AST.AttributeValue = true;
|
|
154
|
+
if (parser.eat('=')) {
|
|
155
|
+
parser.allowWhitespace();
|
|
156
|
+
if (parser.template[parser.index] === '/' && parser.template[parser.index + 1] === '>') {
|
|
157
|
+
const at = parser.index++;
|
|
158
|
+
value = [{ start: at, end: at + 1, type: 'Text', raw: '/', data: '/' }];
|
|
159
|
+
} else {
|
|
160
|
+
value = readAttributeValue(parser);
|
|
161
|
+
}
|
|
162
|
+
end = parser.index;
|
|
163
|
+
} else if (parser.matchRegex(quote)) {
|
|
164
|
+
fail('expected_token', parser.index, { token: '=' });
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (type === null) return attribute(tag.name, tag.loc, start, end, value);
|
|
168
|
+
|
|
169
|
+
const [name = '', ...modifiers] = tag.name.slice(colon + 1).split('|');
|
|
170
|
+
if (name === '') {
|
|
171
|
+
fail('directive_missing_name', { start, end: start + colon + 1 }, { type: tag.name });
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (type === 'StyleDirective') {
|
|
175
|
+
return { start, end, type, name, name_loc: tag.loc, modifiers, value };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const first = value === true ? undefined : Array.isArray(value) ? value[0] : value;
|
|
179
|
+
let expression: AST.Expression | null = null;
|
|
180
|
+
if (first !== undefined) {
|
|
181
|
+
if ((value as unknown[]).length > 1 || first.type === 'Text') {
|
|
182
|
+
fail('directive_invalid_value', first.start);
|
|
183
|
+
}
|
|
184
|
+
expression = (first as AST.ExpressionTag).expression;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const directive: AST.Directive = {
|
|
188
|
+
start,
|
|
189
|
+
end,
|
|
190
|
+
type,
|
|
191
|
+
name,
|
|
192
|
+
name_loc: tag.loc,
|
|
193
|
+
expression,
|
|
194
|
+
modifiers
|
|
195
|
+
};
|
|
196
|
+
if (type === 'TransitionDirective') {
|
|
197
|
+
const direction = tag.name.slice(0, colon);
|
|
198
|
+
directive.intro = direction === 'in' || direction === 'transition';
|
|
199
|
+
directive.outro = direction === 'out' || direction === 'transition';
|
|
200
|
+
}
|
|
201
|
+
if ((type === 'BindDirective' || type === 'ClassDirective') && directive.expression === null) {
|
|
202
|
+
directive.expression = {
|
|
203
|
+
start: start + colon + 1,
|
|
204
|
+
end,
|
|
205
|
+
type: 'Identifier',
|
|
206
|
+
name: directive.name
|
|
207
|
+
} as AST.Expression;
|
|
208
|
+
}
|
|
209
|
+
return directive;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function readAttributeValue(parser: Parser): AST.ExpressionTag | (AST.Text | AST.ExpressionTag)[] {
|
|
213
|
+
const mark = parser.eat("'") ? "'" : parser.eat('"') ? '"' : null;
|
|
214
|
+
if (mark !== null && parser.eat(mark)) {
|
|
215
|
+
return [{ start: parser.index - 1, end: parser.index - 1, type: 'Text', raw: '', data: '' }];
|
|
216
|
+
}
|
|
217
|
+
let value: (AST.Text | AST.ExpressionTag)[];
|
|
218
|
+
try {
|
|
219
|
+
value = readSequence(
|
|
220
|
+
parser,
|
|
221
|
+
() => (mark !== null ? parser.match(mark) : parser.matchRegex(unquotedEnd) !== null),
|
|
222
|
+
'in attribute value'
|
|
223
|
+
);
|
|
224
|
+
} catch (error) {
|
|
225
|
+
const diagnostic = (error as { diagnostic?: { code: string; start: number } }).diagnostic;
|
|
226
|
+
if (diagnostic?.code === 'js_parse_error') {
|
|
227
|
+
const at = diagnostic.start;
|
|
228
|
+
if (parser.template.slice(at - 1, at + 1) === '/>') {
|
|
229
|
+
parser.index = at;
|
|
230
|
+
fail('expected_token', at, { token: mark ?? '}' });
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
throw error;
|
|
234
|
+
}
|
|
235
|
+
if (value.length === 0 && mark === null) fail('expected_attribute_value', parser.index);
|
|
236
|
+
if (mark !== null) parser.index += 1;
|
|
237
|
+
if (mark !== null || value.length > 1 || value[0]?.type === 'Text') return value;
|
|
238
|
+
return value[0] as AST.ExpressionTag;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export function readSequence(
|
|
242
|
+
parser: Parser,
|
|
243
|
+
done: () => boolean,
|
|
244
|
+
where: string
|
|
245
|
+
): (AST.Text | AST.ExpressionTag)[] {
|
|
246
|
+
const chunks: (AST.Text | AST.ExpressionTag)[] = [];
|
|
247
|
+
let chunkStart = parser.index;
|
|
248
|
+
const flush = (end: number): void => {
|
|
249
|
+
if (end > chunkStart) {
|
|
250
|
+
const raw = parser.template.slice(chunkStart, end);
|
|
251
|
+
chunks.push({ start: chunkStart, end, type: 'Text', raw, data: decode(raw, true) });
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
while (parser.index < parser.template.length) {
|
|
255
|
+
const index = parser.index;
|
|
256
|
+
if (done()) {
|
|
257
|
+
flush(parser.index);
|
|
258
|
+
return chunks;
|
|
259
|
+
}
|
|
260
|
+
if (parser.eat('{')) {
|
|
261
|
+
if (parser.match('#')) {
|
|
262
|
+
const at = parser.index - 1;
|
|
263
|
+
parser.eat('#');
|
|
264
|
+
fail('block_invalid_placement', at, { name: lowercaseName(parser), location: where });
|
|
265
|
+
} else if (parser.match('@')) {
|
|
266
|
+
const at = parser.index - 1;
|
|
267
|
+
parser.eat('@');
|
|
268
|
+
fail('tag_invalid_placement', at, { name: lowercaseName(parser), location: where });
|
|
269
|
+
}
|
|
270
|
+
flush(parser.index - 1);
|
|
271
|
+
parser.allowWhitespace();
|
|
272
|
+
const expression = readExpression(parser);
|
|
273
|
+
parser.allowWhitespace();
|
|
274
|
+
parser.eat('}', true);
|
|
275
|
+
chunks.push({ type: 'ExpressionTag', start: index, end: parser.index, expression });
|
|
276
|
+
chunkStart = parser.index;
|
|
277
|
+
} else {
|
|
278
|
+
parser.index++;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
if (parser.loose) return chunks;
|
|
282
|
+
fail('unexpected_eof', parser.template.length);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export function readTagName(parser: Parser, attribute = false): string {
|
|
286
|
+
const start = parser.index;
|
|
287
|
+
if (start >= parser.template.length && !parser.loose)
|
|
288
|
+
fail('unexpected_eof', parser.template.length);
|
|
289
|
+
while (parser.index < parser.template.length) {
|
|
290
|
+
const code = parser.template.charCodeAt(parser.index);
|
|
291
|
+
if (
|
|
292
|
+
isWhitespace(code) ||
|
|
293
|
+
code === 47 ||
|
|
294
|
+
code === 62 ||
|
|
295
|
+
(attribute && (code === 34 || code === 39 || code === 61))
|
|
296
|
+
) {
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
parser.index += 1;
|
|
300
|
+
}
|
|
301
|
+
return parser.template.slice(start, parser.index);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export function readTag(parser: Parser, attribute = false): Identifier {
|
|
305
|
+
const start = parser.index;
|
|
306
|
+
const name = readTagName(parser, attribute);
|
|
307
|
+
const end = parser.index;
|
|
308
|
+
return { type: 'Identifier', name, start, end, loc: location(parser, start, end) };
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function lowercaseName(parser: Parser): string {
|
|
312
|
+
const start = parser.index;
|
|
313
|
+
while (parser.index < parser.template.length) {
|
|
314
|
+
const code = parser.template.charCodeAt(parser.index);
|
|
315
|
+
if (code < 97 || code > 122) break;
|
|
316
|
+
parser.index += 1;
|
|
317
|
+
}
|
|
318
|
+
return parser.template.slice(start, parser.index);
|
|
319
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { fail } from '../diagnostics.ts';
|
|
2
|
+
|
|
3
|
+
const pairs: Readonly<Record<string, string>> = { '{': '}', '(': ')', '[': ']' };
|
|
4
|
+
|
|
5
|
+
function unescaped(text: string, from: number, char: string): number {
|
|
6
|
+
for (let index = text.indexOf(char, from); index !== -1; index = text.indexOf(char, index + 1)) {
|
|
7
|
+
let slashes = 0;
|
|
8
|
+
for (let back = index - 1; text[back] === '\\'; back--) slashes++;
|
|
9
|
+
if (slashes % 2 === 0) return index;
|
|
10
|
+
}
|
|
11
|
+
return Infinity;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function stringEnd(text: string, from: number, quote: string): number {
|
|
15
|
+
if (quote === '`') return unescaped(text, from, quote);
|
|
16
|
+
const line = text.indexOf('\n', from);
|
|
17
|
+
return unescaped(line === -1 ? text : text.slice(0, line), from, quote);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function regexEnd(text: string, from: number): number {
|
|
21
|
+
const slash = unescaped(text, from, '/');
|
|
22
|
+
return slash < unescaped(text, from, '\n') ? slash : Infinity;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function after(text: string, needle: string, from: number): number {
|
|
26
|
+
const found = text.indexOf(needle, from);
|
|
27
|
+
return (found === -1 ? Infinity : found) + needle.length;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function findMatchingBracket(text: string, from: number, open: string): number | undefined {
|
|
31
|
+
const close = pairs[open];
|
|
32
|
+
let depth = 1;
|
|
33
|
+
let index = from;
|
|
34
|
+
while (depth > 0 && index < text.length) {
|
|
35
|
+
const char = text[index];
|
|
36
|
+
if (char === "'" || char === '"' || char === '`') {
|
|
37
|
+
index = stringEnd(text, index + 1, char) + 1;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (char === '/') {
|
|
41
|
+
const next = text[index + 1];
|
|
42
|
+
if (next === undefined || next === '') index++;
|
|
43
|
+
else if (next === '/') index = after(text, '\n', index + 1);
|
|
44
|
+
else if (next === '*') index = after(text, '*/', index + 1);
|
|
45
|
+
else {
|
|
46
|
+
const end = regexEnd(text, index + 1) + 1;
|
|
47
|
+
index = end === Infinity ? index + 1 : end;
|
|
48
|
+
}
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (char === open) depth++;
|
|
52
|
+
else if (char === close) depth--;
|
|
53
|
+
if (depth === 0) return index;
|
|
54
|
+
index++;
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function matchBracket(
|
|
60
|
+
template: string,
|
|
61
|
+
start: number,
|
|
62
|
+
brackets: Readonly<Record<string, string>> = pairs
|
|
63
|
+
): number {
|
|
64
|
+
const closers = new Set(Object.values(brackets));
|
|
65
|
+
const stack: string[] = [];
|
|
66
|
+
let index = start;
|
|
67
|
+
while (index < template.length) {
|
|
68
|
+
const char = template[index++] as string;
|
|
69
|
+
if (char === "'" || char === '"' || char === '`') {
|
|
70
|
+
index = matchQuote(template, index, char);
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (char in brackets) {
|
|
74
|
+
stack.push(char);
|
|
75
|
+
} else if (closers.has(char)) {
|
|
76
|
+
const expected = brackets[stack.pop() as string] as string;
|
|
77
|
+
if (char !== expected) fail('expected_token', index - 1, { token: expected });
|
|
78
|
+
if (stack.length === 0) return index;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
fail('unexpected_eof', template.length);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function matchQuote(template: string, start: number, quote: string): number {
|
|
85
|
+
let escaped = false;
|
|
86
|
+
let index = start;
|
|
87
|
+
while (index < template.length) {
|
|
88
|
+
const char = template[index++];
|
|
89
|
+
if (escaped) {
|
|
90
|
+
escaped = false;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (char === quote) return index;
|
|
94
|
+
if (char === '\\') escaped = true;
|
|
95
|
+
if (quote === '`' && char === '$' && template[index] === '{')
|
|
96
|
+
index = matchBracket(template, index);
|
|
97
|
+
}
|
|
98
|
+
fail('unterminated_string_constant', start);
|
|
99
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const lineSeparators = String.fromCharCode(0x2028, 0x2029);
|
|
2
|
+
|
|
3
|
+
const bidirectionalControls = String.fromCharCode(
|
|
4
|
+
0x202a,
|
|
5
|
+
0x202b,
|
|
6
|
+
0x202c,
|
|
7
|
+
0x202d,
|
|
8
|
+
0x202e,
|
|
9
|
+
0x2066,
|
|
10
|
+
0x2067,
|
|
11
|
+
0x2068,
|
|
12
|
+
0x2069
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
export const nonLfLineBreak = new RegExp(`\\r(?!\\n)|[${lineSeparators}]`);
|
|
16
|
+
|
|
17
|
+
export const bidirectionalRun = new RegExp(`[${bidirectionalControls}]+`, 'g');
|
|
18
|
+
|
|
19
|
+
export const bidirectionalChar = new RegExp(`[${bidirectionalControls}]`);
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { entities } from './entities.ts';
|
|
2
|
+
|
|
3
|
+
const longest = Math.max(...Object.keys(entities).map((name) => name.length));
|
|
4
|
+
|
|
5
|
+
const windows1252 = [
|
|
6
|
+
8364, 129, 8218, 402, 8222, 8230, 8224, 8225, 710, 8240, 352, 8249, 338, 141, 381, 143, 144, 8216,
|
|
7
|
+
8217, 8220, 8221, 8226, 8211, 8212, 732, 8482, 353, 8250, 339, 157, 382, 376
|
|
8
|
+
];
|
|
9
|
+
|
|
10
|
+
function valid(code: number, attribute: boolean): number {
|
|
11
|
+
if (code === 10 && !attribute) return 32;
|
|
12
|
+
if (code < 128) return code;
|
|
13
|
+
if (code <= 159) return windows1252[code - 128] as number;
|
|
14
|
+
if (code < 55296) return code;
|
|
15
|
+
if (code <= 57343) return 0;
|
|
16
|
+
if (code <= 196607) return code;
|
|
17
|
+
if ((code >= 917504 && code <= 917631) || (code >= 917760 && code <= 917999)) return code;
|
|
18
|
+
return 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const word = /\w/;
|
|
22
|
+
|
|
23
|
+
function isHex(char: string | undefined): boolean {
|
|
24
|
+
return char !== undefined && /[0-9a-fA-F]/.test(char);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function isDigit(char: string | undefined): boolean {
|
|
28
|
+
return char !== undefined && char >= '0' && char <= '9';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface Reference {
|
|
32
|
+
readonly end: number;
|
|
33
|
+
readonly code: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function numeric(text: string, at: number): Reference | null {
|
|
37
|
+
let index = at + 1;
|
|
38
|
+
let code: number;
|
|
39
|
+
if ((text[index] === 'x' || text[index] === 'X') && isHex(text[index + 1])) {
|
|
40
|
+
const from = ++index;
|
|
41
|
+
while (isHex(text[index])) index++;
|
|
42
|
+
code = parseInt(text.slice(from, index), 16);
|
|
43
|
+
} else if (isDigit(text[index])) {
|
|
44
|
+
const from = index;
|
|
45
|
+
while (isDigit(text[index])) index++;
|
|
46
|
+
code = parseInt(text.slice(from, index), 10);
|
|
47
|
+
} else {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
if (text[index] === ';') index++;
|
|
51
|
+
return { end: index, code };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function named(text: string, at: number, attribute: boolean): Reference | null {
|
|
55
|
+
for (let length = Math.min(longest, text.length - at); length > 0; length--) {
|
|
56
|
+
const name = text.slice(at, at + length);
|
|
57
|
+
const code = entities[name];
|
|
58
|
+
if (code === undefined) continue;
|
|
59
|
+
if (attribute && !name.endsWith(';')) {
|
|
60
|
+
const next = text[at + length];
|
|
61
|
+
if (next !== undefined && (word.test(next) || next === '=')) continue;
|
|
62
|
+
}
|
|
63
|
+
return { end: at + length, code };
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function decode(text: string, attribute: boolean): string {
|
|
69
|
+
let index = text.indexOf('&');
|
|
70
|
+
if (index === -1) return text;
|
|
71
|
+
let out = '';
|
|
72
|
+
let copied = 0;
|
|
73
|
+
while (index !== -1) {
|
|
74
|
+
const at = index + 1;
|
|
75
|
+
const reference = text[at] === '#' ? numeric(text, at) : named(text, at, attribute);
|
|
76
|
+
if (reference === null) {
|
|
77
|
+
index = text.indexOf('&', at);
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (reference.code) {
|
|
81
|
+
out += text.slice(copied, index) + String.fromCodePoint(valid(reference.code, attribute));
|
|
82
|
+
copied = reference.end;
|
|
83
|
+
}
|
|
84
|
+
index = text.indexOf('&', reference.end);
|
|
85
|
+
}
|
|
86
|
+
return out + text.slice(copied);
|
|
87
|
+
}
|