支持20種開發(fā)語言50種語法格式的在線代碼解析器 AST 插件示例集合【含源碼】

非常棒的在線AST瀏覽器
https://astexplorer.net/
源碼:https://github.com/fkling/astexplorer

一、支持開發(fā)語言

二、示例

1、vue

  • @vue/compiler-dom
  • vue-eslint-parser
  • vue-template-compiler
    源碼:
<template>
  <p>{{ greeting }} World!</p>
</template>

<script>
export default {
  data () {
    return {
      greeting: "Hello"
    };
  }
};
</script>

<style scoped>
p {
  font-size: 2em;
  text-align: center;
}
</style>

解析的語法樹json太長就不做展示了

image.png

2、JavaScript

  • babel-plugin-macros
  • babelv7
  • eslint-v4
  • jscodeshift
  • prettier
  • tslint

支持的語法格式

  • acorn
  • @babel/eslint-parser
  • babel-eslint9
  • @babel/parser
  • esformatter
  • espree
  • esprima
  • flow
  • meriyah
  • recast
  • seafox
  • shift
  • tenko
  • traceur
  • @typescript-eslint/parser
  • typescript
  • uglify-js
  • 例如:typescript源碼:
import logo from './logo.svg';
import './App.css';

function App() {
  return (
    <div className="App">
      <header className="App-header">
        <img src={logo} className="App-logo" alt="logo" />
        <p>
          Edit <code>src/App.js</code> and save to reload.
        </p>
        <a
          className="App-link"
          
          target="_blank"
          rel="noopener noreferrer"
        >
          Learn React
        </a>
      </header>
    </div>
  );
}

