@esportsplus/typescript 0.29.6 → 0.31.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 (129) hide show
  1. package/README.md +97 -3
  2. package/bin/tsc-alias +1 -1
  3. package/bin/tsc-lsp +3 -0
  4. package/build/cli/diagnostics.d.ts +8 -0
  5. package/build/cli/diagnostics.js +95 -0
  6. package/build/cli/tsc.d.ts +12 -2
  7. package/build/cli/tsc.js +343 -52
  8. package/build/compiler/ast.d.ts +7 -5
  9. package/build/compiler/ast.js +6 -6
  10. package/build/compiler/code.d.ts +5 -4
  11. package/build/compiler/code.js +12 -1
  12. package/build/compiler/coordinator.d.ts +16 -7
  13. package/build/compiler/coordinator.js +75 -41
  14. package/build/compiler/imports.d.ts +8 -3
  15. package/build/compiler/imports.js +34 -24
  16. package/build/compiler/index.d.ts +3 -0
  17. package/build/compiler/index.js +1 -0
  18. package/build/compiler/language-service.d.ts +36 -6
  19. package/build/compiler/language-service.js +252 -58
  20. package/build/compiler/plugins/index.d.ts +4 -2
  21. package/build/compiler/plugins/tsc.d.ts +1 -1
  22. package/build/compiler/plugins/vite.d.ts +6 -3
  23. package/build/compiler/plugins/vite.js +15 -8
  24. package/build/compiler/sourcemap.d.ts +52 -0
  25. package/build/compiler/sourcemap.js +265 -0
  26. package/build/compiler/types.d.ts +7 -6
  27. package/build/compiler/uid.d.ts +5 -2
  28. package/build/compiler/uid.js +33 -4
  29. package/build/index.d.ts +1 -1
  30. package/build/index.js +1 -1
  31. package/build/jsonc.d.ts +2 -0
  32. package/build/jsonc.js +85 -0
  33. package/build/lsp/bin.d.ts +1 -0
  34. package/build/lsp/bin.js +2 -0
  35. package/build/lsp/diagnostics.d.ts +10 -0
  36. package/build/lsp/diagnostics.js +69 -0
  37. package/build/lsp/index.d.ts +2 -0
  38. package/build/lsp/index.js +2 -0
  39. package/build/lsp/server.d.ts +4 -0
  40. package/build/lsp/server.js +130 -0
  41. package/build/lsp/workspace.d.ts +14 -0
  42. package/build/lsp/workspace.js +46 -0
  43. package/build/probe/adapter.d.ts +14 -0
  44. package/build/probe/adapter.js +42 -0
  45. package/build/probe/async/channel.d.ts +4 -0
  46. package/build/probe/async/channel.js +560 -0
  47. package/build/probe/async/value.d.ts +9 -0
  48. package/build/probe/async/value.js +16 -0
  49. package/build/probe/channels.d.ts +4 -0
  50. package/build/probe/channels.js +16 -0
  51. package/build/probe/exceptions/channel.d.ts +5 -0
  52. package/build/probe/exceptions/channel.js +657 -0
  53. package/build/probe/exceptions/jsdoc.d.ts +8 -0
  54. package/build/probe/exceptions/jsdoc.js +34 -0
  55. package/build/probe/exceptions/value.d.ts +39 -0
  56. package/build/probe/exceptions/value.js +158 -0
  57. package/build/probe/kernel/analyze.d.ts +8 -0
  58. package/build/probe/kernel/analyze.js +68 -0
  59. package/build/probe/kernel/ast.d.ts +11 -0
  60. package/build/probe/kernel/ast.js +49 -0
  61. package/build/probe/kernel/config.d.ts +5 -0
  62. package/build/probe/kernel/config.js +209 -0
  63. package/build/probe/kernel/fixpoint.d.ts +6 -0
  64. package/build/probe/kernel/fixpoint.js +206 -0
  65. package/build/probe/kernel/format.d.ts +4 -0
  66. package/build/probe/kernel/format.js +32 -0
  67. package/build/probe/kernel/graph.d.ts +4 -0
  68. package/build/probe/kernel/graph.js +507 -0
  69. package/build/probe/kernel/ids.d.ts +8 -0
  70. package/build/probe/kernel/ids.js +66 -0
  71. package/build/probe/kernel/program.d.ts +8 -0
  72. package/build/probe/kernel/program.js +13 -0
  73. package/build/probe/kernel/types.d.ts +134 -0
  74. package/build/probe/kernel/types.js +1 -0
  75. package/build/probe/overlay/base/async.jsonc +13 -0
  76. package/build/probe/overlay/base/exceptions.jsonc +54 -0
  77. package/build/probe/overlay/base/resources.jsonc +57 -0
  78. package/build/probe/overlay/load.d.ts +18 -0
  79. package/build/probe/overlay/load.js +302 -0
  80. package/build/probe/overlay/presets/express.jsonc +25 -0
  81. package/build/probe/overlay/presets/node.jsonc +17 -0
  82. package/build/probe/resources/channel.d.ts +4 -0
  83. package/build/probe/resources/channel.js +798 -0
  84. package/build/probe/resources/value.d.ts +9 -0
  85. package/build/probe/resources/value.js +36 -0
  86. package/build/ts.d.ts +3 -0
  87. package/build/ts.js +3 -0
  88. package/build/tsconfig.d.ts +2 -0
  89. package/build/tsconfig.js +150 -0
  90. package/package.json +29 -9
  91. package/tsconfig.base.json +19 -0
  92. package/tsconfig.dev.json +13 -0
  93. package/tsconfig.package.json +4 -1
  94. package/.claude/skills/code-audit/registry-typescript.json +0 -326
  95. package/.editorconfig +0 -9
  96. package/.gitattributes +0 -2
  97. package/.github/dependabot.yml +0 -25
  98. package/.github/workflows/bump.yml +0 -27
  99. package/.github/workflows/dependabot.yml +0 -58
  100. package/.github/workflows/publish.yml +0 -42
  101. package/.github/workflows/templates/bump.yml +0 -9
  102. package/.github/workflows/templates/dependabot.yml +0 -12
  103. package/.github/workflows/templates/publish.yml +0 -16
  104. package/pnpm-workspace.yaml +0 -6
  105. package/src/cli/tsc.ts +0 -235
  106. package/src/compiler/ast.ts +0 -60
  107. package/src/compiler/code.ts +0 -27
  108. package/src/compiler/coordinator.ts +0 -284
  109. package/src/compiler/imports.ts +0 -185
  110. package/src/compiler/index.ts +0 -7
  111. package/src/compiler/language-service.ts +0 -121
  112. package/src/compiler/plugins/index.ts +0 -5
  113. package/src/compiler/plugins/tsc.ts +0 -6
  114. package/src/compiler/plugins/vite.ts +0 -91
  115. package/src/compiler/types.ts +0 -83
  116. package/src/compiler/uid.ts +0 -10
  117. package/src/constants.ts +0 -4
  118. package/src/index.ts +0 -1
  119. package/tests/cli/tsc.test.ts +0 -155
  120. package/tests/compiler/ast.test.ts +0 -131
  121. package/tests/compiler/code.test.ts +0 -73
  122. package/tests/compiler/coordinator.bench.ts +0 -101
  123. package/tests/compiler/coordinator.test.ts +0 -872
  124. package/tests/compiler/imports.test.ts +0 -167
  125. package/tests/compiler/language-service.test.ts +0 -90
  126. package/tests/compiler/plugins.test.ts +0 -172
  127. package/tests/compiler/uid.test.ts +0 -70
  128. package/tsconfig.json +0 -3
  129. package/vitest.config.ts +0 -14
