Skip to content

Commit

Permalink
fix: Restored getSource file fallback implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
roman.vasilev committed Aug 26, 2018
1 parent 562bf9b commit e29755c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/get-source-file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as ts from 'typescript';

export function getSourceFile(program: ts.Program, fileName: string, sourceText?: string): ts.SourceFile {
if (program !== undefined) {
const sourceFile = program.getSourceFile(fileName);
if (sourceFile) {
return sourceFile;
}
}
if (sourceText === undefined) {
throw new Error(`Invalid source file: ${fileName}`);
}
return ts.createSourceFile(fileName, sourceText, ts.ScriptTarget.ES5, true);
}
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as ts from 'typescript';
import { createProgram } from './create-program';
import { getSourceFile } from './get-source-file';

type createServiceOptions = {
configFile: string;
Expand All @@ -18,7 +19,7 @@ export function createService({ compilerOptions, configFile }: createServiceOpti
program = ts.createProgram(rootFileNames, program.getCompilerOptions(), host, program);
sourceFile = program.getSourceFile(fileName);
}
return sourceFile;
return sourceFile || getSourceFile(program, fileName, sourceText);
},
getDiagnostics: (fileName: string, sourceText?: string) => {
const sourceFile = api.getSourceFile(fileName, sourceText);
Expand Down
8 changes: 7 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
"declaration": false,
"outDir": "dist",
"removeComments": false,
"strict": true,
"noImplicitReturns": true,
"noImplicitAny": true,
"strictNullChecks": true,
"noUnusedParameters": true,
"noUnusedLocals": true,
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"sourceMap": true,
"lib": [
"esnext"
Expand Down

0 comments on commit e29755c

Please sign in to comment.