@wevu/compiler 6.19.0 → 6.19.2
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 +179 -127
- package/package.json +8 -8
package/dist/index.mjs
CHANGED
|
@@ -565,7 +565,8 @@ function resolveMacroAlias(macroName) {
|
|
|
565
565
|
}
|
|
566
566
|
async function evaluateScriptSetupJsonMacro(params) {
|
|
567
567
|
const { preambleContent, originalContent, filename, lang, macroName, macroStatements, bodyPaths, keptStatementPaths, options } = params;
|
|
568
|
-
const
|
|
568
|
+
const combinedContent = preambleContent ? `${preambleContent}\n${originalContent}` : originalContent;
|
|
569
|
+
const ms = new MagicString(combinedContent);
|
|
569
570
|
const dir = path.dirname(filename);
|
|
570
571
|
const tempRoot = resolveWevuConfigTempDir(dir);
|
|
571
572
|
const basename = path.basename(filename, path.extname(filename));
|
|
@@ -930,7 +931,8 @@ function collectWevuPageFeatureFlags(ast) {
|
|
|
930
931
|
for (const stmt of ast.program.body) {
|
|
931
932
|
if (!t.isImportDeclaration(stmt) || !isWevuRuntimeModuleId(stmt.source.value)) continue;
|
|
932
933
|
for (const specifier of stmt.specifiers) if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported)) {
|
|
933
|
-
const
|
|
934
|
+
const importedName = specifier.imported.name;
|
|
935
|
+
const matched = WE_VU_PAGE_HOOK_TO_FEATURE[importedName];
|
|
934
936
|
if (matched) namedHookLocals.set(specifier.local.name, matched);
|
|
935
937
|
} else if (t.isImportNamespaceSpecifier(specifier)) namespaceLocals.add(specifier.local.name);
|
|
936
938
|
}
|
|
@@ -1071,7 +1073,8 @@ function createModuleAnalysis(id, ast) {
|
|
|
1071
1073
|
for (const specifier of stmt.specifiers) if (t.isImportSpecifier(specifier)) {
|
|
1072
1074
|
const imported = specifier.imported;
|
|
1073
1075
|
if (isWevuRuntimeModuleId(source) && t.isIdentifier(imported)) {
|
|
1074
|
-
const
|
|
1076
|
+
const importedName = imported.name;
|
|
1077
|
+
const matched = WE_VU_PAGE_HOOK_TO_FEATURE[importedName];
|
|
1075
1078
|
if (matched) wevuNamedHookLocals.set(specifier.local.name, matched);
|
|
1076
1079
|
}
|
|
1077
1080
|
importedBindings.set(specifier.local.name, {
|
|
@@ -1304,9 +1307,10 @@ function createModuleAnalysisWithOxc(id, code) {
|
|
|
1304
1307
|
//#region src/plugins/wevu/pageFeatures/moduleAnalysis/index.ts
|
|
1305
1308
|
const TS_WITHOUT_JSX_RE = /\.[cm]?ts(?:[?#].*)?$/i;
|
|
1306
1309
|
function parseModuleAnalysisAst(id, code) {
|
|
1310
|
+
const plugins = TS_WITHOUT_JSX_RE.test(id) ? BABEL_TS_MODULE_PLUGINS.filter((plugin) => plugin !== "jsx") : BABEL_TS_MODULE_PLUGINS;
|
|
1307
1311
|
return parse$3(code, {
|
|
1308
1312
|
sourceType: "module",
|
|
1309
|
-
plugins
|
|
1313
|
+
plugins
|
|
1310
1314
|
});
|
|
1311
1315
|
}
|
|
1312
1316
|
function createModuleAnalysisFromCode(id, code, options) {
|
|
@@ -1315,9 +1319,10 @@ function createModuleAnalysisFromCode(id, code, options) {
|
|
|
1315
1319
|
const cached = moduleAnalysisCache.get(cacheKey);
|
|
1316
1320
|
if (cached && cached.code === code) return cached.analysis;
|
|
1317
1321
|
let analysis;
|
|
1318
|
-
if (engine === "oxc")
|
|
1319
|
-
|
|
1320
|
-
|
|
1322
|
+
if (engine === "oxc") {
|
|
1323
|
+
if (!code.includes("import") && !code.includes("export")) analysis = createEmptyModuleAnalysis(id, "oxc");
|
|
1324
|
+
else analysis = createModuleAnalysisWithOxc(id, code);
|
|
1325
|
+
} else analysis = createModuleAnalysis(id, parseModuleAnalysisAst(id, code));
|
|
1321
1326
|
moduleAnalysisCache.set(cacheKey, {
|
|
1322
1327
|
code,
|
|
1323
1328
|
analysis
|
|
@@ -1358,7 +1363,8 @@ function collectWithOxc(code) {
|
|
|
1358
1363
|
if (matched) enabled.add(matched);
|
|
1359
1364
|
} else if (callee?.type === "MemberExpression" && !callee.computed && callee.object?.type === "Identifier" && callee.property?.type === "Identifier") {
|
|
1360
1365
|
if (module.wevuNamespaceLocals.has(callee.object.name)) {
|
|
1361
|
-
const
|
|
1366
|
+
const hook = callee.property.name;
|
|
1367
|
+
const matched = WE_VU_PAGE_HOOK_TO_FEATURE[hook];
|
|
1362
1368
|
if (matched) enabled.add(matched);
|
|
1363
1369
|
}
|
|
1364
1370
|
}
|
|
@@ -1692,7 +1698,8 @@ function collectWevuHookCallsInFunctionBody(module, fn) {
|
|
|
1692
1698
|
if (matched) enabled.add(matched);
|
|
1693
1699
|
} else if (callee?.type === "MemberExpression" && !callee.computed && callee.object?.type === "Identifier" && callee.property?.type === "Identifier") {
|
|
1694
1700
|
if (module.wevuNamespaceLocals.has(callee.object.name)) {
|
|
1695
|
-
const
|
|
1701
|
+
const hook = callee.property.name;
|
|
1702
|
+
const matched = WE_VU_PAGE_HOOK_TO_FEATURE[hook];
|
|
1696
1703
|
if (matched) enabled.add(matched);
|
|
1697
1704
|
}
|
|
1698
1705
|
}
|
|
@@ -3732,25 +3739,35 @@ function rewriteDefaultExport(ast, state, options, enabledPageFeatures, serializ
|
|
|
3732
3739
|
transformed = injectPropsDerivedKeys(componentOptionsObject, options?.propsDerivedKeys) || transformed;
|
|
3733
3740
|
}
|
|
3734
3741
|
const classStyleBindings = options?.classStyleBindings ?? [];
|
|
3735
|
-
if (classStyleBindings.length)
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3742
|
+
if (classStyleBindings.length) {
|
|
3743
|
+
if (componentOptionsObject) {
|
|
3744
|
+
ensureClassStyleRuntimeImports(ast.program);
|
|
3745
|
+
transformed = injectClassStyleComputed(componentOptionsObject, classStyleBindings, options?.propsAliases, warn) || transformed;
|
|
3746
|
+
} else warn("无法自动注入 class/style 计算属性:组件选项不是对象字面量。");
|
|
3747
|
+
}
|
|
3739
3748
|
const templateRefs = options?.templateRefs ?? [];
|
|
3740
|
-
if (templateRefs.length)
|
|
3741
|
-
|
|
3749
|
+
if (templateRefs.length) {
|
|
3750
|
+
if (componentOptionsObject) transformed = injectTemplateRefs(componentOptionsObject, templateRefs, warn) || transformed;
|
|
3751
|
+
else warn("无法自动注入 template ref 元数据:组件选项不是对象字面量。");
|
|
3752
|
+
}
|
|
3742
3753
|
const layoutHosts = options?.layoutHosts ?? [];
|
|
3743
|
-
if (layoutHosts.length)
|
|
3744
|
-
|
|
3754
|
+
if (layoutHosts.length) {
|
|
3755
|
+
if (componentOptionsObject) transformed = injectLayoutHosts(componentOptionsObject, layoutHosts, warn) || transformed;
|
|
3756
|
+
else warn("无法自动注入 layout host 元数据:组件选项不是对象字面量。");
|
|
3757
|
+
}
|
|
3745
3758
|
const inlineExpressions = options?.inlineExpressions ?? [];
|
|
3746
|
-
if (inlineExpressions.length)
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3759
|
+
if (inlineExpressions.length) {
|
|
3760
|
+
if (componentOptionsObject) {
|
|
3761
|
+
const injected = injectInlineExpressions(componentOptionsObject, inlineExpressions);
|
|
3762
|
+
if (!injected) warn("无法自动注入内联表达式元数据:methods 不是对象字面量。");
|
|
3763
|
+
transformed = injected || transformed;
|
|
3764
|
+
} else warn("无法自动注入内联表达式元数据:组件选项不是对象字面量。");
|
|
3765
|
+
}
|
|
3751
3766
|
const functionPropPaths = options?.functionPropPaths ?? [];
|
|
3752
|
-
if (functionPropPaths.length)
|
|
3753
|
-
|
|
3767
|
+
if (functionPropPaths.length) {
|
|
3768
|
+
if (componentOptionsObject) transformed = injectFunctionPropPaths(componentOptionsObject, functionPropPaths) || transformed;
|
|
3769
|
+
else warn("无法自动注入函数 prop 元数据:组件选项不是对象字面量。");
|
|
3770
|
+
}
|
|
3754
3771
|
if (componentExpr) {
|
|
3755
3772
|
if (options?.isApp) transformed = injectWevuDefaultsForApp({
|
|
3756
3773
|
astProgram: ast.program,
|
|
@@ -3793,7 +3810,7 @@ function transformScript(source, options) {
|
|
|
3793
3810
|
const macroVisitors = createMacroVisitors(ast.program, state);
|
|
3794
3811
|
const importVisitors = createImportVisitors(ast.program, state);
|
|
3795
3812
|
const collectVisitors = createCollectVisitors(state);
|
|
3796
|
-
|
|
3813
|
+
const visitor = {
|
|
3797
3814
|
...vueSfcVisitors,
|
|
3798
3815
|
...macroVisitors,
|
|
3799
3816
|
...importVisitors,
|
|
@@ -3806,7 +3823,8 @@ function transformScript(source, options) {
|
|
|
3806
3823
|
runVisitor(vueSfcVisitors.CallExpression, path);
|
|
3807
3824
|
if (!path.removed) runVisitor(macroVisitors.CallExpression, path);
|
|
3808
3825
|
}
|
|
3809
|
-
}
|
|
3826
|
+
};
|
|
3827
|
+
traverse(ast, visitor);
|
|
3810
3828
|
if (options?.templateComponentMeta) state.transformed = pruneTemplateComponentMeta(ast, options.templateComponentMeta) || state.transformed;
|
|
3811
3829
|
state.transformed = rewriteDefaultExport(ast, state, options, enabledPageFeatures, serializedWevuDefaults, parsedWevuDefaults) || state.transformed;
|
|
3812
3830
|
if (!state.transformed) return {
|
|
@@ -4041,7 +4059,8 @@ function collectExpressionScopeBindings(exp, context) {
|
|
|
4041
4059
|
if (!localSet.size) return [];
|
|
4042
4060
|
const used = [];
|
|
4043
4061
|
const usedSet = /* @__PURE__ */ new Set();
|
|
4044
|
-
|
|
4062
|
+
const file = t.file(t.program([t.expressionStatement(t.cloneNode(exp, true))]));
|
|
4063
|
+
traverse(file, { Identifier(path) {
|
|
4045
4064
|
if (!path.isReferencedIdentifier()) return;
|
|
4046
4065
|
const name = path.node.name;
|
|
4047
4066
|
if (!localSet.has(name)) return;
|
|
@@ -5157,12 +5176,13 @@ function analyzeScript(source, filename) {
|
|
|
5157
5176
|
usesFreeUni: false,
|
|
5158
5177
|
virtualHostTrueRanges: []
|
|
5159
5178
|
};
|
|
5179
|
+
const isJsx = /\.[cm]?[jt]sx$/i.test(filename);
|
|
5160
5180
|
const ast = parse$3(source, {
|
|
5161
5181
|
sourceType: "module",
|
|
5162
5182
|
plugins: [
|
|
5163
5183
|
"typescript",
|
|
5164
5184
|
"decorators-legacy",
|
|
5165
|
-
|
|
5185
|
+
...isJsx ? ["jsx"] : []
|
|
5166
5186
|
]
|
|
5167
5187
|
});
|
|
5168
5188
|
const importSources = [];
|
|
@@ -5310,6 +5330,14 @@ function normalizeLineEndings(source) {
|
|
|
5310
5330
|
const mtimeCache = /* @__PURE__ */ new Map();
|
|
5311
5331
|
const loadCache = new LRUCache({ max: 1024 });
|
|
5312
5332
|
const pathExistsCache = new LRUCache({ max: 4096 });
|
|
5333
|
+
const transientRenameRetryDelays = [
|
|
5334
|
+
10,
|
|
5335
|
+
25,
|
|
5336
|
+
50
|
|
5337
|
+
];
|
|
5338
|
+
function isMissingFileError(error) {
|
|
5339
|
+
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
5340
|
+
}
|
|
5313
5341
|
/**
|
|
5314
5342
|
* 返回 true 的时候需要重新 fs 读取
|
|
5315
5343
|
* @param id 文件路径
|
|
@@ -5354,13 +5382,19 @@ async function readFile(id, options) {
|
|
|
5354
5382
|
loadCache.set(id, content);
|
|
5355
5383
|
return content;
|
|
5356
5384
|
}
|
|
5357
|
-
|
|
5358
|
-
|
|
5359
|
-
|
|
5385
|
+
for (let attempt = 0;; attempt += 1) try {
|
|
5386
|
+
if (!await isInvalidate(id)) {
|
|
5387
|
+
const cached = loadCache.get(id);
|
|
5388
|
+
if (cached !== void 0) return cached;
|
|
5389
|
+
}
|
|
5390
|
+
const content = normalizeLineEndings(await readFile$1(id, encoding));
|
|
5391
|
+
loadCache.set(id, content);
|
|
5392
|
+
return content;
|
|
5393
|
+
} catch (error) {
|
|
5394
|
+
const retryDelay = transientRenameRetryDelays[attempt];
|
|
5395
|
+
if (!isMissingFileError(error) || retryDelay === void 0) throw error;
|
|
5396
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
5360
5397
|
}
|
|
5361
|
-
const content = normalizeLineEndings(await readFile$1(id, encoding));
|
|
5362
|
-
loadCache.set(id, content);
|
|
5363
|
-
return content;
|
|
5364
5398
|
}
|
|
5365
5399
|
/**
|
|
5366
5400
|
* 判断文件或路径是否存在,可选缓存。
|
|
@@ -6383,12 +6417,14 @@ function parseForExpression(exp) {
|
|
|
6383
6417
|
if (!segments.length || segments.length > 3) return { listExp: split.list };
|
|
6384
6418
|
const result = { listExp: split.list };
|
|
6385
6419
|
const rawItem = segments[0]?.trim();
|
|
6386
|
-
if (rawItem)
|
|
6387
|
-
|
|
6388
|
-
|
|
6389
|
-
|
|
6390
|
-
|
|
6391
|
-
|
|
6420
|
+
if (rawItem) {
|
|
6421
|
+
if (isIdentifier(rawItem)) result.item = rawItem;
|
|
6422
|
+
else {
|
|
6423
|
+
const aliases = parseItemAliases(rawItem);
|
|
6424
|
+
if (Object.keys(aliases).length) {
|
|
6425
|
+
result.item = FOR_ITEM_ALIAS_PLACEHOLDER;
|
|
6426
|
+
result.itemAliases = aliases;
|
|
6427
|
+
}
|
|
6392
6428
|
}
|
|
6393
6429
|
}
|
|
6394
6430
|
if (segments.length === 2) {
|
|
@@ -7123,13 +7159,14 @@ function normalizeJsExpressionWithContext(exp, context, options) {
|
|
|
7123
7159
|
}
|
|
7124
7160
|
if (locals.has(name)) return;
|
|
7125
7161
|
let replacement;
|
|
7126
|
-
if (context.rewriteScopedSlot)
|
|
7127
|
-
|
|
7128
|
-
|
|
7129
|
-
|
|
7130
|
-
|
|
7131
|
-
|
|
7132
|
-
|
|
7162
|
+
if (context.rewriteScopedSlot) {
|
|
7163
|
+
if (hasOwn(slotProps, name)) {
|
|
7164
|
+
const prop = slotProps[name];
|
|
7165
|
+
const base = createThisMemberAccess(WEVU_SLOT_PROPS_DATA_KEY);
|
|
7166
|
+
replacement = createUnrefCall(prop ? createMemberAccess(base, prop) : base);
|
|
7167
|
+
} 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));
|
|
7168
|
+
else replacement = createUnrefCall(createMemberAccess(createThisMemberAccess(WEVU_SLOT_OWNER_PROXY_KEY), name));
|
|
7169
|
+
} else {
|
|
7133
7170
|
const propsAlias = context.propsAliases?.[name];
|
|
7134
7171
|
replacement = createUnrefCall(propsAlias ? createAliasedPropsAccess(name, propsAlias) : createIdentifierAccessWithPropsFallback(name, context, options?.runtimePropAccess === "helper"));
|
|
7135
7172
|
}
|
|
@@ -7468,11 +7505,12 @@ function transformBindDirective(node, context, forInfo, options) {
|
|
|
7468
7505
|
if (!rawExpValue) return null;
|
|
7469
7506
|
if (options?.isComponent && !COMPONENT_NON_PROP_BINDINGS.has(argValue)) {
|
|
7470
7507
|
const path = collectFunctionPropPath(rawExpValue);
|
|
7471
|
-
if (path)
|
|
7472
|
-
|
|
7473
|
-
|
|
7474
|
-
|
|
7475
|
-
|
|
7508
|
+
if (path) {
|
|
7509
|
+
if (shouldWrapStaticMemberFunctionProp(argValue, path, context)) {
|
|
7510
|
+
const runtimeAttr = createFunctionPropRuntimeAttr(argValue, rawExpValue, context);
|
|
7511
|
+
if (runtimeAttr) return runtimeAttr;
|
|
7512
|
+
} else context.functionPropPaths.add(path);
|
|
7513
|
+
} else if (shouldUseRuntimeFunctionPropBinding(argValue, context) && isComputedMemberExpression(rawExpValue)) {
|
|
7476
7514
|
const runtimeAttr = createFunctionPropRuntimeAttr(argValue, rawExpValue, context);
|
|
7477
7515
|
if (runtimeAttr) return runtimeAttr;
|
|
7478
7516
|
}
|
|
@@ -7860,7 +7898,8 @@ function collectElementAttributes(node, context, options) {
|
|
|
7860
7898
|
}
|
|
7861
7899
|
if (mappedTagClass) staticClass = prependStaticClass(staticClass, mappedTagClass);
|
|
7862
7900
|
if (templateRef) {
|
|
7863
|
-
const
|
|
7901
|
+
const refIndex = context.templateRefIndexSeed++;
|
|
7902
|
+
const className = `${WEVU_TEMPLATE_REF_CLASS_PREFIX}${refIndex}`;
|
|
7864
7903
|
staticClass = staticClass ? `${staticClass} ${className}` : className;
|
|
7865
7904
|
context.templateRefs.push({
|
|
7866
7905
|
selector: `.${className}`,
|
|
@@ -7870,24 +7909,26 @@ function collectElementAttributes(node, context, options) {
|
|
|
7870
7909
|
kind: isComponentElement ? "component" : "element"
|
|
7871
7910
|
});
|
|
7872
7911
|
}
|
|
7873
|
-
if (layoutHostKey)
|
|
7874
|
-
|
|
7875
|
-
|
|
7876
|
-
|
|
7877
|
-
|
|
7878
|
-
|
|
7879
|
-
|
|
7880
|
-
|
|
7881
|
-
|
|
7882
|
-
|
|
7883
|
-
|
|
7884
|
-
|
|
7885
|
-
|
|
7886
|
-
|
|
7887
|
-
|
|
7888
|
-
|
|
7889
|
-
|
|
7890
|
-
|
|
7912
|
+
if (layoutHostKey) {
|
|
7913
|
+
if (!staticId && hasDynamicIdBinding) context.warnings.push("layout-host 暂不支持与动态 id 同时使用,当前节点已忽略。");
|
|
7914
|
+
else {
|
|
7915
|
+
const hostIndex = context.layoutHostIndexSeed++;
|
|
7916
|
+
const hostId = staticId || `${WEVU_LAYOUT_HOST_ID_PREFIX}${hostIndex}`;
|
|
7917
|
+
const hostRefName = `${WEVU_LAYOUT_HOST_REF_PREFIX}${hostIndex}`;
|
|
7918
|
+
staticId = hostId;
|
|
7919
|
+
context.templateRefs.push({
|
|
7920
|
+
selector: `#${hostId}`,
|
|
7921
|
+
inFor: false,
|
|
7922
|
+
name: hostRefName,
|
|
7923
|
+
kind: "component"
|
|
7924
|
+
});
|
|
7925
|
+
context.layoutHosts.push({
|
|
7926
|
+
key: layoutHostKey,
|
|
7927
|
+
refName: hostRefName,
|
|
7928
|
+
selector: `#${hostId}`,
|
|
7929
|
+
kind: "component"
|
|
7930
|
+
});
|
|
7931
|
+
}
|
|
7891
7932
|
}
|
|
7892
7933
|
if (staticId) attrs.unshift(`id="${staticId}"`);
|
|
7893
7934
|
const classAttr = renderClassAttribute(staticClass, dynamicClassExp, context);
|
|
@@ -8069,7 +8110,8 @@ const SLOT_PRESENCE_IDENTIFIER_RE = /^[A-Z_$][\w$]*$/i;
|
|
|
8069
8110
|
function createSlotPresenceExpression(info) {
|
|
8070
8111
|
const slotName = resolveSlotStaticName(info);
|
|
8071
8112
|
if (!slotName) return;
|
|
8072
|
-
|
|
8113
|
+
const access = SLOT_PRESENCE_IDENTIFIER_RE.test(slotName) ? `${WEVU_SLOT_NAMES_PROP}.${slotName}` : `${WEVU_SLOT_NAMES_PROP}['${slotName.replace(/\\/g, "\\\\").replace(/'/g, "\\'")}']`;
|
|
8114
|
+
return `${WEVU_SLOT_NAMES_PROP}&&${access}`;
|
|
8073
8115
|
}
|
|
8074
8116
|
function buildSlotDeclaration(name, propsExp, children, context, options) {
|
|
8075
8117
|
return {
|
|
@@ -8606,12 +8648,13 @@ function transformComponentWithSlots(node, context, transformNode, options) {
|
|
|
8606
8648
|
if (slotDeclarations.length) context.warnings.push("组件上的 v-slot 与 <template v-slot> 不能同时使用;仅使用组件上的 v-slot。");
|
|
8607
8649
|
slotDeclarations.length = 0;
|
|
8608
8650
|
slotDeclarations.push(buildSlotDeclaration(resolveSlotNameFromDirective(slotDirective), slotDirective.exp?.type === NodeTypes.SIMPLE_EXPRESSION ? slotDirective.exp.content : void 0, node.children, context, { wrapper: ownerWrapper }));
|
|
8609
|
-
} else if (slotDeclarations.length && defaultSlotChildren.length)
|
|
8610
|
-
|
|
8611
|
-
|
|
8612
|
-
|
|
8613
|
-
|
|
8614
|
-
|
|
8651
|
+
} else if (slotDeclarations.length && defaultSlotChildren.length) {
|
|
8652
|
+
if (slotDeclarations.some((decl) => decl.name.type === "default" || decl.name.type === "static" && decl.name.value === "default")) context.warnings.push("存在显式的 v-slot:default,默认插槽内容将被忽略。");
|
|
8653
|
+
else {
|
|
8654
|
+
implicitDefaultDeclaration = buildSlotDeclaration({ type: "default" }, void 0, defaultSlotChildren, context, { implicitDefault: true });
|
|
8655
|
+
slotDeclarations.push(implicitDefaultDeclaration);
|
|
8656
|
+
}
|
|
8657
|
+
} else if (!slotDeclarations.length && defaultSlotChildren.length && !context.scopedSlotsRequireProps && !hasLegacySlotAttribute(defaultSlotChildren)) {
|
|
8615
8658
|
implicitDefaultDeclaration = buildSlotDeclaration({ type: "default" }, void 0, defaultSlotChildren, context, { implicitDefault: true });
|
|
8616
8659
|
slotDeclarations.push(implicitDefaultDeclaration);
|
|
8617
8660
|
}
|
|
@@ -8713,10 +8756,12 @@ function transformComponentWithSlotsFallback(node, context, transformNode, optio
|
|
|
8713
8756
|
if (slotDeclarations.length) context.warnings.push("组件上的 v-slot 与 <template v-slot> 不能同时使用;仅使用组件上的 v-slot。");
|
|
8714
8757
|
slotDeclarations.length = 0;
|
|
8715
8758
|
slotDeclarations.push(buildSlotDeclaration(resolveSlotNameFromDirective(slotDirective), slotDirective.exp?.type === NodeTypes.SIMPLE_EXPRESSION ? slotDirective.exp.content : void 0, node.children, context, { wrapper: ownerWrapper }));
|
|
8716
|
-
} else if (slotDeclarations.length && defaultSlotChildren.length)
|
|
8717
|
-
|
|
8718
|
-
|
|
8719
|
-
|
|
8759
|
+
} else if (slotDeclarations.length && defaultSlotChildren.length) {
|
|
8760
|
+
if (slotDeclarations.some((decl) => decl.name.type === "default" || decl.name.type === "static" && decl.name.value === "default")) context.warnings.push("存在显式的 v-slot:default,默认插槽内容将被忽略。");
|
|
8761
|
+
else {
|
|
8762
|
+
implicitDefaultDeclaration = buildSlotDeclaration({ type: "default" }, void 0, defaultSlotChildren, context);
|
|
8763
|
+
slotDeclarations.push(implicitDefaultDeclaration);
|
|
8764
|
+
}
|
|
8720
8765
|
}
|
|
8721
8766
|
if (!slotDeclarations.length) {
|
|
8722
8767
|
const { attrs, vTextExp } = collectElementAttributes(node, context, {
|
|
@@ -9528,7 +9573,8 @@ async function evaluateJsLikeConfig(source, filename, lang) {
|
|
|
9528
9573
|
return await withTempDirLock(tempRoot, async () => {
|
|
9529
9574
|
await ensureDir(tempDir);
|
|
9530
9575
|
const tempFile = path.join(tempDir, `${basename}.${unique}.${extension}`);
|
|
9531
|
-
|
|
9576
|
+
const rewritten = rewriteJsLikeImportsForTempDir(source, dir, tempDir);
|
|
9577
|
+
await writeFile(tempFile, rewritten, "utf8");
|
|
9532
9578
|
try {
|
|
9533
9579
|
const { mod } = await bundleRequire({
|
|
9534
9580
|
filepath: tempFile,
|
|
@@ -9706,7 +9752,8 @@ function tryConvertObjectMethodSourceToFunctionExpression(source) {
|
|
|
9706
9752
|
if (!firstProperty) return null;
|
|
9707
9753
|
if (t.isObjectMethod(firstProperty)) {
|
|
9708
9754
|
const functionName = t.isIdentifier(firstProperty.key) ? t.identifier(firstProperty.key.name) : null;
|
|
9709
|
-
|
|
9755
|
+
const functionExpression = t.functionExpression(functionName, firstProperty.params, firstProperty.body, firstProperty.generator, firstProperty.async);
|
|
9756
|
+
return generate(functionExpression).code;
|
|
9710
9757
|
}
|
|
9711
9758
|
if (t.isObjectProperty(firstProperty) && (t.isFunctionExpression(firstProperty.value) || t.isArrowFunctionExpression(firstProperty.value))) return generate(firstProperty.value).code;
|
|
9712
9759
|
} catch {}
|
|
@@ -10088,18 +10135,59 @@ async function parseVueFile(source, filename, options) {
|
|
|
10088
10135
|
merge: (target, source) => mergeJson(target, source, "macro"),
|
|
10089
10136
|
preambleContent: resolvedDescriptor.script?.content
|
|
10090
10137
|
});
|
|
10091
|
-
if (extracted.stripped !== scriptSetup.content)
|
|
10138
|
+
if (extracted.stripped !== scriptSetup.content) {
|
|
10139
|
+
if (scriptSetup.src) descriptorForCompile = {
|
|
10140
|
+
...descriptorForCompile,
|
|
10141
|
+
scriptSetup: {
|
|
10142
|
+
...descriptorForCompile.scriptSetup,
|
|
10143
|
+
content: extracted.stripped
|
|
10144
|
+
}
|
|
10145
|
+
};
|
|
10146
|
+
else {
|
|
10147
|
+
const setupLoc = scriptSetup.loc;
|
|
10148
|
+
const startOffset = setupLoc.start.offset;
|
|
10149
|
+
const endOffset = setupLoc.end.offset;
|
|
10150
|
+
const nextSource = descriptorForCompileSource.slice(0, startOffset) + extracted.stripped + descriptorForCompileSource.slice(endOffset);
|
|
10151
|
+
const { descriptor: nextDescriptor, errors: nextErrors } = await parseSfc(nextSource, filename, false);
|
|
10152
|
+
restoreScriptSetupSrc(nextDescriptor);
|
|
10153
|
+
restoreScriptSrc(nextDescriptor);
|
|
10154
|
+
if (nextErrors.length > 0) {
|
|
10155
|
+
const error = nextErrors[0];
|
|
10156
|
+
throw new Error(`解析 ${filename} 失败:${error.message}`);
|
|
10157
|
+
}
|
|
10158
|
+
assertMatchingSfcScriptLang(nextDescriptor, filename);
|
|
10159
|
+
if (options?.sfcSrc) {
|
|
10160
|
+
const resolvedNext = await resolveSfcBlockSrc(nextDescriptor, filename, options.sfcSrc);
|
|
10161
|
+
descriptorForCompile = resolvedNext.descriptor;
|
|
10162
|
+
if (resolvedNext.deps.length) {
|
|
10163
|
+
sfcSrcDeps = [.../* @__PURE__ */ new Set([...sfcSrcDeps ?? [], ...resolvedNext.deps])];
|
|
10164
|
+
meta.sfcSrcDeps = sfcSrcDeps;
|
|
10165
|
+
}
|
|
10166
|
+
} else descriptorForCompile = nextDescriptor;
|
|
10167
|
+
descriptorForCompileSource = nextSource;
|
|
10168
|
+
}
|
|
10169
|
+
}
|
|
10170
|
+
scriptSetupMacroConfig = extracted.config;
|
|
10171
|
+
scriptSetupMacroHash = extracted.macroHash;
|
|
10172
|
+
}
|
|
10173
|
+
if (DEFINE_OPTIONS_CALL_RE.test(scriptSetup.content)) defineOptionsHash = extractDefineOptionsHash(scriptSetup.content);
|
|
10174
|
+
}
|
|
10175
|
+
const compileScriptSetup = descriptorForCompile.scriptSetup;
|
|
10176
|
+
if (compileScriptSetup?.content && DEFINE_OPTIONS_CALL_RE.test(compileScriptSetup.content)) {
|
|
10177
|
+
const inlined = await inlineScriptSetupDefineOptionsArgs(compileScriptSetup.content, filename, compileScriptSetup.lang);
|
|
10178
|
+
if (inlined.code !== compileScriptSetup.content) {
|
|
10179
|
+
if (compileScriptSetup.src) descriptorForCompile = {
|
|
10092
10180
|
...descriptorForCompile,
|
|
10093
10181
|
scriptSetup: {
|
|
10094
|
-
...
|
|
10095
|
-
content:
|
|
10182
|
+
...compileScriptSetup,
|
|
10183
|
+
content: inlined.code
|
|
10096
10184
|
}
|
|
10097
10185
|
};
|
|
10098
10186
|
else {
|
|
10099
|
-
const setupLoc =
|
|
10187
|
+
const setupLoc = compileScriptSetup.loc;
|
|
10100
10188
|
const startOffset = setupLoc.start.offset;
|
|
10101
10189
|
const endOffset = setupLoc.end.offset;
|
|
10102
|
-
const nextSource = descriptorForCompileSource.slice(0, startOffset) +
|
|
10190
|
+
const nextSource = descriptorForCompileSource.slice(0, startOffset) + inlined.code + descriptorForCompileSource.slice(endOffset);
|
|
10103
10191
|
const { descriptor: nextDescriptor, errors: nextErrors } = await parseSfc(nextSource, filename, false);
|
|
10104
10192
|
restoreScriptSetupSrc(nextDescriptor);
|
|
10105
10193
|
restoreScriptSrc(nextDescriptor);
|
|
@@ -10118,43 +10206,6 @@ async function parseVueFile(source, filename, options) {
|
|
|
10118
10206
|
} else descriptorForCompile = nextDescriptor;
|
|
10119
10207
|
descriptorForCompileSource = nextSource;
|
|
10120
10208
|
}
|
|
10121
|
-
scriptSetupMacroConfig = extracted.config;
|
|
10122
|
-
scriptSetupMacroHash = extracted.macroHash;
|
|
10123
|
-
}
|
|
10124
|
-
if (DEFINE_OPTIONS_CALL_RE.test(scriptSetup.content)) defineOptionsHash = extractDefineOptionsHash(scriptSetup.content);
|
|
10125
|
-
}
|
|
10126
|
-
const compileScriptSetup = descriptorForCompile.scriptSetup;
|
|
10127
|
-
if (compileScriptSetup?.content && DEFINE_OPTIONS_CALL_RE.test(compileScriptSetup.content)) {
|
|
10128
|
-
const inlined = await inlineScriptSetupDefineOptionsArgs(compileScriptSetup.content, filename, compileScriptSetup.lang);
|
|
10129
|
-
if (inlined.code !== compileScriptSetup.content) if (compileScriptSetup.src) descriptorForCompile = {
|
|
10130
|
-
...descriptorForCompile,
|
|
10131
|
-
scriptSetup: {
|
|
10132
|
-
...compileScriptSetup,
|
|
10133
|
-
content: inlined.code
|
|
10134
|
-
}
|
|
10135
|
-
};
|
|
10136
|
-
else {
|
|
10137
|
-
const setupLoc = compileScriptSetup.loc;
|
|
10138
|
-
const startOffset = setupLoc.start.offset;
|
|
10139
|
-
const endOffset = setupLoc.end.offset;
|
|
10140
|
-
const nextSource = descriptorForCompileSource.slice(0, startOffset) + inlined.code + descriptorForCompileSource.slice(endOffset);
|
|
10141
|
-
const { descriptor: nextDescriptor, errors: nextErrors } = await parseSfc(nextSource, filename, false);
|
|
10142
|
-
restoreScriptSetupSrc(nextDescriptor);
|
|
10143
|
-
restoreScriptSrc(nextDescriptor);
|
|
10144
|
-
if (nextErrors.length > 0) {
|
|
10145
|
-
const error = nextErrors[0];
|
|
10146
|
-
throw new Error(`解析 ${filename} 失败:${error.message}`);
|
|
10147
|
-
}
|
|
10148
|
-
assertMatchingSfcScriptLang(nextDescriptor, filename);
|
|
10149
|
-
if (options?.sfcSrc) {
|
|
10150
|
-
const resolvedNext = await resolveSfcBlockSrc(nextDescriptor, filename, options.sfcSrc);
|
|
10151
|
-
descriptorForCompile = resolvedNext.descriptor;
|
|
10152
|
-
if (resolvedNext.deps.length) {
|
|
10153
|
-
sfcSrcDeps = [.../* @__PURE__ */ new Set([...sfcSrcDeps ?? [], ...resolvedNext.deps])];
|
|
10154
|
-
meta.sfcSrcDeps = sfcSrcDeps;
|
|
10155
|
-
}
|
|
10156
|
-
} else descriptorForCompile = nextDescriptor;
|
|
10157
|
-
descriptorForCompileSource = nextSource;
|
|
10158
10209
|
}
|
|
10159
10210
|
}
|
|
10160
10211
|
const isAppFile = APP_VUE_FILE_RE.test(filename);
|
|
@@ -10341,7 +10392,8 @@ function collectScriptSetupReturnInfo(scriptCode) {
|
|
|
10341
10392
|
}
|
|
10342
10393
|
};
|
|
10343
10394
|
try {
|
|
10344
|
-
|
|
10395
|
+
const ast = parseJsLike(scriptCode);
|
|
10396
|
+
traverse(ast, {
|
|
10345
10397
|
VariableDeclarator(path) {
|
|
10346
10398
|
const init = path.node.init;
|
|
10347
10399
|
if (t.isIdentifier(path.node.id) && t.isIdentifier(init) && propsObjectAliases.has(init.name)) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wevu/compiler",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.19.
|
|
4
|
+
"version": "6.19.2",
|
|
5
5
|
"description": "wevu 编译器基础包,面向小程序模板的编译与转换",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -42,20 +42,20 @@
|
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@jridgewell/remapping": "^2.3.5",
|
|
45
|
-
"@vue/compiler-core": "^3.5.
|
|
46
|
-
"@vue/compiler-dom": "^3.5.
|
|
45
|
+
"@vue/compiler-core": "^3.5.41",
|
|
46
|
+
"@vue/compiler-dom": "^3.5.41",
|
|
47
47
|
"comment-json": "^5.0.0",
|
|
48
48
|
"lru-cache": "^11.5.2",
|
|
49
49
|
"magic-string": "^1.1.0",
|
|
50
50
|
"merge": "^2.1.1",
|
|
51
51
|
"pathe": "^2.0.3",
|
|
52
|
-
"postcss": "^8.5.
|
|
52
|
+
"postcss": "^8.5.26",
|
|
53
53
|
"postcss-selector-parser": "^7.1.4",
|
|
54
|
-
"vue": "^3.5.
|
|
55
|
-
"@weapp-core/constants": "0.1.
|
|
54
|
+
"vue": "^3.5.41",
|
|
55
|
+
"@weapp-core/constants": "0.1.16",
|
|
56
56
|
"@weapp-core/shared": "3.1.0",
|
|
57
|
-
"@weapp-vite/ast": "6.19.
|
|
58
|
-
"rolldown-require": "2.0.
|
|
57
|
+
"@weapp-vite/ast": "6.19.2",
|
|
58
|
+
"rolldown-require": "2.0.23"
|
|
59
59
|
},
|
|
60
60
|
"publishConfig": {
|
|
61
61
|
"access": "public",
|