@wevu/compiler 6.6.13 → 6.6.15
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 +82 -12
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1441,13 +1441,13 @@ function createModuleAnalysis(id, ast) {
|
|
|
1441
1441
|
|
|
1442
1442
|
//#endregion
|
|
1443
1443
|
//#region src/plugins/wevu/pageFeatures/optionsObjects.ts
|
|
1444
|
-
function unwrapTypeLikeExpression$
|
|
1445
|
-
if (t.isTSAsExpression(node) || t.isTSSatisfiesExpression(node) || t.isTSNonNullExpression(node) || t.isTypeCastExpression(node)) return unwrapTypeLikeExpression$
|
|
1446
|
-
if (t.isParenthesizedExpression(node)) return unwrapTypeLikeExpression$
|
|
1444
|
+
function unwrapTypeLikeExpression$2(node) {
|
|
1445
|
+
if (t.isTSAsExpression(node) || t.isTSSatisfiesExpression(node) || t.isTSNonNullExpression(node) || t.isTypeCastExpression(node)) return unwrapTypeLikeExpression$2(node.expression);
|
|
1446
|
+
if (t.isParenthesizedExpression(node)) return unwrapTypeLikeExpression$2(node.expression);
|
|
1447
1447
|
return node;
|
|
1448
1448
|
}
|
|
1449
1449
|
function resolveOptionsObjectFromExpression(node) {
|
|
1450
|
-
const normalized = unwrapTypeLikeExpression$
|
|
1450
|
+
const normalized = unwrapTypeLikeExpression$2(node);
|
|
1451
1451
|
if (t.isObjectExpression(normalized)) return normalized;
|
|
1452
1452
|
if (t.isIdentifier(normalized)) return null;
|
|
1453
1453
|
if (t.isCallExpression(normalized)) {
|
|
@@ -1951,21 +1951,21 @@ function vueSfcTransformPlugin() {
|
|
|
1951
1951
|
function isDefineComponentCall(node, aliases) {
|
|
1952
1952
|
return t.isIdentifier(node.callee) && aliases.has(node.callee.name);
|
|
1953
1953
|
}
|
|
1954
|
-
function isObjectAssignCall(node) {
|
|
1954
|
+
function isObjectAssignCall$1(node) {
|
|
1955
1955
|
const callee = node.callee;
|
|
1956
1956
|
return t.isMemberExpression(callee) && t.isIdentifier(callee.object, { name: "Object" }) && t.isIdentifier(callee.property, { name: "assign" });
|
|
1957
1957
|
}
|
|
1958
|
-
function unwrapTypeLikeExpression(node) {
|
|
1959
|
-
if (t.isTSAsExpression(node) || t.isTSSatisfiesExpression(node) || t.isTSNonNullExpression(node) || t.isTypeCastExpression(node)) return unwrapTypeLikeExpression(node.expression);
|
|
1960
|
-
if (t.isParenthesizedExpression(node)) return unwrapTypeLikeExpression(node.expression);
|
|
1958
|
+
function unwrapTypeLikeExpression$1(node) {
|
|
1959
|
+
if (t.isTSAsExpression(node) || t.isTSSatisfiesExpression(node) || t.isTSNonNullExpression(node) || t.isTypeCastExpression(node)) return unwrapTypeLikeExpression$1(node.expression);
|
|
1960
|
+
if (t.isParenthesizedExpression(node)) return unwrapTypeLikeExpression$1(node.expression);
|
|
1961
1961
|
return node;
|
|
1962
1962
|
}
|
|
1963
1963
|
function resolveObjectExpressionFromAssignCall(node) {
|
|
1964
|
-
if (!isObjectAssignCall(node)) return null;
|
|
1964
|
+
if (!isObjectAssignCall$1(node)) return null;
|
|
1965
1965
|
for (let index = node.arguments.length - 1; index >= 0; index -= 1) {
|
|
1966
1966
|
const arg = node.arguments[index];
|
|
1967
1967
|
if (t.isSpreadElement(arg) || !t.isExpression(arg)) continue;
|
|
1968
|
-
const normalized = unwrapTypeLikeExpression(arg);
|
|
1968
|
+
const normalized = unwrapTypeLikeExpression$1(arg);
|
|
1969
1969
|
if (t.isObjectExpression(normalized)) return normalized;
|
|
1970
1970
|
}
|
|
1971
1971
|
return null;
|
|
@@ -1990,7 +1990,7 @@ function resolveComponentExpression(declaration, defineComponentDecls, aliases)
|
|
|
1990
1990
|
if (t.isExpression(arg)) return arg;
|
|
1991
1991
|
return null;
|
|
1992
1992
|
}
|
|
1993
|
-
if (t.isCallExpression(declaration) && isObjectAssignCall(declaration)) return declaration;
|
|
1993
|
+
if (t.isCallExpression(declaration) && isObjectAssignCall$1(declaration)) return declaration;
|
|
1994
1994
|
if (t.isIdentifier(declaration)) {
|
|
1995
1995
|
const matched = defineComponentDecls.get(declaration.name);
|
|
1996
1996
|
return matched ? t.cloneNode(matched, true) : null;
|
|
@@ -1999,7 +1999,7 @@ function resolveComponentExpression(declaration, defineComponentDecls, aliases)
|
|
|
1999
1999
|
}
|
|
2000
2000
|
function resolveComponentOptionsObject(componentExpr) {
|
|
2001
2001
|
if (!componentExpr) return null;
|
|
2002
|
-
const normalized = unwrapTypeLikeExpression(componentExpr);
|
|
2002
|
+
const normalized = unwrapTypeLikeExpression$1(componentExpr);
|
|
2003
2003
|
if (t.isObjectExpression(normalized)) return normalized;
|
|
2004
2004
|
if (t.isCallExpression(normalized)) return resolveObjectExpressionFromAssignCall(normalized);
|
|
2005
2005
|
return null;
|
|
@@ -2712,6 +2712,71 @@ function injectTemplateRefs(optionsObject, bindings, warn) {
|
|
|
2712
2712
|
|
|
2713
2713
|
//#endregion
|
|
2714
2714
|
//#region src/plugins/vue/transform/transformScript/rewrite/index.ts
|
|
2715
|
+
function hasStaticProperty(target, keyName) {
|
|
2716
|
+
for (const prop of target.properties) {
|
|
2717
|
+
if (prop.type !== "ObjectProperty" && prop.type !== "ObjectMethod" || prop.computed) continue;
|
|
2718
|
+
const key = prop.key;
|
|
2719
|
+
if (key.type === "Identifier" && key.name === keyName) return true;
|
|
2720
|
+
if (key.type === "StringLiteral" && key.value === keyName) return true;
|
|
2721
|
+
}
|
|
2722
|
+
return false;
|
|
2723
|
+
}
|
|
2724
|
+
function isObjectAssignCall(node) {
|
|
2725
|
+
const callee = node.callee;
|
|
2726
|
+
return t.isMemberExpression(callee) && t.isIdentifier(callee.object, { name: "Object" }) && t.isIdentifier(callee.property, { name: "assign" });
|
|
2727
|
+
}
|
|
2728
|
+
function unwrapTypeLikeExpression(node) {
|
|
2729
|
+
if (t.isTSAsExpression(node) || t.isTSSatisfiesExpression(node) || t.isTSNonNullExpression(node) || t.isTypeCastExpression(node)) return unwrapTypeLikeExpression(node.expression);
|
|
2730
|
+
if (t.isParenthesizedExpression(node)) return unwrapTypeLikeExpression(node.expression);
|
|
2731
|
+
return node;
|
|
2732
|
+
}
|
|
2733
|
+
function resolveObjectExpressionFromProgram(program, name) {
|
|
2734
|
+
for (let index = program.body.length - 1; index >= 0; index -= 1) {
|
|
2735
|
+
const statement = program.body[index];
|
|
2736
|
+
if (!t.isVariableDeclaration(statement)) continue;
|
|
2737
|
+
for (const declarator of statement.declarations) {
|
|
2738
|
+
if (!t.isIdentifier(declarator.id, { name }) || !declarator.init || !t.isExpression(declarator.init)) continue;
|
|
2739
|
+
const normalized = unwrapTypeLikeExpression(declarator.init);
|
|
2740
|
+
if (t.isObjectExpression(normalized)) return normalized;
|
|
2741
|
+
if (t.isCallExpression(normalized) && isObjectAssignCall(normalized)) {
|
|
2742
|
+
const lastArg = normalized.arguments[normalized.arguments.length - 1];
|
|
2743
|
+
if (lastArg && !t.isSpreadElement(lastArg) && t.isExpression(lastArg)) {
|
|
2744
|
+
const lastNormalized = unwrapTypeLikeExpression(lastArg);
|
|
2745
|
+
if (t.isObjectExpression(lastNormalized)) return lastNormalized;
|
|
2746
|
+
}
|
|
2747
|
+
}
|
|
2748
|
+
}
|
|
2749
|
+
}
|
|
2750
|
+
return null;
|
|
2751
|
+
}
|
|
2752
|
+
function hasStaticPropertyWithSpreads(target, keyName, program, visited = /* @__PURE__ */ new Set()) {
|
|
2753
|
+
if (hasStaticProperty(target, keyName)) return true;
|
|
2754
|
+
for (const prop of target.properties) {
|
|
2755
|
+
if (!t.isSpreadElement(prop)) continue;
|
|
2756
|
+
const spreadArg = prop.argument;
|
|
2757
|
+
if (t.isObjectExpression(spreadArg) && hasStaticPropertyWithSpreads(spreadArg, keyName, program, visited)) return true;
|
|
2758
|
+
if (!t.isIdentifier(spreadArg) || visited.has(spreadArg.name)) continue;
|
|
2759
|
+
visited.add(spreadArg.name);
|
|
2760
|
+
const resolved = resolveObjectExpressionFromProgram(program, spreadArg.name);
|
|
2761
|
+
if (resolved && hasStaticPropertyWithSpreads(resolved, keyName, program, visited)) return true;
|
|
2762
|
+
}
|
|
2763
|
+
return false;
|
|
2764
|
+
}
|
|
2765
|
+
function hasStaticPropertyInComponentExpression(componentExpr, keyName, program) {
|
|
2766
|
+
const normalized = unwrapTypeLikeExpression(componentExpr);
|
|
2767
|
+
if (t.isObjectExpression(normalized)) return hasStaticPropertyWithSpreads(normalized, keyName, program);
|
|
2768
|
+
if (!t.isCallExpression(normalized) || !isObjectAssignCall(normalized)) return false;
|
|
2769
|
+
for (const arg of normalized.arguments) {
|
|
2770
|
+
if (t.isSpreadElement(arg) || !t.isExpression(arg)) continue;
|
|
2771
|
+
const expr = unwrapTypeLikeExpression(arg);
|
|
2772
|
+
if (t.isObjectExpression(expr) && hasStaticPropertyWithSpreads(expr, keyName, program)) return true;
|
|
2773
|
+
if (t.isIdentifier(expr)) {
|
|
2774
|
+
const resolved = resolveObjectExpressionFromProgram(program, expr.name);
|
|
2775
|
+
if (resolved && hasStaticPropertyWithSpreads(resolved, keyName, program, new Set([expr.name]))) return true;
|
|
2776
|
+
}
|
|
2777
|
+
}
|
|
2778
|
+
return false;
|
|
2779
|
+
}
|
|
2715
2780
|
function rewriteDefaultExport(ast, state, options, enabledPageFeatures, serializedWevuDefaults, parsedWevuDefaults) {
|
|
2716
2781
|
if (!state.defaultExportPath) return false;
|
|
2717
2782
|
const warn = resolveWarnHandler(options?.warn);
|
|
@@ -2719,6 +2784,11 @@ function rewriteDefaultExport(ast, state, options, enabledPageFeatures, serializ
|
|
|
2719
2784
|
const exportPath = state.defaultExportPath;
|
|
2720
2785
|
const componentExpr = resolveComponentExpression(exportPath.node.declaration, state.defineComponentDecls, state.defineComponentAliases);
|
|
2721
2786
|
const componentOptionsObject = resolveComponentOptionsObject(componentExpr);
|
|
2787
|
+
const hasPageMarker = componentExpr ? hasStaticPropertyInComponentExpression(componentExpr, "__wevu_isPage", ast.program) : false;
|
|
2788
|
+
if (componentOptionsObject && options?.isPage && !options?.isApp && !hasPageMarker) {
|
|
2789
|
+
componentOptionsObject.properties.splice(0, 0, t.objectProperty(t.identifier("__wevu_isPage"), t.booleanLiteral(true)));
|
|
2790
|
+
transformed = true;
|
|
2791
|
+
}
|
|
2722
2792
|
if (componentOptionsObject && enabledPageFeatures.size) transformed = injectWevuPageFeatureFlagsIntoOptionsObject(componentOptionsObject, enabledPageFeatures) || transformed;
|
|
2723
2793
|
if (componentOptionsObject && parsedWevuDefaults) transformed = applyWevuDefaultsToComponentOptions({
|
|
2724
2794
|
componentExpr: componentOptionsObject,
|