@vue-jsx-vapor/compiler 2.1.0 → 2.1.1
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 +46 -44
- package/dist/index.js +43 -41
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
@@ -268,17 +268,25 @@ function resolveNode(node, context) {
|
|
268
268
|
const props = node.openingElement.attributes.reduce(
|
269
269
|
(result, attr) => {
|
270
270
|
if (attr.type === "JSXAttribute") {
|
271
|
-
|
272
|
-
|
273
|
-
} else {
|
274
|
-
result.push({
|
271
|
+
result.push(
|
272
|
+
_optionalChain([attr, 'access', _9 => _9.value, 'optionalAccess', _10 => _10.type]) === "StringLiteral" ? {
|
275
273
|
type: _compilerdom.NodeTypes.ATTRIBUTE,
|
276
274
|
name: String(attr.name.name),
|
277
275
|
nameLoc: resolveLocation(attr.name.loc, context),
|
278
276
|
value: resolveValue(attr.value, context),
|
279
277
|
loc: resolveLocation(attr.loc, context)
|
280
|
-
})
|
281
|
-
|
278
|
+
} : resolveDirectiveNode(attr, context)
|
279
|
+
);
|
280
|
+
} else if (attr.type === "JSXSpreadAttribute") {
|
281
|
+
result.push({
|
282
|
+
type: _compilerdom.NodeTypes.DIRECTIVE,
|
283
|
+
name: "bind",
|
284
|
+
rawName: getText(attr, context),
|
285
|
+
exp: resolveExpression(attr.argument, context),
|
286
|
+
arg: void 0,
|
287
|
+
loc: resolveLocation(node.loc, context),
|
288
|
+
modifiers: []
|
289
|
+
});
|
282
290
|
}
|
283
291
|
return result;
|
284
292
|
},
|
@@ -300,34 +308,35 @@ var namespaceRE = /^(?:\$([\w-]+)\$)?([\w-]+)?/;
|
|
300
308
|
function resolveDirectiveNode(node, context, withFn = false) {
|
301
309
|
const { value, name } = node;
|
302
310
|
let nameString = name.type === "JSXNamespacedName" ? name.namespace.name : name.type === "JSXIdentifier" ? name.name : "";
|
303
|
-
|
304
|
-
if (name.type !== "JSXNamespacedName" && !argString) {
|
305
|
-
const [newName, modifiers2] = nameString.split("_");
|
306
|
-
nameString = newName;
|
307
|
-
argString = `_${modifiers2}`;
|
308
|
-
}
|
311
|
+
const isDirective = nameString.startsWith("v-");
|
309
312
|
let modifiers = [];
|
310
313
|
let isStatic = true;
|
311
|
-
|
312
|
-
if (
|
313
|
-
|
314
|
-
[,
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
314
|
+
let argString = name.type === "JSXNamespacedName" ? name.name.name : "";
|
315
|
+
if (name.type !== "JSXNamespacedName" && !argString) {
|
316
|
+
;
|
317
|
+
[nameString, ...modifiers] = nameString.split("_");
|
318
|
+
} else {
|
319
|
+
const result = argString.match(namespaceRE);
|
320
|
+
if (result) {
|
321
|
+
let modifierString = "";
|
322
|
+
[, argString, modifierString] = result;
|
323
|
+
if (argString) {
|
324
|
+
argString = argString.replaceAll("_", ".");
|
325
|
+
isStatic = false;
|
326
|
+
if (modifierString && modifierString.startsWith("_"))
|
327
|
+
modifiers = modifierString.slice(1).split("_");
|
328
|
+
} else if (modifierString) {
|
329
|
+
;
|
330
|
+
[argString, ...modifiers] = modifierString.split("_");
|
331
|
+
}
|
323
332
|
}
|
324
333
|
}
|
325
|
-
const arg = argString && name.type === "JSXNamespacedName" ? resolveSimpleExpression(argString, isStatic, name.name.loc) : void 0;
|
334
|
+
const arg = isDirective ? argString && name.type === "JSXNamespacedName" ? resolveSimpleExpression(argString, isStatic, name.name.loc) : void 0 : resolveSimpleExpression(nameString, true, name.loc);
|
326
335
|
const exp = value ? withFn && value.type === "JSXExpressionContainer" ? resolveExpressionWithFn(value.expression, context) : resolveExpression(value, context) : void 0;
|
327
336
|
return {
|
328
337
|
type: _compilerdom.NodeTypes.DIRECTIVE,
|
329
|
-
name: nameString.slice(2),
|
330
|
-
rawName:
|
338
|
+
name: isDirective ? nameString.slice(2) : "bind",
|
339
|
+
rawName: getText(name, context),
|
331
340
|
exp,
|
332
341
|
arg,
|
333
342
|
loc: resolveLocation(node.loc, context),
|
@@ -356,7 +365,7 @@ function isJSXComponent(node) {
|
|
356
365
|
}
|
357
366
|
}
|
358
367
|
function findProp(expression, key) {
|
359
|
-
if (_optionalChain([expression, 'optionalAccess',
|
368
|
+
if (_optionalChain([expression, 'optionalAccess', _11 => _11.type]) === "JSXElement") {
|
360
369
|
for (const attr of expression.openingElement.attributes) {
|
361
370
|
const name = attr.type === "JSXAttribute" && (attr.name.type === "JSXIdentifier" ? attr.name.name : attr.name.type === "JSXNamespacedName" ? attr.name.namespace.name : "").split("_")[0];
|
362
371
|
if (name && (_shared.isString.call(void 0, key) ? name === key : key.test(name))) {
|
@@ -636,6 +645,7 @@ function processDynamicChildren(context) {
|
|
636
645
|
const anchor = prevDynamics[0].anchor = context.increaseId();
|
637
646
|
registerInsertion(prevDynamics, context, anchor);
|
638
647
|
} else {
|
648
|
+
prevDynamics[0].flags -= 2 /* NON_TEMPLATE */;
|
639
649
|
registerInsertion(
|
640
650
|
prevDynamics,
|
641
651
|
context,
|
@@ -649,15 +659,12 @@ function processDynamicChildren(context) {
|
|
649
659
|
}
|
650
660
|
}
|
651
661
|
if (prevDynamics.length) {
|
652
|
-
context
|
653
|
-
type: 9 /* INSERT_NODE */,
|
654
|
-
elements: prevDynamics.map((child) => child.id),
|
655
|
-
parent: context.reference()
|
656
|
-
});
|
662
|
+
registerInsertion(prevDynamics, context);
|
657
663
|
}
|
658
664
|
}
|
659
665
|
function registerInsertion(dynamics, context, anchor) {
|
660
666
|
for (const child of dynamics) {
|
667
|
+
console.log(child);
|
661
668
|
if (child.template != null) {
|
662
669
|
context.registerOperation({
|
663
670
|
type: 9 /* INSERT_NODE */,
|
@@ -665,13 +672,9 @@ function registerInsertion(dynamics, context, anchor) {
|
|
665
672
|
parent: context.reference(),
|
666
673
|
anchor
|
667
674
|
});
|
668
|
-
} else {
|
669
|
-
|
670
|
-
|
671
|
-
op.parent = context.reference();
|
672
|
-
op.anchor = anchor;
|
673
|
-
}
|
674
|
-
}
|
675
|
+
} else if (child.operation && isBlockOperation(child.operation)) {
|
676
|
+
child.operation.parent = context.reference();
|
677
|
+
child.operation.anchor = anchor;
|
675
678
|
}
|
676
679
|
}
|
677
680
|
}
|
@@ -842,7 +845,7 @@ function transformProp(prop, node, context) {
|
|
842
845
|
if (prop.type === "JSXSpreadAttribute") return;
|
843
846
|
let name = prop.name.type === "JSXIdentifier" ? prop.name.name : prop.name.type === "JSXNamespacedName" ? prop.name.namespace.name : "";
|
844
847
|
name = name.split("_")[0];
|
845
|
-
if (!isDirectiveRegex.test(name) && (!prop.value || prop.value.type === "StringLiteral")) {
|
848
|
+
if (!isDirectiveRegex.test(name) && !isEventRegex.test(name) && (!prop.value || prop.value.type === "StringLiteral")) {
|
846
849
|
if (isReservedProp(name)) return;
|
847
850
|
return {
|
848
851
|
key: resolveSimpleExpression(name, true, prop.name.loc),
|
@@ -900,7 +903,7 @@ function mergePropValues(existing, incoming) {
|
|
900
903
|
var transformTemplateRef = (node, context) => {
|
901
904
|
if (node.type !== "JSXElement") return;
|
902
905
|
const dir = findProp(node, "ref");
|
903
|
-
if (!_optionalChain([dir, 'optionalAccess',
|
906
|
+
if (!_optionalChain([dir, 'optionalAccess', _12 => _12.value])) return;
|
904
907
|
context.ir.hasTemplateRef = true;
|
905
908
|
const value = resolveExpression(dir.value, context);
|
906
909
|
return () => {
|
@@ -1046,7 +1049,6 @@ function processInterpolation(context) {
|
|
1046
1049
|
}
|
1047
1050
|
const id = context.reference();
|
1048
1051
|
if (isFragmentNode(parent)) {
|
1049
|
-
context.dynamic.flags |= 4 /* INSERT */ | 2 /* NON_TEMPLATE */;
|
1050
1052
|
context.registerOperation({
|
1051
1053
|
type: 18 /* CREATE_NODES */,
|
1052
1054
|
id,
|
@@ -1597,7 +1599,7 @@ var transformVSlots = (node, context) => {
|
|
1597
1599
|
(attr) => attr.type === "JSXAttribute" && attr.name.name.toString() === "v-slots"
|
1598
1600
|
);
|
1599
1601
|
const vSlotsDir = attributes[vSlotsIndex];
|
1600
|
-
if (vSlotsDir && _optionalChain([vSlotsDir, 'access',
|
1602
|
+
if (vSlotsDir && _optionalChain([vSlotsDir, 'access', _13 => _13.value, 'optionalAccess', _14 => _14.type]) === "JSXExpressionContainer") {
|
1601
1603
|
attributes.splice(vSlotsIndex, 1);
|
1602
1604
|
context.slots = [
|
1603
1605
|
{
|
package/dist/index.js
CHANGED
@@ -268,17 +268,25 @@ function resolveNode(node, context) {
|
|
268
268
|
const props = node.openingElement.attributes.reduce(
|
269
269
|
(result, attr) => {
|
270
270
|
if (attr.type === "JSXAttribute") {
|
271
|
-
|
272
|
-
|
273
|
-
} else {
|
274
|
-
result.push({
|
271
|
+
result.push(
|
272
|
+
attr.value?.type === "StringLiteral" ? {
|
275
273
|
type: NodeTypes.ATTRIBUTE,
|
276
274
|
name: String(attr.name.name),
|
277
275
|
nameLoc: resolveLocation(attr.name.loc, context),
|
278
276
|
value: resolveValue(attr.value, context),
|
279
277
|
loc: resolveLocation(attr.loc, context)
|
280
|
-
})
|
281
|
-
|
278
|
+
} : resolveDirectiveNode(attr, context)
|
279
|
+
);
|
280
|
+
} else if (attr.type === "JSXSpreadAttribute") {
|
281
|
+
result.push({
|
282
|
+
type: NodeTypes.DIRECTIVE,
|
283
|
+
name: "bind",
|
284
|
+
rawName: getText(attr, context),
|
285
|
+
exp: resolveExpression(attr.argument, context),
|
286
|
+
arg: void 0,
|
287
|
+
loc: resolveLocation(node.loc, context),
|
288
|
+
modifiers: []
|
289
|
+
});
|
282
290
|
}
|
283
291
|
return result;
|
284
292
|
},
|
@@ -300,34 +308,35 @@ var namespaceRE = /^(?:\$([\w-]+)\$)?([\w-]+)?/;
|
|
300
308
|
function resolveDirectiveNode(node, context, withFn = false) {
|
301
309
|
const { value, name } = node;
|
302
310
|
let nameString = name.type === "JSXNamespacedName" ? name.namespace.name : name.type === "JSXIdentifier" ? name.name : "";
|
303
|
-
|
304
|
-
if (name.type !== "JSXNamespacedName" && !argString) {
|
305
|
-
const [newName, modifiers2] = nameString.split("_");
|
306
|
-
nameString = newName;
|
307
|
-
argString = `_${modifiers2}`;
|
308
|
-
}
|
311
|
+
const isDirective = nameString.startsWith("v-");
|
309
312
|
let modifiers = [];
|
310
313
|
let isStatic = true;
|
311
|
-
|
312
|
-
if (
|
313
|
-
|
314
|
-
[,
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
314
|
+
let argString = name.type === "JSXNamespacedName" ? name.name.name : "";
|
315
|
+
if (name.type !== "JSXNamespacedName" && !argString) {
|
316
|
+
;
|
317
|
+
[nameString, ...modifiers] = nameString.split("_");
|
318
|
+
} else {
|
319
|
+
const result = argString.match(namespaceRE);
|
320
|
+
if (result) {
|
321
|
+
let modifierString = "";
|
322
|
+
[, argString, modifierString] = result;
|
323
|
+
if (argString) {
|
324
|
+
argString = argString.replaceAll("_", ".");
|
325
|
+
isStatic = false;
|
326
|
+
if (modifierString && modifierString.startsWith("_"))
|
327
|
+
modifiers = modifierString.slice(1).split("_");
|
328
|
+
} else if (modifierString) {
|
329
|
+
;
|
330
|
+
[argString, ...modifiers] = modifierString.split("_");
|
331
|
+
}
|
323
332
|
}
|
324
333
|
}
|
325
|
-
const arg = argString && name.type === "JSXNamespacedName" ? resolveSimpleExpression(argString, isStatic, name.name.loc) : void 0;
|
334
|
+
const arg = isDirective ? argString && name.type === "JSXNamespacedName" ? resolveSimpleExpression(argString, isStatic, name.name.loc) : void 0 : resolveSimpleExpression(nameString, true, name.loc);
|
326
335
|
const exp = value ? withFn && value.type === "JSXExpressionContainer" ? resolveExpressionWithFn(value.expression, context) : resolveExpression(value, context) : void 0;
|
327
336
|
return {
|
328
337
|
type: NodeTypes.DIRECTIVE,
|
329
|
-
name: nameString.slice(2),
|
330
|
-
rawName:
|
338
|
+
name: isDirective ? nameString.slice(2) : "bind",
|
339
|
+
rawName: getText(name, context),
|
331
340
|
exp,
|
332
341
|
arg,
|
333
342
|
loc: resolveLocation(node.loc, context),
|
@@ -636,6 +645,7 @@ function processDynamicChildren(context) {
|
|
636
645
|
const anchor = prevDynamics[0].anchor = context.increaseId();
|
637
646
|
registerInsertion(prevDynamics, context, anchor);
|
638
647
|
} else {
|
648
|
+
prevDynamics[0].flags -= 2 /* NON_TEMPLATE */;
|
639
649
|
registerInsertion(
|
640
650
|
prevDynamics,
|
641
651
|
context,
|
@@ -649,15 +659,12 @@ function processDynamicChildren(context) {
|
|
649
659
|
}
|
650
660
|
}
|
651
661
|
if (prevDynamics.length) {
|
652
|
-
context
|
653
|
-
type: 9 /* INSERT_NODE */,
|
654
|
-
elements: prevDynamics.map((child) => child.id),
|
655
|
-
parent: context.reference()
|
656
|
-
});
|
662
|
+
registerInsertion(prevDynamics, context);
|
657
663
|
}
|
658
664
|
}
|
659
665
|
function registerInsertion(dynamics, context, anchor) {
|
660
666
|
for (const child of dynamics) {
|
667
|
+
console.log(child);
|
661
668
|
if (child.template != null) {
|
662
669
|
context.registerOperation({
|
663
670
|
type: 9 /* INSERT_NODE */,
|
@@ -665,13 +672,9 @@ function registerInsertion(dynamics, context, anchor) {
|
|
665
672
|
parent: context.reference(),
|
666
673
|
anchor
|
667
674
|
});
|
668
|
-
} else {
|
669
|
-
|
670
|
-
|
671
|
-
op.parent = context.reference();
|
672
|
-
op.anchor = anchor;
|
673
|
-
}
|
674
|
-
}
|
675
|
+
} else if (child.operation && isBlockOperation(child.operation)) {
|
676
|
+
child.operation.parent = context.reference();
|
677
|
+
child.operation.anchor = anchor;
|
675
678
|
}
|
676
679
|
}
|
677
680
|
}
|
@@ -842,7 +845,7 @@ function transformProp(prop, node, context) {
|
|
842
845
|
if (prop.type === "JSXSpreadAttribute") return;
|
843
846
|
let name = prop.name.type === "JSXIdentifier" ? prop.name.name : prop.name.type === "JSXNamespacedName" ? prop.name.namespace.name : "";
|
844
847
|
name = name.split("_")[0];
|
845
|
-
if (!isDirectiveRegex.test(name) && (!prop.value || prop.value.type === "StringLiteral")) {
|
848
|
+
if (!isDirectiveRegex.test(name) && !isEventRegex.test(name) && (!prop.value || prop.value.type === "StringLiteral")) {
|
846
849
|
if (isReservedProp(name)) return;
|
847
850
|
return {
|
848
851
|
key: resolveSimpleExpression(name, true, prop.name.loc),
|
@@ -1046,7 +1049,6 @@ function processInterpolation(context) {
|
|
1046
1049
|
}
|
1047
1050
|
const id = context.reference();
|
1048
1051
|
if (isFragmentNode(parent)) {
|
1049
|
-
context.dynamic.flags |= 4 /* INSERT */ | 2 /* NON_TEMPLATE */;
|
1050
1052
|
context.registerOperation({
|
1051
1053
|
type: 18 /* CREATE_NODES */,
|
1052
1054
|
id,
|