@reckona/mreact-compiler 0.0.152 → 0.0.154
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/emit-server-shared.js +1 -1
- package/dist/emit-server-shared.js.map +1 -1
- package/dist/emit-server.d.ts.map +1 -1
- package/dist/emit-server.js +81 -8
- package/dist/emit-server.js.map +1 -1
- package/dist/ir.d.ts +2 -1
- package/dist/ir.d.ts.map +1 -1
- package/dist/ir.js.map +1 -1
- package/dist/oxc-bindings.d.ts.map +1 -1
- package/dist/oxc-bindings.js +28 -1
- package/dist/oxc-bindings.js.map +1 -1
- package/dist/oxc-compat-create-element.d.ts +11 -0
- package/dist/oxc-compat-create-element.d.ts.map +1 -0
- package/dist/oxc-compat-create-element.js +489 -0
- package/dist/oxc-compat-create-element.js.map +1 -0
- package/dist/oxc-dom-lowering.js +1 -1
- package/dist/oxc-dom-lowering.js.map +1 -1
- package/dist/oxc-render-values.js +8 -0
- package/dist/oxc-render-values.js.map +1 -1
- package/dist/oxc-runtime-emit.d.ts.map +1 -1
- package/dist/oxc-runtime-emit.js +5 -1
- package/dist/oxc-runtime-emit.js.map +1 -1
- package/dist/oxc-transform.d.ts.map +1 -1
- package/dist/oxc-transform.js +6 -0
- package/dist/oxc-transform.js.map +1 -1
- package/dist/oxc.d.ts.map +1 -1
- package/dist/oxc.js +79 -11
- package/dist/oxc.js.map +1 -1
- package/dist/transform.d.ts +1 -0
- package/dist/transform.d.ts.map +1 -1
- package/dist/transform.js +8 -5
- package/dist/transform.js.map +1 -1
- package/package.json +2 -2
- package/src/emit-server-shared.ts +1 -1
- package/src/emit-server.ts +103 -4
- package/src/ir.ts +4 -1
- package/src/oxc-bindings.ts +36 -1
- package/src/oxc-compat-create-element.ts +705 -0
- package/src/oxc-dom-lowering.ts +1 -1
- package/src/oxc-render-values.ts +10 -0
- package/src/oxc-runtime-emit.ts +6 -1
- package/src/oxc-transform.ts +6 -0
- package/src/oxc.ts +130 -4
- package/src/transform.ts +9 -5
package/src/oxc-render-values.ts
CHANGED
|
@@ -818,6 +818,10 @@ function analyzeOxcReactiveAliasExpression(
|
|
|
818
818
|
}
|
|
819
819
|
|
|
820
820
|
function containsAssignmentTo(node: Record<string, unknown>, name: string): boolean {
|
|
821
|
+
if (isOxcFunctionNode(node) && oxcFunctionShadowsName(node, name)) {
|
|
822
|
+
return false;
|
|
823
|
+
}
|
|
824
|
+
|
|
821
825
|
if (node.type === "AssignmentExpression") {
|
|
822
826
|
const left = readObject(node.left);
|
|
823
827
|
if (left.type === "Identifier" && left.name === name) return true;
|
|
@@ -844,6 +848,12 @@ function containsAssignmentTo(node: Record<string, unknown>, name: string): bool
|
|
|
844
848
|
return false;
|
|
845
849
|
}
|
|
846
850
|
|
|
851
|
+
function oxcFunctionShadowsName(functionNode: Record<string, unknown>, name: string): boolean {
|
|
852
|
+
const localBindings = new Set<string>();
|
|
853
|
+
collectOxcFunctionLocalBindings(functionNode, localBindings);
|
|
854
|
+
return localBindings.has(name);
|
|
855
|
+
}
|
|
856
|
+
|
|
847
857
|
function collectOxcPushJsxBindingNames(statements: readonly unknown[], names: Set<string>): void {
|
|
848
858
|
for (const statement of statements) {
|
|
849
859
|
const object = readObject(statement);
|
package/src/oxc-runtime-emit.ts
CHANGED
|
@@ -45,7 +45,12 @@ function emitOxcServerStringNode(node: JsxNodeIr): string {
|
|
|
45
45
|
|
|
46
46
|
if (node.kind === "list") {
|
|
47
47
|
const parameters = emitOxcListParameters(node);
|
|
48
|
-
|
|
48
|
+
const valueExpression = emitOxcServerStringChildren(node.children);
|
|
49
|
+
if (node.bodyStatements === undefined || node.bodyStatements.length === 0) {
|
|
50
|
+
return `(${node.itemsCode}).map((${parameters}) => ${valueExpression}).join("")`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return `(${node.itemsCode}).map((${parameters}) => {\n${node.bodyStatements.map((statement) => ` ${statement}`).join("\n")}\n return ${valueExpression};\n}).join("")`;
|
|
49
54
|
}
|
|
50
55
|
|
|
51
56
|
if (node.kind === "fragment") {
|
package/src/oxc-transform.ts
CHANGED
|
@@ -44,12 +44,18 @@ function rememberStrippedTypeScript(source: string, stripped: string): void {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
function needsTypeScriptStripping(source: string): boolean {
|
|
47
|
+
// This is intentionally an over-approximation: false positives cost an oxc
|
|
48
|
+
// pass, but false negatives leak TypeScript syntax into emitted JavaScript.
|
|
47
49
|
return (
|
|
48
50
|
/\bimport\s+type\b/.test(source) ||
|
|
51
|
+
/\bexport\s+type\b/.test(source) ||
|
|
49
52
|
/\btype\s+[A-Za-z_$][\w$]*\b/.test(source) ||
|
|
50
53
|
/\binterface\s+[A-Za-z_$][\w$]*\b/.test(source) ||
|
|
54
|
+
/<[^>\n]+\bextends\b[^>\n]*>\s*\(/.test(source) ||
|
|
51
55
|
/\b[A-Za-z_$][\w$.]*\s*<[^>\n]+>\s*\(/.test(source) ||
|
|
52
56
|
/\bas\s+(?:const|[A-Za-z_$][\w$]*)\b/.test(source) ||
|
|
57
|
+
/\bsatisfies\s+[A-Za-z_$][\w$<>,\s|&.[\]?]*/.test(source) ||
|
|
58
|
+
/[A-Za-z_$)\]}]\s*!\s*(?=[,.;)\]}])/.test(source) ||
|
|
53
59
|
/:\s*[A-Za-z_$][\w$<>,\s|&.[\]?]*(?=[,)=;{])/.test(source)
|
|
54
60
|
);
|
|
55
61
|
}
|
package/src/oxc.ts
CHANGED
|
@@ -70,6 +70,12 @@ import {
|
|
|
70
70
|
analyzeOxcJsxNode,
|
|
71
71
|
type OxcChildAnalysisContext,
|
|
72
72
|
} from "./oxc-child-analysis.js";
|
|
73
|
+
import {
|
|
74
|
+
analyzeCompatCreateElementRoot,
|
|
75
|
+
collectCompatCreateElementNames,
|
|
76
|
+
collectFunctionShadowedNames,
|
|
77
|
+
hasLowerableCompatCreateElementReturn,
|
|
78
|
+
} from "./oxc-compat-create-element.js";
|
|
73
79
|
import { lowerOxcDomNodeExpression } from "./oxc-dom-lowering.js";
|
|
74
80
|
import {
|
|
75
81
|
lowerOxcCompatObjectExpression,
|
|
@@ -239,6 +245,12 @@ function analyzeOxcToIr(
|
|
|
239
245
|
: undefined;
|
|
240
246
|
const localJsxReturnFunctionNames =
|
|
241
247
|
target === "server" ? collectOxcLocalJsxReturnFunctionNames(program) : new Set<string>();
|
|
248
|
+
// Stream emit keeps interpreting compat trees for now; only the string
|
|
249
|
+
// pipeline lowers createElement calls.
|
|
250
|
+
const compatCreateElementNames =
|
|
251
|
+
target === "server" && options?.serverOutput !== "stream"
|
|
252
|
+
? collectCompatCreateElementNames(program)
|
|
253
|
+
: new Set<string>();
|
|
242
254
|
const localJsxHelperHtmlParameters =
|
|
243
255
|
target === "server"
|
|
244
256
|
? collectLocalJsxHelperHtmlParameters(program, localJsxReturnFunctionNames)
|
|
@@ -265,6 +277,7 @@ function analyzeOxcToIr(
|
|
|
265
277
|
|
|
266
278
|
if (
|
|
267
279
|
isOxcJsxComponentStatement(statement, localJsxReturnFunctionNames) ||
|
|
280
|
+
isCompatCreateElementComponentStatement(code, statement, compatCreateElementNames) ||
|
|
268
281
|
(options?.compatReactNodeReturn === true && isOxcExportedFunctionLike(statement))
|
|
269
282
|
) {
|
|
270
283
|
const declaration = readObject(readObject(statement).declaration);
|
|
@@ -328,6 +341,7 @@ function analyzeOxcToIr(
|
|
|
328
341
|
target,
|
|
329
342
|
diagnostics,
|
|
330
343
|
options?.bodyStatementJsx ?? "dom-node",
|
|
344
|
+
compatCreateElementNames,
|
|
331
345
|
moduleRenderValueBindings,
|
|
332
346
|
options?.compatReactNodeReturn === true,
|
|
333
347
|
options?.serverOutput,
|
|
@@ -476,6 +490,97 @@ function collectOxcReturnExpressions(
|
|
|
476
490
|
return [];
|
|
477
491
|
}
|
|
478
492
|
|
|
493
|
+
interface CompatCreateElementComponent {
|
|
494
|
+
name: string;
|
|
495
|
+
initializer: Record<string, unknown>;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
function readCompatCreateElementFunctionLike(
|
|
499
|
+
code: string,
|
|
500
|
+
expression: Record<string, unknown>,
|
|
501
|
+
names: ReadonlySet<string>,
|
|
502
|
+
): Record<string, unknown> | undefined {
|
|
503
|
+
const functionLike = unwrapOxcComponentFunctionLikeInitializer(expression);
|
|
504
|
+
|
|
505
|
+
return functionLike !== undefined &&
|
|
506
|
+
hasLowerableCompatCreateElementReturn(code, functionLike, names)
|
|
507
|
+
? functionLike
|
|
508
|
+
: undefined;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
function readCompatCreateElementPlainComponent(
|
|
512
|
+
code: string,
|
|
513
|
+
statement: unknown,
|
|
514
|
+
names: ReadonlySet<string>,
|
|
515
|
+
): CompatCreateElementComponent | undefined {
|
|
516
|
+
if (names.size === 0) {
|
|
517
|
+
return undefined;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
const object = readObject(statement);
|
|
521
|
+
|
|
522
|
+
if (
|
|
523
|
+
object.type === "FunctionDeclaration" &&
|
|
524
|
+
hasLowerableCompatCreateElementReturn(code, object, names)
|
|
525
|
+
) {
|
|
526
|
+
const id = readObject(object.id);
|
|
527
|
+
return typeof id.name === "string" ? { name: id.name, initializer: object } : undefined;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
if (object.type !== "VariableDeclaration") {
|
|
531
|
+
return undefined;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
for (const declarator of readArray(object.declarations)) {
|
|
535
|
+
const declaratorObject = readObject(declarator);
|
|
536
|
+
const id = readObject(declaratorObject.id);
|
|
537
|
+
|
|
538
|
+
if (typeof id.name !== "string" || !/^[A-Z]/.test(id.name)) {
|
|
539
|
+
continue;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
const initializer = readCompatCreateElementFunctionLike(
|
|
543
|
+
code,
|
|
544
|
+
readObject(declaratorObject.init),
|
|
545
|
+
names,
|
|
546
|
+
);
|
|
547
|
+
|
|
548
|
+
if (initializer !== undefined) {
|
|
549
|
+
return { name: id.name, initializer };
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
return undefined;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
function isCompatCreateElementComponentStatement(
|
|
557
|
+
code: string,
|
|
558
|
+
statement: unknown,
|
|
559
|
+
names: ReadonlySet<string>,
|
|
560
|
+
): boolean {
|
|
561
|
+
if (names.size === 0) {
|
|
562
|
+
return false;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
const object = readObject(statement);
|
|
566
|
+
|
|
567
|
+
if (object.type === "ExportDefaultDeclaration") {
|
|
568
|
+
return readCompatCreateElementFunctionLike(code, readObject(object.declaration), names) !== undefined;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
if (object.type === "ExportNamedDeclaration") {
|
|
572
|
+
const declaration = readObject(object.declaration);
|
|
573
|
+
|
|
574
|
+
if (declaration.type === "FunctionDeclaration") {
|
|
575
|
+
return hasLowerableCompatCreateElementReturn(code, declaration, names);
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
return readCompatCreateElementPlainComponent(code, declaration, names) !== undefined;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
return readCompatCreateElementPlainComponent(code, statement, names) !== undefined;
|
|
582
|
+
}
|
|
583
|
+
|
|
479
584
|
function analyzeOxcComponent(
|
|
480
585
|
code: string,
|
|
481
586
|
statement: unknown,
|
|
@@ -483,6 +588,7 @@ function analyzeOxcComponent(
|
|
|
483
588
|
target: CompileTarget,
|
|
484
589
|
diagnostics: Diagnostic[],
|
|
485
590
|
bodyStatementJsx: OxcBodyStatementJsxMode,
|
|
591
|
+
compatCreateElementNames: ReadonlySet<string>,
|
|
486
592
|
moduleRenderValueBindings: Set<string>,
|
|
487
593
|
compatReactNodeReturn: boolean,
|
|
488
594
|
serverOutput: AnalyzeModuleOptions["serverOutput"],
|
|
@@ -497,7 +603,11 @@ function analyzeOxcComponent(
|
|
|
497
603
|
if (object.type === "ExportDefaultDeclaration") {
|
|
498
604
|
const declaration = unwrapOxcComponentFunctionLikeInitializer(readObject(object.declaration));
|
|
499
605
|
|
|
500
|
-
if (
|
|
606
|
+
if (
|
|
607
|
+
declaration === undefined ||
|
|
608
|
+
(!hasOxcFunctionLikeComponentReturn(declaration) &&
|
|
609
|
+
!hasLowerableCompatCreateElementReturn(code, declaration, compatCreateElementNames))
|
|
610
|
+
) {
|
|
501
611
|
return [];
|
|
502
612
|
}
|
|
503
613
|
const id = readObject(declaration.id);
|
|
@@ -513,6 +623,7 @@ function analyzeOxcComponent(
|
|
|
513
623
|
target,
|
|
514
624
|
diagnostics,
|
|
515
625
|
bodyStatementJsx,
|
|
626
|
+
compatCreateElementNames,
|
|
516
627
|
moduleRenderValueBindings,
|
|
517
628
|
compatReactNodeReturn,
|
|
518
629
|
serverOutput,
|
|
@@ -527,7 +638,9 @@ function analyzeOxcComponent(
|
|
|
527
638
|
}
|
|
528
639
|
|
|
529
640
|
if (object.type !== "ExportNamedDeclaration") {
|
|
530
|
-
const plainComponent =
|
|
641
|
+
const plainComponent =
|
|
642
|
+
readOxcPlainComponent(statement) ??
|
|
643
|
+
readCompatCreateElementPlainComponent(code, statement, compatCreateElementNames);
|
|
531
644
|
|
|
532
645
|
if (plainComponent === undefined) {
|
|
533
646
|
return [];
|
|
@@ -544,6 +657,7 @@ function analyzeOxcComponent(
|
|
|
544
657
|
target,
|
|
545
658
|
diagnostics,
|
|
546
659
|
bodyStatementJsx,
|
|
660
|
+
compatCreateElementNames,
|
|
547
661
|
moduleRenderValueBindings,
|
|
548
662
|
compatReactNodeReturn,
|
|
549
663
|
serverOutput,
|
|
@@ -561,7 +675,9 @@ function analyzeOxcComponent(
|
|
|
561
675
|
const declaration = readObject(object.declaration);
|
|
562
676
|
|
|
563
677
|
if (declaration.type === "VariableDeclaration") {
|
|
564
|
-
const variableComponent =
|
|
678
|
+
const variableComponent =
|
|
679
|
+
readOxcVariableComponentDeclaration(declaration) ??
|
|
680
|
+
readCompatCreateElementPlainComponent(code, declaration, compatCreateElementNames);
|
|
565
681
|
|
|
566
682
|
if (variableComponent === undefined) {
|
|
567
683
|
return [];
|
|
@@ -577,6 +693,7 @@ function analyzeOxcComponent(
|
|
|
577
693
|
target,
|
|
578
694
|
diagnostics,
|
|
579
695
|
bodyStatementJsx,
|
|
696
|
+
compatCreateElementNames,
|
|
580
697
|
moduleRenderValueBindings,
|
|
581
698
|
compatReactNodeReturn,
|
|
582
699
|
serverOutput,
|
|
@@ -593,7 +710,8 @@ function analyzeOxcComponent(
|
|
|
593
710
|
declaration.type !== "FunctionDeclaration" ||
|
|
594
711
|
(!compatReactNodeReturn &&
|
|
595
712
|
!hasComponentReturn(declaration.body) &&
|
|
596
|
-
!hasLocalJsxHelperCallReturn(declaration.body, localJsxReturnFunctionNames)
|
|
713
|
+
!hasLocalJsxHelperCallReturn(declaration.body, localJsxReturnFunctionNames) &&
|
|
714
|
+
!hasLowerableCompatCreateElementReturn(code, declaration, compatCreateElementNames))
|
|
597
715
|
) {
|
|
598
716
|
return [];
|
|
599
717
|
}
|
|
@@ -614,6 +732,7 @@ function analyzeOxcComponent(
|
|
|
614
732
|
target,
|
|
615
733
|
diagnostics,
|
|
616
734
|
bodyStatementJsx,
|
|
735
|
+
compatCreateElementNames,
|
|
617
736
|
moduleRenderValueBindings,
|
|
618
737
|
compatReactNodeReturn,
|
|
619
738
|
serverOutput,
|
|
@@ -663,6 +782,7 @@ function analyzeOxcFunctionLikeComponent(
|
|
|
663
782
|
target: CompileTarget,
|
|
664
783
|
diagnostics: Diagnostic[],
|
|
665
784
|
bodyStatementJsx: OxcBodyStatementJsxMode,
|
|
785
|
+
compatCreateElementNames: ReadonlySet<string>,
|
|
666
786
|
moduleRenderValueBindings: Set<string>,
|
|
667
787
|
compatReactNodeReturn: boolean,
|
|
668
788
|
serverOutput: AnalyzeModuleOptions["serverOutput"],
|
|
@@ -743,6 +863,12 @@ function analyzeOxcFunctionLikeComponent(
|
|
|
743
863
|
const root =
|
|
744
864
|
analyzeOxcEarlyIfRootReturn(code, earlyIfRootReturn, childAnalysisContext, bodyStatementJsx) ??
|
|
745
865
|
analyzeOxcSwitchRootReturn(code, rootStatement, childAnalysisContext, bodyStatementJsx) ??
|
|
866
|
+
(compatCreateElementNames.size === 0
|
|
867
|
+
? undefined
|
|
868
|
+
: analyzeCompatCreateElementRoot(code, returnExpression, {
|
|
869
|
+
names: compatCreateElementNames,
|
|
870
|
+
shadowed: collectFunctionShadowedNames(functionLike, compatCreateElementNames),
|
|
871
|
+
})) ??
|
|
746
872
|
(isJsxRoot(returnExpression.type) || returnExpression.type === "JSXFragment"
|
|
747
873
|
? analyzeOxcJsxNode(code, returnExpression, childAnalysisContext)
|
|
748
874
|
: isOxcComponentCallExpression(returnExpression)
|
package/src/transform.ts
CHANGED
|
@@ -162,6 +162,10 @@ function transformWithAnalyzer(
|
|
|
162
162
|
metadata.serverHydration = true;
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
+
if (input.serverAwaitHydration === true) {
|
|
166
|
+
metadata.serverAwaitHydration = true;
|
|
167
|
+
}
|
|
168
|
+
|
|
165
169
|
if (input.reactSuspenseRevealScriptSrc !== undefined) {
|
|
166
170
|
metadata.reactSuspenseRevealScriptSrc = input.reactSuspenseRevealScriptSrc;
|
|
167
171
|
}
|
|
@@ -518,16 +522,16 @@ function dedupeAndSortSegments(segments: readonly SourceMapSegment[]): SourceMap
|
|
|
518
522
|
|
|
519
523
|
const sourceMapBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
520
524
|
|
|
521
|
-
function encodeVlq(value: number): string {
|
|
522
|
-
let vlq = value < 0 ?
|
|
525
|
+
export function encodeVlq(value: number): string {
|
|
526
|
+
let vlq = value < 0 ? -value * 2 + 1 : value * 2;
|
|
523
527
|
let encoded = "";
|
|
524
528
|
|
|
525
529
|
do {
|
|
526
|
-
let digit = vlq
|
|
527
|
-
vlq
|
|
530
|
+
let digit = vlq % 32;
|
|
531
|
+
vlq = Math.floor(vlq / 32);
|
|
528
532
|
|
|
529
533
|
if (vlq > 0) {
|
|
530
|
-
digit
|
|
534
|
+
digit += 32;
|
|
531
535
|
}
|
|
532
536
|
|
|
533
537
|
encoded += sourceMapBase64[digit] ?? "";
|