|
6 | 6 | * This transformer requires TypeScript to be at least 3.9.
|
7 | 7 | *
|
8 | 8 | * @param {opt} opts Options
|
9 |
| - * @param {ts} ts TypeScript compiler |
10 | 9 | * @returns {import('typescript').TransformerFactory<SourceFile>}
|
11 | 10 | */
|
12 |
| -export default function(opts = {}, ts = require('typescript')) { |
| 11 | +export default function(opts = {}) { |
| 12 | + const ts = opts.ts || require('typescript'); |
13 | 13 | {
|
14 | 14 | const [major, minor] = ts.version.split('.');
|
15 | 15 | const num = parseInt(major);
|
16 | 16 | const msg = 'TypeScript should be at least 3.9';
|
17 | 17 | if (num < 3) throw new Error(msg);
|
18 | 18 | if (num === 3 && parseInt(minor) !== 9) throw new Error(msg);
|
19 | 19 | }
|
20 |
| - const printer = ts.createPrinter(); |
21 | 20 | const refreshReg = ts.createIdentifier(opts.refreshReg || '$RefreshReg$');
|
22 | 21 | const refreshSig = ts.createIdentifier(opts.refreshSig || '$RefreshSig$');
|
23 | 22 | return context => {
|
@@ -754,7 +753,7 @@ function startsWithLowerCase(str) {
|
754 | 753 | return str[0].toLowerCase() === str[0];
|
755 | 754 | }
|
756 | 755 |
|
757 |
| -/** @typedef {{refreshReg?: string, refreshSig?: string, emitFullSignatures?: boolean}} opt */ |
| 756 | +/** @typedef {{refreshReg?: string, refreshSig?: string, emitFullSignatures?: boolean, ts?: ts}} opt */ |
758 | 757 | /** @typedef {import('typescript')} ts */
|
759 | 758 | /** @typedef {import('typescript').Node} Node */
|
760 | 759 | /** @typedef {import('typescript').Statement} Statement */
|
|
0 commit comments