Skip to content

Commit

Permalink
Fix #134 - support TS 4.9 (#135)
Browse files Browse the repository at this point in the history
* Fix #134 - support TS 4.9

* update version number

Co-authored-by: Jeongho Nam <samchon@archisketch.cmo>
  • Loading branch information
samchon and Jeongho Nam authored Dec 9, 2022
1 parent a81ff17 commit f37f095
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/ttypescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"ttsc": "./bin/tsc",
"ttsserver": "./bin/tsserver"
},
"version": "1.5.12",
"version": "1.5.14",
"description": "Over TypeScript tool to use custom transformers in the tsconfig.json",
"main": "lib/typescript.js",
"files": [
Expand Down
12 changes: 11 additions & 1 deletion packages/ttypescript/src/tsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@ import { runInThisContext } from 'vm';

const ts = loadTypeScript('typescript', { folder: process.cwd(), forceConfigLoad: true });
const tscFileName = resolve.sync('typescript/lib/tsc', { basedir: process.cwd() });
const [major, minor]: [number, number] =
ts.version.split(".").map(
(str: string) => Number(str)
) as [number, number];

const commandLineTsCode = fs
.readFileSync(tscFileName, 'utf8')
.replace(/^[\s\S]+(\(function \(ts\) \{\s+function countLines[\s\S]+)$/, '$1');
.replace(
major >= 4 && minor >= 9
? /^[\s\S]+(\(function \(ts\) {\s+var StatisticType;[\s\S]+)$/
: /^[\s\S]+(\(function \(ts\) \{\s+function countLines[\s\S]+)$/,
'$1'
);

const globalCode = (fs.readFileSync(tscFileName, 'utf8').match(/^([\s\S]*?)var ts;/) || ['', ''])[1];
runInThisContext(
Expand Down

0 comments on commit f37f095

Please sign in to comment.