astro-eslint-parser 1.3.0 → 1.3.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.mts CHANGED
@@ -314,7 +314,7 @@ declare class ParseError extends SyntaxError {
314
314
  }
315
315
 
316
316
  var name = "astro-eslint-parser";
317
- var version = "1.3.0";
317
+ var version = "1.3.2";
318
318
 
319
319
  declare const meta_name: typeof name;
320
320
  declare const meta_version: typeof version;
package/lib/index.d.ts CHANGED
@@ -314,7 +314,7 @@ declare class ParseError extends SyntaxError {
314
314
  }
315
315
 
316
316
  var name = "astro-eslint-parser";
317
- var version = "1.3.0";
317
+ var version = "1.3.2";
318
318
 
319
319
  declare const meta_name: typeof name;
320
320
  declare const meta_version: typeof version;
package/lib/index.js CHANGED
@@ -2282,25 +2282,93 @@ function parse2(code, ctx) {
2282
2282
  }
2283
2283
  function adjustHTML(ast, htmlElement, ctx) {
2284
2284
  const htmlEnd = ctx.code.indexOf("</html");
2285
- if (htmlEnd == null) {
2285
+ if (htmlEnd < 0) {
2286
2286
  return;
2287
2287
  }
2288
+ const isOffsetAfter = buildComparableOffsetComparator(ctx.code);
2288
2289
  const hasTokenAfter = Boolean(ctx.code.slice(htmlEnd + 7).trim());
2289
2290
  const children = [...htmlElement.children];
2290
2291
  for (const child of children) {
2291
2292
  const offset = child.position?.start.offset;
2292
2293
  if (hasTokenAfter && offset != null) {
2293
- if (htmlEnd <= offset) {
2294
+ if (isOffsetAfter(offset, htmlEnd)) {
2294
2295
  htmlElement.children.splice(htmlElement.children.indexOf(child), 1);
2295
2296
  ast.children.push(child);
2296
2297
  }
2297
2298
  }
2298
2299
  if (child.type === "element" && child.name === "body") {
2299
- adjustHTMLBody(ast, htmlElement, htmlEnd, hasTokenAfter, child, ctx);
2300
+ adjustHTMLBody(
2301
+ ast,
2302
+ htmlElement,
2303
+ htmlEnd,
2304
+ hasTokenAfter,
2305
+ child,
2306
+ ctx,
2307
+ isOffsetAfter
2308
+ );
2300
2309
  }
2301
2310
  }
2311
+ function buildComparableOffsetComparator(code) {
2312
+ let remapOffset;
2313
+ const comparableOffsetCache = /* @__PURE__ */ new Map();
2314
+ return (offset, threshold) => {
2315
+ if (threshold > offset) {
2316
+ return false;
2317
+ }
2318
+ let comparableOffset = comparableOffsetCache.get(offset);
2319
+ if (comparableOffset == null) {
2320
+ remapOffset || (remapOffset = buildComparableOffsetRemapper(code));
2321
+ comparableOffset = remapOffset(offset);
2322
+ comparableOffsetCache.set(offset, comparableOffset);
2323
+ }
2324
+ return threshold <= comparableOffset;
2325
+ };
2326
+ }
2327
+ function buildComparableOffsetRemapper(code) {
2328
+ let byteOffsets, codeUnitOffsets;
2329
+ for (let index = 0, byteOffset = 0; index < code.length; ) {
2330
+ const codePoint = code.codePointAt(index);
2331
+ const codeUnitLength = codePoint > 65535 ? 2 : 1;
2332
+ const nextIndex = index + codeUnitLength;
2333
+ const nextByteOffset = byteOffset + getUTF8ByteLength(codePoint);
2334
+ if (byteOffsets) {
2335
+ byteOffsets.push(nextByteOffset);
2336
+ codeUnitOffsets.push(nextIndex);
2337
+ } else if (codePoint > 127) {
2338
+ byteOffsets = [0];
2339
+ codeUnitOffsets = [0];
2340
+ for (let asciiOffset = 1; asciiOffset <= index; asciiOffset++) {
2341
+ byteOffsets.push(asciiOffset);
2342
+ codeUnitOffsets.push(asciiOffset);
2343
+ }
2344
+ byteOffsets.push(nextByteOffset);
2345
+ codeUnitOffsets.push(nextIndex);
2346
+ }
2347
+ index = nextIndex;
2348
+ byteOffset = nextByteOffset;
2349
+ }
2350
+ if (!byteOffsets || !codeUnitOffsets) {
2351
+ return (offset) => offset;
2352
+ }
2353
+ return (offset) => {
2354
+ const index = sortedLastIndex(byteOffsets, (target) => target - offset) - 1;
2355
+ return codeUnitOffsets[Math.max(index, 0)];
2356
+ };
2357
+ }
2358
+ function getUTF8ByteLength(codePoint) {
2359
+ if (codePoint <= 127) {
2360
+ return 1;
2361
+ }
2362
+ if (codePoint <= 2047) {
2363
+ return 2;
2364
+ }
2365
+ if (codePoint <= 65535) {
2366
+ return 3;
2367
+ }
2368
+ return 4;
2369
+ }
2302
2370
  }
2303
- function adjustHTMLBody(ast, htmlElement, htmlEnd, hasTokenAfterHtmlEnd, bodyElement, ctx) {
2371
+ function adjustHTMLBody(ast, htmlElement, htmlEnd, hasTokenAfterHtmlEnd, bodyElement, ctx, isOffsetAfter) {
2304
2372
  const bodyEnd = ctx.code.indexOf("</body");
2305
2373
  if (bodyEnd == null) {
2306
2374
  return;
@@ -2312,15 +2380,13 @@ function adjustHTMLBody(ast, htmlElement, htmlEnd, hasTokenAfterHtmlEnd, bodyEle
2312
2380
  const children = [...bodyElement.children];
2313
2381
  for (const child of children) {
2314
2382
  const offset = child.position?.start.offset;
2315
- if (offset != null) {
2316
- if (bodyEnd <= offset) {
2317
- if (hasTokenAfterHtmlEnd && htmlEnd <= offset) {
2318
- bodyElement.children.splice(bodyElement.children.indexOf(child), 1);
2319
- ast.children.push(child);
2320
- } else if (hasTokenAfter) {
2321
- bodyElement.children.splice(bodyElement.children.indexOf(child), 1);
2322
- htmlElement.children.push(child);
2323
- }
2383
+ if (offset != null && isOffsetAfter(offset, bodyEnd)) {
2384
+ if (hasTokenAfterHtmlEnd && isOffsetAfter(offset, htmlEnd)) {
2385
+ bodyElement.children.splice(bodyElement.children.indexOf(child), 1);
2386
+ ast.children.push(child);
2387
+ } else if (hasTokenAfter) {
2388
+ bodyElement.children.splice(bodyElement.children.indexOf(child), 1);
2389
+ htmlElement.children.push(child);
2324
2390
  }
2325
2391
  }
2326
2392
  }
@@ -2874,7 +2940,7 @@ __export(meta_exports, {
2874
2940
 
2875
2941
  // package.json
2876
2942
  var name = "astro-eslint-parser";
2877
- var version = "1.3.0";
2943
+ var version = "1.3.2";
2878
2944
 
2879
2945
  // src/index.ts
2880
2946
  function parseForESLint2(code, options) {
package/lib/index.mjs CHANGED
@@ -2257,25 +2257,93 @@ function parse2(code, ctx) {
2257
2257
  }
2258
2258
  function adjustHTML(ast, htmlElement, ctx) {
2259
2259
  const htmlEnd = ctx.code.indexOf("</html");
2260
- if (htmlEnd == null) {
2260
+ if (htmlEnd < 0) {
2261
2261
  return;
2262
2262
  }
2263
+ const isOffsetAfter = buildComparableOffsetComparator(ctx.code);
2263
2264
  const hasTokenAfter = Boolean(ctx.code.slice(htmlEnd + 7).trim());
2264
2265
  const children = [...htmlElement.children];
2265
2266
  for (const child of children) {
2266
2267
  const offset = child.position?.start.offset;
2267
2268
  if (hasTokenAfter && offset != null) {
2268
- if (htmlEnd <= offset) {
2269
+ if (isOffsetAfter(offset, htmlEnd)) {
2269
2270
  htmlElement.children.splice(htmlElement.children.indexOf(child), 1);
2270
2271
  ast.children.push(child);
2271
2272
  }
2272
2273
  }
2273
2274
  if (child.type === "element" && child.name === "body") {
2274
- adjustHTMLBody(ast, htmlElement, htmlEnd, hasTokenAfter, child, ctx);
2275
+ adjustHTMLBody(
2276
+ ast,
2277
+ htmlElement,
2278
+ htmlEnd,
2279
+ hasTokenAfter,
2280
+ child,
2281
+ ctx,
2282
+ isOffsetAfter
2283
+ );
2275
2284
  }
2276
2285
  }
2286
+ function buildComparableOffsetComparator(code) {
2287
+ let remapOffset;
2288
+ const comparableOffsetCache = /* @__PURE__ */ new Map();
2289
+ return (offset, threshold) => {
2290
+ if (threshold > offset) {
2291
+ return false;
2292
+ }
2293
+ let comparableOffset = comparableOffsetCache.get(offset);
2294
+ if (comparableOffset == null) {
2295
+ remapOffset || (remapOffset = buildComparableOffsetRemapper(code));
2296
+ comparableOffset = remapOffset(offset);
2297
+ comparableOffsetCache.set(offset, comparableOffset);
2298
+ }
2299
+ return threshold <= comparableOffset;
2300
+ };
2301
+ }
2302
+ function buildComparableOffsetRemapper(code) {
2303
+ let byteOffsets, codeUnitOffsets;
2304
+ for (let index = 0, byteOffset = 0; index < code.length; ) {
2305
+ const codePoint = code.codePointAt(index);
2306
+ const codeUnitLength = codePoint > 65535 ? 2 : 1;
2307
+ const nextIndex = index + codeUnitLength;
2308
+ const nextByteOffset = byteOffset + getUTF8ByteLength(codePoint);
2309
+ if (byteOffsets) {
2310
+ byteOffsets.push(nextByteOffset);
2311
+ codeUnitOffsets.push(nextIndex);
2312
+ } else if (codePoint > 127) {
2313
+ byteOffsets = [0];
2314
+ codeUnitOffsets = [0];
2315
+ for (let asciiOffset = 1; asciiOffset <= index; asciiOffset++) {
2316
+ byteOffsets.push(asciiOffset);
2317
+ codeUnitOffsets.push(asciiOffset);
2318
+ }
2319
+ byteOffsets.push(nextByteOffset);
2320
+ codeUnitOffsets.push(nextIndex);
2321
+ }
2322
+ index = nextIndex;
2323
+ byteOffset = nextByteOffset;
2324
+ }
2325
+ if (!byteOffsets || !codeUnitOffsets) {
2326
+ return (offset) => offset;
2327
+ }
2328
+ return (offset) => {
2329
+ const index = sortedLastIndex(byteOffsets, (target) => target - offset) - 1;
2330
+ return codeUnitOffsets[Math.max(index, 0)];
2331
+ };
2332
+ }
2333
+ function getUTF8ByteLength(codePoint) {
2334
+ if (codePoint <= 127) {
2335
+ return 1;
2336
+ }
2337
+ if (codePoint <= 2047) {
2338
+ return 2;
2339
+ }
2340
+ if (codePoint <= 65535) {
2341
+ return 3;
2342
+ }
2343
+ return 4;
2344
+ }
2277
2345
  }
2278
- function adjustHTMLBody(ast, htmlElement, htmlEnd, hasTokenAfterHtmlEnd, bodyElement, ctx) {
2346
+ function adjustHTMLBody(ast, htmlElement, htmlEnd, hasTokenAfterHtmlEnd, bodyElement, ctx, isOffsetAfter) {
2279
2347
  const bodyEnd = ctx.code.indexOf("</body");
2280
2348
  if (bodyEnd == null) {
2281
2349
  return;
@@ -2287,15 +2355,13 @@ function adjustHTMLBody(ast, htmlElement, htmlEnd, hasTokenAfterHtmlEnd, bodyEle
2287
2355
  const children = [...bodyElement.children];
2288
2356
  for (const child of children) {
2289
2357
  const offset = child.position?.start.offset;
2290
- if (offset != null) {
2291
- if (bodyEnd <= offset) {
2292
- if (hasTokenAfterHtmlEnd && htmlEnd <= offset) {
2293
- bodyElement.children.splice(bodyElement.children.indexOf(child), 1);
2294
- ast.children.push(child);
2295
- } else if (hasTokenAfter) {
2296
- bodyElement.children.splice(bodyElement.children.indexOf(child), 1);
2297
- htmlElement.children.push(child);
2298
- }
2358
+ if (offset != null && isOffsetAfter(offset, bodyEnd)) {
2359
+ if (hasTokenAfterHtmlEnd && isOffsetAfter(offset, htmlEnd)) {
2360
+ bodyElement.children.splice(bodyElement.children.indexOf(child), 1);
2361
+ ast.children.push(child);
2362
+ } else if (hasTokenAfter) {
2363
+ bodyElement.children.splice(bodyElement.children.indexOf(child), 1);
2364
+ htmlElement.children.push(child);
2299
2365
  }
2300
2366
  }
2301
2367
  }
@@ -2849,7 +2915,7 @@ __export(meta_exports, {
2849
2915
 
2850
2916
  // package.json
2851
2917
  var name = "astro-eslint-parser";
2852
- var version = "1.3.0";
2918
+ var version = "1.3.2";
2853
2919
 
2854
2920
  // src/index.ts
2855
2921
  function parseForESLint2(code, options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-eslint-parser",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "Astro component parser for ESLint",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.mjs",
@@ -21,11 +21,11 @@
21
21
  "cover": "nyc --reporter=lcov npm run test",
22
22
  "debug": "npm run mocha -- \"tests/src/**/*.ts\" --reporter dot --timeout 60000",
23
23
  "preversion": "npm run lint && npm test",
24
- "update-fixtures": "env-cmd -e debug npm run ts -- ./tools/update-fixtures.ts",
24
+ "update-fixtures": "env-cmd -e debug -- npm run ts -- ./tools/update-fixtures.ts",
25
25
  "debug-parser": "npm run ts -- ./tools/parser-test.ts",
26
26
  "eslint-playground": "eslint tests/fixtures --ext .astro --config .eslintrc-for-playground.js --format codeframe",
27
27
  "benchmark": "npm run ts -- benchmark/index.ts",
28
- "ts": "env-cmd -e basic node -r esbuild-register",
28
+ "ts": "env-cmd -e basic -- node -r esbuild-register",
29
29
  "mocha": "npm run ts -- ./node_modules/mocha/bin/mocha.js",
30
30
  "prerelease": "npm run clean && npm run build",
31
31
  "release": "changeset publish"
@@ -53,7 +53,7 @@
53
53
  "@typescript-eslint/types": "^7.0.0 || ^8.0.0",
54
54
  "astrojs-compiler-sync": "^1.0.0",
55
55
  "debug": "^4.3.4",
56
- "entities": "^6.0.0",
56
+ "entities": "^7.0.0",
57
57
  "eslint-scope": "^8.0.1",
58
58
  "eslint-visitor-keys": "^4.0.0",
59
59
  "espree": "^10.0.0",
@@ -62,7 +62,7 @@
62
62
  "semver": "^7.3.8"
63
63
  },
64
64
  "devDependencies": {
65
- "@changesets/changelog-github": "^0.5.0",
65
+ "@changesets/changelog-github": "^0.6.0",
66
66
  "@changesets/cli": "^2.24.2",
67
67
  "@eslint-community/eslint-plugin-eslint-comments": "^4.3.0",
68
68
  "@ota-meshi/eslint-plugin": "^0.20.0",
@@ -74,48 +74,48 @@
74
74
  "@types/eslint-visitor-keys": "^3.0.0",
75
75
  "@types/is-glob": "^4.0.4",
76
76
  "@types/mocha": "^10.0.0",
77
- "@types/node": "^22.0.0",
77
+ "@types/node": "^24.0.0",
78
78
  "@types/semver": "^7.3.9",
79
79
  "@typescript-eslint/eslint-plugin": "^8.21.0",
80
80
  "@typescript-eslint/parser": "^8.21.0",
81
81
  "@typescript-eslint/typescript-estree": "^8.21.0",
82
- "astro": "^5.0.0",
82
+ "astro": "^6.0.0",
83
83
  "astro-eslint-parser": ">=0.1.0",
84
84
  "benchmark": "^2.1.4",
85
- "chai": "^5.0.0",
86
- "env-cmd": "^10.1.0",
87
- "esbuild": "^0.25.0",
85
+ "chai": "^6.0.0",
86
+ "env-cmd": "^11.0.0",
87
+ "esbuild": "^0.27.0",
88
88
  "esbuild-register": "^3.3.3",
89
89
  "eslint": "^9.19.0",
90
90
  "eslint-config-prettier": "^10.0.0",
91
91
  "eslint-formatter-codeframe": "^7.32.1",
92
92
  "eslint-plugin-astro": "^1.0.0",
93
93
  "eslint-plugin-eslint-comments": "^3.2.0",
94
- "eslint-plugin-jsdoc": "^50.6.3",
95
- "eslint-plugin-json-schema-validator": "^5.0.0",
96
- "eslint-plugin-jsonc": "^2.0.0",
94
+ "eslint-plugin-jsdoc": "^62.0.0",
95
+ "eslint-plugin-json-schema-validator": "^6.0.0",
96
+ "eslint-plugin-jsonc": "^3.0.0",
97
97
  "eslint-plugin-jsx-a11y": "^6.5.1",
98
98
  "eslint-plugin-n": "^17.0.0",
99
- "eslint-plugin-node-dependencies": "^1.0.0",
99
+ "eslint-plugin-node-dependencies": "^2.0.0",
100
100
  "eslint-plugin-prettier": "^5.0.0",
101
101
  "eslint-plugin-react": "^7.29.4",
102
- "eslint-plugin-regexp": "^2.0.0",
102
+ "eslint-plugin-regexp": "^3.0.0",
103
103
  "eslint-plugin-simple-import-sort": "^12.0.0",
104
104
  "eslint-plugin-svelte": "^3.0.0-0",
105
105
  "estree-walker": "^3.0.0",
106
- "globals": "^16.0.0",
106
+ "globals": "^17.0.0",
107
107
  "locate-character": "^3.0.0",
108
108
  "magic-string": "^0.30.0",
109
109
  "mocha": "^11.0.0",
110
110
  "mocha-chai-jest-snapshot": "^1.1.3",
111
- "nyc": "^17.0.0",
111
+ "nyc": "^18.0.0",
112
112
  "prettier": "^3.0.0",
113
113
  "prettier-plugin-astro": "^0.14.0",
114
114
  "prettier-plugin-svelte": "^3.0.0",
115
115
  "string-replace-loader": "^3.0.3",
116
116
  "svelte": "^5.19.3",
117
117
  "tsup": "^8.0.0",
118
- "typescript": "~5.8.0",
118
+ "typescript": "~5.9.0",
119
119
  "typescript-eslint": "^8.21.0",
120
120
  "typescript-eslint-parser-for-extra-files": "^0.9.0"
121
121
  },