astro-eslint-parser 0.7.0 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -19,6 +19,10 @@ declare class Context {
19
19
  line: number;
20
20
  column: number;
21
21
  };
22
+ getIndexFromLoc(loc: {
23
+ line: number;
24
+ column: number;
25
+ }): number;
22
26
  /**
23
27
  * Get the location information of the given indexes.
24
28
  */
@@ -336,7 +340,10 @@ declare class ParseError extends SyntaxError {
336
340
  /**
337
341
  * Initialize this ParseError instance.
338
342
  */
339
- constructor(message: string, offset: number, ctx: Context);
343
+ constructor(message: string, offset: number | {
344
+ line: number;
345
+ column: number;
346
+ }, ctx: Context);
340
347
  }
341
348
 
342
349
  /**
package/lib/index.js CHANGED
@@ -174,10 +174,16 @@ var import_types = require("@typescript-eslint/types");
174
174
  var ParseError = class extends SyntaxError {
175
175
  constructor(message, offset, ctx) {
176
176
  super(message);
177
- this.index = offset;
178
- const loc = ctx.getLocFromIndex(offset);
179
- this.lineNumber = loc.line;
180
- this.column = loc.column;
177
+ if (typeof offset === "number") {
178
+ this.index = offset;
179
+ const loc = ctx.getLocFromIndex(offset);
180
+ this.lineNumber = loc.line;
181
+ this.column = loc.column;
182
+ } else {
183
+ this.index = ctx.getIndexFromLoc(offset);
184
+ this.lineNumber = offset.line;
185
+ this.column = offset.column;
186
+ }
181
187
  this.originalAST = ctx.originalAST;
182
188
  }
183
189
  };
@@ -1088,6 +1094,9 @@ var Context = class {
1088
1094
  column: loc.column
1089
1095
  };
1090
1096
  }
1097
+ getIndexFromLoc(loc) {
1098
+ return this.locs.getIndexFromLoc(loc);
1099
+ }
1091
1100
  getLocations(start, end) {
1092
1101
  return {
1093
1102
  range: [start, end],
@@ -1209,9 +1218,11 @@ function sortedLastIndex(array, value) {
1209
1218
  var service = __toESM(require("astrojs-compiler-sync"));
1210
1219
  function parse2(code, ctx) {
1211
1220
  const result = service.parse(code, { position: true });
1212
- for (const { code: code2, text, location } of result.diagnostics || []) {
1213
- ctx.originalAST = result.ast;
1214
- throw new ParseError(`[${code2}]: ${text}`, location.length, ctx);
1221
+ for (const { code: code2, text, location, severity } of result.diagnostics || []) {
1222
+ if (severity === 1) {
1223
+ ctx.originalAST = result.ast;
1224
+ throw new ParseError(`${text} [${code2}]`, location, ctx);
1225
+ }
1215
1226
  }
1216
1227
  if (!result.ast.children) {
1217
1228
  result.ast.children = [];
package/lib/index.mjs CHANGED
@@ -145,10 +145,16 @@ import { AST_TOKEN_TYPES, AST_NODE_TYPES } from "@typescript-eslint/types";
145
145
  var ParseError = class extends SyntaxError {
146
146
  constructor(message, offset, ctx) {
147
147
  super(message);
148
- this.index = offset;
149
- const loc = ctx.getLocFromIndex(offset);
150
- this.lineNumber = loc.line;
151
- this.column = loc.column;
148
+ if (typeof offset === "number") {
149
+ this.index = offset;
150
+ const loc = ctx.getLocFromIndex(offset);
151
+ this.lineNumber = loc.line;
152
+ this.column = loc.column;
153
+ } else {
154
+ this.index = ctx.getIndexFromLoc(offset);
155
+ this.lineNumber = offset.line;
156
+ this.column = offset.column;
157
+ }
152
158
  this.originalAST = ctx.originalAST;
153
159
  }
154
160
  };
@@ -1059,6 +1065,9 @@ var Context = class {
1059
1065
  column: loc.column
1060
1066
  };
1061
1067
  }
1068
+ getIndexFromLoc(loc) {
1069
+ return this.locs.getIndexFromLoc(loc);
1070
+ }
1062
1071
  getLocations(start, end) {
1063
1072
  return {
1064
1073
  range: [start, end],
@@ -1180,9 +1189,11 @@ function sortedLastIndex(array, value) {
1180
1189
  import * as service from "astrojs-compiler-sync";
1181
1190
  function parse2(code, ctx) {
1182
1191
  const result = service.parse(code, { position: true });
1183
- for (const { code: code2, text, location } of result.diagnostics || []) {
1184
- ctx.originalAST = result.ast;
1185
- throw new ParseError(`[${code2}]: ${text}`, location.length, ctx);
1192
+ for (const { code: code2, text, location, severity } of result.diagnostics || []) {
1193
+ if (severity === 1) {
1194
+ ctx.originalAST = result.ast;
1195
+ throw new ParseError(`${text} [${code2}]`, location, ctx);
1196
+ }
1186
1197
  }
1187
1198
  if (!result.ast.children) {
1188
1199
  result.ast.children = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-eslint-parser",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "Astro component parser for ESLint",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.mjs",
@@ -79,7 +79,7 @@
79
79
  "eslint": "^8.15.0",
80
80
  "eslint-config-prettier": "^8.3.0",
81
81
  "eslint-formatter-codeframe": "^7.32.1",
82
- "eslint-plugin-astro": "^0.19.0",
82
+ "eslint-plugin-astro": "^0.20.0",
83
83
  "eslint-plugin-eslint-comments": "^3.2.0",
84
84
  "eslint-plugin-json-schema-validator": "^4.0.0",
85
85
  "eslint-plugin-jsonc": "^2.0.0",