@wevu/compiler 6.15.18 → 6.16.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.mjs +39 -7
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -13,7 +13,7 @@ import os from "node:os";
|
|
|
13
13
|
import process from "node:process";
|
|
14
14
|
import { collectFeatureFlagsFromCode, collectJsxImportedComponentsAndDefaultExportFromBabelAst, collectJsxTemplateTagsFromBabelExpression, getRenderPropertyFromComponentOptions, parseJsLikeWithEngine, resolveRenderExpressionFromComponentOptions, toStaticObjectKey, unwrapTypeScriptExpression } from "@weapp-vite/ast";
|
|
15
15
|
import { LRUCache } from "lru-cache";
|
|
16
|
-
import { WEVU_CLASS_STYLE_RUNTIME_FILE, WEVU_CLASS_STYLE_RUNTIME_MODULE, WEVU_EXPRESSION_ERROR_IDENTIFIER, WEVU_INLINE_HANDLER, WEVU_INLINE_MAP_KEY, WEVU_IS_PAGE_KEY, WEVU_LAYOUT_HOSTS_KEY, WEVU_LAYOUT_HOST_ID_PREFIX, WEVU_LAYOUT_HOST_REF_PREFIX, WEVU_MODEL_HANDLER, WEVU_OWNER_HANDLER, WEVU_PROPS_KEY, WEVU_SLOT_NAMES_ATTR, WEVU_SLOT_OWNER_ATTR, WEVU_SLOT_OWNER_ID_ATTR, WEVU_SLOT_OWNER_ID_KEY, WEVU_SLOT_OWNER_ID_PROP, WEVU_SLOT_OWNER_KEY, WEVU_SLOT_PROPS_ATTR, WEVU_SLOT_PROPS_DATA_KEY, WEVU_SLOT_PROPS_KEY, WEVU_SLOT_SCOPE_ATTR, WEVU_SLOT_SCOPE_KEY, WEVU_TEMPLATE_REFS_KEY } from "@weapp-core/constants";
|
|
16
|
+
import { WEVU_CLASS_STYLE_RUNTIME_FILE, WEVU_CLASS_STYLE_RUNTIME_MODULE, WEVU_EXPRESSION_ERROR_IDENTIFIER, WEVU_INLINE_HANDLER, WEVU_INLINE_MAP_KEY, WEVU_IS_PAGE_KEY, WEVU_LAYOUT_HOSTS_KEY, WEVU_LAYOUT_HOST_ID_PREFIX, WEVU_LAYOUT_HOST_REF_PREFIX, WEVU_MODEL_HANDLER, WEVU_OWNER_HANDLER, WEVU_PROPS_KEY, WEVU_SLOT_NAMES_ATTR, WEVU_SLOT_NAMES_PROP, WEVU_SLOT_OWNER_ATTR, WEVU_SLOT_OWNER_ID_ATTR, WEVU_SLOT_OWNER_ID_KEY, WEVU_SLOT_OWNER_ID_PROP, WEVU_SLOT_OWNER_KEY, WEVU_SLOT_PROPS_ATTR, WEVU_SLOT_PROPS_DATA_KEY, WEVU_SLOT_PROPS_KEY, WEVU_SLOT_SCOPE_ATTR, WEVU_SLOT_SCOPE_KEY, WEVU_TEMPLATE_REFS_KEY } from "@weapp-core/constants";
|
|
17
17
|
import { compileScript, parse } from "vue/compiler-sfc";
|
|
18
18
|
import { fileURLToPath } from "node:url";
|
|
19
19
|
import { parse as parse$1 } from "@vue/compiler-dom";
|
|
@@ -6328,6 +6328,16 @@ function stringifySlotName(info, context) {
|
|
|
6328
6328
|
if (info.type === "static") return info.value === "default" ? "'default'" : `'${info.value}'`;
|
|
6329
6329
|
return normalizeWxmlExpressionWithContext(info.exp, context);
|
|
6330
6330
|
}
|
|
6331
|
+
function resolveSlotStaticName(info) {
|
|
6332
|
+
if (info.type === "default") return "default";
|
|
6333
|
+
if (info.type === "static") return info.value || "default";
|
|
6334
|
+
}
|
|
6335
|
+
const SLOT_PRESENCE_IDENTIFIER_RE = /^[A-Z_$][\w$]*$/i;
|
|
6336
|
+
function createSlotPresenceExpression(info) {
|
|
6337
|
+
const slotName = resolveSlotStaticName(info);
|
|
6338
|
+
if (!slotName) return;
|
|
6339
|
+
return `${WEVU_SLOT_NAMES_PROP}&&${SLOT_PRESENCE_IDENTIFIER_RE.test(slotName) ? `${WEVU_SLOT_NAMES_PROP}.${slotName}` : `${WEVU_SLOT_NAMES_PROP}['${slotName.replace(/\\/g, "\\\\").replace(/'/g, "\\'")}']`}`;
|
|
6340
|
+
}
|
|
6331
6341
|
function buildSlotDeclaration(name, propsExp, children, context, options) {
|
|
6332
6342
|
return {
|
|
6333
6343
|
name,
|
|
@@ -6421,7 +6431,12 @@ function transformSlotElement(node, context, transformNode) {
|
|
|
6421
6431
|
const nameAttr = renderSlotNameAttribute(slotNameInfo, context, "name");
|
|
6422
6432
|
if (nameAttr) slotAttrs.push(nameAttr);
|
|
6423
6433
|
const slotAttrString = slotAttrs.length ? ` ${slotAttrs.join(" ")}` : "";
|
|
6424
|
-
|
|
6434
|
+
let slotTag = `<slot${slotAttrString} />`;
|
|
6435
|
+
if (fallbackContent) {
|
|
6436
|
+
const slotPresentExp = createSlotPresenceExpression(slotNameInfo);
|
|
6437
|
+
if (!slotPropsExp && slotPresentExp) slotTag = `${context.platform.wrapIf(slotPresentExp, slotTag, (exp) => renderMustache(exp, context))}${context.platform.wrapElse(fallbackContent)}`;
|
|
6438
|
+
else slotTag = `<slot${slotAttrString}>${fallbackContent}</slot>`;
|
|
6439
|
+
}
|
|
6425
6440
|
if (!slotPropsExp && (context.scopedSlotsRequireProps || slotNameInfo.type !== "default")) return slotTag;
|
|
6426
6441
|
const genericKey = `scoped-slots-${resolveSlotKey(context, slotNameInfo)}`;
|
|
6427
6442
|
context.componentGenerics[genericKey] = true;
|
|
@@ -6432,7 +6447,8 @@ function transformSlotElement(node, context, transformNode) {
|
|
|
6432
6447
|
`${WEVU_SLOT_PROPS_ATTR}="${renderMustache(slotPropsExp, context)}"`
|
|
6433
6448
|
];
|
|
6434
6449
|
if (context.slotMultipleInstance) scopedAttrs.push(`${WEVU_SLOT_SCOPE_ATTR}="${renderMustache(WEVU_SLOT_SCOPE_KEY, context)}"`);
|
|
6435
|
-
|
|
6450
|
+
const scopedTag = `<${genericKey}${scopedAttrs.length ? ` ${scopedAttrs.join(" ")}` : ""} />`;
|
|
6451
|
+
return `${slotTag}${scopedTag}`;
|
|
6436
6452
|
}
|
|
6437
6453
|
function transformSlotElementPlain(node, context, transformNode) {
|
|
6438
6454
|
const slotNameInfo = resolveSlotNameFromSlotElement(node);
|
|
@@ -6477,14 +6493,30 @@ function resolveTemplateSlotCondition(node, context) {
|
|
|
6477
6493
|
function pushSlotNamesAttr(attrs, slotNames, context) {
|
|
6478
6494
|
if (!slotNames.length) return;
|
|
6479
6495
|
const seen = /* @__PURE__ */ new Set();
|
|
6480
|
-
const entries =
|
|
6496
|
+
const entries = /* @__PURE__ */ new Map();
|
|
6481
6497
|
for (const item of slotNames) {
|
|
6482
6498
|
const dedupeKey = `${item.name}:${item.condition ?? ""}`;
|
|
6483
6499
|
if (seen.has(dedupeKey)) continue;
|
|
6484
6500
|
seen.add(dedupeKey);
|
|
6485
|
-
entries.
|
|
6501
|
+
const entry = entries.get(item.name) ?? {
|
|
6502
|
+
conditions: [],
|
|
6503
|
+
unconditional: false
|
|
6504
|
+
};
|
|
6505
|
+
if (item.condition) {
|
|
6506
|
+
if (!entry.unconditional) entry.conditions.push(item.condition);
|
|
6507
|
+
} else {
|
|
6508
|
+
entry.conditions.length = 0;
|
|
6509
|
+
entry.unconditional = true;
|
|
6510
|
+
}
|
|
6511
|
+
entries.set(item.name, entry);
|
|
6512
|
+
}
|
|
6513
|
+
const properties = [];
|
|
6514
|
+
for (const [name, entry] of entries) {
|
|
6515
|
+
const value = entry.conditions.length ? entry.conditions.map((condition) => `(${condition})`).join("||") : "true";
|
|
6516
|
+
properties.push(`[${name}]:${value}`);
|
|
6486
6517
|
}
|
|
6487
|
-
|
|
6518
|
+
const slotNamesRef = registerRuntimeBindingExpression(`{${properties.join(",")}}`, context, { hint: "vue-slots 元数据" });
|
|
6519
|
+
if (slotNamesRef) attrs.push(`${WEVU_SLOT_NAMES_ATTR}="${renderMustache(slotNamesRef, context)}"`);
|
|
6488
6520
|
}
|
|
6489
6521
|
function shouldExposePlainSlotPresence(node) {
|
|
6490
6522
|
return node.tag === "component";
|
|
@@ -6988,7 +7020,7 @@ function normalizeResolvedUsingComponent(result) {
|
|
|
6988
7020
|
return result;
|
|
6989
7021
|
}
|
|
6990
7022
|
function isWevuSfcComponent(result) {
|
|
6991
|
-
return result?.sourceType === "wevu-sfc" || Boolean(result?.resolvedId?.endsWith(".vue"));
|
|
7023
|
+
return result?.sourceType === "wevu-sfc" || Boolean(result?.resolvedId?.endsWith(".vue")) || Boolean(result?.from?.endsWith(".vue"));
|
|
6992
7024
|
}
|
|
6993
7025
|
function isVueSfcSource(source) {
|
|
6994
7026
|
return source.endsWith(".vue");
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wevu/compiler",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.
|
|
4
|
+
"version": "6.16.1",
|
|
5
5
|
"description": "wevu 编译器基础包,面向小程序模板的编译与转换",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"vue": "^3.5.33",
|
|
53
53
|
"@weapp-core/constants": "^0.1.4",
|
|
54
54
|
"@weapp-core/shared": "3.0.4",
|
|
55
|
-
"@weapp-vite/ast": "6.
|
|
55
|
+
"@weapp-vite/ast": "6.16.1",
|
|
56
56
|
"rolldown-require": "2.0.15"
|
|
57
57
|
},
|
|
58
58
|
"publishConfig": {
|