fix(compiler): treat absolute imports as package imports (#18912)

This is a corner case, and converting them is what
was expected in G3. This also fits the fact that
we already convert package paths into relative paths.


PR Close #18912
This commit is contained in:
Tobias Bosch 2017-08-30 16:08:55 -07:00 committed by Jason Aden
parent 4059a72710
commit fce7ae16f5
2 changed files with 8 additions and 5 deletions

View File

@ -142,7 +142,10 @@ class CompilerHostMixin {
resourceNameToFileName(resourceName: string, containingFile: string): string|null {
// Note: we convert package paths into relative paths to be compatible with the the
// previous implementation of UrlResolver.
if (resourceName && resourceName.charAt(0) !== '.' && !path.isAbsolute(resourceName)) {
const firstChar = resourceName[0];
if (firstChar === '/') {
resourceName = resourceName.slice(1);
} else if (firstChar !== '.') {
resourceName = `./${resourceName}`;
}
const filePathWithNgResource =

View File

@ -117,10 +117,10 @@ describe('NgCompilerHost', () => {
.toBe('/tmp/src/a/child.html');
});
it('should resolve absolute paths', () => {
const ngHost = createHost({files: {'tmp': {'src': {'a': {'child.html': '<div>'}}}}});
expect(ngHost.resourceNameToFileName('/tmp/src/a/child.html', '/tmp/src/index.ts'))
.toBe('/tmp/src/a/child.html');
it('should resolve absolute paths as package paths', () => {
const ngHost = createHost({files: {'tmp': {'node_modules': {'a': {'child.html': '<div>'}}}}});
expect(ngHost.resourceNameToFileName('/a/child.html', ''))
.toBe('/tmp/node_modules/a/child.html');
});
});
});