GeezerVison is showing github.com — test: test snapshotting TypeScript compiler · nodejs/node@02e10a5
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboard +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 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); |
Collapse file
Copy file name to clipboard +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 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); |
Collapse file
Copy file name to clipboard +28Lines changed: 28 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 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 }); |