Brunobkr/llama.cpp_AlgMor24_github
ΩFFFΣLLIa • llama.cpp • AlgMor24 ██████╗ ███████╗███████╗███████╗██╗ ██╗ ██╗ █████╗ ██╔═══██╗██╔════╝██╔════╝██╔════╝██║ ██║ ██║██╔══██╗ ██║ ██║█████╗ █████╗ █████╗ ██║ ██║ ██║███████║ ██║ ██║██╔══╝ ██╔══╝ ██╔══╝ ██║ ██║ ██║██╔══██║ ╚██████╔╝██║ ██║ ███████╗███████╗███████╗██║██║ ██║ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚══════╝╚═╝╚═╝ ╚═╝ High-Performance LLM / VLM Inference & Autonomous Agentic Ecosystem… See the full description on the dataset page: https://huggingface.co/datasets/Brunobkr/llama.cpp_AlgMor24_github.
03.1k
1'use strict';2 3Object.defineProperty(exports, '__esModule', { value: true });4 5var acorn = require('acorn');6var jsx = require('acorn-jsx');7var visitorKeys = require('eslint-visitor-keys');8 9function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }10 11function _interopNamespace(e) {12 if (e && e.__esModule) return e;13 var n = Object.create(null);14 if (e) {15 Object.keys(e).forEach(function (k) {16 if (k !== 'default') {17 var d = Object.getOwnPropertyDescriptor(e, k);18 Object.defineProperty(n, k, d.get ? d : {19 enumerable: true,20 get: function () { return e[k]; }21 });22 }23 });24 }25 n["default"] = e;26 return Object.freeze(n);27}28 29var acorn__namespace = /*#__PURE__*/_interopNamespace(acorn);30var jsx__default = /*#__PURE__*/_interopDefaultLegacy(jsx);31var visitorKeys__namespace = /*#__PURE__*/_interopNamespace(visitorKeys);32 33/**34 * @fileoverview Translates tokens between Acorn format and Esprima format.35 * @author Nicholas C. Zakas36 */37 38//------------------------------------------------------------------------------39// Requirements40//------------------------------------------------------------------------------41 42// none!43 44//------------------------------------------------------------------------------45// Private46//------------------------------------------------------------------------------47 48 49// Esprima Token Types50const Token = {51 Boolean: "Boolean",52 EOF: "<end>",53 Identifier: "Identifier",54 PrivateIdentifier: "PrivateIdentifier",55 Keyword: "Keyword",56 Null: "Null",57 Numeric: "Numeric",58 Punctuator: "Punctuator",59 String: "String",60 RegularExpression: "RegularExpression",61 Template: "Template",62 JSXIdentifier: "JSXIdentifier",63 JSXText: "JSXText"64};65 66/**67 * Converts part of a template into an Esprima token.68 * @param {AcornToken[]} tokens The Acorn tokens representing the template.69 * @param {string} code The source code.70 * @returns {EsprimaToken} The Esprima equivalent of the template token.71 * @private72 */73function convertTemplatePart(tokens, code) {74 const firstToken = tokens[0],75 lastTemplateToken = tokens.at(-1);76 77 const token = {78 type: Token.Template,79 value: code.slice(firstToken.start, lastTemplateToken.end)80 };81 82 if (firstToken.loc) {83 token.loc = {84 start: firstToken.loc.start,85 end: lastTemplateToken.loc.end86 };87 }88 89 if (firstToken.range) {90 token.start = firstToken.range[0];91 token.end = lastTemplateToken.range[1];92 token.range = [token.start, token.end];93 }94 95 return token;96}97 98/**99 * Contains logic to translate Acorn tokens into Esprima tokens.100 * @param {Object} acornTokTypes The Acorn token types.101 * @param {string} code The source code Acorn is parsing. This is necessary102 * to correct the "value" property of some tokens.103 * @constructor104 */105function TokenTranslator(acornTokTypes, code) {106 107 // token types108 this._acornTokTypes = acornTokTypes;109 110 // token buffer for templates111 this._tokens = [];112 113 // track the last curly brace114 this._curlyBrace = null;115 116 // the source code117 this._code = code;118 119}120 121TokenTranslator.prototype = {122 constructor: TokenTranslator,123 124 /**125 * Translates a single Esprima token to a single Acorn token. This may be126 * inaccurate due to how templates are handled differently in Esprima and127 * Acorn, but should be accurate for all other tokens.128 * @param {AcornToken} token The Acorn token to translate.129 * @param {Object} extra Espree extra object.130 * @returns {EsprimaToken} The Esprima version of the token.131 */132 translate(token, extra) {133 134 const type = token.type,135 tt = this._acornTokTypes;136 137 if (type === tt.name) {138 token.type = Token.Identifier;139 140 // TODO: See if this is an Acorn bug141 if (token.value === "static") {142 token.type = Token.Keyword;143 }144 145 if (extra.ecmaVersion > 5 && (token.value === "yield" || token.value === "let")) {146 token.type = Token.Keyword;147 }148 149 } else if (type === tt.privateId) {150 token.type = Token.PrivateIdentifier;151 152 } else if (type === tt.semi || type === tt.comma ||153 type === tt.parenL || type === tt.parenR ||154 type === tt.braceL || type === tt.braceR ||155 type === tt.dot || type === tt.bracketL ||156 type === tt.colon || type === tt.question ||157 type === tt.bracketR || type === tt.ellipsis ||158 type === tt.arrow || type === tt.jsxTagStart ||159 type === tt.incDec || type === tt.starstar ||160 type === tt.jsxTagEnd || type === tt.prefix ||161 type === tt.questionDot ||162 (type.binop && !type.keyword) ||163 type.isAssign) {164 165 token.type = Token.Punctuator;166 token.value = this._code.slice(token.start, token.end);167 } else if (type === tt.jsxName) {168 token.type = Token.JSXIdentifier;169 } else if (type.label === "jsxText" || type === tt.jsxAttrValueToken) {170 token.type = Token.JSXText;171 } else if (type.keyword) {172 if (type.keyword === "true" || type.keyword === "false") {173 token.type = Token.Boolean;174 } else if (type.keyword === "null") {175 token.type = Token.Null;176 } else {177 token.type = Token.Keyword;178 }179 } else if (type === tt.num) {180 token.type = Token.Numeric;181 token.value = this._code.slice(token.start, token.end);182 } else if (type === tt.string) {183 184 if (extra.jsxAttrValueToken) {185 extra.jsxAttrValueToken = false;186 token.type = Token.JSXText;187 } else {188 token.type = Token.String;189 }190 191 token.value = this._code.slice(token.start, token.end);192 } else if (type === tt.regexp) {193 token.type = Token.RegularExpression;194 const value = token.value;195 196 token.regex = {197 flags: value.flags,198 pattern: value.pattern199 };200 token.value = `/${value.pattern}/${value.flags}`;201 }202 203 return token;204 },205 206 /**207 * Function to call during Acorn's onToken handler.208 * @param {AcornToken} token The Acorn token.209 * @param {Object} extra The Espree extra object.210 * @returns {void}211 */212 onToken(token, extra) {213 214 const tt = this._acornTokTypes,215 tokens = extra.tokens,216 templateTokens = this._tokens;217 218 /**219 * Flushes the buffered template tokens and resets the template220 * tracking.221 * @returns {void}222 * @private223 */224 const translateTemplateTokens = () => {225 tokens.push(convertTemplatePart(this._tokens, this._code));226 this._tokens = [];227 };228 229 if (token.type === tt.eof) {230 231 // might be one last curlyBrace232 if (this._curlyBrace) {233 tokens.push(this.translate(this._curlyBrace, extra));234 }235 236 return;237 }238 239 if (token.type === tt.backQuote) {240 241 // if there's already a curly, it's not part of the template242 if (this._curlyBrace) {243 tokens.push(this.translate(this._curlyBrace, extra));244 this._curlyBrace = null;245 }246 247 templateTokens.push(token);248 249 // it's the end250 if (templateTokens.length > 1) {251 translateTemplateTokens();252 }253 254 return;255 }256 if (token.type === tt.dollarBraceL) {257 templateTokens.push(token);258 translateTemplateTokens();259 return;260 }261 if (token.type === tt.braceR) {262 263 // if there's already a curly, it's not part of the template264 if (this._curlyBrace) {265 tokens.push(this.translate(this._curlyBrace, extra));266 }267 268 // store new curly for later269 this._curlyBrace = token;270 return;271 }272 if (token.type === tt.template || token.type === tt.invalidTemplate) {273 if (this._curlyBrace) {274 templateTokens.push(this._curlyBrace);275 this._curlyBrace = null;276 }277 278 templateTokens.push(token);279 return;280 }281 282 if (this._curlyBrace) {283 tokens.push(this.translate(this._curlyBrace, extra));284 this._curlyBrace = null;285 }286 287 tokens.push(this.translate(token, extra));288 }289};290 291/**292 * @fileoverview A collection of methods for processing Espree's options.293 * @author Kai Cataldo294 */295 296//------------------------------------------------------------------------------297// Helpers298//------------------------------------------------------------------------------299 300const SUPPORTED_VERSIONS = [301 3,302 5,303 6, // 2015304 7, // 2016305 8, // 2017306 9, // 2018307 10, // 2019308 11, // 2020309 12, // 2021310 13, // 2022311 14, // 2023312 15, // 2024313 16, // 2025314 17 // 2026315];316 317/**318 * Get the latest ECMAScript version supported by Espree.319 * @returns {number} The latest ECMAScript version.320 */321function getLatestEcmaVersion() {322 return SUPPORTED_VERSIONS.at(-1);323}324 325/**326 * Get the list of ECMAScript versions supported by Espree.327 * @returns {number[]} An array containing the supported ECMAScript versions.328 */329function getSupportedEcmaVersions() {330 return [...SUPPORTED_VERSIONS];331}332 333/**334 * Normalize ECMAScript version from the initial config335 * @param {(number|"latest")} ecmaVersion ECMAScript version from the initial config336 * @throws {Error} throws an error if the ecmaVersion is invalid.337 * @returns {number} normalized ECMAScript version338 */339function normalizeEcmaVersion(ecmaVersion = 5) {340 341 let version = ecmaVersion === "latest" ? getLatestEcmaVersion() : ecmaVersion;342 343 if (typeof version !== "number") {344 throw new Error(`ecmaVersion must be a number or "latest". Received value of type ${typeof ecmaVersion} instead.`);345 }346 347 // Calculate ECMAScript edition number from official year version starting with348 // ES2015, which corresponds with ES6 (or a difference of 2009).349 if (version >= 2015) {350 version -= 2009;351 }352 353 if (!SUPPORTED_VERSIONS.includes(version)) {354 throw new Error("Invalid ecmaVersion.");355 }356 357 return version;358}359 360/**361 * Normalize sourceType from the initial config362 * @param {string} sourceType to normalize363 * @throws {Error} throw an error if sourceType is invalid364 * @returns {string} normalized sourceType365 */366function normalizeSourceType(sourceType = "script") {367 if (sourceType === "script" || sourceType === "module") {368 return sourceType;369 }370 371 if (sourceType === "commonjs") {372 return "script";373 }374 375 throw new Error("Invalid sourceType.");376}377 378/**379 * Normalize parserOptions380 * @param {Object} options the parser options to normalize381 * @throws {Error} throw an error if found invalid option.382 * @returns {Object} normalized options383 */384function normalizeOptions(options) {385 const ecmaVersion = normalizeEcmaVersion(options.ecmaVersion);386 const sourceType = normalizeSourceType(options.sourceType);387 const ranges = options.range === true;388 const locations = options.loc === true;389 390 if (ecmaVersion !== 3 && options.allowReserved) {391 392 // a value of `false` is intentionally allowed here, so a shared config can overwrite it when needed393 throw new Error("`allowReserved` is only supported when ecmaVersion is 3");394 }395 if (typeof options.allowReserved !== "undefined" && typeof options.allowReserved !== "boolean") {396 throw new Error("`allowReserved`, when present, must be `true` or `false`");397 }398 const allowReserved = ecmaVersion === 3 ? (options.allowReserved || "never") : false;399 const ecmaFeatures = options.ecmaFeatures || {};400 const allowReturnOutsideFunction = options.sourceType === "commonjs" ||401 Boolean(ecmaFeatures.globalReturn);402 403 if (sourceType === "module" && ecmaVersion < 6) {404 throw new Error("sourceType 'module' is not supported when ecmaVersion < 2015. Consider adding `{ ecmaVersion: 2015 }` to the parser options.");405 }406 407 return Object.assign({}, options, {408 ecmaVersion,409 sourceType,410 ranges,411 locations,412 allowReserved,413 allowReturnOutsideFunction414 });415}416 417/* eslint no-param-reassign: 0 -- stylistic choice */418 419 420const STATE = Symbol("espree's internal state");421const ESPRIMA_FINISH_NODE = Symbol("espree's esprimaFinishNode");422 423 424/**425 * Converts an Acorn comment to a Esprima comment.426 * @param {boolean} block True if it's a block comment, false if not.427 * @param {string} text The text of the comment.428 * @param {int} start The index at which the comment starts.429 * @param {int} end The index at which the comment ends.430 * @param {Location} startLoc The location at which the comment starts.431 * @param {Location} endLoc The location at which the comment ends.432 * @param {string} code The source code being parsed.433 * @returns {Object} The comment object.434 * @private435 */436function convertAcornCommentToEsprimaComment(block, text, start, end, startLoc, endLoc, code) {437 let type;438 439 if (block) {440 type = "Block";441 } else if (code.slice(start, start + 2) === "#!") {442 type = "Hashbang";443 } else {444 type = "Line";445 }446 447 const comment = {448 type,449 value: text450 };451 452 if (typeof start === "number") {453 comment.start = start;454 comment.end = end;455 comment.range = [start, end];456 }457 458 if (typeof startLoc === "object") {459 comment.loc = {460 start: startLoc,461 end: endLoc462 };463 }464 465 return comment;466}467 468var espree = () => Parser => {469 const tokTypes = Object.assign({}, Parser.acorn.tokTypes);470 471 if (Parser.acornJsx) {472 Object.assign(tokTypes, Parser.acornJsx.tokTypes);473 }474 475 return class Espree extends Parser {476 constructor(opts, code) {477 if (typeof opts !== "object" || opts === null) {478 opts = {};479 }480 if (typeof code !== "string" && !(code instanceof String)) {481 code = String(code);482 }483 484 // save original source type in case of commonjs485 const originalSourceType = opts.sourceType;486 const options = normalizeOptions(opts);487 const ecmaFeatures = options.ecmaFeatures || {};488 const tokenTranslator =489 options.tokens === true490 ? new TokenTranslator(tokTypes, code)491 : null;492 493 /*494 * Data that is unique to Espree and is not represented internally495 * in Acorn.496 *497 * For ES2023 hashbangs, Espree will call `onComment()` during the498 * constructor, so we must define state before having access to499 * `this`.500 */501 const state = {502 originalSourceType: originalSourceType || options.sourceType,503 tokens: tokenTranslator ? [] : null,504 comments: options.comment === true ? [] : null,505 impliedStrict: ecmaFeatures.impliedStrict === true && options.ecmaVersion >= 5,506 ecmaVersion: options.ecmaVersion,507 jsxAttrValueToken: false,508 lastToken: null,509 templateElements: []510 };511 512 // Initialize acorn parser.513 super({514 515 // do not use spread, because we don't want to pass any unknown options to acorn516 ecmaVersion: options.ecmaVersion,517 sourceType: options.sourceType,518 ranges: options.ranges,519 locations: options.locations,520 allowReserved: options.allowReserved,521 522 // Truthy value is true for backward compatibility.523 allowReturnOutsideFunction: options.allowReturnOutsideFunction,524 525 // Collect tokens526 onToken(token) {527 if (tokenTranslator) {528 529 // Use `tokens`, `ecmaVersion`, and `jsxAttrValueToken` in the state.530 tokenTranslator.onToken(token, state);531 }532 if (token.type !== tokTypes.eof) {533 state.lastToken = token;534 }535 },536 537 // Collect comments538 onComment(block, text, start, end, startLoc, endLoc) {539 if (state.comments) {540 const comment = convertAcornCommentToEsprimaComment(block, text, start, end, startLoc, endLoc, code);541 542 state.comments.push(comment);543 }544 }545 }, code);546 547 /*548 * We put all of this data into a symbol property as a way to avoid549 * potential naming conflicts with future versions of Acorn.550 */551 this[STATE] = state;552 }553 554 tokenize() {555 do {556 this.next();557 } while (this.type !== tokTypes.eof);558 559 // Consume the final eof token560 this.next();561 562 const extra = this[STATE];563 const tokens = extra.tokens;564 565 if (extra.comments) {566 tokens.comments = extra.comments;567 }568 569 return tokens;570 }571 572 finishNode(...args) {573 const result = super.finishNode(...args);574 575 return this[ESPRIMA_FINISH_NODE](result);576 }577 578 finishNodeAt(...args) {579 const result = super.finishNodeAt(...args);580 581 return this[ESPRIMA_FINISH_NODE](result);582 }583 584 parse() {585 const extra = this[STATE];586 const program = super.parse();587 588 program.sourceType = extra.originalSourceType;589 590 if (extra.comments) {591 program.comments = extra.comments;592 }593 if (extra.tokens) {594 program.tokens = extra.tokens;595 }596 597 /*598 * Adjust opening and closing position of program to match Esprima.599 * Acorn always starts programs at range 0 whereas Esprima starts at the600 * first AST node's start (the only real difference is when there's leading601 * whitespace or leading comments). Acorn also counts trailing whitespace602 * as part of the program whereas Esprima only counts up to the last token.603 */604 if (program.body.length) {605 const [firstNode] = program.body;606 607 if (program.range) {608 program.range[0] = firstNode.range[0];609 }610 if (program.loc) {611 program.loc.start = firstNode.loc.start;612 }613 program.start = firstNode.start;614 }615 if (extra.lastToken) {616 if (program.range) {617 program.range[1] = extra.lastToken.range[1];618 }619 if (program.loc) {620 program.loc.end = extra.lastToken.loc.end;621 }622 program.end = extra.lastToken.end;623 }624 625 626 /*627 * https://github.com/eslint/espree/issues/349628 * Ensure that template elements have correct range information.629 * This is one location where Acorn produces a different value630 * for its start and end properties vs. the values present in the631 * range property. In order to avoid confusion, we set the start632 * and end properties to the values that are present in range.633 * This is done here, instead of in finishNode(), because Acorn634 * uses the values of start and end internally while parsing, making635 * it dangerous to change those values while parsing is ongoing.636 * By waiting until the end of parsing, we can safely change these637 * values without affect any other part of the process.638 */639 this[STATE].templateElements.forEach(templateElement => {640 const startOffset = -1;641 const endOffset = templateElement.tail ? 1 : 2;642 643 templateElement.start += startOffset;644 templateElement.end += endOffset;645 646 if (templateElement.range) {647 templateElement.range[0] += startOffset;648 templateElement.range[1] += endOffset;649 }650 651 if (templateElement.loc) {652 templateElement.loc.start.column += startOffset;653 templateElement.loc.end.column += endOffset;654 }655 });656 657 return program;658 }659 660 parseTopLevel(node) {661 if (this[STATE].impliedStrict) {662 this.strict = true;663 }664 return super.parseTopLevel(node);665 }666 667 /**668 * Overwrites the default raise method to throw Esprima-style errors.669 * @param {int} pos The position of the error.670 * @param {string} message The error message.671 * @throws {SyntaxError} A syntax error.672 * @returns {void}673 */674 raise(pos, message) {675 const loc = Parser.acorn.getLineInfo(this.input, pos);676 const err = new SyntaxError(message);677 678 err.index = pos;679 err.lineNumber = loc.line;680 err.column = loc.column + 1; // acorn uses 0-based columns681 throw err;682 }683 684 /**685 * Overwrites the default raise method to throw Esprima-style errors.686 * @param {int} pos The position of the error.687 * @param {string} message The error message.688 * @throws {SyntaxError} A syntax error.689 * @returns {void}690 */691 raiseRecoverable(pos, message) {692 this.raise(pos, message);693 }694 695 /**696 * Overwrites the default unexpected method to throw Esprima-style errors.697 * @param {int} pos The position of the error.698 * @throws {SyntaxError} A syntax error.699 * @returns {void}700 */701 unexpected(pos) {702 let message = "Unexpected token";703 704 if (pos !== null && pos !== void 0) {705 this.pos = pos;706 707 if (this.options.locations) {708 while (this.pos < this.lineStart) {709 this.lineStart = this.input.lastIndexOf("\n", this.lineStart - 2) + 1;710 --this.curLine;711 }712 }713 714 this.nextToken();715 }716 717 if (this.end > this.start) {718 message += ` ${this.input.slice(this.start, this.end)}`;719 }720 721 this.raise(this.start, message);722 }723 724 /*725 * Esprima-FB represents JSX strings as tokens called "JSXText", but Acorn-JSX726 * uses regular tt.string without any distinction between this and regular JS727 * strings. As such, we intercept an attempt to read a JSX string and set a flag728 * on extra so that when tokens are converted, the next token will be switched729 * to JSXText via onToken.730 */731 jsx_readString(quote) { // eslint-disable-line camelcase -- required by API732 const result = super.jsx_readString(quote);733 734 if (this.type === tokTypes.string) {735 this[STATE].jsxAttrValueToken = true;736 }737 return result;738 }739 740 /**741 * Performs last-minute Esprima-specific compatibility checks and fixes.742 * @param {ASTNode} result The node to check.743 * @returns {ASTNode} The finished node.744 */745 [ESPRIMA_FINISH_NODE](result) {746 747 // Acorn doesn't count the opening and closing backticks as part of templates748 // so we have to adjust ranges/locations appropriately.749 if (result.type === "TemplateElement") {750 751 // save template element references to fix start/end later752 this[STATE].templateElements.push(result);753 }754 755 if (result.type.includes("Function") && !result.generator) {756 result.generator = false;757 }758 759 return result;760 }761 };762};763 764const version$1 = "10.4.0";765 766/**767 * @fileoverview Main Espree file that converts Acorn into Esprima output.768 *769 * This file contains code from the following MIT-licensed projects:770 * 1. Acorn771 * 2. Babylon772 * 3. Babel-ESLint773 *774 * This file also contains code from Esprima, which is BSD licensed.775 *776 * Acorn is Copyright 2012-2015 Acorn Contributors (https://github.com/marijnh/acorn/blob/master/AUTHORS)777 * Babylon is Copyright 2014-2015 various contributors (https://github.com/babel/babel/blob/master/packages/babylon/AUTHORS)778 * Babel-ESLint is Copyright 2014-2015 Sebastian McKenzie <sebmck@gmail.com>779 *780 * Redistribution and use in source and binary forms, with or without781 * modification, are permitted provided that the following conditions are met:782 *783 * * Redistributions of source code must retain the above copyright784 * notice, this list of conditions and the following disclaimer.785 * * Redistributions in binary form must reproduce the above copyright786 * notice, this list of conditions and the following disclaimer in the787 * documentation and/or other materials provided with the distribution.788 *789 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"790 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE791 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE792 * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY793 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES794 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;795 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND796 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT797 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF798 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.799 *800 * Esprima is Copyright (c) jQuery Foundation, Inc. and Contributors, All Rights Reserved.801 *802 * Redistribution and use in source and binary forms, with or without803 * modification, are permitted provided that the following conditions are met:804 *805 * * Redistributions of source code must retain the above copyright806 * notice, this list of conditions and the following disclaimer.807 * * Redistributions in binary form must reproduce the above copyright808 * notice, this list of conditions and the following disclaimer in the809 * documentation and/or other materials provided with the distribution.810 *811 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"812 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE813 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE814 * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY815 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES816 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;817 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND818 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT819 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF820 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.821 */822 823 824// To initialize lazily.825const parsers = {826 _regular: null,827 _jsx: null,828 829 get regular() {830 if (this._regular === null) {831 this._regular = acorn__namespace.Parser.extend(espree());832 }833 return this._regular;834 },835 836 get jsx() {837 if (this._jsx === null) {838 this._jsx = acorn__namespace.Parser.extend(jsx__default["default"](), espree());839 }840 return this._jsx;841 },842 843 get(options) {844 const useJsx = Boolean(845 options &&846 options.ecmaFeatures &&847 options.ecmaFeatures.jsx848 );849 850 return useJsx ? this.jsx : this.regular;851 }852};853 854//------------------------------------------------------------------------------855// Tokenizer856//------------------------------------------------------------------------------857 858/**859 * Tokenizes the given code.860 * @param {string} code The code to tokenize.861 * @param {Object} options Options defining how to tokenize.862 * @returns {Token[]} An array of tokens.863 * @throws {SyntaxError} If the input code is invalid.864 * @private865 */866function tokenize(code, options) {867 const Parser = parsers.get(options);868 869 // Ensure to collect tokens.870 if (!options || options.tokens !== true) {871 options = Object.assign({}, options, { tokens: true }); // eslint-disable-line no-param-reassign -- stylistic choice872 }873 874 return new Parser(options, code).tokenize();875}876 877//------------------------------------------------------------------------------878// Parser879//------------------------------------------------------------------------------880 881/**882 * Parses the given code.883 * @param {string} code The code to tokenize.884 * @param {Object} options Options defining how to tokenize.885 * @returns {ASTNode} The "Program" AST node.886 * @throws {SyntaxError} If the input code is invalid.887 */888function parse(code, options) {889 const Parser = parsers.get(options);890 891 return new Parser(options, code).parse();892}893 894//------------------------------------------------------------------------------895// Public896//------------------------------------------------------------------------------897 898const version = version$1;899const name = "espree";900 901/* istanbul ignore next */902const VisitorKeys = (function() {903 return visitorKeys__namespace.KEYS;904}());905 906// Derive node types from VisitorKeys907/* istanbul ignore next */908const Syntax = (function() {909 let key,910 types = {};911 912 if (typeof Object.create === "function") {913 types = Object.create(null);914 }915 916 for (key in VisitorKeys) {917 if (Object.hasOwn(VisitorKeys, key)) {918 types[key] = key;919 }920 }921 922 if (typeof Object.freeze === "function") {923 Object.freeze(types);924 }925 926 return types;927}());928 929const latestEcmaVersion = getLatestEcmaVersion();930 931const supportedEcmaVersions = getSupportedEcmaVersions();932 933exports.Syntax = Syntax;934exports.VisitorKeys = VisitorKeys;935exports.latestEcmaVersion = latestEcmaVersion;936exports.name = name;937exports.parse = parse;938exports.supportedEcmaVersions = supportedEcmaVersions;939exports.tokenize = tokenize;940exports.version = version;941 