Skip to content

Commit

Permalink
fix(clone): Accept all expressions in owned tpl trees
Browse files Browse the repository at this point in the history
Issue: https://linear.app/plasmic/issue/PLA-11274
Change-Id: If11d5df5ccda97de6448c73f1a372c7f369de608
GitOrigin-RevId: ccd7e0d3400c8da50275c5567fc50f303c691831
  • Loading branch information
FMota0 authored and actions-user committed Oct 18, 2024
1 parent c042d6b commit 939a48a
Showing 1 changed file with 59 additions and 42 deletions.
101 changes: 59 additions & 42 deletions platform/wab/src/wab/shared/insertable-templates/fixers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
import {
TokenType,
derefToken,
derefTokenRefs,
hasTokenRefs,
maybeDerefToken,
mkTokenRef,
replaceAllTokenRefs,
} from "@/wab/commons/StyleToken";
import {
RSH,
RuleSetHelpers,
joinCssValues,
splitCssValue,
} from "@/wab/shared/RuleSetHelpers";
import { TplMgr } from "@/wab/shared/TplMgr";
import { VariantedStylesHelper } from "@/wab/shared/VariantedStylesHelper";
import {
isBaseVariant,
isGlobalVariant,
isScreenVariant,
} from "@/wab/shared/Variants";
import { toVarName } from "@/wab/shared/codegen/util";
import {
arrayEqIgnoreOrder,
assert,
Expand All @@ -7,20 +30,22 @@ import {
withoutNils,
} from "@/wab/shared/common";
import {
derefToken,
derefTokenRefs,
hasTokenRefs,
maybeDerefToken,
mkTokenRef,
replaceAllTokenRefs,
TokenType,
} from "@/wab/commons/StyleToken";
import { isCodeComponent, isPlumeComponent } from "@/wab/shared/core/components";
import { InsertableTemplateTokenResolution } from "@/wab/shared/devflags";
isCodeComponent,
isPlumeComponent,
} from "@/wab/shared/core/components";
import { code, isFallbackableExpr } from "@/wab/shared/core/exprs";
import { ImageAssetType } from "@/wab/shared/core/image-asset-type";
import { mkImageAssetRef } from "@/wab/shared/core/image-assets";
import { toVarName } from "@/wab/shared/codegen/util";
import {
TplTextTag,
findVariantSettingsUnderTpl,
flattenTpls,
isTplComponent,
isTplSlot,
isTplTextBlock,
walkTpls,
} from "@/wab/shared/core/tpls";
import { InsertableTemplateTokenResolution } from "@/wab/shared/devflags";
import { getEffectiveVariantSettingForInsertable } from "@/wab/shared/effective-variant-setting";
import {
inlineMixins,
Expand All @@ -35,11 +60,6 @@ import {
Expr,
ImageAsset,
ImageAssetRef,
isKnownCustomCode,
isKnownExprText,
isKnownObjectPath,
isKnownTemplatedString,
isKnownTplTag,
ObjectPath,
PageHref,
RenderExpr,
Expand All @@ -49,35 +69,18 @@ import {
StyleToken,
TemplatedString,
TplNode,
VarRef,
Variant,
VariantedValue,
VariantSetting,
VariantedValue,
VariantsRef,
VarRef,
VirtualRenderExpr,
isKnownCustomCode,
isKnownExprText,
isKnownObjectPath,
isKnownTemplatedString,
isKnownTplTag,
} from "@/wab/shared/model/classes";
import {
joinCssValues,
RSH,
RuleSetHelpers,
splitCssValue,
} from "@/wab/shared/RuleSetHelpers";
import { TplMgr } from "@/wab/shared/TplMgr";
import { VariantedStylesHelper } from "@/wab/shared/VariantedStylesHelper";
import {
isBaseVariant,
isGlobalVariant,
isScreenVariant,
} from "@/wab/shared/Variants";
import {
findVariantSettingsUnderTpl,
flattenTpls,
isTplComponent,
isTplSlot,
isTplTextBlock,
TplTextTag,
walkTpls,
} from "@/wab/shared/core/tpls";
import { isString } from "lodash";

export function ensureTplWithBaseAndScreenVariants(
Expand Down Expand Up @@ -501,6 +504,21 @@ function getFixedExpr(
helpers: Pick<ContextHelpers, "getNewImageAsset">
) {
const { isOwned, invalidExprNames } = ctx;

if (isOwned) {
// If we are dealing with an owned tree, we just need to fix image assets references to be sure
// that they are included in the new site
return switchType(expr)
.when([ImageAssetRef], (_expr) => {
const newAsset = helpers.getNewImageAsset(_expr.asset);
if (newAsset) {
return new ImageAssetRef({ asset: newAsset });
}
return null;
})
.elseUnsafe(() => expr);
}

return (
switchType(expr)
.when([CustomCode, ObjectPath, TemplatedString], (_expr) => {
Expand All @@ -526,8 +544,7 @@ function getFixedExpr(
}
return null;
})
// If we are dealing with an owned tree, we can keep variable references
.when([VarRef], (_expr) => (isOwned ? expr : null))
.when([VarRef], (_expr) => null)
// TODO: handle event handlers, this may depend on `isOwned`
.when([EventHandler], (_expr) => {
return null;
Expand Down

0 comments on commit 939a48a

Please sign in to comment.