-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
a63af1f
commit 48229e5
Showing
5 changed files
with
168,841 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); |
Oops, something went wrong.