fix(language-service): detect when there isn't a tsconfig.json
Fixes #15874
This commit is contained in:
parent
09d9f5fe54
commit
258d5392d5
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue