Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Parser error with greater/less operators #1184

Closed
1 task done
blutorange opened this issue Dec 14, 2023 · 0 comments · Fixed by #1645
Closed
1 task done

🐛 Parser error with greater/less operators #1184

blutorange opened this issue Dec 14, 2023 · 0 comments · Fixed by #1645
Labels
A-Parser Area: parser L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug S-Help-wanted Status: you're familiar with the code base and want to help the project

Comments

@blutorange
Copy link

blutorange commented Dec 14, 2023

Environment information

CLI:
  Version:                      1.4.1
  Color support:                true

Platform:
  CPU Architecture:             x86_64
  OS:                           linux

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           unset
  JS_RUNTIME_NAME:              unset
  NODE_PACKAGE_MANAGER:         unset

Biome Configuration:
  Status:                       Loaded successfully
  Formatter disabled:           false
  Linter disabled:              false
  Organize imports disabled:    true
  VCS disabled:                 true

Workspace:
  Open Documents:               0

What happened?

While I was migrating our code base to biome, I came across a file where biome reported syntax errors. After taking a look, I found what is probably a bug in the parser (It was some legacy code that I fixed by now, which also got rid of the parser error.)

A simplified version of the code the shows the parser bug is:

function getDataSourcesForParameterCount(ranges) {
  return 0 < $.grep(ranges, (range) => {return 0 >= 1;}).length;
}

This should be legal TypeScript code, but biome gives several parser errors.

When you replace 0 >= 1 with e.g. 1, the parser errors disappear. It also disappears when you remove the 0 < at the beginning or move it to the end (> 0); or when you change < to >.

You can see this in the playground with the latest version. It only happens when TypeScript is enabled, with our without JSX enabled. It might be related to type arguments in functions (e.g. microsoft/TypeScript#36662)

https://biomejs.dev/playground/?unsafeParameterDecoratorsEnabled=false&allowComments=false&code=CgBmAHUAbgBjAHQAaQBvAG4AIABnAGUAdABEAGEAdABhAFMAbwB1AHIAYwBlAHMARgBvAHIAUABhAHIAYQBtAGUAdABlAHIAQwBvAHUAbgB0ACgAcgBhAG4AZwBlAHMAKQAgAHsACgAgACAAcgBlAHQAdQByAG4AIAAwACAAPAAgACQALgBnAHIAZQBwACgAcgBhAG4AZwBlAHMALAAgACgAcgBhAG4AZwBlACkAIAA9AD4AIAB7AHIAZQB0AHUAcgBuACAAMAAgAD4APQAgADEAOwB9ACkALgBsAGUAbgBnAHQAaAA7AAoAfQAKAA%3D%3D&jsx=false

image

An even simpler example:

const a = 0 < (0 >= 1);

The parser seems interpret as a literal 0, followed by a type argument < (0 >:

0: [email protected]
  0: (empty)
  1: (empty)
  2: [email protected]
  3: [email protected]
    0: [email protected]
      0: [email protected]
        0: (empty)
        1: [email protected] "const" [] [Whitespace(" ")]
        2: [email protected]
          0: [email protected]
            0: [email protected]
              0: [email protected] "a" [] [Whitespace(" ")]
            1: (empty)
            2: [email protected]
              0: [email protected] "=" [] [Whitespace(" ")]
              1: [email protected]
                0: [email protected]
                  0: [email protected]
                    0: [email protected] "0" [] [Whitespace(" ")]
                  1: [email protected]
                    0: [email protected] "<" [] [Whitespace(" ")]
                    1: [email protected]
                      0: [email protected]
                        0: [email protected] "(" [] []
                        1: [email protected]
                          0: (empty)
                          1: [email protected] "0" [] [Whitespace(" ")]
                        2: (empty)
                    2: [email protected] ">" [] []
                1: [email protected] "=" [] [Whitespace(" ")]
                2: [email protected]
                  0: [email protected] "1" [] []
      1: (empty)
    1: [email protected]
      0: [email protected] ")" [] []
    2: [email protected]
      0: [email protected] ";" [] []
  4: [email protected] "" [Newline("\n"), Newline("\n")] []

Expected result

It should parse the code successfully.

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@ematipico ematipico added S-Help-wanted Status: you're familiar with the code base and want to help the project A-Parser Area: parser L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug labels Dec 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Parser Area: parser L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug S-Help-wanted Status: you're familiar with the code base and want to help the project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants