astro-eslint-parser 0.13.1 → 0.13.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/lib/index.js +76 -51
  2. package/lib/index.mjs +76 -51
  3. package/package.json +4 -4
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
  },
@@ -2169,6 +2180,8 @@ var import_scope_manager2 = require("@typescript-eslint/scope-manager");
2169
2180
  var READ_FLAG = 1;
2170
2181
  var WRITE_FLAG = 2;
2171
2182
  var READ_WRITE_FLAG = 3;
2183
+ var REFERENCE_TYPE_VALUE_FLAG = 1;
2184
+ var REFERENCE_TYPE_TYPE_FLAG = 2;
2172
2185
  function getProgramScope(scopeManager) {
2173
2186
  const globalScope = scopeManager.globalScope;
2174
2187
  return globalScope.childScopes.find((s) => s.type === "module") || globalScope;
@@ -2202,15 +2215,25 @@ function removeAllScopeAndVariableAndReference(target, info) {
2202
2215
  removeScope(info.scopeManager, scope);
2203
2216
  }
2204
2217
  }
2205
- function addVirtualReference(node, variable, scope, readWrite) {
2218
+ function addVirtualReference(node, variable, scope, status) {
2206
2219
  const reference = new import_scope_manager2.Reference(
2207
2220
  node,
2208
2221
  scope,
2209
- readWrite.write && readWrite.read ? READ_WRITE_FLAG : readWrite.write ? WRITE_FLAG : READ_FLAG
2222
+ status.write && status.read ? READ_WRITE_FLAG : status.write ? WRITE_FLAG : READ_FLAG,
2223
+ void 0,
2224
+ // writeExpr
2225
+ void 0,
2226
+ // maybeImplicitGlobal
2227
+ void 0,
2228
+ // init
2229
+ status.typeRef ? REFERENCE_TYPE_TYPE_FLAG : REFERENCE_TYPE_VALUE_FLAG
2210
2230
  );
2211
2231
  reference.astroVirtualReference = true;
2212
2232
  addReference(variable.references, reference);
2213
2233
  reference.resolved = variable;
2234
+ if (status.forceUsed) {
2235
+ variable.eslintUsed = true;
2236
+ }
2214
2237
  return reference;
2215
2238
  }
2216
2239
  function addGlobalVariable(reference, scopeManager) {
@@ -2432,7 +2455,9 @@ function parseForESLint(code, options) {
2432
2455
  propsVariable,
2433
2456
  scope,
2434
2457
  {
2435
- read: true
2458
+ read: true,
2459
+ typeRef: true,
2460
+ forceUsed: true
2436
2461
  }
2437
2462
  );
2438
2463
  }
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
  },
@@ -2138,6 +2149,8 @@ import {
2138
2149
  var READ_FLAG = 1;
2139
2150
  var WRITE_FLAG = 2;
2140
2151
  var READ_WRITE_FLAG = 3;
2152
+ var REFERENCE_TYPE_VALUE_FLAG = 1;
2153
+ var REFERENCE_TYPE_TYPE_FLAG = 2;
2141
2154
  function getProgramScope(scopeManager) {
2142
2155
  const globalScope = scopeManager.globalScope;
2143
2156
  return globalScope.childScopes.find((s) => s.type === "module") || globalScope;
@@ -2171,15 +2184,25 @@ function removeAllScopeAndVariableAndReference(target, info) {
2171
2184
  removeScope(info.scopeManager, scope);
2172
2185
  }
2173
2186
  }
2174
- function addVirtualReference(node, variable, scope, readWrite) {
2187
+ function addVirtualReference(node, variable, scope, status) {
2175
2188
  const reference = new ReferenceClass(
2176
2189
  node,
2177
2190
  scope,
2178
- readWrite.write && readWrite.read ? READ_WRITE_FLAG : readWrite.write ? WRITE_FLAG : READ_FLAG
2191
+ status.write && status.read ? READ_WRITE_FLAG : status.write ? WRITE_FLAG : READ_FLAG,
2192
+ void 0,
2193
+ // writeExpr
2194
+ void 0,
2195
+ // maybeImplicitGlobal
2196
+ void 0,
2197
+ // init
2198
+ status.typeRef ? REFERENCE_TYPE_TYPE_FLAG : REFERENCE_TYPE_VALUE_FLAG
2179
2199
  );
2180
2200
  reference.astroVirtualReference = true;
2181
2201
  addReference(variable.references, reference);
2182
2202
  reference.resolved = variable;
2203
+ if (status.forceUsed) {
2204
+ variable.eslintUsed = true;
2205
+ }
2183
2206
  return reference;
2184
2207
  }
2185
2208
  function addGlobalVariable(reference, scopeManager) {
@@ -2401,7 +2424,9 @@ function parseForESLint(code, options) {
2401
2424
  propsVariable,
2402
2425
  scope,
2403
2426
  {
2404
- read: true
2427
+ read: true,
2428
+ typeRef: true,
2429
+ forceUsed: true
2405
2430
  }
2406
2431
  );
2407
2432
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-eslint-parser",
3
- "version": "0.13.1",
3
+ "version": "0.13.3",
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.56.0",
73
- "@typescript-eslint/parser": "~5.56.0",
72
+ "@typescript-eslint/eslint-plugin": "~5.57.0",
73
+ "@typescript-eslint/parser": "~5.57.0",
74
74
  "astro": "^2.0.0",
75
75
  "astro-eslint-parser": ">=0.1.0",
76
76
  "benchmark": "^2.1.4",
@@ -106,7 +106,7 @@
106
106
  "svelte": "^3.48.0",
107
107
  "tsup": "^6.2.3",
108
108
  "typescript": "~5.0.0",
109
- "typescript-eslint-parser-for-extra-files": "^0.2.0"
109
+ "typescript-eslint-parser-for-extra-files": "^0.3.0"
110
110
  },
111
111
  "publishConfig": {
112
112
  "access": "public"