Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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>
  • Loading branch information
joyeecheung committed Aug 2, 2022
commit 7bf1941e8e3597309ace47b0cd0c1f7ab3ee334b
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