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鈥檒l 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: JS_MODULE@0..25
  0: (empty)
  1: (empty)
  2: JS_DIRECTIVE_LIST@0..0
  3: JS_MODULE_ITEM_LIST@0..23
    0: JS_VARIABLE_STATEMENT@0..21
      0: JS_VARIABLE_DECLARATION@0..21
        0: (empty)
        1: CONST_KW@0..6 "const" [] [Whitespace(" ")]
        2: JS_VARIABLE_DECLARATOR_LIST@6..21
          0: JS_VARIABLE_DECLARATOR@6..21
            0: JS_IDENTIFIER_BINDING@6..8
              0: IDENT@6..8 "a" [] [Whitespace(" ")]
            1: (empty)
            2: JS_INITIALIZER_CLAUSE@8..21
              0: EQ@8..10 "=" [] [Whitespace(" ")]
              1: JS_ASSIGNMENT_EXPRESSION@10..21
                0: JS_BOGUS_ASSIGNMENT@10..18
                  0: JS_NUMBER_LITERAL_EXPRESSION@10..12
                    0: JS_NUMBER_LITERAL@10..12 "0" [] [Whitespace(" ")]
                  1: TS_TYPE_ARGUMENTS@12..18
                    0: L_ANGLE@12..14 "<" [] [Whitespace(" ")]
                    1: TS_TYPE_ARGUMENT_LIST@14..17
                      0: TS_PARENTHESIZED_TYPE@14..17
                        0: L_PAREN@14..15 "(" [] []
                        1: TS_NUMBER_LITERAL_TYPE@15..17
                          0: (empty)
                          1: JS_NUMBER_LITERAL@15..17 "0" [] [Whitespace(" ")]
                        2: (empty)
                    2: R_ANGLE@17..18 ">" [] []
                1: EQ@18..20 "=" [] [Whitespace(" ")]
                2: JS_NUMBER_LITERAL_EXPRESSION@20..21
                  0: JS_NUMBER_LITERAL@20..21 "1" [] []
      1: (empty)
    1: JS_BOGUS_STATEMENT@21..22
      0: R_PAREN@21..22 ")" [] []
    2: JS_EMPTY_STATEMENT@22..23
      0: SEMICOLON@22..23 ";" [] []
  4: EOF@23..25 "" [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