|
1 | | -const fs = require('node:fs'); |
2 | | -const ts = require('typescript'); |
3 | | -const path = require('node:path'); |
| 1 | +const fs = require("node:fs"); |
| 2 | +const ts = require("typescript"); |
| 3 | +const path = require("node:path"); |
4 | 4 |
|
5 | | -const filePath = path.join(__dirname, '..', 'fixtures', 'ts-sample.ts'); |
| 5 | +const filePath = path.join(__dirname, "..", "fixtures", "ts-sample.ts"); |
| 6 | +const code = fs.readFileSync(filePath, "utf8"); |
6 | 7 |
|
7 | | -const code = fs.readFileSync(filePath, 'utf8'); |
| 8 | +module.exports = { |
| 9 | + name: "typescript", |
| 10 | + type: "operation", |
| 11 | + operations: [ |
| 12 | + { |
| 13 | + name: "transpile", |
| 14 | + fn: () => { |
| 15 | + ts.transpile( |
| 16 | + code, |
| 17 | + { |
| 18 | + // CJS Settings |
| 19 | + target: ts.ScriptTarget.ESNext, |
| 20 | + module: ts.ModuleKind.CommonJS, |
| 21 | + moduleResolution: ts.ModuleResolutionKind.Node, |
8 | 22 |
|
9 | | -/** @type {import('typescript').CompilerOptions} */ |
10 | | -const compilerOptions = { |
11 | | - // also loads and checks js |
12 | | - allowJs: true, |
13 | | - checkJs: true, |
| 23 | + // Avoid writing to disk |
| 24 | + noEmit: true, |
14 | 25 |
|
15 | | - target: ts.ScriptTarget.ESNext, |
16 | | - module: ts.ModuleKind.ESNext, |
| 26 | + // Avoids any checking related code |
| 27 | + checkJs: false, |
| 28 | + strict: false, |
| 29 | + isolatedModules: true, |
| 30 | + skipDefaultLibCheck: true, |
| 31 | + skipLibCheck: true, |
| 32 | + }, |
| 33 | + filePath, |
| 34 | + ); |
| 35 | + }, |
| 36 | + }, |
| 37 | + { |
| 38 | + name: "createSourceFile", |
| 39 | + fn: () => { |
| 40 | + ts.createSourceFile( |
| 41 | + filePath, |
| 42 | + code, |
| 43 | + ts.ScriptTarget.ESNext, |
| 44 | + false, |
| 45 | + ts.ScriptKind.TS, |
| 46 | + ); |
| 47 | + }, |
| 48 | + }, |
| 49 | + { |
| 50 | + name: "getSemanticDiagnostics", |
| 51 | + fn: () => { |
| 52 | + const program = ts.createProgram({ |
| 53 | + rootNames: [filePath], |
| 54 | + options: { |
| 55 | + // CJS Settings |
| 56 | + target: ts.ScriptTarget.ESNext, |
| 57 | + module: ts.ModuleKind.CommonJS, |
| 58 | + moduleResolution: ts.ModuleResolutionKind.Node, |
17 | 59 |
|
18 | | - // test types |
19 | | - strict: true, |
| 60 | + // also loads and checks js |
| 61 | + allowJs: true, |
| 62 | + checkJs: true, |
20 | 63 |
|
21 | | - // loads all declarations |
22 | | - isolatedModules: false, |
23 | | - skipDefaultLibCheck: false, |
24 | | - skipLibCheck: false |
25 | | -}; |
| 64 | + // test types |
| 65 | + strict: true, |
26 | 66 |
|
27 | | -module.exports = { |
28 | | - name: 'typescript', |
29 | | - type: 'operation', |
30 | | - operations: [ |
31 | | - { |
32 | | - name: 'transpile', |
33 | | - fn: () => { |
34 | | - ts.transpileModule(code, { |
35 | | - compilerOptions: compilerOptions, |
36 | | - fileName: filePath, |
37 | | - reportDiagnostics: true |
38 | | - }); |
39 | | - } |
40 | | - }, |
41 | | - { |
42 | | - name: 'createSourceFile', |
43 | | - fn: () => { |
44 | | - ts.createSourceFile( |
45 | | - filePath, |
46 | | - code, |
47 | | - ts.ScriptTarget.ESNext, |
48 | | - true, |
49 | | - ts.ScriptKind.TS |
50 | | - ); |
51 | | - } |
52 | | - }, |
53 | | - { |
54 | | - name: 'getTypeChecker', |
55 | | - fn: () => { |
56 | | - ts.createProgram({ |
57 | | - rootNames: [filePath], |
58 | | - options: compilerOptions |
59 | | - }).getTypeChecker(); |
60 | | - } |
61 | | - } |
62 | | - ], |
63 | | - benchmarker: 'tinybench' |
| 67 | + // Avoid writing to disk |
| 68 | + noEmit: true, |
| 69 | + |
| 70 | + // Avoids loading external files |
| 71 | + isolatedModules: true, |
| 72 | + skipDefaultLibCheck: true, |
| 73 | + skipLibCheck: true, |
| 74 | + }, |
| 75 | + }); |
| 76 | + |
| 77 | + program.getSemanticDiagnostics(program.getSourceFile(filePath)); |
| 78 | + }, |
| 79 | + }, |
| 80 | + ], |
| 81 | + benchmarker: "tinybench", |
64 | 82 | }; |
0 commit comments