Skip to content

Commit

Permalink
fix(language-service): detect when there isn't a tsconfig.json
Browse files Browse the repository at this point in the history
Fixes #15874
  • Loading branch information
chuckjaz authored and hansl committed Apr 10, 2017
1 parent 09d9f5f commit 258d539
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/language-service/src/typescript_host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,9 @@ function findTsConfig(fileName: string): string {
while (fs.existsSync(dir)) {
const candidate = path.join(dir, 'tsconfig.json');
if (fs.existsSync(candidate)) return candidate;
dir = path.dirname(dir);
const parentDir = path.dirname(dir);
if (parentDir === dir) break;
dir = parentDir;
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/language-service/test/test_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import {MockData} from './test_utils';

export const toh = {
'foo.ts': `export * from './app/app.component.ts';`,
app: {
'app.component.ts': `import { Component } from '@angular/core';
Expand Down
42 changes: 42 additions & 0 deletions packages/language-service/test/typescript_host_spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

import 'reflect-metadata';
import * as ts from 'typescript';

import {TypeScriptServiceHost} from '../src/typescript_host';

import {toh} from './test_data';
import {MockTypescriptHost} from './test_utils';


describe('completions', () => {
let host: ts.LanguageServiceHost;
let service: ts.LanguageService;
let ngHost: TypeScriptServiceHost;

beforeEach(() => {
host = new MockTypescriptHost(['/app/main.ts'], toh);
service = ts.createLanguageService(host);
});

it('should be able to create a typescript host',
() => { expect(() => new TypeScriptServiceHost(host, service)).not.toThrow(); });

beforeEach(() => { ngHost = new TypeScriptServiceHost(host, service); });

it('should be able to analyze modules',
() => { expect(ngHost.getAnalyzedModules()).toBeDefined(); });

it('should be able to analyze modules in without a tsconfig.json file', () => {
host = new MockTypescriptHost(['foo.ts'], toh);
service = ts.createLanguageService(host);
ngHost = new TypeScriptServiceHost(host, service);
expect(ngHost.getAnalyzedModules()).toBeDefined();
});
});

0 comments on commit 258d539

Please sign in to comment.