Skip to content

Why alias resolution context is not propagated to merge key resolution? #650

@devingfx

Description

@devingfx

Hi!

( Your YAML lib is awesome and the only one to provide AST out there! So first: Thank you ! )

I am cooking a plugin to the library to be able to add a custom alias resolution function in case the alias is missing its corresponding anchored node.
It work well in general, but it relies on puting the missing nodes (usually generated) in ctx.anchors for later resolution to use cached values...

I wonder why the merge key part do not use/propagate the ctx while resolving alias for merge keys?

Here:

value = ctx && isAlias(value) ? value.resolve(ctx.doc) : value

and here:

const source = ctx && isAlias(value) ? value.resolve(ctx.doc) : value

Those should be

value.resolve(ctx.doc, ctx)

, doesn't they?

Is there a particular reason (I'm missing) why those resolution does not use the context ?

Thx

PS: My plugin would mainly be used to parse file path from missing alias and load the file for it to be included inplace (maybe targeting data with JSONPath). While I could not use ctx.anchor, the cached strategy would be more efficient in case big files are loaded and used several times...

Example: this loads & parse 2 times the same common.yaml file

config:
  <<: *./configs/common.yaml
  foo: bar override
database:
  <<: *./configs/common.yaml

While this example does not (because of ctx)

config: *./configs/common.yaml
database: *./configs/common.yaml

but lacks of a way to override/add pairs to the map...

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions