knip 6.44.2 → 6.45.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.
Files changed (226) hide show
  1. package/dist/ConfigurationChief.d.ts +23 -1033
  2. package/dist/ConfigurationChief.js +71 -15
  3. package/dist/DependencyDeputy.d.ts +10 -6
  4. package/dist/DependencyDeputy.js +51 -27
  5. package/dist/IssueCollector.d.ts +14 -11
  6. package/dist/IssueCollector.js +25 -20
  7. package/dist/IssueFixer.js +1 -1
  8. package/dist/PackagePeeker.d.ts +6 -0
  9. package/dist/PackagePeeker.js +43 -14
  10. package/dist/ProjectPrincipal.d.ts +6 -3
  11. package/dist/ProjectPrincipal.js +83 -32
  12. package/dist/WorkspaceWorker.d.ts +5 -1
  13. package/dist/WorkspaceWorker.js +39 -22
  14. package/dist/binaries/bash-parser.js +1 -7
  15. package/dist/binaries/command.d.ts +3 -3
  16. package/dist/binaries/command.js +6 -2
  17. package/dist/binaries/fallback.js +1 -1
  18. package/dist/binaries/plugins.d.ts +4 -1
  19. package/dist/binaries/plugins.js +66 -18
  20. package/dist/binaries/resolvers/npm.js +7 -5
  21. package/dist/binaries/resolvers/npx.js +8 -40
  22. package/dist/binaries/util.d.ts +13 -1
  23. package/dist/binaries/util.js +35 -1
  24. package/dist/cli.js +10 -84
  25. package/dist/configuration-hints.d.ts +16 -0
  26. package/dist/configuration-hints.js +64 -0
  27. package/dist/constants.d.ts +2 -1
  28. package/dist/constants.js +2 -0
  29. package/dist/graph/SubpathReferences.d.ts +33 -0
  30. package/dist/graph/SubpathReferences.js +114 -0
  31. package/dist/graph/analyze.d.ts +4 -1
  32. package/dist/graph/analyze.js +16 -5
  33. package/dist/graph/build.d.ts +3 -1
  34. package/dist/graph/build.js +47 -23
  35. package/dist/graph-explorer/operations/resolve-export-origins.js +1 -1
  36. package/dist/plugins/angular/index.js +10 -17
  37. package/dist/plugins/aws-cdk/index.d.ts +3 -0
  38. package/dist/plugins/aws-cdk/index.js +32 -0
  39. package/dist/plugins/aws-cdk/types.d.ts +5 -0
  40. package/dist/plugins/aws-cdk/types.js +1 -0
  41. package/dist/plugins/babel/index.d.ts +1 -1
  42. package/dist/plugins/babel/index.js +19 -5
  43. package/dist/plugins/bun/index.js +8 -7
  44. package/dist/plugins/c8/index.js +17 -4
  45. package/dist/plugins/changesets/index.js +3 -2
  46. package/dist/plugins/commitizen/index.js +6 -3
  47. package/dist/plugins/commitlint/index.js +10 -11
  48. package/dist/plugins/cypress/index.js +4 -2
  49. package/dist/plugins/danger/index.js +1 -1
  50. package/dist/plugins/docusaurus/helpers.js +6 -6
  51. package/dist/plugins/docusaurus/index.js +2 -2
  52. package/dist/plugins/electron-forge/index.js +2 -2
  53. package/dist/plugins/electron-vite/index.js +2 -2
  54. package/dist/plugins/eleventy/index.js +3 -2
  55. package/dist/plugins/eslint/helpers.js +4 -3
  56. package/dist/plugins/eslint/resolveFromAST.js +2 -2
  57. package/dist/plugins/evalite/index.d.ts +3 -0
  58. package/dist/plugins/evalite/index.js +26 -0
  59. package/dist/plugins/flue/index.js +2 -2
  60. package/dist/plugins/github-action/index.js +2 -2
  61. package/dist/plugins/github-actions/index.js +2 -2
  62. package/dist/plugins/graphql-codegen/index.js +13 -9
  63. package/dist/plugins/index.d.ts +5 -0
  64. package/dist/plugins/index.js +10 -0
  65. package/dist/plugins/jest/index.js +5 -5
  66. package/dist/plugins/knex/index.js +2 -2
  67. package/dist/plugins/laravel-vite-plugin/resolveFromAST.js +2 -2
  68. package/dist/plugins/lunaria/index.js +5 -2
  69. package/dist/plugins/markdownlint/index.js +8 -2
  70. package/dist/plugins/marko/index.js +2 -2
  71. package/dist/plugins/marko/taglibs.d.ts +1 -1
  72. package/dist/plugins/marko/taglibs.js +4 -28
  73. package/dist/plugins/mdx/index.d.ts +2 -1
  74. package/dist/plugins/mdx/index.js +7 -4
  75. package/dist/plugins/mdxlint/index.js +18 -15
  76. package/dist/plugins/mikro-orm/index.d.ts +3 -0
  77. package/dist/plugins/mikro-orm/index.js +77 -0
  78. package/dist/plugins/mikro-orm/types.d.ts +21 -0
  79. package/dist/plugins/mikro-orm/types.js +1 -0
  80. package/dist/plugins/msw/index.js +6 -3
  81. package/dist/plugins/msw/types.d.ts +1 -1
  82. package/dist/plugins/netlify/index.js +7 -3
  83. package/dist/plugins/next/index.js +63 -9
  84. package/dist/plugins/next/types.d.ts +5 -0
  85. package/dist/plugins/next-mdx/resolveFromAST.js +15 -10
  86. package/dist/plugins/nitro/index.js +5 -6
  87. package/dist/plugins/node/index.js +4 -4
  88. package/dist/plugins/npm-package-json-lint/index.js +10 -3
  89. package/dist/plugins/nuxt/index.js +18 -10
  90. package/dist/plugins/nuxt/types.d.ts +4 -0
  91. package/dist/plugins/nx/index.js +6 -3
  92. package/dist/plugins/openclaw/index.js +11 -11
  93. package/dist/plugins/oxlint/index.js +2 -2
  94. package/dist/plugins/panda-css/index.js +5 -0
  95. package/dist/plugins/payload/index.js +1 -1
  96. package/dist/plugins/playwright/index.js +3 -3
  97. package/dist/plugins/pm2/index.js +7 -7
  98. package/dist/plugins/prettier/index.js +2 -1
  99. package/dist/plugins/prisma/index.js +2 -2
  100. package/dist/plugins/quasar/resolveFromAST.js +14 -9
  101. package/dist/plugins/react-router/index.js +2 -2
  102. package/dist/plugins/release-it/index.js +6 -2
  103. package/dist/plugins/remix/index.js +3 -3
  104. package/dist/plugins/retry-cli/index.d.ts +3 -0
  105. package/dist/plugins/retry-cli/index.js +14 -0
  106. package/dist/plugins/rollup/index.js +1 -4
  107. package/dist/plugins/rstest/index.js +3 -3
  108. package/dist/plugins/semantic-release/index.js +3 -3
  109. package/dist/plugins/serverless-framework/index.js +10 -8
  110. package/dist/plugins/solidjs-vite-plugin/resolveFromAST.js +2 -2
  111. package/dist/plugins/stencil/resolveFromAST.js +5 -5
  112. package/dist/plugins/stryker/index.js +2 -2
  113. package/dist/plugins/swc/index.js +4 -3
  114. package/dist/plugins/tailwind/index.js +2 -2
  115. package/dist/plugins/tanstack-router/index.js +2 -2
  116. package/dist/plugins/ts-node/index.js +6 -1
  117. package/dist/plugins/turbo/index.js +3 -3
  118. package/dist/plugins/typedoc/index.js +2 -2
  119. package/dist/plugins/typescript/content-mappers.d.ts +1 -1
  120. package/dist/plugins/typescript/index.js +6 -9
  121. package/dist/plugins/varlock/scan.js +1 -1
  122. package/dist/plugins/vite/helpers.d.ts +1 -0
  123. package/dist/plugins/vite/helpers.js +13 -3
  124. package/dist/plugins/vite/index.js +5 -2
  125. package/dist/plugins/vite-plugin-pwa/resolveFromAST.js +2 -2
  126. package/dist/plugins/vitest/index.js +14 -16
  127. package/dist/plugins/vue/index.js +1 -1
  128. package/dist/plugins/web-test-runner/index.d.ts +3 -0
  129. package/dist/plugins/web-test-runner/index.js +86 -0
  130. package/dist/plugins/webdriver-io/index.js +22 -17
  131. package/dist/plugins/webdriver-io/types.d.ts +3 -2
  132. package/dist/plugins/wrangler/index.js +3 -3
  133. package/dist/plugins/yarn/index.js +5 -5
  134. package/dist/plugins.js +2 -5
  135. package/dist/reporters/github-actions.js +3 -7
  136. package/dist/reporters/json.d.ts +1 -0
  137. package/dist/reporters/json.js +1 -0
  138. package/dist/reporters/util/configuration-hints.d.ts +3 -1
  139. package/dist/reporters/util/configuration-hints.js +40 -21
  140. package/dist/reporters/util/util.d.ts +1 -1
  141. package/dist/run-cli.d.ts +2 -0
  142. package/dist/run-cli.js +82 -0
  143. package/dist/run.js +12 -0
  144. package/dist/session/incremental.d.ts +1 -0
  145. package/dist/session/incremental.js +1 -0
  146. package/dist/session/index.d.ts +1 -0
  147. package/dist/session/index.js +1 -0
  148. package/dist/session/watch.js +2 -1
  149. package/dist/types/PluginNames.d.ts +2 -2
  150. package/dist/types/PluginNames.js +5 -0
  151. package/dist/types/args.d.ts +3 -1
  152. package/dist/types/config.d.ts +17 -10
  153. package/dist/types/configuration.d.ts +45 -0
  154. package/dist/types/configuration.js +1 -0
  155. package/dist/types/issues.d.ts +4 -0
  156. package/dist/types/module-graph.d.ts +1 -0
  157. package/dist/types/options.d.ts +1 -0
  158. package/dist/types/package-json.d.ts +3 -8
  159. package/dist/types/workspace.d.ts +1 -0
  160. package/dist/typescript/ast-nodes.js +47 -1
  161. package/dist/typescript/get-imports-and-exports.js +18 -6
  162. package/dist/typescript/resolve-module-names.js +7 -45
  163. package/dist/typescript/visitors/calls.d.ts +1 -1
  164. package/dist/typescript/visitors/calls.js +14 -10
  165. package/dist/typescript/visitors/exports.js +16 -26
  166. package/dist/typescript/visitors/imports.d.ts +2 -1
  167. package/dist/typescript/visitors/imports.js +41 -24
  168. package/dist/typescript/visitors/members.d.ts +1 -1
  169. package/dist/typescript/visitors/members.js +38 -24
  170. package/dist/typescript/visitors/shadow.d.ts +2 -0
  171. package/dist/typescript/visitors/shadow.js +25 -0
  172. package/dist/typescript/visitors/walk.d.ts +20 -12
  173. package/dist/typescript/visitors/walk.js +78 -48
  174. package/dist/util/Performance.d.ts +25 -3
  175. package/dist/util/Performance.js +51 -27
  176. package/dist/util/cli-arguments.d.ts +2 -1
  177. package/dist/util/cli-arguments.js +4 -2
  178. package/dist/util/create-input-handler.js +138 -119
  179. package/dist/util/create-options.d.ts +4 -2071
  180. package/dist/util/create-options.js +6 -4
  181. package/dist/util/create-workspace-graph.js +2 -1
  182. package/dist/util/errors.d.ts +5 -2
  183. package/dist/util/errors.js +11 -18
  184. package/dist/util/fs.js +4 -2
  185. package/dist/util/get-included-issue-types.js +1 -0
  186. package/dist/util/input.d.ts +2 -2
  187. package/dist/util/input.js +2 -2
  188. package/dist/util/is-plugin-name.d.ts +2 -0
  189. package/dist/util/is-plugin-name.js +3 -0
  190. package/dist/util/jiti.d.ts +2 -1
  191. package/dist/util/jiti.js +10 -3
  192. package/dist/util/load-config.d.ts +1 -1
  193. package/dist/util/load-config.js +3 -2
  194. package/dist/util/loader.js +3 -2
  195. package/dist/util/map-workspaces.js +23 -1
  196. package/dist/util/module-graph.js +1 -0
  197. package/dist/util/modules.d.ts +2 -0
  198. package/dist/util/modules.js +78 -0
  199. package/dist/util/package-json.d.ts +12 -5
  200. package/dist/util/package-json.js +54 -26
  201. package/dist/util/parse-and-convert-gitignores.d.ts +2 -2
  202. package/dist/util/parse-and-convert-gitignores.js +5 -5
  203. package/dist/util/parse-configuration.d.ts +2 -0
  204. package/dist/util/parse-configuration.js +66 -0
  205. package/dist/util/plugin.js +8 -12
  206. package/dist/util/regex.js +10 -1
  207. package/dist/util/resolve.d.ts +1 -0
  208. package/dist/util/resolve.js +3 -2
  209. package/dist/util/scripts.d.ts +0 -5
  210. package/dist/util/scripts.js +1 -32
  211. package/dist/util/to-source-path.d.ts +4 -1
  212. package/dist/util/to-source-path.js +2 -2
  213. package/dist/util/unhandled-rejection.d.ts +8 -0
  214. package/dist/util/unhandled-rejection.js +29 -0
  215. package/dist/util/validation.d.ts +11 -0
  216. package/dist/util/validation.js +68 -0
  217. package/dist/util/watch.d.ts +3 -1
  218. package/dist/util/watch.js +5 -2
  219. package/dist/version.d.ts +1 -1
  220. package/dist/version.js +1 -1
  221. package/package.json +6 -7
  222. package/schema.json +34 -0
  223. package/dist/schema/configuration.d.ts +0 -3103
  224. package/dist/schema/configuration.js +0 -94
  225. package/dist/schema/plugins.d.ts +0 -1019
  226. package/dist/schema/plugins.js +0 -215
