@esportsplus/template 0.31.7 → 0.32.1
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/build/attributes.js +1 -2
- package/build/constants.d.ts +18 -3
- package/build/constants.js +31 -4
- package/build/html.d.ts +3 -3
- package/build/slot/array.d.ts +2 -2
- package/build/slot/array.js +5 -4
- package/build/slot/render.js +3 -2
- package/build/transformer/codegen.d.ts +2 -9
- package/build/transformer/codegen.js +87 -101
- package/build/transformer/index.d.ts +2 -3
- package/build/transformer/index.js +34 -32
- package/build/transformer/parser.d.ts +3 -2
- package/build/transformer/parser.js +4 -4
- package/build/transformer/plugins/tsc.js +8 -2
- package/build/transformer/plugins/vite.js +9 -14
- package/build/transformer/ts-parser.d.ts +1 -2
- package/build/transformer/ts-parser.js +25 -34
- package/build/transformer/type-analyzer.d.ts +4 -5
- package/build/transformer/type-analyzer.js +61 -71
- package/build/types.d.ts +1 -1
- package/package.json +7 -7
- package/src/attributes.ts +1 -4
- package/src/constants.ts +42 -6
- package/src/html.ts +3 -3
- package/src/slot/array.ts +9 -6
- package/src/slot/render.ts +5 -2
- package/src/transformer/codegen.ts +113 -124
- package/src/transformer/index.ts +44 -49
- package/src/transformer/parser.ts +10 -7
- package/src/transformer/plugins/tsc.ts +10 -2
- package/src/transformer/plugins/vite.ts +12 -25
- package/src/transformer/ts-parser.ts +31 -44
- package/src/transformer/type-analyzer.ts +75 -93
- package/src/types.ts +1 -1
- package/test/vite.config.ts +1 -1
- package/build/event/constants.d.ts +0 -3
- package/build/event/constants.js +0 -13
- package/src/event/constants.ts +0 -16
- package/storage/rewrite-analysis-2026-01-04.md +0 -439
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
import { createTransformer } from '../index';
|
|
2
1
|
import { ts } from '@esportsplus/typescript';
|
|
2
|
+
import { transformCode } from '~/transformer';
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
export default (program: ts.Program): ts.TransformerFactory<ts.SourceFile> => {
|
|
6
|
-
|
|
6
|
+
let typeChecker = program.getTypeChecker();
|
|
7
|
+
|
|
8
|
+
return () => {
|
|
9
|
+
return (sourceFile: ts.SourceFile): ts.SourceFile => {
|
|
10
|
+
let result = transformCode(sourceFile.getFullText(), sourceFile, typeChecker);
|
|
11
|
+
|
|
12
|
+
return result.changed ? result.sourceFile : sourceFile;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
7
15
|
};
|
|
@@ -1,54 +1,41 @@
|
|
|
1
|
-
import { createTransformer, mightNeedTransform, PATTERNS } from '../index';
|
|
2
|
-
import { program, TRANSFORM_PATTERN } from '@esportsplus/typescript/transformer';
|
|
3
1
|
import type { Plugin, ResolvedConfig } from 'vite';
|
|
4
2
|
import { ts } from '@esportsplus/typescript';
|
|
3
|
+
import { program, TRANSFORM_PATTERN } from '@esportsplus/typescript/transformer';
|
|
4
|
+
import { PACKAGE } from '~/constants';
|
|
5
|
+
import { transform } from '~/transformer';
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
export default (options?: { root?: string }): Plugin => {
|
|
8
9
|
let root: string;
|
|
9
10
|
|
|
10
11
|
return {
|
|
11
|
-
enforce: 'pre',
|
|
12
|
-
name: '@esportsplus/template/plugin-vite',
|
|
13
|
-
|
|
14
12
|
configResolved(config: ResolvedConfig) {
|
|
15
13
|
root = options?.root ?? config.root;
|
|
16
14
|
},
|
|
17
|
-
|
|
15
|
+
enforce: 'pre',
|
|
16
|
+
name: `${PACKAGE}/plugin-vite`,
|
|
18
17
|
transform(code: string, id: string) {
|
|
19
18
|
if (!TRANSFORM_PATTERN.test(id) || id.includes('node_modules')) {
|
|
20
19
|
return null;
|
|
21
20
|
}
|
|
22
21
|
|
|
23
|
-
if (!mightNeedTransform(code, { patterns: PATTERNS })) {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
22
|
try {
|
|
28
|
-
let
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
result = ts.transform(sourceFile, [transformer]),
|
|
33
|
-
transformed = result.transformed[0];
|
|
23
|
+
let result = transform(
|
|
24
|
+
ts.createSourceFile(id, code, ts.ScriptTarget.Latest, true),
|
|
25
|
+
program.get(root)
|
|
26
|
+
);
|
|
34
27
|
|
|
35
|
-
if (
|
|
36
|
-
result.dispose();
|
|
28
|
+
if (!result.changed) {
|
|
37
29
|
return null;
|
|
38
30
|
}
|
|
39
31
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
result.dispose();
|
|
43
|
-
|
|
44
|
-
return { code: output, map: null };
|
|
32
|
+
return { code: result.code, map: null };
|
|
45
33
|
}
|
|
46
34
|
catch (error) {
|
|
47
|
-
console.error(
|
|
35
|
+
console.error(`${PACKAGE}: Error transforming ${id}:`, error);
|
|
48
36
|
return null;
|
|
49
37
|
}
|
|
50
38
|
},
|
|
51
|
-
|
|
52
39
|
watchChange(id: string) {
|
|
53
40
|
if (TRANSFORM_PATTERN.test(id)) {
|
|
54
41
|
program.delete(root);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { COMPILER_ENTRYPOINT, COMPILER_ENTRYPOINT_REACTIVITY } from '../constants';
|
|
1
2
|
import { ts } from '@esportsplus/typescript';
|
|
2
3
|
|
|
3
4
|
|
|
@@ -19,35 +20,6 @@ type TemplateInfo = {
|
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
|
|
22
|
-
function extractTemplateInfo(node: ts.TaggedTemplateExpression, depth: number): TemplateInfo {
|
|
23
|
-
let expressions: ts.Expression[] = [],
|
|
24
|
-
literals: string[] = [],
|
|
25
|
-
template = node.template;
|
|
26
|
-
|
|
27
|
-
if (ts.isNoSubstitutionTemplateLiteral(template)) {
|
|
28
|
-
literals.push(template.text);
|
|
29
|
-
}
|
|
30
|
-
else if (ts.isTemplateExpression(template)) {
|
|
31
|
-
literals.push(template.head.text);
|
|
32
|
-
|
|
33
|
-
for (let i = 0, n = template.templateSpans.length; i < n; i++) {
|
|
34
|
-
let span = template.templateSpans[i];
|
|
35
|
-
|
|
36
|
-
expressions.push(span.expression);
|
|
37
|
-
literals.push(span.literal.text);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
depth,
|
|
43
|
-
end: node.end,
|
|
44
|
-
expressions,
|
|
45
|
-
literals,
|
|
46
|
-
node,
|
|
47
|
-
start: node.getStart()
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
23
|
function isFunctionNode(node: ts.Node): boolean {
|
|
52
24
|
return (
|
|
53
25
|
ts.isArrowFunction(node) ||
|
|
@@ -62,8 +34,8 @@ function visitReactiveCalls(node: ts.Node, calls: ReactiveCallInfo[]): void {
|
|
|
62
34
|
ts.isCallExpression(node) &&
|
|
63
35
|
ts.isPropertyAccessExpression(node.expression) &&
|
|
64
36
|
ts.isIdentifier(node.expression.expression) &&
|
|
65
|
-
node.expression.expression.text ===
|
|
66
|
-
node.expression.name.text ===
|
|
37
|
+
node.expression.expression.text === COMPILER_ENTRYPOINT &&
|
|
38
|
+
node.expression.name.text === COMPILER_ENTRYPOINT_REACTIVITY &&
|
|
67
39
|
node.arguments.length === 2
|
|
68
40
|
) {
|
|
69
41
|
calls.push({
|
|
@@ -81,8 +53,33 @@ function visitReactiveCalls(node: ts.Node, calls: ReactiveCallInfo[]): void {
|
|
|
81
53
|
function visitTemplates(node: ts.Node, depth: number, templates: TemplateInfo[]): void {
|
|
82
54
|
let nextDepth = isFunctionNode(node) ? depth + 1 : depth;
|
|
83
55
|
|
|
84
|
-
if (ts.isTaggedTemplateExpression(node) && ts.isIdentifier(node.tag) && node.tag.text ===
|
|
85
|
-
|
|
56
|
+
if (ts.isTaggedTemplateExpression(node) && ts.isIdentifier(node.tag) && node.tag.text === COMPILER_ENTRYPOINT) {
|
|
57
|
+
let expressions: ts.Expression[] = [],
|
|
58
|
+
literals: string[] = [],
|
|
59
|
+
template = node.template;
|
|
60
|
+
|
|
61
|
+
if (ts.isNoSubstitutionTemplateLiteral(template)) {
|
|
62
|
+
literals.push(template.text);
|
|
63
|
+
}
|
|
64
|
+
else if (ts.isTemplateExpression(template)) {
|
|
65
|
+
literals.push(template.head.text);
|
|
66
|
+
|
|
67
|
+
for (let i = 0, n = template.templateSpans.length; i < n; i++) {
|
|
68
|
+
let span = template.templateSpans[i];
|
|
69
|
+
|
|
70
|
+
expressions.push(span.expression);
|
|
71
|
+
literals.push(span.literal.text);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
templates.push({
|
|
76
|
+
depth,
|
|
77
|
+
end: node.end,
|
|
78
|
+
expressions,
|
|
79
|
+
literals,
|
|
80
|
+
node,
|
|
81
|
+
start: node.getStart()
|
|
82
|
+
});
|
|
86
83
|
}
|
|
87
84
|
|
|
88
85
|
ts.forEachChild(node, child => visitTemplates(child, nextDepth, templates));
|
|
@@ -108,16 +105,6 @@ const findReactiveCalls = (sourceFile: ts.SourceFile): ReactiveCallInfo[] => {
|
|
|
108
105
|
return calls;
|
|
109
106
|
};
|
|
110
107
|
|
|
111
|
-
const getTemplateExpressions = (info: TemplateInfo, sourceFile: ts.SourceFile): string[] => {
|
|
112
|
-
let exprs: string[] = [];
|
|
113
|
-
|
|
114
|
-
for (let i = 0, n = info.expressions.length; i < n; i++) {
|
|
115
|
-
exprs.push(info.expressions[i].getText(sourceFile));
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return exprs;
|
|
119
|
-
};
|
|
120
|
-
|
|
121
108
|
|
|
122
|
-
export { findHtmlTemplates, findReactiveCalls
|
|
109
|
+
export { findHtmlTemplates, findReactiveCalls };
|
|
123
110
|
export type { ReactiveCallInfo, TemplateInfo };
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
COMPILER_ENTRYPOINT,
|
|
3
|
+
COMPILER_ENTRYPOINT_REACTIVITY,
|
|
4
|
+
COMPILER_TYPES,
|
|
5
|
+
DIRECT_ATTACH_EVENTS,
|
|
6
|
+
LIFECYCLE_EVENTS
|
|
7
|
+
} from '../constants';
|
|
3
8
|
import { ts } from '@esportsplus/typescript';
|
|
4
9
|
|
|
5
10
|
|
|
@@ -7,15 +12,6 @@ type AnalyzerContext = {
|
|
|
7
12
|
checker?: ts.TypeChecker;
|
|
8
13
|
};
|
|
9
14
|
|
|
10
|
-
type SlotType =
|
|
11
|
-
| 'array-slot'
|
|
12
|
-
| 'document-fragment'
|
|
13
|
-
| 'effect'
|
|
14
|
-
| 'node'
|
|
15
|
-
| 'primitive'
|
|
16
|
-
| 'static'
|
|
17
|
-
| 'unknown';
|
|
18
|
-
|
|
19
15
|
type SpreadAnalysis = {
|
|
20
16
|
canUnpack: boolean;
|
|
21
17
|
keys: string[];
|
|
@@ -81,87 +77,62 @@ function extractTypePropertyKeys(type: ts.Type): string[] {
|
|
|
81
77
|
return keys;
|
|
82
78
|
}
|
|
83
79
|
|
|
84
|
-
function
|
|
85
|
-
for (let i = 0, n = expr.properties.length; i < n; i++) {
|
|
86
|
-
let prop = expr.properties[i];
|
|
87
|
-
|
|
88
|
-
if (ts.isPropertyAssignment(prop)) {
|
|
89
|
-
let name = ts.isIdentifier(prop.name)
|
|
90
|
-
? prop.name.text
|
|
91
|
-
: ts.isStringLiteral(prop.name) ? prop.name.text : null;
|
|
92
|
-
|
|
93
|
-
if (name === key) {
|
|
94
|
-
return prop.initializer.getText(sourceFile);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
else if (ts.isShorthandPropertyAssignment(prop) && prop.name.text === key) {
|
|
98
|
-
return prop.name.text;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function inferSlotType(expr: ts.Expression, ctx?: AnalyzerContext): SlotType {
|
|
80
|
+
function inferCOMPILER_TYPES(expr: ts.Expression, ctx?: AnalyzerContext): COMPILER_TYPES {
|
|
106
81
|
while (ts.isParenthesizedExpression(expr)) {
|
|
107
82
|
expr = expr.expression;
|
|
108
83
|
}
|
|
109
84
|
|
|
110
85
|
if (ts.isArrowFunction(expr) || ts.isFunctionExpression(expr)) {
|
|
111
|
-
return
|
|
86
|
+
return COMPILER_TYPES.Effect;
|
|
112
87
|
}
|
|
113
88
|
|
|
114
89
|
if (
|
|
115
90
|
ts.isCallExpression(expr) &&
|
|
116
91
|
ts.isPropertyAccessExpression(expr.expression) &&
|
|
117
92
|
ts.isIdentifier(expr.expression.expression) &&
|
|
118
|
-
expr.expression.expression.text ===
|
|
119
|
-
expr.expression.name.text ===
|
|
93
|
+
expr.expression.expression.text === COMPILER_ENTRYPOINT &&
|
|
94
|
+
expr.expression.name.text === COMPILER_ENTRYPOINT_REACTIVITY
|
|
120
95
|
) {
|
|
121
|
-
return
|
|
96
|
+
return COMPILER_TYPES.ArraySlot;
|
|
122
97
|
}
|
|
123
98
|
|
|
124
|
-
if (ts.isTaggedTemplateExpression(expr) && ts.isIdentifier(expr.tag) && expr.tag.text ===
|
|
125
|
-
return
|
|
99
|
+
if (ts.isTaggedTemplateExpression(expr) && ts.isIdentifier(expr.tag) && expr.tag.text === COMPILER_ENTRYPOINT) {
|
|
100
|
+
return COMPILER_TYPES.DocumentFragment;
|
|
126
101
|
}
|
|
127
102
|
|
|
128
103
|
if (ts.isArrayLiteralExpression(expr)) {
|
|
129
|
-
return
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (ts.isStringLiteral(expr) || ts.isNoSubstitutionTemplateLiteral(expr)) {
|
|
133
|
-
return 'static';
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (ts.isNumericLiteral(expr)) {
|
|
137
|
-
return 'static';
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (expr.kind === ts.SyntaxKind.TrueKeyword || expr.kind === ts.SyntaxKind.FalseKeyword) {
|
|
141
|
-
return 'static';
|
|
104
|
+
return COMPILER_TYPES.ArraySlot;
|
|
142
105
|
}
|
|
143
106
|
|
|
144
|
-
if (
|
|
145
|
-
|
|
107
|
+
if (
|
|
108
|
+
ts.isNumericLiteral(expr) ||
|
|
109
|
+
ts.isStringLiteral(expr) ||
|
|
110
|
+
ts.isNoSubstitutionTemplateLiteral(expr) ||
|
|
111
|
+
expr.kind === ts.SyntaxKind.TrueKeyword ||
|
|
112
|
+
expr.kind === ts.SyntaxKind.FalseKeyword ||
|
|
113
|
+
expr.kind === ts.SyntaxKind.NullKeyword ||
|
|
114
|
+
expr.kind === ts.SyntaxKind.UndefinedKeyword
|
|
115
|
+
) {
|
|
116
|
+
return COMPILER_TYPES.Static;
|
|
146
117
|
}
|
|
147
118
|
|
|
148
119
|
if (ts.isTemplateExpression(expr)) {
|
|
149
|
-
return
|
|
120
|
+
return COMPILER_TYPES.Primitive;
|
|
150
121
|
}
|
|
151
122
|
|
|
152
123
|
if (ts.isConditionalExpression(expr)) {
|
|
153
|
-
let whenFalse =
|
|
154
|
-
whenTrue =
|
|
124
|
+
let whenFalse = inferCOMPILER_TYPES(expr.whenFalse, ctx),
|
|
125
|
+
whenTrue = inferCOMPILER_TYPES(expr.whenTrue, ctx);
|
|
155
126
|
|
|
156
127
|
if (whenTrue === whenFalse) {
|
|
157
128
|
return whenTrue;
|
|
158
129
|
}
|
|
159
130
|
|
|
160
|
-
if (whenTrue ===
|
|
161
|
-
return
|
|
131
|
+
if (whenTrue === COMPILER_TYPES.Effect || whenFalse === COMPILER_TYPES.Effect) {
|
|
132
|
+
return COMPILER_TYPES.Effect;
|
|
162
133
|
}
|
|
163
134
|
|
|
164
|
-
return
|
|
135
|
+
return COMPILER_TYPES.Unknown;
|
|
165
136
|
}
|
|
166
137
|
|
|
167
138
|
if (ctx?.checker) {
|
|
@@ -172,11 +143,11 @@ function inferSlotType(expr: ts.Expression, ctx?: AnalyzerContext): SlotType {
|
|
|
172
143
|
let type = checker.getTypeAtLocation(expr);
|
|
173
144
|
|
|
174
145
|
if (isTypeFunction(type, checker)) {
|
|
175
|
-
return
|
|
146
|
+
return COMPILER_TYPES.Effect;
|
|
176
147
|
}
|
|
177
148
|
|
|
178
149
|
if (isTypeArray(type, checker)) {
|
|
179
|
-
return
|
|
150
|
+
return COMPILER_TYPES.ArraySlot;
|
|
180
151
|
}
|
|
181
152
|
}
|
|
182
153
|
catch {
|
|
@@ -188,11 +159,11 @@ function inferSlotType(expr: ts.Expression, ctx?: AnalyzerContext): SlotType {
|
|
|
188
159
|
let type = checker.getTypeAtLocation(expr);
|
|
189
160
|
|
|
190
161
|
if (isTypeFunction(type, checker)) {
|
|
191
|
-
return
|
|
162
|
+
return COMPILER_TYPES.Effect;
|
|
192
163
|
}
|
|
193
164
|
|
|
194
165
|
if (isTypeArray(type, checker)) {
|
|
195
|
-
return
|
|
166
|
+
return COMPILER_TYPES.ArraySlot;
|
|
196
167
|
}
|
|
197
168
|
}
|
|
198
169
|
catch {
|
|
@@ -204,11 +175,11 @@ function inferSlotType(expr: ts.Expression, ctx?: AnalyzerContext): SlotType {
|
|
|
204
175
|
let type = checker.getTypeAtLocation(expr);
|
|
205
176
|
|
|
206
177
|
if (isTypeFunction(type, checker)) {
|
|
207
|
-
return
|
|
178
|
+
return COMPILER_TYPES.Effect;
|
|
208
179
|
}
|
|
209
180
|
|
|
210
181
|
if (isTypeArray(type, checker)) {
|
|
211
|
-
return
|
|
182
|
+
return COMPILER_TYPES.ArraySlot;
|
|
212
183
|
}
|
|
213
184
|
}
|
|
214
185
|
catch {
|
|
@@ -216,23 +187,17 @@ function inferSlotType(expr: ts.Expression, ctx?: AnalyzerContext): SlotType {
|
|
|
216
187
|
}
|
|
217
188
|
}
|
|
218
189
|
|
|
219
|
-
return
|
|
190
|
+
return COMPILER_TYPES.Unknown;
|
|
220
191
|
}
|
|
221
192
|
|
|
222
193
|
function isTypeArray(type: ts.Type, checker: ts.TypeChecker): boolean {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
if (typeStr.endsWith('[]') || typeStr.startsWith('Array<') || typeStr.startsWith('ReactiveArray<')) {
|
|
194
|
+
if (checker.isArrayType(type)) {
|
|
226
195
|
return true;
|
|
227
196
|
}
|
|
228
197
|
|
|
229
198
|
let symbol = type.getSymbol();
|
|
230
199
|
|
|
231
|
-
|
|
232
|
-
return true;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
return false;
|
|
200
|
+
return symbol?.getName() === 'ReactiveArray';
|
|
236
201
|
}
|
|
237
202
|
|
|
238
203
|
function isTypeFunction(type: ts.Type, checker: ts.TypeChecker): boolean {
|
|
@@ -252,41 +217,39 @@ function isTypeFunction(type: ts.Type, checker: ts.TypeChecker): boolean {
|
|
|
252
217
|
}
|
|
253
218
|
|
|
254
219
|
|
|
255
|
-
const analyzeExpression = (expr: ts.Expression, checker?: ts.TypeChecker):
|
|
256
|
-
return
|
|
220
|
+
const analyzeExpression = (expr: ts.Expression, checker?: ts.TypeChecker): COMPILER_TYPES => {
|
|
221
|
+
return inferCOMPILER_TYPES(expr, checker ? { checker } : undefined);
|
|
257
222
|
};
|
|
258
223
|
|
|
259
|
-
const generateAttributeBinding = (elementVar: string, name: string, expr: string, staticValue: string): string => {
|
|
260
|
-
let n = getNames();
|
|
261
|
-
|
|
224
|
+
const generateAttributeBinding = (elementVar: string, name: string, expr: string, staticValue: string, ns: string): string => {
|
|
262
225
|
if (name.startsWith('on') && name.length > 2) {
|
|
263
226
|
let event = name.slice(2).toLowerCase(),
|
|
264
227
|
key = name.toLowerCase();
|
|
265
228
|
|
|
266
229
|
if (LIFECYCLE_EVENTS.has(key)) {
|
|
267
|
-
return `${
|
|
230
|
+
return `${ns}.event.${key}(${elementVar}, ${expr});`;
|
|
268
231
|
}
|
|
269
232
|
|
|
270
233
|
if (DIRECT_ATTACH_EVENTS.has(key)) {
|
|
271
|
-
return `${
|
|
234
|
+
return `${ns}.event.direct(${elementVar}, '${event}', ${expr});`;
|
|
272
235
|
}
|
|
273
236
|
|
|
274
|
-
return `${
|
|
237
|
+
return `${ns}.event.delegate(${elementVar}, '${event}', ${expr});`;
|
|
275
238
|
}
|
|
276
239
|
|
|
277
240
|
if (name === 'class') {
|
|
278
|
-
return `${
|
|
241
|
+
return `${ns}.attributes.setClass(${elementVar}, '${staticValue}', ${expr});`;
|
|
279
242
|
}
|
|
280
243
|
|
|
281
244
|
if (name === 'spread') {
|
|
282
|
-
return `${
|
|
245
|
+
return `${ns}.attributes.spread(${elementVar}, ${expr});`;
|
|
283
246
|
}
|
|
284
247
|
|
|
285
248
|
if (name === 'style') {
|
|
286
|
-
return `${
|
|
249
|
+
return `${ns}.attributes.setStyle(${elementVar}, '${staticValue}', ${expr});`;
|
|
287
250
|
}
|
|
288
251
|
|
|
289
|
-
return `${
|
|
252
|
+
return `${ns}.attributes.setProperty(${elementVar}, '${name}', ${expr});`;
|
|
290
253
|
};
|
|
291
254
|
|
|
292
255
|
const generateSpreadBindings = (
|
|
@@ -294,7 +257,8 @@ const generateSpreadBindings = (
|
|
|
294
257
|
exprCode: string,
|
|
295
258
|
elementVar: string,
|
|
296
259
|
sourceFile: ts.SourceFile,
|
|
297
|
-
checker
|
|
260
|
+
checker: ts.TypeChecker | undefined,
|
|
261
|
+
ns: string
|
|
298
262
|
): string[] => {
|
|
299
263
|
while (ts.isParenthesizedExpression(expr)) {
|
|
300
264
|
expr = expr.expression;
|
|
@@ -303,7 +267,7 @@ const generateSpreadBindings = (
|
|
|
303
267
|
let analysis = analyzeSpread(expr, checker);
|
|
304
268
|
|
|
305
269
|
if (!analysis.canUnpack) {
|
|
306
|
-
return [`${
|
|
270
|
+
return [`${ns}.attributes.spread(${elementVar}, ${exprCode});`];
|
|
307
271
|
}
|
|
308
272
|
|
|
309
273
|
let lines: string[] = [];
|
|
@@ -311,10 +275,29 @@ const generateSpreadBindings = (
|
|
|
311
275
|
if (ts.isObjectLiteralExpression(expr)) {
|
|
312
276
|
for (let i = 0, n = analysis.keys.length; i < n; i++) {
|
|
313
277
|
let key = analysis.keys[i],
|
|
314
|
-
value
|
|
278
|
+
value: string | null = null;
|
|
279
|
+
|
|
280
|
+
for (let j = 0, m = expr.properties.length; j < m; j++) {
|
|
281
|
+
let prop = expr.properties[j];
|
|
282
|
+
|
|
283
|
+
if (ts.isPropertyAssignment(prop)) {
|
|
284
|
+
let name = ts.isIdentifier(prop.name)
|
|
285
|
+
? prop.name.text
|
|
286
|
+
: ts.isStringLiteral(prop.name) ? prop.name.text : null;
|
|
287
|
+
|
|
288
|
+
if (name === key) {
|
|
289
|
+
value = prop.initializer.getText(sourceFile);
|
|
290
|
+
break;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
else if (ts.isShorthandPropertyAssignment(prop) && prop.name.text === key) {
|
|
294
|
+
value = prop.name.text;
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
315
298
|
|
|
316
299
|
if (value !== null) {
|
|
317
|
-
lines.push(generateAttributeBinding(elementVar, key, value, ''));
|
|
300
|
+
lines.push(generateAttributeBinding(elementVar, key, value, '', ns));
|
|
318
301
|
}
|
|
319
302
|
}
|
|
320
303
|
}
|
|
@@ -322,7 +305,7 @@ const generateSpreadBindings = (
|
|
|
322
305
|
for (let i = 0, n = analysis.keys.length; i < n; i++) {
|
|
323
306
|
let key = analysis.keys[i];
|
|
324
307
|
|
|
325
|
-
lines.push(generateAttributeBinding(elementVar, key, `${exprCode}.${key}`, ''));
|
|
308
|
+
lines.push(generateAttributeBinding(elementVar, key, `${exprCode}.${key}`, '', ns));
|
|
326
309
|
}
|
|
327
310
|
}
|
|
328
311
|
|
|
@@ -331,4 +314,3 @@ const generateSpreadBindings = (
|
|
|
331
314
|
|
|
332
315
|
|
|
333
316
|
export { analyzeExpression, generateAttributeBinding, generateSpreadBindings };
|
|
334
|
-
export type { SlotType };
|
package/src/types.ts
CHANGED
|
@@ -26,7 +26,7 @@ type Element = HTMLElement & Attributes<any>;
|
|
|
26
26
|
// - Importing from ^ causes 'cannot be named without a reference to...' error
|
|
27
27
|
type Primitive = bigint | boolean | null | number | string | undefined;
|
|
28
28
|
|
|
29
|
-
type Renderable<T> =
|
|
29
|
+
type Renderable<T> = ArraySlot<T> | DocumentFragment | Effect<T> | Node | NodeList | Primitive | Renderable<T>[];
|
|
30
30
|
|
|
31
31
|
type SlotGroup = {
|
|
32
32
|
head: Element;
|
package/test/vite.config.ts
CHANGED
package/build/event/constants.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
const DIRECT_ATTACH_EVENTS = new Set([
|
|
2
|
-
'onblur',
|
|
3
|
-
'onerror',
|
|
4
|
-
'onfocus', 'onfocusin', 'onfocusout',
|
|
5
|
-
'onload',
|
|
6
|
-
'onplay', 'onpause', 'onended', 'ontimeupdate',
|
|
7
|
-
'onreset',
|
|
8
|
-
'onscroll', 'onsubmit'
|
|
9
|
-
]);
|
|
10
|
-
const LIFECYCLE_EVENTS = new Set([
|
|
11
|
-
'onconnect', 'ondisconnect', 'onrender', 'onresize', 'ontick'
|
|
12
|
-
]);
|
|
13
|
-
export { DIRECT_ATTACH_EVENTS, LIFECYCLE_EVENTS };
|
package/src/event/constants.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
const DIRECT_ATTACH_EVENTS = new Set<string>([
|
|
2
|
-
'onblur',
|
|
3
|
-
'onerror',
|
|
4
|
-
'onfocus', 'onfocusin', 'onfocusout',
|
|
5
|
-
'onload',
|
|
6
|
-
'onplay', 'onpause', 'onended', 'ontimeupdate',
|
|
7
|
-
'onreset',
|
|
8
|
-
'onscroll', 'onsubmit'
|
|
9
|
-
]);
|
|
10
|
-
|
|
11
|
-
const LIFECYCLE_EVENTS = new Set<string>([
|
|
12
|
-
'onconnect', 'ondisconnect', 'onrender', 'onresize', 'ontick'
|
|
13
|
-
]);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export { DIRECT_ATTACH_EVENTS, LIFECYCLE_EVENTS };
|