Skip to content

Commit a838aba

Browse files
vicbIgorMinar
authored andcommitted
fix(compiler): walk third party modules (angular#12453)
fixes angular#11889 fixes angular#12428
1 parent bfc97ff commit a838aba

24 files changed

+463
-239
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {Component} from '@angular/core';
10+
11+
@Component({
12+
selector: 'use-third-party',
13+
template: '<third-party-comp [thirdParty]="title"></third-party-comp>' +
14+
'<another-third-party-comp></another-third-party-comp>',
15+
})
16+
export class ComponentUsingThirdParty {
17+
title: string = 'from 3rd party';
18+
}

modules/@angular/compiler-cli/integrationtest/src/messages.fi.xlf

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
<source>Welcome</source>
1313
<target>tervetuloa</target>
1414
</trans-unit>
15+
<trans-unit id="63a85808f03b8181e36a952e0fa38202c2304862" datatype="html">
16+
<source>other-3rdP-component</source>
17+
<target>other-3rdP-component</target>
18+
</trans-unit>
1519
</body>
1620
</file>
1721
</xliff>

modules/@angular/compiler-cli/integrationtest/src/messages.fi.xtb

+1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
<translationbundle>
1010
<translation id="76e1eccb1b772fa9f294ef9c146ea6d0efa8a2d4">käännä teksti</translation>
1111
<translation id="65cc4ab3b4c438e07c89be2b677d08369fb62da2">tervetuloa</translation>
12+
<translation id="63a85808f03b8181e36a952e0fa38202c2304862">other-3rdP-component</translation>
1213
</translationbundle>

modules/@angular/compiler-cli/integrationtest/src/module.ts

+27-12
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ import {FormsModule} from '@angular/forms';
1111
import {BrowserModule} from '@angular/platform-browser';
1212
import {MdButtonModule} from '@angular2-material/button';
1313

14+
import {ThirdpartyModule} from '../third_party_src/module';
15+
1416
import {MultipleComponentsMyComp, NextComp} from './a/multiple_components';
1517
import {AnimateCmp} from './animate';
1618
import {BasicComp} from './basic';
19+
import {ComponentUsingThirdParty} from './comp_using_3rdp';
1720
import {CompWithAnalyzeEntryComponentsProvider, CompWithEntryComponents} from './entry_components';
1821
import {CompConsumingEvents, CompUsingPipes, CompWithProviders, CompWithReferences, DirPublishingEvents, ModuleUsingCustomElements} from './features';
1922
import {CompUsingRootModuleDirectiveAndPipe, SomeDirectiveInRootModule, SomePipeInRootModule, SomeService, someLibModuleWithProviders} from './module_fixtures';
@@ -22,35 +25,47 @@ import {CompForChildQuery, CompWithChildQuery, CompWithDirectiveChild, Directive
2225

2326
@NgModule({
2427
declarations: [
25-
SomeDirectiveInRootModule,
26-
SomePipeInRootModule,
2728
AnimateCmp,
2829
BasicComp,
30+
CompConsumingEvents,
2931
CompForChildQuery,
30-
CompWithEntryComponents,
32+
CompUsingPipes,
33+
CompUsingRootModuleDirectiveAndPipe,
3134
CompWithAnalyzeEntryComponentsProvider,
32-
ProjectingComp,
3335
CompWithChildQuery,
3436
CompWithDirectiveChild,
37+
CompWithEntryComponents,
3538
CompWithNgContent,
36-
CompUsingRootModuleDirectiveAndPipe,
3739
CompWithProviders,
3840
CompWithReferences,
39-
CompUsingPipes,
40-
CompConsumingEvents,
41+
DirectiveForQuery,
4142
DirPublishingEvents,
4243
MultipleComponentsMyComp,
43-
DirectiveForQuery,
4444
NextComp,
45+
ProjectingComp,
46+
SomeDirectiveInRootModule,
47+
SomePipeInRootModule,
48+
ComponentUsingThirdParty,
4549
],
4650
imports: [
47-
BrowserModule, FormsModule, someLibModuleWithProviders(), ModuleUsingCustomElements,
48-
MdButtonModule
51+
BrowserModule,
52+
FormsModule,
53+
MdButtonModule,
54+
ModuleUsingCustomElements,
55+
someLibModuleWithProviders(),
56+
ThirdpartyModule,
4957
],
5058
providers: [SomeService],
5159
entryComponents: [
52-
AnimateCmp, BasicComp, CompWithEntryComponents, CompWithAnalyzeEntryComponentsProvider,
53-
ProjectingComp, CompWithChildQuery, CompUsingRootModuleDirectiveAndPipe, CompWithReferences
60+
AnimateCmp,
61+
BasicComp,
62+
CompUsingRootModuleDirectiveAndPipe,
63+
CompWithAnalyzeEntryComponentsProvider,
64+
CompWithChildQuery,
65+
CompWithEntryComponents,
66+
CompWithReferences,
67+
ProjectingComp,
68+
ComponentUsingThirdParty,
5469
]
5570
})
5671
export class MainModule {

modules/@angular/compiler-cli/integrationtest/test/basic_spec.ts

+8-10
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ describe('template codegen output', () => {
4343
});
4444

4545
it('should be able to create the basic component', () => {
46-
var compFixture = createComponent(BasicComp);
46+
const compFixture = createComponent(BasicComp);
4747
expect(compFixture.componentInstance).toBeTruthy();
4848
});
4949

5050
it('should support ngIf', () => {
51-
var compFixture = createComponent(BasicComp);
52-
var debugElement = compFixture.debugElement;
51+
const compFixture = createComponent(BasicComp);
52+
const debugElement = compFixture.debugElement;
5353
expect(debugElement.children.length).toBe(3);
5454

5555
compFixture.componentInstance.ctxBool = true;
@@ -59,8 +59,8 @@ describe('template codegen output', () => {
5959
});
6060

6161
it('should support ngFor', () => {
62-
var compFixture = createComponent(BasicComp);
63-
var debugElement = compFixture.debugElement;
62+
const compFixture = createComponent(BasicComp);
63+
const debugElement = compFixture.debugElement;
6464
expect(debugElement.children.length).toBe(3);
6565

6666
// test NgFor
@@ -83,11 +83,9 @@ describe('template codegen output', () => {
8383
});
8484

8585
it('should support i18n for content tags', () => {
86-
const compFixture = createComponent(BasicComp);
87-
const debugElement = compFixture.debugElement;
88-
const containerElement = <any>debugElement.nativeElement;
89-
const pElement = <any>containerElement.children.find((c: any) => c.name == 'p');
90-
const pText = <string>pElement.children.map((c: any) => c.data).join('').trim();
86+
const containerElement = createComponent(BasicComp).nativeElement;
87+
const pElement = containerElement.children.find((c: any) => c.name == 'p');
88+
const pText = pElement.children.map((c: any) => c.data).join('').trim();
9189
expect(pText).toBe('tervetuloa');
9290
});
9391
});

modules/@angular/compiler-cli/integrationtest/test/i18n_spec.ts

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const EXPECTED_XMB = `<?xml version="1.0" encoding="UTF-8" ?>
3434
<!ELEMENT ex (#PCDATA)>
3535
]>
3636
<messagebundle>
37+
<msg id="63a85808f03b8181e36a952e0fa38202c2304862">other-3rdP-component</msg>
3738
<msg id="76e1eccb1b772fa9f294ef9c146ea6d0efa8a2d4" desc="desc" meaning="meaning">translate me</msg>
3839
<msg id="65cc4ab3b4c438e07c89be2b677d08369fb62da2">Welcome</msg>
3940
</messagebundle>
@@ -43,6 +44,10 @@ const EXPECTED_XLIFF = `<?xml version="1.0" encoding="UTF-8" ?>
4344
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
4445
<file source-language="en" datatype="plaintext" original="ng2.template">
4546
<body>
47+
<trans-unit id="63a85808f03b8181e36a952e0fa38202c2304862" datatype="html">
48+
<source>other-3rdP-component</source>
49+
<target/>
50+
</trans-unit>
4651
<trans-unit id="76e1eccb1b772fa9f294ef9c146ea6d0efa8a2d4" datatype="html">
4752
<source>translate me</source>
4853
<target/>

modules/@angular/compiler-cli/integrationtest/test/ng_module_spec.ts

+27-8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
import './init';
99

10+
import {ComponentUsingThirdParty} from '../src/comp_using_3rdp';
1011
import {MainModule} from '../src/module';
1112
import {CompUsingLibModuleDirectiveAndPipe, CompUsingRootModuleDirectiveAndPipe, SOME_TOKEN, ServiceUsingLibModule, SomeLibModule, SomeService} from '../src/module_fixtures';
1213

@@ -15,9 +16,9 @@ import {createComponent, createModule} from './util';
1516
describe('NgModule', () => {
1617
it('should support providers', () => {
1718
const moduleRef = createModule();
18-
expect(moduleRef.instance instanceof MainModule).toBe(true);
19-
expect(moduleRef.injector.get(MainModule) instanceof MainModule).toBe(true);
20-
expect(moduleRef.injector.get(SomeService) instanceof SomeService).toBe(true);
19+
expect(moduleRef.instance instanceof MainModule).toEqual(true);
20+
expect(moduleRef.injector.get(MainModule) instanceof MainModule).toEqual(true);
21+
expect(moduleRef.injector.get(SomeService) instanceof SomeService).toEqual(true);
2122
});
2223

2324
it('should support entryComponents components', () => {
@@ -26,7 +27,7 @@ describe('NgModule', () => {
2627
CompUsingRootModuleDirectiveAndPipe);
2728
expect(cf.componentType).toBe(CompUsingRootModuleDirectiveAndPipe);
2829
const compRef = cf.create(moduleRef.injector);
29-
expect(compRef.instance instanceof CompUsingRootModuleDirectiveAndPipe).toBe(true);
30+
expect(compRef.instance instanceof CompUsingRootModuleDirectiveAndPipe).toEqual(true);
3031
});
3132

3233
it('should support entryComponents via the ANALYZE_FOR_ENTRY_COMPONENTS provider and function providers in components',
@@ -42,23 +43,41 @@ describe('NgModule', () => {
4243
]);
4344
});
4445

46+
describe('third-party modules', () => {
47+
// https://github.com/angular/angular/issues/11889
48+
it('should support third party entryComponents components', () => {
49+
const fixture = createComponent(ComponentUsingThirdParty);
50+
const thirdPComps = fixture.nativeElement.children;
51+
expect(thirdPComps[0].children[0].children[0].data).toEqual('3rdP-component');
52+
expect(thirdPComps[1].children[0].children[0].data).toEqual('other-3rdP-component');
53+
});
54+
55+
// https://github.com/angular/angular/issues/12428
56+
it('should support third party directives', () => {
57+
const fixture = createComponent(ComponentUsingThirdParty);
58+
const debugElement = fixture.debugElement;
59+
fixture.detectChanges();
60+
expect(debugElement.children[0].properties['title']).toEqual('from 3rd party');
61+
});
62+
});
63+
4564
it('should support module directives and pipes', () => {
4665
const compFixture = createComponent(CompUsingRootModuleDirectiveAndPipe);
4766
compFixture.detectChanges();
4867

4968
const debugElement = compFixture.debugElement;
50-
expect(debugElement.children[0].properties['title']).toBe('transformed someValue');
69+
expect(debugElement.children[0].properties['title']).toEqual('transformed someValue');
5170
});
5271

5372
it('should support module directives and pipes on lib modules', () => {
5473
const compFixture = createComponent(CompUsingLibModuleDirectiveAndPipe);
5574
compFixture.detectChanges();
5675

5776
const debugElement = compFixture.debugElement;
58-
expect(debugElement.children[0].properties['title']).toBe('transformed someValue');
77+
expect(debugElement.children[0].properties['title']).toEqual('transformed someValue');
5978

60-
expect(debugElement.injector.get(SomeLibModule) instanceof SomeLibModule).toBe(true);
79+
expect(debugElement.injector.get(SomeLibModule) instanceof SomeLibModule).toEqual(true);
6180
expect(debugElement.injector.get(ServiceUsingLibModule) instanceof ServiceUsingLibModule)
62-
.toBe(true);
81+
.toEqual(true);
6382
});
6483
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
This folder emulates consuming precompiled modules and components.
2+
It is compiled separately from the other sources under `src`
3+
to only generate `*.js` / `*.d.ts` / `*.metadata.json` files,
4+
but no `*.ngfactory.ts` files.
5+
6+
** WARNING **
7+
Do not import components/directives from here directly as we want to test that ngc still compiles
8+
them when they are not imported.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {Component} from '@angular/core';
10+
11+
@Component({
12+
selector: 'third-party-comp',
13+
template: '<div>3rdP-component</div>',
14+
})
15+
export class ThirdPartyComponent {
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {Directive, Input} from '@angular/core';
10+
11+
@Directive({
12+
selector: '[thirdParty]',
13+
host: {'[title]': 'thirdParty'},
14+
})
15+
export class ThirdPartyDirective {
16+
@Input() thirdParty: string;
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {NgModule} from '@angular/core';
10+
11+
import {ThirdPartyComponent} from './comp';
12+
import {ThirdPartyDirective} from './directive';
13+
import {AnotherThirdPartyModule} from './other_module';
14+
15+
@NgModule({
16+
declarations: [
17+
ThirdPartyComponent,
18+
ThirdPartyDirective,
19+
],
20+
exports: [
21+
AnotherThirdPartyModule,
22+
ThirdPartyComponent,
23+
ThirdPartyDirective,
24+
],
25+
imports: [AnotherThirdPartyModule]
26+
})
27+
export class ThirdpartyModule {
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {Component} from '@angular/core';
10+
11+
@Component({
12+
selector: 'another-third-party-comp',
13+
template: '<div i18n>other-3rdP-component</div>',
14+
})
15+
export class AnotherThirdpartyComponent {
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {NgModule} from '@angular/core';
10+
import {AnotherThirdpartyComponent} from './other_comp';
11+
12+
@NgModule({
13+
declarations: [AnotherThirdpartyComponent],
14+
exports: [AnotherThirdpartyComponent],
15+
})
16+
export class AnotherThirdPartyModule {
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"angularCompilerOptions": {
3+
// For TypeScript 1.8, we have to lay out generated files
4+
// in the same source directory with your code.
5+
"genDir": ".",
6+
"debug": true
7+
},
8+
9+
"compilerOptions": {
10+
"target": "es5",
11+
"experimentalDecorators": true,
12+
"noImplicitAny": true,
13+
"moduleResolution": "node",
14+
"rootDir": "",
15+
"declaration": true,
16+
"lib": ["es6", "dom"],
17+
"baseUrl": ".",
18+
"outDir": "../node_modules/third_party"
19+
}
20+
}

0 commit comments

Comments
 (0)