Skip to content
This repository was archived by the owner on Jan 14, 2019. It is now read-only.

Commit 1b5dfb7

Browse files
armano2JamesHenry
authored andcommitted
fix: set parent nodes correctly for virtual files (#78)
1 parent f93a9bb commit 1b5dfb7

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/tsconfig-parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export function createProgram(code: string, filePath: string, extra: Extra) {
213213
return undefined;
214214
}
215215

216-
const compilerHost = ts.createCompilerHost(commandLine.options);
216+
const compilerHost = ts.createCompilerHost(commandLine.options, true);
217217
const oldReadFile = compilerHost.readFile;
218218
compilerHost.readFile = (fileName: string) =>
219219
path.normalize(fileName) === path.normalize(filePath)

tests/lib/semanticInfo.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,23 @@ describe('semanticInfo', () => {
143143
);
144144
});
145145

146+
test('non-existent file should provide parents nodes', () => {
147+
const parseResult = parseCodeAndGenerateServices(
148+
`function M() { return Base }`,
149+
createOptions('<input>')
150+
);
151+
152+
// https://github.com/JamesHenry/typescript-estree/issues/77
153+
expect(parseResult.services.program).toBeDefined();
154+
expect(
155+
parseResult.services.program!.getSourceFile('<input>')
156+
).toBeDefined();
157+
expect(
158+
parseResult.services.program!.getSourceFile('<input>')!.statements[0]
159+
.parent
160+
).toBeDefined();
161+
});
162+
146163
test('non-existent project file', () => {
147164
const fileName = path.resolve(FIXTURES_DIR, 'isolated-file.src.ts');
148165
const badConfig = createOptions(fileName);

0 commit comments

Comments
 (0)