svelte-docinfo 0.1.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 (97) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +349 -0
  3. package/dist/analyze-core.d.ts +1386 -0
  4. package/dist/analyze-core.d.ts.map +1 -0
  5. package/dist/analyze-core.js +324 -0
  6. package/dist/analyze.d.ts +137 -0
  7. package/dist/analyze.d.ts.map +1 -0
  8. package/dist/analyze.js +148 -0
  9. package/dist/cli.d.ts +102 -0
  10. package/dist/cli.d.ts.map +1 -0
  11. package/dist/cli.js +206 -0
  12. package/dist/concurrency.d.ts +38 -0
  13. package/dist/concurrency.d.ts.map +1 -0
  14. package/dist/concurrency.js +57 -0
  15. package/dist/declaration-build.d.ts +164 -0
  16. package/dist/declaration-build.d.ts.map +1 -0
  17. package/dist/declaration-build.js +15 -0
  18. package/dist/declaration-helpers.d.ts +169 -0
  19. package/dist/declaration-helpers.d.ts.map +1 -0
  20. package/dist/declaration-helpers.js +239 -0
  21. package/dist/dep-resolver.d.ts +166 -0
  22. package/dist/dep-resolver.d.ts.map +1 -0
  23. package/dist/dep-resolver.js +144 -0
  24. package/dist/diagnostics.d.ts +650 -0
  25. package/dist/diagnostics.d.ts.map +1 -0
  26. package/dist/diagnostics.js +377 -0
  27. package/dist/discovery.d.ts +115 -0
  28. package/dist/discovery.d.ts.map +1 -0
  29. package/dist/discovery.js +126 -0
  30. package/dist/exports.d.ts +105 -0
  31. package/dist/exports.d.ts.map +1 -0
  32. package/dist/exports.js +274 -0
  33. package/dist/files.d.ts +77 -0
  34. package/dist/files.d.ts.map +1 -0
  35. package/dist/files.js +95 -0
  36. package/dist/index.d.ts +32 -0
  37. package/dist/index.d.ts.map +1 -0
  38. package/dist/index.js +30 -0
  39. package/dist/log.d.ts +32 -0
  40. package/dist/log.d.ts.map +1 -0
  41. package/dist/log.js +11 -0
  42. package/dist/logo.d.ts +8 -0
  43. package/dist/logo.d.ts.map +1 -0
  44. package/dist/logo.js +9 -0
  45. package/dist/main.d.ts +11 -0
  46. package/dist/main.d.ts.map +1 -0
  47. package/dist/main.js +18 -0
  48. package/dist/paths.d.ts +35 -0
  49. package/dist/paths.d.ts.map +1 -0
  50. package/dist/paths.js +34 -0
  51. package/dist/postprocess.d.ts +145 -0
  52. package/dist/postprocess.d.ts.map +1 -0
  53. package/dist/postprocess.js +305 -0
  54. package/dist/session.d.ts +248 -0
  55. package/dist/session.d.ts.map +1 -0
  56. package/dist/session.js +496 -0
  57. package/dist/source-config.d.ts +330 -0
  58. package/dist/source-config.d.ts.map +1 -0
  59. package/dist/source-config.js +356 -0
  60. package/dist/source.d.ts +126 -0
  61. package/dist/source.d.ts.map +1 -0
  62. package/dist/source.js +68 -0
  63. package/dist/svelte.d.ts +179 -0
  64. package/dist/svelte.d.ts.map +1 -0
  65. package/dist/svelte.js +898 -0
  66. package/dist/tsdoc.d.ts +145 -0
  67. package/dist/tsdoc.d.ts.map +1 -0
  68. package/dist/tsdoc.js +262 -0
  69. package/dist/types.d.ts +3381 -0
  70. package/dist/types.d.ts.map +1 -0
  71. package/dist/types.js +588 -0
  72. package/dist/typescript-exports.d.ts +91 -0
  73. package/dist/typescript-exports.d.ts.map +1 -0
  74. package/dist/typescript-exports.js +656 -0
  75. package/dist/typescript-extract-class.d.ts +29 -0
  76. package/dist/typescript-extract-class.d.ts.map +1 -0
  77. package/dist/typescript-extract-class.js +251 -0
  78. package/dist/typescript-extract-function.d.ts +47 -0
  79. package/dist/typescript-extract-function.d.ts.map +1 -0
  80. package/dist/typescript-extract-function.js +108 -0
  81. package/dist/typescript-extract-shared.d.ts +166 -0
  82. package/dist/typescript-extract-shared.d.ts.map +1 -0
  83. package/dist/typescript-extract-shared.js +528 -0
  84. package/dist/typescript-extract-type-properties.d.ts +34 -0
  85. package/dist/typescript-extract-type-properties.d.ts.map +1 -0
  86. package/dist/typescript-extract-type-properties.js +241 -0
  87. package/dist/typescript-extract-type.d.ts +48 -0
  88. package/dist/typescript-extract-type.d.ts.map +1 -0
  89. package/dist/typescript-extract-type.js +238 -0
  90. package/dist/typescript-program.d.ts +211 -0
  91. package/dist/typescript-program.d.ts.map +1 -0
  92. package/dist/typescript-program.js +290 -0
  93. package/dist/vite.d.ts +116 -0
  94. package/dist/vite.d.ts.map +1 -0
  95. package/dist/vite.js +418 -0
  96. package/package.json +131 -0
  97. package/virtual-svelte-docinfo.d.ts +49 -0
