Skip to content

Commit

Permalink
Merge pull request #183 from player-ui/bugfix/xlr-value-refs-skips-type
Browse files Browse the repository at this point in the history
Run `applyValueRefs` for Views and Transform `type` Properties
  • Loading branch information
KetanReddy authored Jan 16, 2025
2 parents e89ad9c + b63cd1c commit 9e2b8ef
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,24 @@ exports[`Transform Tests > applyValueRefs Transform 1`] = `
},
"type": {
"node": {
"const": "mock",
"description": "The asset type determines the semantics of how a user interacts with a page",
"title": "Asset.type",
"type": "string",
"or": [
{
"const": "mock",
"description": "The asset type determines the semantics of how a user interacts with a page",
"title": "Asset.type",
"type": "string",
},
{
"ref": "ExpressionRef",
"type": "ref",
},
{
"ref": "BindingRef",
"type": "ref",
},
],
"type": "or",
},
"required": true,
},
Expand Down
76 changes: 40 additions & 36 deletions language/json-language-service/src/xlr/transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,45 +78,49 @@ export const applyAssetWrapperOrSwitch: TransformFunction = (
* Modifies any primitive type property node (except id/type) to be Bindings or Expressions
*/
export const applyValueRefs: TransformFunction = (node, capability) => {
return simpleTransformGenerator("object", "Assets", (inputNode) => {
const xlrNode = { ...inputNode };
for (const key in xlrNode.properties) {
if (key === "id" || key === "type") {
continue;
}
return simpleTransformGenerator(
"object",
["Assets", "Views"],
(inputNode) => {
const xlrNode = { ...inputNode };
for (const key in xlrNode.properties) {
if (key === "id") {
continue;
}

const value = xlrNode.properties[key];
if (value.node.type === "or") {
value.node.or.push({
type: "ref",
ref: "ExpressionRef",
});
value.node.or.push({
type: "ref",
ref: "BindingRef",
});
} else if (isPrimitiveTypeNode(value.node)) {
const newUnionType: OrType = {
type: "or",
description: value.node.description,
or: [
value.node,
{
type: "ref",
ref: "ExpressionRef",
},
{
type: "ref",
ref: "BindingRef",
},
],
};
value.node = newUnionType;
const value = xlrNode.properties[key];
if (value.node.type === "or") {
value.node.or.push({
type: "ref",
ref: "ExpressionRef",
});
value.node.or.push({
type: "ref",
ref: "BindingRef",
});
} else if (isPrimitiveTypeNode(value.node)) {
const newUnionType: OrType = {
type: "or",
description: value.node.description,
or: [
value.node,
{
type: "ref",
ref: "ExpressionRef",
},
{
type: "ref",
ref: "BindingRef",
},
],
};
value.node = newUnionType;
}
}
}

return xlrNode;
})(node, capability);
return xlrNode;
}
)(node, capability);
};

/**
Expand Down

0 comments on commit 9e2b8ef

Please sign in to comment.