astro-eslint-parser 1.3.0 → 1.3.1
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 +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +67 -14
- package/lib/index.mjs +67 -14
- package/package.json +18 -18
package/lib/index.d.mts
CHANGED
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -2282,25 +2282,80 @@ function parse2(code, ctx) {
|
|
|
2282
2282
|
}
|
|
2283
2283
|
function adjustHTML(ast, htmlElement, ctx) {
|
|
2284
2284
|
const htmlEnd = ctx.code.indexOf("</html");
|
|
2285
|
-
if (htmlEnd
|
|
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
|
|
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(
|
|
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
|
+
if (Buffer.byteLength(code, "utf8") === code.length) {
|
|
2329
|
+
return (offset) => offset;
|
|
2330
|
+
}
|
|
2331
|
+
const byteOffsets = [0];
|
|
2332
|
+
const codeUnitOffsets = [0];
|
|
2333
|
+
for (let index = 0, byteOffset = 0; index < code.length; ) {
|
|
2334
|
+
const codePoint = code.codePointAt(index);
|
|
2335
|
+
index += codePoint > 65535 ? 2 : 1;
|
|
2336
|
+
byteOffset += getUTF8ByteLength(codePoint);
|
|
2337
|
+
byteOffsets.push(byteOffset);
|
|
2338
|
+
codeUnitOffsets.push(index);
|
|
2339
|
+
}
|
|
2340
|
+
return (offset) => {
|
|
2341
|
+
const index = sortedLastIndex(byteOffsets, (target) => target - offset) - 1;
|
|
2342
|
+
return codeUnitOffsets[Math.max(index, 0)];
|
|
2343
|
+
};
|
|
2344
|
+
}
|
|
2345
|
+
function getUTF8ByteLength(codePoint) {
|
|
2346
|
+
if (codePoint <= 127) {
|
|
2347
|
+
return 1;
|
|
2348
|
+
}
|
|
2349
|
+
if (codePoint <= 2047) {
|
|
2350
|
+
return 2;
|
|
2351
|
+
}
|
|
2352
|
+
if (codePoint <= 65535) {
|
|
2353
|
+
return 3;
|
|
2354
|
+
}
|
|
2355
|
+
return 4;
|
|
2356
|
+
}
|
|
2302
2357
|
}
|
|
2303
|
-
function adjustHTMLBody(ast, htmlElement, htmlEnd, hasTokenAfterHtmlEnd, bodyElement, ctx) {
|
|
2358
|
+
function adjustHTMLBody(ast, htmlElement, htmlEnd, hasTokenAfterHtmlEnd, bodyElement, ctx, isOffsetAfter) {
|
|
2304
2359
|
const bodyEnd = ctx.code.indexOf("</body");
|
|
2305
2360
|
if (bodyEnd == null) {
|
|
2306
2361
|
return;
|
|
@@ -2312,15 +2367,13 @@ function adjustHTMLBody(ast, htmlElement, htmlEnd, hasTokenAfterHtmlEnd, bodyEle
|
|
|
2312
2367
|
const children = [...bodyElement.children];
|
|
2313
2368
|
for (const child of children) {
|
|
2314
2369
|
const offset = child.position?.start.offset;
|
|
2315
|
-
if (offset != null) {
|
|
2316
|
-
if (
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
htmlElement.children.push(child);
|
|
2323
|
-
}
|
|
2370
|
+
if (offset != null && isOffsetAfter(offset, bodyEnd)) {
|
|
2371
|
+
if (hasTokenAfterHtmlEnd && isOffsetAfter(offset, htmlEnd)) {
|
|
2372
|
+
bodyElement.children.splice(bodyElement.children.indexOf(child), 1);
|
|
2373
|
+
ast.children.push(child);
|
|
2374
|
+
} else if (hasTokenAfter) {
|
|
2375
|
+
bodyElement.children.splice(bodyElement.children.indexOf(child), 1);
|
|
2376
|
+
htmlElement.children.push(child);
|
|
2324
2377
|
}
|
|
2325
2378
|
}
|
|
2326
2379
|
}
|
|
@@ -2874,7 +2927,7 @@ __export(meta_exports, {
|
|
|
2874
2927
|
|
|
2875
2928
|
// package.json
|
|
2876
2929
|
var name = "astro-eslint-parser";
|
|
2877
|
-
var version = "1.3.
|
|
2930
|
+
var version = "1.3.1";
|
|
2878
2931
|
|
|
2879
2932
|
// src/index.ts
|
|
2880
2933
|
function parseForESLint2(code, options) {
|
package/lib/index.mjs
CHANGED
|
@@ -2257,25 +2257,80 @@ function parse2(code, ctx) {
|
|
|
2257
2257
|
}
|
|
2258
2258
|
function adjustHTML(ast, htmlElement, ctx) {
|
|
2259
2259
|
const htmlEnd = ctx.code.indexOf("</html");
|
|
2260
|
-
if (htmlEnd
|
|
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
|
|
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(
|
|
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
|
+
if (Buffer.byteLength(code, "utf8") === code.length) {
|
|
2304
|
+
return (offset) => offset;
|
|
2305
|
+
}
|
|
2306
|
+
const byteOffsets = [0];
|
|
2307
|
+
const codeUnitOffsets = [0];
|
|
2308
|
+
for (let index = 0, byteOffset = 0; index < code.length; ) {
|
|
2309
|
+
const codePoint = code.codePointAt(index);
|
|
2310
|
+
index += codePoint > 65535 ? 2 : 1;
|
|
2311
|
+
byteOffset += getUTF8ByteLength(codePoint);
|
|
2312
|
+
byteOffsets.push(byteOffset);
|
|
2313
|
+
codeUnitOffsets.push(index);
|
|
2314
|
+
}
|
|
2315
|
+
return (offset) => {
|
|
2316
|
+
const index = sortedLastIndex(byteOffsets, (target) => target - offset) - 1;
|
|
2317
|
+
return codeUnitOffsets[Math.max(index, 0)];
|
|
2318
|
+
};
|
|
2319
|
+
}
|
|
2320
|
+
function getUTF8ByteLength(codePoint) {
|
|
2321
|
+
if (codePoint <= 127) {
|
|
2322
|
+
return 1;
|
|
2323
|
+
}
|
|
2324
|
+
if (codePoint <= 2047) {
|
|
2325
|
+
return 2;
|
|
2326
|
+
}
|
|
2327
|
+
if (codePoint <= 65535) {
|
|
2328
|
+
return 3;
|
|
2329
|
+
}
|
|
2330
|
+
return 4;
|
|
2331
|
+
}
|
|
2277
2332
|
}
|
|
2278
|
-
function adjustHTMLBody(ast, htmlElement, htmlEnd, hasTokenAfterHtmlEnd, bodyElement, ctx) {
|
|
2333
|
+
function adjustHTMLBody(ast, htmlElement, htmlEnd, hasTokenAfterHtmlEnd, bodyElement, ctx, isOffsetAfter) {
|
|
2279
2334
|
const bodyEnd = ctx.code.indexOf("</body");
|
|
2280
2335
|
if (bodyEnd == null) {
|
|
2281
2336
|
return;
|
|
@@ -2287,15 +2342,13 @@ function adjustHTMLBody(ast, htmlElement, htmlEnd, hasTokenAfterHtmlEnd, bodyEle
|
|
|
2287
2342
|
const children = [...bodyElement.children];
|
|
2288
2343
|
for (const child of children) {
|
|
2289
2344
|
const offset = child.position?.start.offset;
|
|
2290
|
-
if (offset != null) {
|
|
2291
|
-
if (
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
htmlElement.children.push(child);
|
|
2298
|
-
}
|
|
2345
|
+
if (offset != null && isOffsetAfter(offset, bodyEnd)) {
|
|
2346
|
+
if (hasTokenAfterHtmlEnd && isOffsetAfter(offset, htmlEnd)) {
|
|
2347
|
+
bodyElement.children.splice(bodyElement.children.indexOf(child), 1);
|
|
2348
|
+
ast.children.push(child);
|
|
2349
|
+
} else if (hasTokenAfter) {
|
|
2350
|
+
bodyElement.children.splice(bodyElement.children.indexOf(child), 1);
|
|
2351
|
+
htmlElement.children.push(child);
|
|
2299
2352
|
}
|
|
2300
2353
|
}
|
|
2301
2354
|
}
|
|
@@ -2849,7 +2902,7 @@ __export(meta_exports, {
|
|
|
2849
2902
|
|
|
2850
2903
|
// package.json
|
|
2851
2904
|
var name = "astro-eslint-parser";
|
|
2852
|
-
var version = "1.3.
|
|
2905
|
+
var version = "1.3.1";
|
|
2853
2906
|
|
|
2854
2907
|
// src/index.ts
|
|
2855
2908
|
function parseForESLint2(code, options) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-eslint-parser",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
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": "^
|
|
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.
|
|
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": "^
|
|
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": "^
|
|
82
|
+
"astro": "^6.0.0",
|
|
83
83
|
"astro-eslint-parser": ">=0.1.0",
|
|
84
84
|
"benchmark": "^2.1.4",
|
|
85
|
-
"chai": "^
|
|
86
|
-
"env-cmd": "^
|
|
87
|
-
"esbuild": "^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": "^
|
|
95
|
-
"eslint-plugin-json-schema-validator": "^
|
|
96
|
-
"eslint-plugin-jsonc": "^
|
|
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": "^
|
|
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": "^
|
|
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": "^
|
|
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": "^
|
|
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.
|
|
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
|
},
|