Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

89
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda