astro-eslint-parser 0.10.1 → 0.12.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.
package/lib/index.d.ts CHANGED
@@ -348,10 +348,11 @@ declare class ParseError extends SyntaxError {
348
348
  }, ctx: Context);
349
349
  }
350
350
 
351
+ declare const name = "astro-eslint-parser";
351
352
  /**
352
353
  * Parse source code
353
354
  */
354
355
  declare function parseForESLint(code: string, options?: any): ReturnType<typeof parseForESLint$1>;
355
356
  declare const VisitorKeys: eslint.SourceCode.VisitorKeys;
356
357
 
357
- export { index as AST, ParseError, ParseTemplateResult, VisitorKeys, parseForESLint, parseTemplate, traverseNodes };
358
+ export { index as AST, ParseError, ParseTemplateResult, VisitorKeys, name, parseForESLint, parseTemplate, traverseNodes };
package/lib/index.js CHANGED
@@ -6,8 +6,8 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
8
  var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
9
+ for (var name2 in all)
10
+ __defProp(target, name2, { get: all[name2], enumerable: true });
11
11
  };
12
12
  var __copyProps = (to, from, except, desc) => {
13
13
  if (from && typeof from === "object" || typeof from === "function") {
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
18
18
  return to;
19
19
  };
20
20
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
25
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
26
  mod
23
27
  ));
