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