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

Make anchor & alias resolution lazier #248

Merged
merged 8 commits into from Mar 27, 2021
Merged

Make anchor & alias resolution lazier #248

merged 8 commits into from Mar 27, 2021

Conversation

eemeli
Copy link
Owner

@eemeli eemeli commented Mar 27, 2021

Previously, the source of an alias node was a JS reference to the actual node object that it referred to, and doc.anchors provided separately from that the string identifiers used by YAML anchors.

After this change, scalar and collection nodes get a new anchor?: string property, and the source of an alias is a string identifier. The doc.anchors instance is completely dropped. The createAlias() method is moved to the document instance, and its handling of corner cases is changed a bit.

As a consequence of these changes, assigning the same anchor to multiple nodes will no longer automatically rename an earlier anchor with the same name.

Node creation options are somewhat clarified and streamlined, and the replacer is moved from the options object to be an optional second argument of the createNode() method, matching the new Document() interface.

BREAKING CHANGE: With the earlier drop of Merge as a separate class,
createMergePair() became just a convenience wrapper with confusing
behaviour. For the sake of simplicity, it's easier to drop it completely
and replace calling code with:

```diff
-doc.anchors.createMergePair(node)
+doc.createPair('<<', doc.anchors.createAlias(node))
```
BREAKING CHANGE: All of the node-creating methods are now collected on
the Document, making the API easier to use and understand.

```diff
-doc.anchors.createAlias(node)
+doc.createAlias(node)
```
BREAKING CHANGE:
- The `source` of an alias is changed from a direct reference to
  the aliased node to its `anchor` string representation instead.
- The `anchors` member of the Document class is dropped.
- Anchors are now stored in the `anchor` property of Scalar and
  Collection nodes.
- Assigning the same anchor to multiple nodes will no longer
  automatically rename an earlier anchor with the same name.
BREAKING CHANGE: Previously, `replacer` was passed as an option to
createNode(). Now it's an optional second argument, matching the API
used by the Document constructor.
BREAKING CHANGE: The behaviour of doc.createAlias() changes a bit; now
it checks that any anchor name that it assigns to the target node is
unique in the document.
@eemeli eemeli merged commit 96b5f95 into master Mar 27, 2021
@eemeli eemeli deleted the lazy-anchors branch March 27, 2021 19:19
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.

None yet

1 participant