Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

86
Views
Detect missing semicolons parsing JavaScript with Esprima

I'm doing static analysis of JavaScript code using the esprima and estraverse modules. As JavaScript doesn't enforce the use of semicolons, then no error is thrown when analyzing code with no semicolons, but I would like it to.

The only solution I've come up with is to look for expressions that could require a semicolon and check if there's any, but the esprima.parse function doesn't remember the presence of any semicolon. They appear to be ignored after tokenization.

> esprima.tokenize("a = 3;")
[
  { type: 'Identifier', value: 'a' },
  { type: 'Punctuator', value: '=' },
  { type: 'Numeric', value: '3' },
  { type: 'Punctuator', value: ';' } // <-- Present after tokenization
]
> console.log(JSON.stringify(esprima.parse("a = 3;"), null, 2))
{
  "type": "Program",
  "body": [
    {
      "type": "ExpressionStatement",
      "expression": {
        "type": "AssignmentExpression",
        "operator": "=",
        "left": {
          "type": "Identifier",
          "name": "a"
        },
        "right": {
          "type": "Literal",
          "value": 3,
          "raw": "3"
        }
      }
    }
  ],
  "sourceType": "script"
}
// Not present anywhere

So, in short: Is there a way to detect missing semicolons while making an static analysis of javascript code with esprima?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!