在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:acornjs/acorn开源软件地址:https://github.com/acornjs/acorn开源编程语言:JavaScript 99.9%开源软件介绍:AcornA tiny, fast JavaScript parser, written completely in JavaScript. CommunityAcorn is open source software released under an MIT license. You are welcome to report bugs or create pull requests on github. For questions and discussion, please use the Tern discussion forum. PackagesThis repository holds three packages:
To build the content of the repository, run git clone https://github.com/acornjs/acorn.git
cd acorn
npm install Plugin developmentsAcorn is designed to support plugins which can, within reasonable bounds, redefine the way the parser works. Plugins can add new token types and new tokenizer contexts (if necessary), and extend methods in the parser object. This is not a clean, elegant API—using it requires an understanding of Acorn's internals, and plugins are likely to break whenever those internals are significantly changed. But still, it is possible, in this way, to create parsers for JavaScript dialects without forking all of Acorn. And in principle it is even possible to combine such plugins, so that if you have, for example, a plugin for parsing types and a plugin for parsing JSX-style XML literals, you could load them both and parse code with both JSX tags and types. A plugin is a function from a parser class to an extended parser
class. Plugins can be used by simply applying them to the const {Parser} = require("acorn")
const MyParser = Parser.extend(
require("acorn-jsx")(),
require("acorn-bigint")
)
console.log(MyParser.parse("// Some bigint + JSX code")) Plugins override methods in their new parser class to implement additional functionality. It is recommended for a plugin package to export its plugin function as its default value or, if it takes configuration parameters, to export a constructor function that creates the plugin function. This is what a trivial plugin, which adds a bit of code to the
module.exports = function noisyReadToken(Parser) {
return class extends Parser {
readToken(code) {
console.log("Reading a token!")
super.readToken(code)
}
}
} |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论