@tsrx/content-mapper 0.1.0 → 0.1.2
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.
- package/README.md +106 -60
- package/dist/mapper-B4f--1ac.js +3366 -0
- package/dist/mapper-B4f--1ac.js.map +1 -0
- package/dist/mapper.js +3 -0
- package/dist/protocol.js +126 -0
- package/dist/protocol.js.map +1 -0
- package/dist/rpc.js +137 -0
- package/dist/rpc.js.map +1 -0
- package/dist/server.js +2 -3315
- package/dist/server.js.map +1 -1
- package/package.json +10 -10
- package/src/diagnostic-directives.js +199 -0
- package/src/export-stub.js +112 -9
- package/src/mapper.js +43 -40
- package/src/protocol.js +23 -13
- package/src/rpc.js +11 -2
package/dist/mapper.js
ADDED
package/dist/protocol.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
//#region src/protocol.js
|
|
2
|
+
/**
|
|
3
|
+
* Constants of the TypeScript 7 content-mapper protocol, kept in sync with
|
|
4
|
+
* `tsc/internal/contentmapper` and `tsc/internal/spanmap` in microsoft/TypeScript.
|
|
5
|
+
*/
|
|
6
|
+
/** Span kinds. */
|
|
7
|
+
const SpanMapKind = {
|
|
8
|
+
/** Same length and identical text; the only kind that supports text edits. */
|
|
9
|
+
Verbatim: 0,
|
|
10
|
+
/** Same entity, different text or length. */
|
|
11
|
+
Atom: 1,
|
|
12
|
+
/** Different text; diagnostics covering the whole span exactly show the original text. */
|
|
13
|
+
Alias: 2
|
|
14
|
+
};
|
|
15
|
+
/** Feature bits a span opts into. Diagnostics ignore them. */
|
|
16
|
+
const SpanMapFeature = {
|
|
17
|
+
Hover: 1,
|
|
18
|
+
SignatureHelp: 2,
|
|
19
|
+
Completion: 4,
|
|
20
|
+
Definition: 8,
|
|
21
|
+
TypeDefinition: 16,
|
|
22
|
+
Implementation: 32,
|
|
23
|
+
References: 64,
|
|
24
|
+
DocumentHighlights: 128,
|
|
25
|
+
Rename: 256,
|
|
26
|
+
CallHierarchy: 512,
|
|
27
|
+
CodeActions: 1024,
|
|
28
|
+
Formatting: 2048,
|
|
29
|
+
InlayHints: 4096,
|
|
30
|
+
SemanticTokens: 8192,
|
|
31
|
+
FoldingRanges: 16384,
|
|
32
|
+
SelectionRanges: 32768,
|
|
33
|
+
LinkedEditing: 65536,
|
|
34
|
+
AutoInsert: 1 << 17,
|
|
35
|
+
DocumentSymbols: 1 << 18,
|
|
36
|
+
CodeLens: 1 << 19,
|
|
37
|
+
None: 0,
|
|
38
|
+
All: (1 << 20) - 1
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Diagnostic-directive policies: `Ignore` hides TypeScript's errors in a
|
|
42
|
+
* generated range; `Expect` also reports a diagnostic of the mapper's when
|
|
43
|
+
* there are none there.
|
|
44
|
+
*/
|
|
45
|
+
const DiagnosticDirectivePolicy = {
|
|
46
|
+
Ignore: 0,
|
|
47
|
+
Expect: 1
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* @typedef {[
|
|
51
|
+
* generatedStart: number,
|
|
52
|
+
* generatedLength: number,
|
|
53
|
+
* originalStart: number,
|
|
54
|
+
* originalLength: number,
|
|
55
|
+
* kind: 0 | 1 | 2,
|
|
56
|
+
* features: number,
|
|
57
|
+
* ]} SpanMapping
|
|
58
|
+
*/
|
|
59
|
+
/**
|
|
60
|
+
* @typedef {object} MapperDiagnostic
|
|
61
|
+
* @property {number} start Offset into the original text (UTF-16 code units).
|
|
62
|
+
* @property {number} length
|
|
63
|
+
* @property {number} code
|
|
64
|
+
* @property {string} messageText
|
|
65
|
+
*/
|
|
66
|
+
/**
|
|
67
|
+
* @typedef {object} MappedOutput
|
|
68
|
+
* @property {string} text
|
|
69
|
+
* @property {'.js' | '.jsx' | '.mjs' | '.cjs' | '.ts' | '.tsx' | '.mts' | '.cts' | '.json'} extension
|
|
70
|
+
* @property {SpanMapping[]} mappings
|
|
71
|
+
*/
|
|
72
|
+
/**
|
|
73
|
+
* @typedef {[
|
|
74
|
+
* originalStart: number,
|
|
75
|
+
* originalLength: number,
|
|
76
|
+
* generatedStart: number,
|
|
77
|
+
* generatedEnd: number,
|
|
78
|
+
* policy: 0 | 1,
|
|
79
|
+
* unusedExpectDirectiveIndex?: number,
|
|
80
|
+
* ]} DiagnosticDirective
|
|
81
|
+
*/
|
|
82
|
+
/**
|
|
83
|
+
* @typedef {object} DiagnosticDirectives
|
|
84
|
+
* @property {Array<{ code: number, messageText: string }>} unusedExpectDirectiveDiagnostics What an `Expect` directive reports when TypeScript has no error in its range.
|
|
85
|
+
* @property {DiagnosticDirective[]} directives
|
|
86
|
+
*/
|
|
87
|
+
/**
|
|
88
|
+
* @typedef {MappedOutput & {
|
|
89
|
+
* diagnostics?: MapperDiagnostic[],
|
|
90
|
+
* diagnosticDirectives?: DiagnosticDirectives,
|
|
91
|
+
* supplemental?: MappedOutput[],
|
|
92
|
+
* }} TransformResult
|
|
93
|
+
*/
|
|
94
|
+
/**
|
|
95
|
+
* @typedef {object} InitializeParams
|
|
96
|
+
* @property {string} [locale]
|
|
97
|
+
* @property {Array<'utf-8' | 'utf-16'>} positionEncodings
|
|
98
|
+
*/
|
|
99
|
+
/**
|
|
100
|
+
* @typedef {object} InitializeResult
|
|
101
|
+
* @property {'utf-8' | 'utf-16'} positionEncoding
|
|
102
|
+
* @property {string} diagnosticSource
|
|
103
|
+
*/
|
|
104
|
+
/**
|
|
105
|
+
* @typedef {object} OpenProjectParams
|
|
106
|
+
* @property {string} configFileName Empty for inferred projects.
|
|
107
|
+
* @property {string} projectHandle
|
|
108
|
+
* @property {Record<string, unknown>} [options] The mapper entry's `options` object.
|
|
109
|
+
* @property {Record<string, unknown>} compilerOptions Effective compiler options (wire format).
|
|
110
|
+
*/
|
|
111
|
+
/**
|
|
112
|
+
* @typedef {object} OpenProjectResult
|
|
113
|
+
* @property {string} configIdentity
|
|
114
|
+
* @property {string[]} [watchedFiles]
|
|
115
|
+
* @property {Array<{ path: Array<string | number>, messageText: string, code: number }>} [optionDiagnostics]
|
|
116
|
+
*/
|
|
117
|
+
/**
|
|
118
|
+
* @typedef {object} TransformParams
|
|
119
|
+
* @property {string} fileName
|
|
120
|
+
* @property {string} content
|
|
121
|
+
* @property {string} [projectHandle]
|
|
122
|
+
*/
|
|
123
|
+
|
|
124
|
+
//#endregion
|
|
125
|
+
export { DiagnosticDirectivePolicy, SpanMapFeature, SpanMapKind };
|
|
126
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","names":[],"sources":["../src/protocol.js"],"sourcesContent":["/**\n * Constants of the TypeScript 7 content-mapper protocol, kept in sync with\n * `tsc/internal/contentmapper` and `tsc/internal/spanmap` in microsoft/TypeScript.\n */\n\n/** Span kinds. */\nexport const SpanMapKind = /** @type {const} */ ({\n\t/** Same length and identical text; the only kind that supports text edits. */\n\tVerbatim: 0,\n\t/** Same entity, different text or length. */\n\tAtom: 1,\n\t/** Different text; diagnostics covering the whole span exactly show the original text. */\n\tAlias: 2,\n});\n\n/** Feature bits a span opts into. Diagnostics ignore them. */\nexport const SpanMapFeature = /** @type {const} */ ({\n\tHover: 1 << 0,\n\tSignatureHelp: 1 << 1,\n\tCompletion: 1 << 2,\n\tDefinition: 1 << 3,\n\tTypeDefinition: 1 << 4,\n\tImplementation: 1 << 5,\n\tReferences: 1 << 6,\n\tDocumentHighlights: 1 << 7,\n\tRename: 1 << 8,\n\tCallHierarchy: 1 << 9,\n\tCodeActions: 1 << 10,\n\tFormatting: 1 << 11,\n\tInlayHints: 1 << 12,\n\tSemanticTokens: 1 << 13,\n\tFoldingRanges: 1 << 14,\n\tSelectionRanges: 1 << 15,\n\tLinkedEditing: 1 << 16,\n\tAutoInsert: 1 << 17,\n\tDocumentSymbols: 1 << 18,\n\tCodeLens: 1 << 19,\n\tNone: 0,\n\tAll: (1 << 20) - 1,\n});\n\n/**\n * Diagnostic-directive policies: `Ignore` hides TypeScript's errors in a\n * generated range; `Expect` also reports a diagnostic of the mapper's when\n * there are none there.\n */\nexport const DiagnosticDirectivePolicy = /** @type {const} */ ({ Ignore: 0, Expect: 1 });\n\n/**\n * @typedef {[\n * \tgeneratedStart: number,\n * \tgeneratedLength: number,\n * \toriginalStart: number,\n * \toriginalLength: number,\n * \tkind: 0 | 1 | 2,\n * \tfeatures: number,\n * ]} SpanMapping\n */\n\n/**\n * @typedef {object} MapperDiagnostic\n * @property {number} start Offset into the original text (UTF-16 code units).\n * @property {number} length\n * @property {number} code\n * @property {string} messageText\n */\n\n/**\n * @typedef {object} MappedOutput\n * @property {string} text\n * @property {'.js' | '.jsx' | '.mjs' | '.cjs' | '.ts' | '.tsx' | '.mts' | '.cts' | '.json'} extension\n * @property {SpanMapping[]} mappings\n */\n\n/**\n * @typedef {[\n * \toriginalStart: number,\n * \toriginalLength: number,\n * \tgeneratedStart: number,\n * \tgeneratedEnd: number,\n * \tpolicy: 0 | 1,\n * \tunusedExpectDirectiveIndex?: number,\n * ]} DiagnosticDirective\n */\n\n/**\n * @typedef {object} DiagnosticDirectives\n * @property {Array<{ code: number, messageText: string }>} unusedExpectDirectiveDiagnostics What an `Expect` directive reports when TypeScript has no error in its range.\n * @property {DiagnosticDirective[]} directives\n */\n\n/**\n * @typedef {MappedOutput & {\n * \tdiagnostics?: MapperDiagnostic[],\n * \tdiagnosticDirectives?: DiagnosticDirectives,\n * \tsupplemental?: MappedOutput[],\n * }} TransformResult\n */\n\n/**\n * @typedef {object} InitializeParams\n * @property {string} [locale]\n * @property {Array<'utf-8' | 'utf-16'>} positionEncodings\n */\n\n/**\n * @typedef {object} InitializeResult\n * @property {'utf-8' | 'utf-16'} positionEncoding\n * @property {string} diagnosticSource\n */\n\n/**\n * @typedef {object} OpenProjectParams\n * @property {string} configFileName Empty for inferred projects.\n * @property {string} projectHandle\n * @property {Record<string, unknown>} [options] The mapper entry's `options` object.\n * @property {Record<string, unknown>} compilerOptions Effective compiler options (wire format).\n */\n\n/**\n * @typedef {object} OpenProjectResult\n * @property {string} configIdentity\n * @property {string[]} [watchedFiles]\n * @property {Array<{ path: Array<string | number>, messageText: string, code: number }>} [optionDiagnostics]\n */\n\n/**\n * @typedef {object} TransformParams\n * @property {string} fileName\n * @property {string} content\n * @property {string} [projectHandle]\n */\n"],"mappings":";;;;;;AAMA,MAAa,cAAoC;;CAEhD,UAAU;;CAEV,MAAM;;CAEN,OAAO;AACR;;AAGA,MAAa,iBAAuC;CACnD,OAAO;CACP,eAAe;CACf,YAAY;CACZ,YAAY;CACZ,gBAAgB;CAChB,gBAAgB;CAChB,YAAY;CACZ,oBAAoB;CACpB,QAAQ;CACR,eAAe;CACf,aAAa;CACb,YAAY;CACZ,YAAY;CACZ,gBAAgB;CAChB,eAAe;CACf,iBAAiB;CACjB,eAAe;CACf,YAAY,KAAK;CACjB,iBAAiB,KAAK;CACtB,UAAU,KAAK;CACf,MAAM;CACN,MAAM,KAAK,MAAM;AAClB;;;;;;AAOA,MAAa,4BAAkD;CAAE,QAAQ;CAAG,QAAQ;AAAE"}
|
package/dist/rpc.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { Console } from "node:console";
|
|
2
|
+
|
|
3
|
+
//#region src/rpc.js
|
|
4
|
+
/**
|
|
5
|
+
* Content-mapper transport: `Content-Length`-framed JSON-RPC 2.0 over stdio.
|
|
6
|
+
* TypeScript is the only requester; the mapper never sends requests or
|
|
7
|
+
* notifications. stdout is reserved for protocol messages, so everything
|
|
8
|
+
* else (including `console.log`) goes to stderr.
|
|
9
|
+
*
|
|
10
|
+
* Kept separate from the executable entry (`server.js`) so hosts that bundle
|
|
11
|
+
* the mapper (the VS Code extension ships it for inferred projects) can start
|
|
12
|
+
* it from their own entry file.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {{ jsonrpc: '2.0', id?: number | string | null, method: string, params?: unknown }} RequestMessage
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Run the mapper server on the given streams. Installs the stream handlers
|
|
19
|
+
* and returns; the process exits (with `process.exitCode`) once the input
|
|
20
|
+
* stream ends, which is how TypeScript shuts a mapper down.
|
|
21
|
+
* @param {import('./mapper.js').ContentMapper} mapper
|
|
22
|
+
* @param {{ input?: NodeJS.ReadableStream, output?: NodeJS.WritableStream }} [streams]
|
|
23
|
+
*/
|
|
24
|
+
function run_mapper_server(mapper, streams = {}) {
|
|
25
|
+
const input = streams.input ?? process.stdin;
|
|
26
|
+
const output = streams.output ?? process.stdout;
|
|
27
|
+
let buffered = Buffer.alloc(0);
|
|
28
|
+
input.on("data", (chunk) => {
|
|
29
|
+
buffered = Buffer.concat([buffered, typeof chunk === "string" ? Buffer.from(chunk) : chunk]);
|
|
30
|
+
read_messages();
|
|
31
|
+
});
|
|
32
|
+
input.on("error", (error) => {
|
|
33
|
+
console.error(error);
|
|
34
|
+
process.exitCode = 1;
|
|
35
|
+
});
|
|
36
|
+
input.on("end", () => {
|
|
37
|
+
process.exit(process.exitCode ?? 0);
|
|
38
|
+
});
|
|
39
|
+
function read_messages() {
|
|
40
|
+
while (true) {
|
|
41
|
+
const header_end = buffered.indexOf("\r\n\r\n");
|
|
42
|
+
if (header_end < 0) return;
|
|
43
|
+
const header = buffered.subarray(0, header_end).toString("ascii");
|
|
44
|
+
const length_match = /^Content-Length:\s*(\d+)\s*$/im.exec(header);
|
|
45
|
+
if (!length_match) {
|
|
46
|
+
console.error("@tsrx/content-mapper: missing Content-Length header");
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
const content_length = Number(length_match[1]);
|
|
50
|
+
const message_start = header_end + 4;
|
|
51
|
+
const message_end = message_start + content_length;
|
|
52
|
+
if (buffered.length < message_end) return;
|
|
53
|
+
const body = buffered.subarray(message_start, message_end).toString("utf8");
|
|
54
|
+
buffered = buffered.subarray(message_end);
|
|
55
|
+
/** @type {RequestMessage} */
|
|
56
|
+
let message;
|
|
57
|
+
try {
|
|
58
|
+
message = JSON.parse(body);
|
|
59
|
+
} catch (error) {
|
|
60
|
+
console.error("@tsrx/content-mapper: invalid JSON-RPC message", error);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
handle_message(message);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** @param {RequestMessage} message */
|
|
67
|
+
function handle_message(message) {
|
|
68
|
+
if (message.id === void 0 || message.id === null) return;
|
|
69
|
+
try {
|
|
70
|
+
/** @type {unknown} */
|
|
71
|
+
let result;
|
|
72
|
+
switch (message.method) {
|
|
73
|
+
case "initialize":
|
|
74
|
+
result = mapper.initialize(message.params);
|
|
75
|
+
break;
|
|
76
|
+
case "openProject":
|
|
77
|
+
result = mapper.openProject(message.params);
|
|
78
|
+
break;
|
|
79
|
+
case "closeProject":
|
|
80
|
+
mapper.closeProject(message.params);
|
|
81
|
+
result = null;
|
|
82
|
+
break;
|
|
83
|
+
case "transform":
|
|
84
|
+
result = mapper.transform(message.params);
|
|
85
|
+
break;
|
|
86
|
+
default:
|
|
87
|
+
write({
|
|
88
|
+
jsonrpc: "2.0",
|
|
89
|
+
id: message.id,
|
|
90
|
+
error: {
|
|
91
|
+
code: -32601,
|
|
92
|
+
message: `Unknown method ${message.method}`
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
write({
|
|
98
|
+
jsonrpc: "2.0",
|
|
99
|
+
id: message.id,
|
|
100
|
+
result
|
|
101
|
+
});
|
|
102
|
+
} catch (error) {
|
|
103
|
+
write({
|
|
104
|
+
jsonrpc: "2.0",
|
|
105
|
+
id: message.id,
|
|
106
|
+
error: {
|
|
107
|
+
code: -32603,
|
|
108
|
+
message: error instanceof Error ? error.stack ?? error.message : String(error)
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/** @param {unknown} message */
|
|
114
|
+
function write(message) {
|
|
115
|
+
const body = Buffer.from(JSON.stringify(message), "utf8");
|
|
116
|
+
output.write(`Content-Length: ${body.length}\r\n\r\n`);
|
|
117
|
+
output.write(body);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Route every console method to stderr so stray logging (from a target
|
|
122
|
+
* compiler, for example) can never corrupt the protocol stream on stdout: not
|
|
123
|
+
* only `log` but `dir`, `table`, `trace`, `group` and the rest write there, so
|
|
124
|
+
* each takes the method of a console whose stdout is stderr.
|
|
125
|
+
*/
|
|
126
|
+
function redirect_console_to_stderr() {
|
|
127
|
+
const to_stderr = new Console({
|
|
128
|
+
stdout: process.stderr,
|
|
129
|
+
stderr: process.stderr
|
|
130
|
+
});
|
|
131
|
+
for (const [name, method] of Object.entries(to_stderr)) if (typeof method === "function")
|
|
132
|
+
/** @type {Record<string, unknown>} */ console[name] = method;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
//#endregion
|
|
136
|
+
export { redirect_console_to_stderr, run_mapper_server };
|
|
137
|
+
//# sourceMappingURL=rpc.js.map
|
package/dist/rpc.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc.js","names":[],"sources":["../src/rpc.js"],"sourcesContent":["/**\n * Content-mapper transport: `Content-Length`-framed JSON-RPC 2.0 over stdio.\n * TypeScript is the only requester; the mapper never sends requests or\n * notifications. stdout is reserved for protocol messages, so everything\n * else (including `console.log`) goes to stderr.\n *\n * Kept separate from the executable entry (`server.js`) so hosts that bundle\n * the mapper (the VS Code extension ships it for inferred projects) can start\n * it from their own entry file.\n */\n\nimport { Console } from 'node:console';\n\n/**\n * @typedef {{ jsonrpc: '2.0', id?: number | string | null, method: string, params?: unknown }} RequestMessage\n */\n\n/**\n * Run the mapper server on the given streams. Installs the stream handlers\n * and returns; the process exits (with `process.exitCode`) once the input\n * stream ends, which is how TypeScript shuts a mapper down.\n * @param {import('./mapper.js').ContentMapper} mapper\n * @param {{ input?: NodeJS.ReadableStream, output?: NodeJS.WritableStream }} [streams]\n */\nexport function run_mapper_server(mapper, streams = {}) {\n\tconst input = streams.input ?? process.stdin;\n\tconst output = streams.output ?? process.stdout;\n\tlet buffered = Buffer.alloc(0);\n\n\tinput.on('data', (chunk) => {\n\t\tbuffered = Buffer.concat([buffered, typeof chunk === 'string' ? Buffer.from(chunk) : chunk]);\n\t\tread_messages();\n\t});\n\tinput.on('error', (error) => {\n\t\tconsole.error(error);\n\t\tprocess.exitCode = 1;\n\t});\n\tinput.on('end', () => {\n\t\tprocess.exit(process.exitCode ?? 0);\n\t});\n\n\tfunction read_messages() {\n\t\twhile (true) {\n\t\t\tconst header_end = buffered.indexOf('\\r\\n\\r\\n');\n\t\t\tif (header_end < 0) return;\n\t\t\tconst header = buffered.subarray(0, header_end).toString('ascii');\n\t\t\tconst length_match = /^Content-Length:\\s*(\\d+)\\s*$/im.exec(header);\n\t\t\tif (!length_match) {\n\t\t\t\tconsole.error('@tsrx/content-mapper: missing Content-Length header');\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\t\t\tconst content_length = Number(length_match[1]);\n\t\t\tconst message_start = header_end + 4;\n\t\t\tconst message_end = message_start + content_length;\n\t\t\tif (buffered.length < message_end) return;\n\t\t\tconst body = buffered.subarray(message_start, message_end).toString('utf8');\n\t\t\tbuffered = buffered.subarray(message_end);\n\t\t\t/** @type {RequestMessage} */\n\t\t\tlet message;\n\t\t\ttry {\n\t\t\t\tmessage = JSON.parse(body);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error('@tsrx/content-mapper: invalid JSON-RPC message', error);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\thandle_message(message);\n\t\t}\n\t}\n\n\t/** @param {RequestMessage} message */\n\tfunction handle_message(message) {\n\t\tif (message.id === undefined || message.id === null) {\n\t\t\t// Notifications need no response.\n\t\t\treturn;\n\t\t}\n\t\ttry {\n\t\t\t/** @type {unknown} */\n\t\t\tlet result;\n\t\t\tswitch (message.method) {\n\t\t\t\tcase 'initialize':\n\t\t\t\t\tresult = mapper.initialize(/** @type {any} */ (message.params));\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'openProject':\n\t\t\t\t\tresult = mapper.openProject(/** @type {any} */ (message.params));\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'closeProject':\n\t\t\t\t\tmapper.closeProject(/** @type {any} */ (message.params));\n\t\t\t\t\tresult = null;\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'transform':\n\t\t\t\t\tresult = mapper.transform(/** @type {any} */ (message.params));\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\twrite({\n\t\t\t\t\t\tjsonrpc: '2.0',\n\t\t\t\t\t\tid: message.id,\n\t\t\t\t\t\terror: { code: -32601, message: `Unknown method ${message.method}` },\n\t\t\t\t\t});\n\t\t\t\t\treturn;\n\t\t\t}\n\t\t\twrite({ jsonrpc: '2.0', id: message.id, result });\n\t\t} catch (error) {\n\t\t\twrite({\n\t\t\t\tjsonrpc: '2.0',\n\t\t\t\tid: message.id,\n\t\t\t\terror: {\n\t\t\t\t\tcode: -32603,\n\t\t\t\t\tmessage: error instanceof Error ? (error.stack ?? error.message) : String(error),\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t}\n\n\t/** @param {unknown} message */\n\tfunction write(message) {\n\t\tconst body = Buffer.from(JSON.stringify(message), 'utf8');\n\t\toutput.write(`Content-Length: ${body.length}\\r\\n\\r\\n`);\n\t\toutput.write(body);\n\t}\n}\n\n/**\n * Route every console method to stderr so stray logging (from a target\n * compiler, for example) can never corrupt the protocol stream on stdout: not\n * only `log` but `dir`, `table`, `trace`, `group` and the rest write there, so\n * each takes the method of a console whose stdout is stderr.\n */\nexport function redirect_console_to_stderr() {\n\tconst to_stderr = new Console({ stdout: process.stderr, stderr: process.stderr });\n\tfor (const [name, method] of Object.entries(to_stderr)) {\n\t\tif (typeof method === 'function') {\n\t\t\t/** @type {Record<string, unknown>} */ (/** @type {unknown} */ (console))[name] = method;\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,kBAAkB,Q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