DEV: Allow `transformed` values to be used in all widget hbs statements (#13331)
Previously, the `transformed.blah` shortcut could only be used in top-level hbs statements like {{transformed.blah}}. When attempting to use it in a sub-expression like `{{concat "hello" transformed.world}}`, it would raise a "transformed is not defined" error. This commit updates the shortcut logic to make `transformed.blah` and `attrs.blah` work consistently in all hbs expressions. Co-authored-by: Jordan Vidrine <jordan@jordanvidrine.com>
This commit is contained in:
parent
41038d6cdb
commit
9811a1c5d9
|
@ -262,6 +262,30 @@ discourseModule("Integration | Component | Widget | base", function (hooks) {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
componentTest("using transformed values in a subexpression", {
|
||||||
|
template: hbs`{{mount-widget widget="attach-test"}}`,
|
||||||
|
|
||||||
|
beforeEach() {
|
||||||
|
createWidget("testing", {
|
||||||
|
tagName: "span.value",
|
||||||
|
template: widgetHbs`{{attrs.value}}`,
|
||||||
|
});
|
||||||
|
|
||||||
|
createWidget("attach-test", {
|
||||||
|
transform() {
|
||||||
|
return { someValue: "world" };
|
||||||
|
},
|
||||||
|
tagName: "div.container",
|
||||||
|
template: widgetHbs`{{testing value=(concat "hello" " " transformed.someValue)}}`,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
test(assert) {
|
||||||
|
assert.ok(queryAll(".container").length, "renders container");
|
||||||
|
assert.equal(queryAll(".container .value").text(), "hello world");
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
componentTest("handlebars d-icon", {
|
componentTest("handlebars d-icon", {
|
||||||
template: hbs`{{mount-widget widget="hbs-icon-test" args=args}}`,
|
template: hbs`{{mount-widget widget="hbs-icon-test" args=args}}`,
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ function sexpValue(value) {
|
||||||
} else if (value.type === "SubExpression") {
|
} else if (value.type === "SubExpression") {
|
||||||
return sexp(value);
|
return sexp(value);
|
||||||
}
|
}
|
||||||
return pValue;
|
return resolve(pValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
function pairsToObj(pairs) {
|
function pairsToObj(pairs) {
|
||||||
|
|
Loading…
Reference in New Issue