astro-eslint-parser 0.9.2 → 0.9.3
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 +45 -45
- package/lib/index.js +109 -54
- package/lib/index.mjs +109 -54
- package/package.json +3 -3
package/lib/index.d.ts
CHANGED
|
@@ -174,7 +174,7 @@ interface AstroProgram extends Omit<TSESTree.Program, "type" | "body"> {
|
|
|
174
174
|
/** Node of Astro fragment */
|
|
175
175
|
interface AstroFragment extends BaseNode {
|
|
176
176
|
type: "AstroFragment";
|
|
177
|
-
children: AstroChild[];
|
|
177
|
+
children: (AstroChild | AstroDoctype)[];
|
|
178
178
|
parent?: AstroParentNode;
|
|
179
179
|
}
|
|
180
180
|
/** Node of Astro html comment */
|
|
@@ -212,78 +212,78 @@ type SourceLocation = TSESTree.SourceLocation;
|
|
|
212
212
|
type Range = TSESTree.Range;
|
|
213
213
|
type Position = TSESTree.Position;
|
|
214
214
|
|
|
215
|
-
type index_Comment = Comment;
|
|
216
|
-
type index_Token = Token;
|
|
217
|
-
type index_SourceLocation = SourceLocation;
|
|
218
|
-
type index_Range = Range;
|
|
219
|
-
type index_Position = Position;
|
|
220
|
-
type index_AstroNode = AstroNode;
|
|
221
215
|
type index_AstroChild = AstroChild;
|
|
222
|
-
type
|
|
223
|
-
type index_AstroProgram = AstroProgram;
|
|
216
|
+
type index_AstroDoctype = AstroDoctype;
|
|
224
217
|
type index_AstroFragment = AstroFragment;
|
|
225
218
|
type index_AstroHTMLComment = AstroHTMLComment;
|
|
226
|
-
type
|
|
219
|
+
type index_AstroNode = AstroNode;
|
|
220
|
+
type index_AstroParentNode = AstroParentNode;
|
|
221
|
+
type index_AstroProgram = AstroProgram;
|
|
222
|
+
type index_AstroRawText = AstroRawText;
|
|
227
223
|
type index_AstroShorthandAttribute = AstroShorthandAttribute;
|
|
228
224
|
type index_AstroTemplateLiteralAttribute = AstroTemplateLiteralAttribute;
|
|
229
|
-
type
|
|
230
|
-
type
|
|
225
|
+
type index_Comment = Comment;
|
|
226
|
+
type index_JSXAttribute = JSXAttribute;
|
|
231
227
|
type index_JSXChild = JSXChild;
|
|
232
|
-
type index_JSXParentNode = JSXParentNode;
|
|
233
|
-
type index_JSXElement = JSXElement;
|
|
234
|
-
type index_JSXFragment = JSXFragment;
|
|
235
|
-
type index_JSXOpeningElement = JSXOpeningElement;
|
|
236
228
|
type index_JSXClosingElement = JSXClosingElement;
|
|
237
229
|
type index_JSXClosingFragment = JSXClosingFragment;
|
|
238
|
-
type
|
|
239
|
-
type
|
|
240
|
-
type
|
|
241
|
-
type
|
|
230
|
+
type index_JSXElement = JSXElement;
|
|
231
|
+
type index_JSXEmptyExpression = JSXEmptyExpression;
|
|
232
|
+
type index_JSXExpression = JSXExpression;
|
|
233
|
+
type index_JSXExpressionContainer = JSXExpressionContainer;
|
|
234
|
+
type index_JSXFragment = JSXFragment;
|
|
242
235
|
type index_JSXIdentifier = JSXIdentifier;
|
|
243
236
|
type index_JSXMemberExpression = JSXMemberExpression;
|
|
244
237
|
type index_JSXNamespacedName = JSXNamespacedName;
|
|
245
|
-
type
|
|
246
|
-
type
|
|
238
|
+
type index_JSXNode = JSXNode;
|
|
239
|
+
type index_JSXOpeningElement = JSXOpeningElement;
|
|
240
|
+
type index_JSXOpeningFragment = JSXOpeningFragment;
|
|
241
|
+
type index_JSXParentNode = JSXParentNode;
|
|
242
|
+
type index_JSXSpreadAttribute = JSXSpreadAttribute;
|
|
247
243
|
type index_JSXSpreadChild = JSXSpreadChild;
|
|
248
|
-
type
|
|
244
|
+
type index_JSXTagNameExpression = JSXTagNameExpression;
|
|
249
245
|
type index_JSXText = JSXText;
|
|
246
|
+
type index_Position = Position;
|
|
247
|
+
type index_Range = Range;
|
|
248
|
+
type index_SourceLocation = SourceLocation;
|
|
249
|
+
type index_Token = Token;
|
|
250
250
|
declare namespace index {
|
|
251
251
|
export {
|
|
252
|
-
index_Comment as Comment,
|
|
253
|
-
index_Token as Token,
|
|
254
|
-
index_SourceLocation as SourceLocation,
|
|
255
|
-
index_Range as Range,
|
|
256
|
-
index_Position as Position,
|
|
257
|
-
index_AstroNode as AstroNode,
|
|
258
252
|
index_AstroChild as AstroChild,
|
|
259
|
-
|
|
260
|
-
index_AstroProgram as AstroProgram,
|
|
253
|
+
index_AstroDoctype as AstroDoctype,
|
|
261
254
|
index_AstroFragment as AstroFragment,
|
|
262
255
|
index_AstroHTMLComment as AstroHTMLComment,
|
|
263
|
-
|
|
256
|
+
index_AstroNode as AstroNode,
|
|
257
|
+
index_AstroParentNode as AstroParentNode,
|
|
258
|
+
index_AstroProgram as AstroProgram,
|
|
259
|
+
index_AstroRawText as AstroRawText,
|
|
264
260
|
index_AstroShorthandAttribute as AstroShorthandAttribute,
|
|
265
261
|
index_AstroTemplateLiteralAttribute as AstroTemplateLiteralAttribute,
|
|
266
|
-
|
|
267
|
-
|
|
262
|
+
index_Comment as Comment,
|
|
263
|
+
index_JSXAttribute as JSXAttribute,
|
|
268
264
|
index_JSXChild as JSXChild,
|
|
269
|
-
index_JSXParentNode as JSXParentNode,
|
|
270
|
-
index_JSXElement as JSXElement,
|
|
271
|
-
index_JSXFragment as JSXFragment,
|
|
272
|
-
index_JSXOpeningElement as JSXOpeningElement,
|
|
273
265
|
index_JSXClosingElement as JSXClosingElement,
|
|
274
266
|
index_JSXClosingFragment as JSXClosingFragment,
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
267
|
+
index_JSXElement as JSXElement,
|
|
268
|
+
index_JSXEmptyExpression as JSXEmptyExpression,
|
|
269
|
+
index_JSXExpression as JSXExpression,
|
|
270
|
+
index_JSXExpressionContainer as JSXExpressionContainer,
|
|
271
|
+
index_JSXFragment as JSXFragment,
|
|
279
272
|
index_JSXIdentifier as JSXIdentifier,
|
|
280
273
|
index_JSXMemberExpression as JSXMemberExpression,
|
|
281
274
|
index_JSXNamespacedName as JSXNamespacedName,
|
|
282
|
-
|
|
283
|
-
|
|
275
|
+
index_JSXNode as JSXNode,
|
|
276
|
+
index_JSXOpeningElement as JSXOpeningElement,
|
|
277
|
+
index_JSXOpeningFragment as JSXOpeningFragment,
|
|
278
|
+
index_JSXParentNode as JSXParentNode,
|
|
279
|
+
index_JSXSpreadAttribute as JSXSpreadAttribute,
|
|
284
280
|
index_JSXSpreadChild as JSXSpreadChild,
|
|
285
|
-
|
|
281
|
+
index_JSXTagNameExpression as JSXTagNameExpression,
|
|
286
282
|
index_JSXText as JSXText,
|
|
283
|
+
index_Position as Position,
|
|
284
|
+
index_Range as Range,
|
|
285
|
+
index_SourceLocation as SourceLocation,
|
|
286
|
+
index_Token as Token,
|
|
287
287
|
};
|
|
288
288
|
}
|
|
289
289
|
|
package/lib/index.js
CHANGED
|
@@ -875,60 +875,10 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
875
875
|
openRootFragment(start);
|
|
876
876
|
}
|
|
877
877
|
for (const attr of node.attributes) {
|
|
878
|
-
if (
|
|
879
|
-
const
|
|
880
|
-
if (
|
|
881
|
-
|
|
882
|
-
script.appendOriginal(start2 + colonIndex);
|
|
883
|
-
script.skipOriginalOffset(1);
|
|
884
|
-
script.appendVirtualScript(`_`);
|
|
885
|
-
script.restoreContext.addToken(import_types.AST_TOKEN_TYPES.JSXIdentifier, [
|
|
886
|
-
start2,
|
|
887
|
-
start2 + colonIndex
|
|
888
|
-
]);
|
|
889
|
-
script.restoreContext.addToken(import_types.AST_TOKEN_TYPES.Punctuator, [
|
|
890
|
-
start2 + colonIndex,
|
|
891
|
-
start2 + colonIndex + 1
|
|
892
|
-
]);
|
|
893
|
-
script.restoreContext.addToken(import_types.AST_TOKEN_TYPES.JSXIdentifier, [
|
|
894
|
-
start2 + colonIndex + 1,
|
|
895
|
-
start2 + attr.name.length
|
|
896
|
-
]);
|
|
897
|
-
script.restoreContext.addRestoreNodeProcess(
|
|
898
|
-
(scriptNode, context) => {
|
|
899
|
-
if (scriptNode.type === import_types.AST_NODE_TYPES.JSXAttribute && scriptNode.range[0] === start2) {
|
|
900
|
-
const baseNameNode = scriptNode.name;
|
|
901
|
-
const nsn = {
|
|
902
|
-
...baseNameNode,
|
|
903
|
-
type: import_types.AST_NODE_TYPES.JSXNamespacedName,
|
|
904
|
-
namespace: {
|
|
905
|
-
type: import_types.AST_NODE_TYPES.JSXIdentifier,
|
|
906
|
-
name: attr.name.slice(0, colonIndex),
|
|
907
|
-
...ctx.getLocations(
|
|
908
|
-
baseNameNode.range[0],
|
|
909
|
-
baseNameNode.range[0] + colonIndex
|
|
910
|
-
)
|
|
911
|
-
},
|
|
912
|
-
name: {
|
|
913
|
-
type: import_types.AST_NODE_TYPES.JSXIdentifier,
|
|
914
|
-
name: attr.name.slice(colonIndex + 1),
|
|
915
|
-
...ctx.getLocations(
|
|
916
|
-
baseNameNode.range[0] + colonIndex + 1,
|
|
917
|
-
baseNameNode.range[1]
|
|
918
|
-
)
|
|
919
|
-
}
|
|
920
|
-
};
|
|
921
|
-
scriptNode.name = nsn;
|
|
922
|
-
nsn.namespace.parent = nsn;
|
|
923
|
-
nsn.name.parent = nsn;
|
|
924
|
-
context.addRemoveToken(
|
|
925
|
-
(token) => token.range[0] === baseNameNode.range[0] && token.range[1] === baseNameNode.range[1]
|
|
926
|
-
);
|
|
927
|
-
return true;
|
|
928
|
-
}
|
|
929
|
-
return false;
|
|
930
|
-
}
|
|
931
|
-
);
|
|
878
|
+
if (attr.kind === "quoted" || attr.kind === "empty" || attr.kind === "expression" || attr.kind === "template-literal") {
|
|
879
|
+
const needPunctuatorsProcess = node.type === "component" || node.type === "fragment" ? /[.:@]/u.test(attr.name) : /[.@]/u.test(attr.name) || attr.name.startsWith(":");
|
|
880
|
+
if (needPunctuatorsProcess) {
|
|
881
|
+
processAttributePunctuators(attr);
|
|
932
882
|
}
|
|
933
883
|
}
|
|
934
884
|
if (attr.kind === "shorthand") {
|
|
@@ -1123,6 +1073,111 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1123
1073
|
}
|
|
1124
1074
|
script.appendOriginal(ctx.code.length);
|
|
1125
1075
|
return script;
|
|
1076
|
+
function processAttributePunctuators(attr) {
|
|
1077
|
+
const start = attr.position.start.offset;
|
|
1078
|
+
let targetIndex = start;
|
|
1079
|
+
let colonOffset;
|
|
1080
|
+
for (let index = 0; index < attr.name.length; index++) {
|
|
1081
|
+
const char = attr.name[index];
|
|
1082
|
+
if (char !== ":" && char !== "." && char !== "@") {
|
|
1083
|
+
continue;
|
|
1084
|
+
}
|
|
1085
|
+
if (index === 0) {
|
|
1086
|
+
targetIndex++;
|
|
1087
|
+
}
|
|
1088
|
+
const punctuatorIndex = start + index;
|
|
1089
|
+
script.appendOriginal(punctuatorIndex);
|
|
1090
|
+
script.skipOriginalOffset(1);
|
|
1091
|
+
script.appendVirtualScript(`_`);
|
|
1092
|
+
if (char === ":" && index !== 0 && colonOffset == null) {
|
|
1093
|
+
colonOffset = index;
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
if (colonOffset != null) {
|
|
1097
|
+
const punctuatorIndex = start + colonOffset;
|
|
1098
|
+
script.restoreContext.addToken(import_types.AST_TOKEN_TYPES.JSXIdentifier, [
|
|
1099
|
+
start,
|
|
1100
|
+
punctuatorIndex
|
|
1101
|
+
]);
|
|
1102
|
+
script.restoreContext.addToken(import_types.AST_TOKEN_TYPES.Punctuator, [
|
|
1103
|
+
punctuatorIndex,
|
|
1104
|
+
punctuatorIndex + 1
|
|
1105
|
+
]);
|
|
1106
|
+
script.restoreContext.addToken(import_types.AST_TOKEN_TYPES.JSXIdentifier, [
|
|
1107
|
+
punctuatorIndex + 1,
|
|
1108
|
+
start + attr.name.length
|
|
1109
|
+
]);
|
|
1110
|
+
} else {
|
|
1111
|
+
script.restoreContext.addToken(import_types.AST_TOKEN_TYPES.JSXIdentifier, [
|
|
1112
|
+
start,
|
|
1113
|
+
start + attr.name.length
|
|
1114
|
+
]);
|
|
1115
|
+
}
|
|
1116
|
+
script.restoreContext.addRestoreNodeProcess((scriptNode, context) => {
|
|
1117
|
+
if (scriptNode.type === import_types.AST_NODE_TYPES.JSXAttribute && scriptNode.range[0] === targetIndex) {
|
|
1118
|
+
const baseNameNode = scriptNode.name;
|
|
1119
|
+
if (colonOffset != null) {
|
|
1120
|
+
const nameNode = {
|
|
1121
|
+
...baseNameNode,
|
|
1122
|
+
type: import_types.AST_NODE_TYPES.JSXNamespacedName,
|
|
1123
|
+
namespace: {
|
|
1124
|
+
type: import_types.AST_NODE_TYPES.JSXIdentifier,
|
|
1125
|
+
name: attr.name.slice(0, colonOffset),
|
|
1126
|
+
...ctx.getLocations(
|
|
1127
|
+
baseNameNode.range[0],
|
|
1128
|
+
baseNameNode.range[0] + colonOffset
|
|
1129
|
+
)
|
|
1130
|
+
},
|
|
1131
|
+
name: {
|
|
1132
|
+
type: import_types.AST_NODE_TYPES.JSXIdentifier,
|
|
1133
|
+
name: attr.name.slice(colonOffset + 1),
|
|
1134
|
+
...ctx.getLocations(
|
|
1135
|
+
baseNameNode.range[0] + colonOffset + 1,
|
|
1136
|
+
baseNameNode.range[1]
|
|
1137
|
+
)
|
|
1138
|
+
}
|
|
1139
|
+
};
|
|
1140
|
+
scriptNode.name = nameNode;
|
|
1141
|
+
nameNode.namespace.parent = nameNode;
|
|
1142
|
+
nameNode.name.parent = nameNode;
|
|
1143
|
+
} else {
|
|
1144
|
+
if (baseNameNode.type === import_types.AST_NODE_TYPES.JSXIdentifier) {
|
|
1145
|
+
const nameNode = {
|
|
1146
|
+
...baseNameNode,
|
|
1147
|
+
name: attr.name
|
|
1148
|
+
};
|
|
1149
|
+
scriptNode.name = nameNode;
|
|
1150
|
+
} else {
|
|
1151
|
+
const nameNode = {
|
|
1152
|
+
...baseNameNode,
|
|
1153
|
+
namespace: {
|
|
1154
|
+
...baseNameNode.namespace,
|
|
1155
|
+
name: attr.name.slice(
|
|
1156
|
+
baseNameNode.namespace.range[0] - start,
|
|
1157
|
+
baseNameNode.namespace.range[1] - start
|
|
1158
|
+
)
|
|
1159
|
+
},
|
|
1160
|
+
name: {
|
|
1161
|
+
...baseNameNode.name,
|
|
1162
|
+
name: attr.name.slice(
|
|
1163
|
+
baseNameNode.name.range[0] - start,
|
|
1164
|
+
baseNameNode.name.range[1] - start
|
|
1165
|
+
)
|
|
1166
|
+
}
|
|
1167
|
+
};
|
|
1168
|
+
scriptNode.name = nameNode;
|
|
1169
|
+
nameNode.namespace.parent = nameNode;
|
|
1170
|
+
nameNode.name.parent = nameNode;
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
context.addRemoveToken(
|
|
1174
|
+
(token) => token.range[0] === baseNameNode.range[0] && token.range[1] === baseNameNode.range[1]
|
|
1175
|
+
);
|
|
1176
|
+
return true;
|
|
1177
|
+
}
|
|
1178
|
+
return false;
|
|
1179
|
+
});
|
|
1180
|
+
}
|
|
1126
1181
|
function generateUniqueId(base) {
|
|
1127
1182
|
let candidate = `$_${base.replace(/\W/g, "_")}${uniqueIdSeq++}`;
|
|
1128
1183
|
while (usedUniqueIds.has(candidate) || ctx.code.includes(candidate)) {
|
package/lib/index.mjs
CHANGED
|
@@ -846,60 +846,10 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
846
846
|
openRootFragment(start);
|
|
847
847
|
}
|
|
848
848
|
for (const attr of node.attributes) {
|
|
849
|
-
if (
|
|
850
|
-
const
|
|
851
|
-
if (
|
|
852
|
-
|
|
853
|
-
script.appendOriginal(start2 + colonIndex);
|
|
854
|
-
script.skipOriginalOffset(1);
|
|
855
|
-
script.appendVirtualScript(`_`);
|
|
856
|
-
script.restoreContext.addToken(AST_TOKEN_TYPES.JSXIdentifier, [
|
|
857
|
-
start2,
|
|
858
|
-
start2 + colonIndex
|
|
859
|
-
]);
|
|
860
|
-
script.restoreContext.addToken(AST_TOKEN_TYPES.Punctuator, [
|
|
861
|
-
start2 + colonIndex,
|
|
862
|
-
start2 + colonIndex + 1
|
|
863
|
-
]);
|
|
864
|
-
script.restoreContext.addToken(AST_TOKEN_TYPES.JSXIdentifier, [
|
|
865
|
-
start2 + colonIndex + 1,
|
|
866
|
-
start2 + attr.name.length
|
|
867
|
-
]);
|
|
868
|
-
script.restoreContext.addRestoreNodeProcess(
|
|
869
|
-
(scriptNode, context) => {
|
|
870
|
-
if (scriptNode.type === AST_NODE_TYPES.JSXAttribute && scriptNode.range[0] === start2) {
|
|
871
|
-
const baseNameNode = scriptNode.name;
|
|
872
|
-
const nsn = {
|
|
873
|
-
...baseNameNode,
|
|
874
|
-
type: AST_NODE_TYPES.JSXNamespacedName,
|
|
875
|
-
namespace: {
|
|
876
|
-
type: AST_NODE_TYPES.JSXIdentifier,
|
|
877
|
-
name: attr.name.slice(0, colonIndex),
|
|
878
|
-
...ctx.getLocations(
|
|
879
|
-
baseNameNode.range[0],
|
|
880
|
-
baseNameNode.range[0] + colonIndex
|
|
881
|
-
)
|
|
882
|
-
},
|
|
883
|
-
name: {
|
|
884
|
-
type: AST_NODE_TYPES.JSXIdentifier,
|
|
885
|
-
name: attr.name.slice(colonIndex + 1),
|
|
886
|
-
...ctx.getLocations(
|
|
887
|
-
baseNameNode.range[0] + colonIndex + 1,
|
|
888
|
-
baseNameNode.range[1]
|
|
889
|
-
)
|
|
890
|
-
}
|
|
891
|
-
};
|
|
892
|
-
scriptNode.name = nsn;
|
|
893
|
-
nsn.namespace.parent = nsn;
|
|
894
|
-
nsn.name.parent = nsn;
|
|
895
|
-
context.addRemoveToken(
|
|
896
|
-
(token) => token.range[0] === baseNameNode.range[0] && token.range[1] === baseNameNode.range[1]
|
|
897
|
-
);
|
|
898
|
-
return true;
|
|
899
|
-
}
|
|
900
|
-
return false;
|
|
901
|
-
}
|
|
902
|
-
);
|
|
849
|
+
if (attr.kind === "quoted" || attr.kind === "empty" || attr.kind === "expression" || attr.kind === "template-literal") {
|
|
850
|
+
const needPunctuatorsProcess = node.type === "component" || node.type === "fragment" ? /[.:@]/u.test(attr.name) : /[.@]/u.test(attr.name) || attr.name.startsWith(":");
|
|
851
|
+
if (needPunctuatorsProcess) {
|
|
852
|
+
processAttributePunctuators(attr);
|
|
903
853
|
}
|
|
904
854
|
}
|
|
905
855
|
if (attr.kind === "shorthand") {
|
|
@@ -1094,6 +1044,111 @@ function processTemplate(ctx, resultTemplate) {
|
|
|
1094
1044
|
}
|
|
1095
1045
|
script.appendOriginal(ctx.code.length);
|
|
1096
1046
|
return script;
|
|
1047
|
+
function processAttributePunctuators(attr) {
|
|
1048
|
+
const start = attr.position.start.offset;
|
|
1049
|
+
let targetIndex = start;
|
|
1050
|
+
let colonOffset;
|
|
1051
|
+
for (let index = 0; index < attr.name.length; index++) {
|
|
1052
|
+
const char = attr.name[index];
|
|
1053
|
+
if (char !== ":" && char !== "." && char !== "@") {
|
|
1054
|
+
continue;
|
|
1055
|
+
}
|
|
1056
|
+
if (index === 0) {
|
|
1057
|
+
targetIndex++;
|
|
1058
|
+
}
|
|
1059
|
+
const punctuatorIndex = start + index;
|
|
1060
|
+
script.appendOriginal(punctuatorIndex);
|
|
1061
|
+
script.skipOriginalOffset(1);
|
|
1062
|
+
script.appendVirtualScript(`_`);
|
|
1063
|
+
if (char === ":" && index !== 0 && colonOffset == null) {
|
|
1064
|
+
colonOffset = index;
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
if (colonOffset != null) {
|
|
1068
|
+
const punctuatorIndex = start + colonOffset;
|
|
1069
|
+
script.restoreContext.addToken(AST_TOKEN_TYPES.JSXIdentifier, [
|
|
1070
|
+
start,
|
|
1071
|
+
punctuatorIndex
|
|
1072
|
+
]);
|
|
1073
|
+
script.restoreContext.addToken(AST_TOKEN_TYPES.Punctuator, [
|
|
1074
|
+
punctuatorIndex,
|
|
1075
|
+
punctuatorIndex + 1
|
|
1076
|
+
]);
|
|
1077
|
+
script.restoreContext.addToken(AST_TOKEN_TYPES.JSXIdentifier, [
|
|
1078
|
+
punctuatorIndex + 1,
|
|
1079
|
+
start + attr.name.length
|
|
1080
|
+
]);
|
|
1081
|
+
} else {
|
|
1082
|
+
script.restoreContext.addToken(AST_TOKEN_TYPES.JSXIdentifier, [
|
|
1083
|
+
start,
|
|
1084
|
+
start + attr.name.length
|
|
1085
|
+
]);
|
|
1086
|
+
}
|
|
1087
|
+
script.restoreContext.addRestoreNodeProcess((scriptNode, context) => {
|
|
1088
|
+
if (scriptNode.type === AST_NODE_TYPES.JSXAttribute && scriptNode.range[0] === targetIndex) {
|
|
1089
|
+
const baseNameNode = scriptNode.name;
|
|
1090
|
+
if (colonOffset != null) {
|
|
1091
|
+
const nameNode = {
|
|
1092
|
+
...baseNameNode,
|
|
1093
|
+
type: AST_NODE_TYPES.JSXNamespacedName,
|
|
1094
|
+
namespace: {
|
|
1095
|
+
type: AST_NODE_TYPES.JSXIdentifier,
|
|
1096
|
+
name: attr.name.slice(0, colonOffset),
|
|
1097
|
+
...ctx.getLocations(
|
|
1098
|
+
baseNameNode.range[0],
|
|
1099
|
+
baseNameNode.range[0] + colonOffset
|
|
1100
|
+
)
|
|
1101
|
+
},
|
|
1102
|
+
name: {
|
|
1103
|
+
type: AST_NODE_TYPES.JSXIdentifier,
|
|
1104
|
+
name: attr.name.slice(colonOffset + 1),
|
|
1105
|
+
...ctx.getLocations(
|
|
1106
|
+
baseNameNode.range[0] + colonOffset + 1,
|
|
1107
|
+
baseNameNode.range[1]
|
|
1108
|
+
)
|
|
1109
|
+
}
|
|
1110
|
+
};
|
|
1111
|
+
scriptNode.name = nameNode;
|
|
1112
|
+
nameNode.namespace.parent = nameNode;
|
|
1113
|
+
nameNode.name.parent = nameNode;
|
|
1114
|
+
} else {
|
|
1115
|
+
if (baseNameNode.type === AST_NODE_TYPES.JSXIdentifier) {
|
|
1116
|
+
const nameNode = {
|
|
1117
|
+
...baseNameNode,
|
|
1118
|
+
name: attr.name
|
|
1119
|
+
};
|
|
1120
|
+
scriptNode.name = nameNode;
|
|
1121
|
+
} else {
|
|
1122
|
+
const nameNode = {
|
|
1123
|
+
...baseNameNode,
|
|
1124
|
+
namespace: {
|
|
1125
|
+
...baseNameNode.namespace,
|
|
1126
|
+
name: attr.name.slice(
|
|
1127
|
+
baseNameNode.namespace.range[0] - start,
|
|
1128
|
+
baseNameNode.namespace.range[1] - start
|
|
1129
|
+
)
|
|
1130
|
+
},
|
|
1131
|
+
name: {
|
|
1132
|
+
...baseNameNode.name,
|
|
1133
|
+
name: attr.name.slice(
|
|
1134
|
+
baseNameNode.name.range[0] - start,
|
|
1135
|
+
baseNameNode.name.range[1] - start
|
|
1136
|
+
)
|
|
1137
|
+
}
|
|
1138
|
+
};
|
|
1139
|
+
scriptNode.name = nameNode;
|
|
1140
|
+
nameNode.namespace.parent = nameNode;
|
|
1141
|
+
nameNode.name.parent = nameNode;
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
context.addRemoveToken(
|
|
1145
|
+
(token) => token.range[0] === baseNameNode.range[0] && token.range[1] === baseNameNode.range[1]
|
|
1146
|
+
);
|
|
1147
|
+
return true;
|
|
1148
|
+
}
|
|
1149
|
+
return false;
|
|
1150
|
+
});
|
|
1151
|
+
}
|
|
1097
1152
|
function generateUniqueId(base) {
|
|
1098
1153
|
let candidate = `$_${base.replace(/\W/g, "_")}${uniqueIdSeq++}`;
|
|
1099
1154
|
while (usedUniqueIds.has(candidate) || ctx.code.includes(candidate)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-eslint-parser",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
4
4
|
"description": "Astro component parser for ESLint",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/index.mjs",
|
|
@@ -68,8 +68,8 @@
|
|
|
68
68
|
"@types/mocha": "^10.0.0",
|
|
69
69
|
"@types/node": "^18.0.0",
|
|
70
70
|
"@types/semver": "^7.3.9",
|
|
71
|
-
"@typescript-eslint/eslint-plugin": "~5.
|
|
72
|
-
"@typescript-eslint/parser": "~5.
|
|
71
|
+
"@typescript-eslint/eslint-plugin": "~5.48.0",
|
|
72
|
+
"@typescript-eslint/parser": "~5.48.0",
|
|
73
73
|
"astro": "^1.6.1",
|
|
74
74
|
"astro-eslint-parser": ">=0.1.0",
|
|
75
75
|
"benchmark": "^2.1.4",
|