forked from trivago/prettier-plugin-twig-melody
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fix-mappings-expression' into master
Close GH-16. Fix handling mapping expression when the key parts is being omitted.
- Loading branch information
Showing
7 changed files
with
148 additions
and
9 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,9 @@ | |
|
||
## unreleased | ||
|
||
### Bugfixes | ||
- Fix handling mapping that omit key part | ||
|
||
--- | ||
## 0.8.0 (2024-08-09) | ||
|
||
|
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
70 changes: 70 additions & 0 deletions
70
tests/Expressions/__snapshots__/mappingExpression.snap.twig
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,70 @@ | ||
{# Example mappings literal expression taken from https://twig.symfony.com/doc/3.x/templates.html#literals #} | ||
{# keys as string #} | ||
{{ | ||
{ | ||
foo: 'foo', | ||
bar: 'bar' | ||
} | ||
}} | ||
|
||
{# keys as names (equivalent to the previous mapping) #} | ||
{{ | ||
{ | ||
foo: 'foo', | ||
bar: 'bar' | ||
} | ||
}} | ||
|
||
{# keys as integer #} | ||
{{ | ||
{ | ||
2: 'foo', | ||
4: 'bar' | ||
} | ||
}} | ||
|
||
{# keys can be omitted if it is the same as the variable name #} | ||
{% set nokey = { | ||
nokey | ||
} %} | ||
|
||
{% set nokey = { | ||
no, | ||
key | ||
} %} | ||
{# is equivalent to the following #} | ||
{% set no_key = { | ||
no: no, | ||
key: key | ||
} %} | ||
|
||
{% set foo = 'foo' %} | ||
|
||
{# keys as expressions (the expression must be enclosed into parentheses) #} | ||
{{ | ||
{ | ||
(foo): 'foo', | ||
(1 + 1): 'bar', | ||
(foo ~ 'b'): 'baz' | ||
} | ||
}} | ||
|
||
{% props theme = null, text = null %} | ||
|
||
<div {{ | ||
attributes.defaults({ | ||
class: cva({ | ||
base: 'alert shadow-md', | ||
variants: { | ||
theme: { | ||
info: 'alert-info', | ||
success: 'alert-success', | ||
warning: 'alert-warning', | ||
error: 'alert-error' | ||
} | ||
} | ||
}).apply({ | ||
theme | ||
}) | ||
}) | ||
}}></div> |
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,39 @@ | ||
{# Example mappings literal expression taken from https://twig.symfony.com/doc/3.x/templates.html#literals #} | ||
{# keys as string #} | ||
{{ { 'foo': 'foo', 'bar': 'bar' } }} | ||
|
||
{# keys as names (equivalent to the previous mapping) #} | ||
{{ { foo: 'foo', bar: 'bar' } }} | ||
|
||
{# keys as integer #} | ||
{{ { 2: 'foo', 4: 'bar' } }} | ||
|
||
{# keys can be omitted if it is the same as the variable name #} | ||
{% set nokey = { nokey } %} | ||
|
||
{% set nokey = { no, key } %} | ||
{# is equivalent to the following #} | ||
{% set no_key = { 'no': no, 'key': key } %} | ||
|
||
{% set foo = 'foo' %} | ||
|
||
{# keys as expressions (the expression must be enclosed into parentheses) #} | ||
{{ { (foo): 'foo', (1 + 1): 'bar', (foo ~ 'b'): 'baz' } }} | ||
|
||
{% props theme = null, text = null %} | ||
|
||
<div | ||
{{ attributes.defaults({ | ||
class: cva({ | ||
base: "alert shadow-md", | ||
variants: { | ||
theme: { | ||
info: "alert-info", | ||
success: "alert-success", | ||
warning: "alert-warning", | ||
error: "alert-error", | ||
}, | ||
}, | ||
}).apply({ theme }), | ||
}) }} | ||
></div> |