@wevu/compiler 6.16.17 → 6.16.19
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 +12 -0
- package/dist/index.mjs +78 -25
- package/package.json +5 -5
package/dist/index.d.mts
CHANGED
|
@@ -205,6 +205,7 @@ interface MiniProgramPlatform {
|
|
|
205
205
|
}
|
|
206
206
|
//#endregion
|
|
207
207
|
//#region src/plugins/vue/compiler/template/types.d.ts
|
|
208
|
+
type FunctionPropNameMatcher = string | RegExp;
|
|
208
209
|
/**
|
|
209
210
|
* 作用域插槽组件资源描述。
|
|
210
211
|
*/
|
|
@@ -287,6 +288,7 @@ interface TemplateCompileOptions {
|
|
|
287
288
|
formatWxml?: boolean;
|
|
288
289
|
wxsExtension?: string;
|
|
289
290
|
classStyleWxsSrc?: string;
|
|
291
|
+
functionPropNames?: Iterable<FunctionPropNameMatcher>;
|
|
290
292
|
wevuComponentTags?: Iterable<string>;
|
|
291
293
|
}
|
|
292
294
|
/**
|
|
@@ -447,6 +449,10 @@ interface CompileVueFileOptions {
|
|
|
447
449
|
astEngine?: AstEngineName$1;
|
|
448
450
|
isPage?: boolean;
|
|
449
451
|
isApp?: boolean;
|
|
452
|
+
/**
|
|
453
|
+
* 是否压缩生成的 wevu 脚本输出。
|
|
454
|
+
*/
|
|
455
|
+
minify?: boolean;
|
|
450
456
|
warn?: (message: string) => void;
|
|
451
457
|
autoUsingComponents?: AutoUsingComponentsOptions;
|
|
452
458
|
autoImportTags?: AutoImportTagsOptions;
|
|
@@ -667,6 +673,10 @@ interface TransformScriptOptions {
|
|
|
667
673
|
* wevu 默认值(仅用于 app.vue 注入)
|
|
668
674
|
*/
|
|
669
675
|
wevuDefaults?: WevuDefaults;
|
|
676
|
+
/**
|
|
677
|
+
* 是否压缩生成的脚本代码。
|
|
678
|
+
*/
|
|
679
|
+
minify?: boolean;
|
|
670
680
|
/**
|
|
671
681
|
* 编译期警告回调
|
|
672
682
|
*/
|
|
@@ -802,6 +812,7 @@ declare function injectWevuPageFeatureFlagsIntoOptionsObject(optionsObject: t.Ob
|
|
|
802
812
|
*/
|
|
803
813
|
declare function injectWevuPageFeaturesInJs(source: string, options?: {
|
|
804
814
|
astEngine?: AstEngineName$1;
|
|
815
|
+
minify?: boolean;
|
|
805
816
|
}): {
|
|
806
817
|
code: string;
|
|
807
818
|
transformed: boolean;
|
|
@@ -814,6 +825,7 @@ declare function injectWevuPageFeaturesInJsWithResolver(source: string, options:
|
|
|
814
825
|
id: string;
|
|
815
826
|
resolver: ModuleResolver;
|
|
816
827
|
astEngine?: AstEngineName$1;
|
|
828
|
+
minify?: boolean;
|
|
817
829
|
}): Promise<{
|
|
818
830
|
code: string;
|
|
819
831
|
transformed: boolean;
|
package/dist/index.mjs
CHANGED
|
@@ -1615,7 +1615,9 @@ function injectWevuPageFeaturesInJs(source, options) {
|
|
|
1615
1615
|
transformed: false
|
|
1616
1616
|
};
|
|
1617
1617
|
const generated = generate(ast, {
|
|
1618
|
-
|
|
1618
|
+
compact: options?.minify === true,
|
|
1619
|
+
minified: options?.minify === true,
|
|
1620
|
+
retainLines: options?.minify !== true,
|
|
1619
1621
|
sourceMaps: true,
|
|
1620
1622
|
sourceFileName: "inline.js"
|
|
1621
1623
|
}, source);
|
|
@@ -1661,7 +1663,9 @@ async function injectWevuPageFeaturesInJsWithResolver(source, options) {
|
|
|
1661
1663
|
transformed: false
|
|
1662
1664
|
};
|
|
1663
1665
|
const generated = generate(ast, {
|
|
1664
|
-
|
|
1666
|
+
compact: options?.minify === true,
|
|
1667
|
+
minified: options?.minify === true,
|
|
1668
|
+
retainLines: options?.minify !== true,
|
|
1665
1669
|
sourceMaps: true,
|
|
1666
1670
|
sourceFileName: "inline.js"
|
|
1667
1671
|
}, source);
|
|
@@ -2231,16 +2235,23 @@ function createValidIdentifier(name, fallback) {
|
|
|
2231
2235
|
if (name && t.isValidIdentifier(name)) return t.identifier(name);
|
|
2232
2236
|
return t.identifier(fallback);
|
|
2233
2237
|
}
|
|
2238
|
+
function buildConsoleErrorGuard(message, errorId) {
|
|
2239
|
+
return t.ifStatement(t.logicalExpression("&&", t.binaryExpression("!==", t.unaryExpression("typeof", t.identifier("console")), t.stringLiteral("undefined")), t.binaryExpression("===", t.unaryExpression("typeof", t.memberExpression(t.identifier("console"), t.identifier("error"))), t.stringLiteral("function"))), t.blockStatement([t.expressionStatement(t.callExpression(t.memberExpression(t.identifier("console"), t.identifier("error")), [t.stringLiteral(message), t.cloneNode(errorId)]))]));
|
|
2240
|
+
}
|
|
2241
|
+
function buildRuntimeExpressionErrorGuard(binding, errorId) {
|
|
2242
|
+
return buildConsoleErrorGuard(`[wevu] 模板运行时表达式执行失败: ${binding.name} = ${binding.exp}`, errorId);
|
|
2243
|
+
}
|
|
2234
2244
|
function buildNormalizedExpression(binding, helpers) {
|
|
2245
|
+
const errorId = t.identifier(WEVU_EXPRESSION_ERROR_IDENTIFIER);
|
|
2235
2246
|
if (binding.type === "bind") {
|
|
2236
2247
|
const exp = binding.expAst ? t.cloneNode(binding.expAst, true) : t.identifier("undefined");
|
|
2237
|
-
return t.callExpression(t.arrowFunctionExpression([], t.blockStatement([t.tryStatement(t.blockStatement([t.returnStatement(exp)]), t.catchClause(t.
|
|
2248
|
+
return t.callExpression(t.arrowFunctionExpression([], t.blockStatement([t.tryStatement(t.blockStatement([t.returnStatement(exp)]), t.catchClause(t.cloneNode(errorId), t.blockStatement([buildRuntimeExpressionErrorGuard(binding, errorId), t.returnStatement(t.identifier("undefined"))])), null)])), []);
|
|
2238
2249
|
}
|
|
2239
2250
|
const normalizeHelper = binding.type === "class" ? helpers.normalizeClass : helpers.normalizeStyle;
|
|
2240
2251
|
const errorFallback = binding.errorFallback ?? "";
|
|
2241
2252
|
const exp = binding.expAst ? t.cloneNode(binding.expAst, true) : t.stringLiteral("");
|
|
2242
2253
|
const normalizedCall = t.callExpression(t.cloneNode(normalizeHelper), [exp]);
|
|
2243
|
-
return t.callExpression(t.arrowFunctionExpression([], t.blockStatement([t.tryStatement(t.blockStatement([t.returnStatement(normalizedCall)]), t.catchClause(t.
|
|
2254
|
+
return t.callExpression(t.arrowFunctionExpression([], t.blockStatement([t.tryStatement(t.blockStatement([t.returnStatement(normalizedCall)]), t.catchClause(t.cloneNode(errorId), t.blockStatement([buildRuntimeExpressionErrorGuard(binding, errorId), t.returnStatement(t.stringLiteral(errorFallback))])), null)])), []);
|
|
2244
2255
|
}
|
|
2245
2256
|
function buildArrayMapExpression(binding, forStack, level, listId, helpers) {
|
|
2246
2257
|
const itemParam = createValidIdentifier(forStack[level].item, `__wv_item_${level}`);
|
|
@@ -2288,7 +2299,7 @@ function buildForExpression(binding, forStack, level, helpers) {
|
|
|
2288
2299
|
const unrefHelper = helpers.unref ? t.cloneNode(helpers.unref) : t.identifier("unref");
|
|
2289
2300
|
const listUnrefExp = t.callExpression(unrefHelper, [listExp]);
|
|
2290
2301
|
const listDecl = t.variableDeclaration("let", [t.variableDeclarator(listId, t.arrayExpression([]))]);
|
|
2291
|
-
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);
|
|
2302
|
+
const listSafeAssign = t.tryStatement(t.blockStatement([t.expressionStatement(t.assignmentExpression("=", listId, listUnrefExp))]), t.catchClause(t.identifier(`__wv_err_${level}`), t.blockStatement([buildConsoleErrorGuard(`[wevu] 模板 v-for 数据源表达式执行失败: ${info.listExp}`, t.identifier(`__wv_err_${level}`)), t.expressionStatement(t.assignmentExpression("=", listId, t.arrayExpression([])))])), null);
|
|
2292
2303
|
const arrayCheck = t.callExpression(t.memberExpression(t.identifier("Array"), t.identifier("isArray")), [listId]);
|
|
2293
2304
|
const arrayMap = buildArrayMapExpression(binding, forStack, level, listId, helpers);
|
|
2294
2305
|
const objectCheck = t.logicalExpression("&&", t.binaryExpression("!=", listId, t.nullLiteral()), t.binaryExpression("===", t.unaryExpression("typeof", listId), t.stringLiteral("object")));
|
|
@@ -2991,7 +3002,9 @@ function transformScript(source, options) {
|
|
|
2991
3002
|
transformed: false
|
|
2992
3003
|
};
|
|
2993
3004
|
const generated = generate(ast, {
|
|
2994
|
-
|
|
3005
|
+
compact: options?.minify === true,
|
|
3006
|
+
minified: options?.minify === true,
|
|
3007
|
+
retainLines: options?.minify !== true,
|
|
2995
3008
|
sourceMaps: true,
|
|
2996
3009
|
sourceFileName: "inline.ts"
|
|
2997
3010
|
}, source);
|
|
@@ -3288,26 +3301,49 @@ function stripRenderOptionFromScript(source, filename, warn) {
|
|
|
3288
3301
|
}
|
|
3289
3302
|
//#endregion
|
|
3290
3303
|
//#region src/plugins/vue/compiler/template/format.ts
|
|
3291
|
-
const TOKEN_RE = /<[^>]+>/g;
|
|
3292
3304
|
function tokenizeWxml(source) {
|
|
3293
3305
|
const tokens = [];
|
|
3294
3306
|
let index = 0;
|
|
3295
|
-
|
|
3296
|
-
const start =
|
|
3307
|
+
while (index < source.length) {
|
|
3308
|
+
const start = source.indexOf("<", index);
|
|
3309
|
+
if (start < 0) {
|
|
3310
|
+
tokens.push({
|
|
3311
|
+
type: "text",
|
|
3312
|
+
value: source.slice(index)
|
|
3313
|
+
});
|
|
3314
|
+
break;
|
|
3315
|
+
}
|
|
3297
3316
|
if (start > index) tokens.push({
|
|
3298
3317
|
type: "text",
|
|
3299
3318
|
value: source.slice(index, start)
|
|
3300
3319
|
});
|
|
3320
|
+
let quote;
|
|
3321
|
+
let end = start + 1;
|
|
3322
|
+
for (; end < source.length; end++) {
|
|
3323
|
+
const char = source[end];
|
|
3324
|
+
if (quote) {
|
|
3325
|
+
if (char === quote) quote = void 0;
|
|
3326
|
+
continue;
|
|
3327
|
+
}
|
|
3328
|
+
if (char === "\"" || char === "'") {
|
|
3329
|
+
quote = char;
|
|
3330
|
+
continue;
|
|
3331
|
+
}
|
|
3332
|
+
if (char === ">") break;
|
|
3333
|
+
}
|
|
3334
|
+
if (end >= source.length) {
|
|
3335
|
+
tokens.push({
|
|
3336
|
+
type: "text",
|
|
3337
|
+
value: source.slice(start)
|
|
3338
|
+
});
|
|
3339
|
+
break;
|
|
3340
|
+
}
|
|
3301
3341
|
tokens.push({
|
|
3302
3342
|
type: "tag",
|
|
3303
|
-
value:
|
|
3343
|
+
value: source.slice(start, end + 1)
|
|
3304
3344
|
});
|
|
3305
|
-
index =
|
|
3345
|
+
index = end + 1;
|
|
3306
3346
|
}
|
|
3307
|
-
if (index < source.length) tokens.push({
|
|
3308
|
-
type: "text",
|
|
3309
|
-
value: source.slice(index)
|
|
3310
|
-
});
|
|
3311
3347
|
return tokens.filter((token) => token.value.length > 0);
|
|
3312
3348
|
}
|
|
3313
3349
|
function isClosingTag(value) {
|
|
@@ -4103,6 +4139,7 @@ async function compileJsxFile(source, filename, options) {
|
|
|
4103
4139
|
skipComponentTransform: options?.isApp,
|
|
4104
4140
|
isApp: options?.isApp,
|
|
4105
4141
|
isPage: options?.isPage,
|
|
4142
|
+
minify: options?.minify,
|
|
4106
4143
|
warn: options?.warn,
|
|
4107
4144
|
wevuDefaults: options?.wevuDefaults,
|
|
4108
4145
|
inlineExpressions
|
|
@@ -6005,6 +6042,23 @@ function isComputedMemberExpression(rawExpValue) {
|
|
|
6005
6042
|
const normalized = unwrapTsExpression(parsed);
|
|
6006
6043
|
return normalized.type === "MemberExpression" && normalized.computed;
|
|
6007
6044
|
}
|
|
6045
|
+
function shouldUseRuntimeFunctionPropBinding(argValue, context) {
|
|
6046
|
+
return context.functionPropNames.some((matcher) => {
|
|
6047
|
+
if (typeof matcher === "string") return matcher === argValue;
|
|
6048
|
+
matcher.lastIndex = 0;
|
|
6049
|
+
return matcher.test(argValue);
|
|
6050
|
+
});
|
|
6051
|
+
}
|
|
6052
|
+
function shouldWrapStaticMemberFunctionProp(argValue, path, context) {
|
|
6053
|
+
return path.includes(".") && shouldUseRuntimeFunctionPropBinding(argValue, context);
|
|
6054
|
+
}
|
|
6055
|
+
function createFunctionPropRuntimeAttr(argValue, rawExpValue, context) {
|
|
6056
|
+
const bindingRef = registerRuntimeBindingExpression(rawExpValue, context, { hint: `:${argValue} 函数 prop 绑定` });
|
|
6057
|
+
if (!bindingRef) return null;
|
|
6058
|
+
const bindingName = bindingRef.split("[")[0] || bindingRef;
|
|
6059
|
+
context.functionPropPaths.add(bindingName);
|
|
6060
|
+
return `${argValue}="${renderMustache(bindingRef, context)}"`;
|
|
6061
|
+
}
|
|
6008
6062
|
function transformBindDirective(node, context, forInfo, options) {
|
|
6009
6063
|
const { arg } = node;
|
|
6010
6064
|
if (!arg) return null;
|
|
@@ -6013,16 +6067,12 @@ function transformBindDirective(node, context, forInfo, options) {
|
|
|
6013
6067
|
if (!rawExpValue) return null;
|
|
6014
6068
|
if (options?.isComponent && !COMPONENT_NON_PROP_BINDINGS.has(argValue)) {
|
|
6015
6069
|
const path = collectFunctionPropPath(rawExpValue);
|
|
6016
|
-
if (path) if (path
|
|
6017
|
-
const
|
|
6018
|
-
if (
|
|
6019
|
-
const bindingName = bindingRef.split("[")[0] || bindingRef;
|
|
6020
|
-
context.functionPropPaths.add(bindingName);
|
|
6021
|
-
return `${argValue}="${renderMustache(bindingRef, context)}"`;
|
|
6022
|
-
}
|
|
6070
|
+
if (path) if (shouldWrapStaticMemberFunctionProp(argValue, path, context)) {
|
|
6071
|
+
const runtimeAttr = createFunctionPropRuntimeAttr(argValue, rawExpValue, context);
|
|
6072
|
+
if (runtimeAttr) return runtimeAttr;
|
|
6023
6073
|
} else context.functionPropPaths.add(path);
|
|
6024
|
-
else if (isComputedMemberExpression(rawExpValue)) {
|
|
6025
|
-
const runtimeAttr =
|
|
6074
|
+
else if (shouldUseRuntimeFunctionPropBinding(argValue, context) && isComputedMemberExpression(rawExpValue)) {
|
|
6075
|
+
const runtimeAttr = createFunctionPropRuntimeAttr(argValue, rawExpValue, context);
|
|
6026
6076
|
if (runtimeAttr) return runtimeAttr;
|
|
6027
6077
|
}
|
|
6028
6078
|
}
|
|
@@ -6623,7 +6673,8 @@ function createScopedSlotComponent(context, slotKey, props, children, transformN
|
|
|
6623
6673
|
forIndexSeed: 0,
|
|
6624
6674
|
inlineExpressions: [],
|
|
6625
6675
|
inlineExpressionSeed: 0,
|
|
6626
|
-
functionPropPaths: /* @__PURE__ */ new Set()
|
|
6676
|
+
functionPropPaths: /* @__PURE__ */ new Set(),
|
|
6677
|
+
functionPropNames: context.functionPropNames
|
|
6627
6678
|
};
|
|
6628
6679
|
let template = withSlotProps(scopedContext, {
|
|
6629
6680
|
...collectScopePropMapping(context),
|
|
@@ -7347,6 +7398,7 @@ function compileVueTemplateToWxml(template, filename, options) {
|
|
|
7347
7398
|
inlineExpressions: [],
|
|
7348
7399
|
inlineExpressionSeed: 0,
|
|
7349
7400
|
functionPropPaths: /* @__PURE__ */ new Set(),
|
|
7401
|
+
functionPropNames: Array.from(options?.functionPropNames ?? []),
|
|
7350
7402
|
wevuComponentTags: options?.wevuComponentTags ? new Set(options.wevuComponentTags) : void 0
|
|
7351
7403
|
};
|
|
7352
7404
|
let wxml = ast.children.map((child) => transformNode(child, context)).join("");
|
|
@@ -8197,6 +8249,7 @@ async function compileScriptPhase(descriptor, descriptorForCompile, filename, op
|
|
|
8197
8249
|
skipComponentTransform: isAppFile,
|
|
8198
8250
|
isApp: isAppFile,
|
|
8199
8251
|
isPage: options?.isPage === true,
|
|
8252
|
+
minify: options?.minify,
|
|
8200
8253
|
warn: options?.warn,
|
|
8201
8254
|
templateComponentMeta: Object.keys(autoComponentMeta).length ? autoComponentMeta : void 0,
|
|
8202
8255
|
wevuDefaults: options?.wevuDefaults,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wevu/compiler",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.16.
|
|
4
|
+
"version": "6.16.19",
|
|
5
5
|
"description": "wevu 编译器基础包,面向小程序模板的编译与转换",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -45,15 +45,15 @@
|
|
|
45
45
|
"@vue/compiler-core": "^3.5.34",
|
|
46
46
|
"@vue/compiler-dom": "^3.5.34",
|
|
47
47
|
"comment-json": "^5.0.0",
|
|
48
|
-
"lru-cache": "^11.
|
|
48
|
+
"lru-cache": "^11.5.0",
|
|
49
49
|
"magic-string": "^0.30.21",
|
|
50
50
|
"merge": "^2.1.1",
|
|
51
51
|
"pathe": "^2.0.3",
|
|
52
52
|
"vue": "^3.5.34",
|
|
53
|
-
"@weapp-core/constants": "
|
|
53
|
+
"@weapp-core/constants": "0.1.8",
|
|
54
54
|
"@weapp-core/shared": "3.0.4",
|
|
55
|
-
"@weapp-vite/ast": "6.16.
|
|
56
|
-
"rolldown-require": "2.0.
|
|
55
|
+
"@weapp-vite/ast": "6.16.19",
|
|
56
|
+
"rolldown-require": "2.0.17"
|
|
57
57
|
},
|
|
58
58
|
"publishConfig": {
|
|
59
59
|
"access": "public",
|