123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- import * as acorn from "acorn";
- import jsx from "acorn-jsx";
- import espree from "./lib/espree.js";
- import espreeVersion from "./lib/version.js";
- import * as visitorKeys from "eslint-visitor-keys";
- import { getLatestEcmaVersion, getSupportedEcmaVersions } from "./lib/options.js";
- 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;
- }
- };
- export 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();
- }
- export function parse(code, options) {
- const Parser = parsers.get(options);
- return new Parser(options, code).parse();
- }
- export const version = espreeVersion;
- export const name = "espree";
- export const VisitorKeys = (function() {
- return visitorKeys.KEYS;
- }());
- export const Syntax = (function() {
- let key,
- types = {};
- if (typeof Object.create === "function") {
- types = Object.create(null);
- }
- for (key in VisitorKeys) {
- if (Object.hasOwnProperty.call(VisitorKeys, key)) {
- types[key] = key;
- }
- }
- if (typeof Object.freeze === "function") {
- Object.freeze(types);
- }
- return types;
- }());
- export const latestEcmaVersion = getLatestEcmaVersion();
- export const supportedEcmaVersions = getSupportedEcmaVersions();
|