@esportsplus/template 0.35.1 → 0.38.0
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/compiler/analyzer.d.ts +4 -0
- package/build/compiler/{type-analyzer.js → analyzer.js} +15 -47
- package/build/compiler/codegen.d.ts +8 -6
- package/build/compiler/codegen.js +77 -75
- package/build/compiler/index.d.ts +5 -8
- package/build/compiler/index.js +32 -44
- package/build/compiler/plugins/tsc.js +2 -2
- package/build/compiler/plugins/vite.d.ts +4 -4
- package/build/compiler/plugins/vite.js +2 -2
- package/build/compiler/reactive-inlining.d.ts +5 -0
- package/build/compiler/reactive-inlining.js +75 -0
- package/build/compiler/ts-parser.js +2 -2
- package/package.json +4 -4
- package/src/compiler/analyzer.ts +92 -0
- package/src/compiler/codegen.ts +116 -110
- package/src/compiler/index.ts +35 -65
- package/src/compiler/plugins/tsc.ts +2 -2
- package/src/compiler/plugins/vite.ts +2 -2
- package/src/compiler/reactive-inlining.ts +116 -0
- package/src/compiler/ts-parser.ts +2 -2
- package/test/vite.config.ts +1 -1
- package/build/compiler/type-analyzer.d.ts +0 -6
- package/src/compiler/type-analyzer.ts +0 -148
|
@@ -50,10 +50,10 @@ function isHtmlFromPackage(node: ts.Identifier, checker: ts.TypeChecker | undefi
|
|
|
50
50
|
|
|
51
51
|
// Check if any declaration is from our package
|
|
52
52
|
for (let i = 0, n = declarations.length; i < n; i++) {
|
|
53
|
-
let
|
|
53
|
+
let filename = declarations[i].getSourceFile().fileName;
|
|
54
54
|
|
|
55
55
|
// Check for package in node_modules path or direct package reference
|
|
56
|
-
if (
|
|
56
|
+
if (filename.includes(PACKAGE) || filename.includes('@esportsplus/template')) {
|
|
57
57
|
return true;
|
|
58
58
|
}
|
|
59
59
|
}
|
package/test/vite.config.ts
CHANGED
|
@@ -19,7 +19,7 @@ export default defineConfig({
|
|
|
19
19
|
'templates': resolve(__dirname, 'templates.ts')
|
|
20
20
|
},
|
|
21
21
|
formats: ['es'],
|
|
22
|
-
|
|
22
|
+
filename: (_, entryName) => `${entryName}.js`
|
|
23
23
|
},
|
|
24
24
|
outDir: resolve(__dirname, 'build'),
|
|
25
25
|
emptyOutDir: true,
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { COMPILER_TYPES } from '../constants.js';
|
|
2
|
-
import { ts } from '@esportsplus/typescript';
|
|
3
|
-
declare const analyzeExpression: (expr: ts.Expression, checker?: ts.TypeChecker) => COMPILER_TYPES;
|
|
4
|
-
declare const generateAttributeBinding: (elementVar: string, name: string, expr: string, staticValue: string, addImport: (name: string) => string) => string;
|
|
5
|
-
declare const generateSpreadBindings: (exprCode: string, elementVar: string, addImport: (name: string) => string) => string[];
|
|
6
|
-
export { analyzeExpression, generateAttributeBinding, generateSpreadBindings };
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
COMPILER_ENTRYPOINT,
|
|
3
|
-
COMPILER_ENTRYPOINT_REACTIVITY,
|
|
4
|
-
COMPILER_TYPES,
|
|
5
|
-
DIRECT_ATTACH_EVENTS,
|
|
6
|
-
LIFECYCLE_EVENTS
|
|
7
|
-
} from '~/constants';
|
|
8
|
-
import { ts } from '@esportsplus/typescript';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
function inferCOMPILER_TYPES(expr: ts.Expression, checker?: ts.TypeChecker): COMPILER_TYPES {
|
|
12
|
-
while (ts.isParenthesizedExpression(expr)) {
|
|
13
|
-
expr = expr.expression;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (ts.isArrowFunction(expr) || ts.isFunctionExpression(expr)) {
|
|
17
|
-
return COMPILER_TYPES.Effect;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Only html.reactive() calls become ArraySlot - handled by generateReactiveInlining
|
|
21
|
-
if (
|
|
22
|
-
ts.isCallExpression(expr) &&
|
|
23
|
-
ts.isPropertyAccessExpression(expr.expression) &&
|
|
24
|
-
ts.isIdentifier(expr.expression.expression) &&
|
|
25
|
-
expr.expression.expression.text === COMPILER_ENTRYPOINT &&
|
|
26
|
-
expr.expression.name.text === COMPILER_ENTRYPOINT_REACTIVITY
|
|
27
|
-
) {
|
|
28
|
-
return COMPILER_TYPES.ArraySlot;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (ts.isTaggedTemplateExpression(expr) && ts.isIdentifier(expr.tag) && expr.tag.text === COMPILER_ENTRYPOINT) {
|
|
32
|
-
return COMPILER_TYPES.DocumentFragment;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (
|
|
36
|
-
ts.isNumericLiteral(expr) ||
|
|
37
|
-
ts.isStringLiteral(expr) ||
|
|
38
|
-
ts.isNoSubstitutionTemplateLiteral(expr) ||
|
|
39
|
-
expr.kind === ts.SyntaxKind.TrueKeyword ||
|
|
40
|
-
expr.kind === ts.SyntaxKind.FalseKeyword ||
|
|
41
|
-
expr.kind === ts.SyntaxKind.NullKeyword ||
|
|
42
|
-
expr.kind === ts.SyntaxKind.UndefinedKeyword
|
|
43
|
-
) {
|
|
44
|
-
return COMPILER_TYPES.Static;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (ts.isTemplateExpression(expr)) {
|
|
48
|
-
return COMPILER_TYPES.Primitive;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (ts.isConditionalExpression(expr)) {
|
|
52
|
-
let whenFalse = inferCOMPILER_TYPES(expr.whenFalse, checker),
|
|
53
|
-
whenTrue = inferCOMPILER_TYPES(expr.whenTrue, checker);
|
|
54
|
-
|
|
55
|
-
if (whenTrue === whenFalse) {
|
|
56
|
-
return whenTrue;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (whenTrue === COMPILER_TYPES.Effect || whenFalse === COMPILER_TYPES.Effect) {
|
|
60
|
-
return COMPILER_TYPES.Effect;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return COMPILER_TYPES.Unknown;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (checker && (ts.isIdentifier(expr) || ts.isPropertyAccessExpression(expr) || ts.isCallExpression(expr))) {
|
|
67
|
-
try {
|
|
68
|
-
let type = checker.getTypeAtLocation(expr);
|
|
69
|
-
|
|
70
|
-
if (isTypeFunction(type, checker)) {
|
|
71
|
-
return COMPILER_TYPES.Effect;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
catch {
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return COMPILER_TYPES.Unknown;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function isTypeFunction(type: ts.Type, checker: ts.TypeChecker): boolean {
|
|
82
|
-
// Union types that mix functions with non-functions (e.g., Renderable)
|
|
83
|
-
// should fall through to runtime slot dispatch
|
|
84
|
-
if (type.isUnion()) {
|
|
85
|
-
let allFunctions = true,
|
|
86
|
-
hasFunction = false;
|
|
87
|
-
|
|
88
|
-
for (let i = 0, n = type.types.length; i < n; i++) {
|
|
89
|
-
if (isTypeFunction(type.types[i], checker)) {
|
|
90
|
-
hasFunction = true;
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
allFunctions = false;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return hasFunction && allFunctions;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return type.getCallSignatures().length > 0;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const analyzeExpression = (expr: ts.Expression, checker?: ts.TypeChecker): COMPILER_TYPES => {
|
|
105
|
-
return inferCOMPILER_TYPES(expr, checker);
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
const generateAttributeBinding = (elementVar: string, name: string, expr: string, staticValue: string, addImport: (name: string) => string): string => {
|
|
109
|
-
if (name.startsWith('on') && name.length > 2) {
|
|
110
|
-
let event = name.slice(2).toLowerCase(),
|
|
111
|
-
key = name.toLowerCase();
|
|
112
|
-
|
|
113
|
-
if (LIFECYCLE_EVENTS.has(key)) {
|
|
114
|
-
return `${addImport(key)}(${elementVar}, ${expr});`;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (DIRECT_ATTACH_EVENTS.has(key)) {
|
|
118
|
-
return `${addImport('on')}(${elementVar}, '${event}', ${expr});`;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return `${addImport('delegate')}(${elementVar}, '${event}', ${expr});`;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (name === 'class') {
|
|
125
|
-
return `${addImport('setClass')}(${elementVar}, '${staticValue}', ${expr});`;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (name === COMPILER_TYPES.Attributes) {
|
|
129
|
-
return `${addImport('setProperties')}(${elementVar}, ${expr});`;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (name === 'style') {
|
|
133
|
-
return `${addImport('setStyle')}(${elementVar}, '${staticValue}', ${expr});`;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return `${addImport('setProperty')}(${elementVar}, '${name}', ${expr});`;
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
const generateSpreadBindings = (
|
|
140
|
-
exprCode: string,
|
|
141
|
-
elementVar: string,
|
|
142
|
-
addImport: (name: string) => string
|
|
143
|
-
): string[] => {
|
|
144
|
-
return [`${addImport('setProperties')}(${elementVar}, ${exprCode});`];
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
export { analyzeExpression, generateAttributeBinding, generateSpreadBindings };
|