@@ -1,73 +1,267 @@
1
+ import { API, DiagnosticCategory } from 'typescript/unstable/sync';
1
2
  import { PACKAGE_NAME } from '../constants.js';
2
- import { ts } from '../index.js';
3
+ import fs from 'fs';
3
4
  import path from 'path';
4
- let cache = new Map();
5
- function create(root) {
6
- let tsconfig = ts.findConfigFile(root, ts.sys.fileExists, 'tsconfig.json');
7
- if (!tsconfig) {
8
- throw new Error(`${PACKAGE_NAME}: tsconfig.json not found`);
9
- }
10
- let file = ts.readConfigFile(tsconfig, ts.sys.readFile);
11
- if (file.error) {
12
- throw new Error(`${PACKAGE_NAME}: error reading tsconfig.json ${file.error.messageText}`);
13
- }
14
- let parsed = ts.parseJsonConfigFileContent(file.config, ts.sys, path.dirname(tsconfig));
15
- if (parsed.errors.length > 0) {
16
- throw new Error(`${PACKAGE_NAME}: error parsing tsconfig.json ${parsed.errors[0].messageText}`);
17
- }
18
- let contents = new Map(), rootFiles = new Set(parsed.fileNames.map(f => f.replace(/\\/g, '/'))), versions = new Map();
19
- for (let fileName of rootFiles) {
20
- versions.set(fileName, 0);
21
- }
22
- let host = {
23
- fileExists: ts.sys.fileExists,
24
- getCompilationSettings: () => parsed.options,
25
- getCurrentDirectory: () => root,
26
- getDefaultLibFileName: ts.getDefaultLibFilePath,
27
- getScriptFileNames: () => [...rootFiles],
28
- getScriptSnapshot: (fileName) => {
29
- let content = contents.get(fileName);
30
- if (content !== undefined) {
31
- return ts.ScriptSnapshot.fromString(content);
5
+ const backslashes = /\\/g;
6
+ let cache = new Map(), scratchEntry = null;
7
+ function advance(entry, changed) {
8
+ let snapshot = entry.api.updateSnapshot({ fileChanges: { changed } });
9
+ if (!entry.snapshot.isDisposed()) {
10
+ entry.snapshot.dispose();
11
+ }
12
+ entry.api.clearSourceFileCache();
13
+ entry.project = resolveProject(snapshot, entry.configFileName);
14
+ entry.snapshot = snapshot;
15
+ }
16
+ function advanceScratch(id, content) {
17
+ if (!scratchEntry) {
18
+ scratchEntry = createScratch(id);
19
+ }
20
+ else if (scratchEntry.file !== id) {
21
+ reseedScratch(scratchEntry, id);
22
+ }
23
+ let entry = scratchEntry;
24
+ entry.contents.set(id, content);
25
+ let snapshot = entry.api.updateSnapshot({ fileChanges: { changed: [id] } });
26
+ if (!entry.snapshot.isDisposed()) {
27
+ entry.snapshot.dispose();
28
+ }
29
+ entry.api.clearSourceFileCache();
30
+ entry.project = resolveProject(snapshot, entry.config);
31
+ entry.snapshot = snapshot;
32
+ return entry;
33
+ }
34
+ function createEntry(configFileName) {
35
+ let root = path.dirname(configFileName);
36
+ let contents = new Map(), opened = open(configFileName, overlayFileSystem(contents)), { api, project, snapshot } = opened;
37
+ for (let diagnostic of project.program.getConfigFileParsingDiagnostics()) {
38
+ if (diagnostic.category === DiagnosticCategory.Error) {
39
+ snapshot.dispose();
40
+ api.close();
41
+ throw new Error(`${PACKAGE_NAME}: error parsing tsconfig.json ${diagnostic.text}`);
42
+ }
43
+ }
44
+ return { api, configFileName, contents, pending: new Set(), project, root, seen: seed(project.program), snapshot };
45
+ }
46
+ function createScratch(file) {
47
+ let config = normalize(process.cwd()) + '/tsconfig.tsparse.json', contents = new Map();
48
+ contents.set(config, scratchConfig(file));
49
+ let api = new API({ cwd: process.cwd(), fs: overlayFileSystem(contents) }), snapshot = api.updateSnapshot({ openProjects: [config] }), project = resolveProject(snapshot, config);
50
+ return { api, config, contents, file, project, snapshot };
51
+ }
52
+ function disposeEntry(entry) {
53
+ if (!entry.snapshot.isDisposed()) {
54
+ entry.snapshot.dispose();
55
+ }
56
+ entry.api.close();
57
+ }
58
+ function disposeScratch(entry) {
59
+ if (!entry.snapshot.isDisposed()) {
60
+ entry.snapshot.dispose();
61
+ }
62
+ entry.api.close();
63
+ }
64
+ function getEntry(configFileName) {
65
+ let entry = cache.get(configFileName);
66
+ if (!entry) {
67
+ entry = createEntry(configFileName);
68
+ cache.set(configFileName, entry);
69
+ }
70
+ return entry;
71
+ }
72
+ function normalize(fileName) {
73
+ return fileName.replace(backslashes, '/');
74
+ }
75
+ function open(configPath, overlay) {
76
+ let configFileName = normalize(path.resolve(configPath)), entry = overlay === undefined ? getEntry(configFileName) : undefined, api = entry?.api ?? new API({ cwd: path.dirname(configFileName), fs: overlay }), snapshot = entry?.snapshot ?? api.updateSnapshot({ openProjects: [configFileName] }), project = entry?.project ?? resolveProject(snapshot, configFileName);
77
+ if (entry) {
78
+ return {
79
+ api,
80
+ dispose: () => dispose(configFileName),
81
+ project,
82
+ snapshot
83
+ };
84
+ }
85
+ return {
86
+ api,
87
+ dispose: () => {
88
+ if (!snapshot.isDisposed()) {
89
+ snapshot.dispose();
32
90
  }
33
- if (!ts.sys.fileExists(fileName)) {
91
+ api.close();
92
+ },
93
+ project,
94
+ snapshot,
95
+ };
96
+ }
97
+ function overlayFileSystem(contents) {
98
+ return {
99
+ fileExists: (fileName) => {
100
+ if (contents.has(normalize(fileName))) {
101
+ return true;
102
+ }
103
+ return undefined;
104
+ },
105
+ getAccessibleEntries: (directoryName) => {
106
+ let directory = normalize(directoryName), extra = [];
107
+ for (let key of contents.keys()) {
108
+ if (key.slice(0, key.lastIndexOf('/')) === directory) {
109
+ extra.push(key.slice(key.lastIndexOf('/') + 1));
110
+ }
111
+ }
112
+ if (extra.length === 0) {
34
113
  return undefined;
35
114
  }
36
- return ts.ScriptSnapshot.fromString(ts.sys.readFile(fileName) || '');
115
+ let directories = [], files = [];
116
+ try {
117
+ for (let entry of fs.readdirSync(directory, { withFileTypes: true })) {
118
+ (entry.isDirectory() ? directories : files).push(entry.name);
119
+ }
120
+ }
121
+ catch {
122
+ }
123
+ return { directories, files: [...new Set([...files, ...extra])] };
37
124
  },
38
- getScriptVersion: (fileName) => String(versions.get(fileName) || 0),
39
- readFile: ts.sys.readFile
125
+ readFile: (fileName) => {
126
+ let content = contents.get(normalize(fileName));
127
+ if (content !== undefined) {
128
+ return content;
129
+ }
130
+ return undefined;
131
+ }
40
132
  };
41
- return { contents, host, rootFiles, service: ts.createLanguageService(host), versions };
42
133
  }
43
- function getEntry(root) {
44
- let entry = cache.get(root);
45
- if (!entry) {
46
- entry = create(root);
47
- cache.set(root, entry);
134
+ function recreate(entry) {
135
+ if (!entry.snapshot.isDisposed()) {
136
+ entry.snapshot.dispose();
48
137
  }
49
- return entry;
138
+ entry.api.close();
139
+ entry.api = new API({ cwd: entry.root, fs: overlayFileSystem(entry.contents) });
140
+ entry.snapshot = entry.api.updateSnapshot({ openProjects: [entry.configFileName] });
141
+ entry.project = resolveProject(entry.snapshot, entry.configFileName);
142
+ entry.seen = seed(entry.project.program);
143
+ }
144
+ function reseedScratch(entry, file) {
145
+ entry.contents.delete(entry.file);
146
+ entry.contents.set(entry.config, scratchConfig(file));
147
+ if (!entry.snapshot.isDisposed()) {
148
+ entry.snapshot.dispose();
149
+ }
150
+ entry.api.close();
151
+ entry.api = new API({ cwd: process.cwd(), fs: overlayFileSystem(entry.contents) });
152
+ entry.file = file;
153
+ entry.snapshot = entry.api.updateSnapshot({ openProjects: [entry.config] });
154
+ entry.project = resolveProject(entry.snapshot, entry.config);
155
+ }
156
+ function resolveProject(snapshot, configFileName) {
157
+ let project = snapshot.getProject(configFileName);
158
+ if (!project) {
159
+ throw new Error(`${PACKAGE_NAME}: project not found for ${configFileName}`);
160
+ }
161
+ return project;
162
+ }
163
+ function scratchConfig(file) {
164
+ return JSON.stringify({
165
+ compilerOptions: {
166
+ allowJs: true,
167
+ module: 'esnext',
168
+ moduleResolution: 'bundler',
169
+ skipLibCheck: true,
170
+ target: 'es2024'
171
+ },
172
+ files: [file]
173
+ });
174
+ }
175
+ function seed(program) {
176
+ let seen = new Set();
177
+ for (let name of program.getSourceFileNames()) {
178
+ seen.add(normalize(name));
179
+ }
180
+ return seen;
50
181
  }
51
- const invalidate = (root, fileName) => {
182
+ const dispose = (root) => {
183
+ if (root === undefined) {
184
+ for (let entry of cache.values()) {
185
+ disposeEntry(entry);
186
+ }
187
+ cache.clear();
188
+ if (scratchEntry) {
189
+ disposeScratch(scratchEntry);
190
+ scratchEntry = null;
191
+ }
192
+ return;
193
+ }
52
194
  let entry = cache.get(root);
53
195
  if (entry) {
54
- let normalized = fileName.replace(/\\/g, '/');
55
- entry.contents.delete(normalized);
56
- entry.versions.set(normalized, (entry.versions.get(normalized) || 0) + 1);
196
+ disposeEntry(entry);
197
+ cache.delete(root);
198
+ }
199
+ };
200
+ const findConfig = (startDir) => {
201
+ let current = path.resolve(startDir);
202
+ while (true) {
203
+ let candidate = path.join(current, 'tsconfig.json');
204
+ if (fs.existsSync(candidate)) {
205
+ return normalize(candidate);
206
+ }
207
+ let parent = path.dirname(current);
208
+ if (parent === current) {
209
+ return null;
210
+ }
211
+ current = parent;
212
+ }
213
+ };
214
+ const invalidate = (configFileName, fileName) => {
215
+ let entry = cache.get(configFileName);
216
+ if (!entry) {
217
+ return;
218
+ }
219
+ let id = normalize(fileName);
220
+ entry.contents.delete(id);
221
+ entry.pending.add(id);
222
+ };
223
+ const parse = (fileName, content) => {
224
+ return scratch(fileName, content).sourceFile;
225
+ };
226
+ const scratch = (fileName, content) => {
227
+ let id = normalize(fileName), entry = advanceScratch(id, content), source = entry.project.program.getSourceFile(id);
228
+ if (!source) {
229
+ throw new Error(`${PACKAGE_NAME}: failed to parse ${fileName}`);
57
230
  }
231
+ return { checker: entry.project.checker, program: entry.project.program, sourceFile: source };
58
232
  };
59
- const update = (root, fileName, content) => {
60
- let entry = getEntry(root), normalized = fileName.replace(/\\/g, '/');
61
- if (!entry.rootFiles.has(normalized)) {
62
- entry.rootFiles.add(normalized);
63
- }
64
- entry.contents.set(normalized, content);
65
- entry.versions.set(normalized, (entry.versions.get(normalized) || 0) + 1);
66
- let program = entry.service.getProgram();
67
- if (!program) {
68
- throw new Error(`${PACKAGE_NAME}: failed to get program from language service`);
69
- }
70
- return program;
233
+ const update = (configFileName, fileName, content) => {
234
+ return updateMany(configFileName, new Map([[fileName, content]]));
235
+ };
236
+ const updateMany = (configFileName, updates) => {
237
+ let entry = getEntry(configFileName), ids = [];
238
+ for (let [fileName, content] of updates) {
239
+ let id = normalize(fileName);
240
+ entry.contents.set(id, content);
241
+ ids.push(id);
242
+ }
243
+ if (ids.every(id => entry.seen.has(id))) {
244
+ for (let i = 0, n = ids.length; i < n; i++) {
245
+ entry.pending.add(ids[i]);
246
+ }
247
+ let changed = [...entry.pending];
248
+ entry.pending.clear();
249
+ advance(entry, changed);
250
+ }
251
+ else {
252
+ recreate(entry);
253
+ entry.pending.clear();
254
+ for (let i = 0, n = ids.length; i < n; i++) {
255
+ entry.seen.add(ids[i]);
256
+ }
257
+ }
258
+ for (let i = 0, n = ids.length; i < n; i++) {
259
+ let id = ids[i], source = entry.project.program.getSourceFile(id), content = entry.contents.get(id);
260
+ if (!source || source.text !== content) {
261
+ throw new Error(`${PACKAGE_NAME}: failed to load ${id} into the program`);
262
+ }
263
+ }
264
+ return { checker: entry.project.checker, program: entry.project.program };
71
265
  };
72
- export default { invalidate, update };
73
- export { invalidate, update };
266
+ export default { dispose, findConfig, invalidate, open, parse, scratch, update, updateMany };
267
+ export { dispose, findConfig, invalidate, open, parse, scratch, update, updateMany };
@@ -7,12 +7,14 @@ declare const _default: {
7
7
  }) => ({ root }?: {
8
8
  root?: string;
9
9
  }) => {
10
+ closeBundle: () => void;
11
+ closeWatcher: () => void;
10
12
  configResolved: (config: unknown) => void;
11
- enforce: "pre";
13
+ enforce: 'pre';
12
14
  name: string;
13
15
  transform: (code: string, id: string) => {
14
16
  code: string;
15
- map: null;
17
+ map: import("../index.js").SourceMapV3;
16
18
  } | null;
17
19
  watchChange: (id: string) => void;
18
20
  };
@@ -1,3 +1,3 @@
1
1
  import type { Plugin } from '../types.js';
2
- declare const _default: (plugins: Plugin[]) => () => Plugin[];
3
2
  export default _default;
3
+ declare function _default(plugins: Plugin[]): () => Plugin[];
@@ -1,11 +1,14 @@
1
1
  import type { Plugin } from '../types.js';
2
+ import type { SourceMapV3 } from '../sourcemap.js';
2
3
  type VitePlugin = {
4
+ closeBundle: () => void;
5
+ closeWatcher: () => void;
3
6
  configResolved: (config: unknown) => void;
4
7
  enforce: 'pre';
5
8
  name: string;
6
9
  transform: (code: string, id: string) => {
7
10
  code: string;
8
- map: null;
11
+ map: SourceMapV3;
9
12
  } | null;
10
13
  watchChange: (id: string) => void;
11
14
  };
@@ -14,7 +17,7 @@ type VitePluginOptions = {
14
17
  onWatchChange?: () => void;
15
18
  plugins: Plugin[];
16
19
  };
17
- declare const _default: ({ name, onWatchChange, plugins }: VitePluginOptions) => ({ root }?: {
20
+ export default _default;
21
+ declare function _default({ name, onWatchChange, plugins }: VitePluginOptions): ({ root }?: {
18
22
  root?: string;
19
23
  }) => VitePlugin;
20
- export default _default;
@@ -1,14 +1,24 @@
1
- import { ts } from '../../index.js';
2
1
  import coordinator from '../coordinator.js';
3
2
  import languageService from '../language-service.js';
3
+ import sourcemap from '../sourcemap.js';
4
4
  const DIRECTORY_SEPARATOR_REGEX = /\\/g;
5
5
  const FILE_REGEX = /\.[tj]sx?$/;
6
6
  let contexts = new Map();
7
7
  export default ({ name, onWatchChange, plugins }) => {
8
8
  return ({ root } = {}) => {
9
+ let tsconfig = null;
9
10
  return {
11
+ closeBundle() {
12
+ languageService.dispose(tsconfig ?? '');
13
+ contexts.delete(root || '');
14
+ },
15
+ closeWatcher() {
16
+ languageService.dispose(tsconfig ?? '');
17
+ contexts.delete(root || '');
18
+ },
10
19
  configResolved(config) {
11
20
  root ??= config.root;
21
+ tsconfig = languageService.findConfig(root);
12
22
  },
13
23
  enforce: 'pre',
14
24
  name: `${name}/compiler/vite`,
@@ -17,20 +27,17 @@ export default ({ name, onWatchChange, plugins }) => {
17
27
  return null;
18
28
  }
19
29
  try {
20
- let normalizedId = id.replace(DIRECTORY_SEPARATOR_REGEX, '/'), prog = languageService.update(root || '', normalizedId, code), sourceFile = prog.getSourceFile(normalizedId);
21
- if (!sourceFile) {
22
- sourceFile = ts.createSourceFile(normalizedId, code, ts.ScriptTarget.Latest, true);
23
- }
30
+ let normalizedId = id.replace(DIRECTORY_SEPARATOR_REGEX, '/'), configPath = tsconfig ?? languageService.findConfig(root || ''), { checker, program } = languageService.update(configPath ?? '', normalizedId, code), sourceFile = program.getSourceFile(normalizedId) ?? languageService.parse(normalizedId, code);
24
31
  let key = root || '', ctx = contexts.get(key);
25
32
  if (!ctx) {
26
33
  ctx = new Map();
27
34
  contexts.set(key, ctx);
28
35
  }
29
- let result = coordinator.transform(plugins, code, sourceFile, prog, key, ctx);
36
+ let result = coordinator.transform(plugins, code, sourceFile, { checker, configPath: configPath ?? undefined, program }, key, ctx);
30
37
  if (!result.changed) {
31
38
  return null;
32
39
  }
33
- return { code: result.code, map: null };
40
+ return { code: result.code, map: sourcemap.toSourceMapV3(result.map, result.code, code, normalizedId) };
34
41
  }
35
42
  catch (error) {
36
43
  console.error(`${name}: error transforming ${id}:`, error);
@@ -41,7 +48,7 @@ export default ({ name, onWatchChange, plugins }) => {
41
48
  if (FILE_REGEX.test(id)) {
42
49
  onWatchChange?.();
43
50
  contexts.delete(root || '');
44
- languageService.invalidate(root || '', id);
51
+ languageService.invalidate(tsconfig ?? '', id);
45
52
  }
46
53
  }
47
54
  };
@@ -0,0 +1,52 @@
1
+ type Edit = {
2
+ end: number;
3
+ newText: string;
4
+ start: number;
5
+ };
6
+ type OffsetAnchor = {
7
+ afterEnd: number;
8
+ afterStart: number;
9
+ beforeStart: number;
10
+ identity: boolean;
11
+ };
12
+ type PositionMapping = {
13
+ generations: OffsetAnchor[][];
14
+ };
15
+ type Segment = {
16
+ genColumn: number;
17
+ name?: number;
18
+ originalColumn?: number;
19
+ originalLine?: number;
20
+ source?: number;
21
+ };
22
+ type SourceMapV3 = {
23
+ file?: string;
24
+ mappings: string;
25
+ names: string[];
26
+ sourceRoot?: string;
27
+ sources: (string | null)[];
28
+ sourcesContent?: (string | null)[];
29
+ version: 3;
30
+ };
31
+ declare function resolveOffset(mapping: PositionMapping, offset: number): number;
32
+ declare const buildGeneration: (beforeText: string, edits: Edit[]) => OffsetAnchor[];
33
+ declare const composeEmittedMap: (map: SourceMapV3, mapping: PositionMapping, transformedText: string, originalText: string) => SourceMapV3;
34
+ declare const decode: (mappings: string) => number[][][];
35
+ declare const encode: (decoded: number[][][]) => string;
36
+ declare const originalPositionFor: (mapping: PositionMapping, transformedText: string, originalText: string, line: number, column: number) => {
37
+ column: number;
38
+ line: number;
39
+ };
40
+ declare const toSourceMapV3: (mapping: PositionMapping, transformedText: string, originalText: string, source: string) => SourceMapV3;
41
+ declare const _default: {
42
+ buildGeneration: typeof buildGeneration;
43
+ composeEmittedMap: typeof composeEmittedMap;
44
+ decode: typeof decode;
45
+ encode: typeof encode;
46
+ originalPositionFor: typeof originalPositionFor;
47
+ resolveOffset: typeof resolveOffset;
48
+ toSourceMapV3: typeof toSourceMapV3;
49
+ };
50
+ export default _default;
51
+ export { buildGeneration, composeEmittedMap, decode, encode, originalPositionFor, resolveOffset, toSourceMapV3 };
52
+ export type { Edit, OffsetAnchor, PositionMapping, Segment, SourceMapV3 };