astro-eslint-parser 0.5.1 → 0.6.0

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.
Files changed (58) hide show
  1. package/lib/index.d.ts +345 -9
  2. package/lib/index.js +1745 -42
  3. package/lib/index.mjs +1719 -0
  4. package/package.json +9 -7
  5. package/lib/ast/astro.d.ts +0 -49
  6. package/lib/ast/astro.js +0 -2
  7. package/lib/ast/base.d.ts +0 -6
  8. package/lib/ast/base.js +0 -2
  9. package/lib/ast/index.d.ts +0 -8
  10. package/lib/ast/index.js +0 -18
  11. package/lib/ast/jsx.d.ts +0 -91
  12. package/lib/ast/jsx.js +0 -2
  13. package/lib/astro/index.d.ts +0 -56
  14. package/lib/astro/index.js +0 -357
  15. package/lib/astro-tools/index.d.ts +0 -21
  16. package/lib/astro-tools/index.js +0 -26
  17. package/lib/context/index.d.ts +0 -55
  18. package/lib/context/index.js +0 -158
  19. package/lib/context/parser-options.d.ts +0 -8
  20. package/lib/context/parser-options.js +0 -77
  21. package/lib/context/resolve-parser/espree.d.ts +0 -6
  22. package/lib/context/resolve-parser/espree.js +0 -41
  23. package/lib/context/resolve-parser/index.d.ts +0 -7
  24. package/lib/context/resolve-parser/index.js +0 -34
  25. package/lib/context/resolve-parser/parser-object.d.ts +0 -33
  26. package/lib/context/resolve-parser/parser-object.js +0 -27
  27. package/lib/context/script.d.ts +0 -34
  28. package/lib/context/script.js +0 -178
  29. package/lib/debug.d.ts +0 -2
  30. package/lib/debug.js +0 -8
  31. package/lib/errors.d.ts +0 -14
  32. package/lib/errors.js +0 -20
  33. package/lib/parser/astro-parser/astrojs-compiler-service.d.ts +0 -5
  34. package/lib/parser/astro-parser/astrojs-compiler-service.js +0 -12
  35. package/lib/parser/astro-parser/astrojs-compiler-worker.d.ts +0 -1
  36. package/lib/parser/astro-parser/astrojs-compiler-worker.js +0 -11
  37. package/lib/parser/astro-parser/parse.d.ts +0 -6
  38. package/lib/parser/astro-parser/parse.js +0 -270
  39. package/lib/parser/index.d.ts +0 -21
  40. package/lib/parser/index.js +0 -72
  41. package/lib/parser/lru-cache.d.ts +0 -7
  42. package/lib/parser/lru-cache.js +0 -32
  43. package/lib/parser/process-template.d.ts +0 -7
  44. package/lib/parser/process-template.js +0 -390
  45. package/lib/parser/script.d.ts +0 -7
  46. package/lib/parser/script.js +0 -44
  47. package/lib/parser/sort.d.ts +0 -6
  48. package/lib/parser/sort.js +0 -15
  49. package/lib/parser/template.d.ts +0 -10
  50. package/lib/parser/template.js +0 -102
  51. package/lib/parser/ts-patch.d.ts +0 -8
  52. package/lib/parser/ts-patch.js +0 -65
  53. package/lib/traverse.d.ts +0 -27
  54. package/lib/traverse.js +0 -93
  55. package/lib/types.d.ts +0 -17
  56. package/lib/types.js +0 -2
  57. package/lib/visitor-keys.d.ts +0 -2
  58. package/lib/visitor-keys.js +0 -14
