Skip to content
This repository has been archived by the owner on Sep 16, 2022. It is now read-only.

Commit

Permalink
fix(Compiler): Allow mixing of deferred/not-deferred...
Browse files Browse the repository at this point in the history
... components coming from the same library (i.e. import).

Mostly involved simplifying/refactoring the bit of `DartEmitter` that created a mapping of import prefixes to use. The old method tried to use one mapping for both deferred and non-deferred libraries; my new approach uses (the already created) separate mappings.

I put a bit of refactoring in to make the method(s) more understandable in the future, and a simple change to "path_util.dart" to compensate for how deferred modules are stored (importing themselves is possible).

Closes #1558.
Closes #1559.

PiperOrigin-RevId: 208234448
  • Loading branch information
matanlurey committed Aug 10, 2018
1 parent 18f03d3 commit aad9f7c
Show file tree
Hide file tree
Showing 9 changed files with 260 additions and 74 deletions.
2 changes: 2 additions & 0 deletions _goldens/test/_files/deferred/container_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import 'deferred_component.dart';
<deferred-child-with-ng-content @deferred>
Hello World
</deferred-child-with-ng-content>
<not-deferred-child></not-deferred-child>
''',
directives: [
DeferredChild1Component,
Expand All @@ -27,6 +28,7 @@ import 'deferred_component.dart';
DeferredChildComponentWithoutNgContent,
DeferredChildComponentWithNgContent,
NgIf,
NotDeferredChildComponent,
SampleComponent,
],
)
Expand Down
90 changes: 51 additions & 39 deletions _goldens/test/_files/deferred/container_component.template.golden
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ import 'package:angular/src/core/linker/app_view.dart';
import 'container_component.dart' as import1;
import 'package:angular/src/core/linker/view_container.dart';
import 'package:angular/src/common/directives/ng_if.dart';
import 'dart:html' as import4;
import 'deferred_component.template.dart' as import5;
import 'deferred_component.dart' as import6;
import 'package:angular/src/core/render/api.dart';
import 'package:angular/src/core/linker/view_type.dart' as import5;
import 'package:angular/src/core/linker/view_type.dart' as import8;
import 'package:angular/src/core/change_detection/change_detection.dart';
import 'dart:html' as import7;
import 'package:angular/src/core/linker/app_view_utils.dart' as import8;
import 'package:angular/src/runtime.dart' as import9;
import 'package:angular/src/core/linker/app_view_utils.dart' as import10;
import 'package:angular/src/runtime.dart' as import11;
import 'package:angular/angular.dart';
import 'package:angular/src/core/linker/template_ref.dart';
import 'deferred_component.template.dart' deferred as deflib1;
import 'deferred_component.dart' deferred as deflib0;
import 'deferred_component.template.dart' deferred as deflib1;

final List<dynamic> styles$TestContainerComponent = const [];

Expand All @@ -36,16 +38,19 @@ class ViewTestContainerComponent0 extends AppView<import1.TestContainerComponent
NgIf _NgIf_2_9;
ViewContainer _appEl_3;
ViewContainer _appEl_4;
import4.Element _el_5;
import5.ViewNotDeferredChildComponent0 _compView_5;
import6.NotDeferredChildComponent _NotDeferredChildComponent_5_5;
static RenderComponentType _renderType;
ViewTestContainerComponent0(AppView<dynamic> parentView, int parentIndex) : super(import5.ViewType.component, {}, parentView, parentIndex, ChangeDetectionStrategy.CheckAlways) {
rootEl = import7.document.createElement('test-container');
_renderType ??= import8.appViewUtils.createRenderType((import9.isDevMode ? 'asset:_goldens/test/_files/deferred/container_component.dart' : null), ViewEncapsulation.None, styles$TestContainerComponent);
ViewTestContainerComponent0(AppView<dynamic> parentView, int parentIndex) : super(import8.ViewType.component, {}, parentView, parentIndex, ChangeDetectionStrategy.CheckAlways) {
rootEl = import4.document.createElement('test-container');
_renderType ??= import10.appViewUtils.createRenderType((import11.isDevMode ? 'asset:_goldens/test/_files/deferred/container_component.dart' : null), ViewEncapsulation.None, styles$TestContainerComponent);
setupComponentType(_renderType);
}
@override
ComponentRef<import1.TestContainerComponent> build() {
final _rootEl = rootEl;
final import7.HtmlElement parentRenderNode = initViewRoot(_rootEl);
final import4.HtmlElement parentRenderNode = initViewRoot(_rootEl);
final _anchor_0 = createViewContainerAnchor();
parentRenderNode.append(_anchor_0);
_appEl_0 = ViewContainer(0, null, this, _anchor_0);
Expand All @@ -71,6 +76,11 @@ class ViewTestContainerComponent0 extends AppView<import1.TestContainerComponent
_appEl_4 = ViewContainer(4, null, this, _anchor_4);
TemplateRef _TemplateRef_4_7 = TemplateRef(_appEl_4, viewFactory_TestContainerComponent7);
loadDeferred(deflib0.loadLibrary, deflib1.loadLibrary, _appEl_4, _TemplateRef_4_7);
_compView_5 = import5.ViewNotDeferredChildComponent0(this, 5);
_el_5 = _compView_5.rootEl;
parentRenderNode.append(_el_5);
_NotDeferredChildComponent_5_5 = import6.NotDeferredChildComponent();
_compView_5.create(_NotDeferredChildComponent_5_5, []);
init(const [], null);
return null;
}
Expand All @@ -82,9 +92,9 @@ class ViewTestContainerComponent0 extends AppView<import1.TestContainerComponent
_NgIf_2_9.ngIf = _ctx.showDeferredChild;
_appEl_1.detectChangesInNestedViews();
_appEl_2.detectChangesInNestedViews();
if (!import8.AppViewUtils.throwOnChanges) {
if (!import10.AppViewUtils.throwOnChanges) {
if (_query_queryMe_1_0_isDirty) {
ctx.queryDeferredChild = import8.firstOrNull(_appEl_2.mapNestedViews((_ViewTestContainerComponent4 nestedView) {
ctx.queryDeferredChild = import10.firstOrNull(_appEl_2.mapNestedViews((_ViewTestContainerComponent4 nestedView) {
return nestedView._appEl_1.mapNestedViews((_ViewTestContainerComponent5 nestedView) {
return [nestedView._DeferredChild3Component_0_5];
});
Expand All @@ -95,12 +105,14 @@ class ViewTestContainerComponent0 extends AppView<import1.TestContainerComponent
_appEl_0.detectChangesInNestedViews();
_appEl_3.detectChangesInNestedViews();
_appEl_4.detectChangesInNestedViews();
_compView_5.detectChanges();
}

@override
void destroyInternal() {
_appEl_1?.destroyNestedViews();
_appEl_2?.destroyNestedViews();
_compView_5?.destroy();
}
}

Expand All @@ -109,17 +121,17 @@ AppView<import1.TestContainerComponent> viewFactory_TestContainerComponent0(AppV
}

class _ViewTestContainerComponent1 extends AppView<import1.TestContainerComponent> {
import7.Element _el_0;
import4.Element _el_0;
AppView _compView_0;
dynamic _DeferredChild1Component_0_5;
_ViewTestContainerComponent1(AppView<dynamic> parentView, int parentIndex) : super(import5.ViewType.embedded, {}, parentView, parentIndex, ChangeDetectionStrategy.CheckAlways) {
_ViewTestContainerComponent1(AppView<dynamic> parentView, int parentIndex) : super(import8.ViewType.embedded, {}, parentView, parentIndex, ChangeDetectionStrategy.CheckAlways) {
componentType = ViewTestContainerComponent0._renderType;
}
@override
ComponentRef<import1.TestContainerComponent> build() {
_compView_0 = deflib1.viewFactory_DeferredChild1Component0(this, 0);
_compView_0 = import5.viewFactory_DeferredChild1Component0(this, 0);
_el_0 = _compView_0.rootEl;
_DeferredChild1Component_0_5 = deflib0.DeferredChild1Component();
_DeferredChild1Component_0_5 = import6.DeferredChild1Component();
_compView_0.create(_DeferredChild1Component_0_5, []);
init0(_el_0);
return null;
Expand All @@ -142,7 +154,7 @@ AppView<import1.TestContainerComponent> viewFactory_TestContainerComponent1(AppV

class _ViewTestContainerComponent2 extends AppView<import1.TestContainerComponent> {
ViewContainer _appEl_0;
_ViewTestContainerComponent2(AppView<dynamic> parentView, int parentIndex) : super(import5.ViewType.embedded, {}, parentView, parentIndex, ChangeDetectionStrategy.CheckAlways) {
_ViewTestContainerComponent2(AppView<dynamic> parentView, int parentIndex) : super(import8.ViewType.embedded, {}, parentView, parentIndex, ChangeDetectionStrategy.CheckAlways) {
componentType = ViewTestContainerComponent0._renderType;
}
@override
Expand All @@ -166,17 +178,17 @@ AppView<import1.TestContainerComponent> viewFactory_TestContainerComponent2(AppV
}

class _ViewTestContainerComponent3 extends AppView<import1.TestContainerComponent> {
import7.Element _el_0;
import4.Element _el_0;
AppView _compView_0;
dynamic _DeferredChild2Component_0_5;
_ViewTestContainerComponent3(AppView<dynamic> parentView, int parentIndex) : super(import5.ViewType.embedded, {}, parentView, parentIndex, ChangeDetectionStrategy.CheckAlways) {
_ViewTestContainerComponent3(AppView<dynamic> parentView, int parentIndex) : super(import8.ViewType.embedded, {}, parentView, parentIndex, ChangeDetectionStrategy.CheckAlways) {
componentType = ViewTestContainerComponent0._renderType;
}
@override
ComponentRef<import1.TestContainerComponent> build() {
_compView_0 = deflib1.viewFactory_DeferredChild2Component0(this, 0);
_compView_0 = import5.viewFactory_DeferredChild2Component0(this, 0);
_el_0 = _compView_0.rootEl;
_DeferredChild2Component_0_5 = deflib0.DeferredChild2Component();
_DeferredChild2Component_0_5 = import6.DeferredChild2Component();
_compView_0.create(_DeferredChild2Component_0_5, []);
init0(_el_0);
return null;
Expand All @@ -198,14 +210,14 @@ AppView<import1.TestContainerComponent> viewFactory_TestContainerComponent3(AppV
}

class _ViewTestContainerComponent4 extends AppView<import1.TestContainerComponent> {
import7.DivElement _el_0;
import4.DivElement _el_0;
ViewContainer _appEl_1;
_ViewTestContainerComponent4(AppView<dynamic> parentView, int parentIndex) : super(import5.ViewType.embedded, {}, parentView, parentIndex, ChangeDetectionStrategy.CheckAlways) {
_ViewTestContainerComponent4(AppView<dynamic> parentView, int parentIndex) : super(import8.ViewType.embedded, {}, parentView, parentIndex, ChangeDetectionStrategy.CheckAlways) {
componentType = ViewTestContainerComponent0._renderType;
}
@override
ComponentRef<import1.TestContainerComponent> build() {
var doc = import7.document;
var doc = import4.document;
_el_0 = doc.createElement('div');
final _anchor_1 = createViewContainerAnchor();
_el_0.append(_anchor_1);
Expand All @@ -227,17 +239,17 @@ AppView<import1.TestContainerComponent> viewFactory_TestContainerComponent4(AppV
}

class _ViewTestContainerComponent5 extends AppView<import1.TestContainerComponent> {
import7.Element _el_0;
import4.Element _el_0;
AppView _compView_0;
dynamic _DeferredChild3Component_0_5;
_ViewTestContainerComponent5(AppView<dynamic> parentView, int parentIndex) : super(import5.ViewType.embedded, {}, parentView, parentIndex, ChangeDetectionStrategy.CheckAlways) {
_ViewTestContainerComponent5(AppView<dynamic> parentView, int parentIndex) : super(import8.ViewType.embedded, {}, parentView, parentIndex, ChangeDetectionStrategy.CheckAlways) {
componentType = ViewTestContainerComponent0._renderType;
}
@override
ComponentRef<import1.TestContainerComponent> build() {
_compView_0 = deflib1.viewFactory_DeferredChild3Component0(this, 0);
_compView_0 = import5.viewFactory_DeferredChild3Component0(this, 0);
_el_0 = _compView_0.rootEl;
_DeferredChild3Component_0_5 = deflib0.DeferredChild3Component();
_DeferredChild3Component_0_5 = import6.DeferredChild3Component();
_compView_0.create(_DeferredChild3Component_0_5, []);
init0(_el_0);
return null;
Expand All @@ -250,7 +262,7 @@ class _ViewTestContainerComponent5 extends AppView<import1.TestContainerComponen

@override
void dirtyParentQueriesInternal() {
import9.unsafeCast<ViewTestContainerComponent0>(parentView.parentView)._query_queryMe_1_0_isDirty = true;
import11.unsafeCast<ViewTestContainerComponent0>(parentView.parentView)._query_queryMe_1_0_isDirty = true;
}

@override
Expand All @@ -264,18 +276,18 @@ AppView<import1.TestContainerComponent> viewFactory_TestContainerComponent5(AppV
}

class _ViewTestContainerComponent6 extends AppView<import1.TestContainerComponent> {
import7.Element _el_0;
import4.Element _el_0;
AppView _compView_0;
dynamic _DeferredChildComponentWithoutNgContent_0_5;
_ViewTestContainerComponent6(AppView<dynamic> parentView, int parentIndex) : super(import5.ViewType.embedded, {}, parentView, parentIndex, ChangeDetectionStrategy.CheckAlways) {
_ViewTestContainerComponent6(AppView<dynamic> parentView, int parentIndex) : super(import8.ViewType.embedded, {}, parentView, parentIndex, ChangeDetectionStrategy.CheckAlways) {
componentType = ViewTestContainerComponent0._renderType;
}
@override
ComponentRef<import1.TestContainerComponent> build() {
_compView_0 = deflib1.viewFactory_DeferredChildComponentWithoutNgContent0(this, 0);
_compView_0 = import5.viewFactory_DeferredChildComponentWithoutNgContent0(this, 0);
_el_0 = _compView_0.rootEl;
_DeferredChildComponentWithoutNgContent_0_5 = deflib0.DeferredChildComponentWithoutNgContent();
import7.Text _text_1 = import7.Text('Hello World');
_DeferredChildComponentWithoutNgContent_0_5 = import6.DeferredChildComponentWithoutNgContent();
import4.Text _text_1 = import4.Text('Hello World');
_compView_0.create(_DeferredChildComponentWithoutNgContent_0_5, []);
init0(_el_0);
return null;
Expand All @@ -297,18 +309,18 @@ AppView<import1.TestContainerComponent> viewFactory_TestContainerComponent6(AppV
}

class _ViewTestContainerComponent7 extends AppView<import1.TestContainerComponent> {
import7.Element _el_0;
import4.Element _el_0;
AppView _compView_0;
dynamic _DeferredChildComponentWithNgContent_0_5;
_ViewTestContainerComponent7(AppView<dynamic> parentView, int parentIndex) : super(import5.ViewType.embedded, {}, parentView, parentIndex, ChangeDetectionStrategy.CheckAlways) {
_ViewTestContainerComponent7(AppView<dynamic> parentView, int parentIndex) : super(import8.ViewType.embedded, {}, parentView, parentIndex, ChangeDetectionStrategy.CheckAlways) {
componentType = ViewTestContainerComponent0._renderType;
}
@override
ComponentRef<import1.TestContainerComponent> build() {
_compView_0 = deflib1.viewFactory_DeferredChildComponentWithNgContent0(this, 0);
_compView_0 = import5.viewFactory_DeferredChildComponentWithNgContent0(this, 0);
_el_0 = _compView_0.rootEl;
_DeferredChildComponentWithNgContent_0_5 = deflib0.DeferredChildComponentWithNgContent();
import7.Text _text_1 = import7.Text('Hello World');
_DeferredChildComponentWithNgContent_0_5 = import6.DeferredChildComponentWithNgContent();
import4.Text _text_1 = import4.Text('Hello World');
_compView_0.create(_DeferredChildComponentWithNgContent_0_5, [
[_text_1]
]);
Expand Down Expand Up @@ -336,7 +348,7 @@ final List<dynamic> styles$TestContainerComponentHost = const [];
class _ViewTestContainerComponentHost0 extends AppView<import1.TestContainerComponent> {
ViewTestContainerComponent0 _compView_0;
import1.TestContainerComponent _TestContainerComponent_0_5;
_ViewTestContainerComponentHost0(AppView<dynamic> parentView, int parentIndex) : super(import5.ViewType.host, {}, parentView, parentIndex, ChangeDetectionStrategy.CheckAlways);
_ViewTestContainerComponentHost0(AppView<dynamic> parentView, int parentIndex) : super(import8.ViewType.host, {}, parentView, parentIndex, ChangeDetectionStrategy.CheckAlways);
@override
ComponentRef<import1.TestContainerComponent> build() {
_compView_0 = ViewTestContainerComponent0(this, 0);
Expand Down
6 changes: 6 additions & 0 deletions _goldens/test/_files/deferred/deferred_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ class DeferredChild2Component {}
)
class DeferredChild3Component {}

@Component(
selector: 'not-deferred-child',
template: '',
)
class NotDeferredChildComponent {}

@Component(
selector: 'deferred-child-without-ng-content',
template: '<div>Child</div>',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ external AppView<_user.DeferredChild3Component> viewFactory_DeferredChild3Compon
class ViewDeferredChild3Component0 extends AppView<_user.DeferredChild3Component> {
external ViewDeferredChild3Component0(AppView<dynamic> parentView, int parentIndex);
}
// For @Component class NotDeferredChildComponent.
external List<dynamic> get styles$NotDeferredChildComponent;
external ComponentFactory<_user.NotDeferredChildComponent> get NotDeferredChildComponentNgFactory;
external AppView<_user.NotDeferredChildComponent> viewFactory_NotDeferredChildComponent0(AppView<dynamic> parentView, int parentIndex);
class ViewNotDeferredChildComponent0 extends AppView<_user.NotDeferredChildComponent> {
external ViewNotDeferredChildComponent0(AppView<dynamic> parentView, int parentIndex);
}
// For @Component class DeferredChildComponentWithoutNgContent.
external List<dynamic> get styles$DeferredChildComponentWithoutNgContent;
external ComponentFactory<_user.DeferredChildComponentWithoutNgContent> get DeferredChildComponentWithoutNgContentNgFactory;
Expand Down
59 changes: 59 additions & 0 deletions _goldens/test/_files/deferred/deferred_component.template.golden
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,64 @@ ComponentFactory<import1.DeferredChild3Component> get DeferredChild3ComponentNgF
return _DeferredChild3ComponentNgFactory;
}

final List<dynamic> styles$NotDeferredChildComponent = const [];

class ViewNotDeferredChildComponent0 extends AppView<import1.NotDeferredChildComponent> {
static RenderComponentType _renderType;
ViewNotDeferredChildComponent0(AppView<dynamic> parentView, int parentIndex) : super(import3.ViewType.component, {}, parentView, parentIndex, ChangeDetectionStrategy.CheckAlways) {
rootEl = import5.document.createElement('not-deferred-child');
_renderType ??= import6.appViewUtils.createRenderType((import7.isDevMode ? 'asset:_goldens/test/_files/deferred/deferred_component.dart' : null), ViewEncapsulation.None, styles$NotDeferredChildComponent);
setupComponentType(_renderType);
}
@override
ComponentRef<import1.NotDeferredChildComponent> build() {
final _rootEl = rootEl;
final import5.HtmlElement parentRenderNode = initViewRoot(_rootEl);
init(const [], null);
return null;
}
}

AppView<import1.NotDeferredChildComponent> viewFactory_NotDeferredChildComponent0(AppView<dynamic> parentView, int parentIndex) {
return ViewNotDeferredChildComponent0(parentView, parentIndex);
}

final List<dynamic> styles$NotDeferredChildComponentHost = const [];

class _ViewNotDeferredChildComponentHost0 extends AppView<import1.NotDeferredChildComponent> {
ViewNotDeferredChildComponent0 _compView_0;
import1.NotDeferredChildComponent _NotDeferredChildComponent_0_5;
_ViewNotDeferredChildComponentHost0(AppView<dynamic> parentView, int parentIndex) : super(import3.ViewType.host, {}, parentView, parentIndex, ChangeDetectionStrategy.CheckAlways);
@override
ComponentRef<import1.NotDeferredChildComponent> build() {
_compView_0 = ViewNotDeferredChildComponent0(this, 0);
rootEl = _compView_0.rootEl;
_NotDeferredChildComponent_0_5 = import1.NotDeferredChildComponent();
_compView_0.create(_NotDeferredChildComponent_0_5, projectableNodes);
init0(rootEl);
return ComponentRef(0, this, rootEl, _NotDeferredChildComponent_0_5);
}

@override
void detectChangesInternal() {
_compView_0.detectChanges();
}

@override
void destroyInternal() {
_compView_0?.destroy();
}
}

AppView<import1.NotDeferredChildComponent> viewFactory_NotDeferredChildComponentHost0(AppView<dynamic> parentView, int parentIndex) {
return _ViewNotDeferredChildComponentHost0(parentView, parentIndex);
}

const ComponentFactory<import1.NotDeferredChildComponent> _NotDeferredChildComponentNgFactory = const ComponentFactory('not-deferred-child', viewFactory_NotDeferredChildComponentHost0);
ComponentFactory<import1.NotDeferredChildComponent> get NotDeferredChildComponentNgFactory {
return _NotDeferredChildComponentNgFactory;
}

final List<dynamic> styles$DeferredChildComponentWithoutNgContent = const [];

class ViewDeferredChildComponentWithoutNgContent0 extends AppView<import1.DeferredChildComponentWithoutNgContent> {
Expand Down Expand Up @@ -333,6 +391,7 @@ void initReflector() {
_ngRef.registerComponent(DeferredChild1Component, DeferredChild1ComponentNgFactory);
_ngRef.registerComponent(DeferredChild2Component, DeferredChild2ComponentNgFactory);
_ngRef.registerComponent(DeferredChild3Component, DeferredChild3ComponentNgFactory);
_ngRef.registerComponent(NotDeferredChildComponent, NotDeferredChildComponentNgFactory);
_ngRef.registerComponent(DeferredChildComponentWithoutNgContent, DeferredChildComponentWithoutNgContentNgFactory);
_ngRef.registerComponent(DeferredChildComponentWithNgContent, DeferredChildComponentWithNgContentNgFactory);
_ref0.initReflector();
Expand Down
Loading

0 comments on commit aad9f7c

Please sign in to comment.