fix(ivy): use ReflectionHost to check exports when writing an import (#33192)

This commit fixes ngtsc's import generator to use the ReflectionHost when
looking through the exports of an ES module to find the export of a
particular declaration that's being imported. This is necessary because
some module formats like CommonJS have unusual export mechanics, and the
normal TypeScript ts.TypeChecker does not understand them.

This fixes an issue with ngcc + CommonJS where exports were not being
enumerated correctly.

FW-1630 #resolve

PR Close #33192
This commit is contained in:
Alex Rickabaugh
2019-10-02 10:54:23 +03:00
committed by Matias Niemelä
parent 50710838bf
commit de445709d4
9 changed files with 95 additions and 23 deletions

View File

@ -460,7 +460,7 @@ export class NgtscProgram implements api.Program {
// Finally, check if the reference is being written into a file within the project's logical
// file system, and use a relative import if so. If this fails, ReferenceEmitter will throw
// an error.
new LogicalProjectStrategy(checker, new LogicalFileSystem(this.rootDirs)),
new LogicalProjectStrategy(this.reflector, new LogicalFileSystem(this.rootDirs)),
]);
} else {
// The CompilerHost supports fileNameToModuleName, so use that to emit imports.
@ -470,7 +470,7 @@ export class NgtscProgram implements api.Program {
// Then use aliased references (this is a workaround to StrictDeps checks).
new AliasStrategy(),
// Then use fileNameToModuleName to emit imports.
new FileToModuleStrategy(checker, this.fileToModuleHost),
new FileToModuleStrategy(this.reflector, this.fileToModuleHost),
]);
aliasGenerator = new AliasGenerator(this.fileToModuleHost);
}