Giter VIP home page Giter VIP logo

Comments (7)

mck89 avatar mck89 commented on August 24, 2024 3

I've just released the new version 1.16 containing the fix for this bug. Thank you for reporting!

from peast.

mck89 avatar mck89 commented on August 24, 2024 1

@Krinkle that's amazing, thank you for letting me know!

from peast.

lucaswerkmeister avatar lucaswerkmeister commented on August 24, 2024

I wasn’t able to find a trustworthy-looking “canonical” validator for earlier ES versions

Here’s acorn, for what it’s worth, reporting this as parseable in ES3 and ES5:

> acorn.version
'8.11.3'
> acorn.parse('(a=1,2)', { ecmaVersion: 3 })
Node {
  type: 'Program',
  start: 0,
  end: 7,
  body: [
    Node {
      type: 'ExpressionStatement',
      start: 0,
      end: 7,
      expression: [Node]
    }
  ],
  sourceType: 'script'
}
> acorn.parse('(a=1,2)', { ecmaVersion: 5 })
Node {
  type: 'Program',
  start: 0,
  end: 7,
  body: [
    Node {
      type: 'ExpressionStatement',
      start: 0,
      end: 7,
      expression: [Node]
    }
  ],
  sourceType: 'script'
}

from peast.

lucaswerkmeister avatar lucaswerkmeister commented on August 24, 2024

The difference is apparently caused by the trailingCommaFunctionCallDeclaration syntax feature, specifically its check in parseFormalParameterList() (as opposed to the one in parseArgumentList(), which doesn’t affect this issue AFAICT). If I add &&false to that condition in parseFormalParameterList(), Peast can parse the code again. So I’m guessing Peast is trying to parse (a=1,2) as the beginning of an arrow function (like (a=1,b=2)=>a+b) and complaining that 2 is not a parameter name, and then… somehow not backtracking properly, whereas in ES8+ it does backtrack? (But I’m way out of my depth here, I don’t know how Peast’s parser works.)

from peast.

mck89 avatar mck89 commented on August 24, 2024

Your analysis is correct, when the parser reads the 2 it stops parsing the parseFormalParameterList because it's not valid for that context, for this reason it detects the comma before 2 as a trailing comma so it throws an exception if the trailingCommaFunctionCallDeclaration feature is not active.

I will look into this, it seems that it is caused by the wrong detection of what is a trailing comma in a parameters list.

from peast.

lucaswerkmeister avatar lucaswerkmeister commented on August 24, 2024

Amazing, thank you!

from peast.

Krinkle avatar Krinkle commented on August 24, 2024

@mck89 In case you'd like to keep track, your library is now used in the MediaWiki software that powers Wikipedia!

I selected your library as part of T75714, for our ResourceLoader component, where we validate user-submitted JavaScript code (what?).

I found your library the most well-maintained and up-to-date implementation I could find, valuing in particular:

  • easy to use (one function as entry point),
  • dependency-free (thus easy to audit and review for our checked-into-git vendor, read more),
  • under an OSI-approved and GPL-compatible free software license,
  • fast enough to validate new submissions in real-time during a web response.

You're listed and credited at https://en.wikipedia.org/wiki/Special:Version. The code using it is also mirrored at https://github.com/wikimedia/mediawiki.

from peast.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.