export default App;
  • 解析后的語法樹
{
  "type": "Program",
  "start": 0,
  "end": 528,
  "body": [
    {
      "type": "ImportDeclaration",
      "start": 0,
      "end": 30,
      "specifiers": [
        {
          "type": "ImportDefaultSpecifier",
          "start": 7,
          "end": 11,
          "local": {
            "type": "Identifier",
            "start": 7,
            "end": 11,
            "name": "logo"
          }
        }
      ],
      "source": {
        "type": "Literal",
        "start": 17,
        "end": 29,
        "value": "./logo.svg",
        "raw": "'./logo.svg'"
      }
    },
    {
      "type": "ImportDeclaration",
      "start": 31,
      "end": 50,
      "specifiers": [],
      "source": {
        "type": "Literal",
        "start": 38,
        "end": 49,
        "value": "./App.css",
        "raw": "'./App.css'"
      }
    },
    {
      "type": "FunctionDeclaration",
      "start": 52,
      "end": 506,
      "id": {
        "type": "Identifier",
        "start": 61,
        "end": 64,
        "name": "App"
      },
      "expression": false,
      "generator": false,
      "async": false,
      "params": [],
      "body": {
        "type": "BlockStatement",
        "start": 67,
        "end": 506,
        "body": [
          {
            "type": "ReturnStatement",
            "start": 71,
            "end": 504,
            "argument": {
              "type": "JSXElement",
              "start": 84,
              "end": 499,
              "openingElement": {
                "type": "JSXOpeningElement",
                "start": 84,
                "end": 105,
                "attributes": [
                  {
                    "type": "JSXAttribute",
                    "start": 89,
                    "end": 104,
                    "name": {
                      "type": "JSXIdentifier",
                      "start": 89,
                      "end": 98,
                      "name": "className"
                    },
                    "value": {
                      "type": "Literal",
                      "start": 99,
                      "end": 104,
                      "value": "App",
                      "raw": "\"App\""
                    }
                  }
                ],
                "name": {
                  "type": "JSXIdentifier",
                  "start": 85,
                  "end": 88,
                  "name": "div"
                },
                "selfClosing": false
              },
              "closingElement": {
                "type": "JSXClosingElement",
                "start": 493,
                "end": 499,
                "name": {
                  "type": "JSXIdentifier",
                  "start": 495,
                  "end": 498,
                  "name": "div"
                }
              },
              "children": [
                {
                  "type": "JSXText",
                  "start": 105,
                  "end": 112,
                  "value": "\n      ",
                  "raw": "\n      "
                },
                {
                  "type": "JSXElement",
                  "start": 112,
                  "end": 488,
                  "openingElement": {
                    "type": "JSXOpeningElement",
                    "start": 112,
                    "end": 143,
                    "attributes": [
                      {
                        "type": "JSXAttribute",
                        "start": 120,
                        "end": 142,
                        "name": {
                          "type": "JSXIdentifier",
                          "start": 120,
                          "end": 129,
                          "name": "className"
                        },
                        "value": {
                          "type": "Literal",
                          "start": 130,
                          "end": 142,
                          "value": "App-header",
                          "raw": "\"App-header\""
                        }
                      }
                    ],
                    "name": {
                      "type": "JSXIdentifier",
                      "start": 113,
                      "end": 119,
                      "name": "header"
                    },
                    "selfClosing": false
                  },
                  "closingElement": {
                    "type": "JSXClosingElement",
                    "start": 479,
                    "end": 488,
                    "name": {
                      "type": "JSXIdentifier",
                      "start": 481,
                      "end": 487,
                      "name": "header"
                    }
                  },
                  "children": [
                    {
                      "type": "JSXText",
                      "start": 143,
                      "end": 152,
                      "value": "\n        ",
                      "raw": "\n        "
                    },
                    {
                      "type": "JSXElement",
                      "start": 152,
                      "end": 202,
                      "openingElement": {
                        "type": "JSXOpeningElement",
                        "start": 152,
                        "end": 202,
                        "attributes": [
                          {
                            "type": "JSXAttribute",
                            "start": 157,
                            "end": 167,
                            "name": {
                              "type": "JSXIdentifier",
                              "start": 157,
                              "end": 160,
                              "name": "src"
                            },
                            "value": {
                              "type": "JSXExpressionContainer",
                              "start": 161,
                              "end": 167,
                              "expression": {
                                "type": "Identifier",
                                "start": 162,
                                "end": 166,
                                "name": "logo"
                              }
                            }
                          },
                          {
                            "type": "JSXAttribute",
                            "start": 168,
                            "end": 188,
                            "name": {
                              "type": "JSXIdentifier",
                              "start": 168,
                              "end": 177,
                              "name": "className"
                            },
                            "value": {
                              "type": "Literal",
                              "start": 178,
                              "end": 188,
                              "value": "App-logo",
                              "raw": "\"App-logo\""
                            }
                          },
                          {
                            "type": "JSXAttribute",
                            "start": 189,
                            "end": 199,
                            "name": {
                              "type": "JSXIdentifier",
                              "start": 189,
                              "end": 192,
                              "name": "alt"
                            },
                            "value": {
                              "type": "Literal",
                              "start": 193,
                              "end": 199,
                              "value": "logo",
                              "raw": "\"logo\""
                            }
                          }
                        ],
                        "name": {
                          "type": "JSXIdentifier",
                          "start": 153,
                          "end": 156,
                          "name": "img"
                        },
                        "selfClosing": true
                      },
                      "closingElement": null,
                      "children": []
                    },
                    {
                      "type": "JSXText",
                      "start": 202,
                      "end": 211,
                      "value": "\n        ",
                      "raw": "\n        "
                    },
                    {
                      "type": "JSXElement",
                      "start": 211,
                      "end": 286,
                      "openingElement": {
                        "type": "JSXOpeningElement",
                        "start": 211,
                        "end": 214,
                        "attributes": [],
                        "name": {
                          "type": "JSXIdentifier",
                          "start": 212,
                          "end": 213,
                          "name": "p"
                        },
                        "selfClosing": false
                      },
                      "closingElement": {
                        "type": "JSXClosingElement",
                        "start": 282,
                        "end": 286,
                        "name": {
                          "type": "JSXIdentifier",
                          "start": 284,
                          "end": 285,
                          "name": "p"
                        }
                      },
                      "children": [
                        {
                          "type": "JSXText",
                          "start": 214,
                          "end": 230,
                          "value": "\n          Edit ",
                          "raw": "\n          Edit "
                        },
                        {
                          "type": "JSXElement",
                          "start": 230,
                          "end": 253,
                          "openingElement": {
                            "type": "JSXOpeningElement",
                            "start": 230,
                            "end": 236,
                            "attributes": [],
                            "name": {
                              "type": "JSXIdentifier",
                              "start": 231,
                              "end": 235,
                              "name": "code"
                            },
                            "selfClosing": false
                          },
                          "closingElement": {
                            "type": "JSXClosingElement",
                            "start": 246,
                            "end": 253,
                            "name": {
                              "type": "JSXIdentifier",
                              "start": 248,
                              "end": 252,
                              "name": "code"
                            }
                          },
                          "children": [
                            {
                              "type": "JSXText",
                              "start": 236,
                              "end": 246,
                              "value": "src/App.js",
                              "raw": "src/App.js"
                            }
                          ]
                        },
                        {
                          "type": "JSXText",
                          "start": 253,
                          "end": 282,
                          "value": " and save to reload.\n        ",
                          "raw": " and save to reload.\n        "
                        }
                      ]
                    },
                    {
                      "type": "JSXText",
                      "start": 286,
                      "end": 295,
                      "value": "\n        ",
                      "raw": "\n        "
                    },
                    {
                      "type": "JSXElement",
                      "start": 295,
                      "end": 472,
                      "openingElement": {
                        "type": "JSXOpeningElement",
                        "start": 295,
                        "end": 437,
                        "attributes": [
                          {
                            "type": "JSXAttribute",
                            "start": 308,
                            "end": 328,
                            "name": {
                              "type": "JSXIdentifier",
                              "start": 308,
                              "end": 317,
                              "name": "className"
                            },
                            "value": {
                              "type": "Literal",
                              "start": 318,
                              "end": 328,
                              "value": "App-link",
                              "raw": "\"App-link\""
                            }
                          },
                          {
                            "type": "JSXAttribute",
                            "start": 339,
                            "end": 365,
                            "name": {
                              "type": "JSXIdentifier",
                              "start": 339,
                              "end": 343,
                              "name": "href"
                            },
                            "value": {
                              "type": "Literal",
                              "start": 344,
                              "end": 365,
                              "value": "https://reactjs.org",
                              "raw": "\"https://reactjs.org\""
                            }
                          },
                          {
                            "type": "JSXAttribute",
                            "start": 376,
                            "end": 391,
                            "name": {
                              "type": "JSXIdentifier",
                              "start": 376,
                              "end": 382,
                              "name": "target"
                            },
                            "value": {
                              "type": "Literal",
                              "start": 383,
                              "end": 391,
                              "value": "_blank",
                              "raw": "\"_blank\""
                            }
                          },
                          {
                            "type": "JSXAttribute",
                            "start": 402,
                            "end": 427,
                            "name": {
                              "type": "JSXIdentifier",
                              "start": 402,
                              "end": 405,
                              "name": "rel"
                            },
                            "value": {
                              "type": "Literal",
                              "start": 406,
                              "end": 427,
                              "value": "noopener noreferrer",
                              "raw": "\"noopener noreferrer\""
                            }
                          }
                        ],
                        "name": {
                          "type": "JSXIdentifier",
                          "start": 296,
                          "end": 297,
                          "name": "a"
                        },
                        "selfClosing": false
                      },
                      "closingElement": {
                        "type": "JSXClosingElement",
                        "start": 468,
                        "end": 472,
                        "name": {
                          "type": "JSXIdentifier",
                          "start": 470,
                          "end": 471,
                          "name": "a"
                        }
                      },
                      "children": [
                        {
                          "type": "JSXText",
                          "start": 437,
                          "end": 468,
                          "value": "\n          Learn React\n        ",
                          "raw": "\n          Learn React\n        "
                        }
                      ]
                    },
                    {
                      "type": "JSXText",
                      "start": 472,
                      "end": 479,
                      "value": "\n      ",
                      "raw": "\n      "
                    }
                  ]
                },
                {
                  "type": "JSXText",
                  "start": 488,
                  "end": 493,
                  "value": "\n    ",
                  "raw": "\n    "
                }
              ]
            }
          }
        ]
      }
    },
    {
      "type": "ExportDefaultDeclaration",
      "start": 508,
      "end": 527,
      "declaration": {
        "type": "Identifier",
        "start": 523,
        "end": 526,
        "name": "App"
      }
    }
  ],
  "sourceType": "module"
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 227,748評論 6 531
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 98,165評論 3 414
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事?!?“怎么了?”我有些...
    開封第一講書人閱讀 175,595評論 0 373
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經(jīng)常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 62,633評論 1 309
  • 正文 為了忘掉前任,我火速辦了婚禮,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 71,435評論 6 405
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 54,943評論 1 321
  • 那天,我揣著相機(jī)與錄音,去河邊找鬼。 笑死,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,035評論 3 440
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 42,175評論 0 287
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 48,713評論 1 333
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 40,599評論 3 354
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 42,788評論 1 369
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,303評論 5 358
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 44,034評論 3 347
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,412評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 35,664評論 1 280
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 51,408評論 3 390
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 47,747評論 2 370

推薦閱讀更多精彩內(nèi)容