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

Use a proper tag for !!merge << keys #580

Merged
merged 1 commit into from
Oct 5, 2024
Merged

Use a proper tag for !!merge << keys #580

merged 1 commit into from
Oct 5, 2024

Conversation

eemeli
Copy link
Owner

@eemeli eemeli commented Oct 5, 2024

Fixes #579

Let's handle !!merge << like other explicit YAML 1.1 tags, so that it works even if not separately enabled, and fix the options so that merge: true is a shorthand for customTags: ['merge'] (and combines with that option nicely, if they're both used).

This turned out to be a bit tricky to do "right", while also not introducing any breaking changes. In YAML 1.1, << is special, but only if it's used as a bare mapping key, and so I added an atKey flag into the ComposeContext and a default: 'key' value for tags, so that composition can take the node position into account.

The difficulty here is slightly compounded by a mistake we made early on (#22, CC @ikatyang) in mis-reading the !!merge spec and allowing multiple << keys to be present in a single mapping, which is not valid YAML -- but removing this support now would count as a breaking change, and that would be unfortunate.

While at this, I took the opportunity to add an optional addToJSMap(ctx, map, value) method that !!merge can use to customize how it's added to a JS map, so that its handling is now much less custom.

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.

Support tag:yaml.org,2002:merge for parsing !!merge <<: &foo
1 participant