Skip to content

import YAML file, RollupError: 'Legacy octal escape is not permitted in strict mode' #1992

@256x256

Description

@256x256

Expected Behavior

No errors occur.

Actual Behavior

[!] RollupError: src/data.yaml (1:13): Legacy octal escape is not permitted in strict mode (Note that you need plugins to import files that are not JavaScript)
src/data.yaml (1:13)
1: var data = { 01:"any value" };
                ^
2: 
3: export default data;

Additional Information

I enclose key in quotes to indicate string.

On JS-YAML online demo, converted correctly.

input

# Enclose key in quotes to indicate string

'01': any value

output

{ '01': 'any value' }

Is this problem with tosource, not @rollup/plugin-yaml?

Is this problem in this code?

/tosource/src/tosource.ts

function legalKey(key: string) {
  return (
-    /^([a-z_$][0-9a-z_$]*|[0-9]+)$/gi.test(key) && !KEYWORD_REGEXP.test(key)
+    /^([a-z_$][0-9a-z_$]*|0|[1-9][0-9]*)$/gi.test(key) && !KEYWORD_REGEXP.test(key) // Like this?
  );
}

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