Skip to content

Freeze in the JavaScript grammar #567

@aeschli

Description

@aeschli

Looks like the JS grammar goes into a endless loop with

function t(){
return e.call(this,[t._randomHex(),t._randomHex(),t._randomHex(),t._randomHex(),t._randomHex(),t._randomHex(),t._randomHex(),t._randomHex(),"-",t._randomHex(),t._randomHex(),t._randomHex(),t._randomHex(),"-","4",t._randomHex(),t._randomHex(),t._randomHex(),"-",t._oneOf(t._timeHighBits),t._randomHex(),t._randomHex(),t._randomHex(),"-",t._randomHex(),t._randomHex(),t._randomHex(),t._randomHex(),t._randomHex(),t._randomHex(),t._randomHex(),t._randomHex(),t._randomHex(),t._randomHex(),t._randomHex(),t._randomHex()].join(""))||this}

The last evaluate regex before freezing is:

Running (?x) (?:
  (?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(\basync)
)? ((?<![})!\]])\s*
  (?=
    # sure shot arrow functions even if => is on new line
(
  [(]\s*
  (
    ([)]\s*:) |                                                                 # ():
    ((\.\.\.\s*)?[_$[:alpha:]][_$[:alnum:]]*\s*:)                                            # [(]param: | [(]...param:
  )
) |
(
  [<]\s*[_$[:alpha:]][_$[:alnum:]]*\s+extends\s*[^=>]                                        # < typeparam extends
) |
# arrow function possible to detect only with => on same line
(
  (<\s*([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{[^\{\}]*\})|(\([^\(\)]*\))|(\[[^\[\]]*\]))([^=<>]|=[^<])*\>)*>\s*)?                                                           # typeparameters
  \(\s*([_$[:alpha:]\{\[]([^()]|\((\s*[^()]*)?\))*)?\)                          # parameteres
  (\s*:\s*([^<>\(\)]|\<[^<>]+\>|\([^\(\)]+\))+)?                                # return type
  \s*=>                                                                         # arrow operator
)
  )
)

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