Skip to content

Commit 40b817c

Browse files
joyeecheungruyadorno
authored andcommitted
test: test snapshotting TypeScript compiler
PR-URL: #38905 Refs: #35711 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent d4189ab commit 40b817c

File tree

5 files changed

+168841
-0
lines changed

5 files changed

+168841
-0
lines changed

test/fixtures/snapshot/ts-example.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var VirtualPoint = /** @class */ (function () {
2+
function VirtualPoint(x, y) {
3+
this.x = x;
4+
this.y = y;
5+
}
6+
return VirtualPoint;
7+
}());
8+
var newVPoint = new VirtualPoint(13, 56);

test/fixtures/snapshot/ts-example.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class VirtualPoint {
2+
x: number;
3+
y: number;
4+
5+
constructor(x: number, y: number) {
6+
this.x = x;
7+
this.y = y;
8+
}
9+
}
10+
11+
const newVPoint = new VirtualPoint(13, 56);
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// This file is to be concatenated with
2+
// https://github.com/microsoft/TypeScript/blob/main/lib/typescript.js
3+
// to produce a snapshot that reads a file path from the command
4+
// line and compile it into JavaScript, then write the
5+
// result into another file.
6+
7+
const fs = require('fs');
8+
const v8 = require('v8');
9+
const assert = require('assert');
10+
11+
v8.startupSnapshot.setDeserializeMainFunction(( { ts }) => {
12+
const input = process.argv[1];
13+
const output = process.argv[2];
14+
console.error(`Compiling ${input} to ${output}`);
15+
assert(input);
16+
assert(output);
17+
const source = fs.readFileSync(input, 'utf8');
18+
19+
let result = ts.transpileModule(
20+
source,
21+
{
22+
compilerOptions: {
23+
module: ts.ModuleKind.CommonJS
24+
}
25+
});
26+
27+
fs.writeFileSync(output, result.outputText, 'utf8');
28+
}, { ts });

0 commit comments

Comments
 (0)