forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(upgrade): additional ng2 features for downgraded ng2 components
- Full use of core Angular 2 projection for downgraded Angular 2 components. In particular, this enables multi-slot projection and other features on <ng-content>. - Hierarchical injectors for downgraded Angular 2 components: downgraded components inherit the injector of the first other downgraded Angular 2 component they find up the DOM tree. - declareNg1Module() and initForNg1Tests() methods on the UpgradeAdapter to allow testing hybrid applications through Angular 1 without having to redeclare the adapter module and recompile every downgraded component for every test. Closes angular#6629, angular#7727, angular#8729, angular#5462, angular#9643, angular#9649
- Loading branch information
Showing
13 changed files
with
570 additions
and
157 deletions.
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
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
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,24 @@ | ||
/** | ||
* @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 {CompilerFactory, PlatformRef, Provider, createPlatformFactory} from '@angular/core'; | ||
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; | ||
|
||
import {NG2_COMPILER_SPY} from './constants'; | ||
import {RuntimeCompilerSpy, RuntimeCompilerSpyFactory} from './spies'; | ||
|
||
const INTERNAL_UPGRADE_PLATFORM_PROVIDERS: Provider[] = [ | ||
{provide: NG2_COMPILER_SPY, useClass: RuntimeCompilerSpy}, | ||
{provide: CompilerFactory, useClass: RuntimeCompilerSpyFactory} | ||
]; | ||
|
||
/** | ||
* @experimental | ||
*/ | ||
export const platformUpgrade = | ||
createPlatformFactory(platformBrowserDynamic, 'upgrade', INTERNAL_UPGRADE_PLATFORM_PROVIDERS); |
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 @@ | ||
/** | ||
* @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 {__compiler_private__ as _c} from '@angular/compiler'; | ||
|
||
export type RuntimeCompilerFactory = typeof _c._RuntimeCompilerFactory; | ||
export var RuntimeCompilerFactory: typeof _c.RuntimeCompilerFactory = _c.RuntimeCompilerFactory; | ||
|
||
export type SelectorMatcher = typeof _c.SelectorMatcher; | ||
export var SelectorMatcher: typeof _c.SelectorMatcher = _c.SelectorMatcher; | ||
|
||
export type CssSelector = typeof _c.CssSelector; | ||
export var CssSelector: typeof _c.CssSelector = _c.CssSelector; | ||
|
||
export var createElementCssSelector: typeof _c.createElementCssSelector = | ||
_c.createElementCssSelector; |
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,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 {COMPILER_OPTIONS, Compiler, CompilerOptions, Inject, Injectable} from '@angular/core'; | ||
|
||
import {NG2_COMPILER_SPY} from './constants'; | ||
import {RuntimeCompilerFactory} from './private_import_compiler'; | ||
import {isPresent} from './util'; | ||
|
||
@Injectable() | ||
export class RuntimeCompilerSpyFactory extends RuntimeCompilerFactory { | ||
constructor( | ||
@Inject(COMPILER_OPTIONS) defaultOptions: CompilerOptions[], | ||
@Inject(NG2_COMPILER_SPY) private _spy: RuntimeCompilerSpy) { | ||
super(defaultOptions); | ||
} | ||
createCompiler(options: CompilerOptions[] = []): Compiler { | ||
// Very ugly hack to get access to the compiler's internal objects. | ||
// Better here than in the compiler module itself, though. | ||
let runtimeCompiler: any = <any>super.createCompiler(options); | ||
let spy = this._spy; | ||
let originalCompileTemplate = runtimeCompiler._compileTemplate; | ||
runtimeCompiler._compileTemplate = function(template: any) { | ||
if (!template.isCompiled) { | ||
spy.add(template); | ||
} | ||
return originalCompileTemplate.call(this, template); | ||
}; | ||
return runtimeCompiler; | ||
} | ||
} | ||
|
||
@Injectable() | ||
export class RuntimeCompilerSpy { | ||
ngContentSelectors: {[componentSelector: string]: string[]} = {}; | ||
|
||
add(template: any) { | ||
if (!template.isHost) { | ||
let metadata = template.normalizedCompMeta; | ||
if (isPresent(metadata.template) && isPresent(metadata.template.ngContentSelectors)) { | ||
this.ngContentSelectors[metadata.selector] = metadata.template.ngContentSelectors; | ||
} | ||
} | ||
} | ||
} |
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.