123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- "use strict";
- const acorn = require("acorn");
- const jsx = require("acorn-jsx");
- const astNodeTypes = require("./lib/ast-node-types");
- const espree = require("./lib/espree");
- const { getLatestEcmaVersion, getSupportedEcmaVersions } = require("./lib/options");
- const parsers = {
- _regular: null,
- _jsx: null,
- get regular() {
- if (this._regular === null) {
- this._regular = acorn.Parser.extend(espree());
- }
- return this._regular;
- },
- get jsx() {
- if (this._jsx === null) {
- this._jsx = acorn.Parser.extend(jsx(), espree());
- }
- return this._jsx;
- },
- get(options) {
- const useJsx = Boolean(
- options &&
- options.ecmaFeatures &&
- options.ecmaFeatures.jsx
- );
- return useJsx ? this.jsx : this.regular;
- }
- };
- function tokenize(code, options) {
- const Parser = parsers.get(options);
-
- if (!options || options.tokens !== true) {
- options = Object.assign({}, options, { tokens: true });
- }
- return new Parser(options, code).tokenize();
- }
- function parse(code, options) {
- const Parser = parsers.get(options);
- return new Parser(options, code).parse();
- }
- exports.version = require("./package.json").version;
- exports.tokenize = tokenize;
- exports.parse = parse;
- exports.Syntax = (function() {
- let name,
- types = {};
- if (typeof Object.create === "function") {
- types = Object.create(null);
- }
- for (name in astNodeTypes) {
- if (Object.hasOwnProperty.call(astNodeTypes, name)) {
- types[name] = astNodeTypes[name];
- }
- }
- if (typeof Object.freeze === "function") {
- Object.freeze(types);
- }
- return types;
- }());
- exports.VisitorKeys = (function() {
- return require("eslint-visitor-keys").KEYS;
- }());
- exports.latestEcmaVersion = getLatestEcmaVersion();
- exports.supportedEcmaVersions = getSupportedEcmaVersions();
|