@@ -2,7 +2,7 @@ import { IMPORT_FLAGS, OPAQUE } from '../../constants.js';
2
2
  import { addValue } from '../../util/module-graph.js';
3
3
  import { isStartsLikePackageName } from '../../util/modules.js';
4
4
  import { getSafeScriptFromArgs, getScriptFromArg, getStringValue, isStringLiteral } from '../ast-nodes.js';
5
- import { isShadowed } from './walk.js';
5
+ import { isShadowedIn } from './shadow.js';
6
6
  function getRegisteredCustomElement(node, s) {
7
7
  const callee = node.callee;
8
8
  if (callee.type !== 'MemberExpression' || callee.computed)
@@ -14,7 +14,7 @@ function getRegisteredCustomElement(node, s) {
14
14
  if (object.type === 'Identifier') {
15
15
  isRegistry =
16
16
  (object.name === 'customElements' || s.customElementRegistries.has(object.name)) &&
17
- !isShadowed(object.name, object.start);
17
+ !isShadowedIn(s, object.name, object.start);
18
18
  }
19
19
  else {
20
20
  isRegistry =
@@ -27,7 +27,7 @@ function getRegisteredCustomElement(node, s) {
27
27
  return undefined;
28
28
  const arg = node.arguments[1];
29
29
  if (arg?.type === 'Identifier')
30
- return isShadowed(arg.name, arg.start) ? undefined : arg.name;
30
+ return isShadowedIn(s, arg.name, arg.start) ? undefined : arg.name;
31
31
  if (arg?.type === 'ThisExpression' && s.staticBlockDepth > 0)
32
32
  return s.classNameStack[s.classNameStack.length - 1] || undefined;
33
33
  return undefined;
@@ -36,7 +36,7 @@ export function trackCustomElementRegistry(node, s) {
36
36
  if (node.id.type !== 'Identifier' || !node.init)
37
37
  return;
38
38
  const init = node.init;
39
- if ((init.type === 'Identifier' && init.name === 'customElements' && !isShadowed('customElements', init.start)) ||
39
+ if ((init.type === 'Identifier' && init.name === 'customElements' && !isShadowedIn(s, 'customElements', init.start)) ||
40
40
  (init.type === 'MemberExpression' &&
41
41
  !init.computed &&
42
42
  init.property.type === 'Identifier' &&
@@ -214,17 +214,21 @@ export function handleCallExpression(node, s) {
214
214
  }
215
215
  return;
216
216
  }
217
- const markRefIfNs = (name) => {
217
+ const markRefIfNs = (name, pos) => {
218
218
  const _import = s.localImportMap.get(name);
219
219
  if (_import?.isNamespace) {
220
220
  const internalImport = s.internal.get(_import.filePath);
221
- if (internalImport)
221
+ if (!internalImport)
222
+ return;
223
+ if (!_import.isDynamicImport)
222
224
  internalImport.refs.add(name);
225
+ else if (!isShadowedIn(s, name, pos))
226
+ addValue(internalImport.import, OPAQUE, s.filePath);
223
227
  }
224
228
  };
225
229
  for (const arg of node.arguments) {
226
230
  if (arg.type === 'Identifier')
227
- markRefIfNs(arg.name);
231
+ markRefIfNs(arg.name, arg.start);
228
232
  else if (arg.type === 'ArrowFunctionExpression' && arg.expression) {
229
233
  const body = arg.body.type === 'AwaitExpression' ? arg.body.argument : arg.body;
230
234
  if (body.type === 'ImportExpression' && isStringLiteral(body.source)) {
@@ -236,15 +240,15 @@ export function handleCallExpression(node, s) {
236
240
  else if (arg.type === 'ArrayExpression') {
237
241
  for (const el of arg.elements ?? []) {
238
242
  if (el?.type === 'Identifier')
239
- markRefIfNs(el.name);
243
+ markRefIfNs(el.name, el.start);
240
244
  }
241
245
  }
242
246
  else if (arg.type === 'ObjectExpression') {
243
247
  for (const prop of arg.properties ?? []) {
244
248
  if (prop.type === 'Property' && !prop.computed && prop.value?.type === 'Identifier')
245
- markRefIfNs(prop.value.name);
249
+ markRefIfNs(prop.value.name, prop.value.start);
246
250
  if (prop.type === 'SpreadElement' && prop.argument?.type === 'Identifier')
247
- markRefIfNs(prop.argument.name);
251
+ markRefIfNs(prop.argument.name, prop.argument.start);
248
252
  }
249
253
  }
250
254
  }
@@ -44,24 +44,21 @@ export function handleExportNamed(node, s) {
44
44
  for (const p of declarator.id.properties) {
45
45
  if (p.type === 'RestElement' && p.argument?.type === 'Identifier') {
46
46
  const name = p.argument.name;
47
- const fix = s.options.isFixExports ? [p.start, p.end, FIX_FLAGS.OBJECT_BINDING] : undefined;
48
- s.addExport(name, SYMBOL_TYPE.UNKNOWN, p.argument.start, [], fix, false, s.getJSDocTags(exportStart));
47
+ s.addExport(name, SYMBOL_TYPE.UNKNOWN, p.argument.start, [], undefined, false, s.getJSDocTags(exportStart));
49
48
  if (declarator.init)
50
49
  s.collectRefsInType(declarator.init, name, false);
51
50
  s.destructuredExports.add(name);
52
51
  }
53
52
  else if (p.value?.type === 'Identifier') {
54
53
  const name = p.value.name;
55
- const fix = s.options.isFixExports ? [p.start, p.end, FIX_FLAGS.OBJECT_BINDING] : undefined;
56
- s.addExport(name, SYMBOL_TYPE.UNKNOWN, p.value.start, [], fix, false, s.getJSDocTags(exportStart));
54
+ s.addExport(name, SYMBOL_TYPE.UNKNOWN, p.value.start, [], undefined, false, s.getJSDocTags(exportStart));
57
55
  if (declarator.init)
58
56
  s.collectRefsInType(declarator.init, name, false);
59
57
  s.destructuredExports.add(name);
60
58
  }
61
59
  else if (p.value?.type === 'AssignmentPattern' && p.value.left?.type === 'Identifier') {
62
60
  const name = p.value.left.name;
63
- const fix = s.options.isFixExports ? [p.start, p.end, FIX_FLAGS.OBJECT_BINDING] : undefined;
64
- s.addExport(name, SYMBOL_TYPE.UNKNOWN, p.value.left.start, [], fix, false, s.getJSDocTags(exportStart));
61
+ s.addExport(name, SYMBOL_TYPE.UNKNOWN, p.value.left.start, [], undefined, false, s.getJSDocTags(exportStart));
65
62
  if (declarator.init)
66
63
  s.collectRefsInType(declarator.init, name, false);
67
64
  s.destructuredExports.add(name);
@@ -71,15 +68,13 @@ export function handleExportNamed(node, s) {
71
68
  else if (declarator.id.type === 'ArrayPattern') {
72
69
  for (const el of declarator.id.elements) {
73
70
  if (el?.type === 'Identifier') {
74
- const fix = s.options.isFixExports ? [el.start, el.end, FIX_FLAGS.NONE] : undefined;
75
- s.addExport(el.name, SYMBOL_TYPE.UNKNOWN, el.start, [], fix, false, s.getJSDocTags(exportStart));
71
+ s.addExport(el.name, SYMBOL_TYPE.UNKNOWN, el.start, [], undefined, false, s.getJSDocTags(exportStart));
76
72
  if (declarator.init)
77
73
  s.collectRefsInType(declarator.init, el.name, false);
78
74
  s.destructuredExports.add(el.name);
79
75
  }
80
76
  else if (el?.type === 'RestElement' && el.argument?.type === 'Identifier') {
81
- const fix = s.options.isFixExports ? [el.start, el.end, FIX_FLAGS.NONE] : undefined;
82
- s.addExport(el.argument.name, SYMBOL_TYPE.UNKNOWN, el.argument.start, [], fix, false, s.getJSDocTags(exportStart));
77
+ s.addExport(el.argument.name, SYMBOL_TYPE.UNKNOWN, el.argument.start, [], undefined, false, s.getJSDocTags(exportStart));
83
78
  if (declarator.init)
84
79
  s.collectRefsInType(declarator.init, el.argument.name, false);
85
80
  s.destructuredExports.add(el.argument.name);
@@ -275,7 +270,10 @@ export function handleExportDefault(node, s) {
275
270
  if (_import) {
276
271
  const internalImport = s.internal.get(_import.filePath);
277
272
  if (internalImport) {
278
- if (_import.importedName !== 'default') {
273
+ if (_import.isNamespace) {
274
+ addValue(internalImport.reExportNs, 'default', s.filePath);
275
+ }
276
+ else if (_import.importedName !== 'default') {
279
277
  addNsValue(internalImport.reExportAs, _import.importedName, 'default', s.filePath);
280
278
  }
281
279
  else {
@@ -337,21 +335,12 @@ export function handleExpressionStatement(node, s) {
337
335
  const left = expr.left;
338
336
  if (left.type !== 'MemberExpression')
339
337
  return;
340
- if (!left.computed && left.object.type === 'Identifier' && left.object.name === 'exports') {
341
- if (s.skipExports)
342
- return;
343
- const name = left.property.name;
344
- if (name) {
345
- const fix = s.options.isFixExports ? [node.start, node.end, FIX_FLAGS.NONE] : undefined;
346
- s.addExport(name, SYMBOL_TYPE.UNKNOWN, left.property.start, [], fix, false, EMPTY_TAGS);
347
- }
348
- return;
349
- }
350
- if (left.object.type === 'MemberExpression' &&
351
- !left.object.computed &&
352
- left.object.object.type === 'Identifier' &&
353
- left.object.object.name === 'module' &&
354
- left.object.property.name === 'exports') {
338
+ if ((left.object.type === 'Identifier' && left.object.name === 'exports') ||
339
+ (left.object.type === 'MemberExpression' &&
340
+ !left.object.computed &&
341
+ left.object.object.type === 'Identifier' &&
342
+ left.object.object.name === 'module' &&
343
+ left.object.property.name === 'exports')) {
355
344
  let exportName;
356
345
  if (!left.computed && left.property.type === 'Identifier') {
357
346
  exportName = left.property.name;
@@ -377,6 +366,7 @@ export function handleExpressionStatement(node, s) {
377
366
  if (memberName) {
378
367
  const alias = exportName !== memberName ? exportName : undefined;
379
368
  s.addImport(specifier, memberName, alias, undefined, right.object.arguments[0].start, IMPORT_FLAGS.RE_EXPORT);
369
+ s.handledImportExpressions.add(right.object.start);
380
370
  isReExport = true;
381
371
  }
382
372
  }
@@ -1,6 +1,7 @@
1
1
  import type { ArrayExpression, CallExpression, Expression, ImportExpression, VariableDeclarator } from 'oxc-parser';
2
2
  import type { WalkState } from './walk.ts';
3
+ export declare function markDynamicNamespaceOpaque(name: string, pos: number, s: WalkState): void;
3
4
  export declare function getPromiseAllElements(expression: Expression): ArrayExpression['elements'] | undefined;
4
- export declare function handleVariableDeclarator(node: VariableDeclarator, s: WalkState): void;
5
+ export declare function handleVariableDeclarator(node: VariableDeclarator, isVar: boolean, s: WalkState): void;
5
6
  export declare function handleImportThen(node: CallExpression, s: WalkState): void;
6
7
  export declare function handleImportExpression(node: ImportExpression, s: WalkState): void;
@@ -2,6 +2,26 @@ import { IMPORT_FLAGS, IMPORT_STAR, OPAQUE } from '../../constants.js';
2
2
  import { addValue } from '../../util/module-graph.js';
3
3
  import { isInNodeModules } from '../../util/path.js';
4
4
  import { getStringValue, isStringLiteral } from '../ast-nodes.js';
5
+ import { isShadowedIn } from './shadow.js';
6
+ export function markDynamicNamespaceOpaque(name, pos, s) {
7
+ const _import = s.localImportMap.get(name);
8
+ if (!_import?.isDynamicImport || !_import.isNamespace)
9
+ return;
10
+ if (isShadowedIn(s, name, pos))
11
+ return;
12
+ const internalImport = s.internal.get(_import.filePath);
13
+ if (internalImport)
14
+ addValue(internalImport.import, OPAQUE, s.filePath);
15
+ }
16
+ const getBlockScope = (s) => {
17
+ const i = s.scopeDepth - 1;
18
+ return i < 0 ? undefined : [s.scopeStarts[i], s.scopeEnds[i]];
19
+ };
20
+ const setDynamicNamespace = (name, filePath, scope, isVar, s) => {
21
+ if (scope && !isVar)
22
+ s.scopedImports.push({ name, end: scope[1], prev: s.localImportMap.get(name) });
23
+ s.localImportMap.set(name, { importedName: IMPORT_STAR, filePath, isNamespace: true, isDynamicImport: true, scope });
24
+ };
5
25
  export function getPromiseAllElements(expression) {
6
26
  if (expression.type === 'CallExpression' &&
7
27
  expression.callee.type === 'MemberExpression' &&
@@ -13,7 +33,7 @@ export function getPromiseAllElements(expression) {
13
33
  return expression.arguments[0].elements;
14
34
  }
15
35
  }
16
- export function handleVariableDeclarator(node, s) {
36
+ export function handleVariableDeclarator(node, isVar, s) {
17
37
  const init = node.init;
18
38
  if (!init)
19
39
  return;
@@ -26,7 +46,7 @@ export function handleVariableDeclarator(node, s) {
26
46
  }
27
47
  if (importExpr && isStringLiteral(importExpr.source)) {
28
48
  const caughtFlag = init.type === 'AwaitExpression' && s.caughtTryBlockEnds.length > 0 ? IMPORT_FLAGS.CAUGHT : IMPORT_FLAGS.NONE;
29
- handleDynamicImportBinding(node.id, importExpr, init.type === 'AwaitExpression', caughtFlag, s);
49
+ handleDynamicImportBinding(node.id, importExpr, init.type === 'AwaitExpression', caughtFlag, getBlockScope(s), isVar, s);
30
50
  return;
31
51
  }
32
52
  if (init.type === 'CallExpression' &&
@@ -89,12 +109,7 @@ export function handleVariableDeclarator(node, s) {
89
109
  s.addImport(specifier, 'default', binding.name, undefined, imp.source.start, IMPORT_FLAGS.DYNAMIC | caughtFlag);
90
110
  const resolved = s.resolveModule(specifier, s.filePath);
91
111
  if (resolved && !resolved.isExternalLibraryImport && !isInNodeModules(resolved.resolvedFileName)) {
92
- s.localImportMap.set(binding.name, {
93
- importedName: IMPORT_STAR,
94
- filePath: resolved.resolvedFileName,
95
- isNamespace: true,
96
- isDynamicImport: true,
97
- });
112
+ setDynamicNamespace(binding.name, resolved.resolvedFileName, getBlockScope(s), isVar, s);
98
113
  }
99
114
  }
100
115
  else {
@@ -108,12 +123,18 @@ export function handleVariableDeclarator(node, s) {
108
123
  const registerAlias = (expr) => {
109
124
  if (expr?.type === 'Identifier') {
110
125
  const _import = s.localImportMap.get(expr.name);
126
+ if (_import?.isDynamicImport && isShadowedIn(s, expr.name, expr.start))
127
+ return;
111
128
  if (_import) {
112
- s.addImportAlias(aliasName, expr.name, _import.filePath);
129
+ s.addImportAlias(aliasName, expr.name, _import);
113
130
  if (_import.isNamespace) {
114
131
  const internalImport = s.internal.get(_import.filePath);
115
- if (internalImport)
116
- internalImport.refs.add(expr.name);
132
+ if (internalImport) {
133
+ if (_import.isDynamicImport)
134
+ addValue(internalImport.import, OPAQUE, s.filePath);
135
+ else
136
+ internalImport.refs.add(expr.name);
137
+ }
117
138
  }
118
139
  }
119
140
  }
@@ -129,8 +150,8 @@ export function handleVariableDeclarator(node, s) {
129
150
  for (const prop of init.properties) {
130
151
  if (prop.type === 'SpreadElement' && prop.argument?.type === 'Identifier') {
131
152
  const _import = s.localImportMap.get(prop.argument.name);
132
- if (_import) {
133
- s.addImportAlias(aliasName, prop.argument.name, _import.filePath);
153
+ if (_import && !(_import.isDynamicImport && isShadowedIn(s, prop.argument.name, prop.argument.start))) {
154
+ s.addImportAlias(aliasName, prop.argument.name, _import);
134
155
  if (_import.isNamespace) {
135
156
  const internalImport = s.internal.get(_import.filePath);
136
157
  if (internalImport)
@@ -144,7 +165,7 @@ export function handleVariableDeclarator(node, s) {
144
165
  prop.key?.type === 'Identifier') {
145
166
  const nsName = prop.value.name;
146
167
  const _import = s.localImportMap.get(nsName);
147
- if (_import?.isNamespace) {
168
+ if (_import?.isNamespace && !(_import.isDynamicImport && isShadowedIn(s, nsName, prop.value.start))) {
148
169
  const internalImport = s.internal.get(_import.filePath);
149
170
  if (internalImport)
150
171
  internalImport.refs.add(nsName);
@@ -153,7 +174,7 @@ export function handleVariableDeclarator(node, s) {
153
174
  map = new Map();
154
175
  s.nsContainers.set(aliasName, map);
155
176
  }
156
- map.set(prop.key.name, nsName);
177
+ map.set(prop.key.name, { id: nsName, import: _import });
157
178
  }
158
179
  }
159
180
  }
@@ -222,7 +243,7 @@ export function handleVariableDeclarator(node, s) {
222
243
  internalImport.refs.add(defaultValue.name);
223
244
  }
224
245
  if (prop.value.left?.type === 'Identifier') {
225
- s.addImportAlias(prop.value.left.name, defaultValue.name, _import.filePath);
246
+ s.addImportAlias(prop.value.left.name, defaultValue.name, _import);
226
247
  }
227
248
  }
228
249
  }
@@ -230,7 +251,7 @@ export function handleVariableDeclarator(node, s) {
230
251
  }
231
252
  }
232
253
  }
233
- function handleDynamicImportBinding(id, importExpr, isAwaited, caughtFlag, s) {
254
+ function handleDynamicImportBinding(id, importExpr, isAwaited, caughtFlag, scope, isVar, s) {
234
255
  s.handledImportExpressions.add(importExpr.start);
235
256
  const specifier = getStringValue(importExpr.source);
236
257
  if (id.type === 'ObjectPattern') {
@@ -255,12 +276,7 @@ function handleDynamicImportBinding(id, importExpr, isAwaited, caughtFlag, s) {
255
276
  s.addImport(specifier, 'default', id.name, undefined, importExpr.source.start, IMPORT_FLAGS.DYNAMIC | caughtFlag);
256
277
  const resolved = s.resolveModule(specifier, s.filePath);
257
278
  if (resolved && !resolved.isExternalLibraryImport && !isInNodeModules(resolved.resolvedFileName)) {
258
- s.localImportMap.set(id.name, {
259
- importedName: IMPORT_STAR,
260
- filePath: resolved.resolvedFileName,
261
- isNamespace: true,
262
- isDynamicImport: true,
263
- });
279
+ setDynamicNamespace(id.name, resolved.resolvedFileName, scope, isVar, s);
264
280
  }
265
281
  }
266
282
  else {
@@ -284,7 +300,8 @@ export function handleImportThen(node, s) {
284
300
  if (param?.type !== 'Identifier' && param?.type !== 'ObjectPattern')
285
301
  return;
286
302
  const caughtFlag = s.caughtImportExpressions.has(callee.object.start) ? IMPORT_FLAGS.CAUGHT : IMPORT_FLAGS.NONE;
287
- handleDynamicImportBinding(param, callee.object, true, caughtFlag, s);
303
+ const body = fn.body ?? fn;
304
+ handleDynamicImportBinding(param, callee.object, true, caughtFlag, [body.start, body.end], false, s);
288
305
  }
289
306
  export function handleImportExpression(node, s) {
290
307
  if (s.handledImportExpressions.has(node.start))
@@ -1,4 +1,4 @@
1
1
  import type { MemberExpression, JSXMemberExpression } from 'oxc-parser';
2
- import { type WalkState } from './walk.ts';
2
+ import type { WalkState } from './walk.ts';
3
3
  export declare function handleMemberExpression(node: MemberExpression, s: WalkState): void;
4
4
  export declare function handleJSXMemberExpression(node: JSXMemberExpression, s: WalkState): void;
@@ -1,7 +1,7 @@
1
- import { OPAQUE } from '../../constants.js';
1
+ import { IMPORT_FLAGS, OPAQUE } from '../../constants.js';
2
2
  import { addValue } from '../../util/module-graph.js';
3
3
  import { getStringValue, isStringLiteral } from '../ast-nodes.js';
4
- import { isShadowed } from './walk.js';
4
+ import { isShadowedIn } from './shadow.js';
5
5
  const chainNames = [];
6
6
  function markWholeObjectRead(internalImport, id) {
7
7
  (internalImport.enumerated ??= new Set()).add(id);
@@ -10,6 +10,24 @@ function isNumericKey(value) {
10
10
  return value != null && Number.isFinite(Number(value)) && String(Number(value)) === value;
11
11
  }
12
12
  export function handleMemberExpression(node, s) {
13
+ if (node.object.type === 'CallExpression' &&
14
+ node.object.callee.type === 'Identifier' &&
15
+ node.object.callee.name === 'require' &&
16
+ node.object.arguments.length === 1 &&
17
+ isStringLiteral(node.object.arguments[0]) &&
18
+ !s.handledImportExpressions.has(node.object.start)) {
19
+ let memberName;
20
+ if (!node.computed && node.property.type === 'Identifier')
21
+ memberName = node.property.name;
22
+ else if (node.computed && isStringLiteral(node.property))
23
+ memberName = getStringValue(node.property);
24
+ if (memberName) {
25
+ const specifier = getStringValue(node.object.arguments[0]);
26
+ const reqTags = s.currentVarDeclStart >= 0 ? s.getJSDocTags(s.currentVarDeclStart) : undefined;
27
+ s.addImport(specifier, memberName, undefined, undefined, node.object.arguments[0].start, IMPORT_FLAGS.NONE, undefined, reqTags);
28
+ }
29
+ return;
30
+ }
13
31
  if (node.object.type === 'MemberExpression' &&
14
32
  node.object.object.type === 'MemberExpression' &&
15
33
  !node.computed &&
@@ -18,7 +36,7 @@ export function handleMemberExpression(node, s) {
18
36
  }
19
37
  if (node.object.type === 'Identifier') {
20
38
  const localName = node.object.name;
21
- const shadowed = isShadowed(localName, node.object.start);
39
+ const shadowed = isShadowedIn(s, localName, node.object.start);
22
40
  const _import = !shadowed ? s.localImportMap.get(localName) : undefined;
23
41
  if (_import) {
24
42
  const internalImport = s.internal.get(_import.filePath);
@@ -78,12 +96,11 @@ export function handleMemberExpression(node, s) {
78
96
  isWholeRead = true;
79
97
  }
80
98
  for (const alias of aliases) {
81
- const internalImport = s.internal.get(alias.filePath);
99
+ const internalImport = s.internal.get(alias.import.filePath);
82
100
  if (!internalImport)
83
101
  continue;
84
102
  if (isWholeRead) {
85
- const origin = s.localImportMap.get(alias.id);
86
- markWholeObjectRead(internalImport, origin?.importedName ?? alias.id);
103
+ markWholeObjectRead(internalImport, alias.import.importedName);
87
104
  }
88
105
  else if (memberName) {
89
106
  s.addNsMemberRefs(internalImport, alias.id, memberName);
@@ -97,7 +114,7 @@ export function handleMemberExpression(node, s) {
97
114
  node.object.object.type === 'Identifier' &&
98
115
  node.object.property.type === 'Identifier') {
99
116
  const rootName = node.object.object.name;
100
- if (!isShadowed(rootName, node.object.object.start)) {
117
+ if (!isShadowedIn(s, rootName, node.object.object.start)) {
101
118
  const _import = s.localImportMap.get(rootName);
102
119
  if (_import?.isNamespace) {
103
120
  const internalImport = s.internal.get(_import.filePath);
@@ -119,7 +136,7 @@ export function handleMemberExpression(node, s) {
119
136
  !node.computed &&
120
137
  node.property.type === 'Identifier') {
121
138
  const rootName = node.object.object.name;
122
- if (!isShadowed(rootName, node.object.object.start)) {
139
+ if (!isShadowedIn(s, rootName, node.object.object.start)) {
123
140
  const _import = s.localImportMap.get(rootName);
124
141
  if (_import) {
125
142
  const internalImport = s.internal.get(_import.filePath);
@@ -155,7 +172,7 @@ export function handleMemberExpression(node, s) {
155
172
  chainNames.push(root.property.name);
156
173
  root = root.object;
157
174
  }
158
- if (root.type === 'Identifier' && !isShadowed(root.name, root.start)) {
175
+ if (root.type === 'Identifier' && !isShadowedIn(s, root.name, root.start)) {
159
176
  const _import = s.localImportMap.get(root.name);
160
177
  const internalImport = _import && s.internal.get(_import.filePath);
161
178
  if (internalImport || !_import) {
@@ -176,21 +193,18 @@ export function handleMemberExpression(node, s) {
176
193
  node.object.property.type === 'Identifier') {
177
194
  const containerName = node.object.object.name;
178
195
  const propKey = node.object.property.name;
179
- const nsName = s.nsContainers.get(containerName)?.get(propKey);
180
- if (nsName) {
181
- const _import = s.localImportMap.get(nsName);
182
- if (_import) {
183
- const internalImport = s.internal.get(_import.filePath);
184
- if (internalImport) {
185
- let memberName;
186
- if (!node.computed && node.property.type === 'Identifier')
187
- memberName = node.property.name;
188
- else if (node.computed && isStringLiteral(node.property))
189
- memberName = getStringValue(node.property);
190
- if (memberName) {
191
- s.addNsMemberRefs(internalImport, nsName, memberName);
192
- s.accessedNsContainers.add(`${containerName}.${propKey}`);
193
- }
196
+ const ref = s.nsContainers.get(containerName)?.get(propKey);
197
+ if (ref) {
198
+ const internalImport = s.internal.get(ref.import.filePath);
199
+ if (internalImport) {
200
+ let memberName;
201
+ if (!node.computed && node.property.type === 'Identifier')
202
+ memberName = node.property.name;
203
+ else if (node.computed && isStringLiteral(node.property))
204
+ memberName = getStringValue(node.property);
205
+ if (memberName) {
206
+ s.addNsMemberRefs(internalImport, ref.id, memberName);
207
+ s.accessedNsContainers.add(`${containerName}.${propKey}`);
194
208
  }
195
209
  }
196
210
  }
@@ -0,0 +1,2 @@
1
+ import type { WalkState } from './walk.ts';
2
+ export declare const isShadowedIn: (s: WalkState, name: string, pos: number) => boolean;
@@ -0,0 +1,25 @@
1
+ export const isShadowedIn = (s, name, pos) => {
2
+ if (s.shadowScopes.size === 0)
3
+ return false;
4
+ const ranges = s.shadowScopes.get(name);
5
+ if (!ranges)
6
+ return false;
7
+ const scope = s.localImportMap.get(name)?.scope;
8
+ if (scope) {
9
+ for (let i = ranges.length - 1; i >= 0; i--) {
10
+ const range = ranges[i];
11
+ if (range[0] < scope[0])
12
+ break;
13
+ if (range[0] === scope[0] && range[1] >= scope[1])
14
+ continue;
15
+ if (pos >= range[0] && pos < range[1])
16
+ return true;
17
+ }
18
+ return false;
19
+ }
20
+ for (const range of ranges) {
21
+ if (pos >= range[0] && pos < range[1])
22
+ return true;
23
+ }
24
+ return false;
25
+ };
@@ -5,6 +5,17 @@ import type { Fix } from '../../types/exports.ts';
5
5
  import type { IssueSymbol, SymbolType } from '../../types/issues.ts';
6
6
  import type { Export, ExportMember, ImportMap, ImportMaps } from '../../types/module-graph.ts';
7
7
  import { type ResolveModule } from '../ast-nodes.ts';
8
+ export type LocalImport = {
9
+ importedName: string;
10
+ filePath: string;
11
+ isNamespace: boolean;
12
+ isDynamicImport?: boolean;
13
+ scope?: [number, number];
14
+ };
15
+ export type LocalImportRef = {
16
+ id: string;
17
+ import: LocalImport;
18
+ };
8
19
  interface WalkContext {
9
20
  lineStarts: number[];
10
21
  skipExports: boolean;
@@ -15,19 +26,11 @@ interface WalkContext {
15
26
  scripts: Set<string>;
16
27
  addImport: (specifier: string, identifier: string | undefined, alias: string | undefined, namespace: string | undefined, pos: number, modifiers: number, specifierPos?: number, jsDocTags?: Set<string>) => void;
17
28
  addNsMemberRefs: (internalImport: ImportMaps, namespace: string, member: string | string[]) => void;
18
- addImportAlias: (aliasName: string, id: string, filePath: string) => void;
29
+ addImportAlias: (aliasName: string, id: string, _import: LocalImport) => void;
19
30
  internal: ImportMap;
20
- localImportMap: Map<string, {
21
- importedName: string;
22
- filePath: string;
23
- isNamespace: boolean;
24
- isDynamicImport?: boolean;
25
- }>;
31
+ localImportMap: Map<string, LocalImport>;
26
32
  localDeclarationTypes: Map<string, SymbolType>;
27
- importAliases: Map<string, Set<{
28
- id: string;
29
- filePath: string;
30
- }>>;
33
+ importAliases: Map<string, Set<LocalImportRef>>;
31
34
  referencedInExport: Map<string, Set<string>>;
32
35
  skipBareExprRefs: boolean;
33
36
  localRefs: Set<string> | undefined;
@@ -58,7 +61,7 @@ export interface WalkState extends WalkContext {
58
61
  functionCaughtTryBlockEnds: number[][];
59
62
  bareExprRefs: Set<string>;
60
63
  accessedAliases: Set<string>;
61
- nsContainers: Map<string, Map<string, string>>;
64
+ nsContainers: Map<string, Map<string, LocalImportRef>>;
62
65
  accessedNsContainers: Set<string>;
63
66
  chainedMemberExprs: WeakSet<object>;
64
67
  currentVarDeclStart: number;
@@ -69,6 +72,11 @@ export interface WalkState extends WalkContext {
69
72
  scopeStarts: number[];
70
73
  scopeEnds: number[];
71
74
  shadowScopes: Map<string, [number, number][]>;
75
+ scopedImports: {
76
+ name: string;
77
+ end: number;
78
+ prev: LocalImport | undefined;
79
+ }[];
72
80
  localDeclarations: Map<string, FunctionNode | Class | VariableDeclarator>;
73
81
  localInterfaces: Map<string, TSInterfaceDeclaration | null>;
74
82
  pendingCallRefs: Array<{