fix(language-service): pass compilerOptions.paths to ReflectorHost (#20222)

This commit fixes the options passed to ReflectorHost to include 'paths'
if it's specified in compiler options, so that dependency modules can
be loaded.

PR Close #20222
This commit is contained in:
Keen Yee Liau 2017-11-06 10:30:29 -08:00 committed by Jason Aden
parent fb4b90a564
commit eb8013e853
2 changed files with 30 additions and 0 deletions

View File

@ -376,6 +376,9 @@ export class TypeScriptServiceHost implements LanguageServiceHost {
if (compilerOptions && compilerOptions.baseUrl) {
options.baseUrl = compilerOptions.baseUrl;
}
if (compilerOptions && compilerOptions.paths) {
options.paths = compilerOptions.paths;
}
result = this._reflectorHost =
new ReflectorHost(() => this.tsService.getProgram(), this.host, options);
}

View File

@ -160,6 +160,33 @@ export class MyComponent {
});
it('should respect paths configuration', () => {
mockHost.overrideOptions(options => {
options.baseUrl = '/app';
options.paths = {'bar/*': ['foo/bar/*']};
return options;
});
mockHost.addScript('/app/foo/bar/shared.ts', `
export interface Node {
children: Node[];
}
`);
mockHost.addScript('/app/my.component.ts', `
import { Component } from '@angular/core';
import { Node } from 'bar/shared';
@Component({
selector: 'my-component',
template: '{{tree.~{tree} }}'
})
export class MyComponent {
tree: Node;
}
`);
ngHost.updateAnalyzedModules();
contains('/app/my.component.ts', 'tree', 'children');
});
function addCode(code: string, cb: (fileName: string, content?: string) => void) {
const fileName = '/app/app.component.ts';
const originalContent = mockHost.getFileContent(fileName);