Skip to content

loader.js stores string in anchorMap instead of constructed object for special types #141

@vytronics

Description

@vytronics

Consider the following YAML file:

{
     funcype: &TEST !!js/function "function (){ }",

     my_other_func: *TEST
}

This gets loaded as:
{ funcype: [Function], my_other_func: 'function (){ }' }

Instead of the expected object
{ funcype: [Function], my_other_func: [Function] }

My initial guess at why, given a very cursory review of the code, is because loader.js saves the anchor node as the state.result text instead of the constructed object.

For example, consider this snipppet at line 1339 in composeNode

        if (null !== state.anchor) {
          state.anchorMap[state.anchor] = state.result;
        }

The above line is prior to the code that constructs the actual anchored node:

        if (type.resolve(state.result)) { // `state.result` updated in resolver if matched
          state.result = type.construct(state.result);
          state.tag = type.tag;
          break;
        }

To address this would require constructing the custom type first before inserting into anchorMap. Due to the recursive nature of the parser and that this would need to be addresses in several areas of the code this is something I do not feel very comfortable coding as a pull request. Best reviewed and resolved by the maintainers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions