astro-eslint-parser 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -5,7 +5,7 @@ import { ParseResult } from '@astrojs/compiler';
5
5
  import { Node, AttributeNode, ParentNode } from '@astrojs/compiler/types';
6
6
  import { VisitorKeys as VisitorKeys$1 } from '@typescript-eslint/visitor-keys';
7
7
 
8
- declare type RangeAndLoc = {
8
+ type RangeAndLoc = {
9
9
  range: TSESTree.Range;
10
10
  loc: TSESTree.SourceLocation;
11
11
  };
@@ -70,9 +70,9 @@ interface BaseNode {
70
70
  type: string;
71
71
  }
72
72
 
73
- declare type JSXNode = JSXAttribute | JSXClosingElement | JSXClosingFragment | JSXElement | JSXEmptyExpression | JSXExpressionContainer | JSXFragment | JSXIdentifier | JSXMemberExpression | JSXNamespacedName | JSXOpeningElement | JSXOpeningFragment | JSXSpreadAttribute | JSXSpreadChild | JSXText;
74
- declare type JSXChild = JSXElement | JSXFragment | JSXExpression | JSXText | AstroHTMLComment | AstroRawText;
75
- declare type JSXParentNode = JSXElement | JSXFragment | AstroFragment;
73
+ type JSXNode = JSXAttribute | JSXClosingElement | JSXClosingFragment | JSXElement | JSXEmptyExpression | JSXExpressionContainer | JSXFragment | JSXIdentifier | JSXMemberExpression | JSXNamespacedName | JSXOpeningElement | JSXOpeningFragment | JSXSpreadAttribute | JSXSpreadChild | JSXText;
74
+ type JSXChild = JSXElement | JSXFragment | JSXExpression | JSXText | AstroHTMLComment | AstroRawText;
75
+ type JSXParentNode = JSXElement | JSXFragment | AstroFragment;
76
76
  interface JSXElement extends BaseNode {
77
77
  type: "JSXElement";
78
78
  openingElement: JSXOpeningElement;
@@ -119,7 +119,7 @@ interface JSXSpreadAttribute extends BaseNode {
119
119
  argument: TSESTree.Expression;
120
120
  parent?: JSXOpeningElement;
121
121
  }
122
- declare type JSXTagNameExpression = JSXIdentifier | JSXMemberExpression | JSXNamespacedName;
122
+ type JSXTagNameExpression = JSXIdentifier | JSXMemberExpression | JSXNamespacedName;
123
123
  interface JSXIdentifier extends BaseNode {
124
124
  type: "JSXIdentifier";
125
125
  name: string;
@@ -137,7 +137,7 @@ interface JSXNamespacedName extends BaseNode {
137
137
  name: JSXIdentifier;
138
138
  parent?: JSXAttribute | AstroShorthandAttribute | AstroTemplateLiteralAttribute | JSXMemberExpression | JSXOpeningElement | JSXClosingElement;
139
139
  }
140
- declare type JSXExpression = JSXExpressionContainer | JSXSpreadChild;
140
+ type JSXExpression = JSXExpressionContainer | JSXSpreadChild;
141
141
  interface JSXExpressionContainer extends BaseNode {
142
142
  type: "JSXExpressionContainer";
143
143
  expression: TSESTree.Expression | JSXEmptyExpression;
@@ -159,9 +159,9 @@ interface JSXText extends BaseNode {
159
159
  parent?: JSXParentNode;
160
160
  }
161
161
 
162
- declare type AstroNode = AstroProgram | AstroFragment | AstroHTMLComment | AstroDoctype | AstroShorthandAttribute | AstroTemplateLiteralAttribute | AstroRawText;
163
- declare type AstroChild = JSXElement | JSXFragment | JSXExpression | JSXText | AstroHTMLComment | AstroRawText;
164
- declare type AstroParentNode = JSXElement | JSXFragment | AstroFragment;
162
+ type AstroNode = AstroProgram | AstroFragment | AstroHTMLComment | AstroDoctype | AstroShorthandAttribute | AstroTemplateLiteralAttribute | AstroRawText;
163
+ type AstroChild = JSXElement | JSXFragment | JSXExpression | JSXText | AstroHTMLComment | AstroRawText;
164
+ type AstroParentNode = JSXElement | JSXFragment | AstroFragment;
165
165
  /** Node of Astro program root */
166
166
  interface AstroProgram extends Omit<TSESTree.Program, "type" | "body"> {
167
167
  type: "Program";
@@ -206,11 +206,11 @@ interface AstroRawText extends Omit<JSXText, "type"> {
206
206
  parent?: JSXElement;
207
207
  }
208
208
 
209
- declare type Comment = TSESTree.Comment;
210
- declare type Token = TSESTree.Token;
211
- declare type SourceLocation = TSESTree.SourceLocation;
212
- declare type Range = TSESTree.Range;
213
- declare type Position = TSESTree.Position;
209
+ type Comment = TSESTree.Comment;
210
+ type Token = TSESTree.Token;
211
+ type SourceLocation = TSESTree.SourceLocation;
212
+ type Range = TSESTree.Range;
213
+ type Position = TSESTree.Position;
214
214
 
215
215
  type index_Comment = Comment;
216
216
  type index_Token = Token;
package/lib/index.js CHANGED
@@ -166,7 +166,7 @@ ${code}`
166
166
  );
167
167
  throw e;
168
168
  } finally {
169
- patchResult == null ? void 0 : patchResult.terminate();
169
+ patchResult?.terminate();
170
170
  }
171
171
  }
172
172
 
@@ -325,8 +325,7 @@ function calcAttributeValueStartOffset(node, ctx) {
325
325
  return info.index;
326
326
  }
327
327
  function getEndOffset(node, ctx) {
328
- var _a;
329
- if (((_a = node.position.end) == null ? void 0 : _a.offset) != null) {
328
+ if (node.position.end?.offset != null) {
330
329
  return node.position.end.offset;
331
330
  }
332
331
  if (isTag(node))
@@ -494,8 +493,7 @@ function skipSpaces(string, position) {
494
493
  return position;
495
494
  }
496
495
  function getSortedChildren(parent, code) {
497
- var _a;
498
- if (parent.type === "root" && ((_a = parent.children[0]) == null ? void 0 : _a.type) === "frontmatter") {
496
+ if (parent.type === "root" && parent.children[0]?.type === "frontmatter") {
499
497
  const children = [...parent.children];
500
498
  if (children.every((n) => n.position)) {
501
499
  return children.sort(
@@ -610,7 +608,6 @@ var RestoreContext = class {
610
608
  this.tokens.push(this.ctx.buildToken(type, range));
611
609
  }
612
610
  restore(result) {
613
- var _a, _b;
614
611
  const nodeMap = remapLocationsAndGetNodeMap(result, this.tokens, {
615
612
  remapLocation: (n) => this.remapLocation(n),
616
613
  removeToken: (token) => this.virtualFragments.some(
@@ -619,7 +616,7 @@ var RestoreContext = class {
619
616
  });
620
617
  restoreNodes(result, nodeMap, this.restoreNodeProcesses);
621
618
  const firstOffset = Math.min(
622
- ...[result.ast.body[0], (_a = result.ast.tokens) == null ? void 0 : _a[0], (_b = result.ast.comments) == null ? void 0 : _b[0]].filter((t) => Boolean(t)).map((t) => t.range[0])
619
+ ...[result.ast.body[0], result.ast.tokens?.[0], result.ast.comments?.[0]].filter((t) => Boolean(t)).map((t) => t.range[0])
623
620
  );
624
621
  if (firstOffset < result.ast.range[0]) {
625
622
  result.ast.range[0] = firstOffset;
@@ -1329,7 +1326,6 @@ function parse2(code, ctx) {
1329
1326
  return result;
1330
1327
  }
1331
1328
  function adjustHTML(ast, htmlElement, ctx) {
1332
- var _a;
1333
1329
  const htmlEnd = ctx.code.indexOf("</html");
1334
1330
  if (htmlEnd == null) {
1335
1331
  return;
@@ -1337,7 +1333,7 @@ function adjustHTML(ast, htmlElement, ctx) {
1337
1333
  const hasTokenAfter = Boolean(ctx.code.slice(htmlEnd + 7).trim());
1338
1334
  const children = [...htmlElement.children];
1339
1335
  for (const child of children) {
1340
- const offset = (_a = child.position) == null ? void 0 : _a.start.offset;
1336
+ const offset = child.position?.start.offset;
1341
1337
  if (hasTokenAfter && offset != null) {
1342
1338
  if (htmlEnd <= offset) {
1343
1339
  htmlElement.children.splice(htmlElement.children.indexOf(child), 1);
@@ -1350,7 +1346,6 @@ function adjustHTML(ast, htmlElement, ctx) {
1350
1346
  }
1351
1347
  }
1352
1348
  function adjustHTMLBody(ast, htmlElement, htmlEnd, hasTokenAfterHtmlEnd, bodyElement, ctx) {
1353
- var _a;
1354
1349
  const bodyEnd = ctx.code.indexOf("</body");
1355
1350
  if (bodyEnd == null) {
1356
1351
  return;
@@ -1361,7 +1356,7 @@ function adjustHTMLBody(ast, htmlElement, htmlEnd, hasTokenAfterHtmlEnd, bodyEle
1361
1356
  }
1362
1357
  const children = [...bodyElement.children];
1363
1358
  for (const child of children) {
1364
- const offset = (_a = child.position) == null ? void 0 : _a.start.offset;
1359
+ const offset = child.position?.start.offset;
1365
1360
  if (offset != null) {
1366
1361
  if (bodyEnd <= offset) {
1367
1362
  if (hasTokenAfterHtmlEnd && htmlEnd <= offset) {
@@ -1564,7 +1559,7 @@ function parseTemplate(code, filePath) {
1564
1559
  const normalized = ctx.locs.getNormalizedLineFeed();
1565
1560
  const ctxForAstro = normalized.needRemap ? new Context(normalized.code, filePath) : ctx;
1566
1561
  try {
1567
- const result = parse2((normalized == null ? void 0 : normalized.code) ?? code, ctxForAstro);
1562
+ const result = parse2(normalized?.code ?? code, ctxForAstro);
1568
1563
  if (normalized.needRemap) {
1569
1564
  remap(result, normalized, code, ctxForAstro);
1570
1565
  ctx.originalAST = ctxForAstro.originalAST;
@@ -1577,7 +1572,7 @@ function parseTemplate(code, filePath) {
1577
1572
  return templateResult;
1578
1573
  } catch (e) {
1579
1574
  if (typeof e.pos === "number") {
1580
- const err = new ParseError(e.message, normalized == null ? void 0 : normalized.remapIndex(e.pos), ctx);
1575
+ const err = new ParseError(e.message, normalized?.remapIndex(e.pos), ctx);
1581
1576
  err.astroCompilerError = e;
1582
1577
  throw err;
1583
1578
  }
@@ -1730,11 +1725,10 @@ var ParserOptionsContext = class {
1730
1725
  return getParser({}, this.parserOptions.parser);
1731
1726
  }
1732
1727
  isTypeScript() {
1733
- var _a, _b;
1734
1728
  if (this.state.isTypeScript != null) {
1735
1729
  return this.state.isTypeScript;
1736
1730
  }
1737
- const parserValue = getParserForLang({}, (_a = this.parserOptions) == null ? void 0 : _a.parser);
1731
+ const parserValue = getParserForLang({}, this.parserOptions?.parser);
1738
1732
  if (typeof parserValue !== "string") {
1739
1733
  return this.state.isTypeScript = maybeTSESLintParserObject(parserValue) || isTSESLintParserObject(parserValue);
1740
1734
  }
@@ -1749,7 +1743,7 @@ var ParserOptionsContext = class {
1749
1743
  if (import_fs2.default.existsSync(pkgPath)) {
1750
1744
  try {
1751
1745
  return this.state.isTypeScript = TS_PARSER_NAMES.includes(
1752
- (_b = JSON.parse(import_fs2.default.readFileSync(pkgPath, "utf-8"))) == null ? void 0 : _b.name
1746
+ JSON.parse(import_fs2.default.readFileSync(pkgPath, "utf-8"))?.name
1753
1747
  );
1754
1748
  } catch {
1755
1749
  return this.state.isTypeScript = false;
@@ -2011,7 +2005,7 @@ function addReference(list, reference) {
2011
2005
  function parseForESLint(code, options) {
2012
2006
  const { result: resultTemplate, context: ctx } = parseTemplate(
2013
2007
  code,
2014
- (options == null ? void 0 : options.filePath) ?? "<input>"
2008
+ options?.filePath ?? "<input>"
2015
2009
  );
2016
2010
  const scriptContext = processTemplate(ctx, resultTemplate);
2017
2011
  const parserOptions = new ParserOptionsContext(options);
package/lib/index.mjs CHANGED
@@ -137,7 +137,7 @@ ${code}`
137
137
  );
138
138
  throw e;
139
139
  } finally {
140
- patchResult == null ? void 0 : patchResult.terminate();
140
+ patchResult?.terminate();
141
141
  }
142
142
  }
143
143
 
@@ -296,8 +296,7 @@ function calcAttributeValueStartOffset(node, ctx) {
296
296
  return info.index;
297
297
  }
298
298
  function getEndOffset(node, ctx) {
299
- var _a;
300
- if (((_a = node.position.end) == null ? void 0 : _a.offset) != null) {
299
+ if (node.position.end?.offset != null) {
301
300
  return node.position.end.offset;
302
301
  }
303
302
  if (isTag(node))
@@ -465,8 +464,7 @@ function skipSpaces(string, position) {
465
464
  return position;
466
465
  }
467
466
  function getSortedChildren(parent, code) {
468
- var _a;
469
- if (parent.type === "root" && ((_a = parent.children[0]) == null ? void 0 : _a.type) === "frontmatter") {
467
+ if (parent.type === "root" && parent.children[0]?.type === "frontmatter") {
470
468
  const children = [...parent.children];
471
469
  if (children.every((n) => n.position)) {
472
470
  return children.sort(
@@ -581,7 +579,6 @@ var RestoreContext = class {
581
579
  this.tokens.push(this.ctx.buildToken(type, range));
582
580
  }
583
581
  restore(result) {
584
- var _a, _b;
585
582
  const nodeMap = remapLocationsAndGetNodeMap(result, this.tokens, {
586
583
  remapLocation: (n) => this.remapLocation(n),
587
584
  removeToken: (token) => this.virtualFragments.some(
@@ -590,7 +587,7 @@ var RestoreContext = class {
590
587
  });
591
588
  restoreNodes(result, nodeMap, this.restoreNodeProcesses);
592
589
  const firstOffset = Math.min(
593
- ...[result.ast.body[0], (_a = result.ast.tokens) == null ? void 0 : _a[0], (_b = result.ast.comments) == null ? void 0 : _b[0]].filter((t) => Boolean(t)).map((t) => t.range[0])
590
+ ...[result.ast.body[0], result.ast.tokens?.[0], result.ast.comments?.[0]].filter((t) => Boolean(t)).map((t) => t.range[0])
594
591
  );
595
592
  if (firstOffset < result.ast.range[0]) {
596
593
  result.ast.range[0] = firstOffset;
@@ -1300,7 +1297,6 @@ function parse2(code, ctx) {
1300
1297
  return result;
1301
1298
  }
1302
1299
  function adjustHTML(ast, htmlElement, ctx) {
1303
- var _a;
1304
1300
  const htmlEnd = ctx.code.indexOf("</html");
1305
1301
  if (htmlEnd == null) {
1306
1302
  return;
@@ -1308,7 +1304,7 @@ function adjustHTML(ast, htmlElement, ctx) {
1308
1304
  const hasTokenAfter = Boolean(ctx.code.slice(htmlEnd + 7).trim());
1309
1305
  const children = [...htmlElement.children];
1310
1306
  for (const child of children) {
1311
- const offset = (_a = child.position) == null ? void 0 : _a.start.offset;
1307
+ const offset = child.position?.start.offset;
1312
1308
  if (hasTokenAfter && offset != null) {
1313
1309
  if (htmlEnd <= offset) {
1314
1310
  htmlElement.children.splice(htmlElement.children.indexOf(child), 1);
@@ -1321,7 +1317,6 @@ function adjustHTML(ast, htmlElement, ctx) {
1321
1317
  }
1322
1318
  }
1323
1319
  function adjustHTMLBody(ast, htmlElement, htmlEnd, hasTokenAfterHtmlEnd, bodyElement, ctx) {
1324
- var _a;
1325
1320
  const bodyEnd = ctx.code.indexOf("</body");
1326
1321
  if (bodyEnd == null) {
1327
1322
  return;
@@ -1332,7 +1327,7 @@ function adjustHTMLBody(ast, htmlElement, htmlEnd, hasTokenAfterHtmlEnd, bodyEle
1332
1327
  }
1333
1328
  const children = [...bodyElement.children];
1334
1329
  for (const child of children) {
1335
- const offset = (_a = child.position) == null ? void 0 : _a.start.offset;
1330
+ const offset = child.position?.start.offset;
1336
1331
  if (offset != null) {
1337
1332
  if (bodyEnd <= offset) {
1338
1333
  if (hasTokenAfterHtmlEnd && htmlEnd <= offset) {
@@ -1535,7 +1530,7 @@ function parseTemplate(code, filePath) {
1535
1530
  const normalized = ctx.locs.getNormalizedLineFeed();
1536
1531
  const ctxForAstro = normalized.needRemap ? new Context(normalized.code, filePath) : ctx;
1537
1532
  try {
1538
- const result = parse2((normalized == null ? void 0 : normalized.code) ?? code, ctxForAstro);
1533
+ const result = parse2(normalized?.code ?? code, ctxForAstro);
1539
1534
  if (normalized.needRemap) {
1540
1535
  remap(result, normalized, code, ctxForAstro);
1541
1536
  ctx.originalAST = ctxForAstro.originalAST;
@@ -1548,7 +1543,7 @@ function parseTemplate(code, filePath) {
1548
1543
  return templateResult;
1549
1544
  } catch (e) {
1550
1545
  if (typeof e.pos === "number") {
1551
- const err = new ParseError(e.message, normalized == null ? void 0 : normalized.remapIndex(e.pos), ctx);
1546
+ const err = new ParseError(e.message, normalized?.remapIndex(e.pos), ctx);
1552
1547
  err.astroCompilerError = e;
1553
1548
  throw err;
1554
1549
  }
@@ -1701,11 +1696,10 @@ var ParserOptionsContext = class {
1701
1696
  return getParser({}, this.parserOptions.parser);
1702
1697
  }
1703
1698
  isTypeScript() {
1704
- var _a, _b;
1705
1699
  if (this.state.isTypeScript != null) {
1706
1700
  return this.state.isTypeScript;
1707
1701
  }
1708
- const parserValue = getParserForLang({}, (_a = this.parserOptions) == null ? void 0 : _a.parser);
1702
+ const parserValue = getParserForLang({}, this.parserOptions?.parser);
1709
1703
  if (typeof parserValue !== "string") {
1710
1704
  return this.state.isTypeScript = maybeTSESLintParserObject(parserValue) || isTSESLintParserObject(parserValue);
1711
1705
  }
@@ -1720,7 +1714,7 @@ var ParserOptionsContext = class {
1720
1714
  if (fs2.existsSync(pkgPath)) {
1721
1715
  try {
1722
1716
  return this.state.isTypeScript = TS_PARSER_NAMES.includes(
1723
- (_b = JSON.parse(fs2.readFileSync(pkgPath, "utf-8"))) == null ? void 0 : _b.name
1717
+ JSON.parse(fs2.readFileSync(pkgPath, "utf-8"))?.name
1724
1718
  );
1725
1719
  } catch {
1726
1720
  return this.state.isTypeScript = false;
@@ -1985,7 +1979,7 @@ function addReference(list, reference) {
1985
1979
  function parseForESLint(code, options) {
1986
1980
  const { result: resultTemplate, context: ctx } = parseTemplate(
1987
1981
  code,
1988
- (options == null ? void 0 : options.filePath) ?? "<input>"
1982
+ options?.filePath ?? "<input>"
1989
1983
  );
1990
1984
  const scriptContext = processTemplate(ctx, resultTemplate);
1991
1985
  const parserOptions = new ParserOptionsContext(options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-eslint-parser",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "Astro component parser for ESLint",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.mjs",
@@ -47,7 +47,7 @@
47
47
  },
48
48
  "homepage": "https://github.com/ota-meshi/astro-eslint-parser#readme",
49
49
  "dependencies": {
50
- "@astrojs/compiler": "^0.27.0 || ^0.28.0 || ^0.29.0",
50
+ "@astrojs/compiler": "^0.27.0 || ^0.28.0 || ^0.29.0 || ^0.30.0",
51
51
  "@typescript-eslint/types": "^5.25.0",
52
52
  "astrojs-compiler-sync": "^0.3.0",
53
53
  "debug": "^4.3.4",
@@ -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.4.0",
72
- "@typescript-eslint/parser": "^5.4.0",
71
+ "@typescript-eslint/eslint-plugin": "~5.45.0",
72
+ "@typescript-eslint/parser": "~5.45.0",
73
73
  "astro": "^1.6.1",
74
74
  "astro-eslint-parser": ">=0.1.0",
75
75
  "benchmark": "^2.1.4",
@@ -81,7 +81,7 @@
81
81
  "eslint": "^8.15.0",
82
82
  "eslint-config-prettier": "^8.3.0",
83
83
  "eslint-formatter-codeframe": "^7.32.1",
84
- "eslint-plugin-astro": "^0.20.0",
84
+ "eslint-plugin-astro": "^0.21.0",
85
85
  "eslint-plugin-eslint-comments": "^3.2.0",
86
86
  "eslint-plugin-json-schema-validator": "^4.0.0",
87
87
  "eslint-plugin-jsonc": "^2.0.0",
@@ -95,7 +95,7 @@
95
95
  "eslint-plugin-svelte": "^2.0.0",
96
96
  "estree-walker": "^3.0.0",
97
97
  "locate-character": "^2.0.5",
98
- "magic-string": "^0.26.0",
98
+ "magic-string": "^0.27.0",
99
99
  "mocha": "^10.0.0",
100
100
  "mocha-chai-jest-snapshot": "^1.1.3",
101
101
  "nyc": "^15.1.0",
@@ -106,7 +106,7 @@
106
106
  "string-replace-loader": "^3.0.3",
107
107
  "svelte": "^3.48.0",
108
108
  "tsup": "^6.2.3",
109
- "typescript": "~4.8.0"
109
+ "typescript": "~4.9.0"
110
110
  },
111
111
  "publishConfig": {
112
112
  "access": "public"