محلل JavaScript

يحلل الإدخال باستخدام “محلل JavaScript” ويعرض نتيجة مُنظمة للفحص.

المدخلات: نصالنتيجة: نص

إدخال نصي

شغّل الأداة لعرض النتيجة

أمثلة

Keep a zero-prefixed invoice ID as a string

المدخلات

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"
}
معلومات الموقع
Off
معلومات النطاق
Off
تضمين مصفوفة الرموز
Off
تضمين مصفوفة التعليقات
Off
الإبلاغ عن الأخطاء ومحاولة المتابعة
Off
Find the callback inside a price total

المدخلات

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"
}
معلومات الموقع
Off
معلومات النطاق
Off
تضمين مصفوفة الرموز
Off
تضمين مصفوفة التعليقات
Off
الإبلاغ عن الأخطاء ومحاولة المتابعة
Off
Locate a price after a source comment

المدخلات

// 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
        }
      }
    }
  ]
}
معلومات الموقع
On
معلومات النطاق
On
تضمين مصفوفة الرموز
On
تضمين مصفوفة التعليقات
On
الإبلاغ عن الأخطاء ومحاولة المتابعة
Off
Inspect both branches without running either

المدخلات

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"
}
معلومات الموقع
Off
معلومات النطاق
Off
تضمين مصفوفة الرموز
Off
تضمين مصفوفة التعليقات
Off
الإبلاغ عن الأخطاء ومحاولة المتابعة
Off
Reject a missing value instead of inventing a tree

المدخلات

const broken = ;

Expected rejection

Message contains
Unexpected token ;
معلومات الموقع
Off
معلومات النطاق
Off
تضمين مصفوفة الرموز
Off
تضمين مصفوفة التعليقات
Off
الإبلاغ عن الأخطاء ومحاولة المتابعة
Off

أدوات ذات صلة

تنسيق الشفرة

مرجع العملية

عرض الوثائق التقنية الأصلية (English)