Skip to content

Commit

Permalink
test: test snapshotting TypeScript compiler
Browse files Browse the repository at this point in the history
PR-URL: #38905
Refs: #35711
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
joyeecheung authored and danielleadams committed Aug 11, 2022
1 parent c5e04c5 commit 02e10a5
Show file tree
Hide file tree
Showing 5 changed files with 168,841 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/fixtures/snapshot/ts-example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var VirtualPoint = /** @class */ (function () {
function VirtualPoint(x, y) {
this.x = x;
this.y = y;
}
return VirtualPoint;
}());
var newVPoint = new VirtualPoint(13, 56);
11 changes: 11 additions & 0 deletions test/fixtures/snapshot/ts-example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class VirtualPoint {
x: number;
y: number;

constructor(x: number, y: number) {
this.x = x;
this.y = y;
}
}

const newVPoint = new VirtualPoint(13, 56);
28 changes: 28 additions & 0 deletions test/fixtures/snapshot/typescript-main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// This file is to be concatenated with
// https://github.com/microsoft/TypeScript/blob/main/lib/typescript.js
// to produce a snapshot that reads a file path from the command
// line and compile it into JavaScript, then write the
// result into another file.

const fs = require('fs');
const v8 = require('v8');
const assert = require('assert');

v8.startupSnapshot.setDeserializeMainFunction(( { ts }) => {
const input = process.argv[1];
const output = process.argv[2];
console.error(`Compiling ${input} to ${output}`);
assert(input);
assert(output);
const source = fs.readFileSync(input, 'utf8');

let result = ts.transpileModule(
source,
{
compilerOptions: {
module: ts.ModuleKind.CommonJS
}
});

fs.writeFileSync(output, result.outputText, 'utf8');
}, { ts });
Loading

0 comments on commit 02e10a5

Please sign in to comment.