package/lib/index.js CHANGED
@@ -1,46 +1,1749 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+
26
+ // src/index.ts
27
+ var src_exports = {};
28
+ __export(src_exports, {
29
+ AST: () => ast_exports,
30
+ ParseError: () => ParseError,
31
+ VisitorKeys: () => VisitorKeys,
32
+ parseForESLint: () => parseForESLint2,
33
+ parseTemplate: () => parseTemplate2,
34
+ traverseNodes: () => traverseNodes
17
35
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.parseTemplate = exports.traverseNodes = exports.VisitorKeys = exports.parseForESLint = exports.ParseError = exports.AST = void 0;
27
- const parser_1 = require("./parser");
28
- const astro_tools_1 = require("./astro-tools");
29
- Object.defineProperty(exports, "parseTemplate", { enumerable: true, get: function () { return astro_tools_1.parseTemplate; } });
30
- const AST = __importStar(require("./ast"));
31
- exports.AST = AST;
32
- const traverse_1 = require("./traverse");
33
- Object.defineProperty(exports, "traverseNodes", { enumerable: true, get: function () { return traverse_1.traverseNodes; } });
34
- const visitor_keys_1 = require("./visitor-keys");
35
- const errors_1 = require("./errors");
36
- Object.defineProperty(exports, "ParseError", { enumerable: true, get: function () { return errors_1.ParseError; } });
37
- /**
38
- * Parse source code
39
- */
36
+ module.exports = __toCommonJS(src_exports);
37
+
38
+ // src/visitor-keys.ts
39
+ var import_eslint_visitor_keys = require("eslint-visitor-keys");
40
+ var astroKeys = {
41
+ Program: ["body"],
42
+ AstroFragment: ["children"],
43
+ AstroHTMLComment: [],
44
+ AstroDoctype: [],
45
+ AstroShorthandAttribute: ["name", "value"],
46
+ AstroTemplateLiteralAttribute: ["name", "value"],
47
+ AstroRawText: []
48
+ };
49
+ var KEYS = (0, import_eslint_visitor_keys.unionWith)(
50
+ astroKeys
51
+ );
52
+
53
+ // src/parser/index.ts
54
+ var import_types2 = require("@typescript-eslint/types");
55
+
56
+ // src/debug.ts
57
+ var import_debug = __toESM(require("debug"));
58
+ var debug = (0, import_debug.default)("astro-eslint-parser");
59
+
60
+ // src/parser/ts-patch.ts
61
+ var import_module = require("module");
62
+ var import_path = __toESM(require("path"));
63
+ var import_fs = __toESM(require("fs"));
64
+ function tsPatch(scriptParserOptions) {
65
+ let targetExt = ".astro";
66
+ if (scriptParserOptions.filePath) {
67
+ const ext = import_path.default.extname(scriptParserOptions.filePath);
68
+ if (ext) {
69
+ targetExt = ext;
70
+ }
71
+ }
72
+ try {
73
+ const cwd = process.cwd();
74
+ const relativeTo = import_path.default.join(cwd, "__placeholder__.js");
75
+ const ts = (0, import_module.createRequire)(relativeTo)("typescript");
76
+ const { ensureScriptKind, getScriptKindFromFileName } = ts;
77
+ if (typeof ensureScriptKind === "function" && typeof getScriptKindFromFileName === "function") {
78
+ ts.ensureScriptKind = function(fileName, ...args) {
79
+ if (fileName.endsWith(targetExt)) {
80
+ return ts.ScriptKind.TSX;
81
+ }
82
+ return ensureScriptKind.call(this, fileName, ...args);
83
+ };
84
+ ts.getScriptKindFromFileName = function(fileName, ...args) {
85
+ if (fileName.endsWith(targetExt)) {
86
+ return ts.ScriptKind.TSX;
87
+ }
88
+ return getScriptKindFromFileName.call(this, fileName, ...args);
89
+ };
90
+ return {
91
+ terminate() {
92
+ ts.ensureScriptKind = ensureScriptKind;
93
+ ts.getScriptKindFromFileName = getScriptKindFromFileName;
94
+ }
95
+ };
96
+ }
97
+ } catch {
98
+ }
99
+ const tsxFilePath = `${scriptParserOptions.filePath}.tsx`;
100
+ scriptParserOptions.filePath = tsxFilePath;
101
+ if (!import_fs.default.existsSync(tsxFilePath)) {
102
+ import_fs.default.writeFileSync(tsxFilePath, "/* temp for astro-eslint-parser */");
103
+ return {
104
+ terminate() {
105
+ import_fs.default.unlinkSync(tsxFilePath);
106
+ }
107
+ };
108
+ }
109
+ return null;
110
+ }
111
+
112
+ // src/context/resolve-parser/parser-object.ts
113
+ function isParserObject(value) {
114
+ return isEnhancedParserObject(value) || isBasicParserObject(value);
115
+ }
116
+ function isEnhancedParserObject(value) {
117
+ return Boolean(value && typeof value.parseForESLint === "function");
118
+ }
119
+ function isBasicParserObject(value) {
120
+ return Boolean(value && typeof value.parse === "function");
121
+ }
122
+ function maybeTSESLintParserObject(value) {
123
+ return isEnhancedParserObject(value) && isBasicParserObject(value) && typeof value.createProgram === "function" && typeof value.clearCaches === "function" && typeof value.version === "string";
124
+ }
125
+
126
+ // src/parser/script.ts
127
+ function parseScript(code, _ctx, parserOptions) {
128
+ const parser = parserOptions.getParser();
129
+ let patchResult;
130
+ try {
131
+ const scriptParserOptions = {
132
+ ...parserOptions.parserOptions
133
+ };
134
+ scriptParserOptions.ecmaFeatures = {
135
+ ...scriptParserOptions.ecmaFeatures || {},
136
+ jsx: true
137
+ };
138
+ if (parserOptions.isTypeScript() && scriptParserOptions.filePath && scriptParserOptions.project) {
139
+ patchResult = tsPatch(scriptParserOptions);
140
+ }
141
+ const result = isEnhancedParserObject(parser) ? parser.parseForESLint(code, scriptParserOptions) : parser.parse(code, scriptParserOptions);
142
+ if ("ast" in result && result.ast != null) {
143
+ return result;
144
+ }
145
+ return { ast: result };
146
+ } catch (e) {
147
+ debug(
148
+ "[script] parsing error:",
149
+ e.message,
150
+ `@ ${JSON.stringify(code)}
151
+
152
+ ${code}`
153
+ );
154
+ throw e;
155
+ } finally {
156
+ patchResult == null ? void 0 : patchResult.terminate();
157
+ }
158
+ }
159
+
160
+ // src/parser/sort.ts
161
+ function sort(tokens) {
162
+ return tokens.sort((a, b) => {
163
+ if (a.range[0] !== b.range[0]) {
164
+ return a.range[0] - b.range[0];
165
+ }
166
+ return a.range[1] - b.range[1];
167
+ });
168
+ }
169
+
170
+ // src/parser/process-template.ts
171
+ var import_types = require("@typescript-eslint/types");
172
+
173
+ // src/errors.ts
174
+ var ParseError = class extends SyntaxError {
175
+ constructor(message, offset, ctx) {
176
+ super(message);
177
+ this.index = offset;
178
+ const loc = ctx.getLocFromIndex(offset);
179
+ this.lineNumber = loc.line;
180
+ this.column = loc.column;
181
+ this.originalAST = ctx.originalAST;
182
+ }
183
+ };
184
+
185
+ // src/astro/index.ts
186
+ function isTag(node) {
187
+ return node.type === "element" || node.type === "custom-element" || node.type === "component" || node.type === "fragment";
188
+ }
189
+ function isParent(node) {
190
+ return Array.isArray(node.children);
191
+ }
192
+ function walkElements(parent, code, enter, leave, parents = []) {
193
+ const children = getSortedChildren(parent, code);
194
+ const currParents = [parent, ...parents];
195
+ for (const node of children) {
196
+ enter(node, currParents);
197
+ if (isParent(node)) {
198
+ walkElements(node, code, enter, leave, currParents);
199
+ }
200
+ leave(node, currParents);
201
+ }
202
+ }
203
+ function walk(parent, code, enter, leave) {
204
+ walkElements(
205
+ parent,
206
+ code,
207
+ (node, parents) => {
208
+ enter(node, parents);
209
+ if (isTag(node)) {
210
+ const attrParents = [node, ...parents];
211
+ for (const attr of node.attributes) {
212
+ enter(attr, attrParents);
213
+ leave(attr, attrParents);
214
+ }
215
+ }
216
+ },
217
+ leave
218
+ );
219
+ }
220
+ function calcStartTagEndOffset(node, ctx) {
221
+ const lastAttr = node.attributes[node.attributes.length - 1];
222
+ let beforeCloseIndex;
223
+ if (lastAttr) {
224
+ beforeCloseIndex = calcAttributeEndOffset(lastAttr, ctx);
225
+ } else {
226
+ const info2 = getTokenInfo(
227
+ ctx,
228
+ [`<${node.name}`],
229
+ node.position.start.offset
230
+ );
231
+ beforeCloseIndex = info2.index + info2.match.length;
232
+ }
233
+ const info = getTokenInfo(ctx, [[">", "/>"]], beforeCloseIndex);
234
+ return info.index + info.match.length;
235
+ }
236
+ function calcAttributeEndOffset(node, ctx) {
237
+ let info;
238
+ if (node.kind === "empty") {
239
+ info = getTokenInfo(ctx, [node.name], node.position.start.offset);
240
+ } else if (node.kind === "quoted") {
241
+ info = getTokenInfo(
242
+ ctx,
243
+ [[`"${node.value}"`, `'${node.value}'`, node.value]],
244
+ calcAttributeValueStartOffset(node, ctx)
245
+ );
246
+ } else if (node.kind === "expression") {
247
+ info = getTokenInfo(
248
+ ctx,
249
+ ["{", node.value, "}"],
250
+ calcAttributeValueStartOffset(node, ctx)
251
+ );
252
+ } else if (node.kind === "shorthand") {
253
+ info = getTokenInfo(
254
+ ctx,
255
+ ["{", node.name, "}"],
256
+ node.position.start.offset
257
+ );
258
+ } else if (node.kind === "spread") {
259
+ info = getTokenInfo(
260
+ ctx,
261
+ ["{", "...", node.name, "}"],
262
+ node.position.start.offset
263
+ );
264
+ } else if (node.kind === "template-literal") {
265
+ info = getTokenInfo(
266
+ ctx,
267
+ [`\`${node.value}\``],
268
+ calcAttributeValueStartOffset(node, ctx)
269
+ );
270
+ } else {
271
+ throw new ParseError(
272
+ `Unknown attr kind: ${node.kind}`,
273
+ node.position.start.offset,
274
+ ctx
275
+ );
276
+ }
277
+ return info.index + info.match.length;
278
+ }
279
+ function calcAttributeValueStartOffset(node, ctx) {
280
+ let info;
281
+ if (node.kind === "quoted") {
282
+ info = getTokenInfo(
283
+ ctx,
284
+ [node.name, "=", [`"`, `'`, node.value]],
285
+ node.position.start.offset
286
+ );
287
+ } else if (node.kind === "expression") {
288
+ info = getTokenInfo(
289
+ ctx,
290
+ [node.name, "=", "{"],
291
+ node.position.start.offset
292
+ );
293
+ } else if (node.kind === "template-literal") {
294
+ info = getTokenInfo(
295
+ ctx,
296
+ [node.name, "=", "`"],
297
+ node.position.start.offset
298
+ );
299
+ } else {
300
+ throw new ParseError(
301
+ `Unknown attr kind: ${node.kind}`,
302
+ node.position.start.offset,
303
+ ctx
304
+ );
305
+ }
306
+ return info.index;
307
+ }
308
+ function getEndOffset(node, ctx) {
309
+ var _a;
310
+ if (((_a = node.position.end) == null ? void 0 : _a.offset) != null) {
311
+ return node.position.end.offset;
312
+ }
313
+ if (isTag(node))
314
+ return calcTagEndOffset(node, ctx);
315
+ if (node.type === "expression")
316
+ return calcExpressionEndOffset(node, ctx);
317
+ if (node.type === "comment")
318
+ return calcCommentEndOffset(node, ctx);
319
+ if (node.type === "frontmatter") {
320
+ const start = node.position.start.offset;
321
+ return ctx.code.indexOf("---", start + 3) + 3;
322
+ }
323
+ if (node.type === "doctype") {
324
+ const start = node.position.start.offset;
325
+ return ctx.code.indexOf(">", start) + 1;
326
+ }
327
+ if (node.type === "text") {
328
+ const start = node.position.start.offset;
329
+ return start + node.value.length;
330
+ }
331
+ if (node.type === "root") {
332
+ return ctx.code.length;
333
+ }
334
+ throw new Error(`unknown type: ${node.type}`);
335
+ }
336
+ function calcContentEndOffset(parent, ctx) {
337
+ const code = ctx.code;
338
+ if (isTag(parent)) {
339
+ const end = getEndOffset(parent, ctx);
340
+ if (code[end - 1] !== ">") {
341
+ return end;
342
+ }
343
+ const index = code.lastIndexOf("</", end - 1);
344
+ if (index >= 0 && code.slice(index + 2, end - 1).trim() === parent.name) {
345
+ return index;
346
+ }
347
+ return end;
348
+ } else if (parent.type === "expression") {
349
+ const end = getEndOffset(parent, ctx);
350
+ return code.lastIndexOf("}", end);
351
+ } else if (parent.type === "root") {
352
+ return code.length;
353
+ }
354
+ throw new Error(`unknown type: ${parent.type}`);
355
+ }
356
+ function getSelfClosingTag(node, ctx) {
357
+ if (node.children.length > 0) {
358
+ return null;
359
+ }
360
+ const code = ctx.code;
361
+ const startTagEndOffset = calcStartTagEndOffset(node, ctx);
362
+ if (code.startsWith("/>", startTagEndOffset - 2)) {
363
+ return {
364
+ offset: startTagEndOffset,
365
+ end: "/>"
366
+ };
367
+ }
368
+ if (code.startsWith(`</${node.name}`, startTagEndOffset)) {
369
+ return null;
370
+ }
371
+ return {
372
+ offset: startTagEndOffset,
373
+ end: ">"
374
+ };
375
+ }
376
+ function getEndTag(node, ctx) {
377
+ let beforeIndex;
378
+ if (node.children.length) {
379
+ const lastChild = node.children[node.children.length - 1];
380
+ beforeIndex = getEndOffset(lastChild, ctx);
381
+ } else {
382
+ beforeIndex = calcStartTagEndOffset(node, ctx);
383
+ }
384
+ beforeIndex = skipSpaces(ctx.code, beforeIndex);
385
+ if (ctx.code.startsWith(`</${node.name}`, beforeIndex)) {
386
+ const offset = beforeIndex;
387
+ beforeIndex = beforeIndex + 2 + node.name.length;
388
+ const info = getTokenInfo(ctx, [">"], beforeIndex);
389
+ const end = info.index + info.match.length;
390
+ return {
391
+ offset,
392
+ tag: ctx.code.slice(offset, end)
393
+ };
394
+ }
395
+ return null;
396
+ }
397
+ function calcCommentEndOffset(node, ctx) {
398
+ const info = getTokenInfo(
399
+ ctx,
400
+ ["<!--", node.value, "-->"],
401
+ node.position.start.offset
402
+ );
403
+ return info.index + info.match.length;
404
+ }
405
+ function calcTagEndOffset(node, ctx) {
406
+ let beforeIndex;
407
+ if (node.children.length) {
408
+ const lastChild = node.children[node.children.length - 1];
409
+ beforeIndex = getEndOffset(lastChild, ctx);
410
+ } else {
411
+ beforeIndex = calcStartTagEndOffset(node, ctx);
412
+ }
413
+ beforeIndex = skipSpaces(ctx.code, beforeIndex);
414
+ if (ctx.code.startsWith(`</${node.name}`, beforeIndex)) {
415
+ beforeIndex = beforeIndex + 2 + node.name.length;
416
+ const info = getTokenInfo(ctx, [">"], beforeIndex);
417
+ return info.index + info.match.length;
418
+ }
419
+ return beforeIndex;
420
+ }
421
+ function calcExpressionEndOffset(node, ctx) {
422
+ if (node.children.length) {
423
+ const lastChild = node.children[node.children.length - 1];
424
+ const beforeIndex = getEndOffset(lastChild, ctx);
425
+ const info2 = getTokenInfo(ctx, ["}"], beforeIndex);
426
+ return info2.index + info2.match.length;
427
+ }
428
+ const info = getTokenInfo(ctx, ["{", "}"], node.position.start.offset);
429
+ return info.index + info.match.length;
430
+ }
431
+ function getTokenInfo(ctx, tokens, position) {
432
+ let lastMatch;
433
+ for (const t of tokens) {
434
+ const index = lastMatch ? lastMatch.index + lastMatch.match.length : position;
435
+ const m = typeof t === "string" ? matchOfStr(t, index) : matchOfForMulti(t, index);
436
+ if (m == null) {
437
+ throw new ParseError(
438
+ `Unknown token at ${index}, expected: ${JSON.stringify(
439
+ t
440
+ )}, actual: ${JSON.stringify(ctx.code.slice(index, index + 10))}`,
441
+ index,
442
+ ctx
443
+ );
444
+ }
445
+ lastMatch = m;
446
+ }
447
+ return lastMatch;
448
+ function matchOfStr(search, position2) {
449
+ const index = search.trim() === search ? skipSpaces(ctx.code, position2) : position2;
450
+ if (ctx.code.startsWith(search, index)) {
451
+ return {
452
+ match: search,
453
+ index
454
+ };
455
+ }
456
+ return null;
457
+ }
458
+ function matchOfForMulti(search, position2) {
459
+ for (const s of search) {
460
+ const m = matchOfStr(s, position2);
461
+ if (m) {
462
+ return m;
463
+ }
464
+ }
465
+ return null;
466
+ }
467
+ }
468
+ function skipSpaces(string, position) {
469
+ const re = /\s*/g;
470
+ re.lastIndex = position;
471
+ const match = re.exec(string);
472
+ if (match) {
473
+ return match.index + match[0].length;
474
+ }
475
+ return position;
476
+ }
477
+ function getSortedChildren(parent, code) {
478
+ var _a;
479
+ if (parent.type === "root" && ((_a = parent.children[0]) == null ? void 0 : _a.type) === "frontmatter") {
480
+ const children = [...parent.children];
481
+ if (children.every((n) => n.position)) {
482
+ return children.sort(
483
+ (a, b) => a.position.start.offset - b.position.start.offset
484
+ );
485
+ }
486
+ let start = skipSpaces(code, 0);
487
+ if (code.startsWith("<!", start)) {
488
+ const frontmatter = children.shift();
489
+ const before = [];
490
+ let first;
491
+ while (first = children.shift()) {
492
+ start = skipSpaces(code, start);
493
+ if (first.type === "comment" && code.startsWith("<!--", start)) {
494
+ start = code.indexOf("-->", start + 4) + 3;
495
+ before.push(first);
496
+ } else if (first.type === "doctype" && code.startsWith("<!", start)) {
497
+ start = code.indexOf(">", start + 2) + 1;
498
+ before.push(first);
499
+ } else {
500
+ children.unshift(first);
501
+ break;
502
+ }
503
+ }
504
+ return [...before, frontmatter, ...children];
505
+ }
506
+ }
507
+ return parent.children;
508
+ }
509
+
510
+ // src/traverse.ts
511
+ function fallbackKeysFilter(key) {
512
+ let value = null;
513
+ return key !== "comments" && key !== "leadingComments" && key !== "loc" && key !== "parent" && key !== "range" && key !== "tokens" && key !== "trailingComments" && (value = this[key]) !== null && typeof value === "object" && (typeof value.type === "string" || Array.isArray(value));
514
+ }
515
+ function getFallbackKeys(node) {
516
+ return Object.keys(node).filter(fallbackKeysFilter, node);
517
+ }
518
+ function getKeys(node, visitorKeys) {
519
+ const keys = (visitorKeys || KEYS)[node.type] || getFallbackKeys(node);
520
+ return keys.filter((key) => !getNodes(node, key).next().done);
521
+ }
522
+ function* getNodes(node, key) {
523
+ const child = node[key];
524
+ if (Array.isArray(child)) {
525
+ for (const c of child) {
526
+ if (isNode(c)) {
527
+ yield c;
528
+ }
529
+ }
530
+ } else if (isNode(child)) {
531
+ yield child;
532
+ }
533
+ }
534
+ function isNode(x) {
535
+ return x !== null && typeof x === "object" && typeof x.type === "string";
536
+ }
537
+ function traverse(node, parent, visitor) {
538
+ visitor.enterNode(node, parent);
539
+ const keys = getKeys(node, visitor.visitorKeys);
540
+ for (const key of keys) {
541
+ for (const child of getNodes(node, key)) {
542
+ traverse(child, node, visitor);
543
+ }
544
+ }
545
+ visitor.leaveNode(node, parent);
546
+ }
547
+ function traverseNodes(node, visitor) {
548
+ traverse(node, null, visitor);
549
+ }
550
+
551
+ // src/context/script.ts
552
+ var RestoreNodeProcessContext = class {
553
+ constructor(result, parentMap) {
554
+ this.removeTokens = /* @__PURE__ */ new Set();
555
+ this.result = result;
556
+ this.parentMap = parentMap;
557
+ }
558
+ addRemoveToken(test) {
559
+ this.removeTokens.add(test);
560
+ }
561
+ getParent(node) {
562
+ return this.parentMap.get(node) || null;
563
+ }
564
+ };
565
+ var ScriptContext = class {
566
+ constructor(ctx) {
567
+ this.script = "";
568
+ this.consumedIndex = 0;
569
+ this.offsets = [];
570
+ this.fragments = [];
571
+ this.tokens = [];
572
+ this.restoreNodeProcesses = [];
573
+ this.ctx = ctx;
574
+ }
575
+ get originalCode() {
576
+ return this.ctx.code;
577
+ }
578
+ skipOriginalOffset(offset) {
579
+ this.consumedIndex += offset;
580
+ }
581
+ appendOriginal(index) {
582
+ if (this.consumedIndex >= index) {
583
+ return;
584
+ }
585
+ this.offsets.push({
586
+ original: this.consumedIndex,
587
+ script: this.script.length
588
+ });
589
+ this.script += this.ctx.code.slice(this.consumedIndex, index);
590
+ this.consumedIndex = index;
591
+ }
592
+ appendScript(fragment) {
593
+ const start = this.script.length;
594
+ this.script += fragment;
595
+ this.fragments.push({ start, end: this.script.length });
596
+ }
597
+ addToken(type, range) {
598
+ if (range[0] >= range[1]) {
599
+ return;
600
+ }
601
+ this.tokens.push(this.ctx.buildToken(type, range));
602
+ }
603
+ addRestoreNodeProcess(process2) {
604
+ this.restoreNodeProcesses.push(process2);
605
+ }
606
+ restore(result) {
607
+ var _a, _b;
608
+ const traversed = /* @__PURE__ */ new Map();
609
+ traverseNodes(result.ast, {
610
+ visitorKeys: result.visitorKeys,
611
+ enterNode: (node, p) => {
612
+ if (!traversed.has(node)) {
613
+ traversed.set(node, p);
614
+ this.remapLocation(node);
615
+ }
616
+ },
617
+ leaveNode: (_node) => {
618
+ }
619
+ });
620
+ const tokens = [...this.tokens];
621
+ for (const token of result.ast.tokens || []) {
622
+ if (this.fragments.some(
623
+ (f) => f.start <= token.range[0] && token.range[1] <= f.end
624
+ )) {
625
+ continue;
626
+ }
627
+ this.remapLocation(token);
628
+ tokens.push(token);
629
+ }
630
+ result.ast.tokens = tokens;
631
+ for (const token of result.ast.comments || []) {
632
+ this.remapLocation(token);
633
+ }
634
+ const context = new RestoreNodeProcessContext(result, traversed);
635
+ let restoreNodeProcesses = this.restoreNodeProcesses;
636
+ for (const [node, parent] of traversed) {
637
+ if (!parent)
638
+ continue;
639
+ restoreNodeProcesses = restoreNodeProcesses.filter(
640
+ (proc) => !proc(node, context)
641
+ );
642
+ }
643
+ if (context.removeTokens.size) {
644
+ const tokens2 = result.ast.tokens || [];
645
+ for (let index = tokens2.length - 1; index >= 0; index--) {
646
+ const token = tokens2[index];
647
+ for (const rt of context.removeTokens) {
648
+ if (rt(token)) {
649
+ tokens2.splice(index, 1);
650
+ context.removeTokens.delete(rt);
651
+ if (!context.removeTokens.size) {
652
+ break;
653
+ }
654
+ }
655
+ }
656
+ }
657
+ }
658
+ const firstOffset = Math.min(
659
+ ...[result.ast.body[0], (_a = result.ast.tokens) == null ? void 0 : _a[0], (_b = result.ast.comments) == null ? void 0 : _b[0]].filter(Boolean).map((t) => t.range[0])
660
+ );
661
+ if (firstOffset < result.ast.range[0]) {
662
+ result.ast.range[0] = firstOffset;
663
+ result.ast.loc.start = this.ctx.getLocFromIndex(firstOffset);
664
+ }
665
+ }
666
+ remapLocation(node) {
667
+ let [start, end] = node.range;
668
+ const startFragment = this.fragments.find(
669
+ (f) => f.start <= start && start < f.end
670
+ );
671
+ if (startFragment) {
672
+ start = startFragment.end;
673
+ }
674
+ const endFragment = this.fragments.find(
675
+ (f) => f.start < end && end <= f.end
676
+ );
677
+ if (endFragment) {
678
+ end = endFragment.start;
679
+ }
680
+ if (end < start) {
681
+ const w = start;
682
+ start = end;
683
+ end = w;
684
+ }
685
+ const locs = this.ctx.getLocations(...this.getRemapRange(start, end));
686
+ node.loc = locs.loc;
687
+ node.range = locs.range;
688
+ if (node.start != null) {
689
+ delete node.start;
690
+ }
691
+ if (node.end != null) {
692
+ delete node.end;
693
+ }
694
+ }
695
+ getRemapRange(start, end) {
696
+ if (!this.offsets.length) {
697
+ return [start, end];
698
+ }
699
+ let lastStart = this.offsets[0];
700
+ let lastEnd = this.offsets[0];
701
+ for (const offset of this.offsets) {
702
+ if (offset.script <= start) {
703
+ lastStart = offset;
704
+ }
705
+ if (offset.script < end) {
706
+ lastEnd = offset;
707
+ } else {
708
+ if (offset.script === end) {
709
+ const remapStart2 = lastStart.original + (start - lastStart.script);
710
+ if (this.tokens.some(
711
+ (t) => t.range[0] <= remapStart2 && offset.original <= t.range[1]
712
+ )) {
713
+ lastEnd = offset;
714
+ }
715
+ }
716
+ break;
717
+ }
718
+ }
719
+ const remapStart = lastStart.original + (start - lastStart.script);
720
+ const remapEnd = lastEnd.original + (end - lastEnd.script);
721
+ return [remapStart, remapEnd];
722
+ }
723
+ };
724
+
725
+ // src/parser/process-template.ts
726
+ function processTemplate(ctx, resultTemplate) {
727
+ let uniqueIdSeq = 0;
728
+ const usedUniqueIds = /* @__PURE__ */ new Set();
729
+ const script = new ScriptContext(ctx);
730
+ let fragmentOpened = false;
731
+ function openRootFragment(startOffset) {
732
+ script.appendScript("<>");
733
+ fragmentOpened = true;
734
+ script.addRestoreNodeProcess((scriptNode, { result }) => {
735
+ if (scriptNode.type === import_types.AST_NODE_TYPES.ExpressionStatement && scriptNode.expression.type === import_types.AST_NODE_TYPES.JSXFragment && scriptNode.range[0] === startOffset && result.ast.body.includes(scriptNode)) {
736
+ const index = result.ast.body.indexOf(scriptNode);
737
+ const rootFragment = result.ast.body[index] = scriptNode.expression;
738
+ delete rootFragment.closingFragment;
739
+ delete rootFragment.openingFragment;
740
+ rootFragment.type = "AstroFragment";
741
+ return true;
742
+ }
743
+ return false;
744
+ });
745
+ }
746
+ walkElements(
747
+ resultTemplate.ast,
748
+ ctx.code,
749
+ (node, [parent]) => {
750
+ if (node.type === "frontmatter") {
751
+ const start = node.position.start.offset;
752
+ if (fragmentOpened) {
753
+ script.appendScript("</>;");
754
+ fragmentOpened = false;
755
+ }
756
+ script.appendOriginal(start);
757
+ script.skipOriginalOffset(3);
758
+ const end = getEndOffset(node, ctx);
759
+ const scriptStart = start + 3;
760
+ let scriptEnd = end - 3;
761
+ let endChar;
762
+ while (scriptStart < scriptEnd - 1 && (endChar = script.originalCode[scriptEnd - 1]) && !endChar.trim()) {
763
+ scriptEnd--;
764
+ }
765
+ script.appendOriginal(scriptEnd);
766
+ script.appendScript("\n;");
767
+ script.skipOriginalOffset(end - scriptEnd);
768
+ script.addRestoreNodeProcess((_scriptNode, { result }) => {
769
+ for (let index = 0; index < result.ast.body.length; index++) {
770
+ const st = result.ast.body[index];
771
+ if (st.type === import_types.AST_NODE_TYPES.EmptyStatement) {
772
+ if (st.range[0] === scriptEnd && st.range[1] <= end) {
773
+ result.ast.body.splice(index, 1);
774
+ break;
775
+ }
776
+ }
777
+ }
778
+ return true;
779
+ });
780
+ script.addToken(import_types.AST_TOKEN_TYPES.Punctuator, [
781
+ node.position.start.offset,
782
+ node.position.start.offset + 3
783
+ ]);
784
+ script.addToken(import_types.AST_TOKEN_TYPES.Punctuator, [end - 3, end]);
785
+ } else if (isTag(node)) {
786
+ if (parent.type === "expression") {
787
+ const index = parent.children.indexOf(node);
788
+ const before = parent.children[index - 1];
789
+ if (!before || !isTag(before)) {
790
+ const after = parent.children[index + 1];
791
+ if (after && (isTag(after) || after.type === "comment")) {
792
+ const start2 = node.position.start.offset;
793
+ script.appendOriginal(start2);
794
+ script.appendScript("<>");
795
+ script.addRestoreNodeProcess((scriptNode) => {
796
+ if (scriptNode.range[0] === start2 && scriptNode.type === import_types.AST_NODE_TYPES.JSXFragment) {
797
+ delete scriptNode.openingFragment;
798
+ delete scriptNode.closingFragment;
799
+ const fragmentNode = scriptNode;
800
+ fragmentNode.type = "AstroFragment";
801
+ const last = fragmentNode.children[fragmentNode.children.length - 1];
802
+ if (fragmentNode.range[1] < last.range[1]) {
803
+ fragmentNode.range[1] = last.range[1];
804
+ fragmentNode.loc.end = ctx.getLocFromIndex(
805
+ fragmentNode.range[1]
806
+ );
807
+ }
808
+ return true;
809
+ }
810
+ return false;
811
+ });
812
+ }
813
+ }
814
+ }
815
+ const start = node.position.start.offset;
816
+ script.appendOriginal(start);
817
+ if (!fragmentOpened) {
818
+ openRootFragment(start);
819
+ }
820
+ for (const attr of node.attributes) {
821
+ if ((node.type === "component" || node.type === "fragment") && (attr.kind === "quoted" || attr.kind === "empty" || attr.kind === "expression" || attr.kind === "template-literal")) {
822
+ const colonIndex = attr.name.indexOf(":");
823
+ if (colonIndex >= 0) {
824
+ const start2 = attr.position.start.offset;
825
+ script.appendOriginal(start2 + colonIndex);
826
+ script.skipOriginalOffset(1);
827
+ script.appendScript(`_`);
828
+ script.addToken(import_types.AST_TOKEN_TYPES.JSXIdentifier, [
829
+ start2,
830
+ start2 + colonIndex
831
+ ]);
832
+ script.addToken(import_types.AST_TOKEN_TYPES.Punctuator, [
833
+ start2 + colonIndex,
834
+ start2 + colonIndex + 1
835
+ ]);
836
+ script.addToken(import_types.AST_TOKEN_TYPES.JSXIdentifier, [
837
+ start2 + colonIndex + 1,
838
+ start2 + attr.name.length
839
+ ]);
840
+ script.addRestoreNodeProcess((scriptNode, context) => {
841
+ if (scriptNode.type === import_types.AST_NODE_TYPES.JSXAttribute && scriptNode.range[0] === start2) {
842
+ const baseNameNode = scriptNode.name;
843
+ const nsn = {
844
+ ...baseNameNode,
845
+ type: import_types.AST_NODE_TYPES.JSXNamespacedName,
846
+ namespace: {
847
+ type: import_types.AST_NODE_TYPES.JSXIdentifier,
848
+ name: attr.name.slice(0, colonIndex),
849
+ ...ctx.getLocations(
850
+ baseNameNode.range[0],
851
+ baseNameNode.range[0] + colonIndex
852
+ )
853
+ },
854
+ name: {
855
+ type: import_types.AST_NODE_TYPES.JSXIdentifier,
856
+ name: attr.name.slice(colonIndex + 1),
857
+ ...ctx.getLocations(
858
+ baseNameNode.range[0] + colonIndex + 1,
859
+ baseNameNode.range[1]
860
+ )
861
+ }
862
+ };
863
+ scriptNode.name = nsn;
864
+ nsn.namespace.parent = nsn;
865
+ nsn.name.parent = nsn;
866
+ context.addRemoveToken(
867
+ (token) => token.range[0] === baseNameNode.range[0] && token.range[1] === baseNameNode.range[1]
868
+ );
869
+ return true;
870
+ }
871
+ return false;
872
+ });
873
+ }
874
+ }
875
+ if (attr.kind === "shorthand") {
876
+ const start2 = attr.position.start.offset;
877
+ script.appendOriginal(start2);
878
+ const jsxName = /[\s"'[\]{}]/u.test(attr.name) ? generateUniqueId(attr.name) : attr.name;
879
+ script.appendScript(`${jsxName}=`);
880
+ script.addRestoreNodeProcess((scriptNode) => {
881
+ if (scriptNode.type === import_types.AST_NODE_TYPES.JSXAttribute && scriptNode.range[0] === start2) {
882
+ const attrNode = scriptNode;
883
+ attrNode.type = "AstroShorthandAttribute";
884
+ const locs = ctx.getLocations(
885
+ ...attrNode.value.expression.range
886
+ );
887
+ if (jsxName !== attr.name) {
888
+ attrNode.name.name = attr.name;
889
+ }
890
+ attrNode.name.range = locs.range;
891
+ attrNode.name.loc = locs.loc;
892
+ return true;
893
+ }
894
+ return false;
895
+ });
896
+ } else if (attr.kind === "template-literal") {
897
+ const attrStart = attr.position.start.offset;
898
+ const start2 = calcAttributeValueStartOffset(attr, ctx);
899
+ const end = calcAttributeEndOffset(attr, ctx);
900
+ script.appendOriginal(start2);
901
+ script.appendScript("{");
902
+ script.appendOriginal(end);
903
+ script.appendScript("}");
904
+ script.addRestoreNodeProcess((scriptNode) => {
905
+ if (scriptNode.type === import_types.AST_NODE_TYPES.JSXAttribute && scriptNode.range[0] === attrStart) {
906
+ const attrNode = scriptNode;
907
+ attrNode.type = "AstroTemplateLiteralAttribute";
908
+ return true;
909
+ }
910
+ return false;
911
+ });
912
+ }
913
+ }
914
+ const closing = getSelfClosingTag(node, ctx);
915
+ if (closing && closing.end === ">") {
916
+ script.appendOriginal(closing.offset - 1);
917
+ script.appendScript("/");
918
+ }
919
+ if (node.name === "script" || node.name === "style") {
920
+ const text = node.children[0];
921
+ if (text && text.type === "text") {
922
+ const styleNodeStart = node.position.start.offset;
923
+ const start2 = text.position.start.offset;
924
+ script.appendOriginal(start2);
925
+ script.skipOriginalOffset(text.value.length);
926
+ script.addRestoreNodeProcess((scriptNode) => {
927
+ if (scriptNode.type === import_types.AST_NODE_TYPES.JSXElement && scriptNode.range[0] === styleNodeStart) {
928
+ const textNode = {
929
+ type: "AstroRawText",
930
+ value: text.value,
931
+ raw: text.value,
932
+ parent: scriptNode,
933
+ ...ctx.getLocations(start2, start2 + text.value.length)
934
+ };
935
+ scriptNode.children = [textNode];
936
+ return true;
937
+ }
938
+ return false;
939
+ });
940
+ script.addToken(import_types.AST_TOKEN_TYPES.JSXText, [
941
+ start2,
942
+ start2 + text.value.length
943
+ ]);
944
+ }
945
+ }
946
+ } else if (node.type === "comment") {
947
+ const start = node.position.start.offset;
948
+ const end = getEndOffset(node, ctx);
949
+ const length = end - start;
950
+ script.appendOriginal(start);
951
+ if (!fragmentOpened) {
952
+ openRootFragment(start);
953
+ }
954
+ script.appendOriginal(start + 1);
955
+ script.appendScript(`></`);
956
+ script.skipOriginalOffset(length - 2);
957
+ script.appendOriginal(end);
958
+ script.addRestoreNodeProcess((scriptNode, context) => {
959
+ if (scriptNode.range[0] === start && scriptNode.type === import_types.AST_NODE_TYPES.JSXFragment) {
960
+ delete scriptNode.children;
961
+ delete scriptNode.openingFragment;
962
+ delete scriptNode.closingFragment;
963
+ delete scriptNode.expression;
964
+ const commentNode = scriptNode;
965
+ commentNode.type = "AstroHTMLComment";
966
+ commentNode.value = node.value;
967
+ context.addRemoveToken(
968
+ (token) => token.value === "<" && token.range[0] === scriptNode.range[0]
969
+ );
970
+ context.addRemoveToken(
971
+ (token) => token.value === ">" && token.range[1] === scriptNode.range[1]
972
+ );
973
+ return true;
974
+ }
975
+ return false;
976
+ });
977
+ script.addToken("HTMLComment", [
978
+ start,
979
+ start + length
980
+ ]);
981
+ } else if (node.type === "doctype") {
982
+ const start = node.position.start.offset;
983
+ const end = getEndOffset(node, ctx);
984
+ const length = end - start;
985
+ script.appendOriginal(start);
986
+ if (!fragmentOpened) {
987
+ openRootFragment(start);
988
+ }
989
+ script.appendOriginal(start + 1);
990
+ script.appendScript(`></`);
991
+ script.skipOriginalOffset(length - 2);
992
+ script.appendOriginal(end);
993
+ script.addRestoreNodeProcess((scriptNode, context) => {
994
+ if (scriptNode.range[0] === start && scriptNode.type === import_types.AST_NODE_TYPES.JSXFragment) {
995
+ delete scriptNode.children;
996
+ delete scriptNode.openingFragment;
997
+ delete scriptNode.closingFragment;
998
+ delete scriptNode.expression;
999
+ const doctypeNode = scriptNode;
1000
+ doctypeNode.type = "AstroDoctype";
1001
+ context.addRemoveToken(
1002
+ (token) => token.value === "<" && token.range[0] === scriptNode.range[0]
1003
+ );
1004
+ context.addRemoveToken(
1005
+ (token) => token.value === ">" && token.range[1] === scriptNode.range[1]
1006
+ );
1007
+ return true;
1008
+ }
1009
+ return false;
1010
+ });
1011
+ script.addToken("HTMLDocType", [start, end]);
1012
+ } else {
1013
+ const start = node.position.start.offset;
1014
+ script.appendOriginal(start);
1015
+ if (!fragmentOpened) {
1016
+ openRootFragment(start);
1017
+ }
1018
+ }
1019
+ },
1020
+ (node, [parent]) => {
1021
+ if (isTag(node)) {
1022
+ const closing = getSelfClosingTag(node, ctx);
1023
+ if (!closing) {
1024
+ const end = getEndTag(node, ctx);
1025
+ if (!end) {
1026
+ const offset = calcContentEndOffset(node, ctx);
1027
+ script.appendOriginal(offset);
1028
+ script.appendScript(`</${node.name}>`);
1029
+ script.addRestoreNodeProcess((scriptNode, context) => {
1030
+ const parent2 = context.getParent(scriptNode);
1031
+ if (scriptNode.range[0] === offset && scriptNode.type === import_types.AST_NODE_TYPES.JSXClosingElement && parent2.type === import_types.AST_NODE_TYPES.JSXElement) {
1032
+ parent2.closingElement = null;
1033
+ return true;
1034
+ }
1035
+ return false;
1036
+ });
1037
+ }
1038
+ }
1039
+ }
1040
+ if ((isTag(node) || node.type === "comment") && parent.type === "expression") {
1041
+ const index = parent.children.indexOf(node);
1042
+ const after = parent.children[index + 1];
1043
+ if (!after || !isTag(after) && after.type !== "comment") {
1044
+ const before = parent.children[index - 1];
1045
+ if (before && (isTag(before) || before.type === "comment")) {
1046
+ const end = getEndOffset(node, ctx);
1047
+ script.appendOriginal(end);
1048
+ script.appendScript("</>");
1049
+ }
1050
+ }
1051
+ }
1052
+ }
1053
+ );
1054
+ if (fragmentOpened) {
1055
+ const last = resultTemplate.ast.children[resultTemplate.ast.children.length - 1];
1056
+ const end = getEndOffset(last, ctx);
1057
+ script.appendOriginal(end);
1058
+ script.appendScript("</>");
1059
+ }
1060
+ script.appendOriginal(ctx.code.length);
1061
+ return script;
1062
+ function generateUniqueId(base) {
1063
+ let candidate = `$_${base.replace(/\W/g, "_")}${uniqueIdSeq++}`;
1064
+ while (usedUniqueIds.has(candidate) || ctx.code.includes(candidate)) {
1065
+ candidate = `$_${base.replace(/\W/g, "_")}${uniqueIdSeq++}`;
1066
+ }
1067
+ usedUniqueIds.add(candidate);
1068
+ return candidate;
1069
+ }
1070
+ }
1071
+
1072
+ // src/context/index.ts
1073
+ var Context = class {
1074
+ constructor(code) {
1075
+ this.locsMap = /* @__PURE__ */ new Map();
1076
+ this.state = {};
1077
+ this.locs = new LinesAndColumns(code);
1078
+ this.code = code;
1079
+ }
1080
+ getLocFromIndex(index) {
1081
+ let loc = this.locsMap.get(index);
1082
+ if (!loc) {
1083
+ loc = this.locs.getLocFromIndex(index);
1084
+ this.locsMap.set(index, loc);
1085
+ }
1086
+ return {
1087
+ line: loc.line,
1088
+ column: loc.column
1089
+ };
1090
+ }
1091
+ getLocations(start, end) {
1092
+ return {
1093
+ range: [start, end],
1094
+ loc: {
1095
+ start: this.getLocFromIndex(start),
1096
+ end: this.getLocFromIndex(end)
1097
+ }
1098
+ };
1099
+ }
1100
+ buildToken(type, range) {
1101
+ return {
1102
+ type,
1103
+ value: this.getText(range),
1104
+ ...this.getLocations(...range)
1105
+ };
1106
+ }
1107
+ getText(range) {
1108
+ return this.code.slice(range[0], range[1]);
1109
+ }
1110
+ get originalAST() {
1111
+ return this.state.originalAST;
1112
+ }
1113
+ set originalAST(originalAST) {
1114
+ this.state.originalAST = originalAST;
1115
+ }
1116
+ };
1117
+ var LinesAndColumns = class {
1118
+ constructor(origCode) {
1119
+ const len = origCode.length;
1120
+ const lineStartIndices = [0];
1121
+ const crs = [];
1122
+ let normalizedCode = "";
1123
+ for (let index = 0; index < len; ) {
1124
+ const c = origCode[index++];
1125
+ if (c === "\r") {
1126
+ const next = origCode[index++] || "";
1127
+ if (next === "\n") {
1128
+ normalizedCode += next;
1129
+ crs.push(index - 2);
1130
+ lineStartIndices.push(index);
1131
+ } else {
1132
+ normalizedCode += `
1133
+ ${next}`;
1134
+ lineStartIndices.push(index - 1);
1135
+ }
1136
+ } else {
1137
+ normalizedCode += c;
1138
+ if (c === "\n") {
1139
+ lineStartIndices.push(index);
1140
+ }
1141
+ }
1142
+ }
1143
+ this.lineStartIndices = lineStartIndices;
1144
+ this.normalizedLineFeed = new NormalizedLineFeed(normalizedCode, crs);
1145
+ }
1146
+ getLocFromIndex(index) {
1147
+ const lineNumber = sortedLastIndex(this.lineStartIndices, index);
1148
+ return {
1149
+ line: lineNumber,
1150
+ column: index - this.lineStartIndices[lineNumber - 1]
1151
+ };
1152
+ }
1153
+ getIndexFromLoc(loc) {
1154
+ const lineStartIndex = this.lineStartIndices[loc.line - 1];
1155
+ const positionIndex = lineStartIndex + loc.column;
1156
+ return positionIndex;
1157
+ }
1158
+ getNormalizedLineFeed() {
1159
+ return this.normalizedLineFeed;
1160
+ }
1161
+ };
1162
+ var NormalizedLineFeed = class {
1163
+ get needRemap() {
1164
+ return this.offsets.length > 0;
1165
+ }
1166
+ constructor(code, offsets) {
1167
+ this.code = code;
1168
+ this.offsets = offsets;
1169
+ if (offsets.length) {
1170
+ const cache = {};
1171
+ this.remapIndex = (index) => {
1172
+ let result = cache[index];
1173
+ if (result != null) {
1174
+ return result;
1175
+ }
1176
+ result = index;
1177
+ for (const offset of offsets) {
1178
+ if (offset < result) {
1179
+ result++;
1180
+ } else {
1181
+ break;
1182
+ }
1183
+ }
1184
+ return cache[index] = result;
1185
+ };
1186
+ } else {
1187
+ this.remapIndex = (i) => i;
1188
+ }
1189
+ }
1190
+ };
1191
+ function sortedLastIndex(array, value) {
1192
+ let lower = 0;
1193
+ let upper = array.length;
1194
+ while (lower < upper) {
1195
+ const mid = Math.floor(lower + (upper - lower) / 2);
1196
+ const target = array[mid];
1197
+ if (target < value) {
1198
+ lower = mid + 1;
1199
+ } else if (target > value) {
1200
+ upper = mid;
1201
+ } else {
1202
+ return mid + 1;
1203
+ }
1204
+ }
1205
+ return upper;
1206
+ }
1207
+
1208
+ // src/parser/astro-parser/parse.ts
1209
+ var service = __toESM(require("astrojs-compiler-sync"));
1210
+ function parse2(code, ctx) {
1211
+ const ast = service.parse(code, { position: true }).ast;
1212
+ if (!ast.children) {
1213
+ ast.children = [];
1214
+ }
1215
+ const htmlElement = ast.children.find(
1216
+ (n) => n.type === "element" && n.name === "html"
1217
+ );
1218
+ if (htmlElement) {
1219
+ adjustHTML(ast, htmlElement, ctx);
1220
+ }
1221
+ fixLocations(ast, ctx);
1222
+ return { ast };
1223
+ }
1224
+ function adjustHTML(ast, htmlElement, ctx) {
1225
+ var _a;
1226
+ const htmlEnd = ctx.code.indexOf("</html");
1227
+ if (htmlEnd == null) {
1228
+ return;
1229
+ }
1230
+ const hasTokenAfter = Boolean(ctx.code.slice(htmlEnd + 7).trim());
1231
+ const children = [...htmlElement.children];
1232
+ for (const child of children) {
1233
+ const offset = (_a = child.position) == null ? void 0 : _a.start.offset;
1234
+ if (hasTokenAfter && offset != null) {
1235
+ if (htmlEnd <= offset) {
1236
+ htmlElement.children.splice(htmlElement.children.indexOf(child), 1);
1237
+ ast.children.push(child);
1238
+ }
1239
+ }
1240
+ if (child.type === "element" && child.name === "body") {
1241
+ adjustHTMLBody(ast, htmlElement, htmlEnd, hasTokenAfter, child, ctx);
1242
+ }
1243
+ }
1244
+ }
1245
+ function adjustHTMLBody(ast, htmlElement, htmlEnd, hasTokenAfterHtmlEnd, bodyElement, ctx) {
1246
+ var _a;
1247
+ const bodyEnd = ctx.code.indexOf("</body");
1248
+ if (bodyEnd == null) {
1249
+ return;
1250
+ }
1251
+ const hasTokenAfter = Boolean(ctx.code.slice(bodyEnd + 7, htmlEnd).trim());
1252
+ if (!hasTokenAfter && !hasTokenAfterHtmlEnd) {
1253
+ return;
1254
+ }
1255
+ const children = [...bodyElement.children];
1256
+ for (const child of children) {
1257
+ const offset = (_a = child.position) == null ? void 0 : _a.start.offset;
1258
+ if (offset != null) {
1259
+ if (bodyEnd <= offset) {
1260
+ if (hasTokenAfterHtmlEnd && htmlEnd <= offset) {
1261
+ bodyElement.children.splice(bodyElement.children.indexOf(child), 1);
1262
+ ast.children.push(child);
1263
+ } else if (hasTokenAfter) {
1264
+ bodyElement.children.splice(bodyElement.children.indexOf(child), 1);
1265
+ htmlElement.children.push(child);
1266
+ }
1267
+ }
1268
+ }
1269
+ }
1270
+ }
1271
+ function fixLocations(node, ctx) {
1272
+ let start = 0;
1273
+ walk(
1274
+ node,
1275
+ ctx.code,
1276
+ (node2, [parent]) => {
1277
+ if (node2.type === "frontmatter") {
1278
+ start = node2.position.start.offset = tokenIndex(ctx, "---", start);
1279
+ if (!node2.position.end) {
1280
+ node2.position.end = {};
1281
+ }
1282
+ start = node2.position.end.offset = tokenIndex(ctx, "---", start + 3 + node2.value.length) + 3;
1283
+ } else if (node2.type === "fragment" || node2.type === "element" || node2.type === "component" || node2.type === "custom-element") {
1284
+ if (!node2.position) {
1285
+ node2.position = { start: {}, end: {} };
1286
+ }
1287
+ start = node2.position.start.offset = tokenIndex(ctx, "<", start);
1288
+ start += 1;
1289
+ start += node2.name.length;
1290
+ if (!node2.attributes.length) {
1291
+ start = calcStartTagEndOffset(node2, ctx);
1292
+ }
1293
+ } else if (node2.type === "attribute") {
1294
+ fixLocationForAttr(node2, ctx, start);
1295
+ start = calcAttributeEndOffset(node2, ctx);
1296
+ if (node2.position.end) {
1297
+ node2.position.end.offset = start;
1298
+ }
1299
+ } else if (node2.type === "comment") {
1300
+ node2.position.start.offset = tokenIndex(ctx, "<!--", start);
1301
+ start = calcCommentEndOffset(node2, ctx);
1302
+ if (node2.position.end) {
1303
+ node2.position.end.offset = start;
1304
+ }
1305
+ } else if (node2.type === "text") {
1306
+ if (parent.type === "element" && (parent.name === "script" || parent.name === "style")) {
1307
+ node2.position.start.offset = start;
1308
+ start = ctx.code.indexOf(`</${parent.name}`, start);
1309
+ if (start < 0) {
1310
+ start = ctx.code.length;
1311
+ }
1312
+ } else {
1313
+ const index = tokenIndexSafe(ctx.code, node2.value, start);
1314
+ if (index != null) {
1315
+ start = node2.position.start.offset = index;
1316
+ start += node2.value.length;
1317
+ } else {
1318
+ node2.position.start.offset = start;
1319
+ const value = node2.value.replace(/\s+/gu, "");
1320
+ for (const char of value) {
1321
+ const index2 = tokenIndex(ctx, char, start);
1322
+ start = index2 + 1;
1323
+ }
1324
+ start = skipSpaces(ctx.code, start);
1325
+ node2.value = ctx.code.slice(node2.position.start.offset, start);
1326
+ }
1327
+ }
1328
+ if (node2.position.end) {
1329
+ node2.position.end.offset = start;
1330
+ }
1331
+ } else if (node2.type === "expression") {
1332
+ start = node2.position.start.offset = tokenIndex(ctx, "{", start);
1333
+ start += 1;
1334
+ } else if (node2.type === "doctype") {
1335
+ if (!node2.position) {
1336
+ node2.position = { start: {}, end: {} };
1337
+ }
1338
+ if (!node2.position.end) {
1339
+ node2.position.end = {};
1340
+ }
1341
+ start = node2.position.start.offset = tokenIndex(ctx, "<!", start);
1342
+ start += 2;
1343
+ start = node2.position.end.offset = ctx.code.indexOf(">", start) + 1;
1344
+ } else if (node2.type === "root") {
1345
+ }
1346
+ },
1347
+ (node2, [parent]) => {
1348
+ if (node2.type === "attribute") {
1349
+ const attributes = parent.attributes;
1350
+ if (attributes[attributes.length - 1] === node2) {
1351
+ start = calcStartTagEndOffset(parent, ctx);
1352
+ }
1353
+ } else if (node2.type === "expression") {
1354
+ start = tokenIndex(ctx, "}", start) + 1;
1355
+ } else if (node2.type === "fragment" || node2.type === "element" || node2.type === "component" || node2.type === "custom-element") {
1356
+ if (!getSelfClosingTag(node2, ctx)) {
1357
+ const closeTagStart = tokenIndexSafe(
1358
+ ctx.code,
1359
+ `</${node2.name}`,
1360
+ start
1361
+ );
1362
+ if (closeTagStart != null) {
1363
+ start = closeTagStart + 2 + node2.name.length;
1364
+ start = tokenIndex(ctx, ">", start) + 1;
1365
+ }
1366
+ }
1367
+ } else {
1368
+ return;
1369
+ }
1370
+ if (node2.position.end) {
1371
+ node2.position.end.offset = start;
1372
+ }
1373
+ }
1374
+ );
1375
+ }
1376
+ function fixLocationForAttr(node, ctx, start) {
1377
+ if (node.kind === "empty") {
1378
+ node.position.start.offset = tokenIndex(ctx, node.name, start);
1379
+ } else if (node.kind === "quoted") {
1380
+ node.position.start.offset = tokenIndex(ctx, node.name, start);
1381
+ } else if (node.kind === "expression") {
1382
+ node.position.start.offset = tokenIndex(ctx, node.name, start);
1383
+ } else if (node.kind === "shorthand") {
1384
+ node.position.start.offset = tokenIndex(ctx, "{", start);
1385
+ } else if (node.kind === "spread") {
1386
+ node.position.start.offset = tokenIndex(ctx, "{", start);
1387
+ } else if (node.kind === "template-literal") {
1388
+ node.position.start.offset = tokenIndex(ctx, node.name, start);
1389
+ } else {
1390
+ throw new ParseError(
1391
+ `Unknown attr kind: ${node.kind}`,
1392
+ node.position.start.offset,
1393
+ ctx
1394
+ );
1395
+ }
1396
+ }
1397
+ function tokenIndex(ctx, token, position) {
1398
+ const index = tokenIndexSafe(ctx.code, token, position);
1399
+ if (index == null) {
1400
+ const start = token.trim() === token ? skipSpaces(ctx.code, position) : position;
1401
+ throw new ParseError(
1402
+ `Unknown token at ${start}, expected: ${JSON.stringify(
1403
+ token
1404
+ )}, actual: ${JSON.stringify(ctx.code.slice(start, start + 10))}`,
1405
+ start,
1406
+ ctx
1407
+ );
1408
+ }
1409
+ return index;
1410
+ }
1411
+ function tokenIndexSafe(string, token, position) {
1412
+ const index = token.trim() === token ? skipSpaces(string, position) : position;
1413
+ if (string.startsWith(token, index)) {
1414
+ return index;
1415
+ }
1416
+ return null;
1417
+ }
1418
+
1419
+ // src/parser/lru-cache.ts
1420
+ var LruCache = class extends Map {
1421
+ constructor(capacity) {
1422
+ super();
1423
+ this.capacity = capacity;
1424
+ }
1425
+ get(key) {
1426
+ if (!this.has(key)) {
1427
+ return void 0;
1428
+ }
1429
+ const value = super.get(key);
1430
+ this.set(key, value);
1431
+ return value;
1432
+ }
1433
+ set(key, value) {
1434
+ this.delete(key);
1435
+ super.set(key, value);
1436
+ if (this.size > this.capacity) {
1437
+ this.deleteOldestEntry();
1438
+ }
1439
+ return this;
1440
+ }
1441
+ deleteOldestEntry() {
1442
+ for (const entry of this) {
1443
+ this.delete(entry[0]);
1444
+ return;
1445
+ }
1446
+ }
1447
+ };
1448
+
1449
+ // src/parser/template.ts
1450
+ var lruCache = new LruCache(5);
1451
+ function parseTemplate(code) {
1452
+ const cache = lruCache.get(code);
1453
+ if (cache) {
1454
+ return cache;
1455
+ }
1456
+ const ctx = new Context(code);
1457
+ const normalized = ctx.locs.getNormalizedLineFeed();
1458
+ const ctxForAstro = normalized.needRemap ? new Context(normalized.code) : ctx;
1459
+ try {
1460
+ const result = parse2((normalized == null ? void 0 : normalized.code) ?? code, ctxForAstro);
1461
+ if (normalized.needRemap) {
1462
+ remap(result, normalized, code, ctxForAstro);
1463
+ ctx.originalAST = ctxForAstro.originalAST;
1464
+ }
1465
+ const templateResult = {
1466
+ result,
1467
+ context: ctx
1468
+ };
1469
+ lruCache.set(code, templateResult);
1470
+ return templateResult;
1471
+ } catch (e) {
1472
+ if (typeof e.pos === "number") {
1473
+ const err = new ParseError(e.message, normalized == null ? void 0 : normalized.remapIndex(e.pos), ctx);
1474
+ err.astroCompilerError = e;
1475
+ throw err;
1476
+ }
1477
+ throw e;
1478
+ }
1479
+ }
1480
+ function remap(result, normalized, originalCode, ctxForAstro) {
1481
+ const remapDataMap = /* @__PURE__ */ new Map();
1482
+ walk(
1483
+ result.ast,
1484
+ normalized.code,
1485
+ (node) => {
1486
+ const start = normalized.remapIndex(node.position.start.offset);
1487
+ let end, value;
1488
+ if (node.position.end) {
1489
+ end = normalized.remapIndex(node.position.end.offset);
1490
+ if (node.position.start.offset === start && node.position.end.offset === end) {
1491
+ return;
1492
+ }
1493
+ }
1494
+ if (node.type === "text") {
1495
+ value = originalCode.slice(
1496
+ start,
1497
+ normalized.remapIndex(getEndOffset(node, ctxForAstro))
1498
+ );
1499
+ } else if (node.type === "comment") {
1500
+ value = originalCode.slice(
1501
+ start + 4,
1502
+ normalized.remapIndex(getEndOffset(node, ctxForAstro)) - 3
1503
+ );
1504
+ } else if (node.type === "attribute") {
1505
+ if (node.kind !== "empty" && node.kind !== "shorthand" && node.kind !== "spread") {
1506
+ let valueStart = normalized.remapIndex(
1507
+ calcAttributeValueStartOffset(node, ctxForAstro)
1508
+ );
1509
+ let valueEnd = normalized.remapIndex(
1510
+ calcAttributeEndOffset(node, ctxForAstro)
1511
+ );
1512
+ if (node.kind !== "quoted" || originalCode[valueStart] === '"' || originalCode[valueStart] === "'") {
1513
+ valueStart++;
1514
+ valueEnd--;
1515
+ }
1516
+ value = originalCode.slice(valueStart, valueEnd);
1517
+ }
1518
+ }
1519
+ remapDataMap.set(node, {
1520
+ start,
1521
+ end,
1522
+ value
1523
+ });
1524
+ },
1525
+ (_node) => {
1526
+ }
1527
+ );
1528
+ for (const [node, remapData] of remapDataMap) {
1529
+ node.position.start.offset = remapData.start;
1530
+ if (node.position.end) {
1531
+ node.position.end.offset = remapData.end;
1532
+ }
1533
+ if (node.type === "text" || node.type === "comment" || node.type === "attribute" && node.kind !== "empty" && node.kind !== "shorthand" && node.kind !== "spread") {
1534
+ node.value = remapData.value;
1535
+ }
1536
+ }
1537
+ }
1538
+
1539
+ // src/context/parser-options.ts
1540
+ var import_path3 = __toESM(require("path"));
1541
+ var import_fs2 = __toESM(require("fs"));
1542
+
1543
+ // src/context/resolve-parser/espree.ts
1544
+ var import_module2 = require("module");
1545
+ var import_path2 = __toESM(require("path"));
1546
+ var espreeCache = null;
1547
+ function isLinterPath(p) {
1548
+ return p.includes(`eslint${import_path2.default.sep}lib${import_path2.default.sep}linter${import_path2.default.sep}linter.js`) || p.includes(`eslint${import_path2.default.sep}lib${import_path2.default.sep}linter.js`);
1549
+ }
1550
+ function getEspree() {
1551
+ if (!espreeCache) {
1552
+ const linterPath = Object.keys(require.cache || {}).find(isLinterPath);
1553
+ if (linterPath) {
1554
+ try {
1555
+ espreeCache = (0, import_module2.createRequire)(linterPath)("espree");
1556
+ } catch {
1557
+ }
1558
+ }
1559
+ if (!espreeCache) {
1560
+ espreeCache = require("espree");
1561
+ }
1562
+ }
1563
+ return espreeCache;
1564
+ }
1565
+
1566
+ // src/context/resolve-parser/index.ts
1567
+ function getParserForLang(attrs, parser) {
1568
+ if (parser) {
1569
+ if (typeof parser === "string" || isParserObject(parser)) {
1570
+ return parser;
1571
+ }
1572
+ if (typeof parser === "object") {
1573
+ const value = parser[attrs.lang || "js"];
1574
+ if (typeof value === "string" || isParserObject(value)) {
1575
+ return value;
1576
+ }
1577
+ }
1578
+ }
1579
+ return "espree";
1580
+ }
1581
+ function getParser(attrs, parser) {
1582
+ const parserValue = getParserForLang(attrs, parser);
1583
+ if (isParserObject(parserValue)) {
1584
+ return parserValue;
1585
+ }
1586
+ if (parserValue !== "espree") {
1587
+ return require(parserValue);
1588
+ }
1589
+ return getEspree();
1590
+ }
1591
+
1592
+ // src/context/parser-options.ts
1593
+ var ParserOptionsContext = class {
1594
+ constructor(options) {
1595
+ this.state = {};
1596
+ const parserOptions = {
1597
+ ecmaVersion: 2020,
1598
+ sourceType: "module",
1599
+ loc: true,
1600
+ range: true,
1601
+ raw: true,
1602
+ tokens: true,
1603
+ comment: true,
1604
+ eslintVisitorKeys: true,
1605
+ eslintScopeManager: true,
1606
+ ...options || {}
1607
+ };
1608
+ parserOptions.ecmaFeatures = {
1609
+ ...parserOptions.ecmaFeatures || {},
1610
+ jsx: true
1611
+ };
1612
+ parserOptions.sourceType = "module";
1613
+ if (parserOptions.ecmaVersion <= 5 || parserOptions.ecmaVersion == null) {
1614
+ parserOptions.ecmaVersion = 2015;
1615
+ }
1616
+ this.parserOptions = parserOptions;
1617
+ }
1618
+ getParser() {
1619
+ return getParser({}, this.parserOptions.parser);
1620
+ }
1621
+ isTypeScript() {
1622
+ var _a, _b;
1623
+ if (this.state.isTypeScript != null) {
1624
+ return this.state.isTypeScript;
1625
+ }
1626
+ const parserValue = getParserForLang({}, (_a = this.parserOptions) == null ? void 0 : _a.parser);
1627
+ if (maybeTSESLintParserObject(parserValue) || parserValue === "@typescript-eslint/parser") {
1628
+ return this.state.isTypeScript = true;
1629
+ }
1630
+ if (typeof parserValue !== "string") {
1631
+ return this.state.isTypeScript = false;
1632
+ }
1633
+ const parserName = parserValue;
1634
+ if (parserName.includes("@typescript-eslint/parser")) {
1635
+ let targetPath = parserName;
1636
+ while (targetPath) {
1637
+ const pkgPath = import_path3.default.join(targetPath, "package.json");
1638
+ if (import_fs2.default.existsSync(pkgPath)) {
1639
+ try {
1640
+ return this.state.isTypeScript = ((_b = JSON.parse(import_fs2.default.readFileSync(pkgPath, "utf-8"))) == null ? void 0 : _b.name) === "@typescript-eslint/parser";
1641
+ } catch {
1642
+ return this.state.isTypeScript = false;
1643
+ }
1644
+ }
1645
+ const parent = import_path3.default.dirname(targetPath);
1646
+ if (targetPath === parent) {
1647
+ break;
1648
+ }
1649
+ targetPath = parent;
1650
+ }
1651
+ }
1652
+ return this.state.isTypeScript = false;
1653
+ }
1654
+ };
1655
+
1656
+ // src/parser/index.ts
40
1657
  function parseForESLint(code, options) {
41
- return (0, parser_1.parseForESLint)(code, options);
1658
+ const { result: resultTemplate, context: ctx } = parseTemplate(code);
1659
+ const scriptContext = processTemplate(ctx, resultTemplate);
1660
+ const parserOptions = new ParserOptionsContext(options);
1661
+ const resultScript = parseScript(scriptContext.script, ctx, parserOptions);
1662
+ scriptContext.restore(resultScript);
1663
+ sort(resultScript.ast.comments);
1664
+ sort(resultScript.ast.tokens);
1665
+ extractTokens(resultScript, ctx);
1666
+ resultScript.services = Object.assign(resultScript.services || {}, {
1667
+ isAstro: true,
1668
+ getAstroAst() {
1669
+ return resultTemplate.ast;
1670
+ }
1671
+ });
1672
+ resultScript.visitorKeys = Object.assign({}, KEYS, resultScript.visitorKeys);
1673
+ return resultScript;
42
1674
  }
43
- exports.parseForESLint = parseForESLint;
44
- // Keys
45
- // eslint-disable-next-line @typescript-eslint/naming-convention -- ignore
46
- exports.VisitorKeys = visitor_keys_1.KEYS;
1675
+ function extractTokens(ast, ctx) {
1676
+ if (!ast.ast.tokens) {
1677
+ return;
1678
+ }
1679
+ const useRanges = sort([...ast.ast.tokens, ...ast.ast.comments || []]).map(
1680
+ (t) => t.range
1681
+ );
1682
+ let range = useRanges.shift();
1683
+ for (let index = 0; index < ctx.code.length; index++) {
1684
+ while (range && range[1] <= index) {
1685
+ range = useRanges.shift();
1686
+ }
1687
+ if (range && range[0] <= index) {
1688
+ index = range[1] - 1;
1689
+ continue;
1690
+ }
1691
+ const c = ctx.code[index];
1692
+ if (!c.trim()) {
1693
+ continue;
1694
+ }
1695
+ if (isPunctuator(c)) {
1696
+ ast.ast.tokens.push(
1697
+ ctx.buildToken(import_types2.AST_TOKEN_TYPES.Punctuator, [index, index + 1])
1698
+ );
1699
+ } else {
1700
+ ast.ast.tokens.push(
1701
+ ctx.buildToken(import_types2.AST_TOKEN_TYPES.Identifier, [index, index + 1])
1702
+ );
1703
+ }
1704
+ }
1705
+ sort(ast.ast.tokens);
1706
+ function isPunctuator(c) {
1707
+ return /^[^\w$]$/iu.test(c);
1708
+ }
1709
+ }
1710
+
1711
+ // src/astro-tools/index.ts
1712
+ function parseTemplate2(code) {
1713
+ const parsed = parseTemplate(code);
1714
+ return {
1715
+ result: parsed.result,
1716
+ getEndOffset: (node) => getEndOffset(node, parsed.context),
1717
+ calcAttributeValueStartOffset: (node) => calcAttributeValueStartOffset(node, parsed.context),
1718
+ calcAttributeEndOffset: (node) => calcAttributeEndOffset(node, parsed.context),
1719
+ walk(parent, enter, leave) {
1720
+ walk(
1721
+ parent,
1722
+ code,
1723
+ enter,
1724
+ leave || (() => {
1725
+ })
1726
+ );
1727
+ },
1728
+ getLocFromIndex: (index) => parsed.context.getLocFromIndex(index),
1729
+ getIndexFromLoc: (loc) => parsed.context.locs.getIndexFromLoc(loc)
1730
+ };
1731
+ }
1732
+
1733
+ // src/ast/index.ts
1734
+ var ast_exports = {};
1735
+
1736
+ // src/index.ts
1737
+ function parseForESLint2(code, options) {
1738
+ return parseForESLint(code, options);
1739
+ }
1740
+ var VisitorKeys = KEYS;
1741
+ // Annotate the CommonJS export names for ESM import in node:
1742
+ 0 && (module.exports = {
1743
+ AST,
1744
+ ParseError,
1745
+ VisitorKeys,
1746
+ parseForESLint,
1747
+ parseTemplate,
1748
+ traverseNodes
1749
+ });