Skip to content
This repository has been archived by the owner on Jun 27, 2018. It is now read-only.

Commit

Permalink
Rename compile() arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
teppeis committed Jan 17, 2015
1 parent 8a2dc89 commit 2c309df
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ try {

## API

### compile(code: string, options: typescript.CompilerOptions): string
### compile(code: string, options?: typescript.CompilerOptions): string

* `code`: TypeScript input source code string
* `options`: TypeScript compiler options
Expand Down
20 changes: 10 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ var path = require('path');
var ts = require('typescript');
var FILENAME_TS = 'file.ts';
/**
* @param {string} contents TypeScript source code to compile
* @param {ts.CompilerOptions} compilerOptions TypeScript compile options (some options are ignored)
* @param {string} code TypeScript source code to compile
* @param {ts.CompilerOptions=} options TypeScript compile options (some options are ignored)
*/
function compile(contents, compilerOptions) {
if (compilerOptions === void 0) { compilerOptions = {}; }
if (compilerOptions.target == null) {
compilerOptions.target = 0 /* ES3 */;
function compile(code, options) {
if (options === void 0) { options = {}; }
if (options.target == null) {
options.target = 0 /* ES3 */;
}
if (compilerOptions.module == null) {
compilerOptions.module = 0 /* None */;
if (options.module == null) {
options.module = 0 /* None */;
}
var outputs = {};
var compilerHost = {
getSourceFile: function (filename, languageVersion) {
if (filename === FILENAME_TS) {
return ts.createSourceFile(filename, contents, languageVersion, '0');
return ts.createSourceFile(filename, code, languageVersion, '0');
}
else if (/^lib(?:\.es6)?\.d\.ts$/.test(filename)) {
var libPath = path.join(path.dirname(require.resolve('typescript')), filename);
Expand Down Expand Up @@ -54,7 +54,7 @@ function compile(contents, compilerOptions) {
return os.EOL;
}
};
var program = ts.createProgram([FILENAME_TS], compilerOptions, compilerHost);
var program = ts.createProgram([FILENAME_TS], options, compilerHost);
var diagnostics = program.getDiagnostics();
if (diagnostics.length > 0) {
throw new Error(formatDiagnostics(diagnostics));
Expand Down
18 changes: 9 additions & 9 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ import ts = require('typescript');
var FILENAME_TS = 'file.ts';

/**
* @param {string} contents TypeScript source code to compile
* @param {ts.CompilerOptions} compilerOptions TypeScript compile options (some options are ignored)
* @param {string} code TypeScript source code to compile
* @param {ts.CompilerOptions=} options TypeScript compile options (some options are ignored)
*/
function compile(contents: string, compilerOptions: ts.CompilerOptions = {}) {
if (compilerOptions.target == null) {
compilerOptions.target = ts.ScriptTarget.ES3;
function compile(code: string, options: ts.CompilerOptions = {}) {
if (options.target == null) {
options.target = ts.ScriptTarget.ES3;
}
if (compilerOptions.module == null) {
compilerOptions.module = ts.ModuleKind.None;
if (options.module == null) {
options.module = ts.ModuleKind.None;
}

var outputs: {[index: string]: string} = {};
var compilerHost = {
getSourceFile: function(filename: string, languageVersion: ts.ScriptTarget) {
if (filename === FILENAME_TS) {
return ts.createSourceFile(filename, contents, languageVersion, '0');
return ts.createSourceFile(filename, code, languageVersion, '0');
} else if (/^lib(?:\.es6)?\.d\.ts$/.test(filename)) {
var libPath = path.join(path.dirname(require.resolve('typescript')), filename);
var libSource = fs.readFileSync(libPath).toString();
Expand All @@ -49,7 +49,7 @@ function compile(contents: string, compilerOptions: ts.CompilerOptions = {}) {
getNewLine: function() { return os.EOL; }
};

var program = ts.createProgram([FILENAME_TS], compilerOptions, compilerHost);
var program = ts.createProgram([FILENAME_TS], options, compilerHost);
var diagnostics = program.getDiagnostics();
if (diagnostics.length > 0) {
throw new Error(formatDiagnostics(diagnostics));
Expand Down

0 comments on commit 2c309df

Please sign in to comment.