weapp-vite 6.7.2 → 6.7.4
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/auto-import-components/resolvers.mjs +1 -1
- package/dist/auto-routes.d.ts +10 -2
- package/dist/auto-routes.mjs +40 -7
- package/dist/{chunk-W5TTICYZ.mjs → chunk-3ULSPLMB.mjs} +2 -2
- package/dist/{chunk-XEK4R57H.mjs → chunk-72Q2Z45L.mjs} +1 -1
- package/dist/{chunk-2Q4QRCG5.mjs → chunk-7ZOXQLE2.mjs} +1 -1
- package/dist/{chunk-LVU2OZUF.mjs → chunk-ASAY7IOT.mjs} +2 -2
- package/dist/{chunk-QBSVUTNO.mjs → chunk-BQM4WPKJ.mjs} +2 -2
- package/dist/{chunk-FVM35BZA.mjs → chunk-MKXI5POD.mjs} +767 -43
- package/dist/{chunk-O4WHKAL4.mjs → chunk-MXJF2FFF.mjs} +1 -1
- package/dist/{chunk-IWKOTXCO.mjs → chunk-SE5GHZVY.mjs} +1 -1
- package/dist/{chunk-3STNMT72.mjs → chunk-VZEM2LX3.mjs} +1 -1
- package/dist/{chunk-7JSOF7N2.mjs → chunk-ZVP3HDW7.mjs} +2 -2
- package/dist/cli.mjs +6 -6
- package/dist/{config-D2DJI97q.d.ts → config-DMCmCacG.d.ts} +11 -1
- package/dist/config.d.ts +2 -2
- package/dist/config.mjs +3 -3
- package/dist/{file-X4XT4UCA.mjs → file-IRTTGBIN.mjs} +2 -2
- package/dist/{getInstance-FVRAZQTP.mjs → getInstance-NUZWXHEY.mjs} +4 -4
- package/dist/index.d.ts +3 -3
- package/dist/index.mjs +9 -9
- package/dist/json.d.ts +2 -2
- package/dist/json.mjs +2 -2
- package/dist/mcp.d.ts +2 -2
- package/dist/mcp.mjs +3 -3
- package/dist/{routes-C9hKJjXs.d.ts → routes-74eLuiqj.d.ts} +1 -0
- package/dist/runtime.mjs +2 -2
- package/dist/types.d.ts +2 -2
- package/dist/types.mjs +2 -2
- package/dist/volar.mjs +1 -1
- package/package.json +7 -7
|
@@ -14,16 +14,16 @@ import {
|
|
|
14
14
|
templateExtensions,
|
|
15
15
|
touch,
|
|
16
16
|
vueExtensions
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-3ULSPLMB.mjs";
|
|
18
18
|
import {
|
|
19
19
|
configureLogger,
|
|
20
20
|
default as default2
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-VZEM2LX3.mjs";
|
|
22
22
|
import {
|
|
23
23
|
__commonJS,
|
|
24
24
|
__toESM,
|
|
25
25
|
init_esm_shims
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-BQM4WPKJ.mjs";
|
|
27
27
|
|
|
28
28
|
// ../../node_modules/.pnpm/semver@7.7.4/node_modules/semver/internal/debug.js
|
|
29
29
|
var require_debug = __commonJS({
|
|
@@ -3018,6 +3018,13 @@ var JSON_TYPE_ALIASES = {
|
|
|
3018
3018
|
Null: "null",
|
|
3019
3019
|
Any: "any"
|
|
3020
3020
|
};
|
|
3021
|
+
function mergeTypeCandidates(candidates) {
|
|
3022
|
+
const merged = candidates.filter((item) => Boolean(item)).flatMap((item) => item.split("|").map((part) => part.trim()).filter(Boolean));
|
|
3023
|
+
if (merged.length === 0) {
|
|
3024
|
+
return void 0;
|
|
3025
|
+
}
|
|
3026
|
+
return Array.from(new Set(merged)).join(" | ");
|
|
3027
|
+
}
|
|
3021
3028
|
function normalizeJsonPropertyType(raw) {
|
|
3022
3029
|
if (typeof raw === "string") {
|
|
3023
3030
|
const key = raw.trim();
|
|
@@ -3028,12 +3035,10 @@ function normalizeJsonPropertyType(raw) {
|
|
|
3028
3035
|
return normalized.length > 0 ? normalized.join(" | ") : void 0;
|
|
3029
3036
|
}
|
|
3030
3037
|
if (raw && typeof raw === "object") {
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
return normalizeJsonPropertyType(raw.optionalTypes);
|
|
3036
|
-
}
|
|
3038
|
+
return mergeTypeCandidates([
|
|
3039
|
+
raw.type !== void 0 ? normalizeJsonPropertyType(raw.type) : void 0,
|
|
3040
|
+
Array.isArray(raw.optionalTypes) ? normalizeJsonPropertyType(raw.optionalTypes) : void 0
|
|
3041
|
+
]);
|
|
3037
3042
|
}
|
|
3038
3043
|
return void 0;
|
|
3039
3044
|
}
|
|
@@ -3049,7 +3054,7 @@ function extractJsonPropMetadata(json) {
|
|
|
3049
3054
|
}
|
|
3050
3055
|
for (const [propName, rawConfig] of Object.entries(properties)) {
|
|
3051
3056
|
const config = rawConfig ?? {};
|
|
3052
|
-
const type = normalizeJsonPropertyType(
|
|
3057
|
+
const type = normalizeJsonPropertyType(rawConfig) ?? "any";
|
|
3053
3058
|
props.set(propName, type);
|
|
3054
3059
|
const description = config.description;
|
|
3055
3060
|
if (typeof description === "string" && description.trim().length > 0) {
|
|
@@ -8077,6 +8082,8 @@ init_esm_shims();
|
|
|
8077
8082
|
// src/runtime/autoRoutesPlugin/routes/format.ts
|
|
8078
8083
|
init_esm_shims();
|
|
8079
8084
|
var INDENT = " ";
|
|
8085
|
+
var TS_STRING_PLACEHOLDER = "${string}";
|
|
8086
|
+
var TS_PATH_PLACEHOLDER = "${Path}";
|
|
8080
8087
|
function formatTuple(values, baseIndent = "") {
|
|
8081
8088
|
if (values.length === 0) {
|
|
8082
8089
|
return "[]";
|
|
@@ -8099,6 +8106,7 @@ function formatSubPackagesTuple(subPackages, baseIndent = "") {
|
|
|
8099
8106
|
lines.push(`${fieldIndent}readonly root: ${JSON.stringify(pkg.root)};`);
|
|
8100
8107
|
const pages = formatTuple(pkg.pages, fieldIndent);
|
|
8101
8108
|
lines.push(`${fieldIndent}readonly pages: ${pages};`);
|
|
8109
|
+
lines.push(`${fieldIndent}[k: string]: unknown;`);
|
|
8102
8110
|
lines.push(`${objectIndent}}${index < subPackages.length - 1 ? "," : ""}`);
|
|
8103
8111
|
});
|
|
8104
8112
|
lines.push(`${baseIndent}]`);
|
|
@@ -8114,6 +8122,8 @@ function createTypedRouterDefinition(routes) {
|
|
|
8114
8122
|
"// oxlint-disable",
|
|
8115
8123
|
"// ------",
|
|
8116
8124
|
"// \u7531 weapp-vite \u81EA\u52A8\u751F\u6210\uFF0C\u8BF7\u52FF\u7F16\u8F91\u3002",
|
|
8125
|
+
"import 'wevu/router';",
|
|
8126
|
+
"",
|
|
8117
8127
|
"declare module 'weapp-vite/auto-routes' {",
|
|
8118
8128
|
` export type AutoRoutesPages = ${pagesType};`,
|
|
8119
8129
|
` export type AutoRoutesEntries = ${entriesType};`,
|
|
@@ -8124,12 +8134,33 @@ function createTypedRouterDefinition(routes) {
|
|
|
8124
8134
|
" readonly entries: AutoRoutesEntries;",
|
|
8125
8135
|
" readonly subPackages: AutoRoutesSubPackages;",
|
|
8126
8136
|
" }",
|
|
8137
|
+
" export type AutoRouteEntry = AutoRoutesEntries[number];",
|
|
8138
|
+
` export type AutoRoutesRelativeUrl = \`./${TS_STRING_PLACEHOLDER}\` | \`../${TS_STRING_PLACEHOLDER}\`;`,
|
|
8139
|
+
` export type AutoRoutesAbsoluteUrl<Path extends string> = Path | \`/${TS_PATH_PLACEHOLDER}\` | \`${TS_PATH_PLACEHOLDER}?${TS_STRING_PLACEHOLDER}\` | \`/${TS_PATH_PLACEHOLDER}?${TS_STRING_PLACEHOLDER}\`;`,
|
|
8140
|
+
" export type AutoRoutesUrl = AutoRoutesAbsoluteUrl<AutoRouteEntry> | AutoRoutesRelativeUrl;",
|
|
8141
|
+
" export type AutoRouteNavigateOption = {",
|
|
8142
|
+
" readonly url: AutoRoutesUrl;",
|
|
8143
|
+
" } & Record<string, any>;",
|
|
8144
|
+
" export interface AutoRoutesWxRouter {",
|
|
8145
|
+
" switchTab: (option: AutoRouteNavigateOption) => unknown;",
|
|
8146
|
+
" reLaunch: (option: AutoRouteNavigateOption) => unknown;",
|
|
8147
|
+
" redirectTo: (option: AutoRouteNavigateOption) => unknown;",
|
|
8148
|
+
" navigateTo: (option: AutoRouteNavigateOption) => unknown;",
|
|
8149
|
+
" navigateBack: (option?: Record<string, any>) => unknown;",
|
|
8150
|
+
" }",
|
|
8127
8151
|
" export const routes: AutoRoutes;",
|
|
8128
8152
|
" export const pages: AutoRoutesPages;",
|
|
8129
8153
|
" export const entries: AutoRoutesEntries;",
|
|
8130
8154
|
" export const subPackages: AutoRoutesSubPackages;",
|
|
8155
|
+
" export const wxRouter: AutoRoutesWxRouter;",
|
|
8131
8156
|
" export default routes;",
|
|
8132
8157
|
"}",
|
|
8158
|
+
"",
|
|
8159
|
+
"declare module 'wevu/router' {",
|
|
8160
|
+
" interface WevuTypedRouterRouteMap {",
|
|
8161
|
+
" entries: import('weapp-vite/auto-routes').AutoRoutesEntries[number];",
|
|
8162
|
+
" }",
|
|
8163
|
+
"}",
|
|
8133
8164
|
""
|
|
8134
8165
|
].join("\n");
|
|
8135
8166
|
}
|
|
@@ -8291,7 +8322,26 @@ async function scanRoutes(ctx, candidatesMap) {
|
|
|
8291
8322
|
"const pages = routes.pages;",
|
|
8292
8323
|
"const entries = routes.entries;",
|
|
8293
8324
|
"const subPackages = routes.subPackages;",
|
|
8294
|
-
"
|
|
8325
|
+
"const resolveMiniProgramGlobal = () => (globalThis.wx ?? globalThis.tt ?? globalThis.my);",
|
|
8326
|
+
"const callRouteMethod = (methodName, option) => {",
|
|
8327
|
+
" const miniProgramGlobal = resolveMiniProgramGlobal();",
|
|
8328
|
+
" const routeMethod = miniProgramGlobal?.[methodName];",
|
|
8329
|
+
' if (typeof routeMethod !== "function") {',
|
|
8330
|
+
' throw new Error("[weapp-vite] \u5F53\u524D\u8FD0\u884C\u73AF\u5883\u4E0D\u652F\u6301\u8DEF\u7531\u65B9\u6CD5: " + methodName);',
|
|
8331
|
+
" }",
|
|
8332
|
+
" if (option === undefined) {",
|
|
8333
|
+
" return routeMethod.call(miniProgramGlobal);",
|
|
8334
|
+
" }",
|
|
8335
|
+
" return routeMethod.call(miniProgramGlobal, option);",
|
|
8336
|
+
"};",
|
|
8337
|
+
"const wxRouter = {",
|
|
8338
|
+
' switchTab(option) { return callRouteMethod("switchTab", option); },',
|
|
8339
|
+
' reLaunch(option) { return callRouteMethod("reLaunch", option); },',
|
|
8340
|
+
' redirectTo(option) { return callRouteMethod("redirectTo", option); },',
|
|
8341
|
+
' navigateTo(option) { return callRouteMethod("navigateTo", option); },',
|
|
8342
|
+
' navigateBack(option) { return callRouteMethod("navigateBack", option); },',
|
|
8343
|
+
"};",
|
|
8344
|
+
"export { routes, pages, entries, subPackages, wxRouter };",
|
|
8295
8345
|
"export default routes;"
|
|
8296
8346
|
].join("\n");
|
|
8297
8347
|
return {
|
|
@@ -8350,22 +8400,22 @@ function matchesRouteFile(ctx, candidate) {
|
|
|
8350
8400
|
if (!pathWithoutQuery) {
|
|
8351
8401
|
return false;
|
|
8352
8402
|
}
|
|
8353
|
-
const
|
|
8354
|
-
|
|
8355
|
-
|
|
8356
|
-
|
|
8357
|
-
const relative3 = toPosixPath(path20.relative(
|
|
8358
|
-
if (!relative3 || relative3.startsWith("..")) {
|
|
8403
|
+
const normalizedSrcRoot = normalizePath(configService.absoluteSrcRoot);
|
|
8404
|
+
const normalizedCandidate = normalizePath(
|
|
8405
|
+
path20.isAbsolute(pathWithoutQuery) ? pathWithoutQuery : path20.resolve(configService.cwd, pathWithoutQuery)
|
|
8406
|
+
);
|
|
8407
|
+
const relative3 = toPosixPath(path20.relative(normalizedSrcRoot, normalizedCandidate));
|
|
8408
|
+
if (!relative3 || relative3.startsWith("..") || path20.isAbsolute(relative3)) {
|
|
8359
8409
|
return false;
|
|
8360
8410
|
}
|
|
8361
8411
|
const isPagesPath = relative3.startsWith("pages/") || relative3.includes("/pages/");
|
|
8362
8412
|
if (!isPagesPath) {
|
|
8363
8413
|
return false;
|
|
8364
8414
|
}
|
|
8365
|
-
if (isConfigFile(
|
|
8415
|
+
if (isConfigFile(normalizedCandidate)) {
|
|
8366
8416
|
return true;
|
|
8367
8417
|
}
|
|
8368
|
-
if (isVueFile(
|
|
8418
|
+
if (isVueFile(normalizedCandidate) || isScriptFile(normalizedCandidate) || isTemplateFile(normalizedCandidate) || isStyleFile(normalizedCandidate)) {
|
|
8369
8419
|
return true;
|
|
8370
8420
|
}
|
|
8371
8421
|
return false;
|
|
@@ -8424,13 +8474,11 @@ async function updateCandidateFromFile(ctx, stateCandidates, filePath, event, ma
|
|
|
8424
8474
|
return true;
|
|
8425
8475
|
}
|
|
8426
8476
|
const absolutePath = path20.isAbsolute(pathWithoutQuery) ? pathWithoutQuery : path20.resolve(ctx.configService.cwd, pathWithoutQuery);
|
|
8427
|
-
|
|
8428
|
-
|
|
8429
|
-
|
|
8430
|
-
|
|
8431
|
-
|
|
8432
|
-
const relativeBase = toPosixPath(path20.relative(ctx.configService.absoluteSrcRoot, base));
|
|
8433
|
-
if (!relativeBase || relativeBase.startsWith("..")) {
|
|
8477
|
+
const normalizedSrcRoot = normalizePath(ctx.configService.absoluteSrcRoot);
|
|
8478
|
+
const normalizedAbsolutePath = normalizePath(absolutePath);
|
|
8479
|
+
const base = removeExtensionDeep5(normalizedAbsolutePath);
|
|
8480
|
+
const relativeBase = toPosixPath(path20.relative(normalizedSrcRoot, base));
|
|
8481
|
+
if (!relativeBase || relativeBase.startsWith("..") || path20.isAbsolute(relativeBase)) {
|
|
8434
8482
|
markNeedsFullRescan?.();
|
|
8435
8483
|
return true;
|
|
8436
8484
|
}
|
|
@@ -8487,7 +8535,26 @@ function createAutoRoutesService(ctx) {
|
|
|
8487
8535
|
"const pages = routes.pages;",
|
|
8488
8536
|
"const entries = routes.entries;",
|
|
8489
8537
|
"const subPackages = routes.subPackages;",
|
|
8490
|
-
"
|
|
8538
|
+
"const resolveMiniProgramGlobal = () => (globalThis.wx ?? globalThis.tt ?? globalThis.my);",
|
|
8539
|
+
"const callRouteMethod = (methodName, option) => {",
|
|
8540
|
+
" const miniProgramGlobal = resolveMiniProgramGlobal();",
|
|
8541
|
+
" const routeMethod = miniProgramGlobal?.[methodName];",
|
|
8542
|
+
' if (typeof routeMethod !== "function") {',
|
|
8543
|
+
' throw new Error("[weapp-vite] \u5F53\u524D\u8FD0\u884C\u73AF\u5883\u4E0D\u652F\u6301\u8DEF\u7531\u65B9\u6CD5: " + methodName);',
|
|
8544
|
+
" }",
|
|
8545
|
+
" if (option === undefined) {",
|
|
8546
|
+
" return routeMethod.call(miniProgramGlobal);",
|
|
8547
|
+
" }",
|
|
8548
|
+
" return routeMethod.call(miniProgramGlobal, option);",
|
|
8549
|
+
"};",
|
|
8550
|
+
"const wxRouter = {",
|
|
8551
|
+
' switchTab(option) { return callRouteMethod("switchTab", option); },',
|
|
8552
|
+
' reLaunch(option) { return callRouteMethod("reLaunch", option); },',
|
|
8553
|
+
' redirectTo(option) { return callRouteMethod("redirectTo", option); },',
|
|
8554
|
+
' navigateTo(option) { return callRouteMethod("navigateTo", option); },',
|
|
8555
|
+
' navigateBack(option) { return callRouteMethod("navigateBack", option); },',
|
|
8556
|
+
"};",
|
|
8557
|
+
"export { routes, pages, entries, subPackages, wxRouter };",
|
|
8491
8558
|
"export default routes;"
|
|
8492
8559
|
].join("\n");
|
|
8493
8560
|
updateWatchTargets(state.watchFiles, /* @__PURE__ */ new Set());
|
|
@@ -25733,12 +25800,12 @@ function createAutoRoutesPlugin(ctx) {
|
|
|
25733
25800
|
if (!pathWithoutQuery) {
|
|
25734
25801
|
return false;
|
|
25735
25802
|
}
|
|
25736
|
-
const
|
|
25737
|
-
|
|
25738
|
-
|
|
25739
|
-
|
|
25740
|
-
const relative3 = toPosixPath(path43.relative(
|
|
25741
|
-
if (!relative3 || relative3.startsWith("..")) {
|
|
25803
|
+
const normalizedSrcRoot = normalizePath(configService.absoluteSrcRoot);
|
|
25804
|
+
const normalizedCandidate = normalizePath(
|
|
25805
|
+
path43.isAbsolute(pathWithoutQuery) ? pathWithoutQuery : path43.resolve(configService.cwd, pathWithoutQuery)
|
|
25806
|
+
);
|
|
25807
|
+
const relative3 = toPosixPath(path43.relative(normalizedSrcRoot, normalizedCandidate));
|
|
25808
|
+
if (!relative3 || relative3.startsWith("..") || path43.isAbsolute(relative3)) {
|
|
25742
25809
|
return false;
|
|
25743
25810
|
}
|
|
25744
25811
|
return relative3 === "pages" || relative3.startsWith("pages/") || relative3.includes("/pages/");
|
|
@@ -29869,7 +29936,10 @@ function css(ctx) {
|
|
|
29869
29936
|
init_esm_shims();
|
|
29870
29937
|
import { isObject as isObject9 } from "@weapp-core/shared";
|
|
29871
29938
|
var debug3 = createDebugger("weapp-vite:preflight");
|
|
29872
|
-
var removePlugins = [
|
|
29939
|
+
var removePlugins = [
|
|
29940
|
+
"vite:build-import-analysis",
|
|
29941
|
+
"native:import-analysis-build"
|
|
29942
|
+
];
|
|
29873
29943
|
function createPluginPruner() {
|
|
29874
29944
|
return {
|
|
29875
29945
|
name: "weapp-vite:preflight",
|
|
@@ -30095,6 +30165,192 @@ import fs33 from "fs-extra";
|
|
|
30095
30165
|
import path67 from "pathe";
|
|
30096
30166
|
import { compileJsxFile as compileJsxFile2, compileVueFile as compileVueFile2 } from "wevu/compiler";
|
|
30097
30167
|
|
|
30168
|
+
// src/plugins/performance/onPageScrollDiagnostics.ts
|
|
30169
|
+
init_esm_shims();
|
|
30170
|
+
function isStaticPropertyName(key) {
|
|
30171
|
+
if (key.type === "Identifier") {
|
|
30172
|
+
return key.name;
|
|
30173
|
+
}
|
|
30174
|
+
if (key.type === "StringLiteral") {
|
|
30175
|
+
return key.value;
|
|
30176
|
+
}
|
|
30177
|
+
return void 0;
|
|
30178
|
+
}
|
|
30179
|
+
function getMemberExpressionPropertyName(node) {
|
|
30180
|
+
if (node.computed) {
|
|
30181
|
+
return node.property.type === "StringLiteral" ? node.property.value : void 0;
|
|
30182
|
+
}
|
|
30183
|
+
return node.property.type === "Identifier" ? node.property.name : void 0;
|
|
30184
|
+
}
|
|
30185
|
+
function isOnPageScrollCallee(callee, hookNames, namespaceImports) {
|
|
30186
|
+
if (callee.type === "Identifier") {
|
|
30187
|
+
return hookNames.has(callee.name);
|
|
30188
|
+
}
|
|
30189
|
+
if (callee.type === "MemberExpression" || callee.type === "OptionalMemberExpression") {
|
|
30190
|
+
const object = callee.object;
|
|
30191
|
+
const propName = getMemberExpressionPropertyName(callee);
|
|
30192
|
+
return object.type === "Identifier" && namespaceImports.has(object.name) && propName === "onPageScroll";
|
|
30193
|
+
}
|
|
30194
|
+
return false;
|
|
30195
|
+
}
|
|
30196
|
+
function getCallExpressionCalleeName(callee) {
|
|
30197
|
+
if (callee.type === "Identifier") {
|
|
30198
|
+
return callee.name;
|
|
30199
|
+
}
|
|
30200
|
+
if (callee.type === "MemberExpression" || callee.type === "OptionalMemberExpression") {
|
|
30201
|
+
return getMemberExpressionPropertyName(callee);
|
|
30202
|
+
}
|
|
30203
|
+
return void 0;
|
|
30204
|
+
}
|
|
30205
|
+
function collectPageScrollInspection(functionPath, node) {
|
|
30206
|
+
const inspection = {
|
|
30207
|
+
empty: node.body.type === "BlockStatement" && node.body.body.length === 0,
|
|
30208
|
+
hasSetDataCall: false,
|
|
30209
|
+
syncApis: /* @__PURE__ */ new Set()
|
|
30210
|
+
};
|
|
30211
|
+
functionPath.traverse({
|
|
30212
|
+
Function(innerPath) {
|
|
30213
|
+
if (innerPath !== functionPath) {
|
|
30214
|
+
innerPath.skip();
|
|
30215
|
+
}
|
|
30216
|
+
},
|
|
30217
|
+
CallExpression(callPath) {
|
|
30218
|
+
const callee = callPath.node.callee;
|
|
30219
|
+
const calleeName = getCallExpressionCalleeName(callee);
|
|
30220
|
+
if (calleeName === "setData") {
|
|
30221
|
+
inspection.hasSetDataCall = true;
|
|
30222
|
+
}
|
|
30223
|
+
if (callee.type === "MemberExpression" || callee.type === "OptionalMemberExpression") {
|
|
30224
|
+
const object = callee.object;
|
|
30225
|
+
if (object.type === "Identifier" && object.name === "wx") {
|
|
30226
|
+
const propertyName = getMemberExpressionPropertyName(callee);
|
|
30227
|
+
if (propertyName && propertyName.endsWith("Sync")) {
|
|
30228
|
+
inspection.syncApis.add(`wx.${propertyName}`);
|
|
30229
|
+
}
|
|
30230
|
+
}
|
|
30231
|
+
}
|
|
30232
|
+
},
|
|
30233
|
+
OptionalCallExpression(callPath) {
|
|
30234
|
+
const callee = callPath.node.callee;
|
|
30235
|
+
const calleeName = getCallExpressionCalleeName(callee);
|
|
30236
|
+
if (calleeName === "setData") {
|
|
30237
|
+
inspection.hasSetDataCall = true;
|
|
30238
|
+
}
|
|
30239
|
+
if (callee.type === "MemberExpression" || callee.type === "OptionalMemberExpression") {
|
|
30240
|
+
const object = callee.object;
|
|
30241
|
+
if (object.type === "Identifier" && object.name === "wx") {
|
|
30242
|
+
const propertyName = getMemberExpressionPropertyName(callee);
|
|
30243
|
+
if (propertyName && propertyName.endsWith("Sync")) {
|
|
30244
|
+
inspection.syncApis.add(`wx.${propertyName}`);
|
|
30245
|
+
}
|
|
30246
|
+
}
|
|
30247
|
+
}
|
|
30248
|
+
}
|
|
30249
|
+
});
|
|
30250
|
+
return inspection;
|
|
30251
|
+
}
|
|
30252
|
+
function createWarningPrefix(filename, line, column) {
|
|
30253
|
+
const pos = typeof line === "number" && typeof column === "number" ? `${line}:${column}` : "?:?";
|
|
30254
|
+
return `[weapp-vite][onPageScroll] ${filename}:${pos}`;
|
|
30255
|
+
}
|
|
30256
|
+
function collectOnPageScrollPerformanceWarnings(code, filename) {
|
|
30257
|
+
let ast;
|
|
30258
|
+
try {
|
|
30259
|
+
ast = parseJsLike(code);
|
|
30260
|
+
} catch {
|
|
30261
|
+
return [];
|
|
30262
|
+
}
|
|
30263
|
+
const onPageScrollHookNames = /* @__PURE__ */ new Set(["onPageScroll"]);
|
|
30264
|
+
const namespaceImports = /* @__PURE__ */ new Set();
|
|
30265
|
+
for (const statement of ast.program.body) {
|
|
30266
|
+
if (statement.type !== "ImportDeclaration" || statement.source.value !== "wevu") {
|
|
30267
|
+
continue;
|
|
30268
|
+
}
|
|
30269
|
+
for (const specifier of statement.specifiers) {
|
|
30270
|
+
if (specifier.type === "ImportSpecifier" && specifier.imported.type === "Identifier" && specifier.imported.name === "onPageScroll") {
|
|
30271
|
+
onPageScrollHookNames.add(specifier.local.name);
|
|
30272
|
+
}
|
|
30273
|
+
if (specifier.type === "ImportNamespaceSpecifier") {
|
|
30274
|
+
namespaceImports.add(specifier.local.name);
|
|
30275
|
+
}
|
|
30276
|
+
}
|
|
30277
|
+
}
|
|
30278
|
+
const warnings = [];
|
|
30279
|
+
const warningSet = /* @__PURE__ */ new Set();
|
|
30280
|
+
const addWarning = (warning) => {
|
|
30281
|
+
if (warningSet.has(warning)) {
|
|
30282
|
+
return;
|
|
30283
|
+
}
|
|
30284
|
+
warningSet.add(warning);
|
|
30285
|
+
warnings.push(warning);
|
|
30286
|
+
};
|
|
30287
|
+
const reportInspection = (functionPath, node, sourceLabel) => {
|
|
30288
|
+
const inspection = collectPageScrollInspection(functionPath, node);
|
|
30289
|
+
const line = node.loc?.start.line;
|
|
30290
|
+
const column = typeof node.loc?.start.column === "number" ? node.loc.start.column + 1 : void 0;
|
|
30291
|
+
const prefix = createWarningPrefix(filename, line, column);
|
|
30292
|
+
if (inspection.empty) {
|
|
30293
|
+
addWarning(`${prefix} \u68C0\u6D4B\u5230\u7A7A\u7684 ${sourceLabel} \u56DE\u8C03\uFF0C\u5EFA\u8BAE\u79FB\u9664\u65E0\u6548\u76D1\u542C\u4EE5\u964D\u4F4E\u6EDA\u52A8\u65F6\u8C03\u5EA6\u5F00\u9500\u3002`);
|
|
30294
|
+
}
|
|
30295
|
+
if (inspection.hasSetDataCall) {
|
|
30296
|
+
addWarning(`${prefix} \u68C0\u6D4B\u5230 ${sourceLabel} \u5185\u8C03\u7528 setData\uFF0C\u5EFA\u8BAE\u6539\u7528\u8282\u6D41\u3001IntersectionObserver \u6216\u5408\u5E76\u66F4\u65B0\u3002`);
|
|
30297
|
+
}
|
|
30298
|
+
for (const syncApi of inspection.syncApis) {
|
|
30299
|
+
addWarning(`${prefix} \u68C0\u6D4B\u5230 ${sourceLabel} \u5185\u8C03\u7528\u540C\u6B65 API\uFF08${syncApi}\uFF09\uFF0C\u53EF\u80FD\u963B\u585E\u6E32\u67D3\u7EBF\u7A0B\u3002`);
|
|
30300
|
+
}
|
|
30301
|
+
};
|
|
30302
|
+
traverse(ast, {
|
|
30303
|
+
ObjectMethod(path81) {
|
|
30304
|
+
const keyName = isStaticPropertyName(path81.node.key);
|
|
30305
|
+
if (keyName !== "onPageScroll") {
|
|
30306
|
+
return;
|
|
30307
|
+
}
|
|
30308
|
+
reportInspection(path81, path81.node, "onPageScroll");
|
|
30309
|
+
},
|
|
30310
|
+
ObjectProperty(path81) {
|
|
30311
|
+
if (path81.node.computed) {
|
|
30312
|
+
return;
|
|
30313
|
+
}
|
|
30314
|
+
const keyName = isStaticPropertyName(path81.node.key);
|
|
30315
|
+
if (keyName !== "onPageScroll") {
|
|
30316
|
+
return;
|
|
30317
|
+
}
|
|
30318
|
+
const value = path81.node.value;
|
|
30319
|
+
if (value.type !== "FunctionExpression" && value.type !== "ArrowFunctionExpression") {
|
|
30320
|
+
return;
|
|
30321
|
+
}
|
|
30322
|
+
reportInspection(path81.get("value"), value, "onPageScroll");
|
|
30323
|
+
},
|
|
30324
|
+
CallExpression(path81) {
|
|
30325
|
+
if (!isOnPageScrollCallee(path81.node.callee, onPageScrollHookNames, namespaceImports)) {
|
|
30326
|
+
return;
|
|
30327
|
+
}
|
|
30328
|
+
const arg0 = path81.node.arguments[0];
|
|
30329
|
+
if (!arg0 || arg0.type === "SpreadElement") {
|
|
30330
|
+
return;
|
|
30331
|
+
}
|
|
30332
|
+
if (arg0.type !== "FunctionExpression" && arg0.type !== "ArrowFunctionExpression") {
|
|
30333
|
+
return;
|
|
30334
|
+
}
|
|
30335
|
+
reportInspection(path81.get("arguments.0"), arg0, "onPageScroll(...)");
|
|
30336
|
+
},
|
|
30337
|
+
OptionalCallExpression(path81) {
|
|
30338
|
+
if (!isOnPageScrollCallee(path81.node.callee, onPageScrollHookNames, namespaceImports)) {
|
|
30339
|
+
return;
|
|
30340
|
+
}
|
|
30341
|
+
const arg0 = path81.node.arguments[0];
|
|
30342
|
+
if (!arg0 || arg0.type === "SpreadElement") {
|
|
30343
|
+
return;
|
|
30344
|
+
}
|
|
30345
|
+
if (arg0.type !== "FunctionExpression" && arg0.type !== "ArrowFunctionExpression") {
|
|
30346
|
+
return;
|
|
30347
|
+
}
|
|
30348
|
+
reportInspection(path81.get("arguments.0"), arg0, "onPageScroll(...)");
|
|
30349
|
+
}
|
|
30350
|
+
});
|
|
30351
|
+
return warnings;
|
|
30352
|
+
}
|
|
30353
|
+
|
|
30098
30354
|
// src/plugins/wevu.ts
|
|
30099
30355
|
init_esm_shims();
|
|
30100
30356
|
import path63 from "pathe";
|
|
@@ -30183,6 +30439,9 @@ function createWevuAutoPageFeaturesPlugin(ctx) {
|
|
|
30183
30439
|
if (!await pageMatcher.isPageFile(filename)) {
|
|
30184
30440
|
return null;
|
|
30185
30441
|
}
|
|
30442
|
+
for (const warning of collectOnPageScrollPerformanceWarnings(code, filename)) {
|
|
30443
|
+
default2.warn(warning);
|
|
30444
|
+
}
|
|
30186
30445
|
const result = await injectWevuPageFeaturesInJsWithResolver(code, {
|
|
30187
30446
|
id: filename,
|
|
30188
30447
|
resolver: createViteResolverAdapter(
|
|
@@ -33038,6 +33297,92 @@ function createUsingComponentPathResolver(ctx, configService, reExportResolution
|
|
|
33038
33297
|
};
|
|
33039
33298
|
}
|
|
33040
33299
|
|
|
33300
|
+
// src/plugins/vue/transform/wevuPreset.ts
|
|
33301
|
+
init_esm_shims();
|
|
33302
|
+
var PERFORMANCE_PRESET_DEFAULTS = {
|
|
33303
|
+
app: {
|
|
33304
|
+
setData: {
|
|
33305
|
+
strategy: "patch",
|
|
33306
|
+
suspendWhenHidden: true,
|
|
33307
|
+
diagnostics: "fallback",
|
|
33308
|
+
highFrequencyWarning: {
|
|
33309
|
+
enabled: true,
|
|
33310
|
+
devOnly: true
|
|
33311
|
+
}
|
|
33312
|
+
}
|
|
33313
|
+
},
|
|
33314
|
+
component: {
|
|
33315
|
+
setData: {
|
|
33316
|
+
strategy: "patch",
|
|
33317
|
+
suspendWhenHidden: true,
|
|
33318
|
+
diagnostics: "fallback",
|
|
33319
|
+
highFrequencyWarning: {
|
|
33320
|
+
enabled: true,
|
|
33321
|
+
devOnly: true
|
|
33322
|
+
}
|
|
33323
|
+
}
|
|
33324
|
+
}
|
|
33325
|
+
};
|
|
33326
|
+
function getPlainRecord(value) {
|
|
33327
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
33328
|
+
return void 0;
|
|
33329
|
+
}
|
|
33330
|
+
return value;
|
|
33331
|
+
}
|
|
33332
|
+
function mergeDefaults(defaults, options) {
|
|
33333
|
+
if (!defaults) {
|
|
33334
|
+
return options;
|
|
33335
|
+
}
|
|
33336
|
+
if (!options) {
|
|
33337
|
+
return defaults;
|
|
33338
|
+
}
|
|
33339
|
+
const merged = {
|
|
33340
|
+
...defaults,
|
|
33341
|
+
...options
|
|
33342
|
+
};
|
|
33343
|
+
const defaultSetData = getPlainRecord(defaults.setData);
|
|
33344
|
+
const optionSetData = getPlainRecord(options.setData);
|
|
33345
|
+
if (defaultSetData || optionSetData) {
|
|
33346
|
+
merged.setData = {
|
|
33347
|
+
...defaultSetData ?? {},
|
|
33348
|
+
...optionSetData ?? {}
|
|
33349
|
+
};
|
|
33350
|
+
}
|
|
33351
|
+
const defaultOptions3 = getPlainRecord(defaults.options);
|
|
33352
|
+
const optionOptions = getPlainRecord(options.options);
|
|
33353
|
+
if (defaultOptions3 || optionOptions) {
|
|
33354
|
+
merged.options = {
|
|
33355
|
+
...defaultOptions3 ?? {},
|
|
33356
|
+
...optionOptions ?? {}
|
|
33357
|
+
};
|
|
33358
|
+
}
|
|
33359
|
+
return merged;
|
|
33360
|
+
}
|
|
33361
|
+
function mergeWevuDefaults(base, next) {
|
|
33362
|
+
return {
|
|
33363
|
+
app: mergeDefaults(base.app, next.app),
|
|
33364
|
+
component: mergeDefaults(base.component, next.component)
|
|
33365
|
+
};
|
|
33366
|
+
}
|
|
33367
|
+
function resolveWevuPreset(config) {
|
|
33368
|
+
return config?.wevu?.preset;
|
|
33369
|
+
}
|
|
33370
|
+
function resolveWevuDefaultsWithPreset(config) {
|
|
33371
|
+
const userDefaults = config?.wevu?.defaults;
|
|
33372
|
+
const preset = resolveWevuPreset(config);
|
|
33373
|
+
if (preset !== "performance") {
|
|
33374
|
+
return userDefaults;
|
|
33375
|
+
}
|
|
33376
|
+
return mergeWevuDefaults(PERFORMANCE_PRESET_DEFAULTS, userDefaults ?? {});
|
|
33377
|
+
}
|
|
33378
|
+
function isAutoSetDataPickEnabledWithPreset(config) {
|
|
33379
|
+
const explicit = config?.wevu?.autoSetDataPick;
|
|
33380
|
+
if (typeof explicit === "boolean") {
|
|
33381
|
+
return explicit;
|
|
33382
|
+
}
|
|
33383
|
+
return resolveWevuPreset(config) === "performance";
|
|
33384
|
+
}
|
|
33385
|
+
|
|
33041
33386
|
// src/plugins/vue/transform/compileOptions.ts
|
|
33042
33387
|
function createCompileVueFileOptions(ctx, pluginCtx, vuePath, isPage, isApp, configService, state) {
|
|
33043
33388
|
const scopedSlotsCompiler = configService.weappViteConfig?.vue?.template?.scopedSlotsCompiler ?? "auto";
|
|
@@ -33067,7 +33412,7 @@ function createCompileVueFileOptions(ctx, pluginCtx, vuePath, isPage, isApp, con
|
|
|
33067
33412
|
}
|
|
33068
33413
|
}
|
|
33069
33414
|
const jsonConfig = configService.weappViteConfig?.json;
|
|
33070
|
-
const wevuDefaults = configService.weappViteConfig
|
|
33415
|
+
const wevuDefaults = resolveWevuDefaultsWithPreset(configService.weappViteConfig);
|
|
33071
33416
|
const jsonKind = isApp ? "app" : isPage ? "page" : "component";
|
|
33072
33417
|
const templatePlatform = getMiniProgramTemplatePlatform(configService.platform);
|
|
33073
33418
|
return {
|
|
@@ -33294,6 +33639,331 @@ async function injectWevuPageFeaturesInJsWithViteResolver(ctx, source, id, optio
|
|
|
33294
33639
|
});
|
|
33295
33640
|
}
|
|
33296
33641
|
|
|
33642
|
+
// src/plugins/vue/transform/injectSetDataPick.ts
|
|
33643
|
+
init_esm_shims();
|
|
33644
|
+
var TEMPLATE_MUSTACHE_RE = /\{\{([\s\S]*?)\}\}/g;
|
|
33645
|
+
var WX_FOR_TAG_RE = /<[^>]*\bwx:for\s*=\s*(?:"[^"]*"|'[^']*')[^>]*>/g;
|
|
33646
|
+
var WX_FOR_ITEM_RE = /\bwx:for-item\s*=\s*(?:"([^"]+)"|'([^']+)')/;
|
|
33647
|
+
var WX_FOR_INDEX_RE = /\bwx:for-index\s*=\s*(?:"([^"]+)"|'([^']+)')/;
|
|
33648
|
+
var JS_GLOBAL_IDENTIFIERS = /* @__PURE__ */ new Set([
|
|
33649
|
+
"undefined",
|
|
33650
|
+
"NaN",
|
|
33651
|
+
"Infinity",
|
|
33652
|
+
"globalThis",
|
|
33653
|
+
"Math",
|
|
33654
|
+
"Number",
|
|
33655
|
+
"String",
|
|
33656
|
+
"Boolean",
|
|
33657
|
+
"Object",
|
|
33658
|
+
"Array",
|
|
33659
|
+
"Date",
|
|
33660
|
+
"JSON",
|
|
33661
|
+
"RegExp",
|
|
33662
|
+
"Map",
|
|
33663
|
+
"Set",
|
|
33664
|
+
"WeakMap",
|
|
33665
|
+
"WeakSet",
|
|
33666
|
+
"parseInt",
|
|
33667
|
+
"parseFloat",
|
|
33668
|
+
"isNaN",
|
|
33669
|
+
"isFinite",
|
|
33670
|
+
"decodeURI",
|
|
33671
|
+
"decodeURIComponent",
|
|
33672
|
+
"encodeURI",
|
|
33673
|
+
"encodeURIComponent"
|
|
33674
|
+
]);
|
|
33675
|
+
function isAutoSetDataPickEnabled(config) {
|
|
33676
|
+
return isAutoSetDataPickEnabledWithPreset(config);
|
|
33677
|
+
}
|
|
33678
|
+
function isTargetWevuComponentCall(callee) {
|
|
33679
|
+
if (callee.type === "Identifier") {
|
|
33680
|
+
return callee.name === "createWevuComponent" || callee.name === "defineComponent";
|
|
33681
|
+
}
|
|
33682
|
+
if (callee.type !== "MemberExpression" || callee.computed) {
|
|
33683
|
+
return false;
|
|
33684
|
+
}
|
|
33685
|
+
return callee.property.type === "Identifier" && (callee.property.name === "createWevuComponent" || callee.property.name === "defineComponent");
|
|
33686
|
+
}
|
|
33687
|
+
function getObjectPropertyByKey(objectExpression, key) {
|
|
33688
|
+
for (const member of objectExpression.properties) {
|
|
33689
|
+
if (member.type !== "ObjectProperty") {
|
|
33690
|
+
continue;
|
|
33691
|
+
}
|
|
33692
|
+
if (member.key.type === "Identifier" && member.key.name === key) {
|
|
33693
|
+
return member;
|
|
33694
|
+
}
|
|
33695
|
+
if (member.key.type === "StringLiteral" && member.key.value === key) {
|
|
33696
|
+
return member;
|
|
33697
|
+
}
|
|
33698
|
+
}
|
|
33699
|
+
return void 0;
|
|
33700
|
+
}
|
|
33701
|
+
function unwrapExpression(node) {
|
|
33702
|
+
let current2 = node;
|
|
33703
|
+
while (true) {
|
|
33704
|
+
if (current2.type === "TSAsExpression" || current2.type === "TSTypeAssertion" || current2.type === "TSNonNullExpression" || current2.type === "ParenthesizedExpression" || current2.type === "TSSatisfiesExpression") {
|
|
33705
|
+
current2 = current2.expression;
|
|
33706
|
+
continue;
|
|
33707
|
+
}
|
|
33708
|
+
return current2;
|
|
33709
|
+
}
|
|
33710
|
+
}
|
|
33711
|
+
function resolveOptionsObjectExpression2(expression, scope) {
|
|
33712
|
+
if (!expression) {
|
|
33713
|
+
return void 0;
|
|
33714
|
+
}
|
|
33715
|
+
const unwrapped = unwrapExpression(expression);
|
|
33716
|
+
if (unwrapped.type === "ObjectExpression") {
|
|
33717
|
+
return unwrapped;
|
|
33718
|
+
}
|
|
33719
|
+
if (unwrapped.type === "Identifier") {
|
|
33720
|
+
const binding = scope.getBinding(unwrapped.name);
|
|
33721
|
+
if (!binding || !binding.path.isVariableDeclarator()) {
|
|
33722
|
+
return void 0;
|
|
33723
|
+
}
|
|
33724
|
+
const init = binding.path.node.init;
|
|
33725
|
+
if (!init || init.type !== "ObjectExpression" && init.type !== "CallExpression" && init.type !== "Identifier") {
|
|
33726
|
+
return void 0;
|
|
33727
|
+
}
|
|
33728
|
+
return resolveOptionsObjectExpression2(init, binding.path.scope);
|
|
33729
|
+
}
|
|
33730
|
+
if (unwrapped.type === "CallExpression" && unwrapped.callee.type === "MemberExpression" && !unwrapped.callee.computed && unwrapped.callee.object.type === "Identifier" && unwrapped.callee.object.name === "Object" && unwrapped.callee.property.type === "Identifier" && unwrapped.callee.property.name === "assign") {
|
|
33731
|
+
for (let i = unwrapped.arguments.length - 1; i >= 0; i--) {
|
|
33732
|
+
const arg = unwrapped.arguments[i];
|
|
33733
|
+
if (arg.type !== "SpreadElement") {
|
|
33734
|
+
const resolved = resolveOptionsObjectExpression2(arg, scope);
|
|
33735
|
+
if (resolved) {
|
|
33736
|
+
return resolved;
|
|
33737
|
+
}
|
|
33738
|
+
}
|
|
33739
|
+
}
|
|
33740
|
+
}
|
|
33741
|
+
return void 0;
|
|
33742
|
+
}
|
|
33743
|
+
function createPickArrayExpression(keys) {
|
|
33744
|
+
return {
|
|
33745
|
+
type: "ArrayExpression",
|
|
33746
|
+
elements: keys.map((key) => ({ type: "StringLiteral", value: key }))
|
|
33747
|
+
};
|
|
33748
|
+
}
|
|
33749
|
+
function mergePickArrayExpression(arrayExpression, keys) {
|
|
33750
|
+
const existing = /* @__PURE__ */ new Set();
|
|
33751
|
+
for (const element of arrayExpression.elements) {
|
|
33752
|
+
if (element && element.type === "StringLiteral") {
|
|
33753
|
+
existing.add(element.value);
|
|
33754
|
+
}
|
|
33755
|
+
}
|
|
33756
|
+
let changed = false;
|
|
33757
|
+
for (const key of keys) {
|
|
33758
|
+
if (existing.has(key)) {
|
|
33759
|
+
continue;
|
|
33760
|
+
}
|
|
33761
|
+
arrayExpression.elements.push({ type: "StringLiteral", value: key });
|
|
33762
|
+
existing.add(key);
|
|
33763
|
+
changed = true;
|
|
33764
|
+
}
|
|
33765
|
+
return changed;
|
|
33766
|
+
}
|
|
33767
|
+
function injectPickIntoSetDataObject(setDataObject, keys) {
|
|
33768
|
+
const pickProp = getObjectPropertyByKey(setDataObject, "pick");
|
|
33769
|
+
if (!pickProp) {
|
|
33770
|
+
setDataObject.properties.unshift({
|
|
33771
|
+
type: "ObjectProperty",
|
|
33772
|
+
key: { type: "Identifier", name: "pick" },
|
|
33773
|
+
computed: false,
|
|
33774
|
+
shorthand: false,
|
|
33775
|
+
value: createPickArrayExpression(keys)
|
|
33776
|
+
});
|
|
33777
|
+
return true;
|
|
33778
|
+
}
|
|
33779
|
+
if (pickProp.value.type !== "ArrayExpression") {
|
|
33780
|
+
return false;
|
|
33781
|
+
}
|
|
33782
|
+
return mergePickArrayExpression(pickProp.value, keys);
|
|
33783
|
+
}
|
|
33784
|
+
function injectPickIntoOptionsObject(optionsObject, keys) {
|
|
33785
|
+
const setDataProp = getObjectPropertyByKey(optionsObject, "setData");
|
|
33786
|
+
if (!setDataProp) {
|
|
33787
|
+
optionsObject.properties.unshift({
|
|
33788
|
+
type: "ObjectProperty",
|
|
33789
|
+
key: { type: "Identifier", name: "setData" },
|
|
33790
|
+
computed: false,
|
|
33791
|
+
shorthand: false,
|
|
33792
|
+
value: {
|
|
33793
|
+
type: "ObjectExpression",
|
|
33794
|
+
properties: [
|
|
33795
|
+
{
|
|
33796
|
+
type: "ObjectProperty",
|
|
33797
|
+
key: { type: "Identifier", name: "pick" },
|
|
33798
|
+
computed: false,
|
|
33799
|
+
shorthand: false,
|
|
33800
|
+
value: createPickArrayExpression(keys)
|
|
33801
|
+
}
|
|
33802
|
+
]
|
|
33803
|
+
}
|
|
33804
|
+
});
|
|
33805
|
+
return true;
|
|
33806
|
+
}
|
|
33807
|
+
const setDataValue = unwrapExpression(setDataProp.value);
|
|
33808
|
+
if (setDataValue.type === "ObjectExpression") {
|
|
33809
|
+
return injectPickIntoSetDataObject(setDataValue, keys);
|
|
33810
|
+
}
|
|
33811
|
+
if (setDataValue.type === "Identifier" || setDataValue.type === "MemberExpression" || setDataValue.type === "CallExpression") {
|
|
33812
|
+
setDataProp.value = {
|
|
33813
|
+
type: "ObjectExpression",
|
|
33814
|
+
properties: [
|
|
33815
|
+
{
|
|
33816
|
+
type: "ObjectProperty",
|
|
33817
|
+
key: { type: "Identifier", name: "pick" },
|
|
33818
|
+
computed: false,
|
|
33819
|
+
shorthand: false,
|
|
33820
|
+
value: createPickArrayExpression(keys)
|
|
33821
|
+
},
|
|
33822
|
+
{
|
|
33823
|
+
type: "SpreadElement",
|
|
33824
|
+
argument: setDataValue
|
|
33825
|
+
}
|
|
33826
|
+
]
|
|
33827
|
+
};
|
|
33828
|
+
return true;
|
|
33829
|
+
}
|
|
33830
|
+
return false;
|
|
33831
|
+
}
|
|
33832
|
+
function collectLoopScopeAliases(template) {
|
|
33833
|
+
const aliases = /* @__PURE__ */ new Set();
|
|
33834
|
+
const tagMatches = template.match(WX_FOR_TAG_RE) ?? [];
|
|
33835
|
+
for (const tag of tagMatches) {
|
|
33836
|
+
const itemMatch = tag.match(WX_FOR_ITEM_RE);
|
|
33837
|
+
if (itemMatch) {
|
|
33838
|
+
const itemAlias = (itemMatch[1] ?? itemMatch[2] ?? "").trim();
|
|
33839
|
+
if (itemAlias) {
|
|
33840
|
+
aliases.add(itemAlias);
|
|
33841
|
+
}
|
|
33842
|
+
} else {
|
|
33843
|
+
aliases.add("item");
|
|
33844
|
+
}
|
|
33845
|
+
const indexMatch = tag.match(WX_FOR_INDEX_RE);
|
|
33846
|
+
if (indexMatch) {
|
|
33847
|
+
const indexAlias = (indexMatch[1] ?? indexMatch[2] ?? "").trim();
|
|
33848
|
+
if (indexAlias) {
|
|
33849
|
+
aliases.add(indexAlias);
|
|
33850
|
+
}
|
|
33851
|
+
} else {
|
|
33852
|
+
aliases.add("index");
|
|
33853
|
+
}
|
|
33854
|
+
}
|
|
33855
|
+
return aliases;
|
|
33856
|
+
}
|
|
33857
|
+
function extractTemplateExpressions(template) {
|
|
33858
|
+
const expressions = [];
|
|
33859
|
+
let match = TEMPLATE_MUSTACHE_RE.exec(template);
|
|
33860
|
+
while (match) {
|
|
33861
|
+
const expression = (match[1] ?? "").trim();
|
|
33862
|
+
if (expression) {
|
|
33863
|
+
expressions.push(expression);
|
|
33864
|
+
}
|
|
33865
|
+
match = TEMPLATE_MUSTACHE_RE.exec(template);
|
|
33866
|
+
}
|
|
33867
|
+
TEMPLATE_MUSTACHE_RE.lastIndex = 0;
|
|
33868
|
+
return expressions;
|
|
33869
|
+
}
|
|
33870
|
+
function collectIdentifiersFromExpression(expression) {
|
|
33871
|
+
const collected = /* @__PURE__ */ new Set();
|
|
33872
|
+
let ast;
|
|
33873
|
+
try {
|
|
33874
|
+
ast = parse(`const __weappViteExpr = (${expression});`, {
|
|
33875
|
+
...BABEL_TS_MODULE_PARSER_OPTIONS,
|
|
33876
|
+
sourceType: "module"
|
|
33877
|
+
});
|
|
33878
|
+
} catch {
|
|
33879
|
+
return collected;
|
|
33880
|
+
}
|
|
33881
|
+
traverse(ast, {
|
|
33882
|
+
Identifier(path81) {
|
|
33883
|
+
if (!path81.isReferencedIdentifier()) {
|
|
33884
|
+
return;
|
|
33885
|
+
}
|
|
33886
|
+
const name = path81.node.name;
|
|
33887
|
+
if (name === "__weappViteExpr") {
|
|
33888
|
+
return;
|
|
33889
|
+
}
|
|
33890
|
+
if (path81.scope.hasBinding(name, true)) {
|
|
33891
|
+
return;
|
|
33892
|
+
}
|
|
33893
|
+
if (JS_GLOBAL_IDENTIFIERS.has(name)) {
|
|
33894
|
+
return;
|
|
33895
|
+
}
|
|
33896
|
+
collected.add(name);
|
|
33897
|
+
},
|
|
33898
|
+
MemberExpression(path81) {
|
|
33899
|
+
const member = path81.node;
|
|
33900
|
+
if (member.computed || member.object.type !== "ThisExpression" || member.property.type !== "Identifier") {
|
|
33901
|
+
return;
|
|
33902
|
+
}
|
|
33903
|
+
collected.add(member.property.name);
|
|
33904
|
+
},
|
|
33905
|
+
OptionalMemberExpression(path81) {
|
|
33906
|
+
const member = path81.node;
|
|
33907
|
+
if (member.computed || member.object.type !== "ThisExpression" || member.property.type !== "Identifier") {
|
|
33908
|
+
return;
|
|
33909
|
+
}
|
|
33910
|
+
collected.add(member.property.name);
|
|
33911
|
+
}
|
|
33912
|
+
});
|
|
33913
|
+
return collected;
|
|
33914
|
+
}
|
|
33915
|
+
function collectSetDataPickKeysFromTemplate(template) {
|
|
33916
|
+
const templateExpressions = extractTemplateExpressions(template);
|
|
33917
|
+
if (!templateExpressions.length) {
|
|
33918
|
+
return [];
|
|
33919
|
+
}
|
|
33920
|
+
const loopAliases = collectLoopScopeAliases(template);
|
|
33921
|
+
const keys = /* @__PURE__ */ new Set();
|
|
33922
|
+
for (const expression of templateExpressions) {
|
|
33923
|
+
const identifiers = collectIdentifiersFromExpression(expression);
|
|
33924
|
+
for (const identifier3 of identifiers) {
|
|
33925
|
+
if (!loopAliases.has(identifier3)) {
|
|
33926
|
+
keys.add(identifier3);
|
|
33927
|
+
}
|
|
33928
|
+
}
|
|
33929
|
+
}
|
|
33930
|
+
return Array.from(keys).sort((a3, b) => a3.localeCompare(b));
|
|
33931
|
+
}
|
|
33932
|
+
function injectSetDataPickInJs(source, pickKeys) {
|
|
33933
|
+
if (!pickKeys.length) {
|
|
33934
|
+
return { code: source, transformed: false };
|
|
33935
|
+
}
|
|
33936
|
+
const ast = parseJsLike(source);
|
|
33937
|
+
const candidateOptions = /* @__PURE__ */ new Set();
|
|
33938
|
+
traverse(ast, {
|
|
33939
|
+
CallExpression(path81) {
|
|
33940
|
+
if (!isTargetWevuComponentCall(path81.node.callee)) {
|
|
33941
|
+
return;
|
|
33942
|
+
}
|
|
33943
|
+
const firstArg = path81.node.arguments[0];
|
|
33944
|
+
if (!firstArg || firstArg.type === "SpreadElement") {
|
|
33945
|
+
return;
|
|
33946
|
+
}
|
|
33947
|
+
const resolvedOptions = resolveOptionsObjectExpression2(firstArg, path81.scope);
|
|
33948
|
+
if (resolvedOptions) {
|
|
33949
|
+
candidateOptions.add(resolvedOptions);
|
|
33950
|
+
}
|
|
33951
|
+
}
|
|
33952
|
+
});
|
|
33953
|
+
if (!candidateOptions.size) {
|
|
33954
|
+
return { code: source, transformed: false };
|
|
33955
|
+
}
|
|
33956
|
+
let changed = false;
|
|
33957
|
+
for (const optionsObject of candidateOptions) {
|
|
33958
|
+
changed = injectPickIntoOptionsObject(optionsObject, pickKeys) || changed;
|
|
33959
|
+
}
|
|
33960
|
+
if (!changed) {
|
|
33961
|
+
return { code: source, transformed: false };
|
|
33962
|
+
}
|
|
33963
|
+
const generated = generate(ast, { retainLines: true });
|
|
33964
|
+
return { code: generated.code, transformed: true };
|
|
33965
|
+
}
|
|
33966
|
+
|
|
33297
33967
|
// src/plugins/vue/transform/scopedSlot.ts
|
|
33298
33968
|
init_esm_shims();
|
|
33299
33969
|
import { buildClassStyleComputedCode, createJsonMerger as createJsonMerger2, getClassStyleWxsSource, WE_VU_MODULE_ID, WE_VU_RUNTIME_APIS } from "wevu/compiler";
|
|
@@ -33691,6 +34361,13 @@ async function emitVueBundleAssets(bundle, state) {
|
|
|
33691
34361
|
compiled.script = injected.code;
|
|
33692
34362
|
}
|
|
33693
34363
|
}
|
|
34364
|
+
if (!isApp && compiled.script && compiled.template && isAutoSetDataPickEnabled(configService.weappViteConfig)) {
|
|
34365
|
+
const keys = collectSetDataPickKeysFromTemplate(compiled.template);
|
|
34366
|
+
const injectedPick = injectSetDataPickInJs(compiled.script, keys);
|
|
34367
|
+
if (injectedPick.transformed) {
|
|
34368
|
+
compiled.script = injectedPick.code;
|
|
34369
|
+
}
|
|
34370
|
+
}
|
|
33694
34371
|
cached.source = source;
|
|
33695
34372
|
cached.result = compiled;
|
|
33696
34373
|
result = compiled;
|
|
@@ -33800,6 +34477,13 @@ async function emitVueBundleAssets(bundle, state) {
|
|
|
33800
34477
|
result.script = injected.code;
|
|
33801
34478
|
}
|
|
33802
34479
|
}
|
|
34480
|
+
if (result.script && result.template && isAutoSetDataPickEnabled(configService.weappViteConfig)) {
|
|
34481
|
+
const keys = collectSetDataPickKeysFromTemplate(result.template);
|
|
34482
|
+
const injectedPick = injectSetDataPickInJs(result.script, keys);
|
|
34483
|
+
if (injectedPick.transformed) {
|
|
34484
|
+
result.script = injectedPick.code;
|
|
34485
|
+
}
|
|
34486
|
+
}
|
|
33803
34487
|
if (result.template) {
|
|
33804
34488
|
const normalizedTemplate = normalizeVueTemplateForPlatform(result.template, {
|
|
33805
34489
|
platform: configService.platform,
|
|
@@ -34038,6 +34722,9 @@ function createVueTransformPlugin(ctx) {
|
|
|
34038
34722
|
}
|
|
34039
34723
|
}
|
|
34040
34724
|
if (isPage && result.script) {
|
|
34725
|
+
for (const warning of collectOnPageScrollPerformanceWarnings(result.script, filename)) {
|
|
34726
|
+
default2.warn(warning);
|
|
34727
|
+
}
|
|
34041
34728
|
const injected = await injectWevuPageFeaturesInJsWithViteResolver(this, result.script, filename, {
|
|
34042
34729
|
checkMtime: configService.isDev
|
|
34043
34730
|
});
|
|
@@ -34045,6 +34732,13 @@ function createVueTransformPlugin(ctx) {
|
|
|
34045
34732
|
result.script = injected.code;
|
|
34046
34733
|
}
|
|
34047
34734
|
}
|
|
34735
|
+
if (!isApp && result.script && result.template && isAutoSetDataPickEnabled(configService.weappViteConfig)) {
|
|
34736
|
+
const keys = collectSetDataPickKeysFromTemplate(result.template);
|
|
34737
|
+
const injectedPick = injectSetDataPickInJs(result.script, keys);
|
|
34738
|
+
if (injectedPick.transformed) {
|
|
34739
|
+
result.script = injectedPick.code;
|
|
34740
|
+
}
|
|
34741
|
+
}
|
|
34048
34742
|
compilationCache.set(filename, { result, source, isPage });
|
|
34049
34743
|
const relativeBase = configService.relativeOutputPath(getEntryBasePath(filename));
|
|
34050
34744
|
if (relativeBase) {
|
|
@@ -34502,6 +35196,11 @@ function mergeMiniprogram(options, ...configs) {
|
|
|
34502
35196
|
external,
|
|
34503
35197
|
plugins: oxcRolldownPlugin ? [oxcRolldownPlugin] : void 0
|
|
34504
35198
|
};
|
|
35199
|
+
const miniprogramDefines = {
|
|
35200
|
+
...getDefineImportMetaEnv(),
|
|
35201
|
+
// Vite 动态导入预加载 helper 依赖该标记,miniprogram 构建需稳定替换为 false。
|
|
35202
|
+
__VITE_IS_MODERN__: "false"
|
|
35203
|
+
};
|
|
34505
35204
|
if (isDev) {
|
|
34506
35205
|
const watchInclude = [
|
|
34507
35206
|
path70.join(cwd, srcRoot, "**")
|
|
@@ -34522,10 +35221,9 @@ function mergeMiniprogram(options, ...configs) {
|
|
|
34522
35221
|
{
|
|
34523
35222
|
root: cwd,
|
|
34524
35223
|
mode: "development",
|
|
34525
|
-
define:
|
|
34526
|
-
...getDefineImportMetaEnv()
|
|
34527
|
-
},
|
|
35224
|
+
define: miniprogramDefines,
|
|
34528
35225
|
build: {
|
|
35226
|
+
modulePreload: false,
|
|
34529
35227
|
watch: {
|
|
34530
35228
|
exclude: [
|
|
34531
35229
|
...defaultExcluded,
|
|
@@ -34543,6 +35241,10 @@ function mergeMiniprogram(options, ...configs) {
|
|
|
34543
35241
|
}
|
|
34544
35242
|
}
|
|
34545
35243
|
);
|
|
35244
|
+
inline.define = {
|
|
35245
|
+
...inline.define ?? {},
|
|
35246
|
+
__VITE_IS_MODERN__: "false"
|
|
35247
|
+
};
|
|
34546
35248
|
stripRollupOptions(inline);
|
|
34547
35249
|
arrangePlugins(inline, ctx, subPackageMeta);
|
|
34548
35250
|
injectBuiltinAliases(inline);
|
|
@@ -34554,10 +35256,9 @@ function mergeMiniprogram(options, ...configs) {
|
|
|
34554
35256
|
{
|
|
34555
35257
|
root: cwd,
|
|
34556
35258
|
mode: "production",
|
|
34557
|
-
define:
|
|
34558
|
-
...getDefineImportMetaEnv()
|
|
34559
|
-
},
|
|
35259
|
+
define: miniprogramDefines,
|
|
34560
35260
|
build: {
|
|
35261
|
+
modulePreload: false,
|
|
34561
35262
|
emptyOutDir: false,
|
|
34562
35263
|
// @ts-ignore
|
|
34563
35264
|
rolldownOptions: {
|
|
@@ -34566,6 +35267,10 @@ function mergeMiniprogram(options, ...configs) {
|
|
|
34566
35267
|
}
|
|
34567
35268
|
}
|
|
34568
35269
|
);
|
|
35270
|
+
inlineConfig.define = {
|
|
35271
|
+
...inlineConfig.define ?? {},
|
|
35272
|
+
__VITE_IS_MODERN__: "false"
|
|
35273
|
+
};
|
|
34569
35274
|
stripRollupOptions(inlineConfig);
|
|
34570
35275
|
arrangePlugins(inlineConfig, ctx, subPackageMeta);
|
|
34571
35276
|
inlineConfig.logLevel = "info";
|
|
@@ -36980,7 +37685,26 @@ function createRuntimeState() {
|
|
|
36980
37685
|
"const pages = routes.pages;",
|
|
36981
37686
|
"const entries = routes.entries;",
|
|
36982
37687
|
"const subPackages = routes.subPackages;",
|
|
36983
|
-
"
|
|
37688
|
+
"const resolveMiniProgramGlobal = () => (globalThis.wx ?? globalThis.tt ?? globalThis.my);",
|
|
37689
|
+
"const callRouteMethod = (methodName, option) => {",
|
|
37690
|
+
" const miniProgramGlobal = resolveMiniProgramGlobal();",
|
|
37691
|
+
" const routeMethod = miniProgramGlobal?.[methodName];",
|
|
37692
|
+
' if (typeof routeMethod !== "function") {',
|
|
37693
|
+
' throw new Error("[weapp-vite] \u5F53\u524D\u8FD0\u884C\u73AF\u5883\u4E0D\u652F\u6301\u8DEF\u7531\u65B9\u6CD5: " + methodName);',
|
|
37694
|
+
" }",
|
|
37695
|
+
" if (option === undefined) {",
|
|
37696
|
+
" return routeMethod.call(miniProgramGlobal);",
|
|
37697
|
+
" }",
|
|
37698
|
+
" return routeMethod.call(miniProgramGlobal, option);",
|
|
37699
|
+
"};",
|
|
37700
|
+
"const wxRouter = {",
|
|
37701
|
+
' switchTab(option) { return callRouteMethod("switchTab", option); },',
|
|
37702
|
+
' reLaunch(option) { return callRouteMethod("reLaunch", option); },',
|
|
37703
|
+
' redirectTo(option) { return callRouteMethod("redirectTo", option); },',
|
|
37704
|
+
' navigateTo(option) { return callRouteMethod("navigateTo", option); },',
|
|
37705
|
+
' navigateBack(option) { return callRouteMethod("navigateBack", option); },',
|
|
37706
|
+
"};",
|
|
37707
|
+
"export { routes, pages, entries, subPackages, wxRouter };",
|
|
36984
37708
|
"export default routes;"
|
|
36985
37709
|
].join("\n"),
|
|
36986
37710
|
typedDefinition: "",
|
|
@@ -37394,7 +38118,7 @@ function createScanService(ctx) {
|
|
|
37394
38118
|
vueAppPath = await findVueEntry(appBasename);
|
|
37395
38119
|
}
|
|
37396
38120
|
if (!appConfigFile && vueAppPath) {
|
|
37397
|
-
const { extractConfigFromVue: extractConfigFromVue2 } = await import("./file-
|
|
38121
|
+
const { extractConfigFromVue: extractConfigFromVue2 } = await import("./file-IRTTGBIN.mjs");
|
|
37398
38122
|
configFromVue = await extractConfigFromVue2(vueAppPath);
|
|
37399
38123
|
if (configFromVue) {
|
|
37400
38124
|
appConfigFile = vueAppPath;
|