@@ -29,6 +33,7 @@ __export(src_exports, {
29
33
  AST: () => ast_exports,
30
34
  ParseError: () => ParseError,
31
35
  VisitorKeys: () => VisitorKeys,
36
+ name: () => name,
32
37
  parseForESLint: () => parseForESLint2,
33
38
  parseTemplate: () => parseTemplate2,
34
39
  traverseNodes: () => traverseNodes
@@ -195,6 +200,9 @@ var import_types = require("@typescript-eslint/types");
195
200
 
196
201
  // src/errors.ts
197
202
  var ParseError = class extends SyntaxError {
203
+ /**
204
+ * Initialize this ParseError instance.
205
+ */
198
206
  constructor(message, offset, ctx) {
199
207
  super(message);
200
208
  if (typeof offset === "number") {
@@ -617,6 +625,9 @@ var RestoreContext = class {
617
625
  }
618
626
  this.tokens.push(this.ctx.buildToken(type, range));
619
627
  }
628
+ /**
629
+ * Restore AST nodes
630
+ */
620
631
  restore(result) {
621
632
  const nodeMap = remapLocationsAndGetNodeMap(result, this.tokens, {
622
633
  remapLocation: (n) => this.remapLocation(n),
@@ -808,6 +819,7 @@ function processTemplate(ctx, resultTemplate) {
808
819
  walkElements(
809
820
  resultTemplate.ast,
810
821
  ctx.code,
822
+ // eslint-disable-next-line complexity -- X(
811
823
  (node, [parent]) => {
812
824
  if (node.type === "frontmatter") {
813
825
  const start = node.position.start.offset;
@@ -1261,6 +1273,9 @@ var Context = class {
1261
1273
  getIndexFromLoc(loc) {
1262
1274
  return this.locs.getIndexFromLoc(loc);
1263
1275
  }
1276
+ /**
1277
+ * Get the location information of the given indexes.
1278
+ */
1264
1279
  getLocations(start, end) {
1265
1280
  return {
1266
1281
  range: [start, end],
@@ -1270,6 +1285,9 @@ var Context = class {
1270
1285
  }
1271
1286
  };
1272
1287
  }
1288
+ /**
1289
+ * Build token
1290
+ */
1273
1291
  buildToken(type, range) {
1274
1292
  return {
1275
1293
  type,
@@ -1277,6 +1295,9 @@ var Context = class {
1277
1295
  ...this.getLocations(...range)
1278
1296
  };
1279
1297
  }
1298
+ /**
1299
+ * get text
1300
+ */
1280
1301
  getText(range) {
1281
1302
  return this.code.slice(range[0], range[1]);
1282
1303
  }
@@ -1440,6 +1461,7 @@ function fixLocations(node, ctx) {
1440
1461
  walk(
1441
1462
  node,
1442
1463
  ctx.code,
1464
+ // eslint-disable-next-line complexity -- X(
1443
1465
  (node2, [parent]) => {
1444
1466
  if (node2.type === "frontmatter") {
1445
1467
  start = node2.position.start.offset = tokenIndex(ctx, "---", start);
@@ -1712,7 +1734,11 @@ var import_module2 = require("module");
1712
1734
  var import_path2 = __toESM(require("path"));
1713
1735
  var espreeCache = null;
1714
1736
  function isLinterPath(p) {
1715
- 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`);
1737
+ return (
1738
+ // ESLint 6 and above
1739
+ p.includes(`eslint${import_path2.default.sep}lib${import_path2.default.sep}linter${import_path2.default.sep}linter.js`) || // ESLint 5
1740
+ p.includes(`eslint${import_path2.default.sep}lib${import_path2.default.sep}linter.js`)
1741
+ );
1716
1742
  }
1717
1743
  function getEspree() {
1718
1744
  if (!espreeCache) {
@@ -1773,6 +1799,7 @@ var ParserOptionsContext = class {
1773
1799
  tokens: true,
1774
1800
  comment: true,
1775
1801
  eslintVisitorKeys: true,
1802
+ // eslintScopeManager: true,
1776
1803
  ...options || {}
1777
1804
  };
1778
1805
  parserOptions.ecmaFeatures = {
@@ -1875,12 +1902,12 @@ function addVirtualReference(node, variable, scope, readWrite) {
1875
1902
  }
1876
1903
  function addGlobalVariable(reference, scopeManager) {
1877
1904
  const globalScope = scopeManager.globalScope;
1878
- const name = reference.identifier.name;
1879
- let variable = globalScope.set.get(name);
1905
+ const name2 = reference.identifier.name;
1906
+ let variable = globalScope.set.get(name2);
1880
1907
  if (!variable) {
1881
- variable = new import_scope_manager2.Variable(name, globalScope);
1908
+ variable = new import_scope_manager2.Variable(name2, globalScope);
1882
1909
  globalScope.variables.push(variable);
1883
- globalScope.set.set(name, variable);
1910
+ globalScope.set.set(name2, variable);
1884
1911
  }
1885
1912
  reference.resolved = variable;
1886
1913
  variable.references.push(reference);
@@ -1888,13 +1915,13 @@ function addGlobalVariable(reference, scopeManager) {
1888
1915
  }
1889
1916
  function removeReferenceFromThrough(reference, baseScope) {
1890
1917
  const variable = reference.resolved;
1891
- const name = reference.identifier.name;
1918
+ const name2 = reference.identifier.name;
1892
1919
  let scope = baseScope;
1893
1920
  while (scope) {
1894
1921
  for (const ref of [...scope.through]) {
1895
1922
  if (reference === ref) {
1896
1923
  scope.through.splice(scope.through.indexOf(ref), 1);
1897
- } else if (ref.identifier.name === name) {
1924
+ } else if (ref.identifier.name === name2) {
1898
1925
  ref.resolved = variable;
1899
1926
  if (!variable.references.includes(ref)) {
1900
1927
  addReference(variable.references, ref);
@@ -1931,9 +1958,9 @@ function removeReference(reference, baseScope) {
1931
1958
  if (varIndex >= 0) {
1932
1959
  baseScope.variables.splice(varIndex, 1);
1933
1960
  }
1934
- const name = reference.identifier.name;
1935
- if (reference.resolved === baseScope.set.get(name)) {
1936
- baseScope.set.delete(name);
1961
+ const name2 = reference.identifier.name;
1962
+ if (reference.resolved === baseScope.set.get(name2)) {
1963
+ baseScope.set.delete(name2);
1937
1964
  }
1938
1965
  } else {
1939
1966
  const refIndex = reference.resolved.references.indexOf(reference);
@@ -1971,9 +1998,9 @@ function removeIdentifierVariable(node, scope) {
1971
1998
  r.resolved = null;
1972
1999
  });
1973
2000
  scope.variables.splice(varIndex, 1);
1974
- const name = node.name;
1975
- if (variable === scope.set.get(name)) {
1976
- scope.set.delete(name);
2001
+ const name2 = node.name;
2002
+ if (variable === scope.set.get(name2)) {
2003
+ scope.set.delete(name2);
1977
2004
  }
1978
2005
  } else {
1979
2006
  const idIndex = variable.identifiers.indexOf(node);
@@ -2187,6 +2214,7 @@ function parseTemplate2(code) {
2187
2214
  var ast_exports = {};
2188
2215
 
2189
2216
  // src/index.ts
2217
+ var name = "astro-eslint-parser";
2190
2218
  function parseForESLint2(code, options) {
2191
2219
  return parseForESLint(code, options);
2192
2220
  }
@@ -2196,6 +2224,7 @@ var VisitorKeys = KEYS;
2196
2224
  AST,
2197
2225
  ParseError,
2198
2226
  VisitorKeys,
2227
+ name,
2199
2228
  parseForESLint,
2200
2229
  parseTemplate,
2201
2230
  traverseNodes
package/lib/index.mjs CHANGED
@@ -166,6 +166,9 @@ import { AST_TOKEN_TYPES, AST_NODE_TYPES } from "@typescript-eslint/types";
166
166
 
167
167
  // src/errors.ts
168
168
  var ParseError = class extends SyntaxError {
169
+ /**
170
+ * Initialize this ParseError instance.
171
+ */
169
172
  constructor(message, offset, ctx) {
170
173
  super(message);
171
174
  if (typeof offset === "number") {
@@ -588,6 +591,9 @@ var RestoreContext = class {
588
591
  }
589
592
  this.tokens.push(this.ctx.buildToken(type, range));
590
593
  }
594
+ /**
595
+ * Restore AST nodes
596
+ */
591
597
  restore(result) {
592
598
  const nodeMap = remapLocationsAndGetNodeMap(result, this.tokens, {
593
599
  remapLocation: (n) => this.remapLocation(n),
@@ -779,6 +785,7 @@ function processTemplate(ctx, resultTemplate) {
779
785
  walkElements(
780
786
  resultTemplate.ast,
781
787
  ctx.code,
788
+ // eslint-disable-next-line complexity -- X(
782
789
  (node, [parent]) => {
783
790
  if (node.type === "frontmatter") {
784
791
  const start = node.position.start.offset;
@@ -1232,6 +1239,9 @@ var Context = class {
1232
1239
  getIndexFromLoc(loc) {
1233
1240
  return this.locs.getIndexFromLoc(loc);
1234
1241
  }
1242
+ /**
1243
+ * Get the location information of the given indexes.
1244
+ */
1235
1245
  getLocations(start, end) {
1236
1246
  return {
1237
1247
  range: [start, end],
@@ -1241,6 +1251,9 @@ var Context = class {
1241
1251
  }
1242
1252
  };
1243
1253
  }
1254
+ /**
1255
+ * Build token
1256
+ */
1244
1257
  buildToken(type, range) {
1245
1258
  return {
1246
1259
  type,
@@ -1248,6 +1261,9 @@ var Context = class {
1248
1261
  ...this.getLocations(...range)
1249
1262
  };
1250
1263
  }
1264
+ /**
1265
+ * get text
1266
+ */
1251
1267
  getText(range) {
1252
1268
  return this.code.slice(range[0], range[1]);
1253
1269
  }
@@ -1411,6 +1427,7 @@ function fixLocations(node, ctx) {
1411
1427
  walk(
1412
1428
  node,
1413
1429
  ctx.code,
1430
+ // eslint-disable-next-line complexity -- X(
1414
1431
  (node2, [parent]) => {
1415
1432
  if (node2.type === "frontmatter") {
1416
1433
  start = node2.position.start.offset = tokenIndex(ctx, "---", start);
@@ -1683,7 +1700,11 @@ import { createRequire as createRequire2 } from "module";
1683
1700
  import path2 from "path";
1684
1701
  var espreeCache = null;
1685
1702
  function isLinterPath(p) {
1686
- return p.includes(`eslint${path2.sep}lib${path2.sep}linter${path2.sep}linter.js`) || p.includes(`eslint${path2.sep}lib${path2.sep}linter.js`);
1703
+ return (
1704
+ // ESLint 6 and above
1705
+ p.includes(`eslint${path2.sep}lib${path2.sep}linter${path2.sep}linter.js`) || // ESLint 5
1706
+ p.includes(`eslint${path2.sep}lib${path2.sep}linter.js`)
1707
+ );
1687
1708
  }
1688
1709
  function getEspree() {
1689
1710
  if (!espreeCache) {
@@ -1744,6 +1765,7 @@ var ParserOptionsContext = class {
1744
1765
  tokens: true,
1745
1766
  comment: true,
1746
1767
  eslintVisitorKeys: true,
1768
+ // eslintScopeManager: true,
1747
1769
  ...options || {}
1748
1770
  };
1749
1771
  parserOptions.ecmaFeatures = {
@@ -1849,12 +1871,12 @@ function addVirtualReference(node, variable, scope, readWrite) {
1849
1871
  }
1850
1872
  function addGlobalVariable(reference, scopeManager) {
1851
1873
  const globalScope = scopeManager.globalScope;
1852
- const name = reference.identifier.name;
1853
- let variable = globalScope.set.get(name);
1874
+ const name2 = reference.identifier.name;
1875
+ let variable = globalScope.set.get(name2);
1854
1876
  if (!variable) {
1855
- variable = new VariableClass(name, globalScope);
1877
+ variable = new VariableClass(name2, globalScope);
1856
1878
  globalScope.variables.push(variable);
1857
- globalScope.set.set(name, variable);
1879
+ globalScope.set.set(name2, variable);
1858
1880
  }
1859
1881
  reference.resolved = variable;
1860
1882
  variable.references.push(reference);
@@ -1862,13 +1884,13 @@ function addGlobalVariable(reference, scopeManager) {
1862
1884
  }
1863
1885
  function removeReferenceFromThrough(reference, baseScope) {
1864
1886
  const variable = reference.resolved;
1865
- const name = reference.identifier.name;
1887
+ const name2 = reference.identifier.name;
1866
1888
  let scope = baseScope;
1867
1889
  while (scope) {
1868
1890
  for (const ref of [...scope.through]) {
1869
1891
  if (reference === ref) {
1870
1892
  scope.through.splice(scope.through.indexOf(ref), 1);
1871
- } else if (ref.identifier.name === name) {
1893
+ } else if (ref.identifier.name === name2) {
1872
1894
  ref.resolved = variable;
1873
1895
  if (!variable.references.includes(ref)) {
1874
1896
  addReference(variable.references, ref);
@@ -1905,9 +1927,9 @@ function removeReference(reference, baseScope) {
1905
1927
  if (varIndex >= 0) {
1906
1928
  baseScope.variables.splice(varIndex, 1);
1907
1929
  }
1908
- const name = reference.identifier.name;
1909
- if (reference.resolved === baseScope.set.get(name)) {
1910
- baseScope.set.delete(name);
1930
+ const name2 = reference.identifier.name;
1931
+ if (reference.resolved === baseScope.set.get(name2)) {
1932
+ baseScope.set.delete(name2);
1911
1933
  }
1912
1934
  } else {
1913
1935
  const refIndex = reference.resolved.references.indexOf(reference);
@@ -1945,9 +1967,9 @@ function removeIdentifierVariable(node, scope) {
1945
1967
  r.resolved = null;
1946
1968
  });
1947
1969
  scope.variables.splice(varIndex, 1);
1948
- const name = node.name;
1949
- if (variable === scope.set.get(name)) {
1950
- scope.set.delete(name);
1970
+ const name2 = node.name;
1971
+ if (variable === scope.set.get(name2)) {
1972
+ scope.set.delete(name2);
1951
1973
  }
1952
1974
  } else {
1953
1975
  const idIndex = variable.identifiers.indexOf(node);
@@ -2161,6 +2183,7 @@ function parseTemplate2(code) {
2161
2183
  var ast_exports = {};
2162
2184
 
2163
2185
  // src/index.ts
2186
+ var name = "astro-eslint-parser";
2164
2187
  function parseForESLint2(code, options) {
2165
2188
  return parseForESLint(code, options);
2166
2189
  }
@@ -2169,6 +2192,7 @@ export {
2169
2192
  ast_exports as AST,
2170
2193
  ParseError,
2171
2194
  VisitorKeys,
2195
+ name,
2172
2196
  parseForESLint2 as parseForESLint,
2173
2197
  parseTemplate2 as parseTemplate,
2174
2198
  traverseNodes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-eslint-parser",
3
- "version": "0.10.1",
3
+ "version": "0.12.0",
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.33.0",
50
+ "@astrojs/compiler": "^1.0.0",
51
51
  "@typescript-eslint/scope-manager": "^5.48.2",
52
52
  "@typescript-eslint/types": "^5.25.0",
53
53
  "astrojs-compiler-sync": "^0.3.0",
@@ -68,20 +68,19 @@
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.48.0",
72
- "@typescript-eslint/parser": "~5.48.0",
73
- "astro": "^1.6.1",
71
+ "@typescript-eslint/eslint-plugin": "~5.54.0",
72
+ "@typescript-eslint/parser": "~5.54.0",
73
+ "astro": "^2.0.0",
74
74
  "astro-eslint-parser": ">=0.1.0",
75
75
  "benchmark": "^2.1.4",
76
76
  "chai": "^4.3.4",
77
- "code-red": "^0.2.3",
78
77
  "env-cmd": "^10.1.0",
79
- "esbuild": "^0.16.0",
78
+ "esbuild": "^0.17.0",
80
79
  "esbuild-register": "^3.3.3",
81
80
  "eslint": "^8.15.0",
82
81
  "eslint-config-prettier": "^8.3.0",
83
82
  "eslint-formatter-codeframe": "^7.32.1",
84
- "eslint-plugin-astro": "^0.21.0",
83
+ "eslint-plugin-astro": "^0.23.0",
85
84
  "eslint-plugin-eslint-comments": "^3.2.0",
86
85
  "eslint-plugin-json-schema-validator": "^4.0.0",
87
86
  "eslint-plugin-jsonc": "^2.0.0",
@@ -91,16 +90,16 @@
91
90
  "eslint-plugin-prettier": "^4.0.0",
92
91
  "eslint-plugin-react": "^7.29.4",
93
92
  "eslint-plugin-regexp": "^1.5.0",
94
- "eslint-plugin-simple-import-sort": "^9.0.0",
93
+ "eslint-plugin-simple-import-sort": "^10.0.0",
95
94
  "eslint-plugin-svelte": "^2.0.0",
96
95
  "estree-walker": "^3.0.0",
97
96
  "locate-character": "^2.0.5",
98
- "magic-string": "^0.27.0",
97
+ "magic-string": "^0.30.0",
99
98
  "mocha": "^10.0.0",
100
99
  "mocha-chai-jest-snapshot": "^1.1.3",
101
100
  "nyc": "^15.1.0",
102
101
  "prettier": "^2.0.5",
103
- "prettier-plugin-astro": "^0.7.0",
102
+ "prettier-plugin-astro": "^0.8.0",
104
103
  "prettier-plugin-svelte": "^2.7.0",
105
104
  "semver": "^7.3.5",
106
105
  "string-replace-loader": "^3.0.3",