Parseur JavaScript

Analyse l'entrée avec “Parseur JavaScript” et présente un résultat structuré pour inspection.

Entrée: TexteRésultat: Texte

Saisie de texte

Exécuter pour voir le résultat

Exemples

Keep a zero-prefixed invoice ID as a string

Entrée

const invoice = "00123";

Expected answer

JSON
{
  "type": "Program",
  "body": [
    {
      "type": "VariableDeclaration",
      "declarations": [
        {
          "type": "VariableDeclarator",
          "id": {
            "type": "Identifier",
            "name": "invoice"
          },
          "init": {
            "type": "Literal",
            "value": "00123",
            "raw": "\"00123\""
          }
        }
      ],
      "kind": "const"
    }
  ],
  "sourceType": "script"
}
Informations de localisation
Off
Informations sur la plage
Off
Inclure le tableau de jetons
Off
Inclure le tableau de commentaires
Off
Signaler les erreurs et essayer de continuer
Off
Find the callback inside a price total

Entrée

const total = prices.reduce((sum, price) => sum + price, 0);

Expected answer

JSON
{
  "type": "Program",
  "body": [
    {
      "type": "VariableDeclaration",
      "declarations": [
        {
          "type": "VariableDeclarator",
          "id": {
            "type": "Identifier",
            "name": "total"
          },
          "init": {
            "type": "CallExpression",
            "callee": {
              "type": "MemberExpression",
              "computed": false,
              "object": {
                "type": "Identifier",
                "name": "prices"
              },
              "property": {
                "type": "Identifier",
                "name": "reduce"
              }
            },
            "arguments": [
              {
                "type": "ArrowFunctionExpression",
                "id": null,
                "params": [
                  {
                    "type": "Identifier",
                    "name": "sum"
                  },
                  {
                    "type": "Identifier",
                    "name": "price"
                  }
                ],
                "body": {
                  "type": "BinaryExpression",
                  "operator": "+",
                  "left": {
                    "type": "Identifier",
                    "name": "sum"
                  },
                  "right": {
                    "type": "Identifier",
                    "name": "price"
                  }
                },
                "generator": false,
                "expression": true,
                "async": false
              },
              {
                "type": "Literal",
                "value": 0,
                "raw": "0"
              }
            ]
          }
        }
      ],
      "kind": "const"
    }
  ],
  "sourceType": "script"
}
Informations de localisation
Off
Informations sur la plage
Off
Inclure le tableau de jetons
Off
Inclure le tableau de commentaires
Off
Signaler les erreurs et essayer de continuer
Off
Locate a price after a source comment

Entrée

// USD prices
const price = 19.95;

Expected answer

JSON
{
  "type": "Program",
  "body": [
    {
      "type": "VariableDeclaration",
      "declarations": [
        {
          "type": "VariableDeclarator",
          "id": {
            "type": "Identifier",
            "name": "price",
            "range": [
              20,
              25
            ],
            "loc": {
              "start": {
                "line": 2,
                "column": 6
              },
              "end": {
                "line": 2,
                "column": 11
              }
            }
          },
          "init": {
            "type": "Literal",
            "value": 19.95,
            "raw": "19.95",
            "range": [
              28,
              33
            ],
            "loc": {
              "start": {
                "line": 2,
                "column": 14
              },
              "end": {
                "line": 2,
                "column": 19
              }
            }
          },
          "range": [
            20,
            33
          ],
          "loc": {
            "start": {
              "line": 2,
              "column": 6
            },
            "end": {
              "line": 2,
              "column": 19
            }
          }
        }
      ],
      "kind": "const",
      "range": [
        14,
        34
      ],
      "loc": {
        "start": {
          "line": 2,
          "column": 0
        },
        "end": {
          "line": 2,
          "column": 20
        }
      }
    }
  ],
  "sourceType": "script",
  "range": [
    14,
    34
  ],
  "loc": {
    "start": {
      "line": 2,
      "column": 0
    },
    "end": {
      "line": 2,
      "column": 20
    }
  },
  "comments": [
    {
      "type": "Line",
      "value": " USD prices",
      "range": [
        0,
        13
      ],
      "loc": {
        "start": {
          "line": 1,
          "column": 0
        },
        "end": {
          "line": 1,
          "column": 13
        }
      }
    }
  ],
  "tokens": [
    {
      "type": "Keyword",
      "value": "const",
      "range": [
        14,
        19
      ],
      "loc": {
        "start": {
          "line": 2,
          "column": 0
        },
        "end": {
          "line": 2,
          "column": 5
        }
      }
    },
    {
      "type": "Identifier",
      "value": "price",
      "range": [
        20,
        25
      ],
      "loc": {
        "start": {
          "line": 2,
          "column": 6
        },
        "end": {
          "line": 2,
          "column": 11
        }
      }
    },
    {
      "type": "Punctuator",
      "value": "=",
      "range": [
        26,
        27
      ],
      "loc": {
        "start": {
          "line": 2,
          "column": 12
        },
        "end": {
          "line": 2,
          "column": 13
        }
      }
    },
    {
      "type": "Numeric",
      "value": "19.95",
      "range": [
        28,
        33
      ],
      "loc": {
        "start": {
          "line": 2,
          "column": 14
        },
        "end": {
          "line": 2,
          "column": 19
        }
      }
    },
    {
      "type": "Punctuator",
      "value": ";",
      "range": [
        33,
        34
      ],
      "loc": {
        "start": {
          "line": 2,
          "column": 19
        },
        "end": {
          "line": 2,
          "column": 20
        }
      }
    }
  ]
}
Informations de localisation
On
Informations sur la plage
On
Inclure le tableau de jetons
On
Inclure le tableau de commentaires
On
Signaler les erreurs et essayer de continuer
Off
Inspect both branches without running either

Entrée

if (isReady) { start(); } else { retry(); }

Expected answer

JSON
{
  "type": "Program",
  "body": [
    {
      "type": "IfStatement",
      "test": {
        "type": "Identifier",
        "name": "isReady"
      },
      "consequent": {
        "type": "BlockStatement",
        "body": [
          {
            "type": "ExpressionStatement",
            "expression": {
              "type": "CallExpression",
              "callee": {
                "type": "Identifier",
                "name": "start"
              },
              "arguments": []
            }
          }
        ]
      },
      "alternate": {
        "type": "BlockStatement",
        "body": [
          {
            "type": "ExpressionStatement",
            "expression": {
              "type": "CallExpression",
              "callee": {
                "type": "Identifier",
                "name": "retry"
              },
              "arguments": []
            }
          }
        ]
      }
    }
  ],
  "sourceType": "script"
}
Informations de localisation
Off
Informations sur la plage
Off
Inclure le tableau de jetons
Off
Inclure le tableau de commentaires
Off
Signaler les erreurs et essayer de continuer
Off
Reject a missing value instead of inventing a tree

Entrée

const broken = ;

Expected rejection

Message contains
Unexpected token ;
Informations de localisation
Off
Informations sur la plage
Off
Inclure le tableau de jetons
Off
Inclure le tableau de commentaires
Off
Signaler les erreurs et essayer de continuer
Off

Outils associés

Nettoyage du code

Référence de l’opération

Voir la documentation technique originale (English)