@reckona/mreact-compiler 0.0.96 → 0.0.98
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/diagnostics.d.ts +1 -0
- package/dist/diagnostics.d.ts.map +1 -1
- package/dist/diagnostics.js +8 -0
- package/dist/diagnostics.js.map +1 -1
- package/dist/emit-client.js +14 -9
- package/dist/emit-client.js.map +1 -1
- package/dist/emit-compat.js +5 -1
- package/dist/emit-compat.js.map +1 -1
- package/dist/emit-server-stream.d.ts.map +1 -1
- package/dist/emit-server-stream.js +70 -6
- package/dist/emit-server-stream.js.map +1 -1
- package/dist/emit-server.d.ts.map +1 -1
- package/dist/emit-server.js +69 -13
- package/dist/emit-server.js.map +1 -1
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +7 -4
- package/dist/internal.js.map +1 -1
- package/dist/ir.d.ts +1 -0
- package/dist/ir.d.ts.map +1 -1
- package/dist/ir.js.map +1 -1
- package/dist/oxc-child-analysis.d.ts.map +1 -1
- package/dist/oxc-child-analysis.js +44 -10
- package/dist/oxc-child-analysis.js.map +1 -1
- package/dist/oxc-component-detection.d.ts +5 -2
- package/dist/oxc-component-detection.d.ts.map +1 -1
- package/dist/oxc-component-detection.js +80 -3
- package/dist/oxc-component-detection.js.map +1 -1
- package/dist/oxc-component-props.d.ts +1 -1
- package/dist/oxc-component-props.d.ts.map +1 -1
- package/dist/oxc-component-props.js +1 -1
- package/dist/oxc-component-props.js.map +1 -1
- package/dist/oxc-component-references.d.ts.map +1 -1
- package/dist/oxc-component-references.js +247 -12
- package/dist/oxc-component-references.js.map +1 -1
- package/dist/oxc-runtime-emit.d.ts.map +1 -1
- package/dist/oxc-runtime-emit.js +10 -2
- package/dist/oxc-runtime-emit.js.map +1 -1
- package/dist/oxc.d.ts.map +1 -1
- package/dist/oxc.js +109 -20
- package/dist/oxc.js.map +1 -1
- package/dist/transform.js +29 -11
- package/dist/transform.js.map +1 -1
- package/package.json +2 -2
- package/src/diagnostics.ts +10 -0
- package/src/emit-client.ts +20 -10
- package/src/emit-compat.ts +6 -1
- package/src/emit-server-stream.ts +96 -6
- package/src/emit-server.ts +93 -29
- package/src/internal.ts +9 -4
- package/src/ir.ts +1 -0
- package/src/oxc-child-analysis.ts +66 -21
- package/src/oxc-component-detection.ts +145 -2
- package/src/oxc-component-props.ts +2 -1
- package/src/oxc-component-references.ts +366 -11
- package/src/oxc-runtime-emit.ts +12 -2
- package/src/oxc.ts +167 -5
- package/src/transform.ts +42 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emit-server.d.ts","sourceRoot":"","sources":["../src/emit-server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAKV,QAAQ,EACT,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"emit-server.d.ts","sourceRoot":"","sources":["../src/emit-server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAKV,QAAQ,EACT,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAkBrE,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,aAAa,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,iBAAiB;IAChC,iBAAiB,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACpC,MAAM,CAAC,EAAE,mBAAmB,GAAG,SAAS,CAAC;IACzC,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AASD,wBAAgB,UAAU,CACxB,EAAE,EAAE,QAAQ,EACZ,OAAO,GAAE,iBAAsB,GAC9B,UAAU,CA8GZ"}
|
package/dist/emit-server.js
CHANGED
|
@@ -2,7 +2,7 @@ import { emitEscapeHtmlHelper } from "./emit-escape-helper.js";
|
|
|
2
2
|
import { createCodeBuilder } from "./emit-code-builder.js";
|
|
3
3
|
import { escapeHtmlAttribute as escapeHtml } from "@reckona/mreact-shared/html-escape";
|
|
4
4
|
import { htmlAttributeName, isDangerousHtmlAttribute, isStaticUrlValueUnsafe, isUrlAttribute, parseStaticStyleObjectLiteral, parseStyleLiteralValue, simpleSideEffectFreeExpression, } from "./emit-server-shared.js";
|
|
5
|
-
import { oxcServerStringReactNodeRenderHelperPlaceholder } from "./oxc-runtime-emit.js";
|
|
5
|
+
import { emitOxcCompatObjectChildren, oxcServerStringReactNodeRenderHelperPlaceholder, } from "./oxc-runtime-emit.js";
|
|
6
6
|
// Module-local handle to the URL-safety helper name for the current emit
|
|
7
7
|
// call. Used by deeply-nested attribute emitters to avoid threading the
|
|
8
8
|
// name through every signature. Reset at the top of `emitServer`.
|
|
@@ -189,30 +189,43 @@ function collectHtmlStatements(node, outVar, escapeHelperName, escapeBatchHelper
|
|
|
189
189
|
return [`${outVar} += ${escapeHelperName}(${node.code});`];
|
|
190
190
|
}
|
|
191
191
|
if (node.kind === "conditional") {
|
|
192
|
+
const conditionCode = node.conditionValueName ?? node.conditionCode;
|
|
192
193
|
const whenTrueStatements = node.whenTrue.flatMap((child) => collectHtmlStatements(child, outVar, escapeHelperName, escapeBatchHelperName, asyncComponentNames, dynamicAttributes, contextProviderHelperName, contextConsumerHelperName, reactNodeRenderHelperName));
|
|
193
194
|
const whenFalseStatements = node.whenFalse.flatMap((child) => collectHtmlStatements(child, outVar, escapeHelperName, escapeBatchHelperName, asyncComponentNames, dynamicAttributes, contextProviderHelperName, contextConsumerHelperName, reactNodeRenderHelperName));
|
|
194
195
|
if (whenTrueStatements.length === 0 && whenFalseStatements.length === 0) {
|
|
195
196
|
return [];
|
|
196
197
|
}
|
|
198
|
+
let statements;
|
|
197
199
|
if (whenFalseStatements.length === 0) {
|
|
198
|
-
|
|
199
|
-
`if (${
|
|
200
|
+
statements = [
|
|
201
|
+
`if (${conditionCode}) {`,
|
|
200
202
|
...whenTrueStatements.map((statement) => ` ${statement}`),
|
|
201
203
|
`}`,
|
|
202
204
|
];
|
|
203
205
|
}
|
|
204
|
-
if (whenTrueStatements.length === 0) {
|
|
205
|
-
|
|
206
|
-
`if (!(${
|
|
206
|
+
else if (whenTrueStatements.length === 0) {
|
|
207
|
+
statements = [
|
|
208
|
+
`if (!(${conditionCode})) {`,
|
|
209
|
+
...whenFalseStatements.map((statement) => ` ${statement}`),
|
|
210
|
+
`}`,
|
|
211
|
+
];
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
statements = [
|
|
215
|
+
`if (${conditionCode}) {`,
|
|
216
|
+
...whenTrueStatements.map((statement) => ` ${statement}`),
|
|
217
|
+
`} else {`,
|
|
207
218
|
...whenFalseStatements.map((statement) => ` ${statement}`),
|
|
208
219
|
`}`,
|
|
209
220
|
];
|
|
210
221
|
}
|
|
222
|
+
if (node.conditionValueName === undefined) {
|
|
223
|
+
return statements;
|
|
224
|
+
}
|
|
211
225
|
return [
|
|
212
|
-
`
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
...whenFalseStatements.map((statement) => ` ${statement}`),
|
|
226
|
+
`{`,
|
|
227
|
+
` const ${node.conditionValueName} = (${node.conditionCode});`,
|
|
228
|
+
...statements.map((statement) => ` ${statement}`),
|
|
216
229
|
`}`,
|
|
217
230
|
];
|
|
218
231
|
}
|
|
@@ -286,7 +299,7 @@ function collectHtmlStatements(node, outVar, escapeHelperName, escapeBatchHelper
|
|
|
286
299
|
}
|
|
287
300
|
if (node.runtime === "compat" && reactNodeRenderHelperName !== undefined) {
|
|
288
301
|
return [
|
|
289
|
-
`${outVar} += ${reactNodeRenderHelperName}(${node.name}, ${
|
|
302
|
+
`${outVar} += ${reactNodeRenderHelperName}(${node.name}, ${emitCompatRuntimePropsObject(node.props, node.children)});`,
|
|
290
303
|
];
|
|
291
304
|
}
|
|
292
305
|
return [
|
|
@@ -356,8 +369,12 @@ function collectHtmlParts(node, escapeHelperName, escapeBatchHelperName, asyncCo
|
|
|
356
369
|
return [`${escapeHelperName}(${node.code})`];
|
|
357
370
|
}
|
|
358
371
|
if (node.kind === "conditional") {
|
|
372
|
+
const whenTrue = emitHtmlExpressionFromChildren(node.whenTrue, escapeHelperName, escapeBatchHelperName, asyncComponentNames, dynamicAttributes, contextProviderHelperName, contextConsumerHelperName, reactNodeRenderHelperName);
|
|
373
|
+
const whenFalse = emitHtmlExpressionFromChildren(node.whenFalse, escapeHelperName, escapeBatchHelperName, asyncComponentNames, dynamicAttributes, contextProviderHelperName, contextConsumerHelperName, reactNodeRenderHelperName);
|
|
359
374
|
return [
|
|
360
|
-
|
|
375
|
+
node.conditionValueName === undefined
|
|
376
|
+
? `((${node.conditionCode}) ? ${whenTrue} : ${whenFalse})`
|
|
377
|
+
: `(() => { const ${node.conditionValueName} = (${node.conditionCode}); return ${node.conditionValueName} ? ${whenTrue} : ${whenFalse}; })()`,
|
|
361
378
|
];
|
|
362
379
|
}
|
|
363
380
|
if (node.kind === "list") {
|
|
@@ -413,7 +430,7 @@ function collectHtmlParts(node, escapeHelperName, escapeBatchHelperName, asyncCo
|
|
|
413
430
|
}
|
|
414
431
|
if (node.runtime === "compat" && reactNodeRenderHelperName !== undefined) {
|
|
415
432
|
return [
|
|
416
|
-
`${reactNodeRenderHelperName}(${node.name}, ${
|
|
433
|
+
`${reactNodeRenderHelperName}(${node.name}, ${emitCompatRuntimePropsObject(node.props, node.children)})`,
|
|
417
434
|
];
|
|
418
435
|
}
|
|
419
436
|
return [
|
|
@@ -505,6 +522,9 @@ function collectHtmlAttributeParts(tagName, attr, escapeHelperName, escapeBatchH
|
|
|
505
522
|
return [emitDynamicAttributeExpression(htmlName, attr.code, escapeHelperName)];
|
|
506
523
|
}
|
|
507
524
|
function collectElementAttributeParts(tagName, attrs, escapeHelperName, escapeBatchHelperName, dynamicAttributes, attributeScan = scanElementAttributes(tagName, attrs)) {
|
|
525
|
+
if (dynamicAttributes === "emit" && attrs.some((attr) => attr.kind === "spread-attr")) {
|
|
526
|
+
return [emitMergedSpreadAttributeExpression(tagName, attrs, attributeScan)];
|
|
527
|
+
}
|
|
508
528
|
return attrs.flatMap((attr) => attr.kind !== "spread-attr" &&
|
|
509
529
|
((tagName === "input" &&
|
|
510
530
|
((attr.name === "defaultValue" && attributeScan.hasExplicitInputValue) ||
|
|
@@ -514,6 +534,27 @@ function collectElementAttributeParts(tagName, attrs, escapeHelperName, escapeBa
|
|
|
514
534
|
? []
|
|
515
535
|
: collectHtmlAttributeParts(tagName, attr, escapeHelperName, escapeBatchHelperName, dynamicAttributes));
|
|
516
536
|
}
|
|
537
|
+
function emitMergedSpreadAttributeExpression(tagName, attrs, attributeScan) {
|
|
538
|
+
const statements = attrs.flatMap((attr) => {
|
|
539
|
+
if (attr.kind !== "spread-attr" &&
|
|
540
|
+
((tagName === "input" &&
|
|
541
|
+
((attr.name === "defaultValue" && attributeScan.hasExplicitInputValue) ||
|
|
542
|
+
(attr.name === "defaultChecked" && attributeScan.hasExplicitInputChecked))) ||
|
|
543
|
+
((tagName === "textarea" || tagName === "select") &&
|
|
544
|
+
(attr.name === "value" || attr.name === "defaultValue")))) {
|
|
545
|
+
return [];
|
|
546
|
+
}
|
|
547
|
+
if (attr.kind === "spread-attr") {
|
|
548
|
+
return [`Object.assign(_props, (${attr.code}) ?? {});`];
|
|
549
|
+
}
|
|
550
|
+
if (attr.kind === "event" || attr.name === "key" || attr.name === "dangerouslySetInnerHTML") {
|
|
551
|
+
return [];
|
|
552
|
+
}
|
|
553
|
+
const valueCode = attr.kind === "static-attr" ? stringLiteral(attr.value) : `(${attr.code})`;
|
|
554
|
+
return [`_props[${stringLiteral(attr.name)}] = ${valueCode};`];
|
|
555
|
+
});
|
|
556
|
+
return `(() => { const _props = {}; ${statements.join(" ")} return ${currentSpreadAttributesHelperName}(${stringLiteral(tagName)}, _props); })()`;
|
|
557
|
+
}
|
|
517
558
|
function scanElementAttributes(tagName, attrs) {
|
|
518
559
|
let hasExplicitInputValue = false;
|
|
519
560
|
let hasExplicitInputChecked = false;
|
|
@@ -717,6 +758,21 @@ function emitPropsObject(props, children = [], escapeHelperName, escapeBatchHelp
|
|
|
717
758
|
}
|
|
718
759
|
return `{ ${entries.join(", ")} }`;
|
|
719
760
|
}
|
|
761
|
+
function emitCompatRuntimePropsObject(props, children = []) {
|
|
762
|
+
const entries = props.map((prop) => {
|
|
763
|
+
if (prop.kind === "spread-prop") {
|
|
764
|
+
return `...(${prop.code})`;
|
|
765
|
+
}
|
|
766
|
+
if (prop.kind === "render-prop") {
|
|
767
|
+
return `${emitPropName(prop.name)}: ${emitOxcCompatObjectChildren(prop.children)}`;
|
|
768
|
+
}
|
|
769
|
+
return `${emitPropName(prop.name)}: (${prop.code})`;
|
|
770
|
+
});
|
|
771
|
+
if (children.length > 0) {
|
|
772
|
+
entries.push(`children: ${emitOxcCompatObjectChildren(children)}`);
|
|
773
|
+
}
|
|
774
|
+
return `{ ${entries.join(", ")} }`;
|
|
775
|
+
}
|
|
720
776
|
function emitComponentCallExpression(name, propsCode, asyncComponentNames) {
|
|
721
777
|
const call = `${name}(${propsCode})`;
|
|
722
778
|
return asyncComponentNames.has(name) ? `(await ${call})` : call;
|