Skip to content

Commit

Permalink
Fix global __assign and other functions for tsc
Browse files Browse the repository at this point in the history
  • Loading branch information
cevek committed Sep 7, 2020
1 parent 1db6195 commit 505e3aa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 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.11",
"version": "1.5.12",
"description": "Over TypeScript tool to use custom transformers in the tsconfig.json",
"main": "lib/typescript.js",
"files": [
Expand Down
16 changes: 10 additions & 6 deletions packages/ttypescript/src/tsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ const ts = loadTypeScript('typescript', { folder: process.cwd(), forceConfigLoad
const tscFileName = resolve.sync('typescript/lib/tsc', { basedir: process.cwd() });
const commandLineTsCode = fs
.readFileSync(tscFileName, 'utf8')
.replace(/^[\s\S]+(\(function \(ts\) \{\s+function countLines[\s\S]+)$/, '$1')
.replace(/^[\s\S]+(\(function \(ts\) \{\s+function countLines[\s\S]+)$/, '$1');

runInThisContext(`(function (exports, require, module, __filename, __dirname, ts) {${commandLineTsCode}\n});`, {
filename: tscFileName,
lineOffset: 0,
displayErrors: true,
}).call(ts, ts, require, { exports: ts }, tscFileName, dirname(tscFileName), ts);
const globalCode = (fs.readFileSync(tscFileName, 'utf8').match(/^([\s\S]*?)var ts;/) || ['', ''])[1];
runInThisContext(
`(function (exports, require, module, __filename, __dirname, ts) {${globalCode}${commandLineTsCode}\n});`,
{
filename: tscFileName,
lineOffset: 0,
displayErrors: true,
}
).call(ts, ts, require, { exports: ts }, tscFileName, dirname(tscFileName), ts);

0 comments on commit 505e3aa

Please sign in to comment.