knip 6.14.2 → 6.16.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.
Files changed (111) hide show
  1. package/dist/CacheConsultant.d.ts +1 -0
  2. package/dist/CacheConsultant.js +2 -0
  3. package/dist/ConfigurationChief.d.ts +32 -0
  4. package/dist/ConfigurationChief.js +9 -11
  5. package/dist/DependencyDeputy.d.ts +0 -4
  6. package/dist/DependencyDeputy.js +4 -16
  7. package/dist/IssueCollector.d.ts +1 -0
  8. package/dist/IssueCollector.js +10 -20
  9. package/dist/IssueFixer.js +10 -15
  10. package/dist/ProjectPrincipal.d.ts +2 -3
  11. package/dist/ProjectPrincipal.js +13 -21
  12. package/dist/WorkspaceWorker.js +6 -1
  13. package/dist/binaries/fallback.js +1 -1
  14. package/dist/binaries/plugins.js +1 -1
  15. package/dist/binaries/resolvers/bun.js +1 -1
  16. package/dist/binaries/resolvers/bunx.js +1 -1
  17. package/dist/binaries/resolvers/npm.js +1 -1
  18. package/dist/binaries/resolvers/npx.js +1 -1
  19. package/dist/binaries/resolvers/pnpm.js +1 -1
  20. package/dist/binaries/resolvers/pnpx.js +1 -1
  21. package/dist/binaries/resolvers/yarn.js +1 -1
  22. package/dist/binaries/util.d.ts +1 -2
  23. package/dist/binaries/util.js +1 -1
  24. package/dist/cli.js +3 -1
  25. package/dist/compilers/compilers.d.ts +3 -0
  26. package/dist/compilers/compilers.js +9 -13
  27. package/dist/compilers/index.d.ts +52 -0
  28. package/dist/compilers/scss.js +9 -3
  29. package/dist/graph/analyze.js +15 -8
  30. package/dist/graph/build.js +3 -5
  31. package/dist/manifest/index.js +11 -14
  32. package/dist/plugins/_custom-elements/custom-element-visitor.d.ts +7 -0
  33. package/dist/plugins/_custom-elements/custom-element-visitor.js +106 -0
  34. package/dist/plugins/bun/index.js +1 -1
  35. package/dist/plugins/catalyst/index.d.ts +3 -0
  36. package/dist/plugins/catalyst/index.js +16 -0
  37. package/dist/plugins/execa/visitors/execa.js +4 -17
  38. package/dist/plugins/fast/index.d.ts +3 -0
  39. package/dist/plugins/fast/index.js +16 -0
  40. package/dist/plugins/index.d.ts +5 -0
  41. package/dist/plugins/index.js +10 -0
  42. package/dist/plugins/lit/index.d.ts +3 -0
  43. package/dist/plugins/lit/index.js +25 -0
  44. package/dist/plugins/nano-spawn/index.d.ts +3 -0
  45. package/dist/plugins/nano-spawn/index.js +15 -0
  46. package/dist/plugins/nano-spawn/visitors/nano-spawn.d.ts +2 -0
  47. package/dist/plugins/nano-spawn/visitors/nano-spawn.js +12 -0
  48. package/dist/plugins/orval/index.d.ts +3 -0
  49. package/dist/plugins/orval/index.js +16 -0
  50. package/dist/plugins/orval/resolveFromAST.d.ts +2 -0
  51. package/dist/plugins/orval/resolveFromAST.js +11 -0
  52. package/dist/plugins/orval/types.d.ts +9 -0
  53. package/dist/plugins/orval/types.js +1 -0
  54. package/dist/plugins/relay/index.js +1 -1
  55. package/dist/plugins/stencil/index.js +17 -1
  56. package/dist/plugins/sveltejs-package/helpers.js +1 -1
  57. package/dist/plugins/vite/helpers.js +23 -6
  58. package/dist/plugins/webdriver-io/index.js +3 -3
  59. package/dist/plugins/webdriver-io/types.d.ts +5 -1
  60. package/dist/reporters/github-actions.d.ts +1 -1
  61. package/dist/reporters/github-actions.js +19 -1
  62. package/dist/reporters/index.d.ts +1 -1
  63. package/dist/reporters/symbols.js +2 -1
  64. package/dist/reporters/trace.d.ts +3 -1
  65. package/dist/reporters/trace.js +48 -16
  66. package/dist/reporters/util/configuration-hints.d.ts +1 -1
  67. package/dist/reporters/util/configuration-hints.js +3 -2
  68. package/dist/schema/configuration.d.ts +83 -1
  69. package/dist/schema/configuration.js +2 -0
  70. package/dist/schema/plugins.d.ts +25 -0
  71. package/dist/schema/plugins.js +5 -0
  72. package/dist/types/PluginNames.d.ts +2 -2
  73. package/dist/types/PluginNames.js +5 -0
  74. package/dist/types/args.d.ts +1 -1
  75. package/dist/types/config.d.ts +2 -0
  76. package/dist/types/issues.d.ts +1 -0
  77. package/dist/types/module-graph.d.ts +1 -0
  78. package/dist/types/project.d.ts +0 -1
  79. package/dist/typescript/ast-helpers.js +21 -20
  80. package/dist/typescript/ast-nodes.d.ts +1 -0
  81. package/dist/typescript/ast-nodes.js +19 -0
  82. package/dist/typescript/get-imports-and-exports.js +18 -2
  83. package/dist/typescript/resolve-module-names.d.ts +6 -2
  84. package/dist/typescript/resolve-module-names.js +20 -29
  85. package/dist/typescript/visitors/calls.d.ts +3 -2
  86. package/dist/typescript/visitors/calls.js +88 -16
  87. package/dist/typescript/visitors/exports.js +12 -0
  88. package/dist/typescript/visitors/walk.d.ts +7 -0
  89. package/dist/typescript/visitors/walk.js +43 -1
  90. package/dist/util/Performance.d.ts +13 -28
  91. package/dist/util/Performance.js +41 -72
  92. package/dist/util/cli-arguments.d.ts +3 -1
  93. package/dist/util/cli-arguments.js +4 -0
  94. package/dist/util/create-options.d.ts +53 -0
  95. package/dist/util/create-options.js +2 -1
  96. package/dist/util/disk-cache.d.ts +1 -0
  97. package/dist/util/disk-cache.js +8 -0
  98. package/dist/util/gitignore-cache.js +5 -11
  99. package/dist/util/glob-cache.js +2 -8
  100. package/dist/util/glob-core.js +4 -7
  101. package/dist/util/jiti.js +1 -0
  102. package/dist/util/load-tsconfig.js +0 -3
  103. package/dist/util/parse-args.d.ts +14 -0
  104. package/dist/util/parse-args.js +112 -0
  105. package/dist/util/trace.js +1 -1
  106. package/dist/version.d.ts +1 -1
  107. package/dist/version.js +1 -1
  108. package/package.json +3 -6
  109. package/schema.json +73 -43
  110. package/dist/util/math.d.ts +0 -6
  111. package/dist/util/math.js +0 -11
