编程知识 cdmana.com

A brief introduction to various JavaScript parsers

author : sea

Various js Parser is the cornerstone of front-end engineering , It can be said that without it , A lot of Engineering doesn't work properly , We use it every day babel、webpack、eslint、TypeScript We all need a set of corresponding js Parser , Today we'll look at it , What parsers are commonly used in the market at present , What characteristics do they have ?

Preface

Say js Before parser , We need to know something about ESTree This project , The original intention of this project is through the power of the community , Guarantee and es Consistency of specifications , To express through a custom grammatical structure JavaScript Of AST, Later, with the increasing popularity , With the participation of many well-known Engineers , It has become a de facto norm , The current library is Mozilla Maintained with the community .

without AST standard , That means that you can't create a parser at all , And if the AST Disunity of norms , Some of the corresponding tool libraries can't communicate with each other well , such as webpack It can't be used normally babel Related to the plug-in .

Precisely because EsTree The specification of the definition of , So now all the js Parser or compiler , It's basically impossible to get around it , If you want to write one yourself js Parser , Then you must read the document again .

One . Well-known JS Parser

1.1 uglify-js (11.2k*)

Creation time :2010-8-1
Work address :https://github.com/mishoo/UglifyJS
The authors introduce :Mihai Bazon,Lisp The programmer ,Emacs lovers , It looks like Romanian
The author blog :

  • https://github.com/mishoo
  • uglify-js Can pass --acorn perhaps --spidermonkey Specify corresponding parsing

    1.2 Esprima (6k*)

    Creation time :2011-11-20
    Work address :https://github.com/jquery/esprima
    The authors introduce :ariya Indonesians , Got a doctorate in Germany , Currently living in Silicon Valley mountain view , Created the world's first truly headless Web browser PhantomJS. Also for the WebKit, KDE, and Qt Contributed a lot of code
    The author blog :

    • https://ariya.io/about
    • https://github.com/ariya

    This is a The first one uses JavaScript Written in line with EsTree canonical JavaScript The parser , Many subsequent compilers are affected by it , I think its emergence has historical significance .

    1.3 acorn (6.8k*)

    Creation time :2012-9-23
    Work address :https://github.com/acornjs/acorn
    The authors introduce :Marijn Haverbeke, It's also a rich text editor prosemirror(4.8k)、 Browser code editor CodeMirror(21.7k) The author of , He also published a Book 《Eloquent JavaScript》, And this book is also available online https://eloquentjavascript.net/, At present, the book has been translated in China , But only the second edition 《JavaScript Programming insight 》, There are also people who currently live in Berlin, Germany .
    The author blog :

    • https://marijnhaverbeke.nl/
    • https://github.com/marijnh

    acorn and Esprima Is very similar , Output ast It's all in line with EsTree canonical , at present webpack Of AST The parser uses acorn, and Esprima equally , It also doesn't directly support JSX

    It should be mentioned that ,acorn Of es6 Grammar support RReverser Contributed more than half of [2]

    1.4 @babel/parser(babylon)

    Creation time :2012-9-23
    Work address :https://github.com/babel/babel/tree/master/packages/babel-parser

    babel Official parser , first fork On acorn, Later, he completely went his own way , from babylon After the change of name , The plug-in system it builds is very powerful .

    1.5 espree (1.3k*)

    Creation time :2014-11-30
    Work address :https://github.com/eslint/espree
    author :Nicholas C. Zakas, Multiple copies js Books , among 《 Red Treasure Book The third edition 》 Most famous ,eslint He also created , stay 2016 He was diagnosed with Lyme disease in , I haven't worked for a long time now , If you're interested , You can go to github It donated him , Donation page links .
    The author blog :

    • https://github.com/nzakas
    • https://humanwhocodes.com/

    eslint、prettier Default parser for , first fork On Esprima A branch of (v1.2.2), Later, because ES6 Rapid development of , but Esprima I don't support it for a short time , It's based on acorn Developed .

    1.5 TypeScript

    Creation time :2014-7-6
    Work address :https://github.com/microsoft/TypeScript/tree/master/src/compiler
    author : This is microsoft Of Anders Hejlsberg Leaders created , He is also C#、Delphi、Turbo Pascal The author of

    Now there are a lot of big projects , The first choice is TypeScript, Its parser is .........

版权声明
本文为[Irving the procedural ape]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201225100106178Z.html

Scroll to Top