@wevu/compiler 6.15.0 → 6.15.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.d.mts +1 -1
- package/dist/index.mjs +63 -56
- package/package.json +3 -2
package/dist/index.d.mts
CHANGED
|
@@ -681,7 +681,7 @@ declare function collectWevuPageFeatureFlagsFromCode(code: string, options?: {
|
|
|
681
681
|
astEngine?: AstEngineName$1;
|
|
682
682
|
}): Set<WevuPageFeatureFlag>;
|
|
683
683
|
//#endregion
|
|
684
|
-
//#region src/plugins/wevu/pageFeatures/moduleAnalysis.d.ts
|
|
684
|
+
//#region src/plugins/wevu/pageFeatures/moduleAnalysis/types.d.ts
|
|
685
685
|
type FunctionLike = t.FunctionDeclaration | t.FunctionExpression | t.ArrowFunctionExpression | t.ObjectMethod | {
|
|
686
686
|
type: string;
|
|
687
687
|
[key: string]: any;
|
package/dist/index.mjs
CHANGED
|
@@ -13,6 +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_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
17
|
import { compileScript, parse } from "vue/compiler-sfc";
|
|
17
18
|
import { fileURLToPath } from "node:url";
|
|
18
19
|
import { parse as parse$1 } from "@vue/compiler-dom";
|
|
@@ -845,7 +846,7 @@ function collectWevuPageFeatureFlagsFromCode(code, options) {
|
|
|
845
846
|
}
|
|
846
847
|
}
|
|
847
848
|
//#endregion
|
|
848
|
-
//#region src/plugins/wevu/pageFeatures/moduleAnalysis.ts
|
|
849
|
+
//#region src/plugins/wevu/pageFeatures/moduleAnalysis/shared.ts
|
|
849
850
|
function createEmptyModuleAnalysis(id, engine) {
|
|
850
851
|
return {
|
|
851
852
|
id,
|
|
@@ -870,6 +871,15 @@ function getFunctionLikeFromExpression(node) {
|
|
|
870
871
|
if (t.isFunctionExpression(node) || t.isArrowFunctionExpression(node)) return node;
|
|
871
872
|
return null;
|
|
872
873
|
}
|
|
874
|
+
function isOxcFunctionLike(node) {
|
|
875
|
+
return node?.type === "FunctionDeclaration" || node?.type === "FunctionExpression" || node?.type === "ArrowFunctionExpression";
|
|
876
|
+
}
|
|
877
|
+
function getImportedSpecifierName(node) {
|
|
878
|
+
if (node?.type === "Identifier") return node.name;
|
|
879
|
+
if ((node?.type === "StringLiteral" || node?.type === "Literal") && typeof node.value === "string") return node.value;
|
|
880
|
+
}
|
|
881
|
+
//#endregion
|
|
882
|
+
//#region src/plugins/wevu/pageFeatures/moduleAnalysis/babel.ts
|
|
873
883
|
function createModuleAnalysis(id, ast) {
|
|
874
884
|
const localFunctions = /* @__PURE__ */ new Map();
|
|
875
885
|
const exports = /* @__PURE__ */ new Map();
|
|
@@ -999,13 +1009,8 @@ function createModuleAnalysis(id, ast) {
|
|
|
999
1009
|
exports
|
|
1000
1010
|
};
|
|
1001
1011
|
}
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
}
|
|
1005
|
-
function getImportedSpecifierName(node) {
|
|
1006
|
-
if (node?.type === "Identifier") return node.name;
|
|
1007
|
-
if ((node?.type === "StringLiteral" || node?.type === "Literal") && typeof node.value === "string") return node.value;
|
|
1008
|
-
}
|
|
1012
|
+
//#endregion
|
|
1013
|
+
//#region src/plugins/wevu/pageFeatures/moduleAnalysis/oxc.ts
|
|
1009
1014
|
function resolveOxcParseFilename(id) {
|
|
1010
1015
|
if (path.extname(id)) return id;
|
|
1011
1016
|
return `${id}.js`;
|
|
@@ -1133,6 +1138,8 @@ function createModuleAnalysisWithOxc(id, code) {
|
|
|
1133
1138
|
exports
|
|
1134
1139
|
};
|
|
1135
1140
|
}
|
|
1141
|
+
//#endregion
|
|
1142
|
+
//#region src/plugins/wevu/pageFeatures/moduleAnalysis/index.ts
|
|
1136
1143
|
function createModuleAnalysisFromCode(id, code, options) {
|
|
1137
1144
|
const engine = options?.astEngine ?? "babel";
|
|
1138
1145
|
const cacheKey = createModuleAnalysisCacheKey(id, engine);
|
|
@@ -2204,13 +2211,13 @@ function createValidIdentifier(name, fallback) {
|
|
|
2204
2211
|
function buildNormalizedExpression(binding, helpers) {
|
|
2205
2212
|
if (binding.type === "bind") {
|
|
2206
2213
|
const exp = binding.expAst ? t.cloneNode(binding.expAst, true) : t.identifier("undefined");
|
|
2207
|
-
return t.callExpression(t.arrowFunctionExpression([], t.blockStatement([t.tryStatement(t.blockStatement([t.returnStatement(exp)]), t.catchClause(t.identifier(
|
|
2214
|
+
return t.callExpression(t.arrowFunctionExpression([], t.blockStatement([t.tryStatement(t.blockStatement([t.returnStatement(exp)]), t.catchClause(t.identifier(WEVU_EXPRESSION_ERROR_IDENTIFIER), t.blockStatement([t.returnStatement(t.identifier("undefined"))])), null)])), []);
|
|
2208
2215
|
}
|
|
2209
2216
|
const normalizeHelper = binding.type === "class" ? helpers.normalizeClass : helpers.normalizeStyle;
|
|
2210
2217
|
const errorFallback = binding.errorFallback ?? "";
|
|
2211
2218
|
const exp = binding.expAst ? t.cloneNode(binding.expAst, true) : t.stringLiteral("");
|
|
2212
2219
|
const normalizedCall = t.callExpression(t.cloneNode(normalizeHelper), [exp]);
|
|
2213
|
-
return t.callExpression(t.arrowFunctionExpression([], t.blockStatement([t.tryStatement(t.blockStatement([t.returnStatement(normalizedCall)]), t.catchClause(t.identifier(
|
|
2220
|
+
return t.callExpression(t.arrowFunctionExpression([], t.blockStatement([t.tryStatement(t.blockStatement([t.returnStatement(normalizedCall)]), t.catchClause(t.identifier(WEVU_EXPRESSION_ERROR_IDENTIFIER), t.blockStatement([t.returnStatement(t.stringLiteral(errorFallback))])), null)])), []);
|
|
2214
2221
|
}
|
|
2215
2222
|
function buildArrayMapExpression(binding, forStack, level, listId, helpers) {
|
|
2216
2223
|
const itemParam = createValidIdentifier(forStack[level].item, `__wv_item_${level}`);
|
|
@@ -2574,7 +2581,7 @@ function buildMethodsMergeFromSpreadSources(componentExpr, inlineMapExpr) {
|
|
|
2574
2581
|
return t.callExpression(t.memberExpression(t.identifier("Object"), t.identifier("assign")), [
|
|
2575
2582
|
t.objectExpression([]),
|
|
2576
2583
|
...spreadSources,
|
|
2577
|
-
t.objectExpression([t.objectProperty(createStaticObjectKey$1(
|
|
2584
|
+
t.objectExpression([t.objectProperty(createStaticObjectKey$1(WEVU_INLINE_MAP_KEY), inlineMapExpr)])
|
|
2578
2585
|
]);
|
|
2579
2586
|
}
|
|
2580
2587
|
function injectInlineExpressions(componentExpr, inlineExpressions) {
|
|
@@ -2587,13 +2594,13 @@ function injectInlineExpressions(componentExpr, inlineExpressions) {
|
|
|
2587
2594
|
componentExpr.properties.push(t.objectProperty(createStaticObjectKey$1("methods"), mergedMethods));
|
|
2588
2595
|
return true;
|
|
2589
2596
|
}
|
|
2590
|
-
componentExpr.properties.push(t.objectProperty(createStaticObjectKey$1("methods"), t.objectExpression([t.objectProperty(createStaticObjectKey$1(
|
|
2597
|
+
componentExpr.properties.push(t.objectProperty(createStaticObjectKey$1("methods"), t.objectExpression([t.objectProperty(createStaticObjectKey$1(WEVU_INLINE_MAP_KEY), inlineMapExpr)])));
|
|
2591
2598
|
return true;
|
|
2592
2599
|
}
|
|
2593
2600
|
if (!t.isObjectExpression(methodsProp.value)) return false;
|
|
2594
|
-
const mapProp = getObjectPropertyByKey$1(methodsProp.value,
|
|
2601
|
+
const mapProp = getObjectPropertyByKey$1(methodsProp.value, WEVU_INLINE_MAP_KEY);
|
|
2595
2602
|
if (!mapProp) {
|
|
2596
|
-
methodsProp.value.properties.push(t.objectProperty(createStaticObjectKey$1(
|
|
2603
|
+
methodsProp.value.properties.push(t.objectProperty(createStaticObjectKey$1(WEVU_INLINE_MAP_KEY), inlineMapExpr));
|
|
2597
2604
|
return true;
|
|
2598
2605
|
}
|
|
2599
2606
|
if (t.isObjectExpression(mapProp.value)) {
|
|
@@ -2616,8 +2623,8 @@ function injectLayoutHosts(optionsObject, bindings, warn) {
|
|
|
2616
2623
|
const warnHandler = resolveWarnHandler(warn);
|
|
2617
2624
|
const entries = bindings.map((binding) => buildLayoutHostEntry(binding));
|
|
2618
2625
|
const hostsArray = t.arrayExpression(entries);
|
|
2619
|
-
const key = createStaticObjectKey$1(
|
|
2620
|
-
const existing = getObjectPropertyByKey$1(optionsObject,
|
|
2626
|
+
const key = createStaticObjectKey$1(WEVU_LAYOUT_HOSTS_KEY);
|
|
2627
|
+
const existing = getObjectPropertyByKey$1(optionsObject, WEVU_LAYOUT_HOSTS_KEY);
|
|
2621
2628
|
if (!existing) {
|
|
2622
2629
|
optionsObject.properties.push(t.objectProperty(key, hostsArray));
|
|
2623
2630
|
return true;
|
|
@@ -2630,7 +2637,7 @@ function injectLayoutHosts(optionsObject, bindings, warn) {
|
|
|
2630
2637
|
existing.value = t.arrayExpression([...entries, t.spreadElement(t.cloneNode(existing.value, true))]);
|
|
2631
2638
|
return true;
|
|
2632
2639
|
}
|
|
2633
|
-
warnHandler(
|
|
2640
|
+
warnHandler(`无法自动注入 layout host 元数据,请手动合并 ${WEVU_LAYOUT_HOSTS_KEY}。`);
|
|
2634
2641
|
return false;
|
|
2635
2642
|
}
|
|
2636
2643
|
//#endregion
|
|
@@ -2754,8 +2761,8 @@ function injectTemplateRefs(optionsObject, bindings, warn) {
|
|
|
2754
2761
|
const warnHandler = resolveWarnHandler(warn);
|
|
2755
2762
|
const entries = bindings.map((binding) => buildTemplateRefEntry(binding));
|
|
2756
2763
|
const refsArray = t.arrayExpression(entries);
|
|
2757
|
-
const key = createStaticObjectKey$1(
|
|
2758
|
-
const existing = getObjectPropertyByKey$1(optionsObject,
|
|
2764
|
+
const key = createStaticObjectKey$1(WEVU_TEMPLATE_REFS_KEY);
|
|
2765
|
+
const existing = getObjectPropertyByKey$1(optionsObject, WEVU_TEMPLATE_REFS_KEY);
|
|
2759
2766
|
if (!existing) {
|
|
2760
2767
|
optionsObject.properties.push(t.objectProperty(key, refsArray));
|
|
2761
2768
|
return true;
|
|
@@ -2768,7 +2775,7 @@ function injectTemplateRefs(optionsObject, bindings, warn) {
|
|
|
2768
2775
|
existing.value = t.arrayExpression([...entries, t.spreadElement(t.cloneNode(existing.value, true))]);
|
|
2769
2776
|
return true;
|
|
2770
2777
|
}
|
|
2771
|
-
warnHandler(
|
|
2778
|
+
warnHandler(`无法自动注入 template ref 元数据,请手动合并 ${WEVU_TEMPLATE_REFS_KEY}。`);
|
|
2772
2779
|
return false;
|
|
2773
2780
|
}
|
|
2774
2781
|
//#endregion
|
|
@@ -2875,9 +2882,9 @@ function rewriteDefaultExport(ast, state, options, enabledPageFeatures, serializ
|
|
|
2875
2882
|
const exportPath = state.defaultExportPath;
|
|
2876
2883
|
const componentExpr = resolveComponentExpression(exportPath.node.declaration, state.defineComponentDecls, state.defineComponentAliases);
|
|
2877
2884
|
const componentOptionsObject = resolveComponentOptionsObject(componentExpr);
|
|
2878
|
-
const hasPageMarker = componentExpr ? hasStaticPropertyInComponentExpression(componentExpr,
|
|
2885
|
+
const hasPageMarker = componentExpr ? hasStaticPropertyInComponentExpression(componentExpr, WEVU_IS_PAGE_KEY, ast.program) : false;
|
|
2879
2886
|
if (componentOptionsObject && options?.isPage && !options?.isApp && !hasPageMarker) {
|
|
2880
|
-
componentOptionsObject.properties.splice(0, 0, t.objectProperty(t.identifier(
|
|
2887
|
+
componentOptionsObject.properties.splice(0, 0, t.objectProperty(t.identifier(WEVU_IS_PAGE_KEY), t.booleanLiteral(true)));
|
|
2881
2888
|
transformed = true;
|
|
2882
2889
|
}
|
|
2883
2890
|
if (componentOptionsObject && enabledPageFeatures.size) transformed = injectWevuPageFeatureFlagsIntoOptionsObject(componentOptionsObject, enabledPageFeatures) || transformed;
|
|
@@ -3638,7 +3645,7 @@ function compileEventAttribute(name, value, context) {
|
|
|
3638
3645
|
if (t.isIdentifier(exp)) return [`${bindAttr}="${escapeAttr(exp.name)}"`];
|
|
3639
3646
|
if (t.isMemberExpression(exp) && !exp.computed && t.isThisExpression(exp.object) && t.isIdentifier(exp.property)) return [`${bindAttr}="${escapeAttr(exp.property.name)}"`];
|
|
3640
3647
|
const inline = registerInlineExpression$1(exp, context);
|
|
3641
|
-
const attrs = [`data-wi-${eventSuffix}="${inline.id}"`, `${bindAttr}="
|
|
3648
|
+
const attrs = [`data-wi-${eventSuffix}="${inline.id}"`, `${bindAttr}="${WEVU_INLINE_HANDLER}"`];
|
|
3642
3649
|
inline.scopeKeys.forEach((scopeKey, index) => {
|
|
3643
3650
|
attrs.push(`data-wv-s${index}="${renderMustache$1(scopeKey, context)}"`);
|
|
3644
3651
|
});
|
|
@@ -4344,11 +4351,11 @@ function generateHash(str) {
|
|
|
4344
4351
|
/**
|
|
4345
4352
|
* class/style WXS 模块名。
|
|
4346
4353
|
*/
|
|
4347
|
-
const CLASS_STYLE_WXS_MODULE =
|
|
4354
|
+
const CLASS_STYLE_WXS_MODULE = WEVU_CLASS_STYLE_RUNTIME_MODULE;
|
|
4348
4355
|
/**
|
|
4349
4356
|
* class/style WXS 文件名(不含扩展名)。
|
|
4350
4357
|
*/
|
|
4351
|
-
const CLASS_STYLE_WXS_FILE =
|
|
4358
|
+
const CLASS_STYLE_WXS_FILE = WEVU_CLASS_STYLE_RUNTIME_FILE;
|
|
4352
4359
|
function resolveScriptModuleTag(extension) {
|
|
4353
4360
|
return (extension.startsWith(".") ? extension.slice(1) : extension) === "sjs" ? "sjs" : "wxs";
|
|
4354
4361
|
}
|
|
@@ -4357,7 +4364,7 @@ function resolveScriptModuleTag(extension) {
|
|
|
4357
4364
|
*/
|
|
4358
4365
|
function buildClassStyleWxsTag(extension, src) {
|
|
4359
4366
|
const normalized = extension.startsWith(".") ? extension.slice(1) : extension;
|
|
4360
|
-
const resolvedSrc = src ??
|
|
4367
|
+
const resolvedSrc = src ?? `./${CLASS_STYLE_WXS_FILE}.${normalized}`;
|
|
4361
4368
|
return `<${resolveScriptModuleTag(normalized)} module="${CLASS_STYLE_WXS_MODULE}" src="${resolvedSrc}"/>`;
|
|
4362
4369
|
}
|
|
4363
4370
|
/**
|
|
@@ -5000,10 +5007,10 @@ const SCOPED_SLOT_GLOBALS = new Set([
|
|
|
5000
5007
|
"encodeURIComponent",
|
|
5001
5008
|
"require",
|
|
5002
5009
|
"arguments",
|
|
5003
|
-
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
|
|
5010
|
+
WEVU_SLOT_OWNER_KEY,
|
|
5011
|
+
WEVU_SLOT_PROPS_KEY,
|
|
5012
|
+
WEVU_SLOT_PROPS_DATA_KEY,
|
|
5013
|
+
WEVU_CLASS_STYLE_RUNTIME_MODULE
|
|
5007
5014
|
]);
|
|
5008
5015
|
function collectScopedSlotLocals(context) {
|
|
5009
5016
|
const locals = /* @__PURE__ */ new Set();
|
|
@@ -5060,10 +5067,10 @@ function rewriteScopedSlotExpression(exp, context) {
|
|
|
5060
5067
|
}
|
|
5061
5068
|
if (locals.has(name)) return;
|
|
5062
5069
|
if (Object.hasOwn(slotProps, name)) {
|
|
5063
|
-
replaceIdentifierWithExpression(path, createMemberAccess(
|
|
5070
|
+
replaceIdentifierWithExpression(path, createMemberAccess(WEVU_SLOT_PROPS_DATA_KEY, slotProps[name]));
|
|
5064
5071
|
return;
|
|
5065
5072
|
}
|
|
5066
|
-
replaceIdentifierWithExpression(path, createMemberAccess(
|
|
5073
|
+
replaceIdentifierWithExpression(path, createMemberAccess(WEVU_SLOT_OWNER_KEY, name));
|
|
5067
5074
|
} });
|
|
5068
5075
|
const stmt = ast.program.body[0];
|
|
5069
5076
|
const updatedExpression = stmt && "expression" in stmt ? stmt.expression : null;
|
|
@@ -5157,7 +5164,7 @@ function normalizeStyleBindingExpression(exp, context) {
|
|
|
5157
5164
|
return null;
|
|
5158
5165
|
};
|
|
5159
5166
|
const buildStylePair = (keyExpr, valueExpr) => {
|
|
5160
|
-
return t.callExpression(t.memberExpression(t.identifier(
|
|
5167
|
+
return t.callExpression(t.memberExpression(t.identifier(WEVU_CLASS_STYLE_RUNTIME_MODULE), t.identifier("stylePair")), [keyExpr, valueExpr]);
|
|
5161
5168
|
};
|
|
5162
5169
|
const visit = (node) => {
|
|
5163
5170
|
if (!node) return;
|
|
@@ -5223,7 +5230,7 @@ const INLINE_GLOBALS = new Set([
|
|
|
5223
5230
|
"encodeURIComponent",
|
|
5224
5231
|
"require",
|
|
5225
5232
|
"arguments",
|
|
5226
|
-
|
|
5233
|
+
WEVU_CLASS_STYLE_RUNTIME_MODULE,
|
|
5227
5234
|
"__wevuUnref",
|
|
5228
5235
|
"globalThis",
|
|
5229
5236
|
"setTimeout",
|
|
@@ -5250,8 +5257,8 @@ function createMemberAccess$1(target, prop) {
|
|
|
5250
5257
|
function resolveSlotPropBinding(slotProps, name) {
|
|
5251
5258
|
if (!Object.hasOwn(slotProps, name)) return null;
|
|
5252
5259
|
const prop = slotProps[name];
|
|
5253
|
-
if (!prop) return
|
|
5254
|
-
return generateExpression(createMemberAccess$1(
|
|
5260
|
+
if (!prop) return WEVU_SLOT_PROPS_DATA_KEY;
|
|
5261
|
+
return generateExpression(createMemberAccess$1(WEVU_SLOT_PROPS_DATA_KEY, prop));
|
|
5255
5262
|
}
|
|
5256
5263
|
function rewriteExpressionAst(ast, locals, options) {
|
|
5257
5264
|
traverse(ast, {
|
|
@@ -5434,12 +5441,12 @@ function createHasOwnPropertyCall(target, key) {
|
|
|
5434
5441
|
}
|
|
5435
5442
|
function createIdentifierAccessWithPropsFallback(name) {
|
|
5436
5443
|
if (name === "props") {
|
|
5437
|
-
const propsObject = createThisMemberAccess(
|
|
5444
|
+
const propsObject = createThisMemberAccess(WEVU_PROPS_KEY);
|
|
5438
5445
|
return t.conditionalExpression(t.binaryExpression("!=", propsObject, t.nullLiteral()), propsObject, createThisMemberAccess("props"));
|
|
5439
5446
|
}
|
|
5440
5447
|
const thisAccess = createThisMemberAccess(name);
|
|
5441
|
-
const propsAccess = createMemberAccess(createThisMemberAccess(
|
|
5442
|
-
const propsObject = createThisMemberAccess(
|
|
5448
|
+
const propsAccess = createMemberAccess(createThisMemberAccess(WEVU_PROPS_KEY), name);
|
|
5449
|
+
const propsObject = createThisMemberAccess(WEVU_PROPS_KEY);
|
|
5443
5450
|
const stateObject = createThisMemberAccess("$state");
|
|
5444
5451
|
const hasPropsObject = t.binaryExpression("!=", propsObject, t.nullLiteral());
|
|
5445
5452
|
const hasDefinedPropsValue = t.binaryExpression("!==", propsAccess, t.identifier("undefined"));
|
|
@@ -5496,10 +5503,10 @@ function normalizeJsExpressionWithContext(exp, context, options) {
|
|
|
5496
5503
|
let replacement;
|
|
5497
5504
|
if (context.rewriteScopedSlot) if (Object.hasOwn(slotProps, name)) {
|
|
5498
5505
|
const prop = slotProps[name];
|
|
5499
|
-
const base = createThisMemberAccess(
|
|
5506
|
+
const base = createThisMemberAccess(WEVU_SLOT_PROPS_DATA_KEY);
|
|
5500
5507
|
replacement = createUnrefCall(prop ? createMemberAccess(base, prop) : base);
|
|
5501
|
-
} else if (name ===
|
|
5502
|
-
else replacement = createUnrefCall(createMemberAccess(createThisMemberAccess(
|
|
5508
|
+
} else if (name === WEVU_SLOT_OWNER_KEY || name === WEVU_SLOT_PROPS_DATA_KEY || name === WEVU_SLOT_PROPS_KEY || name === WEVU_SLOT_SCOPE_KEY) replacement = createUnrefCall(createThisMemberAccess(name));
|
|
5509
|
+
else replacement = createUnrefCall(createMemberAccess(createThisMemberAccess(WEVU_SLOT_OWNER_KEY), name));
|
|
5503
5510
|
else replacement = createUnrefCall(createIdentifierAccessWithPropsFallback(name));
|
|
5504
5511
|
const parent = path.parentPath;
|
|
5505
5512
|
if (parent.isObjectProperty() && parent.node.shorthand && parent.node.key === path.node) {
|
|
@@ -5650,7 +5657,7 @@ function renderClassAttribute(staticClass, dynamicClassExp, context) {
|
|
|
5650
5657
|
for (const part of normalizedParts) parts.push(`(${part})`);
|
|
5651
5658
|
const mergedExp = parts.length > 1 ? `[${parts.join(",")}]` : parts[0];
|
|
5652
5659
|
context.classStyleWxs = true;
|
|
5653
|
-
return `class="${renderMustache(
|
|
5660
|
+
return `class="${renderMustache(`${WEVU_CLASS_STYLE_RUNTIME_MODULE}.cls(${mergedExp})`, context)}"`;
|
|
5654
5661
|
}
|
|
5655
5662
|
const jsParts = [];
|
|
5656
5663
|
if (staticValue) jsParts.push(t.stringLiteral(staticValue));
|
|
@@ -5678,7 +5685,7 @@ function renderStyleAttribute(staticStyle, dynamicStyleExp, vShowExp, context) {
|
|
|
5678
5685
|
}
|
|
5679
5686
|
const mergedExp = parts.length > 1 ? `[${parts.join(",")}]` : parts[0] || "''";
|
|
5680
5687
|
context.classStyleWxs = true;
|
|
5681
|
-
return `style="${renderMustache(
|
|
5688
|
+
return `style="${renderMustache(`${WEVU_CLASS_STYLE_RUNTIME_MODULE}.style(${mergedExp})`, context)}"`;
|
|
5682
5689
|
}
|
|
5683
5690
|
const jsParts = [];
|
|
5684
5691
|
if (staticValue) jsParts.push(t.stringLiteral(staticValue));
|
|
@@ -5811,7 +5818,7 @@ const QUOTE_RE$1 = /"/g;
|
|
|
5811
5818
|
function transformVModel(element, expValue, context) {
|
|
5812
5819
|
const escapedModel = expValue.replace(QUOTE_RE$1, """);
|
|
5813
5820
|
const bindModel = (event) => {
|
|
5814
|
-
return `${context.platform.eventBindingAttr(event)}="
|
|
5821
|
+
return `${context.platform.eventBindingAttr(event)}="${WEVU_MODEL_HANDLER}" data-wv-model="${escapedModel}"`;
|
|
5815
5822
|
};
|
|
5816
5823
|
if (!element) return `value="${renderMustache(expValue, context)}" ${bindModel("input")}`;
|
|
5817
5824
|
const tag = element.tag;
|
|
@@ -5891,17 +5898,17 @@ function transformOnDirective(node, context, options) {
|
|
|
5891
5898
|
`data-wi-${eventSuffix}="${inlineExpression.id}"`,
|
|
5892
5899
|
...scopeAttrs,
|
|
5893
5900
|
...indexAttrs,
|
|
5894
|
-
`${bindAttr}="
|
|
5901
|
+
`${bindAttr}="${WEVU_OWNER_HANDLER}"`
|
|
5895
5902
|
].filter(Boolean).join(" ");
|
|
5896
5903
|
}
|
|
5897
5904
|
if (!isInlineExpression && rawExpValue) return [
|
|
5898
5905
|
detailAttr,
|
|
5899
5906
|
`data-wh-${eventSuffix}="${rawExpValue}"`,
|
|
5900
|
-
`${bindAttr}="
|
|
5907
|
+
`${bindAttr}="${WEVU_OWNER_HANDLER}"`
|
|
5901
5908
|
].filter(Boolean).join(" ");
|
|
5902
5909
|
if (isInlineExpression) {
|
|
5903
5910
|
context.warnings.push("作用域插槽的事件处理解析失败,请使用简单的方法引用。");
|
|
5904
|
-
return [detailAttr, `${bindAttr}="
|
|
5911
|
+
return [detailAttr, `${bindAttr}="${WEVU_OWNER_HANDLER}"`].filter(Boolean).join(" ");
|
|
5905
5912
|
}
|
|
5906
5913
|
}
|
|
5907
5914
|
const expValue = normalizeWxmlExpressionWithContext(rawExpValue, context);
|
|
@@ -5913,13 +5920,13 @@ function transformOnDirective(node, context, options) {
|
|
|
5913
5920
|
`data-wi-${eventSuffix}="${inlineExpression.id}"`,
|
|
5914
5921
|
...scopeAttrs,
|
|
5915
5922
|
...indexAttrs,
|
|
5916
|
-
`${bindAttr}="
|
|
5923
|
+
`${bindAttr}="${WEVU_INLINE_HANDLER}"`
|
|
5917
5924
|
].filter(Boolean).join(" ");
|
|
5918
5925
|
}
|
|
5919
5926
|
if (isInlineExpression) return [
|
|
5920
5927
|
detailAttr,
|
|
5921
5928
|
`data-wv-inline-${eventSuffix}="${inlineSource.replace(QUOTE_RE, """)}"`,
|
|
5922
|
-
`${bindAttr}="
|
|
5929
|
+
`${bindAttr}="${WEVU_INLINE_HANDLER}"`
|
|
5923
5930
|
].filter(Boolean).join(" ");
|
|
5924
5931
|
return [detailAttr, `${bindAttr}="${expValue}"`].filter(Boolean).join(" ");
|
|
5925
5932
|
}
|
|
@@ -6053,8 +6060,8 @@ function collectElementAttributes(node, context, options) {
|
|
|
6053
6060
|
if (layoutHostKey) if (!staticId && hasDynamicIdBinding) context.warnings.push("layout-host 暂不支持与动态 id 同时使用,当前节点已忽略。");
|
|
6054
6061
|
else {
|
|
6055
6062
|
const hostIndex = context.layoutHostIndexSeed++;
|
|
6056
|
-
const hostId = staticId ||
|
|
6057
|
-
const hostRefName =
|
|
6063
|
+
const hostId = staticId || `${WEVU_LAYOUT_HOST_ID_PREFIX}${hostIndex}`;
|
|
6064
|
+
const hostRefName = `${WEVU_LAYOUT_HOST_REF_PREFIX}${hostIndex}`;
|
|
6058
6065
|
staticId = hostId;
|
|
6059
6066
|
context.templateRefs.push({
|
|
6060
6067
|
selector: `#${hostId}`,
|
|
@@ -6290,8 +6297,8 @@ function transformSlotElement(node, context, transformNode) {
|
|
|
6290
6297
|
const genericKey = `scoped-slots-${resolveSlotKey(context, slotNameInfo)}`;
|
|
6291
6298
|
context.componentGenerics[genericKey] = true;
|
|
6292
6299
|
slotPropsExp = slotPropsExp ?? "[]";
|
|
6293
|
-
const scopedAttrs = [
|
|
6294
|
-
if (context.slotMultipleInstance) scopedAttrs.push(
|
|
6300
|
+
const scopedAttrs = [`${WEVU_SLOT_OWNER_ATTR}="${renderMustache(WEVU_SLOT_OWNER_ID_PROP, context)}"`, `${WEVU_SLOT_PROPS_ATTR}="${renderMustache(slotPropsExp, context)}"`];
|
|
6301
|
+
if (context.slotMultipleInstance) scopedAttrs.push(`${WEVU_SLOT_SCOPE_ATTR}="${renderMustache(WEVU_SLOT_SCOPE_KEY, context)}"`);
|
|
6295
6302
|
return `${slotTag}${`<${genericKey}${scopedAttrs.length ? ` ${scopedAttrs.join(" ")}` : ""} />`}`;
|
|
6296
6303
|
}
|
|
6297
6304
|
function transformSlotElementPlain(node, context, transformNode) {
|
|
@@ -6372,8 +6379,8 @@ function transformComponentWithSlots(node, context, transformNode, options) {
|
|
|
6372
6379
|
if (slotNames.length) mergedAttrs.push(`vue-slots="${renderMustache(`[${slotNames.join(",")}]`, context)}"`);
|
|
6373
6380
|
if (scopedSlotDeclarations.length) {
|
|
6374
6381
|
const scopePropsExp = buildScopePropsExpression(context);
|
|
6375
|
-
if (scopePropsExp) mergedAttrs.push(
|
|
6376
|
-
mergedAttrs.push(
|
|
6382
|
+
if (scopePropsExp) mergedAttrs.push(`${WEVU_SLOT_SCOPE_ATTR}="${renderMustache(scopePropsExp, context)}"`);
|
|
6383
|
+
mergedAttrs.push(`${WEVU_SLOT_OWNER_ID_ATTR}="${renderMustache(`${WEVU_SLOT_OWNER_ID_KEY} || ''`, context)}"`);
|
|
6377
6384
|
}
|
|
6378
6385
|
const attrString = mergedAttrs.length ? ` ${mergedAttrs.join(" ")}` : "";
|
|
6379
6386
|
const { tag } = node;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wevu/compiler",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.15.
|
|
4
|
+
"version": "6.15.1",
|
|
5
5
|
"description": "wevu 编译器基础包,面向小程序模板的编译与转换",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -49,8 +49,9 @@
|
|
|
49
49
|
"merge": "^2.1.1",
|
|
50
50
|
"pathe": "^2.0.3",
|
|
51
51
|
"vue": "^3.5.32",
|
|
52
|
+
"@weapp-core/constants": "0.1.0",
|
|
52
53
|
"@weapp-core/shared": "3.0.3",
|
|
53
|
-
"@weapp-vite/ast": "6.15.
|
|
54
|
+
"@weapp-vite/ast": "6.15.1",
|
|
54
55
|
"rolldown-require": "2.0.13"
|
|
55
56
|
},
|
|
56
57
|
"publishConfig": {
|