@wevu/compiler 0.0.5 → 0.0.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.d.mts +5 -1
- package/dist/index.mjs +192 -29
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -319,6 +319,9 @@ declare const CLASS_STYLE_WXS_MODULE = "__weapp_vite";
|
|
|
319
319
|
* class/style WXS 文件名(不含扩展名)。
|
|
320
320
|
*/
|
|
321
321
|
declare const CLASS_STYLE_WXS_FILE = "__weapp_vite_class_style";
|
|
322
|
+
interface ClassStyleWxsSourceOptions {
|
|
323
|
+
extension?: string;
|
|
324
|
+
}
|
|
322
325
|
/**
|
|
323
326
|
* 构建 class/style WXS 引用标签。
|
|
324
327
|
*/
|
|
@@ -337,12 +340,13 @@ declare function resolveClassStyleWxsLocation(options: {
|
|
|
337
340
|
/**
|
|
338
341
|
* 获取内置 class/style WXS 运行时代码。
|
|
339
342
|
*/
|
|
340
|
-
declare function getClassStyleWxsSource(): string;
|
|
343
|
+
declare function getClassStyleWxsSource(options?: ClassStyleWxsSourceOptions): string;
|
|
341
344
|
//#endregion
|
|
342
345
|
//#region src/plugins/vue/transform/classStyleComputed.d.ts
|
|
343
346
|
interface ClassStyleHelperNames {
|
|
344
347
|
normalizeClassName: string;
|
|
345
348
|
normalizeStyleName: string;
|
|
349
|
+
unrefName?: string;
|
|
346
350
|
}
|
|
347
351
|
declare function buildClassStyleComputedCode(bindings: ClassStyleBinding[], helpers: ClassStyleHelperNames): string | null;
|
|
348
352
|
//#endregion
|
package/dist/index.mjs
CHANGED
|
@@ -617,23 +617,46 @@ function resolveClassStyleWxsLocation(options) {
|
|
|
617
617
|
/**
|
|
618
618
|
* 获取内置 class/style WXS 运行时代码。
|
|
619
619
|
*/
|
|
620
|
-
function getClassStyleWxsSource() {
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
"var hasOwn = objectCtor && objectCtor.prototype ? objectCtor.prototype.hasOwnProperty : null",
|
|
624
|
-
"",
|
|
620
|
+
function getClassStyleWxsSource(options = {}) {
|
|
621
|
+
const isSjs = (options.extension?.startsWith(".") ? options.extension.slice(1) : options.extension) === "sjs";
|
|
622
|
+
const isArrayFunctionLines = isSjs ? [
|
|
625
623
|
"function isArray(value) {",
|
|
626
|
-
" if (
|
|
627
|
-
" return
|
|
624
|
+
" if (!toString) {",
|
|
625
|
+
" return false",
|
|
628
626
|
" }",
|
|
629
|
-
" return value
|
|
630
|
-
"}"
|
|
627
|
+
" return toString.call(value) === '[object Array]'",
|
|
628
|
+
"}"
|
|
629
|
+
] : [
|
|
630
|
+
"function isArray(value) {",
|
|
631
|
+
" if (!value) {",
|
|
632
|
+
" return false",
|
|
633
|
+
" }",
|
|
634
|
+
" if (typeof Array !== 'undefined' && Array.isArray && Array.isArray(value)) {",
|
|
635
|
+
" return true",
|
|
636
|
+
" }",
|
|
637
|
+
" if (toString && toString.call(value) === '[object Array]') {",
|
|
638
|
+
" return true",
|
|
639
|
+
" }",
|
|
640
|
+
" return typeof value.length === 'number' && typeof value.join === 'function'",
|
|
641
|
+
"}"
|
|
642
|
+
];
|
|
643
|
+
const hyphenateUpperCaseLine = isSjs ? " res += str.charAt(i).toLowerCase()" : " res += String.fromCharCode(code + 32)";
|
|
644
|
+
const bodyLines = [
|
|
645
|
+
"var objectCtor = ({}).constructor",
|
|
646
|
+
"var objectProto = objectCtor ? objectCtor.prototype : null",
|
|
647
|
+
"var hasOwn = objectProto ? objectProto.hasOwnProperty : null",
|
|
648
|
+
"var toString = objectProto ? objectProto.toString : null",
|
|
649
|
+
"",
|
|
650
|
+
...isArrayFunctionLines,
|
|
631
651
|
"",
|
|
632
652
|
"function getObjectKeys(obj) {",
|
|
633
|
-
" if (
|
|
634
|
-
" return
|
|
653
|
+
" if (objectCtor && objectCtor.keys) {",
|
|
654
|
+
" return objectCtor.keys(obj)",
|
|
655
|
+
" }",
|
|
656
|
+
" if (objectCtor && objectCtor.getOwnPropertyNames) {",
|
|
657
|
+
" return objectCtor.getOwnPropertyNames(obj)",
|
|
635
658
|
" }",
|
|
636
|
-
" return
|
|
659
|
+
" return null",
|
|
637
660
|
"}",
|
|
638
661
|
"",
|
|
639
662
|
"function isWordCharCode(code) {",
|
|
@@ -661,7 +684,7 @@ function getClassStyleWxsSource() {
|
|
|
661
684
|
" if (i > 0 && isWordCharCode(str.charCodeAt(i - 1))) {",
|
|
662
685
|
" res += '-'",
|
|
663
686
|
" }",
|
|
664
|
-
|
|
687
|
+
hyphenateUpperCaseLine,
|
|
665
688
|
" continue",
|
|
666
689
|
" }",
|
|
667
690
|
" res += str.charAt(i)",
|
|
@@ -790,12 +813,24 @@ function getClassStyleWxsSource() {
|
|
|
790
813
|
" }",
|
|
791
814
|
" return ''",
|
|
792
815
|
"}",
|
|
793
|
-
""
|
|
816
|
+
""
|
|
817
|
+
];
|
|
818
|
+
const exportLines = isSjs ? [
|
|
819
|
+
"export default {",
|
|
820
|
+
" cls: normalizeClass,",
|
|
821
|
+
" style: normalizeStyle,",
|
|
822
|
+
" stylePair: stylePair,",
|
|
823
|
+
"}"
|
|
824
|
+
] : [
|
|
794
825
|
"module.exports = {",
|
|
795
826
|
" cls: normalizeClass,",
|
|
796
827
|
" style: normalizeStyle,",
|
|
797
828
|
" stylePair: stylePair,",
|
|
798
|
-
"}"
|
|
829
|
+
"}"
|
|
830
|
+
];
|
|
831
|
+
return [
|
|
832
|
+
...bodyLines,
|
|
833
|
+
...exportLines,
|
|
799
834
|
""
|
|
800
835
|
].join("\n");
|
|
801
836
|
}
|
|
@@ -1498,6 +1533,36 @@ function mergeJsExpressionParts(parts) {
|
|
|
1498
1533
|
if (parts.length === 1) return parts[0];
|
|
1499
1534
|
return t.arrayExpression(parts);
|
|
1500
1535
|
}
|
|
1536
|
+
function unwrapTsExpression(node) {
|
|
1537
|
+
if (t.isTSAsExpression(node) || t.isTSNonNullExpression(node) || t.isTSTypeAssertion(node)) return unwrapTsExpression(node.expression);
|
|
1538
|
+
return node;
|
|
1539
|
+
}
|
|
1540
|
+
function shouldPreferJsClassStyleRuntime(exp) {
|
|
1541
|
+
const ast = parseBabelExpression(exp);
|
|
1542
|
+
if (!ast) return true;
|
|
1543
|
+
const visit = (node) => {
|
|
1544
|
+
const current = unwrapTsExpression(node);
|
|
1545
|
+
if (t.isIdentifier(current) || t.isMemberExpression(current) || t.isOptionalMemberExpression(current) || t.isCallExpression(current) || t.isOptionalCallExpression(current) || t.isThisExpression(current) || t.isSuper(current) || t.isAwaitExpression(current) || t.isYieldExpression(current) || t.isNewExpression(current)) return true;
|
|
1546
|
+
if (t.isStringLiteral(current) || t.isNumericLiteral(current) || t.isBooleanLiteral(current) || t.isNullLiteral(current) || t.isBigIntLiteral(current) || t.isRegExpLiteral(current)) return false;
|
|
1547
|
+
if (t.isTemplateLiteral(current)) return current.expressions.some((exp) => visit(exp));
|
|
1548
|
+
if (t.isArrayExpression(current)) {
|
|
1549
|
+
for (const element of current.elements) {
|
|
1550
|
+
if (!element || t.isSpreadElement(element)) return true;
|
|
1551
|
+
if (visit(element)) return true;
|
|
1552
|
+
}
|
|
1553
|
+
return false;
|
|
1554
|
+
}
|
|
1555
|
+
if (t.isObjectExpression(current)) {
|
|
1556
|
+
for (const property of current.properties) if (t.isSpreadElement(property) || !t.isObjectProperty(property)) return true;
|
|
1557
|
+
return false;
|
|
1558
|
+
}
|
|
1559
|
+
if (t.isConditionalExpression(current)) return visit(current.test) || visit(current.consequent) || visit(current.alternate);
|
|
1560
|
+
if (t.isLogicalExpression(current) || t.isBinaryExpression(current)) return visit(current.left) || visit(current.right);
|
|
1561
|
+
if (t.isUnaryExpression(current)) return visit(current.argument);
|
|
1562
|
+
return true;
|
|
1563
|
+
};
|
|
1564
|
+
return visit(ast);
|
|
1565
|
+
}
|
|
1501
1566
|
function createClassStyleBinding(context, type, exp, expAst) {
|
|
1502
1567
|
const index = context.classStyleBindings.length;
|
|
1503
1568
|
return {
|
|
@@ -1513,7 +1578,7 @@ function renderClassAttribute(staticClass, dynamicClassExp, context) {
|
|
|
1513
1578
|
if (!dynamicClassExp) return staticValue ? `class="${staticValue}"` : void 0;
|
|
1514
1579
|
const parts = [];
|
|
1515
1580
|
if (staticValue) parts.push(toWxmlStringLiteral(staticValue));
|
|
1516
|
-
if (context.classStyleRuntime === "wxs") {
|
|
1581
|
+
if (context.classStyleRuntime === "wxs" && !shouldPreferJsClassStyleRuntime(dynamicClassExp)) {
|
|
1517
1582
|
const normalizedParts = normalizeClassBindingExpression(dynamicClassExp, context);
|
|
1518
1583
|
for (const part of normalizedParts) parts.push(`(${part})`);
|
|
1519
1584
|
const mergedExp = parts.length > 1 ? `[${parts.join(",")}]` : parts[0];
|
|
@@ -1535,7 +1600,7 @@ function renderStyleAttribute(staticStyle, dynamicStyleExp, vShowExp, context) {
|
|
|
1535
1600
|
if (!Boolean(dynamicStyleExp || vShowExp)) return staticValue ? `style="${staticValue}"` : void 0;
|
|
1536
1601
|
const parts = [];
|
|
1537
1602
|
if (staticValue) parts.push(toWxmlStringLiteral(staticValue));
|
|
1538
|
-
if (context.classStyleRuntime === "wxs") {
|
|
1603
|
+
if (context.classStyleRuntime === "wxs" && (!dynamicStyleExp || !shouldPreferJsClassStyleRuntime(dynamicStyleExp))) {
|
|
1539
1604
|
if (dynamicStyleExp) {
|
|
1540
1605
|
const normalizedParts = normalizeStyleBindingExpression(dynamicStyleExp, context);
|
|
1541
1606
|
for (const part of normalizedParts) parts.push(`(${part})`);
|
|
@@ -1685,6 +1750,17 @@ function buildInlineScopeAttrs(scopeBindings) {
|
|
|
1685
1750
|
return `data-wv-s${index}="{{${binding.replace(/"/g, """)}}}"`;
|
|
1686
1751
|
});
|
|
1687
1752
|
}
|
|
1753
|
+
function resolveEventPrefix(modifiers) {
|
|
1754
|
+
const hasCatch = modifiers.some((modifier) => modifier.content === "catch");
|
|
1755
|
+
const hasStop = modifiers.some((modifier) => modifier.content === "stop");
|
|
1756
|
+
const hasCapture = modifiers.some((modifier) => modifier.content === "capture");
|
|
1757
|
+
const hasMut = modifiers.some((modifier) => modifier.content === "mut");
|
|
1758
|
+
if ((hasCatch || hasStop) && hasCapture) return "capture-catch";
|
|
1759
|
+
if (hasCatch || hasStop) return "catch";
|
|
1760
|
+
if (hasMut) return "mut-bind";
|
|
1761
|
+
if (hasCapture) return "capture-bind";
|
|
1762
|
+
return "bind";
|
|
1763
|
+
}
|
|
1688
1764
|
function transformOnDirective(node, context) {
|
|
1689
1765
|
const { exp, arg } = node;
|
|
1690
1766
|
if (!arg) return null;
|
|
@@ -1694,7 +1770,8 @@ function transformOnDirective(node, context) {
|
|
|
1694
1770
|
const isInlineExpression = rawExpValue && !isSimpleHandler(rawExpValue);
|
|
1695
1771
|
const inlineExpression = isInlineExpression ? registerInlineExpression(rawExpValue, context) : null;
|
|
1696
1772
|
const mappedEvent = context.platform.mapEventName(argValue);
|
|
1697
|
-
const
|
|
1773
|
+
const eventPrefix = resolveEventPrefix(node.modifiers);
|
|
1774
|
+
const bindAttr = context.platform.eventBindingAttr(`${eventPrefix}:${mappedEvent}`);
|
|
1698
1775
|
if (context.rewriteScopedSlot) {
|
|
1699
1776
|
if (inlineExpression) {
|
|
1700
1777
|
const scopeAttrs = buildInlineScopeAttrs(inlineExpression.scopeBindings);
|
|
@@ -2260,7 +2337,7 @@ function transformForElement(node, context, transformNode) {
|
|
|
2260
2337
|
const forInfo = parseForExpression(forDirective.exp.type === NodeTypes.SIMPLE_EXPRESSION ? forDirective.exp.content : "");
|
|
2261
2338
|
if (context.classStyleRuntime === "js" && !forInfo.index) forInfo.index = `__wv_index_${context.forIndexSeed++}`;
|
|
2262
2339
|
const listExp = forInfo.listExp ? normalizeWxmlExpressionWithContext(forInfo.listExp, context) : void 0;
|
|
2263
|
-
const listExpAst =
|
|
2340
|
+
const listExpAst = forInfo.listExp ? normalizeJsExpressionWithContext(forInfo.listExp, context, { hint: "v-for 列表" }) : void 0;
|
|
2264
2341
|
const scopedForInfo = listExp ? {
|
|
2265
2342
|
...forInfo,
|
|
2266
2343
|
listExp,
|
|
@@ -2436,6 +2513,27 @@ function toOnEventName(eventName) {
|
|
|
2436
2513
|
if (!eventName) return "on";
|
|
2437
2514
|
return `on${(eventName[0] ?? "").toUpperCase()}${eventName.slice(1)}`;
|
|
2438
2515
|
}
|
|
2516
|
+
function parseEventBinding$3(eventName) {
|
|
2517
|
+
const prefixed = /^(bind|catch|capture-bind|capture-catch|mut-bind):(.+)$/.exec(eventName);
|
|
2518
|
+
if (prefixed) return {
|
|
2519
|
+
prefix: prefixed[1],
|
|
2520
|
+
name: prefixed[2]
|
|
2521
|
+
};
|
|
2522
|
+
return {
|
|
2523
|
+
prefix: "bind",
|
|
2524
|
+
name: eventName
|
|
2525
|
+
};
|
|
2526
|
+
}
|
|
2527
|
+
function toAlipayDirectiveEvent(prefix, eventName) {
|
|
2528
|
+
if (!eventName) return "on";
|
|
2529
|
+
const pascalEvent = `${(eventName[0] ?? "").toUpperCase()}${eventName.slice(1)}`;
|
|
2530
|
+
switch (prefix) {
|
|
2531
|
+
case "catch": return `catch${pascalEvent}`;
|
|
2532
|
+
case "capture-bind": return `capture${pascalEvent}`;
|
|
2533
|
+
case "capture-catch": return `captureCatch${pascalEvent}`;
|
|
2534
|
+
default: return toOnEventName(eventName);
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2439
2537
|
/**
|
|
2440
2538
|
* 支付宝小程序平台适配器。
|
|
2441
2539
|
*/
|
|
@@ -2454,8 +2552,9 @@ const alipayPlatform = {
|
|
|
2454
2552
|
keyAttr: (value) => `a:key="${value}"`,
|
|
2455
2553
|
mapEventName: (eventName) => eventMap$3[eventName] || eventName,
|
|
2456
2554
|
eventBindingAttr: (eventName) => {
|
|
2457
|
-
|
|
2458
|
-
|
|
2555
|
+
const { prefix, name } = parseEventBinding$3(eventName);
|
|
2556
|
+
if (name.includes(":")) return `on:${name}`;
|
|
2557
|
+
return toAlipayDirectiveEvent(prefix, name);
|
|
2459
2558
|
}
|
|
2460
2559
|
};
|
|
2461
2560
|
|
|
@@ -2483,6 +2582,17 @@ const eventMap$2 = {
|
|
|
2483
2582
|
longtap: "longtap",
|
|
2484
2583
|
longpress: "longpress"
|
|
2485
2584
|
};
|
|
2585
|
+
function parseEventBinding$2(eventName) {
|
|
2586
|
+
const prefixed = /^(bind|catch|capture-bind|capture-catch|mut-bind):(.+)$/.exec(eventName);
|
|
2587
|
+
if (prefixed) return {
|
|
2588
|
+
prefix: prefixed[1],
|
|
2589
|
+
name: prefixed[2]
|
|
2590
|
+
};
|
|
2591
|
+
return {
|
|
2592
|
+
prefix: "bind",
|
|
2593
|
+
name: eventName
|
|
2594
|
+
};
|
|
2595
|
+
}
|
|
2486
2596
|
/**
|
|
2487
2597
|
* 百度智能小程序平台适配器。
|
|
2488
2598
|
*/
|
|
@@ -2501,7 +2611,14 @@ const swanPlatform = {
|
|
|
2501
2611
|
keyAttr: (value) => `s-key="${value}"`,
|
|
2502
2612
|
mapEventName: (eventName) => eventMap$2[eventName] || eventName,
|
|
2503
2613
|
eventBindingAttr: (eventName) => {
|
|
2504
|
-
|
|
2614
|
+
const { prefix, name } = parseEventBinding$2(eventName);
|
|
2615
|
+
switch (prefix) {
|
|
2616
|
+
case "catch": return name.includes(":") ? `catch:${name}` : `catch${name}`;
|
|
2617
|
+
case "capture-bind": return `capture-bind:${name}`;
|
|
2618
|
+
case "capture-catch": return `capture-catch:${name}`;
|
|
2619
|
+
case "mut-bind": return `mut-bind:${name}`;
|
|
2620
|
+
default: return name.includes(":") ? `bind:${name}` : `bind${name}`;
|
|
2621
|
+
}
|
|
2505
2622
|
}
|
|
2506
2623
|
};
|
|
2507
2624
|
|
|
@@ -2529,6 +2646,17 @@ const eventMap$1 = {
|
|
|
2529
2646
|
longtap: "longtap",
|
|
2530
2647
|
longpress: "longpress"
|
|
2531
2648
|
};
|
|
2649
|
+
function parseEventBinding$1(eventName) {
|
|
2650
|
+
const prefixed = /^(bind|catch|capture-bind|capture-catch|mut-bind):(.+)$/.exec(eventName);
|
|
2651
|
+
if (prefixed) return {
|
|
2652
|
+
prefix: prefixed[1],
|
|
2653
|
+
name: prefixed[2]
|
|
2654
|
+
};
|
|
2655
|
+
return {
|
|
2656
|
+
prefix: "bind",
|
|
2657
|
+
name: eventName
|
|
2658
|
+
};
|
|
2659
|
+
}
|
|
2532
2660
|
/**
|
|
2533
2661
|
* 抖音小程序平台适配器。
|
|
2534
2662
|
*/
|
|
@@ -2547,7 +2675,14 @@ const ttPlatform = {
|
|
|
2547
2675
|
keyAttr: (value) => `tt:key="${value}"`,
|
|
2548
2676
|
mapEventName: (eventName) => eventMap$1[eventName] || eventName,
|
|
2549
2677
|
eventBindingAttr: (eventName) => {
|
|
2550
|
-
|
|
2678
|
+
const { prefix, name } = parseEventBinding$1(eventName);
|
|
2679
|
+
switch (prefix) {
|
|
2680
|
+
case "catch": return name.includes(":") ? `catch:${name}` : `catch${name}`;
|
|
2681
|
+
case "capture-bind": return `capture-bind:${name}`;
|
|
2682
|
+
case "capture-catch": return `capture-catch:${name}`;
|
|
2683
|
+
case "mut-bind": return `mut-bind:${name}`;
|
|
2684
|
+
default: return name.includes(":") ? `bind:${name}` : `bind${name}`;
|
|
2685
|
+
}
|
|
2551
2686
|
}
|
|
2552
2687
|
};
|
|
2553
2688
|
|
|
@@ -2575,6 +2710,17 @@ const eventMap = {
|
|
|
2575
2710
|
longtap: "longtap",
|
|
2576
2711
|
longpress: "longpress"
|
|
2577
2712
|
};
|
|
2713
|
+
function parseEventBinding(eventName) {
|
|
2714
|
+
const prefixed = /^(bind|catch|capture-bind|capture-catch|mut-bind):(.+)$/.exec(eventName);
|
|
2715
|
+
if (prefixed) return {
|
|
2716
|
+
prefix: prefixed[1],
|
|
2717
|
+
name: prefixed[2]
|
|
2718
|
+
};
|
|
2719
|
+
return {
|
|
2720
|
+
prefix: "bind",
|
|
2721
|
+
name: eventName
|
|
2722
|
+
};
|
|
2723
|
+
}
|
|
2578
2724
|
/**
|
|
2579
2725
|
* 微信小程序平台适配器。
|
|
2580
2726
|
*/
|
|
@@ -2593,7 +2739,14 @@ const wechatPlatform = {
|
|
|
2593
2739
|
keyAttr: (value) => `wx:key="${value}"`,
|
|
2594
2740
|
mapEventName: (eventName) => eventMap[eventName] || eventName,
|
|
2595
2741
|
eventBindingAttr: (eventName) => {
|
|
2596
|
-
|
|
2742
|
+
const { prefix, name } = parseEventBinding(eventName);
|
|
2743
|
+
switch (prefix) {
|
|
2744
|
+
case "catch": return name.includes(":") ? `catch:${name}` : `catch${name}`;
|
|
2745
|
+
case "capture-bind": return `capture-bind:${name}`;
|
|
2746
|
+
case "capture-catch": return `capture-catch:${name}`;
|
|
2747
|
+
case "mut-bind": return `mut-bind:${name}`;
|
|
2748
|
+
default: return name.includes(":") ? `bind:${name}` : `bind${name}`;
|
|
2749
|
+
}
|
|
2597
2750
|
}
|
|
2598
2751
|
};
|
|
2599
2752
|
|
|
@@ -2737,13 +2890,20 @@ function buildForExpression(binding, forStack, level, helpers) {
|
|
|
2737
2890
|
const info = forStack[level];
|
|
2738
2891
|
const listId = t.identifier(`__wv_list_${level}`);
|
|
2739
2892
|
const listExp = info.listExpAst ? t.cloneNode(info.listExpAst, true) : t.arrayExpression([]);
|
|
2740
|
-
const
|
|
2893
|
+
const unrefHelper = helpers.unref ? t.cloneNode(helpers.unref) : t.identifier("unref");
|
|
2894
|
+
const listUnrefExp = t.callExpression(unrefHelper, [listExp]);
|
|
2895
|
+
const listDecl = t.variableDeclaration("let", [t.variableDeclarator(listId, t.arrayExpression([]))]);
|
|
2896
|
+
const listSafeAssign = t.tryStatement(t.blockStatement([t.expressionStatement(t.assignmentExpression("=", listId, listUnrefExp))]), t.catchClause(t.identifier(`__wv_err_${level}`), t.blockStatement([t.expressionStatement(t.assignmentExpression("=", listId, t.arrayExpression([])))])), null);
|
|
2741
2897
|
const arrayCheck = t.callExpression(t.memberExpression(t.identifier("Array"), t.identifier("isArray")), [listId]);
|
|
2742
2898
|
const arrayMap = buildArrayMapExpression(binding, forStack, level, listId, helpers);
|
|
2743
2899
|
const objectCheck = t.logicalExpression("&&", t.binaryExpression("!=", listId, t.nullLiteral()), t.binaryExpression("===", t.unaryExpression("typeof", listId), t.stringLiteral("object")));
|
|
2744
2900
|
const objectBlock = buildObjectMapExpression(binding, forStack, level, listId, helpers);
|
|
2745
2901
|
const fallbackReturn = t.returnStatement(t.arrayExpression([]));
|
|
2746
|
-
const body = t.blockStatement([
|
|
2902
|
+
const body = t.blockStatement([
|
|
2903
|
+
listDecl,
|
|
2904
|
+
listSafeAssign,
|
|
2905
|
+
t.ifStatement(arrayCheck, t.blockStatement([t.returnStatement(arrayMap)]), t.ifStatement(objectCheck, objectBlock, t.blockStatement([fallbackReturn])))
|
|
2906
|
+
]);
|
|
2747
2907
|
return t.callExpression(t.arrowFunctionExpression([], body), []);
|
|
2748
2908
|
}
|
|
2749
2909
|
function buildComputedFunctionBody(binding, helpers) {
|
|
@@ -2770,7 +2930,8 @@ function buildClassStyleComputedCode(bindings, helpers) {
|
|
|
2770
2930
|
if (!bindings.length) return null;
|
|
2771
2931
|
const obj = buildClassStyleComputedObject(bindings, {
|
|
2772
2932
|
normalizeClass: t.identifier(helpers.normalizeClassName),
|
|
2773
|
-
normalizeStyle: t.identifier(helpers.normalizeStyleName)
|
|
2933
|
+
normalizeStyle: t.identifier(helpers.normalizeStyleName),
|
|
2934
|
+
unref: t.identifier(helpers.unrefName ?? "unref")
|
|
2774
2935
|
});
|
|
2775
2936
|
if (!obj) return null;
|
|
2776
2937
|
const { code } = generate(obj, { compact: true });
|
|
@@ -4668,7 +4829,8 @@ function injectClassStyleComputed(optionsObject, bindings, warn) {
|
|
|
4668
4829
|
const warnHandler = resolveWarnHandler(warn);
|
|
4669
4830
|
const entries = buildClassStyleComputedEntries(bindings, {
|
|
4670
4831
|
normalizeClass: t.identifier("__wevuNormalizeClass"),
|
|
4671
|
-
normalizeStyle: t.identifier("__wevuNormalizeStyle")
|
|
4832
|
+
normalizeStyle: t.identifier("__wevuNormalizeStyle"),
|
|
4833
|
+
unref: t.identifier("__wevuUnref")
|
|
4672
4834
|
});
|
|
4673
4835
|
if (!entries.length) return false;
|
|
4674
4836
|
const computedProp = getObjectPropertyByKey(optionsObject, "computed");
|
|
@@ -4690,6 +4852,7 @@ function injectClassStyleComputed(optionsObject, bindings, warn) {
|
|
|
4690
4852
|
function ensureClassStyleRuntimeImports(program) {
|
|
4691
4853
|
ensureRuntimeImport(program, "normalizeClass", "__wevuNormalizeClass");
|
|
4692
4854
|
ensureRuntimeImport(program, "normalizeStyle", "__wevuNormalizeStyle");
|
|
4855
|
+
ensureRuntimeImport(program, "unref", "__wevuUnref");
|
|
4693
4856
|
}
|
|
4694
4857
|
|
|
4695
4858
|
//#endregion
|
|
@@ -4926,7 +5089,7 @@ function rewriteDefaultExport(ast, state, options, enabledPageFeatures, serializ
|
|
|
4926
5089
|
parsedWevuDefaults,
|
|
4927
5090
|
options
|
|
4928
5091
|
}) || transformed;
|
|
4929
|
-
const classStyleBindings = options?.
|
|
5092
|
+
const classStyleBindings = options?.classStyleBindings ?? [];
|
|
4930
5093
|
if (classStyleBindings.length) if (componentExpr && t.isObjectExpression(componentExpr)) {
|
|
4931
5094
|
ensureClassStyleRuntimeImports(ast.program);
|
|
4932
5095
|
transformed = injectClassStyleComputed(componentExpr, classStyleBindings, warn) || transformed;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wevu/compiler",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.7",
|
|
5
5
|
"description": "wevu 编译器基础包,面向小程序模板的编译与转换",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -45,16 +45,16 @@
|
|
|
45
45
|
"@babel/parser": "^7.29.0",
|
|
46
46
|
"@babel/traverse": "^7.29.0",
|
|
47
47
|
"@babel/types": "^7.29.0",
|
|
48
|
-
"@vue/compiler-core": "^3.5.
|
|
48
|
+
"@vue/compiler-core": "^3.5.28",
|
|
49
49
|
"comment-json": "^4.5.1",
|
|
50
50
|
"fs-extra": "^11.3.3",
|
|
51
51
|
"lru-cache": "^11.2.5",
|
|
52
52
|
"magic-string": "^0.30.21",
|
|
53
53
|
"merge": "^2.1.1",
|
|
54
54
|
"pathe": "^2.0.3",
|
|
55
|
-
"vue": "^3.5.
|
|
55
|
+
"vue": "^3.5.28",
|
|
56
56
|
"@weapp-core/shared": "3.0.1",
|
|
57
|
-
"rolldown-require": "2.0.
|
|
57
|
+
"rolldown-require": "2.0.6"
|
|
58
58
|
},
|
|
59
59
|
"publishConfig": {
|
|
60
60
|
"access": "public",
|