Skip to content

Commit 02e10a5

Browse files
joyeecheungdanielleadams
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 c5e04c5 commit 02e10a5

File tree

5 files changed

+168841
-0
lines changed

5 files changed

+168841
-0
lines changed

test/fixtures/snapshot/ts-example.js

Lines changed: 8 additions & 0 deletions
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

Lines changed: 11 additions & 0 deletions
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);
Lines changed: 28 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy