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

YAML Inline Extend syntax cannot be parsed #8876

Closed
Vampire opened this issue Jul 31, 2020 · 2 comments · Fixed by #8888
Closed

YAML Inline Extend syntax cannot be parsed #8876

Vampire opened this issue Jul 31, 2020 · 2 comments · Fixed by #8888
Labels
lang:yaml Issues affecting YAML locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:enhancement A potential new feature to be added, or an improvement to how we print something

Comments

@Vampire
Copy link

Vampire commented Jul 31, 2020

The blog post https://blog.daemonl.com/2016/02/yaml.html shows that there is an "inline extend" syntax where this YAML

foo:
 <<: &anchor
   K1: "One"
 K2: "Two"

bar:
 <<: *anchor
 K3: "Three"

defines this JSON

{
    "foo": {
        "K1": "One",
        "K2": "Two"
    }, 
    "bar": {
        "K1": "One",
        "K3": "Three"
    }
}

But If I give the mentioned YAML to prettier, I am greeted with this error:

[error] test.yml: SyntaxError: Merge nodes can only have Alias nodes as values (2:2)
[error]   1 | foo:
[error] > 2 |  <<: &anchor
[error]     |  ^^^^^^^^^^^
[error] > 3 |    K1: "One"
[error]     | ^^^^^^^^^^^^
[error] > 4 |  K2: "Two"
[error]     | ^^^^^^^^^^^^
[error] > 5 | 
[error]     | ^
[error]   6 | bar:
[error]   7 |  <<: *anchor
[error]   8 |  K3: "Three"

Sending given YAML through js-yaml produces the exact expected result.
It would be nice if prettier would support this syntax too.

@alexander-akait
Copy link
Member

We should improve it on parser side firstly prettier/yaml-unist-parser#273

@alexander-akait alexander-akait added lang:yaml Issues affecting YAML scope:dependency Issues that cannot be solved inside Prettier itself, and must be fixed in a dependency type:enhancement A potential new feature to be added, or an improvement to how we print something and removed scope:dependency Issues that cannot be solved inside Prettier itself, and must be fixed in a dependency labels Jul 31, 2020
@alexander-akait
Copy link
Member

Can be implemented prettier/yaml-unist-parser#273, PR welcome

@github-actions github-actions bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Nov 2, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lang:yaml Issues affecting YAML locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:enhancement A potential new feature to be added, or an improvement to how we print something
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants