Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

87
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda