fix(language-service): detect when there isn't a tsconfig.json

Fixes #15874
This commit is contained in:
Chuck Jazdzewski 2017-04-10 11:23:40 -07:00 committed by Hans
parent 09d9f5fe54
commit 258d5392d5
3 changed files with 46 additions and 1 deletions

View File

@ -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;
}
}

View File

@ -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';

View File

@ -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();
});
});