@vobs/compiler 1.2.0 → 1.2.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/dist/compile.cjs +276 -245
- package/dist/compile.cjs.map +1 -1
- package/dist/compile.js +9 -6
- package/dist/compile.js.map +1 -1
- package/dist/i18n-extractor.cjs +45 -16
- package/dist/i18n-extractor.cjs.map +1 -1
- package/dist/i18n-extractor.js +6 -5
- package/dist/i18n-extractor.js.map +1 -1
- package/dist/index.cjs +288 -251
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +18 -11
- package/dist/index.js.map +1 -1
- package/dist/plugin.cjs +18 -2
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.js +0 -2
- package/dist/plugin.js.map +1 -1
- package/package.json +6 -2
package/dist/compile.cjs
CHANGED
|
@@ -1,14 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var error = require('@vobs/runtime/error');
|
|
5
|
-
|
|
6
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
-
|
|
8
|
-
var ts__default = /*#__PURE__*/_interopDefault(ts);
|
|
9
|
-
|
|
1
|
+
var __VOBS_CJS_FILE_URL = require("url").pathToFileURL(__filename).href;
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
10
4
|
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
9
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all)
|
|
12
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
28
|
+
mod
|
|
29
|
+
));
|
|
30
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
31
|
+
|
|
32
|
+
// packages/compiler/src/compile.ts
|
|
33
|
+
var compile_exports = {};
|
|
34
|
+
__export(compile_exports, {
|
|
35
|
+
compile: () => compile,
|
|
36
|
+
compileWithSourceMap: () => compileWithSourceMap,
|
|
37
|
+
createCompiler: () => createCompiler
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(compile_exports);
|
|
40
|
+
var import_typescript = __toESM(require("typescript"), 1);
|
|
41
|
+
var import_error = require("@vobs/runtime/error");
|
|
12
42
|
function createCompiler(options = {}) {
|
|
13
43
|
const basePlugins = options.plugins ?? [];
|
|
14
44
|
return {
|
|
@@ -31,7 +61,7 @@ function compile(code, options = {}) {
|
|
|
31
61
|
const result = compileWithSourceMap(code, options);
|
|
32
62
|
const firstError = result.diagnostics.find((diagnostic) => diagnostic.severity === "error");
|
|
33
63
|
if (firstError) {
|
|
34
|
-
throw new
|
|
64
|
+
throw new import_error.VobsError({
|
|
35
65
|
code: firstError.code,
|
|
36
66
|
layer: "compiler",
|
|
37
67
|
message: firstError.message,
|
|
@@ -45,12 +75,12 @@ function compile(code, options = {}) {
|
|
|
45
75
|
__name(compile, "compile");
|
|
46
76
|
function compileWithSourceMap(code, options = {}) {
|
|
47
77
|
const filename = options.filename ?? "component.tsx";
|
|
48
|
-
let sourceFile =
|
|
78
|
+
let sourceFile = import_typescript.default.createSourceFile(
|
|
49
79
|
filename,
|
|
50
80
|
code,
|
|
51
|
-
|
|
81
|
+
import_typescript.default.ScriptTarget.Latest,
|
|
52
82
|
true,
|
|
53
|
-
|
|
83
|
+
import_typescript.default.ScriptKind.TSX
|
|
54
84
|
);
|
|
55
85
|
const state = {
|
|
56
86
|
generatedId: 0,
|
|
@@ -66,18 +96,18 @@ function compileWithSourceMap(code, options = {}) {
|
|
|
66
96
|
diagnostics: []
|
|
67
97
|
};
|
|
68
98
|
const cleanFilename = filename.split(/[?#]/u, 1)[0] || filename;
|
|
69
|
-
const diagnostics =
|
|
99
|
+
const diagnostics = import_typescript.default.transpileModule(code, {
|
|
70
100
|
// Vite appends query strings (for example `?direct`) to module IDs;
|
|
71
101
|
// strip them so TypeScript still recognizes TSX syntax for diagnostics.
|
|
72
102
|
fileName: cleanFilename,
|
|
73
103
|
reportDiagnostics: true,
|
|
74
|
-
compilerOptions: { jsx:
|
|
104
|
+
compilerOptions: { jsx: import_typescript.default.JsxEmit.Preserve, target: import_typescript.default.ScriptTarget.Latest }
|
|
75
105
|
}).diagnostics?.map((diagnostic) => toCompilerDiagnostic(diagnostic, sourceFile, cleanFilename)) ?? [];
|
|
76
106
|
const plugins = options.plugins ?? [];
|
|
77
107
|
validatePlugins(plugins);
|
|
78
108
|
const context = {
|
|
79
109
|
filename,
|
|
80
|
-
factory:
|
|
110
|
+
factory: import_typescript.default.factory,
|
|
81
111
|
addRuntimeImport(name) {
|
|
82
112
|
resolveHelperName(state, name);
|
|
83
113
|
},
|
|
@@ -89,15 +119,15 @@ function compileWithSourceMap(code, options = {}) {
|
|
|
89
119
|
}
|
|
90
120
|
for (const plugin of plugins) sourceFile = transformPluginNodes(sourceFile, plugin, context);
|
|
91
121
|
const statements = sourceFile.statements.map(
|
|
92
|
-
(statement) =>
|
|
122
|
+
(statement) => import_typescript.default.isImportDeclaration(statement) ? rebuildImport(state, statement) : transformStatement(state, statement)
|
|
93
123
|
);
|
|
94
124
|
const templateDeclarations = createTemplateDeclarations(state);
|
|
95
|
-
const resultFile =
|
|
125
|
+
const resultFile = import_typescript.default.factory.updateSourceFile(sourceFile, [
|
|
96
126
|
...createRuntimeImports(state),
|
|
97
127
|
...templateDeclarations,
|
|
98
128
|
...statements
|
|
99
129
|
]);
|
|
100
|
-
const generated =
|
|
130
|
+
const generated = import_typescript.default.createPrinter().printFile(resultFile);
|
|
101
131
|
return {
|
|
102
132
|
code: generated,
|
|
103
133
|
map: buildSourceMap(state, filename, code, generated, resultFile),
|
|
@@ -108,11 +138,11 @@ __name(compileWithSourceMap, "compileWithSourceMap");
|
|
|
108
138
|
function toCompilerDiagnostic(diagnostic, sourceFile, filename) {
|
|
109
139
|
const start = diagnostic.start ?? 0;
|
|
110
140
|
const length = diagnostic.length ?? 1;
|
|
111
|
-
const message =
|
|
141
|
+
const message = import_typescript.default.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
|
112
142
|
const { line, column, codeFrame } = buildCodeFrame(sourceFile, start, length);
|
|
113
143
|
return {
|
|
114
144
|
code: `VOBS_C${String(diagnostic.code).padStart(3, "0")}`,
|
|
115
|
-
severity: diagnostic.category ===
|
|
145
|
+
severity: diagnostic.category === import_typescript.default.DiagnosticCategory.Warning ? "warning" : "error",
|
|
116
146
|
message,
|
|
117
147
|
location: { file: filename, line, column },
|
|
118
148
|
codeFrame
|
|
@@ -135,7 +165,7 @@ function reportUnsupportedTag(state, tagName) {
|
|
|
135
165
|
const sourceFile = tagName.getSourceFile() ?? state.sourceFile;
|
|
136
166
|
if (!sourceFile) return;
|
|
137
167
|
const label = tagName.getText();
|
|
138
|
-
const kindNote = tagName.kind ===
|
|
168
|
+
const kindNote = tagName.kind === import_typescript.default.SyntaxKind.JsxNamespacedName ? "\uFF08JSX \u547D\u540D\u7A7A\u95F4\u6807\u7B7E\uFF09" : "";
|
|
139
169
|
const { line, column, codeFrame } = buildCodeFrame(sourceFile, tagName.getStart(sourceFile), tagName.getWidth(sourceFile));
|
|
140
170
|
state.diagnostics.push({
|
|
141
171
|
code: "VOBS_C101",
|
|
@@ -148,7 +178,7 @@ function reportUnsupportedTag(state, tagName) {
|
|
|
148
178
|
}
|
|
149
179
|
__name(reportUnsupportedTag, "reportUnsupportedTag");
|
|
150
180
|
function buildSourceMap(state, filename, source, generated, resultFile) {
|
|
151
|
-
const reparsed =
|
|
181
|
+
const reparsed = import_typescript.default.createSourceFile(filename, generated, import_typescript.default.ScriptTarget.Latest, true, import_typescript.default.ScriptKind.TSX);
|
|
152
182
|
const segments = [];
|
|
153
183
|
walkPairedTrees(state, resultFile, reparsed, reparsed, segments);
|
|
154
184
|
segments.sort((a, b) => a.genLine - b.genLine || a.genCol - b.genCol);
|
|
@@ -163,8 +193,8 @@ function buildSourceMap(state, filename, source, generated, resultFile) {
|
|
|
163
193
|
}
|
|
164
194
|
__name(buildSourceMap, "buildSourceMap");
|
|
165
195
|
function statementLists(node) {
|
|
166
|
-
if (
|
|
167
|
-
if (
|
|
196
|
+
if (import_typescript.default.isSourceFile(node) || import_typescript.default.isBlock(node) || import_typescript.default.isModuleBlock(node)) return node.statements;
|
|
197
|
+
if (import_typescript.default.isCaseClause(node) || import_typescript.default.isDefaultClause(node)) return node.statements;
|
|
168
198
|
return null;
|
|
169
199
|
}
|
|
170
200
|
__name(statementLists, "statementLists");
|
|
@@ -183,10 +213,10 @@ function walkPairedTrees(state, original, generated, reparsed, segments) {
|
|
|
183
213
|
}
|
|
184
214
|
const originalChildren = [];
|
|
185
215
|
const generatedChildren = [];
|
|
186
|
-
|
|
216
|
+
import_typescript.default.forEachChild(original, (node) => {
|
|
187
217
|
originalChildren.push(node);
|
|
188
218
|
});
|
|
189
|
-
|
|
219
|
+
import_typescript.default.forEachChild(generated, (node) => {
|
|
190
220
|
generatedChildren.push(node);
|
|
191
221
|
});
|
|
192
222
|
if (originalChildren.length !== generatedChildren.length) return;
|
|
@@ -256,8 +286,8 @@ __name(encodeVlq, "encodeVlq");
|
|
|
256
286
|
function validatePlugins(plugins) {
|
|
257
287
|
const names = /* @__PURE__ */ new Set();
|
|
258
288
|
for (const plugin of plugins) {
|
|
259
|
-
if (!plugin.name) throw new
|
|
260
|
-
if (names.has(plugin.name)) throw new
|
|
289
|
+
if (!plugin.name) throw new import_error.VobsError({ code: "VOBS_C007", layer: "compiler", message: "\u7F16\u8BD1\u5668\u63D2\u4EF6\u5FC5\u987B\u63D0\u4F9B name", fix: "\u4E3A\u63D2\u4EF6\u6DFB\u52A0\u7A33\u5B9A\u4E14\u552F\u4E00\u7684 name\u3002" });
|
|
290
|
+
if (names.has(plugin.name)) throw new import_error.VobsError({ code: "VOBS_C007", layer: "compiler", message: `\u68C0\u6D4B\u5230\u91CD\u590D\u63D2\u4EF6: ${plugin.name}`, fix: "\u4E3A\u6BCF\u4E2A\u7F16\u8BD1\u5668\u63D2\u4EF6\u4F7F\u7528\u552F\u4E00\u7684 name\u3002" });
|
|
261
291
|
names.add(plugin.name);
|
|
262
292
|
}
|
|
263
293
|
}
|
|
@@ -269,11 +299,11 @@ function transformPluginNodes(sourceFile, plugin, context) {
|
|
|
269
299
|
const visit = /* @__PURE__ */ __name((node) => {
|
|
270
300
|
const replacement = transformNode(node, context);
|
|
271
301
|
if (replacement === null) return void 0;
|
|
272
|
-
return
|
|
302
|
+
return import_typescript.default.visitEachChild(replacement ?? node, visit, transformContext);
|
|
273
303
|
}, "visit");
|
|
274
|
-
return
|
|
304
|
+
return import_typescript.default.visitNode(root, visit);
|
|
275
305
|
}, "transformer");
|
|
276
|
-
const result =
|
|
306
|
+
const result = import_typescript.default.transform(sourceFile, [transformer]);
|
|
277
307
|
try {
|
|
278
308
|
return result.transformed[0];
|
|
279
309
|
} finally {
|
|
@@ -284,8 +314,8 @@ __name(transformPluginNodes, "transformPluginNodes");
|
|
|
284
314
|
function collectDeclaredNames(sourceFile) {
|
|
285
315
|
const names = /* @__PURE__ */ new Set();
|
|
286
316
|
const visit = /* @__PURE__ */ __name((node) => {
|
|
287
|
-
if (
|
|
288
|
-
|
|
317
|
+
if (import_typescript.default.isIdentifier(node) && isBindingName(node)) names.add(node.text);
|
|
318
|
+
import_typescript.default.forEachChild(node, visit);
|
|
289
319
|
}, "visit");
|
|
290
320
|
visit(sourceFile);
|
|
291
321
|
return names;
|
|
@@ -294,11 +324,11 @@ __name(collectDeclaredNames, "collectDeclaredNames");
|
|
|
294
324
|
function collectStateAliases(sourceFile) {
|
|
295
325
|
const aliases = /* @__PURE__ */ new Set();
|
|
296
326
|
for (const statement of sourceFile.statements) {
|
|
297
|
-
if (!
|
|
298
|
-
const
|
|
299
|
-
if (
|
|
327
|
+
if (!import_typescript.default.isImportDeclaration(statement) || !import_typescript.default.isStringLiteral(statement.moduleSpecifier)) continue;
|
|
328
|
+
const module2 = statement.moduleSpecifier.text;
|
|
329
|
+
if (module2 !== "@vobs/reactivity" && module2 !== "@vobs/vobs") continue;
|
|
300
330
|
const clause = statement.importClause;
|
|
301
|
-
if (!clause?.namedBindings || !
|
|
331
|
+
if (!clause?.namedBindings || !import_typescript.default.isNamedImports(clause.namedBindings)) continue;
|
|
302
332
|
for (const element of clause.namedBindings.elements) {
|
|
303
333
|
if (element.propertyName ? element.propertyName.text === "state" : element.name.text === "state") {
|
|
304
334
|
aliases.add(element.name.text);
|
|
@@ -311,9 +341,9 @@ __name(collectStateAliases, "collectStateAliases");
|
|
|
311
341
|
function collectLocallyDeclaredNames(sourceFile) {
|
|
312
342
|
const names = /* @__PURE__ */ new Set();
|
|
313
343
|
const visit = /* @__PURE__ */ __name((node) => {
|
|
314
|
-
if (
|
|
315
|
-
if (
|
|
316
|
-
|
|
344
|
+
if (import_typescript.default.isImportDeclaration(node)) return;
|
|
345
|
+
if (import_typescript.default.isIdentifier(node) && isBindingName(node)) names.add(node.text);
|
|
346
|
+
import_typescript.default.forEachChild(node, visit);
|
|
317
347
|
}, "visit");
|
|
318
348
|
visit(sourceFile);
|
|
319
349
|
return names;
|
|
@@ -322,9 +352,9 @@ __name(collectLocallyDeclaredNames, "collectLocallyDeclaredNames");
|
|
|
322
352
|
function isBindingName(node) {
|
|
323
353
|
const parent = node.parent;
|
|
324
354
|
if (!parent) return false;
|
|
325
|
-
if (
|
|
326
|
-
if (
|
|
327
|
-
if (
|
|
355
|
+
if (import_typescript.default.isPropertyAccessExpression(parent) && parent.name === node) return false;
|
|
356
|
+
if (import_typescript.default.isQualifiedName(parent) && parent.right === node) return false;
|
|
357
|
+
if (import_typescript.default.isJsxAttribute(parent)) return false;
|
|
328
358
|
return parent.name === node;
|
|
329
359
|
}
|
|
330
360
|
__name(isBindingName, "isBindingName");
|
|
@@ -342,45 +372,45 @@ function resolveHelperName(state, name) {
|
|
|
342
372
|
}
|
|
343
373
|
__name(resolveHelperName, "resolveHelperName");
|
|
344
374
|
function helperRef(state, name) {
|
|
345
|
-
return
|
|
375
|
+
return import_typescript.default.factory.createIdentifier(resolveHelperName(state, name));
|
|
346
376
|
}
|
|
347
377
|
__name(helperRef, "helperRef");
|
|
348
378
|
function createRuntimeImports(state) {
|
|
349
379
|
const modules = /* @__PURE__ */ new Map();
|
|
350
380
|
for (const [name, alias] of state.helperAliases) {
|
|
351
|
-
const
|
|
352
|
-
const imported = modules.get(
|
|
353
|
-
imported.push(
|
|
381
|
+
const module2 = name === "insertResourceBoundary" ? "@vobs/resource" : "@vobs/vobs";
|
|
382
|
+
const imported = modules.get(module2) ?? [];
|
|
383
|
+
imported.push(import_typescript.default.factory.createImportSpecifier(
|
|
354
384
|
false,
|
|
355
|
-
alias === name ? void 0 :
|
|
356
|
-
|
|
385
|
+
alias === name ? void 0 : import_typescript.default.factory.createIdentifier(name),
|
|
386
|
+
import_typescript.default.factory.createIdentifier(alias)
|
|
357
387
|
));
|
|
358
|
-
modules.set(
|
|
388
|
+
modules.set(module2, imported);
|
|
359
389
|
}
|
|
360
|
-
return [...modules.entries()].map(([
|
|
390
|
+
return [...modules.entries()].map(([module2, imported]) => import_typescript.default.factory.createImportDeclaration(
|
|
361
391
|
void 0,
|
|
362
|
-
|
|
392
|
+
import_typescript.default.factory.createImportClause(
|
|
363
393
|
false,
|
|
364
394
|
void 0,
|
|
365
|
-
|
|
395
|
+
import_typescript.default.factory.createNamedImports(imported)
|
|
366
396
|
),
|
|
367
|
-
|
|
397
|
+
import_typescript.default.factory.createStringLiteral(module2)
|
|
368
398
|
));
|
|
369
399
|
}
|
|
370
400
|
__name(createRuntimeImports, "createRuntimeImports");
|
|
371
401
|
function rebuildImport(state, node) {
|
|
372
|
-
if (!
|
|
373
|
-
return tagStatement(state,
|
|
402
|
+
if (!import_typescript.default.isStringLiteral(node.moduleSpecifier)) return node;
|
|
403
|
+
return tagStatement(state, import_typescript.default.factory.createImportDeclaration(
|
|
374
404
|
node.modifiers,
|
|
375
405
|
node.importClause,
|
|
376
|
-
|
|
406
|
+
import_typescript.default.factory.createStringLiteral(node.moduleSpecifier.text),
|
|
377
407
|
node.attributes
|
|
378
408
|
), node);
|
|
379
409
|
}
|
|
380
410
|
__name(rebuildImport, "rebuildImport");
|
|
381
411
|
function transformStatement(state, node) {
|
|
382
|
-
if (
|
|
383
|
-
return tagStatement(state,
|
|
412
|
+
if (import_typescript.default.isFunctionDeclaration(node) && node.body) {
|
|
413
|
+
return tagStatement(state, import_typescript.default.factory.updateFunctionDeclaration(
|
|
384
414
|
node,
|
|
385
415
|
node.modifiers,
|
|
386
416
|
node.asteriskToken,
|
|
@@ -391,15 +421,15 @@ function transformStatement(state, node) {
|
|
|
391
421
|
transformBlock(state, node.body)
|
|
392
422
|
), node);
|
|
393
423
|
}
|
|
394
|
-
if (
|
|
395
|
-
if (
|
|
396
|
-
return tagStatement(state,
|
|
424
|
+
if (import_typescript.default.isVariableStatement(node)) return transformVariableStatement(state, node);
|
|
425
|
+
if (import_typescript.default.isExportAssignment(node) && containsJsx(node.expression)) {
|
|
426
|
+
return tagStatement(state, import_typescript.default.factory.updateExportAssignment(node, node.modifiers, transformEmbeddedExpression(state, node.expression)), node);
|
|
397
427
|
}
|
|
398
|
-
if (
|
|
399
|
-
return tagStatement(state,
|
|
428
|
+
if (import_typescript.default.isExpressionStatement(node) && containsJsx(node.expression)) {
|
|
429
|
+
return tagStatement(state, import_typescript.default.factory.updateExpressionStatement(node, transformEmbeddedExpression(state, node.expression)), node);
|
|
400
430
|
}
|
|
401
|
-
if (
|
|
402
|
-
return tagStatement(state,
|
|
431
|
+
if (import_typescript.default.isReturnStatement(node) && node.expression && containsJsx(node.expression)) {
|
|
432
|
+
return tagStatement(state, import_typescript.default.factory.updateReturnStatement(node, transformEmbeddedExpression(state, node.expression)), node);
|
|
403
433
|
}
|
|
404
434
|
return node;
|
|
405
435
|
}
|
|
@@ -415,7 +445,7 @@ function transformVariableStatement(state, node) {
|
|
|
415
445
|
}
|
|
416
446
|
if (nextInitializer === initializer) return declaration;
|
|
417
447
|
changed = true;
|
|
418
|
-
return
|
|
448
|
+
return import_typescript.default.factory.updateVariableDeclaration(
|
|
419
449
|
declaration,
|
|
420
450
|
declaration.name,
|
|
421
451
|
declaration.exclamationToken,
|
|
@@ -424,28 +454,28 @@ function transformVariableStatement(state, node) {
|
|
|
424
454
|
);
|
|
425
455
|
});
|
|
426
456
|
if (!changed) return node;
|
|
427
|
-
return tagStatement(state,
|
|
457
|
+
return tagStatement(state, import_typescript.default.factory.updateVariableStatement(
|
|
428
458
|
node,
|
|
429
459
|
node.modifiers,
|
|
430
|
-
|
|
460
|
+
import_typescript.default.factory.updateVariableDeclarationList(node.declarationList, declarations)
|
|
431
461
|
), node);
|
|
432
462
|
}
|
|
433
463
|
__name(transformVariableStatement, "transformVariableStatement");
|
|
434
464
|
function inferStateDebugName(state, declaration, initializer) {
|
|
435
465
|
if (state.stateAliases.size === 0) return void 0;
|
|
436
|
-
if (!
|
|
466
|
+
if (!import_typescript.default.isIdentifier(declaration.name)) return void 0;
|
|
437
467
|
let call = initializer;
|
|
438
|
-
while (
|
|
468
|
+
while (import_typescript.default.isParenthesizedExpression(call) || import_typescript.default.isAsExpression(call) || import_typescript.default.isTypeAssertionExpression(call) || import_typescript.default.isSatisfiesExpression(call)) {
|
|
439
469
|
call = call.expression;
|
|
440
470
|
}
|
|
441
|
-
if (!
|
|
471
|
+
if (!import_typescript.default.isCallExpression(call)) return void 0;
|
|
442
472
|
const callee = call.expression;
|
|
443
|
-
if (!
|
|
473
|
+
if (!import_typescript.default.isIdentifier(callee) || !state.stateAliases.has(callee.text)) return void 0;
|
|
444
474
|
if (state.localBindings.has(callee.text)) return void 0;
|
|
445
475
|
if (call.arguments.length !== 1) return void 0;
|
|
446
|
-
return
|
|
476
|
+
return import_typescript.default.factory.createCallExpression(callee, call.typeArguments, [
|
|
447
477
|
...call.arguments,
|
|
448
|
-
|
|
478
|
+
import_typescript.default.factory.createStringLiteral(declaration.name.text)
|
|
449
479
|
]);
|
|
450
480
|
}
|
|
451
481
|
__name(inferStateDebugName, "inferStateDebugName");
|
|
@@ -456,7 +486,7 @@ function containsJsx(expression) {
|
|
|
456
486
|
found = true;
|
|
457
487
|
return;
|
|
458
488
|
}
|
|
459
|
-
|
|
489
|
+
import_typescript.default.forEachChild(node, visit);
|
|
460
490
|
}, "visit");
|
|
461
491
|
visit(expression);
|
|
462
492
|
return found;
|
|
@@ -464,20 +494,20 @@ function containsJsx(expression) {
|
|
|
464
494
|
__name(containsJsx, "containsJsx");
|
|
465
495
|
function transformBlock(state, block) {
|
|
466
496
|
const statements = block.statements.map((statement) => {
|
|
467
|
-
if (!
|
|
468
|
-
const expression =
|
|
469
|
-
return isJsxExpression(expression) ? tagStatement(state,
|
|
497
|
+
if (!import_typescript.default.isReturnStatement(statement) || !statement.expression) return transformStatement(state, statement);
|
|
498
|
+
const expression = import_typescript.default.isParenthesizedExpression(statement.expression) ? statement.expression.expression : statement.expression;
|
|
499
|
+
return isJsxExpression(expression) ? tagStatement(state, import_typescript.default.factory.updateReturnStatement(statement, transformJsxExpression(state, expression)), statement) : statement;
|
|
470
500
|
});
|
|
471
|
-
return
|
|
501
|
+
return import_typescript.default.factory.updateBlock(block, statements);
|
|
472
502
|
}
|
|
473
503
|
__name(transformBlock, "transformBlock");
|
|
474
504
|
function isJsxExpression(node) {
|
|
475
|
-
return
|
|
505
|
+
return import_typescript.default.isJsxElement(node) || import_typescript.default.isJsxSelfClosingElement(node) || import_typescript.default.isJsxFragment(node);
|
|
476
506
|
}
|
|
477
507
|
__name(isJsxExpression, "isJsxExpression");
|
|
478
508
|
function transformJsxExpression(state, node) {
|
|
479
|
-
if (
|
|
480
|
-
if (
|
|
509
|
+
if (import_typescript.default.isJsxFragment(node)) return transformFragment(state, node.children);
|
|
510
|
+
if (import_typescript.default.isJsxElement(node)) {
|
|
481
511
|
return transformElement(state, node, node.openingElement.tagName, node.openingElement.attributes, node.children);
|
|
482
512
|
}
|
|
483
513
|
return transformElement(state, node, node.tagName, node.attributes, []);
|
|
@@ -485,35 +515,35 @@ function transformJsxExpression(state, node) {
|
|
|
485
515
|
__name(transformJsxExpression, "transformJsxExpression");
|
|
486
516
|
function transformElement(state, node, tagName, attributes, children) {
|
|
487
517
|
if (isFragmentTag(tagName)) return transformFragment(state, children);
|
|
488
|
-
if (!
|
|
518
|
+
if (!import_typescript.default.isIdentifier(tagName)) {
|
|
489
519
|
reportUnsupportedTag(state, tagName);
|
|
490
520
|
}
|
|
491
|
-
if (
|
|
521
|
+
if (import_typescript.default.isIdentifier(tagName) && tagName.text === "ResourceBoundary") {
|
|
492
522
|
return transformResourceBoundary(state, node, attributes, children);
|
|
493
523
|
}
|
|
494
|
-
if (
|
|
524
|
+
if (import_typescript.default.isIdentifier(tagName) && tagName.text === "AsyncBoundary") {
|
|
495
525
|
return transformAsyncBoundary(state, node, attributes, children);
|
|
496
526
|
}
|
|
497
|
-
if (
|
|
527
|
+
if (import_typescript.default.isIdentifier(tagName) && tagName.text === "ErrorBoundary") {
|
|
498
528
|
return transformErrorBoundary(state, node, attributes, children);
|
|
499
529
|
}
|
|
500
|
-
if (
|
|
530
|
+
if (import_typescript.default.isIdentifier(tagName) && tagName.text === "Profiler") {
|
|
501
531
|
return transformProfiler(state, node, attributes, children);
|
|
502
532
|
}
|
|
503
|
-
if (
|
|
533
|
+
if (import_typescript.default.isIdentifier(tagName) && /^[A-Z]/.test(tagName.text)) {
|
|
504
534
|
const args = [
|
|
505
|
-
|
|
535
|
+
import_typescript.default.factory.createCallExpression(helperRef(state, "resolveComponent"), void 0, [
|
|
506
536
|
tagName,
|
|
507
|
-
|
|
508
|
-
|
|
537
|
+
import_typescript.default.factory.createStringLiteral(state.filename),
|
|
538
|
+
import_typescript.default.factory.createStringLiteral(tagName.text)
|
|
509
539
|
]),
|
|
510
540
|
createComponentProps(state, attributes, children)
|
|
511
541
|
];
|
|
512
542
|
if (state.sourceLocation) args.push(createSourceLocation(tagName));
|
|
513
|
-
return
|
|
543
|
+
return import_typescript.default.factory.createCallExpression(helperRef(state, "createComponent"), void 0, args);
|
|
514
544
|
}
|
|
515
545
|
if (isStaticElement(tagName, attributes, children)) {
|
|
516
|
-
return
|
|
546
|
+
return import_typescript.default.factory.createCallExpression(
|
|
517
547
|
helperRef(state, "cloneTemplate"),
|
|
518
548
|
void 0,
|
|
519
549
|
[registerTemplate(state, serializeStaticHtml(node))]
|
|
@@ -525,25 +555,25 @@ function transformElement(state, node, tagName, attributes, children) {
|
|
|
525
555
|
createConstStatement(
|
|
526
556
|
state,
|
|
527
557
|
elementId,
|
|
528
|
-
|
|
558
|
+
import_typescript.default.factory.createCallExpression(
|
|
529
559
|
helperRef(state, "createElement"),
|
|
530
560
|
void 0,
|
|
531
|
-
[
|
|
561
|
+
[import_typescript.default.factory.createStringLiteral(elementName)]
|
|
532
562
|
),
|
|
533
563
|
node
|
|
534
564
|
)
|
|
535
565
|
];
|
|
536
566
|
appendAttributes(state, statements, elementId, attributes);
|
|
537
567
|
appendChildren(state, statements, elementId, children);
|
|
538
|
-
statements.push(tagStatement(state,
|
|
539
|
-
return
|
|
540
|
-
|
|
568
|
+
statements.push(tagStatement(state, import_typescript.default.factory.createReturnStatement(elementId), node));
|
|
569
|
+
return import_typescript.default.factory.createCallExpression(
|
|
570
|
+
import_typescript.default.factory.createArrowFunction(
|
|
541
571
|
void 0,
|
|
542
572
|
void 0,
|
|
543
573
|
[],
|
|
544
574
|
void 0,
|
|
545
|
-
|
|
546
|
-
|
|
575
|
+
import_typescript.default.factory.createToken(import_typescript.default.SyntaxKind.EqualsGreaterThanToken),
|
|
576
|
+
import_typescript.default.factory.createBlock(statements, true)
|
|
547
577
|
),
|
|
548
578
|
void 0,
|
|
549
579
|
[]
|
|
@@ -559,29 +589,29 @@ function transformFragment(state, children) {
|
|
|
559
589
|
const anchor = nextIdentifier(state, "_fragmentAnchor");
|
|
560
590
|
const statements = [];
|
|
561
591
|
appendChildren(state, statements, parent, children, anchor);
|
|
562
|
-
return
|
|
592
|
+
return import_typescript.default.factory.createCallExpression(
|
|
563
593
|
helperRef(state, "createFragment"),
|
|
564
594
|
void 0,
|
|
565
|
-
[
|
|
595
|
+
[import_typescript.default.factory.createArrowFunction(
|
|
566
596
|
void 0,
|
|
567
597
|
void 0,
|
|
568
598
|
[
|
|
569
|
-
|
|
570
|
-
|
|
599
|
+
import_typescript.default.factory.createParameterDeclaration(void 0, void 0, parent),
|
|
600
|
+
import_typescript.default.factory.createParameterDeclaration(void 0, void 0, anchor)
|
|
571
601
|
],
|
|
572
602
|
void 0,
|
|
573
|
-
|
|
574
|
-
|
|
603
|
+
import_typescript.default.factory.createToken(import_typescript.default.SyntaxKind.EqualsGreaterThanToken),
|
|
604
|
+
import_typescript.default.factory.createBlock(statements, true)
|
|
575
605
|
)]
|
|
576
606
|
);
|
|
577
607
|
}
|
|
578
608
|
__name(transformFragment, "transformFragment");
|
|
579
609
|
function transformResourceBoundary(state, node, attributes, children) {
|
|
580
610
|
const resource = getAttributeExpression(attributes, "resource");
|
|
581
|
-
if (!resource) throw new
|
|
611
|
+
if (!resource) throw new import_error.VobsError({ code: "VOBS_C002", layer: "compiler", message: "ResourceBoundary \u5FC5\u987B\u63D0\u4F9B resource \u5C5E\u6027", fix: "\u4E3A ResourceBoundary \u6DFB\u52A0 resource={resource}\u3002" });
|
|
582
612
|
const options = [
|
|
583
|
-
|
|
584
|
-
|
|
613
|
+
import_typescript.default.factory.createPropertyAssignment("resource", transformEmbeddedExpression(state, resource)),
|
|
614
|
+
import_typescript.default.factory.createPropertyAssignment("children", createBoundaryFactory(state, children))
|
|
585
615
|
];
|
|
586
616
|
appendBoundaryOptionalProperty(state, options, attributes, "loading");
|
|
587
617
|
appendBoundaryOptionalProperty(state, options, attributes, "empty");
|
|
@@ -591,34 +621,34 @@ function transformResourceBoundary(state, node, attributes, children) {
|
|
|
591
621
|
__name(transformResourceBoundary, "transformResourceBoundary");
|
|
592
622
|
function transformErrorBoundary(state, node, attributes, children) {
|
|
593
623
|
const fallback = getAttributeExpression(attributes, "fallback");
|
|
594
|
-
if (!fallback) throw new
|
|
624
|
+
if (!fallback) throw new import_error.VobsError({ code: "VOBS_C002", layer: "compiler", message: "ErrorBoundary \u5FC5\u987B\u63D0\u4F9B fallback \u5C5E\u6027", fix: "\u4E3A ErrorBoundary \u6DFB\u52A0 fallback={(error, retry) => ...}\u3002" });
|
|
595
625
|
return createBoundaryFragment(state, node, "insertErrorBoundary", [
|
|
596
|
-
|
|
597
|
-
|
|
626
|
+
import_typescript.default.factory.createPropertyAssignment("children", createBoundaryFactory(state, children)),
|
|
627
|
+
import_typescript.default.factory.createPropertyAssignment("fallback", transformEmbeddedExpression(state, fallback))
|
|
598
628
|
]);
|
|
599
629
|
}
|
|
600
630
|
__name(transformErrorBoundary, "transformErrorBoundary");
|
|
601
631
|
function transformAsyncBoundary(state, node, attributes, children) {
|
|
602
632
|
const promise = getAttributeExpression(attributes, "promise");
|
|
603
|
-
if (!promise) throw new
|
|
633
|
+
if (!promise) throw new import_error.VobsError({ code: "VOBS_C002", layer: "compiler", message: "AsyncBoundary \u5FC5\u987B\u63D0\u4F9B promise \u5C5E\u6027", fix: "\u4E3A AsyncBoundary \u6DFB\u52A0 promise={promise}\u3002" });
|
|
604
634
|
const options = [
|
|
605
|
-
|
|
606
|
-
|
|
635
|
+
import_typescript.default.factory.createPropertyAssignment("promise", transformEmbeddedExpression(state, promise)),
|
|
636
|
+
import_typescript.default.factory.createPropertyAssignment("children", createAsyncFactory(state, children))
|
|
607
637
|
];
|
|
608
638
|
appendBoundaryOptionalProperty(state, options, attributes, "loading");
|
|
609
639
|
appendBoundaryOptionalProperty(state, options, attributes, "fallback");
|
|
610
640
|
const resetKey = getAttributeExpression(attributes, "resetKey");
|
|
611
|
-
if (resetKey) options.push(
|
|
641
|
+
if (resetKey) options.push(import_typescript.default.factory.createPropertyAssignment("resetKey", createGetter(resetKey)));
|
|
612
642
|
return createBoundaryFragment(state, node, "insertAsyncBoundary", options);
|
|
613
643
|
}
|
|
614
644
|
__name(transformAsyncBoundary, "transformAsyncBoundary");
|
|
615
645
|
function transformProfiler(state, node, attributes, children) {
|
|
616
|
-
const idAttribute = attributes.properties.find((attribute) =>
|
|
617
|
-
const id = idAttribute &&
|
|
618
|
-
if (!id) throw new
|
|
646
|
+
const idAttribute = attributes.properties.find((attribute) => import_typescript.default.isJsxAttribute(attribute) && attribute.name.getText() === "id");
|
|
647
|
+
const id = idAttribute && import_typescript.default.isJsxAttribute(idAttribute) && idAttribute.initializer && import_typescript.default.isStringLiteral(idAttribute.initializer) ? import_typescript.default.factory.createStringLiteral(idAttribute.initializer.text) : idAttribute && import_typescript.default.isJsxAttribute(idAttribute) && idAttribute.initializer && import_typescript.default.isJsxExpression(idAttribute.initializer) ? idAttribute.initializer.expression : null;
|
|
648
|
+
if (!id) throw new import_error.VobsError({ code: "VOBS_C002", layer: "compiler", message: "Profiler \u5FC5\u987B\u63D0\u4F9B id \u5C5E\u6027", fix: '\u4E3A Profiler \u6DFB\u52A0 id="ComponentName"\u3002' });
|
|
619
649
|
const options = [
|
|
620
|
-
|
|
621
|
-
|
|
650
|
+
import_typescript.default.factory.createPropertyAssignment("id", transformEmbeddedExpression(state, id)),
|
|
651
|
+
import_typescript.default.factory.createPropertyAssignment("children", createBoundaryFactory(state, children))
|
|
622
652
|
];
|
|
623
653
|
appendBoundaryOptionalProperty(state, options, attributes, "onRender");
|
|
624
654
|
return createBoundaryFragment(state, node, "insertProfiler", options);
|
|
@@ -627,22 +657,22 @@ __name(transformProfiler, "transformProfiler");
|
|
|
627
657
|
function createBoundaryFragment(state, node, helper, options) {
|
|
628
658
|
const parent = nextIdentifier(state, "_boundaryParent");
|
|
629
659
|
const anchor = nextIdentifier(state, "_boundaryAnchor");
|
|
630
|
-
return
|
|
660
|
+
return import_typescript.default.factory.createCallExpression(
|
|
631
661
|
helperRef(state, "createFragment"),
|
|
632
662
|
void 0,
|
|
633
|
-
[
|
|
663
|
+
[import_typescript.default.factory.createArrowFunction(
|
|
634
664
|
void 0,
|
|
635
665
|
void 0,
|
|
636
666
|
[
|
|
637
|
-
|
|
638
|
-
|
|
667
|
+
import_typescript.default.factory.createParameterDeclaration(void 0, void 0, parent),
|
|
668
|
+
import_typescript.default.factory.createParameterDeclaration(void 0, void 0, anchor)
|
|
639
669
|
],
|
|
640
670
|
void 0,
|
|
641
|
-
|
|
642
|
-
|
|
671
|
+
import_typescript.default.factory.createToken(import_typescript.default.SyntaxKind.EqualsGreaterThanToken),
|
|
672
|
+
import_typescript.default.factory.createBlock([callStatement(state, helper, [
|
|
643
673
|
parent,
|
|
644
674
|
anchor,
|
|
645
|
-
|
|
675
|
+
import_typescript.default.factory.createObjectLiteralExpression(options, true)
|
|
646
676
|
], node)], true)
|
|
647
677
|
)]
|
|
648
678
|
);
|
|
@@ -650,27 +680,27 @@ function createBoundaryFragment(state, node, helper, options) {
|
|
|
650
680
|
__name(createBoundaryFragment, "createBoundaryFragment");
|
|
651
681
|
function createBoundaryFactory(state, children) {
|
|
652
682
|
const content = transformFragment(state, children);
|
|
653
|
-
return
|
|
683
|
+
return import_typescript.default.factory.createArrowFunction(
|
|
654
684
|
void 0,
|
|
655
685
|
void 0,
|
|
656
686
|
[],
|
|
657
687
|
void 0,
|
|
658
|
-
|
|
688
|
+
import_typescript.default.factory.createToken(import_typescript.default.SyntaxKind.EqualsGreaterThanToken),
|
|
659
689
|
content
|
|
660
690
|
);
|
|
661
691
|
}
|
|
662
692
|
__name(createBoundaryFactory, "createBoundaryFactory");
|
|
663
693
|
function createAsyncFactory(state, children) {
|
|
664
|
-
const value =
|
|
665
|
-
const expressionChild = children.length === 1 && children[0].kind ===
|
|
666
|
-
if (expressionChild &&
|
|
694
|
+
const value = import_typescript.default.factory.createIdentifier("value");
|
|
695
|
+
const expressionChild = children.length === 1 && children[0].kind === import_typescript.default.SyntaxKind.JsxExpression ? children[0].expression : void 0;
|
|
696
|
+
if (expressionChild && import_typescript.default.isArrowFunction(expressionChild)) {
|
|
667
697
|
const transformed = transformEmbeddedExpression(state, expressionChild);
|
|
668
698
|
return transformed;
|
|
669
699
|
}
|
|
670
700
|
const content = transformFragment(state, children);
|
|
671
|
-
return
|
|
672
|
-
|
|
673
|
-
], void 0,
|
|
701
|
+
return import_typescript.default.factory.createArrowFunction(void 0, void 0, [
|
|
702
|
+
import_typescript.default.factory.createParameterDeclaration(void 0, void 0, value)
|
|
703
|
+
], void 0, import_typescript.default.factory.createToken(import_typescript.default.SyntaxKind.EqualsGreaterThanToken), content);
|
|
674
704
|
}
|
|
675
705
|
__name(createAsyncFactory, "createAsyncFactory");
|
|
676
706
|
function appendBoundaryOptionalProperty(state, properties, attributes, name) {
|
|
@@ -678,14 +708,14 @@ function appendBoundaryOptionalProperty(state, properties, attributes, name) {
|
|
|
678
708
|
if (expression) {
|
|
679
709
|
const transformed = transformEmbeddedExpression(state, expression);
|
|
680
710
|
const value = isJsxExpression(unwrapExpression(expression)) ? createGetter(transformed) : transformed;
|
|
681
|
-
properties.push(
|
|
711
|
+
properties.push(import_typescript.default.factory.createPropertyAssignment(name, value));
|
|
682
712
|
}
|
|
683
713
|
}
|
|
684
714
|
__name(appendBoundaryOptionalProperty, "appendBoundaryOptionalProperty");
|
|
685
715
|
function getAttributeExpression(attributes, name) {
|
|
686
716
|
for (const attribute of attributes.properties) {
|
|
687
|
-
if (!
|
|
688
|
-
if (attribute.initializer &&
|
|
717
|
+
if (!import_typescript.default.isJsxAttribute(attribute) || attribute.name.getText() !== name) continue;
|
|
718
|
+
if (attribute.initializer && import_typescript.default.isJsxExpression(attribute.initializer)) {
|
|
689
719
|
return attribute.initializer.expression ?? null;
|
|
690
720
|
}
|
|
691
721
|
}
|
|
@@ -693,14 +723,14 @@ function getAttributeExpression(attributes, name) {
|
|
|
693
723
|
}
|
|
694
724
|
__name(getAttributeExpression, "getAttributeExpression");
|
|
695
725
|
function transformEmbeddedExpression(state, expression) {
|
|
696
|
-
const result =
|
|
726
|
+
const result = import_typescript.default.transform(expression, [(context) => (root) => {
|
|
697
727
|
const visit = /* @__PURE__ */ __name((node) => {
|
|
698
|
-
if (
|
|
728
|
+
if (import_typescript.default.isJsxElement(node) || import_typescript.default.isJsxSelfClosingElement(node) || import_typescript.default.isJsxFragment(node)) {
|
|
699
729
|
return transformJsxExpression(state, node);
|
|
700
730
|
}
|
|
701
|
-
return
|
|
731
|
+
return import_typescript.default.visitEachChild(node, visit, context);
|
|
702
732
|
}, "visit");
|
|
703
|
-
return
|
|
733
|
+
return import_typescript.default.visitNode(root, visit);
|
|
704
734
|
}]);
|
|
705
735
|
try {
|
|
706
736
|
return result.transformed[0];
|
|
@@ -710,20 +740,20 @@ function transformEmbeddedExpression(state, expression) {
|
|
|
710
740
|
}
|
|
711
741
|
__name(transformEmbeddedExpression, "transformEmbeddedExpression");
|
|
712
742
|
function isStaticElement(tagName, attributes, children) {
|
|
713
|
-
if (!
|
|
743
|
+
if (!import_typescript.default.isIdentifier(tagName) || !/^[a-z]/.test(tagName.text)) return false;
|
|
714
744
|
for (const attribute of attributes.properties) {
|
|
715
|
-
if (
|
|
716
|
-
if (!
|
|
745
|
+
if (import_typescript.default.isJsxSpreadAttribute(attribute)) return false;
|
|
746
|
+
if (!import_typescript.default.isJsxAttribute(attribute)) return false;
|
|
717
747
|
const name = attribute.name.getText();
|
|
718
748
|
if (name === "key" || name === "ref" || name.startsWith("on")) return false;
|
|
719
749
|
if (isPropertyAttribute(name)) return false;
|
|
720
750
|
const initializer = attribute.initializer;
|
|
721
|
-
if (initializer && !
|
|
751
|
+
if (initializer && !import_typescript.default.isStringLiteral(initializer)) return false;
|
|
722
752
|
}
|
|
723
753
|
for (const child of children) {
|
|
724
|
-
if (
|
|
725
|
-
if (
|
|
726
|
-
const nested =
|
|
754
|
+
if (import_typescript.default.isJsxText(child)) continue;
|
|
755
|
+
if (import_typescript.default.isJsxElement(child) || import_typescript.default.isJsxSelfClosingElement(child)) {
|
|
756
|
+
const nested = import_typescript.default.isJsxElement(child) ? { tagName: child.openingElement.tagName, attributes: child.openingElement.attributes, children: child.children } : { tagName: child.tagName, attributes: child.attributes, children: [] };
|
|
727
757
|
if (!isStaticElement(nested.tagName, nested.attributes, nested.children)) return false;
|
|
728
758
|
continue;
|
|
729
759
|
}
|
|
@@ -733,7 +763,7 @@ function isStaticElement(tagName, attributes, children) {
|
|
|
733
763
|
}
|
|
734
764
|
__name(isStaticElement, "isStaticElement");
|
|
735
765
|
function serializeStaticHtml(node) {
|
|
736
|
-
const { tagName, attributes, children } =
|
|
766
|
+
const { tagName, attributes, children } = import_typescript.default.isJsxElement(node) ? { tagName: node.openingElement.tagName, attributes: node.openingElement.attributes, children: node.children } : { tagName: node.tagName, attributes: node.attributes, children: [] };
|
|
737
767
|
return serializeStaticElement(tagName, attributes, children);
|
|
738
768
|
}
|
|
739
769
|
__name(serializeStaticHtml, "serializeStaticHtml");
|
|
@@ -741,25 +771,25 @@ function serializeStaticElement(tagName, attributes, children) {
|
|
|
741
771
|
const name = tagName.getText();
|
|
742
772
|
let html = `<${name}`;
|
|
743
773
|
for (const attribute of attributes.properties) {
|
|
744
|
-
if (!
|
|
774
|
+
if (!import_typescript.default.isJsxAttribute(attribute)) continue;
|
|
745
775
|
const attributeName = attribute.name.getText() === "className" ? "class" : attribute.name.getText();
|
|
746
776
|
const initializer = attribute.initializer;
|
|
747
777
|
if (!initializer) {
|
|
748
778
|
html += ` ${attributeName}=""`;
|
|
749
779
|
continue;
|
|
750
780
|
}
|
|
751
|
-
if (
|
|
781
|
+
if (import_typescript.default.isStringLiteral(initializer)) {
|
|
752
782
|
html += ` ${attributeName}="${escapeHtmlAttribute(initializer.text)}"`;
|
|
753
783
|
}
|
|
754
784
|
}
|
|
755
785
|
html += ">";
|
|
756
786
|
for (const child of children) {
|
|
757
|
-
if (
|
|
787
|
+
if (import_typescript.default.isJsxText(child)) {
|
|
758
788
|
const text = child.text.replace(/\s+/g, " ").trimStart();
|
|
759
789
|
if (text.trim()) html += escapeHtmlText(text);
|
|
760
790
|
continue;
|
|
761
791
|
}
|
|
762
|
-
if (
|
|
792
|
+
if (import_typescript.default.isJsxElement(child)) {
|
|
763
793
|
html += serializeStaticElement(
|
|
764
794
|
child.openingElement.tagName,
|
|
765
795
|
child.openingElement.attributes,
|
|
@@ -767,7 +797,7 @@ function serializeStaticElement(tagName, attributes, children) {
|
|
|
767
797
|
);
|
|
768
798
|
continue;
|
|
769
799
|
}
|
|
770
|
-
if (
|
|
800
|
+
if (import_typescript.default.isJsxSelfClosingElement(child)) {
|
|
771
801
|
html += serializeStaticElement(child.tagName, child.attributes, []);
|
|
772
802
|
}
|
|
773
803
|
}
|
|
@@ -793,103 +823,103 @@ function registerTemplate(state, html) {
|
|
|
793
823
|
__name(registerTemplate, "registerTemplate");
|
|
794
824
|
function createTemplateDeclarations(state) {
|
|
795
825
|
return [...state.templates.entries()].map(
|
|
796
|
-
([html, identifier]) =>
|
|
797
|
-
|
|
826
|
+
([html, identifier]) => import_typescript.default.factory.createVariableStatement(void 0, import_typescript.default.factory.createVariableDeclarationList([
|
|
827
|
+
import_typescript.default.factory.createVariableDeclaration(identifier, void 0, void 0, import_typescript.default.factory.createCallExpression(
|
|
798
828
|
helperRef(state, "createTemplate"),
|
|
799
829
|
void 0,
|
|
800
|
-
[
|
|
830
|
+
[import_typescript.default.factory.createStringLiteral(html)]
|
|
801
831
|
))
|
|
802
|
-
],
|
|
832
|
+
], import_typescript.default.NodeFlags.Const))
|
|
803
833
|
);
|
|
804
834
|
}
|
|
805
835
|
__name(createTemplateDeclarations, "createTemplateDeclarations");
|
|
806
836
|
function appendAttributes(state, statements, element, attributes) {
|
|
807
837
|
const staticProps = [];
|
|
808
|
-
const hasSpread = attributes.properties.some((attribute) =>
|
|
838
|
+
const hasSpread = attributes.properties.some((attribute) => import_typescript.default.isJsxSpreadAttribute(attribute));
|
|
809
839
|
for (const attribute of attributes.properties) {
|
|
810
|
-
if (
|
|
840
|
+
if (import_typescript.default.isJsxSpreadAttribute(attribute)) {
|
|
811
841
|
statements.push(callStatement(state, "spreadProps", [element, transformEmbeddedExpression(state, attribute.expression)], attribute));
|
|
812
842
|
continue;
|
|
813
843
|
}
|
|
814
|
-
if (!
|
|
844
|
+
if (!import_typescript.default.isJsxAttribute(attribute)) continue;
|
|
815
845
|
const name = attribute.name.getText();
|
|
816
846
|
if (name === "key") continue;
|
|
817
847
|
if (name === "ref") {
|
|
818
848
|
const initializer2 = attribute.initializer;
|
|
819
|
-
if (initializer2 &&
|
|
849
|
+
if (initializer2 && import_typescript.default.isJsxExpression(initializer2) && initializer2.expression) {
|
|
820
850
|
statements.push(callStatement(state, "setRef", [element, transformEmbeddedExpression(state, initializer2.expression)], attribute));
|
|
821
851
|
}
|
|
822
852
|
continue;
|
|
823
853
|
}
|
|
824
854
|
const initializer = attribute.initializer;
|
|
825
|
-
if (name.startsWith("on") && initializer &&
|
|
855
|
+
if (name.startsWith("on") && initializer && import_typescript.default.isJsxExpression(initializer) && initializer.expression) {
|
|
826
856
|
statements.push(callStatement(state, "addEventListener", [
|
|
827
857
|
element,
|
|
828
|
-
|
|
858
|
+
import_typescript.default.factory.createStringLiteral(name.slice(2).toLowerCase()),
|
|
829
859
|
initializer.expression
|
|
830
860
|
], attribute));
|
|
831
861
|
continue;
|
|
832
862
|
}
|
|
833
863
|
if (!initializer) {
|
|
834
864
|
if (hasSpread) {
|
|
835
|
-
statements.push(callStatement(state, isPropertyAttribute(name) ? "setProperty" : "setAttribute", [element,
|
|
865
|
+
statements.push(callStatement(state, isPropertyAttribute(name) ? "setProperty" : "setAttribute", [element, import_typescript.default.factory.createStringLiteral(isPropertyAttribute(name) ? name : name === "className" ? "class" : name), isPropertyAttribute(name) ? import_typescript.default.factory.createTrue() : import_typescript.default.factory.createStringLiteral("")], attribute));
|
|
836
866
|
continue;
|
|
837
867
|
}
|
|
838
|
-
if (isPropertyAttribute(name)) staticProps.push(createStaticProperty(name,
|
|
839
|
-
else staticProps.push(createStaticProperty(name === "className" ? "class" : name,
|
|
868
|
+
if (isPropertyAttribute(name)) staticProps.push(createStaticProperty(name, import_typescript.default.factory.createTrue()));
|
|
869
|
+
else staticProps.push(createStaticProperty(name === "className" ? "class" : name, import_typescript.default.factory.createStringLiteral("")));
|
|
840
870
|
continue;
|
|
841
871
|
}
|
|
842
|
-
if (
|
|
872
|
+
if (import_typescript.default.isStringLiteral(initializer)) {
|
|
843
873
|
if (hasSpread) {
|
|
844
|
-
statements.push(callStatement(state, isPropertyAttribute(name) ? "setProperty" : "setAttribute", [element,
|
|
874
|
+
statements.push(callStatement(state, isPropertyAttribute(name) ? "setProperty" : "setAttribute", [element, import_typescript.default.factory.createStringLiteral(isPropertyAttribute(name) ? name : name === "className" ? "class" : name), import_typescript.default.factory.createStringLiteral(initializer.text)], attribute));
|
|
845
875
|
continue;
|
|
846
876
|
}
|
|
847
877
|
staticProps.push(createStaticProperty(
|
|
848
878
|
isPropertyAttribute(name) ? name : name === "className" ? "class" : name,
|
|
849
|
-
|
|
879
|
+
import_typescript.default.factory.createStringLiteral(initializer.text)
|
|
850
880
|
));
|
|
851
881
|
continue;
|
|
852
882
|
}
|
|
853
883
|
const attributeName = name === "className" ? "class" : name;
|
|
854
884
|
const propertyAttribute = isPropertyAttribute(name);
|
|
855
|
-
if (
|
|
885
|
+
if (import_typescript.default.isJsxExpression(initializer) && initializer.expression) {
|
|
856
886
|
statements.push(callStatement(state, propertyAttribute ? "bindProperty" : "bindAttribute", [
|
|
857
887
|
element,
|
|
858
|
-
|
|
888
|
+
import_typescript.default.factory.createStringLiteral(propertyAttribute ? name : attributeName),
|
|
859
889
|
createGetter(initializer.expression)
|
|
860
890
|
], attribute));
|
|
861
891
|
}
|
|
862
892
|
}
|
|
863
893
|
if (staticProps.length) statements.splice(1, 0, callStatement(state, "setStaticProps", [
|
|
864
894
|
element,
|
|
865
|
-
|
|
895
|
+
import_typescript.default.factory.createObjectLiteralExpression(staticProps, true)
|
|
866
896
|
], attributes));
|
|
867
897
|
}
|
|
868
898
|
__name(appendAttributes, "appendAttributes");
|
|
869
899
|
function createStaticProperty(name, value) {
|
|
870
|
-
return
|
|
900
|
+
return import_typescript.default.factory.createPropertyAssignment(import_typescript.default.factory.createStringLiteral(name), value);
|
|
871
901
|
}
|
|
872
902
|
__name(createStaticProperty, "createStaticProperty");
|
|
873
903
|
function isPropertyAttribute(name) {
|
|
874
904
|
return name === "value" || name === "checked" || name === "selected" || name === "disabled" || name === "multiple" || name === "readOnly" || name === "required" || name === "autofocus" || name === "hidden" || name === "tabIndex";
|
|
875
905
|
}
|
|
876
906
|
__name(isPropertyAttribute, "isPropertyAttribute");
|
|
877
|
-
function appendChildren(state, statements, element, children, anchor =
|
|
907
|
+
function appendChildren(state, statements, element, children, anchor = import_typescript.default.factory.createNull()) {
|
|
878
908
|
for (const child of children) {
|
|
879
|
-
if (
|
|
909
|
+
if (import_typescript.default.isJsxText(child)) {
|
|
880
910
|
const text = child.text.replace(/\s+/g, " ").trimStart();
|
|
881
911
|
if (text.trim()) {
|
|
882
912
|
statements.push(callStatement(state, "insertBefore", [
|
|
883
913
|
element,
|
|
884
|
-
|
|
885
|
-
|
|
914
|
+
import_typescript.default.factory.createCallExpression(helperRef(state, "createText"), void 0, [
|
|
915
|
+
import_typescript.default.factory.createStringLiteral(text)
|
|
886
916
|
]),
|
|
887
917
|
anchor
|
|
888
918
|
], child));
|
|
889
919
|
}
|
|
890
920
|
continue;
|
|
891
921
|
}
|
|
892
|
-
if (
|
|
922
|
+
if (import_typescript.default.isJsxElement(child) || import_typescript.default.isJsxSelfClosingElement(child) || import_typescript.default.isJsxFragment(child)) {
|
|
893
923
|
statements.push(callStatement(state, "insertBefore", [
|
|
894
924
|
element,
|
|
895
925
|
transformJsxExpression(state, child),
|
|
@@ -897,7 +927,7 @@ function appendChildren(state, statements, element, children, anchor = ts__defau
|
|
|
897
927
|
], child));
|
|
898
928
|
continue;
|
|
899
929
|
}
|
|
900
|
-
if (child.kind ===
|
|
930
|
+
if (child.kind === import_typescript.default.SyntaxKind.JsxExpression) {
|
|
901
931
|
const expression = child.expression;
|
|
902
932
|
if (!expression) continue;
|
|
903
933
|
const list = transformListExpression(state, element, expression, anchor);
|
|
@@ -910,9 +940,9 @@ function appendChildren(state, statements, element, children, anchor = ts__defau
|
|
|
910
940
|
statements.push(callStatement(state, "insertDynamic", [element, anchor, dynamic], child));
|
|
911
941
|
continue;
|
|
912
942
|
}
|
|
913
|
-
if (!containsJsx(expression) && !
|
|
943
|
+
if (!containsJsx(expression) && !import_typescript.default.isIdentifier(expression)) {
|
|
914
944
|
const textId = nextIdentifier(state, "_text");
|
|
915
|
-
statements.push(createConstStatement(state, textId,
|
|
945
|
+
statements.push(createConstStatement(state, textId, import_typescript.default.factory.createCallExpression(helperRef(state, "createText"), void 0, [import_typescript.default.factory.createStringLiteral("")]), child));
|
|
916
946
|
statements.push(callStatement(state, "insertBefore", [element, textId, anchor], child));
|
|
917
947
|
statements.push(callStatement(state, "bindText", [textId, createGetter(expression)], child));
|
|
918
948
|
continue;
|
|
@@ -926,18 +956,18 @@ __name(appendChildren, "appendChildren");
|
|
|
926
956
|
function createComponentProps(state, attributes, children) {
|
|
927
957
|
const properties = [];
|
|
928
958
|
for (const attribute of attributes.properties) {
|
|
929
|
-
if (
|
|
930
|
-
properties.push(
|
|
959
|
+
if (import_typescript.default.isJsxSpreadAttribute(attribute)) {
|
|
960
|
+
properties.push(import_typescript.default.factory.createSpreadAssignment(attribute.expression));
|
|
931
961
|
continue;
|
|
932
962
|
}
|
|
933
963
|
const name = propertyName(attribute.name.getText());
|
|
934
964
|
if (attribute.name.getText() === "key") continue;
|
|
935
965
|
const initializer = attribute.initializer;
|
|
936
966
|
if (!initializer) {
|
|
937
|
-
properties.push(
|
|
938
|
-
} else if (
|
|
939
|
-
properties.push(
|
|
940
|
-
} else if (
|
|
967
|
+
properties.push(import_typescript.default.factory.createPropertyAssignment(name, import_typescript.default.factory.createTrue()));
|
|
968
|
+
} else if (import_typescript.default.isStringLiteral(initializer)) {
|
|
969
|
+
properties.push(import_typescript.default.factory.createPropertyAssignment(name, import_typescript.default.factory.createStringLiteral(initializer.text)));
|
|
970
|
+
} else if (import_typescript.default.isJsxExpression(initializer) && initializer.expression) {
|
|
941
971
|
properties.push(createGetterProperty(name, transformEmbeddedExpression(state, initializer.expression)));
|
|
942
972
|
}
|
|
943
973
|
}
|
|
@@ -945,43 +975,43 @@ function createComponentProps(state, attributes, children) {
|
|
|
945
975
|
if (childExpressions.length === 1) {
|
|
946
976
|
properties.push(createGetterProperty("children", childExpressions[0]));
|
|
947
977
|
} else if (childExpressions.length > 1) {
|
|
948
|
-
properties.push(createGetterProperty("children",
|
|
978
|
+
properties.push(createGetterProperty("children", import_typescript.default.factory.createArrayLiteralExpression(childExpressions)));
|
|
949
979
|
}
|
|
950
|
-
return
|
|
980
|
+
return import_typescript.default.factory.createObjectLiteralExpression(properties, true);
|
|
951
981
|
}
|
|
952
982
|
__name(createComponentProps, "createComponentProps");
|
|
953
983
|
function createSourceLocation(node) {
|
|
954
984
|
const sourceFile = node.getSourceFile();
|
|
955
985
|
const position = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
|
|
956
|
-
return
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
986
|
+
return import_typescript.default.factory.createObjectLiteralExpression([
|
|
987
|
+
import_typescript.default.factory.createPropertyAssignment("file", import_typescript.default.factory.createStringLiteral(sourceFile.fileName)),
|
|
988
|
+
import_typescript.default.factory.createPropertyAssignment("line", import_typescript.default.factory.createNumericLiteral(position.line + 1)),
|
|
989
|
+
import_typescript.default.factory.createPropertyAssignment("column", import_typescript.default.factory.createNumericLiteral(position.character + 1))
|
|
960
990
|
], true);
|
|
961
991
|
}
|
|
962
992
|
__name(createSourceLocation, "createSourceLocation");
|
|
963
993
|
function transformDynamicExpression(state, expression) {
|
|
964
|
-
if (
|
|
994
|
+
if (import_typescript.default.isBinaryExpression(expression) && expression.operatorToken.kind === import_typescript.default.SyntaxKind.AmpersandAmpersandToken) {
|
|
965
995
|
const right = unwrapExpression(expression.right);
|
|
966
996
|
if (!isJsxExpression(right)) return null;
|
|
967
|
-
return createGetter(
|
|
997
|
+
return createGetter(import_typescript.default.factory.createConditionalExpression(
|
|
968
998
|
expression.left,
|
|
969
|
-
|
|
999
|
+
import_typescript.default.factory.createToken(import_typescript.default.SyntaxKind.QuestionToken),
|
|
970
1000
|
transformJsxExpression(state, right),
|
|
971
|
-
|
|
972
|
-
|
|
1001
|
+
import_typescript.default.factory.createToken(import_typescript.default.SyntaxKind.ColonToken),
|
|
1002
|
+
import_typescript.default.factory.createNull()
|
|
973
1003
|
));
|
|
974
1004
|
}
|
|
975
|
-
if (
|
|
1005
|
+
if (import_typescript.default.isConditionalExpression(expression)) {
|
|
976
1006
|
const whenTrue = transformDynamicBranch(state, expression.whenTrue);
|
|
977
1007
|
const whenFalse = transformDynamicBranch(state, expression.whenFalse);
|
|
978
1008
|
if (!whenTrue && !whenFalse) return null;
|
|
979
|
-
return createGetter(
|
|
1009
|
+
return createGetter(import_typescript.default.factory.createConditionalExpression(
|
|
980
1010
|
expression.condition,
|
|
981
|
-
|
|
982
|
-
whenTrue ??
|
|
983
|
-
|
|
984
|
-
whenFalse ??
|
|
1011
|
+
import_typescript.default.factory.createToken(import_typescript.default.SyntaxKind.QuestionToken),
|
|
1012
|
+
whenTrue ?? import_typescript.default.factory.createNull(),
|
|
1013
|
+
import_typescript.default.factory.createToken(import_typescript.default.SyntaxKind.ColonToken),
|
|
1014
|
+
whenFalse ?? import_typescript.default.factory.createNull()
|
|
985
1015
|
));
|
|
986
1016
|
}
|
|
987
1017
|
return null;
|
|
@@ -990,17 +1020,17 @@ __name(transformDynamicExpression, "transformDynamicExpression");
|
|
|
990
1020
|
function transformDynamicBranch(state, expression) {
|
|
991
1021
|
const branch = unwrapExpression(expression);
|
|
992
1022
|
if (isJsxExpression(branch)) return transformJsxExpression(state, branch);
|
|
993
|
-
if (branch.kind ===
|
|
1023
|
+
if (branch.kind === import_typescript.default.SyntaxKind.NullKeyword || branch.kind === import_typescript.default.SyntaxKind.FalseKeyword) return branch;
|
|
994
1024
|
return null;
|
|
995
1025
|
}
|
|
996
1026
|
__name(transformDynamicBranch, "transformDynamicBranch");
|
|
997
1027
|
function transformListExpression(state, parent, expression, anchor) {
|
|
998
|
-
if (!
|
|
999
|
-
if (!
|
|
1028
|
+
if (!import_typescript.default.isCallExpression(expression) || expression.arguments.length !== 1) return null;
|
|
1029
|
+
if (!import_typescript.default.isPropertyAccessExpression(expression.expression) || expression.expression.name.text !== "map") return null;
|
|
1000
1030
|
const callback = expression.arguments[0];
|
|
1001
|
-
if (!
|
|
1031
|
+
if (!import_typescript.default.isArrowFunction(callback) && !import_typescript.default.isFunctionExpression(callback)) return null;
|
|
1002
1032
|
const body = unwrapExpression(callback.body);
|
|
1003
|
-
if (!isJsxExpression(body) ||
|
|
1033
|
+
if (!isJsxExpression(body) || import_typescript.default.isJsxFragment(body)) return null;
|
|
1004
1034
|
const key = findKeyExpression(body);
|
|
1005
1035
|
const renderItem = transformListCallback(callback, transformJsxExpression(state, body));
|
|
1006
1036
|
const args = [
|
|
@@ -1014,8 +1044,8 @@ function transformListExpression(state, parent, expression, anchor) {
|
|
|
1014
1044
|
}
|
|
1015
1045
|
__name(transformListExpression, "transformListExpression");
|
|
1016
1046
|
function transformListCallback(callback, body) {
|
|
1017
|
-
if (
|
|
1018
|
-
return
|
|
1047
|
+
if (import_typescript.default.isArrowFunction(callback)) {
|
|
1048
|
+
return import_typescript.default.factory.updateArrowFunction(
|
|
1019
1049
|
callback,
|
|
1020
1050
|
callback.modifiers,
|
|
1021
1051
|
callback.typeParameters,
|
|
@@ -1025,7 +1055,7 @@ function transformListCallback(callback, body) {
|
|
|
1025
1055
|
body
|
|
1026
1056
|
);
|
|
1027
1057
|
}
|
|
1028
|
-
return
|
|
1058
|
+
return import_typescript.default.factory.updateFunctionExpression(
|
|
1029
1059
|
callback,
|
|
1030
1060
|
callback.modifiers,
|
|
1031
1061
|
callback.asteriskToken,
|
|
@@ -1033,26 +1063,26 @@ function transformListCallback(callback, body) {
|
|
|
1033
1063
|
callback.typeParameters,
|
|
1034
1064
|
callback.parameters,
|
|
1035
1065
|
callback.type,
|
|
1036
|
-
|
|
1066
|
+
import_typescript.default.factory.createBlock([import_typescript.default.factory.createReturnStatement(body)], true)
|
|
1037
1067
|
);
|
|
1038
1068
|
}
|
|
1039
1069
|
__name(transformListCallback, "transformListCallback");
|
|
1040
1070
|
function createKeyCallback(callback, key) {
|
|
1041
|
-
return
|
|
1071
|
+
return import_typescript.default.factory.createArrowFunction(
|
|
1042
1072
|
void 0,
|
|
1043
1073
|
void 0,
|
|
1044
1074
|
callback.parameters,
|
|
1045
1075
|
void 0,
|
|
1046
|
-
|
|
1076
|
+
import_typescript.default.factory.createToken(import_typescript.default.SyntaxKind.EqualsGreaterThanToken),
|
|
1047
1077
|
key
|
|
1048
1078
|
);
|
|
1049
1079
|
}
|
|
1050
1080
|
__name(createKeyCallback, "createKeyCallback");
|
|
1051
1081
|
function findKeyExpression(node) {
|
|
1052
|
-
const attributes =
|
|
1082
|
+
const attributes = import_typescript.default.isJsxElement(node) ? node.openingElement.attributes : node.attributes;
|
|
1053
1083
|
for (const attribute of attributes.properties) {
|
|
1054
|
-
if (!
|
|
1055
|
-
if (attribute.initializer &&
|
|
1084
|
+
if (!import_typescript.default.isJsxAttribute(attribute) || attribute.name.getText() !== "key") continue;
|
|
1085
|
+
if (attribute.initializer && import_typescript.default.isJsxExpression(attribute.initializer)) {
|
|
1056
1086
|
return attribute.initializer.expression ?? null;
|
|
1057
1087
|
}
|
|
1058
1088
|
}
|
|
@@ -1060,18 +1090,18 @@ function findKeyExpression(node) {
|
|
|
1060
1090
|
}
|
|
1061
1091
|
__name(findKeyExpression, "findKeyExpression");
|
|
1062
1092
|
function unwrapExpression(node) {
|
|
1063
|
-
return
|
|
1093
|
+
return import_typescript.default.isParenthesizedExpression(node) ? node.expression : node;
|
|
1064
1094
|
}
|
|
1065
1095
|
__name(unwrapExpression, "unwrapExpression");
|
|
1066
1096
|
function childToComponentExpression(state, child) {
|
|
1067
|
-
if (
|
|
1097
|
+
if (import_typescript.default.isJsxText(child)) {
|
|
1068
1098
|
const text = child.text.replace(/\s+/g, " ").trim();
|
|
1069
|
-
return text ? [
|
|
1099
|
+
return text ? [import_typescript.default.factory.createStringLiteral(text)] : [];
|
|
1070
1100
|
}
|
|
1071
|
-
if (
|
|
1101
|
+
if (import_typescript.default.isJsxElement(child) || import_typescript.default.isJsxSelfClosingElement(child) || import_typescript.default.isJsxFragment(child)) {
|
|
1072
1102
|
return [transformJsxExpression(state, child)];
|
|
1073
1103
|
}
|
|
1074
|
-
if (child.kind ===
|
|
1104
|
+
if (child.kind === import_typescript.default.SyntaxKind.JsxExpression) {
|
|
1075
1105
|
const expression = child.expression;
|
|
1076
1106
|
return expression ? [transformEmbeddedExpression(state, expression)] : [];
|
|
1077
1107
|
}
|
|
@@ -1079,43 +1109,43 @@ function childToComponentExpression(state, child) {
|
|
|
1079
1109
|
}
|
|
1080
1110
|
__name(childToComponentExpression, "childToComponentExpression");
|
|
1081
1111
|
function propertyName(name) {
|
|
1082
|
-
return /^[$A-Z_a-z][$\w]*$/u.test(name) ?
|
|
1112
|
+
return /^[$A-Z_a-z][$\w]*$/u.test(name) ? import_typescript.default.factory.createIdentifier(name) : import_typescript.default.factory.createStringLiteral(name);
|
|
1083
1113
|
}
|
|
1084
1114
|
__name(propertyName, "propertyName");
|
|
1085
1115
|
function createGetter(expression) {
|
|
1086
|
-
return
|
|
1116
|
+
return import_typescript.default.factory.createArrowFunction(
|
|
1087
1117
|
void 0,
|
|
1088
1118
|
void 0,
|
|
1089
1119
|
[],
|
|
1090
1120
|
void 0,
|
|
1091
|
-
|
|
1121
|
+
import_typescript.default.factory.createToken(import_typescript.default.SyntaxKind.EqualsGreaterThanToken),
|
|
1092
1122
|
expression
|
|
1093
1123
|
);
|
|
1094
1124
|
}
|
|
1095
1125
|
__name(createGetter, "createGetter");
|
|
1096
1126
|
function createGetterProperty(name, expression) {
|
|
1097
|
-
return
|
|
1127
|
+
return import_typescript.default.factory.createGetAccessorDeclaration(
|
|
1098
1128
|
void 0,
|
|
1099
1129
|
typeof name === "string" ? propertyName(name) : name,
|
|
1100
1130
|
[],
|
|
1101
1131
|
void 0,
|
|
1102
|
-
|
|
1132
|
+
import_typescript.default.factory.createBlock([import_typescript.default.factory.createReturnStatement(expression)], true)
|
|
1103
1133
|
);
|
|
1104
1134
|
}
|
|
1105
1135
|
__name(createGetterProperty, "createGetterProperty");
|
|
1106
1136
|
function callStatement(state, name, args, source) {
|
|
1107
|
-
const statement =
|
|
1108
|
-
|
|
1137
|
+
const statement = import_typescript.default.factory.createExpressionStatement(
|
|
1138
|
+
import_typescript.default.factory.createCallExpression(helperRef(state, name), void 0, args)
|
|
1109
1139
|
);
|
|
1110
1140
|
return source ? tagStatement(state, statement, source) : statement;
|
|
1111
1141
|
}
|
|
1112
1142
|
__name(callStatement, "callStatement");
|
|
1113
1143
|
function createConstStatement(state, name, initializer, source) {
|
|
1114
|
-
const statement =
|
|
1144
|
+
const statement = import_typescript.default.factory.createVariableStatement(
|
|
1115
1145
|
void 0,
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
],
|
|
1146
|
+
import_typescript.default.factory.createVariableDeclarationList([
|
|
1147
|
+
import_typescript.default.factory.createVariableDeclaration(name, void 0, void 0, initializer)
|
|
1148
|
+
], import_typescript.default.NodeFlags.Const)
|
|
1119
1149
|
);
|
|
1120
1150
|
return source ? tagStatement(state, statement, source) : statement;
|
|
1121
1151
|
}
|
|
@@ -1138,12 +1168,13 @@ function nextIdentifier(state, prefix) {
|
|
|
1138
1168
|
do {
|
|
1139
1169
|
name = `${prefix}${state.generatedId++}`;
|
|
1140
1170
|
} while (state.takenNames.has(name));
|
|
1141
|
-
return
|
|
1171
|
+
return import_typescript.default.factory.createIdentifier(name);
|
|
1142
1172
|
}
|
|
1143
1173
|
__name(nextIdentifier, "nextIdentifier");
|
|
1144
|
-
|
|
1145
|
-
exports
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1174
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1175
|
+
0 && (module.exports = {
|
|
1176
|
+
compile,
|
|
1177
|
+
compileWithSourceMap,
|
|
1178
|
+
createCompiler
|
|
1179
|
+
});
|
|
1149
1180
|
//# sourceMappingURL=compile.cjs.map
|