Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add support for ember-component-attributes addon #218

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions transforms/angle-brackets/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,23 +205,32 @@ function transformLinkToAttrs(params) {
attributes = [firstParamOutput];
} else if (params.length === 2) {
// @route and @model param

// eslint-disable-next-line no-unused-vars
let [_, secondParamInput] = params;
if (secondParamInput.type === 'SubExpression') {
let htmlAttrs;
if (secondParamInput.path.original === 'html-attributes') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we should do this only for the second param. The addon works for any param AFAIK. Seems like it also only works for LinkTo here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I thought it would be a good idea if I included you in the discussion as I worked on it so I could get your feedback. I only had enough time yesterday to tackle a little bit of the problem. 😄

htmlAttrs = secondParamInput.hash.pairs;
}

let _queryParamOrModel;
if (isQueryParam(secondParamInput)) {
_queryParamOrModel = b.attr(
'@query',
b.mustache(b.path('hash'), [], secondParamInput.hash)
);
} else {
_queryParamOrModel = b.attr(
'@model',
b.mustache(secondParamInput.path, secondParamInput.params)
);
if (secondParamInput.path.original !== 'html-attributes') {
_queryParamOrModel = b.attr(
'@model',
b.mustache(secondParamInput.path, secondParamInput.params)
);
}
}
attributes = _queryParamOrModel ? [firstParamOutput, _queryParamOrModel] : [firstParamOutput];
if (htmlAttrs) {
attributes = [...attributes, ...htmlAttrs];
}
attributes = [firstParamOutput, _queryParamOrModel];
} else {
let _modelParam = b.attr('@model', transformModelParams(secondParamInput));
attributes = [firstParamOutput, _modelParam];
Expand Down
2 changes: 2 additions & 0 deletions transforms/angle-brackets/transform.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ test('link-to', () => {
{{#link-to "user" this.first this.second (query-params foo="baz")}}Show{{/link-to}}
{{#link-to "user" this.first}}Show{{/link-to}}
{{#link-to "user" this.first (query-params foo="baz")}}Show{{/link-to}}
{{#link-to "categories" (html-attributes id="main-bar" class="large" data-foo="123")}}{{svg-jar "crate"}}{{/link-to}}
`;

expect(runTest('link-to.hbs', input)).toMatchInlineSnapshot(`
Expand All @@ -393,6 +394,7 @@ test('link-to', () => {
<LinkTo @route=\\"user\\" @models={{array this.first this.second}} @query={{hash foo=\\"baz\\"}}>Show</LinkTo>
<LinkTo @route=\\"user\\" @model={{this.first}}>Show</LinkTo>
<LinkTo @route=\\"user\\" @model={{this.first}} @query={{hash foo=\\"baz\\"}}>Show</LinkTo>
<LinkTo @route=\\"categories\\" id=\\"main-bar\\" class=\\"large\\" data-foo=\\"123\\">{{svg-jar \\"crate\\"}}</LinkTo>
"
`);
});
Expand Down