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

Open
#1,992 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
javascript, yaml
Domain
build-system

Research direction

Start with the StackBlitz reproduction and inspect /tosource/src/tosource.ts, especially legalKey, to determine how the quoted YAML key becomes the generated object key. Confirm the generated JavaScript is accepted by Rollup in strict mode and that the imported key remains "01" without the legacy-octal error.

Written by the indexing model from the issue text.

Description

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?
  );
}
Dominant language
JavaScript
Stars
3.8k
Forks
635
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rollup/plugins

All issues in rollup/plugins

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.