Skip to content

loading yaml with numeric keys #30

Description

@sodiumjoe

Revisiting this issue, I don't think the raw config is quite the correct solution.

The original issue is that this plugin unquotes numeric keys:

❯ node
Welcome to Node.js v18.14.0.
Type ".help" for more information.
> yaml = require('@modyfi/vite-plugin-yaml')
{ default: [Function: src_default] }
> await yaml.default().transform(`
... '07': foo
... `, "foo.yaml")
{
  code: 'const data = { 07:"foo" };\nexport default data;',
  map: { mappings: '' }
}
>

Which, as the above issue notes, results in an error because of the leading 0.

The problem with raw mode is it fails on objects:

> await yaml.default({raw: true}).transform(`
... foo: bar
... `, "foo.yaml")
{
  code: 'const data = [object Object];\nexport default data;',
  map: { mappings: '' }
}

The above issue correctly identified tosource as the culprit here. Since js-yaml.load returns plain JSON, I'm not sure why tosource is necessary at all, as opposed to just JSON.stringify.

Happy to submit a PR if that sounds reasonable.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions