-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcompileTests.ts
40 lines (30 loc) · 1.4 KB
/
compileTests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import * as ts from "typescript";
import Transformer from '../src/transformer';
function compile(fileNames: string[], options: ts.CompilerOptions): void {
let program = ts.createProgram(fileNames, options);
let emitResult = program.emit(undefined, undefined, undefined, undefined, {before: [Transformer(program)]});
let allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
allDiagnostics.forEach(diagnostic => {
let message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
if (diagnostic.file) {
let { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start!);
console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
} else {
console.log(`${message}`);
}
});
let exitCode = emitResult.emitSkipped ? 1 : 0;
console.log(`Process exiting with code '${exitCode}'.`);
process.exit(exitCode);
}
// const a = ts.convertCompilerOptionsFromJson({}, '../../')
// const a = ts.parseCommandLine(process.argv)
compile(process.argv.slice(2), {
noEmitOnError: true, noImplicitAny: true,
target: ts.ScriptTarget.ES5, module: ts.ModuleKind.CommonJS,
emitDecoratorMetadata: true,
strict: true,
lib: ["lib.dom.d.ts", "lib.es2015.d.ts"],
experimentalDecorators: true,
outDir: "./tests/emit_output"
});