@@ -9,6 +9,8 @@ import { extractImportsFromComments } from './comments.js';
9
9
  import { _parseFile, buildLineStarts, getLineAndCol, shouldCountRefs, } from './ast-nodes.js';
10
10
  import { buildJSDocTagLookup } from './visitors/jsdoc.js';
11
11
  import { _walkAST } from './visitors/walk.js';
12
+ const EMPTY_CHILD_PROCESS_NAMES = new Set();
13
+ const EMPTY_CHILD_PROCESS_METHODS = new Map();
12
14
  const getImportsAndExports = (filePath, sourceText, resolveModule, options, ignoreExportsUsedInFile, skipExportsForFile, visitor, pluginCtx, cachedParseResult) => {
13
15
  const skipExports = skipExportsForFile || !options.isReportExports;
14
16
  const isDts = filePath.endsWith('.d.ts') || filePath.endsWith('.d.cts') || filePath.endsWith('.d.mts');
@@ -34,6 +36,7 @@ const getImportsAndExports = (filePath, sourceText, resolveModule, options, igno
34
36
  const localDeclarationTypes = new Map();
35
37
  const referencedInExport = new Map();
36
38
  const destructuredExports = new Set();
39
+ const registeredCustomElements = new Set();
37
40
  const addNsMemberRefs = (internalImport, namespace, member) => {
38
41
  if (typeof member === 'string') {
39
42
  internalImport.refs.add(`${namespace}.${member}`);
@@ -167,15 +170,18 @@ const getImportsAndExports = (filePath, sourceText, resolveModule, options, igno
167
170
  let hasChildProcessImport = false;
168
171
  let hasPathJoinImport = false;
169
172
  let hasPathResolveImport = false;
173
+ let childProcessNamespaces;
174
+ let childProcessMethods;
170
175
  for (const _imports of result.module.staticImports) {
171
176
  const specifier = _imports.moduleRequest.value;
177
+ const isPathImport = specifier === 'node:path' || specifier === 'path';
178
+ const isChildProcessImport = specifier === 'node:child_process' || specifier === 'child_process';
172
179
  if (specifier === 'node:module' || specifier === 'module')
173
180
  hasNodeModuleImport = true;
174
181
  else if (specifier === 'node:worker_threads' || specifier === 'worker_threads')
175
182
  hasWorkerThreadsImport = true;
176
- else if (specifier === 'node:child_process' || specifier === 'child_process')
183
+ else if (isChildProcessImport)
177
184
  hasChildProcessImport = true;
178
- const isPathImport = specifier === 'node:path' || specifier === 'path';
179
185
  const pos = _imports.moduleRequest.start;
180
186
  const jsdocTags = getJSDocTags(_imports.start);
181
187
  if (_imports.entries.length === 0) {
@@ -190,12 +196,16 @@ const getImportsAndExports = (filePath, sourceText, resolveModule, options, igno
190
196
  const modifiers = entry.isType ? IMPORT_FLAGS.TYPE_ONLY : IMPORT_FLAGS.NONE;
191
197
  if (entry.importName.kind === 'NamespaceObject') {
192
198
  const localName = entry.localName.value;
199
+ if (isChildProcessImport)
200
+ (childProcessNamespaces ??= new Set()).add(localName);
193
201
  addImport(specifier, IMPORT_STAR, localName, undefined, entry.localName.start, modifiers, pos, jsdocTags, resolved);
194
202
  if (internalPath)
195
203
  localImportMap.set(localName, { importedName: IMPORT_STAR, filePath: internalPath, isNamespace: true });
196
204
  }
197
205
  else if (entry.importName.kind === 'Default') {
198
206
  const localName = entry.localName.value;
207
+ if (isChildProcessImport)
208
+ (childProcessNamespaces ??= new Set()).add(localName);
199
209
  const alias = localName !== 'default' ? localName : undefined;
200
210
  addImport(specifier, 'default', alias, undefined, entry.localName.start, modifiers, pos, jsdocTags, resolved);
201
211
  if (internalPath)
@@ -205,6 +215,8 @@ const getImportsAndExports = (filePath, sourceText, resolveModule, options, igno
205
215
  const importedName = entry.importName.name;
206
216
  const localName = entry.localName.value;
207
217
  const alias = localName !== importedName ? localName : undefined;
218
+ if (isChildProcessImport)
219
+ (childProcessMethods ??= new Map()).set(localName, importedName);
208
220
  if (isPathImport && !alias) {
209
221
  if (importedName === 'join')
210
222
  hasPathJoinImport = true;
@@ -254,6 +266,7 @@ const getImportsAndExports = (filePath, sourceText, resolveModule, options, igno
254
266
  pluginCtx.sourceText = sourceText;
255
267
  pluginCtx.addScript = (s) => scripts.add(s);
256
268
  pluginCtx.addImport = (spec, pos, mod) => addImport(spec, undefined, undefined, undefined, pos, mod);
269
+ pluginCtx.markExportRegistered = (name) => registeredCustomElements.add(name);
257
270
  }
258
271
  const localRefs = _walkAST(result.program, sourceText, filePath, {
259
272
  lineStarts,
@@ -277,6 +290,9 @@ const getImportsAndExports = (filePath, sourceText, resolveModule, options, igno
277
290
  hasNodeModuleImport,
278
291
  hasWorkerThreadsImport,
279
292
  hasChildProcessImport,
293
+ childProcessNamespaces: childProcessNamespaces ?? EMPTY_CHILD_PROCESS_NAMES,
294
+ childProcessMethods: childProcessMethods ?? EMPTY_CHILD_PROCESS_METHODS,
295
+ registeredCustomElements,
280
296
  hasPathJoinImport,
281
297
  hasPathResolveImport,
282
298
  resolveModule,
@@ -1,7 +1,11 @@
1
1
  import type { ToSourceFilePath, WorkspaceManifestHandler } from '../util/to-source-path.ts';
2
2
  import type { ResolveModule } from './ast-nodes.ts';
3
+ type ScopedPaths = Array<{
4
+ scope: string;
5
+ paths: Record<string, string[]>;
6
+ }>;
3
7
  export declare function clearModuleResolutionCaches(): void;
4
8
  export declare function createCustomModuleResolver(compilerOptions: {
5
- paths?: Record<string, string[]>;
6
- rootDirs?: string[];
9
+ scopedPaths?: ScopedPaths;
7
10
  }, customCompilerExtensions: string[], toSourceFilePath: ToSourceFilePath, findWorkspaceManifestImports?: WorkspaceManifestHandler): ResolveModule;
11
+ export {};
@@ -27,28 +27,32 @@ export function clearModuleResolutionCaches() {
27
27
  for (const cache of moduleResolutionCaches)
28
28
  cache.clear();
29
29
  }
30
- function compilePathMappings(paths) {
31
- if (!paths)
30
+ function compilePathMappings(scopedPaths) {
31
+ if (!scopedPaths)
32
32
  return undefined;
33
33
  const mappings = [];
34
- for (const key in paths) {
35
- const starIdx = key.indexOf('*');
36
- if (starIdx >= 0) {
37
- mappings.push({ prefix: key.slice(0, starIdx), wildcard: true, values: paths[key] });
38
- }
39
- else {
40
- mappings.push({ prefix: key, wildcard: false, values: paths[key] });
34
+ for (const { scope, paths } of scopedPaths) {
35
+ for (const key in paths) {
36
+ const starIndex = key.indexOf('*');
37
+ if (starIndex >= 0) {
38
+ mappings.push({ prefix: key.slice(0, starIndex), wildcard: true, values: paths[key], scope });
39
+ }
40
+ else {
41
+ mappings.push({ prefix: key, wildcard: false, values: paths[key], scope });
42
+ }
41
43
  }
42
44
  }
43
- return mappings.length > 0 ? mappings : undefined;
45
+ if (mappings.length === 0)
46
+ return undefined;
47
+ mappings.sort((a, b) => b.scope.length - a.scope.length);
48
+ return mappings;
44
49
  }
45
50
  export function createCustomModuleResolver(compilerOptions, customCompilerExtensions, toSourceFilePath, findWorkspaceManifestImports) {
46
51
  const customCompilerExtensionsSet = new Set(customCompilerExtensions);
47
52
  const hasCustomExts = customCompilerExtensionsSet.size > 0;
48
53
  const extensions = [...DEFAULT_EXTENSIONS, ...customCompilerExtensions, ...DTS_EXTENSIONS];
49
54
  const resolveSync = hasCustomExts ? _createSyncModuleResolver(extensions) : _resolveModuleSync;
50
- const pathMappings = compilePathMappings(compilerOptions.paths);
51
- const rootDirs = compilerOptions.rootDirs;
55
+ const pathMappings = compilePathMappings(compilerOptions.scopedPaths);
52
56
  function toSourcePath(resolvedFileName) {
53
57
  if (!hasCustomExts || !customCompilerExtensionsSet.has(extname(resolvedFileName))) {
54
58
  return toSourceFilePath(resolvedFileName) || resolvedFileName;
@@ -87,7 +91,10 @@ export function createCustomModuleResolver(compilerOptions, customCompilerExtens
87
91
  if (resolvedFileName)
88
92
  return toResult(resolvedFileName);
89
93
  if (pathMappings) {
90
- for (const { prefix, wildcard, values } of pathMappings) {
94
+ const dir = dirname(containingFile);
95
+ for (const { prefix, wildcard, values, scope } of pathMappings) {
96
+ if (dir !== scope && !dir.startsWith(`${scope}/`))
97
+ continue;
91
98
  if (wildcard ? specifier.startsWith(prefix) : specifier === prefix) {
92
99
  const captured = wildcard ? specifier.slice(prefix.length) : '';
93
100
  for (const value of values) {
@@ -111,22 +118,6 @@ export function createCustomModuleResolver(compilerOptions, customCompilerExtens
111
118
  }
112
119
  }
113
120
  }
114
- if (rootDirs && !isAbsolute(specifier)) {
115
- const containingDir = dirname(containingFile);
116
- for (const srcRoot of rootDirs) {
117
- if (!containingDir.startsWith(srcRoot))
118
- continue;
119
- const relPath = containingDir.slice(srcRoot.length);
120
- for (const targetRoot of rootDirs) {
121
- if (targetRoot === srcRoot)
122
- continue;
123
- const mapped = join(targetRoot, relPath, specifier);
124
- const resolved = resolveSync(mapped, containingFile);
125
- if (resolved)
126
- return toResult(resolved);
127
- }
128
- }
129
- }
130
121
  const candidate = isAbsolute(specifier) ? specifier : join(dirname(containingFile), specifier);
131
122
  if (existsSync(candidate)) {
132
123
  return { resolvedFileName: candidate, isExternalLibraryImport: false };
@@ -1,4 +1,5 @@
1
- import type { CallExpression, NewExpression } from 'oxc-parser';
2
- import type { WalkState } from './walk.ts';
1
+ import type { CallExpression, NewExpression, VariableDeclarator } from 'oxc-parser';
2
+ import { type WalkState } from './walk.ts';
3
+ export declare function trackCustomElementRegistry(node: VariableDeclarator, s: WalkState): void;
3
4
  export declare function handleCallExpression(node: CallExpression, s: WalkState): void;
4
5
  export declare function handleNewExpression(node: NewExpression, s: WalkState): void;
@@ -1,6 +1,49 @@
1
1
  import { IMPORT_FLAGS, OPAQUE } from '../../constants.js';
2
2
  import { addValue } from '../../util/module-graph.js';
3
- import { getStringValue, isStringLiteral } from '../ast-nodes.js';
3
+ import { getSafeScriptFromArgs, getStringValue, isStringLiteral } from '../ast-nodes.js';
4
+ import { isShadowed } from './walk.js';
5
+ function getRegisteredCustomElement(node, s) {
6
+ const callee = node.callee;
7
+ if (callee.type !== 'MemberExpression' || callee.computed)
8
+ return undefined;
9
+ if (callee.property.type !== 'Identifier' || callee.property.name !== 'define')
10
+ return undefined;
11
+ const object = callee.object;
12
+ let isRegistry;
13
+ if (object.type === 'Identifier') {
14
+ isRegistry =
15
+ (object.name === 'customElements' || s.customElementRegistries.has(object.name)) &&
16
+ !isShadowed(object.name, object.start);
17
+ }
18
+ else {
19
+ isRegistry =
20
+ object.type === 'MemberExpression' &&
21
+ !object.computed &&
22
+ object.property.type === 'Identifier' &&
23
+ object.property.name === 'customElements';
24
+ }
25
+ if (!isRegistry)
26
+ return undefined;
27
+ const arg = node.arguments[1];
28
+ if (arg?.type === 'Identifier')
29
+ return isShadowed(arg.name, arg.start) ? undefined : arg.name;
30
+ if (arg?.type === 'ThisExpression' && s.staticBlockDepth > 0)
31
+ return s.classNameStack[s.classNameStack.length - 1] || undefined;
32
+ return undefined;
33
+ }
34
+ export function trackCustomElementRegistry(node, s) {
35
+ if (node.id.type !== 'Identifier' || !node.init)
36
+ return;
37
+ const init = node.init;
38
+ if ((init.type === 'Identifier' && init.name === 'customElements' && !isShadowed('customElements', init.start)) ||
39
+ (init.type === 'MemberExpression' &&
40
+ !init.computed &&
41
+ init.property.type === 'Identifier' &&
42
+ init.property.name === 'customElements') ||
43
+ (init.type === 'NewExpression' && init.callee.type === 'Identifier' && init.callee.name === 'CustomElementRegistry')) {
44
+ s.customElementRegistries.add(node.id.name);
45
+ }
46
+ }
4
47
  function extractInlineDirnamePath(node, s) {
5
48
  if (node?.type !== 'CallExpression')
6
49
  return undefined;
@@ -41,8 +84,28 @@ function extractInlineDirnamePath(node, s) {
41
84
  const joined = parts.join('/').replace(/\/+/g, '/');
42
85
  return joined.startsWith('.') || joined.startsWith('/') ? joined : `./${joined}`;
43
86
  }
44
- const CHILD_PROCESS_ENTRY_METHODS = new Set(['fork', 'spawn', 'execFile']);
87
+ const CHILD_PROCESS_FILE_METHODS = new Set(['fork', 'spawn', 'spawnSync', 'execFile', 'execFileSync']);
88
+ const CHILD_PROCESS_COMMAND_METHODS = new Set(['exec', 'execSync']);
89
+ function getChildProcessMethod(node, s) {
90
+ const callee = node.callee;
91
+ if (callee.type === 'Identifier')
92
+ return s.childProcessMethods.get(callee.name);
93
+ if (callee.type === 'MemberExpression' &&
94
+ !callee.computed &&
95
+ callee.object.type === 'Identifier' &&
96
+ callee.property.type === 'Identifier' &&
97
+ s.childProcessNamespaces.has(callee.object.name))
98
+ return callee.property.name;
99
+ return undefined;
100
+ }
45
101
  export function handleCallExpression(node, s) {
102
+ if (node.arguments.length >= 2) {
103
+ const registered = getRegisteredCustomElement(node, s);
104
+ if (registered) {
105
+ s.registeredCustomElements.add(registered);
106
+ return;
107
+ }
108
+ }
46
109
  if (node.callee.type === 'Identifier' &&
47
110
  node.callee.name === 'require' &&
48
111
  node.arguments.length === 1 &&
@@ -95,22 +158,31 @@ export function handleCallExpression(node, s) {
95
158
  }
96
159
  }
97
160
  if (s.hasChildProcessImport && node.arguments.length >= 1) {
98
- let isChildProcessEntry = false;
99
- if (node.callee.type === 'Identifier' && CHILD_PROCESS_ENTRY_METHODS.has(node.callee.name)) {
100
- isChildProcessEntry = true;
101
- }
102
- else if (node.callee.type === 'MemberExpression' &&
103
- !node.callee.computed &&
104
- node.callee.property.type === 'Identifier' &&
105
- CHILD_PROCESS_ENTRY_METHODS.has(node.callee.property.name)) {
106
- isChildProcessEntry = true;
107
- }
108
- if (isChildProcessEntry) {
109
- const specifier = extractInlineDirnamePath(node.arguments[0], s);
110
- if (specifier) {
111
- s.addImport(specifier, undefined, undefined, undefined, node.arguments[0].start, IMPORT_FLAGS.ENTRY);
161
+ const method = getChildProcessMethod(node, s);
162
+ if (method) {
163
+ const arg = node.arguments[0];
164
+ if (CHILD_PROCESS_COMMAND_METHODS.has(method)) {
165
+ if (isStringLiteral(arg)) {
166
+ const command = getStringValue(arg);
167
+ if (command)
168
+ s.scripts.add(command);
169
+ }
112
170
  return;
113
171
  }
172
+ if (CHILD_PROCESS_FILE_METHODS.has(method)) {
173
+ const specifier = extractInlineDirnamePath(arg, s);
174
+ if (specifier) {
175
+ s.addImport(specifier, undefined, undefined, undefined, arg.start, IMPORT_FLAGS.ENTRY);
176
+ return;
177
+ }
178
+ if (method !== 'fork') {
179
+ const script = getSafeScriptFromArgs(arg, node.arguments[1]);
180
+ if (script) {
181
+ s.scripts.add(script);
182
+ return;
183
+ }
184
+ }
185
+ }
114
186
  }
115
187
  }
116
188
  if (node.callee.type === 'MemberExpression' &&
@@ -3,6 +3,13 @@ import { addNsValue, addValue } from '../../util/module-graph.js';
3
3
  import { extractEnumMembers, extractNamespaceMembers, getLineAndCol, getStringValue, isStringLiteral, } from '../ast-nodes.js';
4
4
  import { EMPTY_TAGS } from './jsdoc.js';
5
5
  const getName = (n) => (n?.type === 'Identifier' ? n.name : undefined);
6
+ const addLocalToExport = (s, local, exported) => {
7
+ const set = s.localToExports.get(local);
8
+ if (set)
9
+ set.add(exported);
10
+ else
11
+ s.localToExports.set(local, new Set([exported]));
12
+ };
6
13
  const hasExplicitFunctionReturnType = (node) => !!node &&
7
14
  (node.type === 'ArrowFunctionExpression' ||
8
15
  node.type === 'FunctionExpression' ||
@@ -214,6 +221,8 @@ export function handleExportNamed(node, s) {
214
221
  s.addExport(exportedName, type, spec.exported?.start ?? spec.start, [], fix, isReExport, s.getJSDocTags(node.start));
215
222
  if (exportedName)
216
223
  s.specifierExportNames.add(exportedName);
224
+ if (localName && exportedName)
225
+ addLocalToExport(s, localName, exportedName);
217
226
  }
218
227
  }
219
228
  }
@@ -240,6 +249,8 @@ export function handleExportDefault(node, s) {
240
249
  pos = decl.id?.start ?? decl.start;
241
250
  members = [];
242
251
  s.collectRefsInType(decl, 'default', true);
252
+ if (decl.id)
253
+ addLocalToExport(s, decl.id.name, 'default');
243
254
  }
244
255
  else if (decl.type === 'TSInterfaceDeclaration') {
245
256
  type = SYMBOL_TYPE.INTERFACE;
@@ -249,6 +260,7 @@ export function handleExportDefault(node, s) {
249
260
  else if (decl.type === 'Identifier') {
250
261
  type = s.localDeclarationTypes.get(decl.name) ?? SYMBOL_TYPE.UNKNOWN;
251
262
  pos = decl.start;
263
+ addLocalToExport(s, decl.name, 'default');
252
264
  const _import = s.localImportMap.get(decl.name);
253
265
  if (_import) {
254
266
  const internalImport = s.internal.get(_import.filePath);
@@ -35,6 +35,9 @@ interface WalkContext {
35
35
  hasNodeModuleImport: boolean;
36
36
  hasWorkerThreadsImport: boolean;
37
37
  hasChildProcessImport: boolean;
38
+ childProcessNamespaces: ReadonlySet<string>;
39
+ childProcessMethods: ReadonlyMap<string, string>;
40
+ registeredCustomElements: Set<string>;
38
41
  hasPathJoinImport: boolean;
39
42
  hasPathResolveImport: boolean;
40
43
  resolveModule: ResolveModule;
@@ -72,6 +75,10 @@ export interface WalkState extends WalkContext {
72
75
  exportName: string;
73
76
  seen: Set<string>;
74
77
  }>;
78
+ localToExports: Map<string, Set<string>>;
79
+ customElementRegistries: Set<string>;
80
+ classNameStack: string[];
81
+ staticBlockDepth: number;
75
82
  addExport: (identifier: string, type: SymbolType, pos: number, members: ExportMember[], fix: Fix, isReExport: boolean, jsDocTags: Set<string>) => void;
76
83
  getFix: (start: number, end: number, flags?: number) => Fix;
77
84
  getTypeFix: (start: number, end: number) => Fix;
@@ -5,7 +5,7 @@ import { isInNodeModules } from '../../util/path.js';
5
5
  import { timerify } from '../../util/Performance.js';
6
6
  import { getLineAndCol, getStringValue, isStringLiteral } from '../ast-nodes.js';
7
7
  import { EMPTY_TAGS } from './jsdoc.js';
8
- import { handleCallExpression, handleNewExpression } from './calls.js';
8
+ import { handleCallExpression, handleNewExpression, trackCustomElementRegistry } from './calls.js';
9
9
  import { handleExportAssignment, handleExportDefault, handleExportNamed, handleExpressionStatement, } from './exports.js';
10
10
  import { handleImportExpression, handleVariableDeclarator } from './imports.js';
11
11
  import { handleJSXMemberExpression, handleMemberExpression } from './members.js';
@@ -42,6 +42,7 @@ const _addExport = (identifier, type, pos, members, fix, isReExport, jsDocTags)
42
42
  line,
43
43
  col,
44
44
  hasRefsInFile: false,
45
+ isRegistered: false,
45
46
  referencedIn: undefined,
46
47
  fixes: fix ? [fix] : [],
47
48
  isReExport,
@@ -104,6 +105,13 @@ const _collectRefsInType = (node, exportName, signatureOnly, seen = new Set(), i
104
105
  return;
105
106
  }
106
107
  break;
108
+ case 'VariableDeclarator':
109
+ if (inBody) {
110
+ if (node.init)
111
+ _collectRefsInType(node.init, exportName, signatureOnly, seen, inBody);
112
+ return;
113
+ }
114
+ break;
107
115
  }
108
116
  const keys = visitorKeys[type];
109
117
  if (!keys)
@@ -205,11 +213,27 @@ const coreVisitorObject = {
205
213
  state.nsRanges.push([node.start, node.end]);
206
214
  },
207
215
  ClassDeclaration(node) {
216
+ state.classNameStack.push(node.id?.name ?? '');
208
217
  if (node.id?.name) {
209
218
  state.localDeclarationTypes.set(node.id.name, SYMBOL_TYPE.CLASS);
210
219
  state.localDeclarations.set(node.id.name, node);
211
220
  }
212
221
  },
222
+ 'ClassDeclaration:exit'() {
223
+ state.classNameStack.pop();
224
+ },
225
+ ClassExpression(node) {
226
+ state.classNameStack.push(node.id?.name ?? '');
227
+ },
228
+ 'ClassExpression:exit'() {
229
+ state.classNameStack.pop();
230
+ },
231
+ StaticBlock() {
232
+ state.staticBlockDepth++;
233
+ },
234
+ 'StaticBlock:exit'() {
235
+ state.staticBlockDepth--;
236
+ },
213
237
  FunctionDeclaration(node) {
214
238
  if (node.id?.name) {
215
239
  state.localDeclarationTypes.set(node.id.name, SYMBOL_TYPE.FUNCTION);
@@ -267,6 +291,7 @@ const coreVisitorObject = {
267
291
  },
268
292
  VariableDeclarator(node) {
269
293
  handleVariableDeclarator(node, state);
294
+ trackCustomElementRegistry(node, state);
270
295
  },
271
296
  ImportExpression(node) {
272
297
  handleImportExpression(node, state);
@@ -697,6 +722,10 @@ function walkAST(program, sourceText, filePath, ctx) {
697
722
  localDeclarations: new Map(),
698
723
  pendingCallRefs: [],
699
724
  pendingMemberCallRefs: [],
725
+ localToExports: new Map(),
726
+ customElementRegistries: new Set(),
727
+ classNameStack: [],
728
+ staticBlockDepth: 0,
700
729
  addExport: _addExport,
701
730
  getFix: _getFix,
702
731
  getTypeFix: _getTypeFix,
@@ -777,6 +806,19 @@ function walkAST(program, sourceText, filePath, ctx) {
777
806
  item.hasRefsInFile = true;
778
807
  }
779
808
  }
809
+ for (const name of state.registeredCustomElements) {
810
+ const item = state.exports.get(name);
811
+ if (item)
812
+ item.isRegistered = true;
813
+ const aliases = state.localToExports.get(name);
814
+ if (aliases) {
815
+ for (const exportName of aliases) {
816
+ const aliased = state.exports.get(exportName);
817
+ if (aliased)
818
+ aliased.isRegistered = true;
819
+ }
820
+ }
821
+ }
780
822
  const localRefs = state.localRefs;
781
823
  state = undefined;
782
824
  return localRefs;
@@ -1,38 +1,22 @@
1
- import { type PerformanceEntry, PerformanceObserver } from 'node:perf_hooks';
2
- export declare const timerify: <T extends (...params: any[]) => any>(fn: T, name?: string) => T;
3
- type MemInfo = {
4
- label: string;
5
- heapUsed: number;
6
- heapTotal: number;
7
- rss: number;
8
- };
9
- interface MemoryEntry extends PerformanceEntry {
10
- detail: MemInfo;
11
- }
1
+ import { type RecordableHistogram } from 'node:perf_hooks';
12
2
  declare class Performance {
13
- isEnabled: boolean;
14
- isTimerifyFunctions: boolean;
15
- isMemoryUsageEnabled: boolean;
16
- isDurationEnabled: boolean;
17
- startTime: number;
18
- endTime: number;
19
- perfEntries: PerformanceEntry[];
20
- memEntries: MemoryEntry[];
21
- perfId?: string;
22
- memId?: string;
23
- fnObserver?: PerformanceObserver;
24
- memObserver?: PerformanceObserver;
3
+ readonly isEnabled: boolean;
4
+ readonly isTimerifyFunctions: boolean;
5
+ readonly isMemoryUsageEnabled: boolean;
6
+ readonly isDurationEnabled: boolean;
7
+ private readonly startTime;
8
+ private readonly memId;
9
+ private readonly histograms;
10
+ private readonly memEntries;
11
+ private readonly memObserver?;
25
12
  constructor({ isTimerifyFunctions, isMemoryUsageEnabled, isDurationEnabled }: {
26
13
  isDurationEnabled?: boolean | undefined;
27
14
  isMemoryUsageEnabled?: boolean | undefined;
28
15
  isTimerifyFunctions?: boolean | undefined;
29
16
  });
30
- private setMark;
31
- private clearMark;
32
- private flush;
33
- private getPerfEntriesByName;
34
- getTimerifiedFunctionsTable(): string;
17
+ registerHistogram(name: string): RecordableHistogram;
35
18
  addMemoryMark(label: string): void;
19
+ getTimerifiedFunctionsTable(): string;
36
20
  getMemoryUsageTable(): string;
37
21
  getCurrentDurationInMs(): number;
38
22
  getMemHeapUsage(): number;
@@ -41,4 +25,5 @@ declare class Performance {
41
25
  reset(): void;
42
26
  }
43
27
  export declare const perfObserver: Performance;
28
+ export declare const timerify: <T extends (...params: any[]) => any>(fn: T, name?: string) => T;
44
29
  export {};