astro-eslint-parser 0.16.0 → 0.16.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 +4 -43
- package/lib/index.d.ts +4 -43
- package/lib/index.js +135 -47
- package/lib/index.mjs +139 -47
- package/package.json +13 -12
package/lib/index.d.mts
CHANGED
|
@@ -249,43 +249,7 @@ type index_Range = Range;
|
|
|
249
249
|
type index_SourceLocation = SourceLocation;
|
|
250
250
|
type index_Token = Token;
|
|
251
251
|
declare namespace index {
|
|
252
|
-
export {
|
|
253
|
-
index_AstroChild as AstroChild,
|
|
254
|
-
index_AstroDoctype as AstroDoctype,
|
|
255
|
-
index_AstroFragment as AstroFragment,
|
|
256
|
-
index_AstroHTMLComment as AstroHTMLComment,
|
|
257
|
-
index_AstroNode as AstroNode,
|
|
258
|
-
index_AstroParentNode as AstroParentNode,
|
|
259
|
-
index_AstroProgram as AstroProgram,
|
|
260
|
-
index_AstroRawText as AstroRawText,
|
|
261
|
-
index_AstroShorthandAttribute as AstroShorthandAttribute,
|
|
262
|
-
index_AstroTemplateLiteralAttribute as AstroTemplateLiteralAttribute,
|
|
263
|
-
index_Comment as Comment,
|
|
264
|
-
index_JSXAttribute as JSXAttribute,
|
|
265
|
-
index_JSXChild as JSXChild,
|
|
266
|
-
index_JSXClosingElement as JSXClosingElement,
|
|
267
|
-
index_JSXClosingFragment as JSXClosingFragment,
|
|
268
|
-
index_JSXElement as JSXElement,
|
|
269
|
-
index_JSXEmptyExpression as JSXEmptyExpression,
|
|
270
|
-
index_JSXExpression as JSXExpression,
|
|
271
|
-
index_JSXExpressionContainer as JSXExpressionContainer,
|
|
272
|
-
index_JSXFragment as JSXFragment,
|
|
273
|
-
index_JSXIdentifier as JSXIdentifier,
|
|
274
|
-
index_JSXMemberExpression as JSXMemberExpression,
|
|
275
|
-
index_JSXNamespacedName as JSXNamespacedName,
|
|
276
|
-
index_JSXNode as JSXNode,
|
|
277
|
-
index_JSXOpeningElement as JSXOpeningElement,
|
|
278
|
-
index_JSXOpeningFragment as JSXOpeningFragment,
|
|
279
|
-
index_JSXParentNode as JSXParentNode,
|
|
280
|
-
index_JSXSpreadAttribute as JSXSpreadAttribute,
|
|
281
|
-
index_JSXSpreadChild as JSXSpreadChild,
|
|
282
|
-
index_JSXTagNameExpression as JSXTagNameExpression,
|
|
283
|
-
index_JSXText as JSXText,
|
|
284
|
-
index_Position as Position,
|
|
285
|
-
index_Range as Range,
|
|
286
|
-
index_SourceLocation as SourceLocation,
|
|
287
|
-
index_Token as Token,
|
|
288
|
-
};
|
|
252
|
+
export type { index_AstroChild as AstroChild, index_AstroDoctype as AstroDoctype, index_AstroFragment as AstroFragment, index_AstroHTMLComment as AstroHTMLComment, index_AstroNode as AstroNode, index_AstroParentNode as AstroParentNode, index_AstroProgram as AstroProgram, index_AstroRawText as AstroRawText, index_AstroShorthandAttribute as AstroShorthandAttribute, index_AstroTemplateLiteralAttribute as AstroTemplateLiteralAttribute, index_Comment as Comment, index_JSXAttribute as JSXAttribute, index_JSXChild as JSXChild, index_JSXClosingElement as JSXClosingElement, index_JSXClosingFragment as JSXClosingFragment, index_JSXElement as JSXElement, index_JSXEmptyExpression as JSXEmptyExpression, index_JSXExpression as JSXExpression, index_JSXExpressionContainer as JSXExpressionContainer, index_JSXFragment as JSXFragment, index_JSXIdentifier as JSXIdentifier, index_JSXMemberExpression as JSXMemberExpression, index_JSXNamespacedName as JSXNamespacedName, index_JSXNode as JSXNode, index_JSXOpeningElement as JSXOpeningElement, index_JSXOpeningFragment as JSXOpeningFragment, index_JSXParentNode as JSXParentNode, index_JSXSpreadAttribute as JSXSpreadAttribute, index_JSXSpreadChild as JSXSpreadChild, index_JSXTagNameExpression as JSXTagNameExpression, index_JSXText as JSXText, index_Position as Position, index_Range as Range, index_SourceLocation as SourceLocation, index_Token as Token };
|
|
289
253
|
}
|
|
290
254
|
|
|
291
255
|
/**
|
|
@@ -350,15 +314,12 @@ declare class ParseError extends SyntaxError {
|
|
|
350
314
|
}
|
|
351
315
|
|
|
352
316
|
var name = "astro-eslint-parser";
|
|
353
|
-
var version = "0.16.
|
|
317
|
+
var version = "0.16.2";
|
|
354
318
|
|
|
355
319
|
declare const meta_name: typeof name;
|
|
356
320
|
declare const meta_version: typeof version;
|
|
357
321
|
declare namespace meta {
|
|
358
|
-
export {
|
|
359
|
-
meta_name as name,
|
|
360
|
-
meta_version as version,
|
|
361
|
-
};
|
|
322
|
+
export { meta_name as name, meta_version as version };
|
|
362
323
|
}
|
|
363
324
|
|
|
364
325
|
/**
|
|
@@ -367,4 +328,4 @@ declare namespace meta {
|
|
|
367
328
|
declare function parseForESLint(code: string, options?: any): ReturnType<typeof parseForESLint$1>;
|
|
368
329
|
declare const VisitorKeys: eslint.SourceCode.VisitorKeys;
|
|
369
330
|
|
|
370
|
-
export { index as AST, ParseError, ParseTemplateResult, VisitorKeys, meta, name, parseForESLint, parseTemplate, traverseNodes };
|
|
331
|
+
export { index as AST, ParseError, type ParseTemplateResult, VisitorKeys, meta, name, parseForESLint, parseTemplate, traverseNodes };
|
package/lib/index.d.ts
CHANGED
|
@@ -249,43 +249,7 @@ type index_Range = Range;
|
|
|
249
249
|
type index_SourceLocation = SourceLocation;
|
|
250
250
|
type index_Token = Token;
|
|
251
251
|
declare namespace index {
|
|
252
|
-
export {
|
|
253
|
-
index_AstroChild as AstroChild,
|
|
254
|
-
index_AstroDoctype as AstroDoctype,
|
|
255
|
-
index_AstroFragment as AstroFragment,
|
|
256
|
-
index_AstroHTMLComment as AstroHTMLComment,
|
|
257
|
-
index_AstroNode as AstroNode,
|
|
258
|
-
index_AstroParentNode as AstroParentNode,
|
|
259
|
-
index_AstroProgram as AstroProgram,
|
|
260
|
-
index_AstroRawText as AstroRawText,
|
|
261
|
-
index_AstroShorthandAttribute as AstroShorthandAttribute,
|
|
262
|
-
index_AstroTemplateLiteralAttribute as AstroTemplateLiteralAttribute,
|
|
263
|
-
index_Comment as Comment,
|
|
264
|
-
index_JSXAttribute as JSXAttribute,
|
|
265
|
-
index_JSXChild as JSXChild,
|
|
266
|
-
index_JSXClosingElement as JSXClosingElement,
|
|
267
|
-
index_JSXClosingFragment as JSXClosingFragment,
|
|
268
|
-
index_JSXElement as JSXElement,
|
|
269
|
-
index_JSXEmptyExpression as JSXEmptyExpression,
|
|
270
|
-
index_JSXExpression as JSXExpression,
|
|
271
|
-
index_JSXExpressionContainer as JSXExpressionContainer,
|
|
272
|
-
index_JSXFragment as JSXFragment,
|
|
273
|
-
index_JSXIdentifier as JSXIdentifier,
|
|
274
|
-
index_JSXMemberExpression as JSXMemberExpression,
|
|
275
|
-
index_JSXNamespacedName as JSXNamespacedName,
|
|
276
|
-
index_JSXNode as JSXNode,
|
|
277
|
-
index_JSXOpeningElement as JSXOpeningElement,
|
|
278
|
-
index_JSXOpeningFragment as JSXOpeningFragment,
|
|
279
|
-
index_JSXParentNode as JSXParentNode,
|
|
280
|
-
index_JSXSpreadAttribute as JSXSpreadAttribute,
|
|
281
|
-
index_JSXSpreadChild as JSXSpreadChild,
|
|
282
|
-
index_JSXTagNameExpression as JSXTagNameExpression,
|
|
283
|
-
index_JSXText as JSXText,
|
|
284
|
-
index_Position as Position,
|
|
285
|
-
index_Range as Range,
|
|
286
|
-
index_SourceLocation as SourceLocation,
|
|
287
|
-
index_Token as Token,
|
|
288
|
-
};
|
|
252
|
+
export type { index_AstroChild as AstroChild, index_AstroDoctype as AstroDoctype, index_AstroFragment as AstroFragment, index_AstroHTMLComment as AstroHTMLComment, index_AstroNode as AstroNode, index_AstroParentNode as AstroParentNode, index_AstroProgram as AstroProgram, index_AstroRawText as AstroRawText, index_AstroShorthandAttribute as AstroShorthandAttribute, index_AstroTemplateLiteralAttribute as AstroTemplateLiteralAttribute, index_Comment as Comment, index_JSXAttribute as JSXAttribute, index_JSXChild as JSXChild, index_JSXClosingElement as JSXClosingElement, index_JSXClosingFragment as JSXClosingFragment, index_JSXElement as JSXElement, index_JSXEmptyExpression as JSXEmptyExpression, index_JSXExpression as JSXExpression, index_JSXExpressionContainer as JSXExpressionContainer, index_JSXFragment as JSXFragment, index_JSXIdentifier as JSXIdentifier, index_JSXMemberExpression as JSXMemberExpression, index_JSXNamespacedName as JSXNamespacedName, index_JSXNode as JSXNode, index_JSXOpeningElement as JSXOpeningElement, index_JSXOpeningFragment as JSXOpeningFragment, index_JSXParentNode as JSXParentNode, index_JSXSpreadAttribute as JSXSpreadAttribute, index_JSXSpreadChild as JSXSpreadChild, index_JSXTagNameExpression as JSXTagNameExpression, index_JSXText as JSXText, index_Position as Position, index_Range as Range, index_SourceLocation as SourceLocation, index_Token as Token };
|
|
289
253
|
}
|
|
290
254
|
|
|
291
255
|
/**
|
|
@@ -350,15 +314,12 @@ declare class ParseError extends SyntaxError {
|
|
|
350
314
|
}
|
|
351
315
|
|
|
352
316
|
var name = "astro-eslint-parser";
|
|
353
|
-
var version = "0.16.
|
|
317
|
+
var version = "0.16.2";
|
|
354
318
|
|
|
355
319
|
declare const meta_name: typeof name;
|
|
356
320
|
declare const meta_version: typeof version;
|
|
357
321
|
declare namespace meta {
|
|
358
|
-
export {
|
|
359
|
-
meta_name as name,
|
|
360
|
-
meta_version as version,
|
|
361
|
-
};
|
|
322
|
+
export { meta_name as name, meta_version as version };
|
|
362
323
|
}
|
|
363
324
|
|
|
364
325
|
/**
|
|
@@ -367,4 +328,4 @@ declare namespace meta {
|
|
|
367
328
|
declare function parseForESLint(code: string, options?: any): ReturnType<typeof parseForESLint$1>;
|
|
368
329
|
declare const VisitorKeys: eslint.SourceCode.VisitorKeys;
|
|
369
330
|
|
|
370
|
-
export { index as AST, ParseError, ParseTemplateResult, VisitorKeys, meta, name, parseForESLint, parseTemplate, traverseNodes };
|
|
331
|
+
export { index as AST, ParseError, type ParseTemplateResult, VisitorKeys, meta, name, parseForESLint, parseTemplate, traverseNodes };
|
package/lib/index.js
CHANGED
|
@@ -496,6 +496,9 @@ function sort(tokens) {
|
|
|
496
496
|
// src/parser/process-template.ts
|
|
497
497
|
var import_types = require("@typescript-eslint/types");
|
|
498
498
|
|
|
499
|
+
// src/astro/index.ts
|
|
500
|
+
var import_decode = require("entities/lib/decode.js");
|
|
501
|
+
|
|
499
502
|
// src/errors.ts
|
|
500
503
|
var ParseError = class extends SyntaxError {
|
|
501
504
|
/**
|
|
@@ -575,7 +578,22 @@ function calcAttributeEndOffset(node, ctx) {
|
|
|
575
578
|
} else if (node.kind === "quoted") {
|
|
576
579
|
info = getTokenInfo(
|
|
577
580
|
ctx,
|
|
578
|
-
[
|
|
581
|
+
[
|
|
582
|
+
[
|
|
583
|
+
{
|
|
584
|
+
token: `"${node.value}"`,
|
|
585
|
+
htmlEntityDecode: true
|
|
586
|
+
},
|
|
587
|
+
{
|
|
588
|
+
token: `'${node.value}'`,
|
|
589
|
+
htmlEntityDecode: true
|
|
590
|
+
},
|
|
591
|
+
{
|
|
592
|
+
token: node.value,
|
|
593
|
+
htmlEntityDecode: true
|
|
594
|
+
}
|
|
595
|
+
]
|
|
596
|
+
],
|
|
579
597
|
calcAttributeValueStartOffset(node, ctx)
|
|
580
598
|
);
|
|
581
599
|
} else if (node.kind === "expression") {
|
|
@@ -616,7 +634,11 @@ function calcAttributeValueStartOffset(node, ctx) {
|
|
|
616
634
|
if (node.kind === "quoted") {
|
|
617
635
|
info = getTokenInfo(
|
|
618
636
|
ctx,
|
|
619
|
-
[
|
|
637
|
+
[
|
|
638
|
+
node.name,
|
|
639
|
+
"=",
|
|
640
|
+
[`"`, `'`, { token: node.value, htmlEntityDecode: true }]
|
|
641
|
+
],
|
|
620
642
|
node.position.start.offset
|
|
621
643
|
);
|
|
622
644
|
} else if (node.kind === "expression") {
|
|
@@ -766,7 +788,7 @@ function getTokenInfo(ctx, tokens, position) {
|
|
|
766
788
|
let lastMatch;
|
|
767
789
|
for (const t of tokens) {
|
|
768
790
|
const index = lastMatch ? lastMatch.index + lastMatch.match.length : position;
|
|
769
|
-
const m =
|
|
791
|
+
const m = Array.isArray(t) ? matchOfForMulti(t, index) : match(t, index);
|
|
770
792
|
if (m == null) {
|
|
771
793
|
throw new ParseError(
|
|
772
794
|
`Unknown token at ${index}, expected: ${JSON.stringify(
|
|
@@ -779,7 +801,8 @@ function getTokenInfo(ctx, tokens, position) {
|
|
|
779
801
|
lastMatch = m;
|
|
780
802
|
}
|
|
781
803
|
return lastMatch;
|
|
782
|
-
function
|
|
804
|
+
function match(token, position2) {
|
|
805
|
+
const search = typeof token === "string" ? token : token.token;
|
|
783
806
|
const index = search.trim() === search ? skipSpaces(ctx.code, position2) : position2;
|
|
784
807
|
if (ctx.code.startsWith(search, index)) {
|
|
785
808
|
return {
|
|
@@ -787,17 +810,66 @@ function getTokenInfo(ctx, tokens, position) {
|
|
|
787
810
|
index
|
|
788
811
|
};
|
|
789
812
|
}
|
|
813
|
+
if (typeof token !== "string") {
|
|
814
|
+
return matchWithHTMLEntity(token, index);
|
|
815
|
+
}
|
|
790
816
|
return null;
|
|
791
817
|
}
|
|
792
818
|
function matchOfForMulti(search, position2) {
|
|
793
819
|
for (const s of search) {
|
|
794
|
-
const m =
|
|
820
|
+
const m = match(s, position2);
|
|
795
821
|
if (m) {
|
|
796
822
|
return m;
|
|
797
823
|
}
|
|
798
824
|
}
|
|
799
825
|
return null;
|
|
800
826
|
}
|
|
827
|
+
function matchWithHTMLEntity(token, position2) {
|
|
828
|
+
const search = token.token;
|
|
829
|
+
let codeOffset = position2;
|
|
830
|
+
let searchOffset = 0;
|
|
831
|
+
while (searchOffset < search.length) {
|
|
832
|
+
const searchChar = search[searchOffset];
|
|
833
|
+
if (ctx.code[codeOffset] === searchChar) {
|
|
834
|
+
codeOffset++;
|
|
835
|
+
searchOffset++;
|
|
836
|
+
continue;
|
|
837
|
+
}
|
|
838
|
+
const entity = getHTMLEntity(codeOffset);
|
|
839
|
+
if (entity?.entity === searchChar) {
|
|
840
|
+
codeOffset += entity.length;
|
|
841
|
+
searchOffset++;
|
|
842
|
+
continue;
|
|
843
|
+
}
|
|
844
|
+
return null;
|
|
845
|
+
}
|
|
846
|
+
return {
|
|
847
|
+
match: ctx.code.slice(position2, codeOffset),
|
|
848
|
+
index: position2
|
|
849
|
+
};
|
|
850
|
+
function getHTMLEntity(position3) {
|
|
851
|
+
let codeOffset2 = position3;
|
|
852
|
+
if (ctx.code[codeOffset2++] !== "&")
|
|
853
|
+
return null;
|
|
854
|
+
let entity = "";
|
|
855
|
+
const entityDecoder = new import_decode.EntityDecoder(
|
|
856
|
+
import_decode.htmlDecodeTree,
|
|
857
|
+
(cp) => entity += String.fromCodePoint(cp)
|
|
858
|
+
);
|
|
859
|
+
entityDecoder.startEntity(import_decode.DecodingMode.Attribute);
|
|
860
|
+
const length = entityDecoder.write(ctx.code, codeOffset2);
|
|
861
|
+
if (length < 0) {
|
|
862
|
+
return null;
|
|
863
|
+
}
|
|
864
|
+
if (length === 0) {
|
|
865
|
+
return null;
|
|
866
|
+
}
|
|
867
|
+
return {
|
|
868
|
+
entity,
|
|
869
|
+
length
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
}
|
|
801
873
|
}
|
|
802
874
|
function skipSpaces(string, position) {
|
|
803
875
|
const re = /\s*/g;
|
|
@@ -894,6 +966,10 @@ var RestoreNodeProcessContext = class {
|
|
|
894
966
|
getParent(node) {
|
|
895
967
|
return this.nodeMap.get(node) || null;
|
|
896
968
|
}
|
|
969
|
+
findToken(startIndex) {
|
|
970
|
+
const tokens = this.result.ast.tokens || [];
|
|
971
|
+
return tokens.find((t) => t.range[0] === startIndex) || null;
|
|
972
|
+
}
|
|
897
973
|
};
|
|
898
974
|
var RestoreContext = class {
|
|
899
975
|
constructor(ctx) {
|
|
@@ -1201,7 +1277,31 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1201
1277
|
processAttributePunctuators(attr);
|
|
1202
1278
|
}
|
|
1203
1279
|
}
|
|
1204
|
-
if (attr.kind === "
|
|
1280
|
+
if (attr.kind === "quoted") {
|
|
1281
|
+
if (attr.raw && !attr.raw.startsWith('"') && !attr.raw.startsWith("'")) {
|
|
1282
|
+
const attrStart = attr.position.start.offset;
|
|
1283
|
+
const start2 = calcAttributeValueStartOffset(attr, ctx);
|
|
1284
|
+
const end = calcAttributeEndOffset(attr, ctx);
|
|
1285
|
+
script.appendOriginal(start2);
|
|
1286
|
+
script.appendVirtualScript('"');
|
|
1287
|
+
script.appendOriginal(end);
|
|
1288
|
+
script.appendVirtualScript('"');
|
|
1289
|
+
script.restoreContext.addRestoreNodeProcess(
|
|
1290
|
+
(scriptNode, context) => {
|
|
1291
|
+
if (scriptNode.type === import_types.AST_NODE_TYPES.JSXAttribute && scriptNode.range[0] === attrStart) {
|
|
1292
|
+
const attrNode = scriptNode;
|
|
1293
|
+
if (attrNode.value?.type === "Literal" && typeof attrNode.value.value === "string") {
|
|
1294
|
+
const raw = ctx.code.slice(start2, end);
|
|
1295
|
+
attrNode.value.raw = raw;
|
|
1296
|
+
context.findToken(start2).value = raw;
|
|
1297
|
+
return true;
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
return false;
|
|
1301
|
+
}
|
|
1302
|
+
);
|
|
1303
|
+
}
|
|
1304
|
+
} else if (attr.kind === "shorthand") {
|
|
1205
1305
|
const start2 = attr.position.start.offset;
|
|
1206
1306
|
script.appendOriginal(start2);
|
|
1207
1307
|
const jsxName = /[\s"'[\]{}]/u.test(attr.name) ? generateUniqueId(attr.name) : attr.name;
|
|
@@ -1437,54 +1537,42 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1437
1537
|
if (scriptNode.type === import_types.AST_NODE_TYPES.JSXAttribute && scriptNode.range[0] === targetIndex) {
|
|
1438
1538
|
const baseNameNode = scriptNode.name;
|
|
1439
1539
|
if (colonOffset != null) {
|
|
1440
|
-
const nameNode =
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
)
|
|
1458
|
-
}
|
|
1540
|
+
const nameNode = baseNameNode;
|
|
1541
|
+
nameNode.type = import_types.AST_NODE_TYPES.JSXNamespacedName;
|
|
1542
|
+
nameNode.namespace = {
|
|
1543
|
+
type: import_types.AST_NODE_TYPES.JSXIdentifier,
|
|
1544
|
+
name: attr.name.slice(0, colonOffset),
|
|
1545
|
+
...ctx.getLocations(
|
|
1546
|
+
baseNameNode.range[0],
|
|
1547
|
+
baseNameNode.range[0] + colonOffset
|
|
1548
|
+
)
|
|
1549
|
+
};
|
|
1550
|
+
nameNode.name = {
|
|
1551
|
+
type: import_types.AST_NODE_TYPES.JSXIdentifier,
|
|
1552
|
+
name: attr.name.slice(colonOffset + 1),
|
|
1553
|
+
...ctx.getLocations(
|
|
1554
|
+
baseNameNode.range[0] + colonOffset + 1,
|
|
1555
|
+
baseNameNode.range[1]
|
|
1556
|
+
)
|
|
1459
1557
|
};
|
|
1460
1558
|
scriptNode.name = nameNode;
|
|
1461
1559
|
nameNode.namespace.parent = nameNode;
|
|
1462
1560
|
nameNode.name.parent = nameNode;
|
|
1463
1561
|
} else {
|
|
1464
1562
|
if (baseNameNode.type === import_types.AST_NODE_TYPES.JSXIdentifier) {
|
|
1465
|
-
const nameNode =
|
|
1466
|
-
|
|
1467
|
-
name: attr.name
|
|
1468
|
-
};
|
|
1563
|
+
const nameNode = baseNameNode;
|
|
1564
|
+
nameNode.name = attr.name;
|
|
1469
1565
|
scriptNode.name = nameNode;
|
|
1470
1566
|
} else {
|
|
1471
|
-
const nameNode =
|
|
1472
|
-
|
|
1473
|
-
namespace
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
name: {
|
|
1481
|
-
...baseNameNode.name,
|
|
1482
|
-
name: attr.name.slice(
|
|
1483
|
-
baseNameNode.name.range[0] - start,
|
|
1484
|
-
baseNameNode.name.range[1] - start
|
|
1485
|
-
)
|
|
1486
|
-
}
|
|
1487
|
-
};
|
|
1567
|
+
const nameNode = baseNameNode;
|
|
1568
|
+
nameNode.namespace.name = attr.name.slice(
|
|
1569
|
+
baseNameNode.namespace.range[0] - start,
|
|
1570
|
+
baseNameNode.namespace.range[1] - start
|
|
1571
|
+
);
|
|
1572
|
+
nameNode.name.name = attr.name.slice(
|
|
1573
|
+
baseNameNode.name.range[0] - start,
|
|
1574
|
+
baseNameNode.name.range[1] - start
|
|
1575
|
+
);
|
|
1488
1576
|
scriptNode.name = nameNode;
|
|
1489
1577
|
nameNode.namespace.parent = nameNode;
|
|
1490
1578
|
nameNode.name.parent = nameNode;
|
|
@@ -2561,7 +2649,7 @@ __export(meta_exports, {
|
|
|
2561
2649
|
|
|
2562
2650
|
// package.json
|
|
2563
2651
|
var name = "astro-eslint-parser";
|
|
2564
|
-
var version = "0.16.
|
|
2652
|
+
var version = "0.16.2";
|
|
2565
2653
|
|
|
2566
2654
|
// src/index.ts
|
|
2567
2655
|
function parseForESLint2(code, options) {
|
package/lib/index.mjs
CHANGED
|
@@ -466,6 +466,13 @@ function sort(tokens) {
|
|
|
466
466
|
// src/parser/process-template.ts
|
|
467
467
|
import { AST_TOKEN_TYPES, AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
468
468
|
|
|
469
|
+
// src/astro/index.ts
|
|
470
|
+
import {
|
|
471
|
+
EntityDecoder,
|
|
472
|
+
DecodingMode,
|
|
473
|
+
htmlDecodeTree
|
|
474
|
+
} from "entities/lib/decode.js";
|
|
475
|
+
|
|
469
476
|
// src/errors.ts
|
|
470
477
|
var ParseError = class extends SyntaxError {
|
|
471
478
|
/**
|
|
@@ -545,7 +552,22 @@ function calcAttributeEndOffset(node, ctx) {
|
|
|
545
552
|
} else if (node.kind === "quoted") {
|
|
546
553
|
info = getTokenInfo(
|
|
547
554
|
ctx,
|
|
548
|
-
[
|
|
555
|
+
[
|
|
556
|
+
[
|
|
557
|
+
{
|
|
558
|
+
token: `"${node.value}"`,
|
|
559
|
+
htmlEntityDecode: true
|
|
560
|
+
},
|
|
561
|
+
{
|
|
562
|
+
token: `'${node.value}'`,
|
|
563
|
+
htmlEntityDecode: true
|
|
564
|
+
},
|
|
565
|
+
{
|
|
566
|
+
token: node.value,
|
|
567
|
+
htmlEntityDecode: true
|
|
568
|
+
}
|
|
569
|
+
]
|
|
570
|
+
],
|
|
549
571
|
calcAttributeValueStartOffset(node, ctx)
|
|
550
572
|
);
|
|
551
573
|
} else if (node.kind === "expression") {
|
|
@@ -586,7 +608,11 @@ function calcAttributeValueStartOffset(node, ctx) {
|
|
|
586
608
|
if (node.kind === "quoted") {
|
|
587
609
|
info = getTokenInfo(
|
|
588
610
|
ctx,
|
|
589
|
-
[
|
|
611
|
+
[
|
|
612
|
+
node.name,
|
|
613
|
+
"=",
|
|
614
|
+
[`"`, `'`, { token: node.value, htmlEntityDecode: true }]
|
|
615
|
+
],
|
|
590
616
|
node.position.start.offset
|
|
591
617
|
);
|
|
592
618
|
} else if (node.kind === "expression") {
|
|
@@ -736,7 +762,7 @@ function getTokenInfo(ctx, tokens, position) {
|
|
|
736
762
|
let lastMatch;
|
|
737
763
|
for (const t of tokens) {
|
|
738
764
|
const index = lastMatch ? lastMatch.index + lastMatch.match.length : position;
|
|
739
|
-
const m =
|
|
765
|
+
const m = Array.isArray(t) ? matchOfForMulti(t, index) : match(t, index);
|
|
740
766
|
if (m == null) {
|
|
741
767
|
throw new ParseError(
|
|
742
768
|
`Unknown token at ${index}, expected: ${JSON.stringify(
|
|
@@ -749,7 +775,8 @@ function getTokenInfo(ctx, tokens, position) {
|
|
|
749
775
|
lastMatch = m;
|
|
750
776
|
}
|
|
751
777
|
return lastMatch;
|
|
752
|
-
function
|
|
778
|
+
function match(token, position2) {
|
|
779
|
+
const search = typeof token === "string" ? token : token.token;
|
|
753
780
|
const index = search.trim() === search ? skipSpaces(ctx.code, position2) : position2;
|
|
754
781
|
if (ctx.code.startsWith(search, index)) {
|
|
755
782
|
return {
|
|
@@ -757,17 +784,66 @@ function getTokenInfo(ctx, tokens, position) {
|
|
|
757
784
|
index
|
|
758
785
|
};
|
|
759
786
|
}
|
|
787
|
+
if (typeof token !== "string") {
|
|
788
|
+
return matchWithHTMLEntity(token, index);
|
|
789
|
+
}
|
|
760
790
|
return null;
|
|
761
791
|
}
|
|
762
792
|
function matchOfForMulti(search, position2) {
|
|
763
793
|
for (const s of search) {
|
|
764
|
-
const m =
|
|
794
|
+
const m = match(s, position2);
|
|
765
795
|
if (m) {
|
|
766
796
|
return m;
|
|
767
797
|
}
|
|
768
798
|
}
|
|
769
799
|
return null;
|
|
770
800
|
}
|
|
801
|
+
function matchWithHTMLEntity(token, position2) {
|
|
802
|
+
const search = token.token;
|
|
803
|
+
let codeOffset = position2;
|
|
804
|
+
let searchOffset = 0;
|
|
805
|
+
while (searchOffset < search.length) {
|
|
806
|
+
const searchChar = search[searchOffset];
|
|
807
|
+
if (ctx.code[codeOffset] === searchChar) {
|
|
808
|
+
codeOffset++;
|
|
809
|
+
searchOffset++;
|
|
810
|
+
continue;
|
|
811
|
+
}
|
|
812
|
+
const entity = getHTMLEntity(codeOffset);
|
|
813
|
+
if (entity?.entity === searchChar) {
|
|
814
|
+
codeOffset += entity.length;
|
|
815
|
+
searchOffset++;
|
|
816
|
+
continue;
|
|
817
|
+
}
|
|
818
|
+
return null;
|
|
819
|
+
}
|
|
820
|
+
return {
|
|
821
|
+
match: ctx.code.slice(position2, codeOffset),
|
|
822
|
+
index: position2
|
|
823
|
+
};
|
|
824
|
+
function getHTMLEntity(position3) {
|
|
825
|
+
let codeOffset2 = position3;
|
|
826
|
+
if (ctx.code[codeOffset2++] !== "&")
|
|
827
|
+
return null;
|
|
828
|
+
let entity = "";
|
|
829
|
+
const entityDecoder = new EntityDecoder(
|
|
830
|
+
htmlDecodeTree,
|
|
831
|
+
(cp) => entity += String.fromCodePoint(cp)
|
|
832
|
+
);
|
|
833
|
+
entityDecoder.startEntity(DecodingMode.Attribute);
|
|
834
|
+
const length = entityDecoder.write(ctx.code, codeOffset2);
|
|
835
|
+
if (length < 0) {
|
|
836
|
+
return null;
|
|
837
|
+
}
|
|
838
|
+
if (length === 0) {
|
|
839
|
+
return null;
|
|
840
|
+
}
|
|
841
|
+
return {
|
|
842
|
+
entity,
|
|
843
|
+
length
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
}
|
|
771
847
|
}
|
|
772
848
|
function skipSpaces(string, position) {
|
|
773
849
|
const re = /\s*/g;
|
|
@@ -864,6 +940,10 @@ var RestoreNodeProcessContext = class {
|
|
|
864
940
|
getParent(node) {
|
|
865
941
|
return this.nodeMap.get(node) || null;
|
|
866
942
|
}
|
|
943
|
+
findToken(startIndex) {
|
|
944
|
+
const tokens = this.result.ast.tokens || [];
|
|
945
|
+
return tokens.find((t) => t.range[0] === startIndex) || null;
|
|
946
|
+
}
|
|
867
947
|
};
|
|
868
948
|
var RestoreContext = class {
|
|
869
949
|
constructor(ctx) {
|
|
@@ -1171,7 +1251,31 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1171
1251
|
processAttributePunctuators(attr);
|
|
1172
1252
|
}
|
|
1173
1253
|
}
|
|
1174
|
-
if (attr.kind === "
|
|
1254
|
+
if (attr.kind === "quoted") {
|
|
1255
|
+
if (attr.raw && !attr.raw.startsWith('"') && !attr.raw.startsWith("'")) {
|
|
1256
|
+
const attrStart = attr.position.start.offset;
|
|
1257
|
+
const start2 = calcAttributeValueStartOffset(attr, ctx);
|
|
1258
|
+
const end = calcAttributeEndOffset(attr, ctx);
|
|
1259
|
+
script.appendOriginal(start2);
|
|
1260
|
+
script.appendVirtualScript('"');
|
|
1261
|
+
script.appendOriginal(end);
|
|
1262
|
+
script.appendVirtualScript('"');
|
|
1263
|
+
script.restoreContext.addRestoreNodeProcess(
|
|
1264
|
+
(scriptNode, context) => {
|
|
1265
|
+
if (scriptNode.type === AST_NODE_TYPES.JSXAttribute && scriptNode.range[0] === attrStart) {
|
|
1266
|
+
const attrNode = scriptNode;
|
|
1267
|
+
if (attrNode.value?.type === "Literal" && typeof attrNode.value.value === "string") {
|
|
1268
|
+
const raw = ctx.code.slice(start2, end);
|
|
1269
|
+
attrNode.value.raw = raw;
|
|
1270
|
+
context.findToken(start2).value = raw;
|
|
1271
|
+
return true;
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
return false;
|
|
1275
|
+
}
|
|
1276
|
+
);
|
|
1277
|
+
}
|
|
1278
|
+
} else if (attr.kind === "shorthand") {
|
|
1175
1279
|
const start2 = attr.position.start.offset;
|
|
1176
1280
|
script.appendOriginal(start2);
|
|
1177
1281
|
const jsxName = /[\s"'[\]{}]/u.test(attr.name) ? generateUniqueId(attr.name) : attr.name;
|
|
@@ -1407,54 +1511,42 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1407
1511
|
if (scriptNode.type === AST_NODE_TYPES.JSXAttribute && scriptNode.range[0] === targetIndex) {
|
|
1408
1512
|
const baseNameNode = scriptNode.name;
|
|
1409
1513
|
if (colonOffset != null) {
|
|
1410
|
-
const nameNode =
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
)
|
|
1428
|
-
}
|
|
1514
|
+
const nameNode = baseNameNode;
|
|
1515
|
+
nameNode.type = AST_NODE_TYPES.JSXNamespacedName;
|
|
1516
|
+
nameNode.namespace = {
|
|
1517
|
+
type: AST_NODE_TYPES.JSXIdentifier,
|
|
1518
|
+
name: attr.name.slice(0, colonOffset),
|
|
1519
|
+
...ctx.getLocations(
|
|
1520
|
+
baseNameNode.range[0],
|
|
1521
|
+
baseNameNode.range[0] + colonOffset
|
|
1522
|
+
)
|
|
1523
|
+
};
|
|
1524
|
+
nameNode.name = {
|
|
1525
|
+
type: AST_NODE_TYPES.JSXIdentifier,
|
|
1526
|
+
name: attr.name.slice(colonOffset + 1),
|
|
1527
|
+
...ctx.getLocations(
|
|
1528
|
+
baseNameNode.range[0] + colonOffset + 1,
|
|
1529
|
+
baseNameNode.range[1]
|
|
1530
|
+
)
|
|
1429
1531
|
};
|
|
1430
1532
|
scriptNode.name = nameNode;
|
|
1431
1533
|
nameNode.namespace.parent = nameNode;
|
|
1432
1534
|
nameNode.name.parent = nameNode;
|
|
1433
1535
|
} else {
|
|
1434
1536
|
if (baseNameNode.type === AST_NODE_TYPES.JSXIdentifier) {
|
|
1435
|
-
const nameNode =
|
|
1436
|
-
|
|
1437
|
-
name: attr.name
|
|
1438
|
-
};
|
|
1537
|
+
const nameNode = baseNameNode;
|
|
1538
|
+
nameNode.name = attr.name;
|
|
1439
1539
|
scriptNode.name = nameNode;
|
|
1440
1540
|
} else {
|
|
1441
|
-
const nameNode =
|
|
1442
|
-
|
|
1443
|
-
namespace
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
name: {
|
|
1451
|
-
...baseNameNode.name,
|
|
1452
|
-
name: attr.name.slice(
|
|
1453
|
-
baseNameNode.name.range[0] - start,
|
|
1454
|
-
baseNameNode.name.range[1] - start
|
|
1455
|
-
)
|
|
1456
|
-
}
|
|
1457
|
-
};
|
|
1541
|
+
const nameNode = baseNameNode;
|
|
1542
|
+
nameNode.namespace.name = attr.name.slice(
|
|
1543
|
+
baseNameNode.namespace.range[0] - start,
|
|
1544
|
+
baseNameNode.namespace.range[1] - start
|
|
1545
|
+
);
|
|
1546
|
+
nameNode.name.name = attr.name.slice(
|
|
1547
|
+
baseNameNode.name.range[0] - start,
|
|
1548
|
+
baseNameNode.name.range[1] - start
|
|
1549
|
+
);
|
|
1458
1550
|
scriptNode.name = nameNode;
|
|
1459
1551
|
nameNode.namespace.parent = nameNode;
|
|
1460
1552
|
nameNode.name.parent = nameNode;
|
|
@@ -2534,7 +2626,7 @@ __export(meta_exports, {
|
|
|
2534
2626
|
|
|
2535
2627
|
// package.json
|
|
2536
2628
|
var name = "astro-eslint-parser";
|
|
2537
|
-
var version = "0.16.
|
|
2629
|
+
var version = "0.16.2";
|
|
2538
2630
|
|
|
2539
2631
|
// src/index.ts
|
|
2540
2632
|
function parseForESLint2(code, options) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-eslint-parser",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.2",
|
|
4
4
|
"description": "Astro component parser for ESLint",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/index.mjs",
|
|
@@ -53,12 +53,13 @@
|
|
|
53
53
|
"@typescript-eslint/types": "^5.0.0",
|
|
54
54
|
"astrojs-compiler-sync": "^0.3.0",
|
|
55
55
|
"debug": "^4.3.4",
|
|
56
|
+
"entities": "^4.5.0",
|
|
56
57
|
"eslint-visitor-keys": "^3.0.0",
|
|
57
58
|
"espree": "^9.0.0",
|
|
58
59
|
"semver": "^7.3.8"
|
|
59
60
|
},
|
|
60
61
|
"devDependencies": {
|
|
61
|
-
"@changesets/changelog-github": "^0.
|
|
62
|
+
"@changesets/changelog-github": "^0.5.0",
|
|
62
63
|
"@changesets/cli": "^2.24.2",
|
|
63
64
|
"@ota-meshi/eslint-plugin": "^0.15.0",
|
|
64
65
|
"@types/benchmark": "^2.1.1",
|
|
@@ -68,21 +69,21 @@
|
|
|
68
69
|
"@types/eslint-scope": "^3.7.0",
|
|
69
70
|
"@types/eslint-visitor-keys": "^1.0.0",
|
|
70
71
|
"@types/mocha": "^10.0.0",
|
|
71
|
-
"@types/node": "^
|
|
72
|
+
"@types/node": "^20.0.0",
|
|
72
73
|
"@types/semver": "^7.3.9",
|
|
73
|
-
"@typescript-eslint/eslint-plugin": "~6.
|
|
74
|
-
"@typescript-eslint/parser": "~6.
|
|
75
|
-
"astro": "^
|
|
74
|
+
"@typescript-eslint/eslint-plugin": "~6.19.0",
|
|
75
|
+
"@typescript-eslint/parser": "~6.19.0",
|
|
76
|
+
"astro": "^4.0.0",
|
|
76
77
|
"astro-eslint-parser": ">=0.1.0",
|
|
77
78
|
"benchmark": "^2.1.4",
|
|
78
|
-
"chai": "^
|
|
79
|
+
"chai": "^5.0.0",
|
|
79
80
|
"env-cmd": "^10.1.0",
|
|
80
81
|
"esbuild": "^0.19.0",
|
|
81
82
|
"esbuild-register": "^3.3.3",
|
|
82
83
|
"eslint": "^8.15.0",
|
|
83
84
|
"eslint-config-prettier": "^9.0.0",
|
|
84
85
|
"eslint-formatter-codeframe": "^7.32.1",
|
|
85
|
-
"eslint-plugin-astro": "^0.
|
|
86
|
+
"eslint-plugin-astro": "^0.31.0",
|
|
86
87
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
87
88
|
"eslint-plugin-json-schema-validator": "^4.0.0",
|
|
88
89
|
"eslint-plugin-jsonc": "^2.0.0",
|
|
@@ -91,7 +92,7 @@
|
|
|
91
92
|
"eslint-plugin-node-dependencies": "^0.11.0",
|
|
92
93
|
"eslint-plugin-prettier": "^5.0.0",
|
|
93
94
|
"eslint-plugin-react": "^7.29.4",
|
|
94
|
-
"eslint-plugin-regexp": "^
|
|
95
|
+
"eslint-plugin-regexp": "^2.0.0",
|
|
95
96
|
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
96
97
|
"eslint-plugin-svelte": "^2.0.0",
|
|
97
98
|
"estree-walker": "^3.0.0",
|
|
@@ -106,9 +107,9 @@
|
|
|
106
107
|
"prettier-plugin-svelte": "^3.0.0",
|
|
107
108
|
"string-replace-loader": "^3.0.3",
|
|
108
109
|
"svelte": "^4.0.0",
|
|
109
|
-
"tsup": "^
|
|
110
|
-
"typescript": "~5.
|
|
111
|
-
"typescript-eslint-parser-for-extra-files": "^0.
|
|
110
|
+
"tsup": "^8.0.0",
|
|
111
|
+
"typescript": "~5.3.0",
|
|
112
|
+
"typescript-eslint-parser-for-extra-files": "^0.6.0"
|
|
112
113
|
},
|
|
113
114
|
"publishConfig": {
|
|
114
115
|
"access": "public"
|