fix(ngcc): report the correct viaModule when reflecting over commonjs (#33192)

In the ReflectionHost API, a 'viaModule' indicates that a particular value
originated in another absolute module. It should always be 'null' for values
originating in relatively-imported modules.

This commit fixes a bug in the CommonJsReflectionHost where viaModule would
be reported even for relatively-imported values, which causes invalid import
statements to be generated during compilation.

A test is added to verify the correct behavior.

FW-1628 #resolve

PR Close #33192
This commit is contained in:
Alex Rickabaugh
2019-10-02 10:30:53 +03:00
committed by Matias Niemelä
parent 2196114501
commit afcff73be3
2 changed files with 57 additions and 3 deletions

View File

@ -174,7 +174,8 @@ export class CommonJsReflectionHost extends Esm5ReflectionHost {
return null;
}
return {node: importedFile, viaModule: importInfo.from};
const viaModule = !importInfo.from.startsWith('.') ? importInfo.from : null;
return {node: importedFile, viaModule};
}
private resolveModuleName(moduleName: string, containingFile: ts.SourceFile): ts.SourceFile