@@ -0,0 +1,144 @@
1
+ /**
2
+ * Import resolver primitives for the analysis session.
3
+ *
4
+ * Exposes the `ImportResolver` token contract (`{resolve, identity}`) plus
5
+ * building blocks the session uses inside its three-phase setFiles pipeline:
6
+ *
7
+ * - `ensureLexerReady` — one-time wasm init for `es-module-lexer`. Phase 1 is
8
+ * sync per-file; the session awaits this once before the loop starts.
9
+ * - `lexImports` — sync specifier extraction from already-prepared content
10
+ * (raw TS/JS, or svelte2tsx virtual content for `.svelte` files).
11
+ * - `createDefaultResolver` — the TS + tsconfig fallback used when neither
12
+ * `AnalysisSessionOptions.resolveImport` nor a per-call override is provided.
13
+ * Carries a fresh symbol identity per session (cache-key-safe).
14
+ * - `normalizeResolveImport` — coerces the public `ResolveImport` union (bare
15
+ * function or token-paired resolver) to an `ImportResolver` at each boundary.
16
+ * - `wrapResolveImport` — the fn→token primitive behind `normalizeResolveImport`:
17
+ * wraps a bare function in an `ImportResolver`, synthesizing a throwaway
18
+ * identity unless a stable one is passed.
19
+ *
20
+ * @internal — subpath-importable for power users who want to drive resolution
21
+ * outside the session, but not part of the stable barrel surface.
22
+ *
23
+ * @see `session.ts` for the three-phase ingestion pipeline that consumes these
24
+ * @see `loadTsconfig` in `typescript-program.ts` for the TS module-resolution
25
+ * compiler-options shortcut used by the default resolver
26
+ *
27
+ * @module
28
+ */
29
+ import ts from 'typescript';
30
+ import { init as esModuleLexerInit, parse as esModuleLexerParse } from 'es-module-lexer';
31
+ /**
32
+ * Normalize the public `ResolveImport` union to an `ImportResolver`.
33
+ *
34
+ * Wraps a bare function via `wrapResolveImport` (fresh synthesized identity);
35
+ * passes a token-paired resolver through unchanged. `undefined` in, `undefined`
36
+ * out — callers fall back to the session default. Call once per logical
37
+ * resolver scope: at session construction for the default, per call for an
38
+ * override.
39
+ */
40
+ export const normalizeResolveImport = (value) => value === undefined ? undefined : typeof value === 'function' ? wrapResolveImport(value) : value;
41
+ /**
42
+ * Ensure `es-module-lexer`'s wasm runtime is initialized.
43
+ *
44
+ * Idempotent and cheap after the first call. The session awaits this once at
45
+ * the top of `setFiles` so phase 1's per-file lex is purely synchronous.
46
+ */
47
+ export const ensureLexerReady = async () => {
48
+ await esModuleLexerInit;
49
+ };
50
+ /**
51
+ * Lex import specifiers from prepared content.
52
+ *
53
+ * Sync — caller must have awaited `ensureLexerReady` at least once before
54
+ * invoking. For `.svelte` files, pass the svelte2tsx-transformed virtual
55
+ * content, not the raw `.svelte` source (which isn't lex-able as JS/TS).
56
+ *
57
+ * Dynamic imports (`import(specifier)` with non-literal arg) are omitted.
58
+ *
59
+ * @throws Error if lexing fails (malformed source). Callers should catch and
60
+ * emit `import_parse_failed`.
61
+ *
62
+ * @param content - prepared file content (TS/JS, or svelte2tsx virtual)
63
+ * @param fileId - absolute file path (used for error messages)
64
+ * @returns specifiers in declaration order
65
+ */
66
+ export const lexImports = (content, fileId) => {
67
+ const [imports] = esModuleLexerParse(content, fileId);
68
+ const specifiers = [];
69
+ for (const imp of imports) {
70
+ if (imp.n)
71
+ specifiers.push(imp.n);
72
+ }
73
+ return specifiers;
74
+ };
75
+ /**
76
+ * Create the default `ImportResolver` (TypeScript + tsconfig).
77
+ *
78
+ * Uses `ts.resolveModuleName` against `ts.sys` directly — no `ts.Program` is
79
+ * built. Identity is a fresh symbol per call, so each session that constructs
80
+ * its own default gets a unique cache scope. Multiple sessions sharing one
81
+ * resolver instance share the cache scope (correct, since resolver state is
82
+ * shared too).
83
+ *
84
+ * Falls back to appending `.svelte` when the bare specifier doesn't resolve —
85
+ * lets `.svelte` imports work without polluting the consumer's tsconfig.
86
+ *
87
+ * @param compilerOptions - parsed tsconfig (from `loadTsconfig`)
88
+ * @param projectRoot - absolute project root for the module-resolution cache
89
+ */
90
+ export const createDefaultResolver = (compilerOptions, projectRoot) => {
91
+ const cache = ts.createModuleResolutionCache(projectRoot, ts.sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase(), compilerOptions);
92
+ const resolve = (specifier, fromFile) => {
93
+ const result = ts.resolveModuleName(specifier, fromFile, compilerOptions, ts.sys, cache);
94
+ if (result.resolvedModule)
95
+ return result.resolvedModule.resolvedFileName;
96
+ // Fallback: try with .svelte extension. ts.resolveModuleName doesn't
97
+ // know about .svelte files unless explicitly configured.
98
+ if (!specifier.endsWith('.svelte')) {
99
+ const svelte = ts.resolveModuleName(specifier + '.svelte', fromFile, compilerOptions, ts.sys, cache);
100
+ if (svelte.resolvedModule)
101
+ return svelte.resolvedModule.resolvedFileName;
102
+ }
103
+ return null;
104
+ };
105
+ return { resolve, identity: Symbol('ts-default') };
106
+ };
107
+ /**
108
+ * Wrap a bare `resolveImport` function into an `ImportResolver` token.
109
+ *
110
+ * `identity` is optional; when omitted, a fresh `Symbol('wrapped')` is
111
+ * synthesized per call. The synthesized default suits single-use scopes —
112
+ * `normalizeResolveImport` relies on it to wrap a bare function for a one-shot
113
+ * `analyze` call or for a session default (wrapped once at construction, so the
114
+ * identity stays stable for the session's lifetime).
115
+ *
116
+ * For a long-lived session that re-wraps the *same* logical resolver across
117
+ * calls (Vite plugin, LSP), a throwaway identity cache-misses every time — the
118
+ * fresh `Symbol('wrapped')` never compares equal. Pass a stable `identity`
119
+ * here, or — simpler — construct an `ImportResolver` (`{resolve, identity}`)
120
+ * directly and pass it through the `ResolveImport` union.
121
+ */
122
+ export const wrapResolveImport = (resolveImport, identity = Symbol('wrapped')) => ({
123
+ resolve: resolveImport,
124
+ identity,
125
+ });
126
+ /**
127
+ * Shared no-op `ImportResolver` for the "dependency resolution disabled" case.
128
+ *
129
+ * Stable string identity (`'no-deps'`) instead of a per-call symbol so that
130
+ * repeated ingests within a long-lived session cache-hit on identity. Each
131
+ * session still owns its own cache (entries live on the per-session `owned`
132
+ * map; sessions don't share state), but within one session every reference
133
+ * to `noDepsResolver` is `===` to every other — so a Vite re-save of
134
+ * byte-identical content with `resolveDependencies: false` exercises the
135
+ * cache-hit branch. The resolver always returns `null`, so any two calls
136
+ * with identical content under this identity produce identical resolution
137
+ * results — `string` identity correctly captures that. Used by both the
138
+ * one-shot `analyzeFromFiles` path and the long-lived Vite plugin
139
+ * (`resolveDependencies: false`).
140
+ */
141
+ export const noDepsResolver = {
142
+ resolve: () => null,
143
+ identity: 'no-deps',
144
+ };