@fluffjs/cli 0.4.0 → 0.4.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/CodeGenerator.d.ts
CHANGED
|
@@ -66,9 +66,9 @@ export declare class CodeGenerator {
|
|
|
66
66
|
generateRenderMethodFromHtml(html: string, styles?: string, markerConfigExpr?: t.Expression): string;
|
|
67
67
|
getMarkerConfigExpression(): t.Expression;
|
|
68
68
|
private buildMarkerConfigExpression;
|
|
69
|
-
private
|
|
70
|
-
private
|
|
71
|
-
private
|
|
69
|
+
private buildMarkerConfigArray;
|
|
70
|
+
private buildCompactDepsExpression;
|
|
71
|
+
private buildCompactPropertyChainExpression;
|
|
72
72
|
generateBindingsSetup(): string;
|
|
73
73
|
getBindingsMap(): Record<string, CompactBinding[]>;
|
|
74
74
|
generateExpressionAssignments(): string;
|
package/CodeGenerator.js
CHANGED
|
@@ -102,73 +102,81 @@ export class CodeGenerator {
|
|
|
102
102
|
const entries = Array.from(this.markerConfigs.entries())
|
|
103
103
|
.map(([id, config]) => t.arrayExpression([
|
|
104
104
|
t.numericLiteral(id),
|
|
105
|
-
this.
|
|
105
|
+
this.buildMarkerConfigArray(config)
|
|
106
106
|
]));
|
|
107
107
|
return t.arrayExpression(entries);
|
|
108
108
|
}
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
109
|
+
buildMarkerConfigArray(config) {
|
|
110
|
+
const MARKER_TYPE_MAP = {
|
|
111
|
+
'if': 0, 'for': 1, 'text': 2, 'switch': 3, 'break': 4
|
|
112
|
+
};
|
|
113
|
+
const typeNum = MARKER_TYPE_MAP[config.type];
|
|
113
114
|
if (config.type === 'text') {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
115
|
+
const elements = [
|
|
116
|
+
t.numericLiteral(typeNum),
|
|
117
|
+
t.numericLiteral(config.exprId),
|
|
118
|
+
config.deps ? this.buildCompactDepsExpression(config.deps) : t.nullLiteral(),
|
|
119
|
+
config.pipes && config.pipes.length > 0
|
|
120
|
+
? t.arrayExpression(config.pipes.map(pipe => t.arrayExpression([
|
|
121
|
+
t.numericLiteral(CodeGenerator.internString(pipe.name)),
|
|
122
|
+
t.arrayExpression(pipe.argExprIds.map(arg => t.numericLiteral(arg)))
|
|
123
|
+
])))
|
|
124
|
+
: t.nullLiteral()
|
|
125
|
+
];
|
|
126
|
+
return t.arrayExpression(elements);
|
|
124
127
|
}
|
|
125
128
|
else if (config.type === 'if') {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
branchProps.push(t.objectProperty(t.stringLiteral('exprId'), t.numericLiteral(branch.exprId)));
|
|
130
|
-
}
|
|
131
|
-
if (branch.deps) {
|
|
132
|
-
branchProps.push(t.objectProperty(t.stringLiteral('deps'), this.buildDepsExpression(branch.deps)));
|
|
129
|
+
const branches = t.arrayExpression(config.branches.map(branch => {
|
|
130
|
+
if (branch.exprId === undefined && !branch.deps) {
|
|
131
|
+
return t.arrayExpression([]);
|
|
133
132
|
}
|
|
134
|
-
return t.
|
|
135
|
-
|
|
133
|
+
return t.arrayExpression([
|
|
134
|
+
branch.exprId !== undefined ? t.numericLiteral(branch.exprId) : t.nullLiteral(),
|
|
135
|
+
branch.deps ? this.buildCompactDepsExpression(branch.deps) : t.nullLiteral()
|
|
136
|
+
]);
|
|
137
|
+
}));
|
|
138
|
+
return t.arrayExpression([t.numericLiteral(typeNum), branches]);
|
|
136
139
|
}
|
|
137
140
|
else if (config.type === 'for') {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
141
|
+
return t.arrayExpression([
|
|
142
|
+
t.numericLiteral(typeNum),
|
|
143
|
+
t.numericLiteral(CodeGenerator.internString(config.iterator)),
|
|
144
|
+
t.numericLiteral(config.iterableExprId),
|
|
145
|
+
t.booleanLiteral(config.hasEmpty),
|
|
146
|
+
config.deps ? this.buildCompactDepsExpression(config.deps) : t.nullLiteral(),
|
|
147
|
+
config.trackBy !== undefined
|
|
148
|
+
? t.numericLiteral(CodeGenerator.internString(config.trackBy))
|
|
149
|
+
: t.nullLiteral()
|
|
150
|
+
]);
|
|
145
151
|
}
|
|
146
152
|
else if (config.type === 'switch') {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
153
|
+
const cases = t.arrayExpression(config.cases.map(caseConfig => t.arrayExpression([
|
|
154
|
+
t.booleanLiteral(caseConfig.isDefault),
|
|
155
|
+
t.booleanLiteral(caseConfig.fallthrough),
|
|
156
|
+
caseConfig.valueExprId !== undefined
|
|
157
|
+
? t.numericLiteral(caseConfig.valueExprId)
|
|
158
|
+
: t.nullLiteral()
|
|
159
|
+
])));
|
|
160
|
+
return t.arrayExpression([
|
|
161
|
+
t.numericLiteral(typeNum),
|
|
162
|
+
t.numericLiteral(config.expressionExprId),
|
|
163
|
+
config.deps ? this.buildCompactDepsExpression(config.deps) : t.nullLiteral(),
|
|
164
|
+
cases
|
|
165
|
+
]);
|
|
166
|
+
}
|
|
167
|
+
else if (config.type === 'break') {
|
|
168
|
+
return t.arrayExpression([t.numericLiteral(typeNum)]);
|
|
169
|
+
}
|
|
170
|
+
return t.arrayExpression([t.numericLiteral(typeNum)]);
|
|
171
|
+
}
|
|
172
|
+
buildCompactDepsExpression(deps) {
|
|
173
|
+
return t.arrayExpression(deps.map(dep => this.buildCompactPropertyChainExpression(dep)));
|
|
174
|
+
}
|
|
175
|
+
buildCompactPropertyChainExpression(dep) {
|
|
168
176
|
if (Array.isArray(dep)) {
|
|
169
|
-
return t.arrayExpression(dep.map(part => t.
|
|
177
|
+
return t.arrayExpression(dep.map(part => t.numericLiteral(CodeGenerator.internString(part))));
|
|
170
178
|
}
|
|
171
|
-
return t.
|
|
179
|
+
return t.numericLiteral(CodeGenerator.internString(dep));
|
|
172
180
|
}
|
|
173
181
|
generateBindingsSetup() {
|
|
174
182
|
const statements = [
|
package/package.json
CHANGED
|
@@ -9,6 +9,9 @@ type MarkerConfigEntriesLiteral = [number, MarkerConfigLiteral][];
|
|
|
9
9
|
export declare class MarkerConfigAstReader {
|
|
10
10
|
static readMarkerConfigEntries(code: string): MarkerConfigEntriesLiteral;
|
|
11
11
|
static collectDeps(entries: MarkerConfigEntriesLiteral): string[];
|
|
12
|
+
private static collectDepsFromCompactConfig;
|
|
13
|
+
private static collectNumberDeps;
|
|
14
|
+
static collectCompactDeps(entries: MarkerConfigEntriesLiteral): number[][];
|
|
12
15
|
private static collectDepsFromRecord;
|
|
13
16
|
private static collectDepsFromIf;
|
|
14
17
|
private static collectStringsFromDep;
|
|
@@ -31,6 +31,9 @@ export class MarkerConfigAstReader {
|
|
|
31
31
|
static collectDeps(entries) {
|
|
32
32
|
const deps = [];
|
|
33
33
|
for (const [, config] of entries) {
|
|
34
|
+
if (Array.isArray(config)) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
34
37
|
if (!MarkerConfigAstReader.isRecord(config)) {
|
|
35
38
|
continue;
|
|
36
39
|
}
|
|
@@ -56,6 +59,72 @@ export class MarkerConfigAstReader {
|
|
|
56
59
|
}
|
|
57
60
|
return deps;
|
|
58
61
|
}
|
|
62
|
+
static collectDepsFromCompactConfig(config, deps) {
|
|
63
|
+
const [typeNum] = config;
|
|
64
|
+
if (typeof typeNum !== 'number')
|
|
65
|
+
return;
|
|
66
|
+
switch (typeNum) {
|
|
67
|
+
case 0: // if
|
|
68
|
+
{
|
|
69
|
+
const [, branches] = config;
|
|
70
|
+
if (Array.isArray(branches)) {
|
|
71
|
+
for (const branch of branches) {
|
|
72
|
+
if (Array.isArray(branch) && branch.length >= 2) {
|
|
73
|
+
const [, branchDeps] = branch;
|
|
74
|
+
if (Array.isArray(branchDeps)) {
|
|
75
|
+
MarkerConfigAstReader.collectNumberDeps(branchDeps, deps);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
case 1: // for
|
|
83
|
+
{
|
|
84
|
+
const [, , , , forDeps] = config;
|
|
85
|
+
if (Array.isArray(forDeps)) {
|
|
86
|
+
MarkerConfigAstReader.collectNumberDeps(forDeps, deps);
|
|
87
|
+
}
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
case 2: // text
|
|
91
|
+
{
|
|
92
|
+
const [, , textDeps] = config;
|
|
93
|
+
if (Array.isArray(textDeps)) {
|
|
94
|
+
MarkerConfigAstReader.collectNumberDeps(textDeps, deps);
|
|
95
|
+
}
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
case 3: // switch
|
|
99
|
+
{
|
|
100
|
+
const [, , switchDeps] = config;
|
|
101
|
+
if (Array.isArray(switchDeps)) {
|
|
102
|
+
MarkerConfigAstReader.collectNumberDeps(switchDeps, deps);
|
|
103
|
+
}
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
static collectNumberDeps(compactDeps, deps) {
|
|
109
|
+
for (const dep of compactDeps) {
|
|
110
|
+
if (typeof dep === 'number') {
|
|
111
|
+
deps.push([dep]);
|
|
112
|
+
}
|
|
113
|
+
else if (Array.isArray(dep)) {
|
|
114
|
+
const numDeps = dep.filter((d) => typeof d === 'number');
|
|
115
|
+
deps.push(numDeps);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
static collectCompactDeps(entries) {
|
|
120
|
+
const deps = [];
|
|
121
|
+
for (const [, config] of entries) {
|
|
122
|
+
if (Array.isArray(config)) {
|
|
123
|
+
MarkerConfigAstReader.collectDepsFromCompactConfig(config, deps);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return deps;
|
|
127
|
+
}
|
|
59
128
|
static collectDepsFromRecord(configRecord, deps) {
|
|
60
129
|
const configDeps = configRecord.deps;
|
|
61
130
|
if (Array.isArray(configDeps)) {
|
|
@@ -153,7 +222,7 @@ export class MarkerConfigAstReader {
|
|
|
153
222
|
return false;
|
|
154
223
|
}
|
|
155
224
|
const [id, config] = entry;
|
|
156
|
-
return typeof id === 'number' && MarkerConfigAstReader.isRecord(config);
|
|
225
|
+
return typeof id === 'number' && (MarkerConfigAstReader.isRecord(config) || Array.isArray(config));
|
|
157
226
|
});
|
|
158
227
|
}
|
|
159
228
|
static isRecord(value) {
|