astro-eslint-parser 0.13.0 → 0.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -41,6 +41,7 @@ declare class Context {
41
41
  }
42
42
  declare class LinesAndColumns {
43
43
  private readonly lineStartIndices;
44
+ private readonly code;
44
45
  private readonly normalizedLineFeed;
45
46
  constructor(origCode: string);
46
47
  getLocFromIndex(index: number): {
package/lib/index.js CHANGED
@@ -132,6 +132,64 @@ var TSService = class {
132
132
  }
133
133
  createWatch(tsconfigPath) {
134
134
  const { ts } = this;
135
+ const createAbstractBuilder = (...args) => {
136
+ const [
137
+ rootNames,
138
+ options,
139
+ argHost,
140
+ oldProgram,
141
+ configFileParsingDiagnostics,
142
+ projectReferences
143
+ ] = args;
144
+ const host = argHost;
145
+ if (!this.patchedHostSet.has(host)) {
146
+ this.patchedHostSet.add(host);
147
+ const getTargetSourceFile = (fileName, languageVersionOrOptions) => {
148
+ var _a;
149
+ if (this.currTarget.filePath === normalizeFileName(ts, fileName)) {
150
+ return (_a = this.currTarget).sourceFile ?? (_a.sourceFile = ts.createSourceFile(
151
+ this.currTarget.filePath,
152
+ this.currTarget.code,
153
+ languageVersionOrOptions,
154
+ true,
155
+ ts.ScriptKind.TSX
156
+ ));
157
+ }
158
+ return null;
159
+ };
160
+ const original2 = {
161
+ getSourceFile: host.getSourceFile,
162
+ getSourceFileByPath: host.getSourceFileByPath
163
+ };
164
+ host.getSourceFile = (fileName, languageVersionOrOptions, ...args2) => {
165
+ const originalSourceFile = original2.getSourceFile.call(
166
+ host,
167
+ fileName,
168
+ languageVersionOrOptions,
169
+ ...args2
170
+ );
171
+ return getTargetSourceFile(fileName, languageVersionOrOptions) ?? originalSourceFile;
172
+ };
173
+ host.getSourceFileByPath = (fileName, path6, languageVersionOrOptions, ...args2) => {
174
+ const originalSourceFile = original2.getSourceFileByPath.call(
175
+ host,
176
+ fileName,
177
+ path6,
178
+ languageVersionOrOptions,
179
+ ...args2
180
+ );
181
+ return getTargetSourceFile(fileName, languageVersionOrOptions) ?? originalSourceFile;
182
+ };
183
+ }
184
+ return ts.createAbstractBuilder(
185
+ rootNames,
186
+ options,
187
+ host,
188
+ oldProgram,
189
+ configFileParsingDiagnostics,
190
+ projectReferences
191
+ );
192
+ };
135
193
  const watchCompilerHost = ts.createWatchCompilerHost(
136
194
  tsconfigPath,
137
195
  {
@@ -143,54 +201,7 @@ var TSService = class {
143
201
  allowNonTsExtensions: true
144
202
  },
145
203
  ts.sys,
146
- (rootNames, options, argHost, oldProgram, configFileParsingDiagnostics, projectReferences) => {
147
- const host = argHost;
148
- if (!this.patchedHostSet.has(host)) {
149
- this.patchedHostSet.add(host);
150
- const getTargetSourceFile = (fileName, languageVersionOrOptions) => {
151
- var _a;
152
- if (this.currTarget.filePath === normalizeFileName(ts, fileName)) {
153
- return (_a = this.currTarget).sourceFile ?? (_a.sourceFile = ts.createSourceFile(
154
- this.currTarget.filePath,
155
- this.currTarget.code,
156
- languageVersionOrOptions,
157
- true,
158
- ts.ScriptKind.TSX
159
- ));
160
- }
161
- return null;
162
- };
163
- const original2 = {
164
- getSourceFile: host.getSourceFile,
165
- getSourceFileByPath: host.getSourceFileByPath
166
- };
167
- host.getSourceFile = (fileName, languageVersionOrOptions, ...args) => {
168
- return getTargetSourceFile(fileName, languageVersionOrOptions) ?? original2.getSourceFile.call(
169
- host,
170
- fileName,
171
- languageVersionOrOptions,
172
- ...args
173
- );
174
- };
175
- host.getSourceFileByPath = (fileName, path6, languageVersionOrOptions, ...args) => {
176
- return getTargetSourceFile(fileName, languageVersionOrOptions) ?? original2.getSourceFileByPath.call(
177
- host,
178
- fileName,
179
- path6,
180
- languageVersionOrOptions,
181
- ...args
182
- );
183
- };
184
- }
185
- return ts.createAbstractBuilder(
186
- rootNames,
187
- options,
188
- host,
189
- oldProgram,
190
- configFileParsingDiagnostics,
191
- projectReferences
192
- );
193
- },
204
+ createAbstractBuilder,
194
205
  (diagnostic) => {
195
206
  throw new Error(formatDiagnostics(ts, [diagnostic]));
196
207
  },
@@ -1621,6 +1632,7 @@ ${next}`;
1621
1632
  }
1622
1633
  }
1623
1634
  this.lineStartIndices = lineStartIndices;
1635
+ this.code = origCode;
1624
1636
  this.normalizedLineFeed = new NormalizedLineFeed(normalizedCode, crs);
1625
1637
  }
1626
1638
  getLocFromIndex(index) {
@@ -1634,9 +1646,15 @@ ${next}`;
1634
1646
  };
1635
1647
  }
1636
1648
  getIndexFromLoc(loc) {
1637
- const lineStartIndex = this.lineStartIndices[loc.line - 1];
1638
- const positionIndex = lineStartIndex + loc.column;
1639
- return positionIndex;
1649
+ const lineIndex = loc.line - 1;
1650
+ if (this.lineStartIndices.length > lineIndex) {
1651
+ const lineStartIndex = this.lineStartIndices[lineIndex];
1652
+ const positionIndex = lineStartIndex + loc.column;
1653
+ return positionIndex;
1654
+ } else if (this.lineStartIndices.length === lineIndex) {
1655
+ return this.code.length + loc.column;
1656
+ }
1657
+ return this.code.length + loc.column;
1640
1658
  }
1641
1659
  getNormalizedLineFeed() {
1642
1660
  return this.normalizedLineFeed;
package/lib/index.mjs CHANGED
@@ -98,6 +98,64 @@ var TSService = class {
98
98
  }
99
99
  createWatch(tsconfigPath) {
100
100
  const { ts } = this;
101
+ const createAbstractBuilder = (...args) => {
102
+ const [
103
+ rootNames,
104
+ options,
105
+ argHost,
106
+ oldProgram,
107
+ configFileParsingDiagnostics,
108
+ projectReferences
109
+ ] = args;
110
+ const host = argHost;
111
+ if (!this.patchedHostSet.has(host)) {
112
+ this.patchedHostSet.add(host);
113
+ const getTargetSourceFile = (fileName, languageVersionOrOptions) => {
114
+ var _a;
115
+ if (this.currTarget.filePath === normalizeFileName(ts, fileName)) {
116
+ return (_a = this.currTarget).sourceFile ?? (_a.sourceFile = ts.createSourceFile(
117
+ this.currTarget.filePath,
118
+ this.currTarget.code,
119
+ languageVersionOrOptions,
120
+ true,
121
+ ts.ScriptKind.TSX
122
+ ));
123
+ }
124
+ return null;
125
+ };
126
+ const original2 = {
127
+ getSourceFile: host.getSourceFile,
128
+ getSourceFileByPath: host.getSourceFileByPath
129
+ };
130
+ host.getSourceFile = (fileName, languageVersionOrOptions, ...args2) => {
131
+ const originalSourceFile = original2.getSourceFile.call(
132
+ host,
133
+ fileName,
134
+ languageVersionOrOptions,
135
+ ...args2
136
+ );
137
+ return getTargetSourceFile(fileName, languageVersionOrOptions) ?? originalSourceFile;
138
+ };
139
+ host.getSourceFileByPath = (fileName, path6, languageVersionOrOptions, ...args2) => {
140
+ const originalSourceFile = original2.getSourceFileByPath.call(
141
+ host,
142
+ fileName,
143
+ path6,
144
+ languageVersionOrOptions,
145
+ ...args2
146
+ );
147
+ return getTargetSourceFile(fileName, languageVersionOrOptions) ?? originalSourceFile;
148
+ };
149
+ }
150
+ return ts.createAbstractBuilder(
151
+ rootNames,
152
+ options,
153
+ host,
154
+ oldProgram,
155
+ configFileParsingDiagnostics,
156
+ projectReferences
157
+ );
158
+ };
101
159
  const watchCompilerHost = ts.createWatchCompilerHost(
102
160
  tsconfigPath,
103
161
  {
@@ -109,54 +167,7 @@ var TSService = class {
109
167
  allowNonTsExtensions: true
110
168
  },
111
169
  ts.sys,
112
- (rootNames, options, argHost, oldProgram, configFileParsingDiagnostics, projectReferences) => {
113
- const host = argHost;
114
- if (!this.patchedHostSet.has(host)) {
115
- this.patchedHostSet.add(host);
116
- const getTargetSourceFile = (fileName, languageVersionOrOptions) => {
117
- var _a;
118
- if (this.currTarget.filePath === normalizeFileName(ts, fileName)) {
119
- return (_a = this.currTarget).sourceFile ?? (_a.sourceFile = ts.createSourceFile(
120
- this.currTarget.filePath,
121
- this.currTarget.code,
122
- languageVersionOrOptions,
123
- true,
124
- ts.ScriptKind.TSX
125
- ));
126
- }
127
- return null;
128
- };
129
- const original2 = {
130
- getSourceFile: host.getSourceFile,
131
- getSourceFileByPath: host.getSourceFileByPath
132
- };
133
- host.getSourceFile = (fileName, languageVersionOrOptions, ...args) => {
134
- return getTargetSourceFile(fileName, languageVersionOrOptions) ?? original2.getSourceFile.call(
135
- host,
136
- fileName,
137
- languageVersionOrOptions,
138
- ...args
139
- );
140
- };
141
- host.getSourceFileByPath = (fileName, path6, languageVersionOrOptions, ...args) => {
142
- return getTargetSourceFile(fileName, languageVersionOrOptions) ?? original2.getSourceFileByPath.call(
143
- host,
144
- fileName,
145
- path6,
146
- languageVersionOrOptions,
147
- ...args
148
- );
149
- };
150
- }
151
- return ts.createAbstractBuilder(
152
- rootNames,
153
- options,
154
- host,
155
- oldProgram,
156
- configFileParsingDiagnostics,
157
- projectReferences
158
- );
159
- },
170
+ createAbstractBuilder,
160
171
  (diagnostic) => {
161
172
  throw new Error(formatDiagnostics(ts, [diagnostic]));
162
173
  },
@@ -1587,6 +1598,7 @@ ${next}`;
1587
1598
  }
1588
1599
  }
1589
1600
  this.lineStartIndices = lineStartIndices;
1601
+ this.code = origCode;
1590
1602
  this.normalizedLineFeed = new NormalizedLineFeed(normalizedCode, crs);
1591
1603
  }
1592
1604
  getLocFromIndex(index) {
@@ -1600,9 +1612,15 @@ ${next}`;
1600
1612
  };
1601
1613
  }
1602
1614
  getIndexFromLoc(loc) {
1603
- const lineStartIndex = this.lineStartIndices[loc.line - 1];
1604
- const positionIndex = lineStartIndex + loc.column;
1605
- return positionIndex;
1615
+ const lineIndex = loc.line - 1;
1616
+ if (this.lineStartIndices.length > lineIndex) {
1617
+ const lineStartIndex = this.lineStartIndices[lineIndex];
1618
+ const positionIndex = lineStartIndex + loc.column;
1619
+ return positionIndex;
1620
+ } else if (this.lineStartIndices.length === lineIndex) {
1621
+ return this.code.length + loc.column;
1622
+ }
1623
+ return this.code.length + loc.column;
1606
1624
  }
1607
1625
  getNormalizedLineFeed() {
1608
1626
  return this.normalizedLineFeed;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-eslint-parser",
3
- "version": "0.13.0",
3
+ "version": "0.13.2",
4
4
  "description": "Astro component parser for ESLint",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.mjs",
@@ -69,8 +69,8 @@
69
69
  "@types/mocha": "^10.0.0",
70
70
  "@types/node": "^18.0.0",
71
71
  "@types/semver": "^7.3.9",
72
- "@typescript-eslint/eslint-plugin": "~5.55.0",
73
- "@typescript-eslint/parser": "~5.55.0",
72
+ "@typescript-eslint/eslint-plugin": "~5.56.0",
73
+ "@typescript-eslint/parser": "~5.56.0",
74
74
  "astro": "^2.0.0",
75
75
  "astro-eslint-parser": ">=0.1.0",
76
76
  "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.25.0",
84
+ "eslint-plugin-astro": "^0.26.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",