@esportsplus/template 0.16.0 → 0.16.2
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/.editorconfig +9 -9
- package/.gitattributes +2 -2
- package/.github/dependabot.yml +24 -24
- package/.github/workflows/bump.yml +8 -8
- package/.github/workflows/dependabot.yml +11 -11
- package/.github/workflows/publish.yml +16 -16
- package/README.md +385 -385
- package/build/compiler/codegen.js +9 -9
- package/build/compiler/index.js +3 -3
- package/{src/llm.txt → llm.txt} +403 -403
- package/package.json +10 -3
- package/src/attributes.ts +312 -312
- package/src/compiler/codegen.ts +492 -492
- package/src/compiler/constants.ts +24 -24
- package/src/compiler/index.ts +87 -87
- package/src/compiler/parser.ts +242 -242
- package/src/compiler/plugins/tsc.ts +6 -6
- package/src/compiler/plugins/vite.ts +10 -10
- package/src/compiler/ts-analyzer.ts +89 -89
- package/src/compiler/ts-parser.ts +112 -112
- package/src/constants.ts +44 -44
- package/src/event/index.ts +130 -130
- package/src/event/onconnect.ts +22 -22
- package/src/event/onresize.ts +37 -37
- package/src/event/ontick.ts +59 -59
- package/src/html.ts +18 -18
- package/src/index.ts +18 -18
- package/src/render.ts +13 -13
- package/src/slot/array.ts +257 -257
- package/src/slot/cleanup.ts +37 -37
- package/src/slot/effect.ts +114 -114
- package/src/slot/index.ts +16 -16
- package/src/slot/render.ts +61 -61
- package/src/svg.ts +27 -27
- package/src/types.ts +40 -40
- package/src/utilities.ts +53 -53
- package/test/attributes.test.ts +311 -0
- package/test/compiler/parser.test.ts +402 -0
- package/test/compiler/ts-analyzer.test.ts +296 -0
- package/test/constants.test.ts +153 -0
- package/test/event/index.test.ts +359 -0
- package/test/html.test.ts +33 -0
- package/test/index.ts +648 -648
- package/test/render.test.ts +154 -0
- package/test/slot/array.test.ts +475 -0
- package/test/slot/cleanup.test.ts +243 -0
- package/test/slot/effect.test.ts +263 -0
- package/test/slot/index.test.ts +176 -0
- package/test/slot/render.test.ts +216 -0
- package/test/svg.test.ts +92 -0
- package/test/utilities.test.ts +242 -0
- package/tsconfig.json +8 -8
- package/vitest.config.ts +21 -0
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { uid } from '@esportsplus/typescript/compiler';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const ENTRYPOINT = 'html';
|
|
5
|
-
|
|
6
|
-
const ENTRYPOINT_REACTIVITY = 'reactive';
|
|
7
|
-
|
|
8
|
-
const NAMESPACE = uid('template');
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const enum TYPES {
|
|
12
|
-
ArraySlot = 'array-slot',
|
|
13
|
-
Attributes = 'attributes',
|
|
14
|
-
Attribute = 'attribute',
|
|
15
|
-
DocumentFragment = 'document-fragment',
|
|
16
|
-
Effect = 'effect',
|
|
17
|
-
Node = 'node',
|
|
18
|
-
Primitive = 'primitive',
|
|
19
|
-
Static = 'static',
|
|
20
|
-
Unknown = 'unknown'
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export { ENTRYPOINT, ENTRYPOINT_REACTIVITY, NAMESPACE, TYPES };
|
|
1
|
+
import { uid } from '@esportsplus/typescript/compiler';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const ENTRYPOINT = 'html';
|
|
5
|
+
|
|
6
|
+
const ENTRYPOINT_REACTIVITY = 'reactive';
|
|
7
|
+
|
|
8
|
+
const NAMESPACE = uid('template');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
const enum TYPES {
|
|
12
|
+
ArraySlot = 'array-slot',
|
|
13
|
+
Attributes = 'attributes',
|
|
14
|
+
Attribute = 'attribute',
|
|
15
|
+
DocumentFragment = 'document-fragment',
|
|
16
|
+
Effect = 'effect',
|
|
17
|
+
Node = 'node',
|
|
18
|
+
Primitive = 'primitive',
|
|
19
|
+
Static = 'static',
|
|
20
|
+
Unknown = 'unknown'
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
export { ENTRYPOINT, ENTRYPOINT_REACTIVITY, NAMESPACE, TYPES };
|
|
25
25
|
export { PACKAGE_NAME } from '~/constants';
|
package/src/compiler/index.ts
CHANGED
|
@@ -1,87 +1,87 @@
|
|
|
1
|
-
import { ts } from '@esportsplus/typescript';
|
|
2
|
-
import { ast } from '@esportsplus/typescript/compiler';
|
|
3
|
-
import type { ImportIntent, ReplacementIntent, TransformContext } from '@esportsplus/typescript/compiler';
|
|
4
|
-
import { ENTRYPOINT, ENTRYPOINT_REACTIVITY, NAMESPACE, PACKAGE_NAME } from './constants';
|
|
5
|
-
import { generateCode, printer, rewriteExpression } from './codegen';
|
|
6
|
-
import { findHtmlTemplates, findReactiveCalls } from './ts-parser';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export default {
|
|
10
|
-
patterns: [
|
|
11
|
-
`${ENTRYPOINT}\``,
|
|
12
|
-
`${ENTRYPOINT}.${ENTRYPOINT_REACTIVITY}`
|
|
13
|
-
],
|
|
14
|
-
transform: (ctx: TransformContext) => {
|
|
15
|
-
let callRanges: { end: number; start: number }[] = [],
|
|
16
|
-
callTemplates = new Map<string, string>(),
|
|
17
|
-
imports: ImportIntent[] = [],
|
|
18
|
-
prepend: string[] = [],
|
|
19
|
-
ranges: { end: number; start: number }[] = [],
|
|
20
|
-
remove: string[] = [],
|
|
21
|
-
replacements: ReplacementIntent[] = [],
|
|
22
|
-
templates = findHtmlTemplates(ctx.sourceFile, ctx.checker);
|
|
23
|
-
|
|
24
|
-
for (let i = 0, n = templates.length; i < n; i++) {
|
|
25
|
-
ranges.push({
|
|
26
|
-
end: templates[i].end,
|
|
27
|
-
start: templates[i].start
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
let calls = findReactiveCalls(ctx.sourceFile, ctx.checker);
|
|
32
|
-
|
|
33
|
-
for (let i = 0, n = calls.length; i < n; i++) {
|
|
34
|
-
let call = calls[i];
|
|
35
|
-
|
|
36
|
-
if (ast.inRange(ranges, call.start, call.end)) {
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Add callback range so nested templates inside it are excluded from separate processing
|
|
41
|
-
callRanges.push({
|
|
42
|
-
end: call.callbackArg.end,
|
|
43
|
-
start: call.callbackArg.getStart(ctx.sourceFile)
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
// Pre-compute the rewritten callback to capture templates
|
|
47
|
-
let rewrittenCallback = rewriteExpression({
|
|
48
|
-
checker: ctx.checker,
|
|
49
|
-
sourceFile: ctx.sourceFile,
|
|
50
|
-
templates: callTemplates
|
|
51
|
-
}, call.callbackArg);
|
|
52
|
-
|
|
53
|
-
replacements.push({
|
|
54
|
-
generate: (sourceFile) => `new ${NAMESPACE}.ArraySlot(
|
|
55
|
-
${printer.printNode(ts.EmitHint.Expression, call.arrayArg, sourceFile)},
|
|
56
|
-
${rewrittenCallback}
|
|
57
|
-
)`,
|
|
58
|
-
node: call.node
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Add template definitions from reactive call callbacks
|
|
63
|
-
for (let [html, id] of callTemplates) {
|
|
64
|
-
prepend.push(`const ${id} = ${NAMESPACE}.template(\`${html}\`);`);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (templates.length > 0) {
|
|
68
|
-
let result = generateCode(templates, ctx.sourceFile, ctx.checker, callRanges);
|
|
69
|
-
|
|
70
|
-
prepend.push(...result.prepend);
|
|
71
|
-
replacements.push(...result.replacements);
|
|
72
|
-
remove.push(ENTRYPOINT);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (replacements.length === 0 && prepend.length === 0) {
|
|
76
|
-
return {};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
imports.push({
|
|
80
|
-
namespace: NAMESPACE,
|
|
81
|
-
package: PACKAGE_NAME,
|
|
82
|
-
remove: remove
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
return { imports, prepend, replacements };
|
|
86
|
-
}
|
|
87
|
-
};
|
|
1
|
+
import { ts } from '@esportsplus/typescript';
|
|
2
|
+
import { ast } from '@esportsplus/typescript/compiler';
|
|
3
|
+
import type { ImportIntent, ReplacementIntent, TransformContext } from '@esportsplus/typescript/compiler';
|
|
4
|
+
import { ENTRYPOINT, ENTRYPOINT_REACTIVITY, NAMESPACE, PACKAGE_NAME } from './constants';
|
|
5
|
+
import { generateCode, printer, rewriteExpression } from './codegen';
|
|
6
|
+
import { findHtmlTemplates, findReactiveCalls } from './ts-parser';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export default {
|
|
10
|
+
patterns: [
|
|
11
|
+
`${ENTRYPOINT}\``,
|
|
12
|
+
`${ENTRYPOINT}.${ENTRYPOINT_REACTIVITY}`
|
|
13
|
+
],
|
|
14
|
+
transform: (ctx: TransformContext) => {
|
|
15
|
+
let callRanges: { end: number; start: number }[] = [],
|
|
16
|
+
callTemplates = new Map<string, string>(),
|
|
17
|
+
imports: ImportIntent[] = [],
|
|
18
|
+
prepend: string[] = [],
|
|
19
|
+
ranges: { end: number; start: number }[] = [],
|
|
20
|
+
remove: string[] = [],
|
|
21
|
+
replacements: ReplacementIntent[] = [],
|
|
22
|
+
templates = findHtmlTemplates(ctx.sourceFile, ctx.checker);
|
|
23
|
+
|
|
24
|
+
for (let i = 0, n = templates.length; i < n; i++) {
|
|
25
|
+
ranges.push({
|
|
26
|
+
end: templates[i].end,
|
|
27
|
+
start: templates[i].start
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let calls = findReactiveCalls(ctx.sourceFile, ctx.checker);
|
|
32
|
+
|
|
33
|
+
for (let i = 0, n = calls.length; i < n; i++) {
|
|
34
|
+
let call = calls[i];
|
|
35
|
+
|
|
36
|
+
if (ast.inRange(ranges, call.start, call.end)) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Add callback range so nested templates inside it are excluded from separate processing
|
|
41
|
+
callRanges.push({
|
|
42
|
+
end: call.callbackArg.end,
|
|
43
|
+
start: call.callbackArg.getStart(ctx.sourceFile)
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Pre-compute the rewritten callback to capture templates
|
|
47
|
+
let rewrittenCallback = rewriteExpression({
|
|
48
|
+
checker: ctx.checker,
|
|
49
|
+
sourceFile: ctx.sourceFile,
|
|
50
|
+
templates: callTemplates
|
|
51
|
+
}, call.callbackArg);
|
|
52
|
+
|
|
53
|
+
replacements.push({
|
|
54
|
+
generate: (sourceFile) => `new ${NAMESPACE}.ArraySlot(
|
|
55
|
+
${printer.printNode(ts.EmitHint.Expression, call.arrayArg, sourceFile)},
|
|
56
|
+
${rewrittenCallback}
|
|
57
|
+
)`,
|
|
58
|
+
node: call.node
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Add template definitions from reactive call callbacks
|
|
63
|
+
for (let [html, id] of callTemplates) {
|
|
64
|
+
prepend.push(`const ${id} = ${NAMESPACE}.template(\`${html}\`);`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (templates.length > 0) {
|
|
68
|
+
let result = generateCode(templates, ctx.sourceFile, ctx.checker, callRanges);
|
|
69
|
+
|
|
70
|
+
prepend.push(...result.prepend);
|
|
71
|
+
replacements.push(...result.replacements);
|
|
72
|
+
remove.push(ENTRYPOINT);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (replacements.length === 0 && prepend.length === 0) {
|
|
76
|
+
return {};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
imports.push({
|
|
80
|
+
namespace: NAMESPACE,
|
|
81
|
+
package: PACKAGE_NAME,
|
|
82
|
+
remove: remove
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
return { imports, prepend, replacements };
|
|
86
|
+
}
|
|
87
|
+
};
|