feat(ivy): produce diagnostics for missing exports, incorrect entrypoint (#27743)

This commit adds tracking of modules, directives, and pipes which are made
visible to consumers through NgModules exported from the package entrypoint.
ngtsc will now produce a diagnostic if such classes are not themselves
exported via the entrypoint (as this is a requirement for downstream
consumers to use them with Ivy).

To accomplish this, a graph of references is created and populated via the
ReferencesRegistry. Symbols exported via the package entrypoint are compared
against the graph to determine if any publicly visible symbols are not
properly exported. Diagnostics are produced for each one which also show the
path by which they become visible.

This commit also introduces a diagnostic (instead of a hard compiler crash)
if an entrypoint file cannot be correctly determined.

PR Close #27743
This commit is contained in:
Alex Rickabaugh
2018-12-13 11:52:20 -08:00
committed by Kara Erickson
parent ac157170c8
commit 0b9094ec63
22 changed files with 597 additions and 66 deletions

View File

@ -0,0 +1,25 @@
package(default_visibility = ["//visibility:public"])
load("//tools:defaults.bzl", "jasmine_node_test", "ts_library")
ts_library(
name = "test_lib",
testonly = True,
srcs = glob([
"**/*.ts",
]),
deps = [
"//packages:types",
"//packages/compiler-cli/src/ngtsc/entry_point",
"@ngdeps//typescript",
],
)
jasmine_node_test(
name = "test",
bootstrap = ["angular/tools/testing/init_node_no_angular_spec.js"],
deps = [
":test_lib",
"//tools/testing:node_no_angular",
],
)

View File

@ -0,0 +1,50 @@
/**
* @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 {ReferenceGraph} from '../src/reference_graph';
describe('entry_point reference graph', () => {
let graph: ReferenceGraph<string>;
const refs =
(target: string) => { return Array.from(graph.transitiveReferencesOf(target)).sort(); };
beforeEach(() => {
graph = new ReferenceGraph();
graph.add('origin', 'alpha');
graph.add('alpha', 'beta');
graph.add('beta', 'gamma');
});
it('should track a simple chain of references', () => {
// origin -> alpha -> beta -> gamma
expect(refs('origin')).toEqual(['alpha', 'beta', 'gamma']);
expect(refs('beta')).toEqual(['gamma']);
});
it('should not crash on a cycle', () => {
// origin -> alpha -> beta -> gamma
// ^---------------/
graph.add('beta', 'origin');
expect(refs('origin')).toEqual(['alpha', 'beta', 'gamma', 'origin']);
});
it('should report a path between two nodes in the graph', () => {
// ,------------------------\
// origin -> alpha -> beta -> gamma -> delta
// \----------------^
graph.add('beta', 'delta');
graph.add('delta', 'alpha');
expect(graph.pathFrom('origin', 'gamma')).toEqual(['origin', 'alpha', 'beta', 'gamma']);
expect(graph.pathFrom('beta', 'alpha')).toEqual(['beta', 'delta', 'alpha']);
});
it('should not report a path that doesn\'t exist',
() => { expect(graph.pathFrom('gamma', 'beta')).toBeNull(); });
});