-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
Handle svelte syntax #204
Merged
Merged
Handle svelte syntax #204
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
685da96
Add test for svelte
Shinigami92 de5b6da
Merge branch 'main' into issue-201
Shinigami92 c34ac24
Handle curly brackets in text for svelte
Shinigami92 f67d9bf
Handle svelte interpolation in tag attributes
Shinigami92 f4da05a
Remove space from test-case for now
Shinigami92 b98ecea
Use bracketSpacing for interpolated-code tokens
Shinigami92 2379491
Merge branch 'main' into issue-201
Shinigami92 2074e55
Extract a detectDangerousQuoteCombination for readability
Shinigami92 1a1e091
Merge functions into a combined formatFrameworkInterpolation
Shinigami92 df2a297
Simplify is_Interpolation functions
Shinigami92 daedd2a
Apply suggestion
Shinigami92 55b0485
Add JSDoc
Shinigami92 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { isQuoted, isWrappedWith } from './common'; | ||
|
||
/** | ||
* Indicates whether the attribute value is a Svelte interpolation. | ||
* | ||
* --- | ||
* | ||
* Example interpolation: | ||
* ``` | ||
* a(href="{ cat.id }") | ||
* ``` | ||
* | ||
* In this case `val` is `"{ cat.id }"`. | ||
* | ||
* --- | ||
* | ||
* @param val Value of tag attribute. | ||
* @returns `true` if `val` passes the svelte interpolation check, otherwise `false`. | ||
*/ | ||
export function isSvelteInterpolation(val: string): boolean { | ||
Shinigami92 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return val.length >= 3 && isQuoted(val) && isWrappedWith(val, '{', '}', 1) && !val.includes('{', 2); | ||
Shinigami92 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
main | ||
h1 Hello { name }! | ||
p | ||
| Visit the | ||
a(href="https://svelte.dev/tutorial") | ||
| Svelte tutorial | ||
| to learn how to build Svelte | ||
| apps. | ||
p | ||
+each('cats as cat') | ||
a(href="{ cat.id }") { cat.name } | ||
| !{ ' ' } | ||
|
||
p | ||
+if('!user.loggedIn') | ||
button(on:click="{ toggle }") | ||
| Log out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { readFileSync } from 'fs'; | ||
import { resolve } from 'path'; | ||
import { format } from 'prettier'; | ||
import { plugin } from './../../../src/index'; | ||
|
||
describe('Frameworks', () => { | ||
describe('Svelte', () => { | ||
test('should format svelte', () => { | ||
const expected: string = readFileSync(resolve(__dirname, 'formatted.pug'), 'utf8'); | ||
const code: string = readFileSync(resolve(__dirname, 'unformatted.pug'), 'utf8'); | ||
const actual: string = format(code, { | ||
parser: 'pug', | ||
plugins: [plugin], | ||
|
||
// @ts-expect-error | ||
pugFramework: 'svelte' | ||
}); | ||
|
||
expect(actual).toBe(expected); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
main | ||
h1 Hello { name}! | ||
p | ||
| Visit the | ||
a(href='https://svelte.dev/tutorial') | ||
| Svelte tutorial | ||
| to learn how to build Svelte | ||
| apps. | ||
p | ||
+each('cats as cat') | ||
a(href='{ cat.id }') { cat.name } | ||
| !{ ' ' } | ||
|
||
p | ||
+if('!user.loggedIn') | ||
button(on:click='{ toggle}') | ||
| Log out |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor this entire method into smaller parts (that can be reused and are easier to grasp)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, this code hurts, but I personally decided for now to await feedback from svelte community if there are further errors and printed warnings in their console output
Based on this feedback I can refactor this messy code
But now it's working and the svelte community can start working our formatter