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

Add curly braces when attribute shorthand is used but not allowed #119

Merged
merged 10 commits into from
Aug 30, 2020

Conversation

jesseskinner
Copy link
Contributor

Closes #110

I also added the ability for custom options in formatting tests, which was needed to reproduce this bug.

src/print/index.ts Outdated Show resolved Hide resolved
@jesseskinner jesseskinner requested a review from benmccann August 18, 2020 21:06
@benmccann
Copy link
Member

@jesseskinner just fyi - I don't know enough to review the PRs in this repo. I just noticed that one issue and thought I'd point it out

@jesseskinner
Copy link
Contributor Author

@benmccann No problem! Thanks for catching that.

Copy link
Contributor

@ehrencrona ehrencrona left a comment

Choose a reason for hiding this comment

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

I think I'd find it more readable if you instead had a completely separate branch for the attribute shorthand case, i.e.

if (isAttributeShorthand) {
    if (options.svelteAllowShorthand) {
        return concat([line, '{', node.name, '}']);
    }
    else {
        return concat([line, node.name, '="{', node.name, '}"']);
    }
} else { ... }

But your solution works fine too, so LGTM

src/print/index.ts Outdated Show resolved Hide resolved
Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

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

Thanks for this! Could you resolve the merge conflicts and apply the refactoring suggestion from @ehrencrona which makes it more readable? I'm happy to merge this in then.

@jesseskinner
Copy link
Contributor Author

jesseskinner commented Aug 30, 2020

@dummdidumm Done & done. The refactoring broke an old test, and that revealed that svelteStrictMode came into play here too, so I added the extra test case. With "svelteStrictMode": true, it will change <input {value} /> to <input value="{value}" /> whereas "svelteAllowShorthand": false would only necessitate changing it to <input value={value} /> (without the quotes).

Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

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

Thanks, all looking good! I refactored the other branch to make that one more readable, too, and added some more tests.

@dummdidumm dummdidumm merged commit 36ff82c into sveltejs:master Aug 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error when parsing dynamic attributes expressions
4 participants