X-Git-Url: https://git.josue.xyz/?p=dotfiles%2F.git;a=blobdiff_plain;f=.config%2Fcoc%2Fextensions%2Fnode_modules%2Fcoc-prettier%2Fnode_modules%2Fvue-eslint-parser%2Findex.js;h=02c0cd69c1a3dccfed094e4d1486bddd8d47fc40;hp=18496b8bafdc9a0ce58f6a83ad368188a202f397;hb=4d07c77cf4d78cab8639e13ddc3c22495e585b0b;hpb=b3950616b54221c40a7dab9099bda675007e5b6e diff --git a/.config/coc/extensions/node_modules/coc-prettier/node_modules/vue-eslint-parser/index.js b/.config/coc/extensions/node_modules/coc-prettier/node_modules/vue-eslint-parser/index.js index 18496b8b..02c0cd69 100644 --- a/.config/coc/extensions/node_modules/coc-prettier/node_modules/vue-eslint-parser/index.js +++ b/.config/coc/extensions/node_modules/coc-prettier/node_modules/vue-eslint-parser/index.js @@ -144,7 +144,7 @@ var index = /*#__PURE__*/Object.freeze({ }); class LocationCalculator { - constructor(gapOffsets, ltOffsets, baseOffset) { + constructor(gapOffsets, ltOffsets, baseOffset, shiftOffset = 0) { this.gapOffsets = gapOffsets; this.ltOffsets = ltOffsets; this.baseOffset = baseOffset || 0; @@ -152,9 +152,13 @@ class LocationCalculator { this.baseOffset === 0 ? 0 : sortedLastIndex(gapOffsets, this.baseOffset); + this.shiftOffset = shiftOffset; } getSubCalculatorAfter(offset) { - return new LocationCalculator(this.gapOffsets, this.ltOffsets, this.baseOffset + offset); + return new LocationCalculator(this.gapOffsets, this.ltOffsets, this.baseOffset + offset, this.shiftOffset); + } + getSubCalculatorShift(offset) { + return new LocationCalculator(this.gapOffsets, this.ltOffsets, this.baseOffset, this.shiftOffset + offset); } _getLocation(offset) { const line = sortedLastIndex(this.ltOffsets, offset) + 1; @@ -172,18 +176,23 @@ class LocationCalculator { return g0 - this.baseIndexOfGap; } getLocation(index) { - return this._getLocation(this.baseOffset + index); + return this._getLocation(this.baseOffset + index + this.shiftOffset); } getOffsetWithGap(index) { - return this.baseOffset + index + this._getGap(index); + const shiftOffset = this.shiftOffset; + return (this.baseOffset + + index + + shiftOffset + + this._getGap(index + shiftOffset)); } fixLocation(node) { + const shiftOffset = this.shiftOffset; const range = node.range; const loc = node.loc; - const gap0 = this._getGap(range[0]); - const gap1 = this._getGap(range[1]); - const d0 = this.baseOffset + Math.max(0, gap0); - const d1 = this.baseOffset + Math.max(0, gap1); + const gap0 = this._getGap(range[0] + shiftOffset); + const gap1 = this._getGap(range[1] + shiftOffset); + const d0 = this.baseOffset + Math.max(0, gap0) + shiftOffset; + const d1 = this.baseOffset + Math.max(0, gap1) + shiftOffset; if (d0 !== 0) { range[0] += d0; if (node.start != null) { @@ -201,8 +210,9 @@ class LocationCalculator { return node; } fixErrorLocation(error) { - const gap = this._getGap(error.index); - const diff = this.baseOffset + Math.max(0, gap); + const shiftOffset = this.shiftOffset; + const gap = this._getGap(error.index + shiftOffset); + const diff = this.baseOffset + Math.max(0, gap) + shiftOffset; error.index += diff; const loc = this._getLocation(error.index); error.lineNumber = loc.line; @@ -489,7 +499,7 @@ function splitFilters(exp) { function parseExpressionBody(code, locationCalculator, parserOptions, allowEmpty = false) { debug('[script] parse expression: "0(%s)"', code); try { - const ast = parseScriptFragment(`0(${code})`, locationCalculator.getSubCalculatorAfter(-2), parserOptions).ast; + const ast = parseScriptFragment(`0(${code})`, locationCalculator.getSubCalculatorShift(-2), parserOptions).ast; const tokens = ast.tokens || []; const comments = ast.comments || []; const references = analyzeExternalReferences(ast, parserOptions); @@ -534,7 +544,8 @@ function parseFilter(code, locationCalculator, parserOptions) { const argsCode = paren === -1 ? null : code.slice(paren); if (calleeCode.trim()) { const spaces = /^\s*/u.exec(calleeCode)[0]; - const { ast } = parseScriptFragment(`${spaces}"${calleeCode.trim()}"`, locationCalculator, parserOptions); + const subCalculator = locationCalculator.getSubCalculatorShift(spaces.length); + const { ast } = parseScriptFragment(`"${calleeCode.trim()}"`, subCalculator, parserOptions); const statement = ast.body[0]; const callee = statement.expression; if (callee.type !== "Literal") { @@ -553,10 +564,13 @@ function parseFilter(code, locationCalculator, parserOptions) { expression.callee = { type: "Identifier", parent: expression, - range: [callee.range[0], callee.range[1] - 2], + range: [ + callee.range[0], + subCalculator.getOffsetWithGap(calleeCode.trim().length), + ], loc: { start: callee.loc.start, - end: locationCalculator.getLocation(callee.range[1] - callee.range[0] - 1), + end: subCalculator.getLocation(calleeCode.trim().length), }, name: String(callee.value), }; @@ -571,7 +585,9 @@ function parseFilter(code, locationCalculator, parserOptions) { return throwEmptyError(locationCalculator, "a filter name"); } if (argsCode != null) { - const { ast } = parseScriptFragment(`0${argsCode}`, locationCalculator.getSubCalculatorAfter(paren - 1), parserOptions); + const { ast } = parseScriptFragment(`0${argsCode}`, locationCalculator + .getSubCalculatorAfter(paren) + .getSubCalculatorShift(-1), parserOptions); const statement = ast.body[0]; const callExpression = statement.expression; ast.tokens.shift(); @@ -683,7 +699,7 @@ function parseExpression(code, locationCalculator, parserOptions, { allowEmpty = range: [prevLoc, prevLoc + 1], loc: {}, })); - const retF = parseFilter(filterCode, locationCalculator.getSubCalculatorAfter(prevLoc + 1), parserOptions); + const retF = parseFilter(filterCode, locationCalculator.getSubCalculatorShift(prevLoc + 1), parserOptions); if (retF) { if (retF.expression) { ret.expression.filters.push(retF.expression); @@ -708,7 +724,7 @@ function parseVForExpression(code, locationCalculator, parserOptions) { } try { const replaced = processedCode !== code; - const ast = parseScriptFragment(`for(let ${processedCode});`, locationCalculator.getSubCalculatorAfter(-8), parserOptions).ast; + const ast = parseScriptFragment(`for(let ${processedCode});`, locationCalculator.getSubCalculatorShift(-8), parserOptions).ast; const tokens = ast.tokens || []; const comments = ast.comments || []; const scope = analyzeVariablesAndExternalReferences(ast, parserOptions); @@ -767,7 +783,7 @@ function parseVOnExpressionBody(code, locationCalculator, parserOptions) { throwEmptyError(locationCalculator, "statements"); } try { - const ast = parseScriptFragment(`void function($event){${code}}`, locationCalculator.getSubCalculatorAfter(-22), parserOptions).ast; + const ast = parseScriptFragment(`void function($event){${code}}`, locationCalculator.getSubCalculatorShift(-22), parserOptions).ast; const references = analyzeExternalReferences(ast, parserOptions); const outermostStatement = ast.body[0]; const functionDecl = outermostStatement.expression @@ -816,7 +832,7 @@ function parseSlotScopeExpression(code, locationCalculator, parserOptions) { throwEmptyError(locationCalculator, "an identifier or an array/object pattern"); } try { - const ast = parseScriptFragment(`void function(${code}) {}`, locationCalculator.getSubCalculatorAfter(-14), parserOptions).ast; + const ast = parseScriptFragment(`void function(${code}) {}`, locationCalculator.getSubCalculatorShift(-14), parserOptions).ast; const statement = ast.body[0]; const rawExpression = statement.expression; const functionDecl = rawExpression.argument;