/** * @author Toru Nagashima * See LICENSE file in root directory for full license. */ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); //#region \0rolldown/runtime.js var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __exportAll = (all, no_symbols) => { let target = {}; for (var name in all) { __defProp(target, name, { get: all[name], enumerable: true }); } if (!no_symbols) { __defProp(target, Symbol.toStringTag, { value: "Module" }); } return target; }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) { key = keys[i]; if (!__hasOwnProp.call(to, key) && key !== except) { __defProp(to, key, { get: ((k) => from[k]).bind(null, key), enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } } } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod)); //#endregion let path = require("path"); path = __toESM(path); let eslint_visitor_keys = require("eslint-visitor-keys"); eslint_visitor_keys = __toESM(eslint_visitor_keys); let assert = require("assert"); assert = __toESM(assert); let debug = require("debug"); debug = __toESM(debug); let eslint_scope = require("eslint-scope"); eslint_scope = __toESM(eslint_scope); let semver = require("semver"); let module$1 = require("module"); let espree = require("espree"); espree = __toESM(espree); let events = require("events"); events = __toESM(events); let esquery = require("esquery"); esquery = __toESM(esquery); //#region src/ast/errors.ts /** * Check whether the given value has acorn style location information. * @param x The value to check. * @returns `true` if the value has acorn style location information. */ function isAcornStyleParseError(x) { return typeof x.message === "string" && typeof x.pos === "number" && typeof x.loc === "object" && x.loc !== null && typeof x.loc.line === "number" && typeof x.loc.column === "number"; } /** * Check whether the given value is probably a TSError. * @param x The value to check. * @returns `true` if the given value is probably a TSError. */ function isTSError(x) { return !(x instanceof ParseError) && typeof x.message === "string" && typeof x.index === "number" && typeof x.lineNumber === "number" && typeof x.column === "number" && x.name === "TSError"; } /** * HTML parse errors. */ var ParseError = class ParseError extends SyntaxError { code; index; lineNumber; column; /** * Create new parser error object. * @param code The error code. See also: https://html.spec.whatwg.org/multipage/parsing.html#parse-errors * @param offset The offset number of this error. * @param line The line number of this error. * @param column The column number of this error. */ static fromCode(code, offset, line, column) { return new ParseError(code, code, offset, line, column); } /** * Normalize the error object. * @param x The error object to normalize. */ static normalize(x) { if (isTSError(x)) return new ParseError(x.message, void 0, x.index, x.lineNumber, x.column); if (ParseError.isParseError(x)) return x; if (isAcornStyleParseError(x)) return new ParseError(x.message, void 0, x.pos, x.loc.line, x.loc.column); return null; } /** * Initialize this ParseError instance. * @param message The error message. * @param code The error code. See also: https://html.spec.whatwg.org/multipage/parsing.html#parse-errors * @param offset The offset number of this error. * @param line The line number of this error. * @param column The column number of this error. */ constructor(message, code, offset, line, column) { super(message); this.code = code; this.index = offset; this.lineNumber = line; this.column = column; } /** * Type guard for ParseError. * @param x The value to check. * @returns `true` if the value has `message`, `pos`, `loc` properties. */ static isParseError(x) { return x instanceof ParseError || typeof x.message === "string" && typeof x.index === "number" && typeof x.lineNumber === "number" && typeof x.column === "number"; } }; //#endregion //#region src/ast/nodes.ts /** * Constants of namespaces. * @see https://infra.spec.whatwg.org/#namespaces */ const NS = Object.freeze({ HTML: "http://www.w3.org/1999/xhtml", MathML: "http://www.w3.org/1998/Math/MathML", SVG: "http://www.w3.org/2000/svg", XLink: "http://www.w3.org/1999/xlink", XML: "http://www.w3.org/XML/1998/namespace", XMLNS: "http://www.w3.org/2000/xmlns/" }); //#endregion //#region src/ast/traverse.ts const KEYS = eslint_visitor_keys.unionWith({ VAttribute: ["key", "value"], VDirectiveKey: [ "name", "argument", "modifiers" ], VDocumentFragment: ["children"], VElement: [ "startTag", "children", "endTag" ], VEndTag: [], VExpressionContainer: ["expression"], VFilter: ["callee", "arguments"], VFilterSequenceExpression: ["expression", "filters"], VForExpression: ["left", "right"], VIdentifier: [], VLiteral: [], VOnExpression: ["body"], VSlotScopeExpression: ["params"], VStartTag: ["attributes"], VText: [], VGenericExpression: ["params"] }); /** * Check that the given key should be traversed or not. * @param key The key to check. * @param value The value of the key in the node. * @returns `true` if the key should be traversed. */ function fallbackKeysFilter(key, value = null) { return key !== "comments" && key !== "leadingComments" && key !== "loc" && key !== "parent" && key !== "range" && key !== "tokens" && key !== "trailingComments" && value !== null && typeof value === "object" && (typeof value.type === "string" || Array.isArray(value)); } /** * Get the keys of the given node to traverse it. * @param node The node to get. * @returns The keys to traverse. */ function getFallbackKeys(node) { return Object.keys(node).filter((key) => fallbackKeysFilter(key, node[key])); } /** * Check wheather a given value is a node. * @param x The value to check. * @returns `true` if the value is a node. */ function isNode(x) { return x !== null && typeof x === "object" && typeof x.type === "string"; } /** * Traverse the given node. * @param node The node to traverse. * @param parent The parent node. * @param visitor The node visitor. */ function traverse(node, parent, visitor) { let i = 0; let j = 0; visitor.enterNode(node, parent); const keys = (visitor.visitorKeys ?? KEYS)[node.type] ?? getFallbackKeys(node); for (i = 0; i < keys.length; ++i) { const child = node[keys[i]]; if (Array.isArray(child)) { for (j = 0; j < child.length; ++j) if (isNode(child[j])) traverse(child[j], node, visitor); } else if (isNode(child)) traverse(child, node, visitor); } visitor.leaveNode(node, parent); } /** * Traverse the given AST tree. * @param node Root node to traverse. * @param visitor Visitor. */ function traverseNodes(node, visitor) { traverse(node, null, visitor); } //#endregion //#region src/ast/index.ts var ast_exports = /* @__PURE__ */ __exportAll({ KEYS: () => KEYS, NS: () => NS, ParseError: () => ParseError, getFallbackKeys: () => getFallbackKeys, traverseNodes: () => traverseNodes }); //#endregion //#region src/utils/utils.ts /** * @see https://github.com/vuejs/vue-next/blob/48de8a42b7fed7a03f7f1ff5d53d6a704252cafe/packages/shared/src/index.ts#L109 */ function camelize(str) { return str.replace(/-(\w)/gu, (_, c) => c ? c.toUpperCase() : ""); } /** * A binary search implementation that finds the index at which `predicate` * stops returning `true` and starts returning `false` (consistently) when run * on the items of the array. It **assumes** that mapping the array via the * predicate results in the shape `[...true[], ...false[]]`. *For any other case * the result is unpredictable*. * * This is the base implementation of the `sortedIndex` functions which define * the predicate for the user, for common use-cases. * * It is similar to `findIndex`, but runs at O(logN), whereas the latter is * general purpose function which runs on any array and predicate, but runs at * O(N) time. * * MIT License | Copyright (c) 2018 remeda | https://remedajs.com/ * * The implementation is copied from remeda package: * https://github.com/remeda/remeda/blob/df5fe74841c07bc356bbaa2c89bc7ba0cafafd0a/packages/remeda/src/internal/binarySearchCutoffIndex.ts#L15 */ function binarySearchCutoffIndex(array, predicate) { let lowIndex = 0; let highIndex = array.length; while (lowIndex < highIndex) { const pivotIndex = lowIndex + highIndex >>> 1; const pivot = array[pivotIndex]; if (predicate(pivot, pivotIndex, array)) lowIndex = pivotIndex + 1; else highIndex = pivotIndex; } return highIndex; } /** * Find the insertion position (index) of an item in an array with items sorted * in ascending order; so that `splice(sortedIndex, 0, item)` would result in * maintaining the array's sort-ness. The array can contain duplicates. * If the item already exists in the array the index would be of the *last* * occurrence of the item. * * Runs in O(logN) time. * * @param item - The item to insert. * @returns Insertion index (In the range 0..data.length). * @signature * R.sortedLastIndex(item)(data) * @example * R.pipe(['a','a','b','c','c'], sortedLastIndex('c')) // => 5 * * MIT License | Copyright (c) 2018 remeda | https://remedajs.com/ * * The implementation is copied from remeda package: * https://github.com/remeda/remeda/blob/df5fe74841c07bc356bbaa2c89bc7ba0cafafd0a/packages/remeda/src/sortedLastIndex.ts#L51 */ function sortedLastIndex(array, item) { return binarySearchCutoffIndex(array, (pivot) => pivot <= item); } /** * Find the insertion position (index) of an item in an array with items sorted * in ascending order using a value function; so that * `splice(sortedIndex, 0, item)` would result in maintaining the arrays sort- * ness. The array can contain duplicates. * If the item already exists in the array the index would be of the *first* * occurrence of the item. * * Runs in O(logN) time. * * See also: * * `findIndex` - scans a possibly unsorted array in-order (linear search). * * `sortedIndex` - like this function, but doesn't take a callbackfn. * * `sortedLastIndexBy` - like this function, but finds the last suitable index. * * `sortedLastIndex` - like `sortedIndex`, but finds the last suitable index. * * `rankBy` - scans a possibly unsorted array in-order, returning the index based on a sorting criteria. * * @param data - The (ascending) sorted array. * @param item - The item to insert. * @param valueFunction - All comparisons would be performed on the result of * calling this function on each compared item. Preferably this function should * return a `number` or `string`. This function should be the same as the one * provided to sortBy to sort the array. The function is called exactly once on * each items that is compared against in the array, and once at the beginning * on `item`. When called on `item` the `index` argument is `undefined`. * @returns Insertion index (In the range 0..data.length). * @signature * R.sortedIndexBy(data, item, valueFunction) * @example * R.sortedIndexBy([{age:20},{age:22}],{age:21},prop('age')) // => 1 * * MIT License | Copyright (c) 2018 remeda | https://remedajs.com/ * * The implementation is copied from remeda package: * https://github.com/remeda/remeda/blob/df5fe74841c07bc356bbaa2c89bc7ba0cafafd0a/packages/remeda/src/sortedIndexBy.ts#L37 */ function sortedIndexBy(array, item, valueFunction) { const value = valueFunction(item, void 0, array); return binarySearchCutoffIndex(array, (pivot, index) => valueFunction(pivot, index, array) < value); } /** * Find the insertion position (index) of an item in an array with items sorted * in ascending order using a value function; so that * `splice(sortedIndex, 0, item)` would result in maintaining the arrays sort- * ness. The array can contain duplicates. * If the item already exists in the array the index would be of the *last* * occurrence of the item. * * Runs in O(logN) time. * * See also: * * `findIndex` - scans a possibly unsorted array in-order (linear search). * * `sortedLastIndex` - a simplified version of this function, without a callbackfn. * * `sortedIndexBy` - like this function, but returns the first suitable index. * * `sortedIndex` - like `sortedLastIndex` but without a callbackfn. * * `rankBy` - scans a possibly unsorted array in-order, returning the index based on a sorting criteria. * * @param data - The (ascending) sorted array. * @param item - The item to insert. * @param valueFunction - All comparisons would be performed on the result of * calling this function on each compared item. Preferably this function should * return a `number` or `string`. This function should be the same as the one * provided to sortBy to sort the array. The function is called exactly once on * each items that is compared against in the array, and once at the beginning * on `item`. When called on `item` the `index` argument is `undefined`. * @returns Insertion index (In the range 0..data.length). * @signature * R.sortedLastIndexBy(data, item, valueFunction) * @example * R.sortedLastIndexBy([{age:20},{age:22}],{age:21},prop('age')) // => 1 * * MIT License | Copyright (c) 2018 remeda | https://remedajs.com/ * * The implementation is copied from remeda package: * https://github.com/remeda/remeda/blob/df5fe74841c07bc356bbaa2c89bc7ba0cafafd0a/packages/remeda/src/sortedLastIndexBy.ts#L37 */ function sortedLastIndexBy(array, item, valueFunction) { const value = valueFunction(item, void 0, array); return binarySearchCutoffIndex(array, (pivot, index) => valueFunction(pivot, index, array) <= value); } /** * Creates a duplicate-free version of an array. * * This function takes an array and returns a new array containing only the unique values * from the original array, preserving the order of first occurrence. * * @template T - The type of elements in the array. * @param {T[]} arr - The array to process. * @returns {T[]} A new array with only unique values from the original array. * * @example * const array = [1, 2, 2, 3, 4, 4, 5]; * const result = uniq(array); * // result will be [1, 2, 3, 4, 5] * * MIT © Viva Republica, Inc. | https://es-toolkit.dev/ * * The implementation is copied from es-toolkit package: * https://github.com/toss/es-toolkit/blob/16709839f131269b84cdd96e9645df52648ccedf/src/array/uniq.ts#L16 */ function uniq(arr) { return Array.from(new Set(arr)); } /** * Returns the intersection of multiple arrays. * * This function takes multiple arrays and returns a new array containing the elements that are * present in all provided arrays. It effectively filters out any elements that are not found * in every array. * * @template T - The type of elements in the arrays. * @param {...(ArrayLike | null | undefined)} arrays - The arrays to compare. * @returns {T[]} A new array containing the elements that are present in all arrays. * * @example * const array1 = [1, 2, 3, 4, 5]; * const array2 = [3, 4, 5, 6, 7]; * const result = intersection(array1, array2); * // result will be [3, 4, 5] since these elements are in both arrays. * * MIT © Viva Republica, Inc. | https://es-toolkit.dev/ * * The implementation is copied from es-toolkit package: * https://github.com/toss/es-toolkit/blob/16709839f131269b84cdd96e9645df52648ccedf/src/compat/array/intersection.ts#L22 * https://github.com/toss/es-toolkit/blob/16709839f131269b84cdd96e9645df52648ccedf/src/array/intersection.ts#L19 */ function intersection(...arrays) { if (arrays.length === 0) return []; let result = uniq(arrays[0]); for (let i = 1; i < arrays.length; i++) { const array = arrays[i]; const secondSet = new Set(array); result = result.filter((item) => secondSet.has(item)); } return result; } /** * This function takes multiple arrays and returns a new array containing only the unique values * from all input arrays, preserving the order of their first occurrence. * * @template T - The type of elements in the arrays. * @param {Array | null | undefined>} arrays - The arrays to inspect. * @returns {T[]} Returns the new array of combined unique values. * * @example * // Returns [2, 1] * union([2], [1, 2]); * * @example * // Returns [2, 1, 3] * union([2], [1, 2], [2, 3]); * * @example * // Returns [1, 3, 2, [5], [4]] (does not deeply flatten nested arrays) * union([1, 3, 2], [1, [5]], [2, [4]]); * * @example * // Returns [0, 2, 1] (ignores non-array values like 3 and { '0': 1 }) * union([0], 3, { '0': 1 }, null, [2, 1]); * @example * // Returns [0, 'a', 2, 1] (treats array-like object { 0: 'a', length: 1 } as a valid array) * union([0], { 0: 'a', length: 1 }, [2, 1]); * * MIT © Viva Republica, Inc. | https://es-toolkit.dev/ * * The implementation is copied from es-toolkit package: * https://github.com/toss/es-toolkit/blob/16709839f131269b84cdd96e9645df52648ccedf/src/compat/array/union.ts#L61 * https://github.com/toss/es-toolkit/blob/16709839f131269b84cdd96e9645df52648ccedf/src/compat/array/flattenDepth.ts#L21 */ function union(...arrays) { return uniq(arrays.flat()); } //#endregion //#region src/common/lines-and-columns.ts /** * A class for getting lines and columns location. */ var LinesAndColumns = class { ltOffsets; /** * Initialize. * @param ltOffsets The list of the offset of line terminators. */ constructor(ltOffsets) { this.ltOffsets = ltOffsets; } /** * Calculate the location of the given index. * @param index The index to calculate their location. * @returns The location of the index. */ getLocFromIndex(index) { const line = sortedLastIndex(this.ltOffsets, index) + 1; return { line, column: index - (line === 1 ? 0 : this.ltOffsets[line - 2]) }; } createOffsetLocationCalculator(offset) { return { getFixOffset() { return offset; }, getLocFromIndex: this.getLocFromIndex.bind(this) }; } }; //#endregion //#region src/common/location-calculator.ts /** * @author Toru Nagashima * @copyright 2017 Toru Nagashima. All rights reserved. * See LICENSE file in root directory for full license. */ /** * Location calculators. * * HTML tokenizers remove several characters to handle HTML entities and line terminators. * Tokens have the processed text as their value, but tokens have offsets and locations in the original text. * This calculator calculates the original locations from the processed texts. * * This calculator will be used for: * * - Adjusts the locations of script ASTs. * - Creates expression containers in postprocess. */ var LocationCalculatorForHtml = class LocationCalculatorForHtml extends LinesAndColumns { gapOffsets; baseOffset; baseIndexOfGap; shiftOffset; /** * Initialize this calculator. * @param gapOffsets The list of the offset of removed characters in tokenization phase. * @param ltOffsets The list of the offset of line terminators. * @param baseOffset The base offset to calculate locations. * @param shiftOffset The shift offset to calculate locations. */ constructor(gapOffsets, ltOffsets, baseOffset, shiftOffset = 0) { super(ltOffsets); this.gapOffsets = gapOffsets; this.ltOffsets = ltOffsets; this.baseOffset = baseOffset ?? 0; this.baseIndexOfGap = this.baseOffset === 0 ? 0 : sortedLastIndex(gapOffsets, this.baseOffset); this.shiftOffset = shiftOffset; } /** * Get sub calculator which have the given base offset. * @param offset The base offset of new sub calculator. * @returns Sub calculator. */ getSubCalculatorAfter(offset) { return new LocationCalculatorForHtml(this.gapOffsets, this.ltOffsets, this.baseOffset + offset, this.shiftOffset); } /** * Get sub calculator that shifts the given offset. * @param offset The shift of new sub calculator. * @returns Sub calculator. */ getSubCalculatorShift(offset) { return new LocationCalculatorForHtml(this.gapOffsets, this.ltOffsets, this.baseOffset, this.shiftOffset + offset); } /** * Calculate gap at the given index. * @param index The index to calculate gap. */ _getGap(index) { const offsets = this.gapOffsets; let g0 = sortedLastIndex(offsets, index + this.baseOffset); let pos = index + this.baseOffset + g0 - this.baseIndexOfGap; while (g0 < offsets.length && offsets[g0] <= pos) { g0 += 1; pos += 1; } return g0 - this.baseIndexOfGap; } /** * Calculate the location of the given index. * @param index The index to calculate their location. * @returns The location of the index. */ getLocation(index) { return this.getLocFromIndex(this.getOffsetWithGap(index)); } /** * Calculate the offset of the given index. * @param index The index to calculate their location. * @returns The offset of the index. */ getOffsetWithGap(index) { return index + this.getFixOffset(index); } /** * Gets the fix location offset of the given offset with using the base offset of this calculator. * @param offset The offset to modify. */ getFixOffset(offset) { const shiftOffset = this.shiftOffset; const gap = this._getGap(offset + shiftOffset); return this.baseOffset + gap + shiftOffset; } }; //#endregion //#region src/common/debug.ts /** * @author Toru Nagashima * @copyright 2017 Toru Nagashima. All rights reserved. * See LICENSE file in root directory for full license. */ const debug$1 = (0, debug.default)("vue-eslint-parser"); //#endregion //#region src/common/ast-utils.ts /** * Check whether the node is a `