Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / vue-eslint-parser / index.js
index 18496b8bafdc9a0ce58f6a83ad368188a202f397..02c0cd69c1a3dccfed094e4d1486bddd8d47fc40 100644 (file)
@@ -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;