-
Notifications
You must be signed in to change notification settings - Fork 309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: use angular compiler api to transform codes #562
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
985ddc3
feat(compiler): introduce `NgJestCompiler` for code compilation
ahnpnl 62b2e57
fix: add `@ngtools/webpack` to peerDependencies list
ahnpnl 7dd6450
feat(compiler): provide ngcc-jest-processor util
ahnpnl 3107354
fix(compiler): fallback to ES2015 when no target is defined
ahnpnl e637da1
perf(compiler): only create `NgJestCompiler` instance in `process`
ahnpnl 2063723
test(unit): improve unit tests
ahnpnl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
e2e/test-app-v10/projects/my-lib/src/lib/disableable.directive.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Directive, ElementRef, Input } from '@angular/core'; | ||
|
||
/** | ||
* A base class for components that can be disabled, and that store their disabled | ||
* state in the HTML element. This prevents the HTML element from being focused or clicked, | ||
* and can be used for CSS selectors. | ||
*/ | ||
@Directive() | ||
export abstract class DisableableDirective { | ||
|
||
/** Binds to the HTML disabled property OR disabled attribute, if present. */ | ||
@Input() | ||
public set disabled(v: boolean) { | ||
const elt = this.elementRef.nativeElement; | ||
const disabledProp = (elt as any).disabled; | ||
if (typeof (disabledProp) === 'boolean') { | ||
// Set disabled property | ||
(elt as any).disabled = v; | ||
return; | ||
} | ||
|
||
// Set disabled attribute | ||
elt.setAttribute('disabled', v.toString()); | ||
} | ||
public get disabled(): boolean { | ||
const elt = this.elementRef.nativeElement; | ||
const disabledProp = (elt as any).disabled; | ||
if (typeof (disabledProp) === 'boolean') { | ||
return disabledProp; | ||
} | ||
const disabledAttr = elt.getAttribute('disabled'); | ||
return disabledAttr === 'true'; | ||
} | ||
|
||
constructor(public elementRef: ElementRef<HTMLElement>) { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { forwardRef, Inject, Injector } from '@angular/core'; | ||
|
||
class Door { | ||
lock: Lock; | ||
|
||
// Door attempts to inject Lock, despite it not being defined yet. | ||
// forwardRef makes this possible. | ||
constructor(@Inject(forwardRef(() => Lock)) lock: Lock) { | ||
this.lock = lock; | ||
} | ||
} | ||
|
||
// Only at this point Lock is defined. | ||
class Lock {} | ||
|
||
test('should work', () => { | ||
const injector = Injector.create({providers: [{provide: Lock, deps: []}, {provide: Door, deps: [Lock]}]}); | ||
|
||
expect(injector.get(Door) instanceof Door).toBe(true); | ||
expect(injector.get(Door).lock instanceof Lock).toBe(true); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
e2e/test-app-v9/src/app/ngc-compiled-lib/ngc-compiled-lib.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { Ng2GoogleChartsModule } from 'ng2-google-charts'; | ||
import { GeoChartComponent } from './ngc-compiled-lib.component'; | ||
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; | ||
|
||
describe('GeoChartComponent', () => { | ||
let component: GeoChartComponent; | ||
let fixture: ComponentFixture<GeoChartComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
CommonModule, | ||
Ng2GoogleChartsModule, | ||
], | ||
providers: [], | ||
declarations: [ GeoChartComponent ], | ||
schemas: [ | ||
CUSTOM_ELEMENTS_SCHEMA, | ||
], | ||
}).compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(GeoChartComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
64 changes: 64 additions & 0 deletions
64
e2e/test-app-v9/src/app/ngc-compiled-lib/ngc-compiled-lib.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core'; | ||
import { GoogleChartInterface } from 'ng2-google-charts'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
|
||
@Component({ | ||
// tslint:disable-next-line:component-selector | ||
selector: 'influo-geo-chart', | ||
template: ` | ||
<google-chart | ||
*ngIf="googleChartConfig$ | async as googleChartConfig; else loader" | ||
[data]="googleChartConfig"> | ||
</google-chart> | ||
<ng-template #loader> | ||
<mat-spinner color="accent" diameter="80" strokeWidth="8"></mat-spinner> | ||
</ng-template> | ||
`, | ||
}) | ||
export class GeoChartComponent implements OnInit, OnChanges { | ||
@Input() columns: any; | ||
@Input() config: GoogleChartInterface; | ||
@Input() data: Array<Array<string | number>>; | ||
|
||
private defaultConfig: GoogleChartInterface = { | ||
chartType: 'GeoChart', | ||
dataTable: [], | ||
options: { | ||
legend: false, | ||
region: 155, | ||
enableRegionInteractivity: true, | ||
displayMode: 'region', | ||
colors: [ '#e6e6e6', '#1672AD' ], | ||
datalessRegionColor: '#e6e6e6', | ||
}, | ||
}; | ||
|
||
constructor() { | ||
} | ||
|
||
_googleChartConfig = new BehaviorSubject<GoogleChartInterface | null>(null); | ||
|
||
set googleChartConfig(config: GoogleChartInterface) { | ||
const value = this._googleChartConfig.getValue() || {}; | ||
|
||
this._googleChartConfig.next(Object.assign({}, value, config)); | ||
} | ||
|
||
get googleChartConfig$() { | ||
return this._googleChartConfig.asObservable(); | ||
} | ||
|
||
ngOnInit() { | ||
} | ||
|
||
ngOnChanges(changes: SimpleChanges): void { | ||
if (this.columns && this.data) { | ||
this.googleChartConfig = Object.assign({}, this.defaultConfig, this.config, { | ||
dataTable: [ | ||
this.columns, | ||
...this.data, | ||
], | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow this is it! Haha, will have to get used to it!