@vue-jsx-vapor/compiler 2.4.5 → 2.4.7
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/index.cjs +26 -23
- package/dist/index.d.cts +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.js +26 -23
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
@@ -303,7 +303,6 @@ function newBlock(node) {
|
|
303
303
|
effect: [],
|
304
304
|
operation: [],
|
305
305
|
returns: [],
|
306
|
-
expressions: [],
|
307
306
|
tempId: 0
|
308
307
|
};
|
309
308
|
}
|
@@ -407,23 +406,17 @@ var TransformContext = class TransformContext {
|
|
407
406
|
const id = this.pushTemplate(this.template);
|
408
407
|
return this.dynamic.template = id;
|
409
408
|
}
|
410
|
-
registerEffect(expressions,
|
409
|
+
registerEffect(expressions, operation, getEffectIndex = () => this.block.effect.length, getOperationIndex = () => this.block.operation.length) {
|
410
|
+
const operations = [operation].flat();
|
411
411
|
expressions = expressions.filter((exp) => !isConstantExpression(exp));
|
412
|
-
if (this.inVOnce || expressions.length === 0 || expressions.every((e) => e.ast && (0, __vue_compiler_dom.isConstantNode)(e.ast, {}))) return this.registerOperation(
|
413
|
-
this.block.
|
414
|
-
const existing = this.block.effect.find((e) => isSameExpression(e.expressions, expressions));
|
415
|
-
if (existing) existing.operations.push(...operations);
|
416
|
-
else this.block.effect.push({
|
412
|
+
if (this.inVOnce || expressions.length === 0 || expressions.every((e) => e.ast && (0, __vue_compiler_dom.isConstantNode)(e.ast, {}))) return this.registerOperation(operations, getOperationIndex);
|
413
|
+
this.block.effect.splice(getEffectIndex(), 0, {
|
417
414
|
expressions,
|
418
415
|
operations
|
419
416
|
});
|
420
|
-
function isSameExpression(a, b) {
|
421
|
-
if (a.length !== b.length) return false;
|
422
|
-
return a.every((exp, i) => exp.content === b[i].content);
|
423
|
-
}
|
424
417
|
}
|
425
|
-
registerOperation(
|
426
|
-
this.block.operation.
|
418
|
+
registerOperation(operation, getOperationIndex = () => this.block.operation.length) {
|
419
|
+
this.block.operation.splice(getOperationIndex(), 0, ...[operation].flat());
|
427
420
|
}
|
428
421
|
create(node, index) {
|
429
422
|
return Object.assign(Object.create(TransformContext.prototype), this, {
|
@@ -548,6 +541,10 @@ const isReservedProp = /* @__PURE__ */ (0, __vue_shared.makeMap)(",key,ref,ref_f
|
|
548
541
|
const isEventRegex = /^on[A-Z]/;
|
549
542
|
const isDirectiveRegex = /^v-[a-z]/;
|
550
543
|
const transformElement = (node, context) => {
|
544
|
+
let effectIndex = context.block.effect.length;
|
545
|
+
const getEffectIndex = () => effectIndex++;
|
546
|
+
let operationIndex = context.block.operation.length;
|
547
|
+
const getOperationIndex = () => operationIndex++;
|
551
548
|
return function postTransformElement() {
|
552
549
|
({node} = context);
|
553
550
|
if (node.type !== "JSXElement" || isTemplate(node)) return;
|
@@ -557,8 +554,8 @@ const transformElement = (node, context) => {
|
|
557
554
|
const propsResult = buildProps(node, context, isComponent);
|
558
555
|
let { parent } = context;
|
559
556
|
while (parent && parent.parent && parent.node.type === "JSXElement" && isTemplate(parent.node)) parent = parent.parent;
|
560
|
-
const singleRoot = context.root === parent && parent.node.
|
561
|
-
(isComponent ? transformComponentElement : transformNativeElement)(tag, propsResult, singleRoot, context);
|
557
|
+
const singleRoot = context.root === parent && parent.node.type !== "JSXFragment";
|
558
|
+
(isComponent ? transformComponentElement : transformNativeElement)(tag, propsResult, singleRoot, context, getEffectIndex, getOperationIndex);
|
562
559
|
};
|
563
560
|
};
|
564
561
|
function transformComponentElement(tag, propsResult, singleRoot, context) {
|
@@ -584,13 +581,13 @@ function transformComponentElement(tag, propsResult, singleRoot, context) {
|
|
584
581
|
tag,
|
585
582
|
props: propsResult[0] ? propsResult[1] : [propsResult[1]],
|
586
583
|
asset,
|
587
|
-
root: singleRoot,
|
584
|
+
root: singleRoot && !context.inVFor,
|
588
585
|
slots: [...context.slots],
|
589
586
|
once: context.inVOnce
|
590
587
|
};
|
591
588
|
context.slots = [];
|
592
589
|
}
|
593
|
-
function transformNativeElement(tag, propsResult, singleRoot, context) {
|
590
|
+
function transformNativeElement(tag, propsResult, singleRoot, context, getEffectIndex, getOperationIndex) {
|
594
591
|
const { scopeId } = context.options;
|
595
592
|
let template = "";
|
596
593
|
template += `<${tag}`;
|
@@ -603,7 +600,7 @@ function transformNativeElement(tag, propsResult, singleRoot, context) {
|
|
603
600
|
element: context.reference(),
|
604
601
|
props: dynamicArgs,
|
605
602
|
root: singleRoot
|
606
|
-
});
|
603
|
+
}, getEffectIndex, getOperationIndex);
|
607
604
|
} else for (const prop of propsResult[1]) {
|
608
605
|
const { key, values } = prop;
|
609
606
|
if (key.isStatic && values.length === 1 && values[0].isStatic) {
|
@@ -617,7 +614,7 @@ function transformNativeElement(tag, propsResult, singleRoot, context) {
|
|
617
614
|
prop,
|
618
615
|
tag,
|
619
616
|
root: singleRoot
|
620
|
-
});
|
617
|
+
}, getEffectIndex, getOperationIndex);
|
621
618
|
}
|
622
619
|
}
|
623
620
|
template += `>${context.childrenTemplate.join("")}`;
|
@@ -801,6 +798,9 @@ function processLogicalExpression(node, context) {
|
|
801
798
|
//#endregion
|
802
799
|
//#region src/transforms/transformText.ts
|
803
800
|
const seen = /* @__PURE__ */ new WeakMap();
|
801
|
+
function markNonTemplate(node, context) {
|
802
|
+
seen.get(context.root).add(node);
|
803
|
+
}
|
804
804
|
const transformText = (node, context) => {
|
805
805
|
if (!seen.has(context.root)) seen.set(context.root, /* @__PURE__ */ new WeakSet());
|
806
806
|
if (seen.get(context.root).has(node)) {
|
@@ -817,7 +817,7 @@ const transformText = (node, context) => {
|
|
817
817
|
else if (hasInterp) for (let i = 0; i < node.children.length; i++) {
|
818
818
|
const c = node.children[i];
|
819
819
|
const prev = node.children[i - 1];
|
820
|
-
if (c.type === "JSXExpressionContainer" && prev && prev.type === "JSXText")
|
820
|
+
if (c.type === "JSXExpressionContainer" && prev && prev.type === "JSXText") markNonTemplate(prev, context);
|
821
821
|
}
|
822
822
|
} else if (node.type === "JSXExpressionContainer") if (node.expression.type === "ConditionalExpression") return processConditionalExpression(node.expression, context);
|
823
823
|
else if (node.expression.type === "LogicalExpression") return processLogicalExpression(node.expression, context);
|
@@ -877,7 +877,7 @@ function processTextContainer(children, context) {
|
|
877
877
|
function createTextLikeExpressions(nodes, context) {
|
878
878
|
const values = [];
|
879
879
|
for (const node of nodes) {
|
880
|
-
|
880
|
+
markNonTemplate(node, context);
|
881
881
|
if (isEmptyText(node)) continue;
|
882
882
|
values.push(resolveExpression(node, context, !context.inVOnce));
|
883
883
|
}
|
@@ -1020,7 +1020,10 @@ function processIf(node, attribute, context) {
|
|
1020
1020
|
let lastIfNode;
|
1021
1021
|
if (siblings) {
|
1022
1022
|
let i = siblings.length;
|
1023
|
-
while (i--) if (siblings[i].operation
|
1023
|
+
while (i--) if (siblings[i].operation && siblings[i].operation.type === IRNodeTypes.IF) {
|
1024
|
+
lastIfNode = siblings[i].operation;
|
1025
|
+
break;
|
1026
|
+
}
|
1024
1027
|
}
|
1025
1028
|
if (!siblingIf || !lastIfNode || lastIfNode.type !== IRNodeTypes.IF) {
|
1026
1029
|
context.options.onError((0, __vue_compiler_dom.createCompilerError)(__vue_compiler_dom.ErrorCodes.X_V_ELSE_NO_ADJACENT_IF, resolveLocation(node.loc, context)));
|
@@ -1404,8 +1407,8 @@ function getBaseTransformPreset() {
|
|
1404
1407
|
transformVIf,
|
1405
1408
|
transformVFor,
|
1406
1409
|
transformTemplateRef,
|
1407
|
-
transformText,
|
1408
1410
|
transformElement,
|
1411
|
+
transformText,
|
1409
1412
|
transformVSlot,
|
1410
1413
|
transformChildren
|
1411
1414
|
], {
|
package/dist/index.d.cts
CHANGED
@@ -42,8 +42,8 @@ declare class TransformContext<T extends BlockIRNode['node'] = BlockIRNode['node
|
|
42
42
|
reference(): number;
|
43
43
|
pushTemplate(content: string): number;
|
44
44
|
registerTemplate(): number;
|
45
|
-
registerEffect(expressions: SimpleExpressionNode[],
|
46
|
-
registerOperation(
|
45
|
+
registerEffect(expressions: SimpleExpressionNode[], operation: OperationNode | OperationNode[], getEffectIndex?: () => number, getOperationIndex?: () => number): void;
|
46
|
+
registerOperation(operation: OperationNode | OperationNode[], getOperationIndex?: () => number): void;
|
47
47
|
create<E extends T>(node: E, index: number): TransformContext<E>;
|
48
48
|
}
|
49
49
|
declare function transform(node: RootNode, options?: TransformOptions): RootIRNode;
|
@@ -135,7 +135,7 @@ interface BaseIRNode {
|
|
135
135
|
type: IRNodeTypes;
|
136
136
|
}
|
137
137
|
interface RootNode {
|
138
|
-
type: IRNodeTypes.ROOT;
|
138
|
+
type: IRNodeTypes.ROOT | JSXFragment['type'];
|
139
139
|
source: string;
|
140
140
|
children: JSXFragment['children'];
|
141
141
|
}
|
@@ -146,7 +146,6 @@ interface BlockIRNode extends BaseIRNode {
|
|
146
146
|
tempId: number;
|
147
147
|
effect: IREffect[];
|
148
148
|
operation: OperationNode[];
|
149
|
-
expressions: SimpleExpressionNode[];
|
150
149
|
returns: number[];
|
151
150
|
}
|
152
151
|
interface RootIRNode {
|
package/dist/index.d.ts
CHANGED
@@ -42,8 +42,8 @@ declare class TransformContext<T extends BlockIRNode['node'] = BlockIRNode['node
|
|
42
42
|
reference(): number;
|
43
43
|
pushTemplate(content: string): number;
|
44
44
|
registerTemplate(): number;
|
45
|
-
registerEffect(expressions: SimpleExpressionNode[],
|
46
|
-
registerOperation(
|
45
|
+
registerEffect(expressions: SimpleExpressionNode[], operation: OperationNode | OperationNode[], getEffectIndex?: () => number, getOperationIndex?: () => number): void;
|
46
|
+
registerOperation(operation: OperationNode | OperationNode[], getOperationIndex?: () => number): void;
|
47
47
|
create<E extends T>(node: E, index: number): TransformContext<E>;
|
48
48
|
}
|
49
49
|
declare function transform(node: RootNode, options?: TransformOptions): RootIRNode;
|
@@ -135,7 +135,7 @@ interface BaseIRNode {
|
|
135
135
|
type: IRNodeTypes;
|
136
136
|
}
|
137
137
|
interface RootNode {
|
138
|
-
type: IRNodeTypes.ROOT;
|
138
|
+
type: IRNodeTypes.ROOT | JSXFragment['type'];
|
139
139
|
source: string;
|
140
140
|
children: JSXFragment['children'];
|
141
141
|
}
|
@@ -146,7 +146,6 @@ interface BlockIRNode extends BaseIRNode {
|
|
146
146
|
tempId: number;
|
147
147
|
effect: IREffect[];
|
148
148
|
operation: OperationNode[];
|
149
|
-
expressions: SimpleExpressionNode[];
|
150
149
|
returns: number[];
|
151
150
|
}
|
152
151
|
interface RootIRNode {
|
package/dist/index.js
CHANGED
@@ -280,7 +280,6 @@ function newBlock(node) {
|
|
280
280
|
effect: [],
|
281
281
|
operation: [],
|
282
282
|
returns: [],
|
283
|
-
expressions: [],
|
284
283
|
tempId: 0
|
285
284
|
};
|
286
285
|
}
|
@@ -384,23 +383,17 @@ var TransformContext = class TransformContext {
|
|
384
383
|
const id = this.pushTemplate(this.template);
|
385
384
|
return this.dynamic.template = id;
|
386
385
|
}
|
387
|
-
registerEffect(expressions,
|
386
|
+
registerEffect(expressions, operation, getEffectIndex = () => this.block.effect.length, getOperationIndex = () => this.block.operation.length) {
|
387
|
+
const operations = [operation].flat();
|
388
388
|
expressions = expressions.filter((exp) => !isConstantExpression(exp));
|
389
|
-
if (this.inVOnce || expressions.length === 0 || expressions.every((e) => e.ast && isConstantNode(e.ast, {}))) return this.registerOperation(
|
390
|
-
this.block.
|
391
|
-
const existing = this.block.effect.find((e) => isSameExpression(e.expressions, expressions));
|
392
|
-
if (existing) existing.operations.push(...operations);
|
393
|
-
else this.block.effect.push({
|
389
|
+
if (this.inVOnce || expressions.length === 0 || expressions.every((e) => e.ast && isConstantNode(e.ast, {}))) return this.registerOperation(operations, getOperationIndex);
|
390
|
+
this.block.effect.splice(getEffectIndex(), 0, {
|
394
391
|
expressions,
|
395
392
|
operations
|
396
393
|
});
|
397
|
-
function isSameExpression(a, b) {
|
398
|
-
if (a.length !== b.length) return false;
|
399
|
-
return a.every((exp, i) => exp.content === b[i].content);
|
400
|
-
}
|
401
394
|
}
|
402
|
-
registerOperation(
|
403
|
-
this.block.operation.
|
395
|
+
registerOperation(operation, getOperationIndex = () => this.block.operation.length) {
|
396
|
+
this.block.operation.splice(getOperationIndex(), 0, ...[operation].flat());
|
404
397
|
}
|
405
398
|
create(node, index) {
|
406
399
|
return Object.assign(Object.create(TransformContext.prototype), this, {
|
@@ -525,6 +518,10 @@ const isReservedProp = /* @__PURE__ */ makeMap(",key,ref,ref_for,ref_key,");
|
|
525
518
|
const isEventRegex = /^on[A-Z]/;
|
526
519
|
const isDirectiveRegex = /^v-[a-z]/;
|
527
520
|
const transformElement = (node, context) => {
|
521
|
+
let effectIndex = context.block.effect.length;
|
522
|
+
const getEffectIndex = () => effectIndex++;
|
523
|
+
let operationIndex = context.block.operation.length;
|
524
|
+
const getOperationIndex = () => operationIndex++;
|
528
525
|
return function postTransformElement() {
|
529
526
|
({node} = context);
|
530
527
|
if (node.type !== "JSXElement" || isTemplate(node)) return;
|
@@ -534,8 +531,8 @@ const transformElement = (node, context) => {
|
|
534
531
|
const propsResult = buildProps(node, context, isComponent);
|
535
532
|
let { parent } = context;
|
536
533
|
while (parent && parent.parent && parent.node.type === "JSXElement" && isTemplate(parent.node)) parent = parent.parent;
|
537
|
-
const singleRoot = context.root === parent && parent.node.
|
538
|
-
(isComponent ? transformComponentElement : transformNativeElement)(tag, propsResult, singleRoot, context);
|
534
|
+
const singleRoot = context.root === parent && parent.node.type !== "JSXFragment";
|
535
|
+
(isComponent ? transformComponentElement : transformNativeElement)(tag, propsResult, singleRoot, context, getEffectIndex, getOperationIndex);
|
539
536
|
};
|
540
537
|
};
|
541
538
|
function transformComponentElement(tag, propsResult, singleRoot, context) {
|
@@ -561,13 +558,13 @@ function transformComponentElement(tag, propsResult, singleRoot, context) {
|
|
561
558
|
tag,
|
562
559
|
props: propsResult[0] ? propsResult[1] : [propsResult[1]],
|
563
560
|
asset,
|
564
|
-
root: singleRoot,
|
561
|
+
root: singleRoot && !context.inVFor,
|
565
562
|
slots: [...context.slots],
|
566
563
|
once: context.inVOnce
|
567
564
|
};
|
568
565
|
context.slots = [];
|
569
566
|
}
|
570
|
-
function transformNativeElement(tag, propsResult, singleRoot, context) {
|
567
|
+
function transformNativeElement(tag, propsResult, singleRoot, context, getEffectIndex, getOperationIndex) {
|
571
568
|
const { scopeId } = context.options;
|
572
569
|
let template = "";
|
573
570
|
template += `<${tag}`;
|
@@ -580,7 +577,7 @@ function transformNativeElement(tag, propsResult, singleRoot, context) {
|
|
580
577
|
element: context.reference(),
|
581
578
|
props: dynamicArgs,
|
582
579
|
root: singleRoot
|
583
|
-
});
|
580
|
+
}, getEffectIndex, getOperationIndex);
|
584
581
|
} else for (const prop of propsResult[1]) {
|
585
582
|
const { key, values } = prop;
|
586
583
|
if (key.isStatic && values.length === 1 && values[0].isStatic) {
|
@@ -594,7 +591,7 @@ function transformNativeElement(tag, propsResult, singleRoot, context) {
|
|
594
591
|
prop,
|
595
592
|
tag,
|
596
593
|
root: singleRoot
|
597
|
-
});
|
594
|
+
}, getEffectIndex, getOperationIndex);
|
598
595
|
}
|
599
596
|
}
|
600
597
|
template += `>${context.childrenTemplate.join("")}`;
|
@@ -778,6 +775,9 @@ function processLogicalExpression(node, context) {
|
|
778
775
|
//#endregion
|
779
776
|
//#region src/transforms/transformText.ts
|
780
777
|
const seen = /* @__PURE__ */ new WeakMap();
|
778
|
+
function markNonTemplate(node, context) {
|
779
|
+
seen.get(context.root).add(node);
|
780
|
+
}
|
781
781
|
const transformText = (node, context) => {
|
782
782
|
if (!seen.has(context.root)) seen.set(context.root, /* @__PURE__ */ new WeakSet());
|
783
783
|
if (seen.get(context.root).has(node)) {
|
@@ -794,7 +794,7 @@ const transformText = (node, context) => {
|
|
794
794
|
else if (hasInterp) for (let i = 0; i < node.children.length; i++) {
|
795
795
|
const c = node.children[i];
|
796
796
|
const prev = node.children[i - 1];
|
797
|
-
if (c.type === "JSXExpressionContainer" && prev && prev.type === "JSXText")
|
797
|
+
if (c.type === "JSXExpressionContainer" && prev && prev.type === "JSXText") markNonTemplate(prev, context);
|
798
798
|
}
|
799
799
|
} else if (node.type === "JSXExpressionContainer") if (node.expression.type === "ConditionalExpression") return processConditionalExpression(node.expression, context);
|
800
800
|
else if (node.expression.type === "LogicalExpression") return processLogicalExpression(node.expression, context);
|
@@ -854,7 +854,7 @@ function processTextContainer(children, context) {
|
|
854
854
|
function createTextLikeExpressions(nodes, context) {
|
855
855
|
const values = [];
|
856
856
|
for (const node of nodes) {
|
857
|
-
|
857
|
+
markNonTemplate(node, context);
|
858
858
|
if (isEmptyText(node)) continue;
|
859
859
|
values.push(resolveExpression(node, context, !context.inVOnce));
|
860
860
|
}
|
@@ -997,7 +997,10 @@ function processIf(node, attribute, context) {
|
|
997
997
|
let lastIfNode;
|
998
998
|
if (siblings) {
|
999
999
|
let i = siblings.length;
|
1000
|
-
while (i--) if (siblings[i].operation
|
1000
|
+
while (i--) if (siblings[i].operation && siblings[i].operation.type === IRNodeTypes.IF) {
|
1001
|
+
lastIfNode = siblings[i].operation;
|
1002
|
+
break;
|
1003
|
+
}
|
1001
1004
|
}
|
1002
1005
|
if (!siblingIf || !lastIfNode || lastIfNode.type !== IRNodeTypes.IF) {
|
1003
1006
|
context.options.onError(createCompilerError(ErrorCodes.X_V_ELSE_NO_ADJACENT_IF, resolveLocation(node.loc, context)));
|
@@ -1381,8 +1384,8 @@ function getBaseTransformPreset() {
|
|
1381
1384
|
transformVIf,
|
1382
1385
|
transformVFor,
|
1383
1386
|
transformTemplateRef,
|
1384
|
-
transformText,
|
1385
1387
|
transformElement,
|
1388
|
+
transformText,
|
1386
1389
|
transformVSlot,
|
1387
1390
|
transformChildren
|
1388
1391
|
], {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vue-jsx-vapor/compiler",
|
3
|
-
"version": "2.4.
|
3
|
+
"version": "2.4.7",
|
4
4
|
"description": "Vue JSX Vapor Compiler",
|
5
5
|
"type": "module",
|
6
6
|
"keywords": [
|
@@ -34,11 +34,11 @@
|
|
34
34
|
"./*": "./*"
|
35
35
|
},
|
36
36
|
"dependencies": {
|
37
|
-
"@babel/parser": "^7.27.
|
38
|
-
"@babel/types": "^7.27.
|
39
|
-
"@vue/compiler-dom": "https://pkg.pr.new/@vue/compiler-dom@
|
40
|
-
"@vue/compiler-vapor": "https://pkg.pr.new/@vue/compiler-vapor@
|
41
|
-
"@vue/shared": "https://pkg.pr.new/@vue/shared@
|
37
|
+
"@babel/parser": "^7.27.7",
|
38
|
+
"@babel/types": "^7.27.7",
|
39
|
+
"@vue/compiler-dom": "https://pkg.pr.new/@vue/compiler-dom@715b798",
|
40
|
+
"@vue/compiler-vapor": "https://pkg.pr.new/@vue/compiler-vapor@715b798",
|
41
|
+
"@vue/shared": "https://pkg.pr.new/@vue/shared@715b798"
|
42
42
|
},
|
43
43
|
"scripts": {
|
44
44
|
"build": "tsdown",
|