fix(linker): prevent pollution of empty embeddedView context (#10548)
Fixes #10045
This commit is contained in:
parent
74b57dfa7d
commit
46bbcefb36
@ -15,12 +15,12 @@ import {Parser} from '../expression_parser/parser';
|
|||||||
import {ListWrapper, SetWrapper, StringMapWrapper} from '../facade/collection';
|
import {ListWrapper, SetWrapper, StringMapWrapper} from '../facade/collection';
|
||||||
import {BaseException} from '../facade/exceptions';
|
import {BaseException} from '../facade/exceptions';
|
||||||
import {isBlank, isPresent} from '../facade/lang';
|
import {isBlank, isPresent} from '../facade/lang';
|
||||||
|
import {Identifiers, identifierToken} from '../identifiers';
|
||||||
import * as html from '../ml_parser/ast';
|
import * as html from '../ml_parser/ast';
|
||||||
import {HtmlParser, ParseTreeResult} from '../ml_parser/html_parser';
|
import {HtmlParser, ParseTreeResult} from '../ml_parser/html_parser';
|
||||||
import {expandNodes} from '../ml_parser/icu_ast_expander';
|
import {expandNodes} from '../ml_parser/icu_ast_expander';
|
||||||
import {InterpolationConfig} from '../ml_parser/interpolation_config';
|
import {InterpolationConfig} from '../ml_parser/interpolation_config';
|
||||||
import {mergeNsAndName, splitNsName} from '../ml_parser/tags';
|
import {mergeNsAndName, splitNsName} from '../ml_parser/tags';
|
||||||
import {Identifiers, identifierToken} from '../identifiers';
|
|
||||||
import {ParseError, ParseErrorLevel, ParseSourceSpan} from '../parse_util';
|
import {ParseError, ParseErrorLevel, ParseSourceSpan} from '../parse_util';
|
||||||
import {ProviderElementContext, ProviderViewContext} from '../provider_analyzer';
|
import {ProviderElementContext, ProviderViewContext} from '../provider_analyzer';
|
||||||
import {ElementSchemaRegistry} from '../schema/element_schema_registry';
|
import {ElementSchemaRegistry} from '../schema/element_schema_registry';
|
||||||
@ -32,6 +32,7 @@ import {AttrAst, BoundDirectivePropertyAst, BoundElementPropertyAst, BoundEventA
|
|||||||
import {PreparsedElementType, preparseElement} from './template_preparser';
|
import {PreparsedElementType, preparseElement} from './template_preparser';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Group 1 = "bind-"
|
// Group 1 = "bind-"
|
||||||
// Group 2 = "var-"
|
// Group 2 = "var-"
|
||||||
// Group 3 = "let-"
|
// Group 3 = "let-"
|
||||||
|
@ -6,14 +6,11 @@
|
|||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {isBlank} from '../facade/lang';
|
|
||||||
import {AppElement} from './element';
|
import {AppElement} from './element';
|
||||||
import {ElementRef} from './element_ref';
|
import {ElementRef} from './element_ref';
|
||||||
import {AppView} from './view';
|
import {AppView} from './view';
|
||||||
import {EmbeddedViewRef} from './view_ref';
|
import {EmbeddedViewRef} from './view_ref';
|
||||||
|
|
||||||
const EMPTY_CONTEXT = new Object();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an Embedded Template that can be used to instantiate Embedded Views.
|
* Represents an Embedded Template that can be used to instantiate Embedded Views.
|
||||||
*
|
*
|
||||||
@ -51,10 +48,7 @@ export class TemplateRef_<C> extends TemplateRef<C> {
|
|||||||
createEmbeddedView(context: C): EmbeddedViewRef<C> {
|
createEmbeddedView(context: C): EmbeddedViewRef<C> {
|
||||||
var view: AppView<C> = this._viewFactory(
|
var view: AppView<C> = this._viewFactory(
|
||||||
this._appElement.parentView.viewUtils, this._appElement.parentInjector, this._appElement);
|
this._appElement.parentView.viewUtils, this._appElement.parentInjector, this._appElement);
|
||||||
if (isBlank(context)) {
|
view.create(context || <any>{}, null, null);
|
||||||
context = <any>EMPTY_CONTEXT;
|
|
||||||
}
|
|
||||||
view.create(context, null, null);
|
|
||||||
return view.ref;
|
return view.ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -470,6 +470,27 @@ function declareTests({useJit}: {useJit: boolean}) {
|
|||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
it('should not share empty context for template directives - issue #10045',
|
||||||
|
inject(
|
||||||
|
[TestComponentBuilder, AsyncTestCompleter],
|
||||||
|
(tcb: TestComponentBuilder, async: AsyncTestCompleter) => {
|
||||||
|
tcb.overrideView(
|
||||||
|
MyComp, new ViewMetadata({
|
||||||
|
template:
|
||||||
|
'<template pollutedContext let-foo="bar">{{foo}}</template><template noContext let-foo="bar">{{foo}}</template>',
|
||||||
|
directives: [PollutedContext, NoContext]
|
||||||
|
}))
|
||||||
|
|
||||||
|
.createAsync(MyComp)
|
||||||
|
.then((fixture) => {
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(fixture.debugElement.nativeElement).toHaveText('baz');
|
||||||
|
|
||||||
|
async.done();
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
it('should not detach views in ViewContainers when the parent view is destroyed.',
|
it('should not detach views in ViewContainers when the parent view is destroyed.',
|
||||||
inject(
|
inject(
|
||||||
[TestComponentBuilder, AsyncTestCompleter],
|
[TestComponentBuilder, AsyncTestCompleter],
|
||||||
@ -2303,6 +2324,21 @@ class SomeViewport {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Directive({selector: '[pollutedContext]'})
|
||||||
|
class PollutedContext {
|
||||||
|
constructor(private tplRef: TemplateRef<any>, private vcRef: ViewContainerRef) {
|
||||||
|
const evRef = this.vcRef.createEmbeddedView(this.tplRef);
|
||||||
|
evRef.context.bar = 'baz';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Directive({selector: '[noContext]'})
|
||||||
|
class NoContext {
|
||||||
|
constructor(private tplRef: TemplateRef<any>, private vcRef: ViewContainerRef) {
|
||||||
|
this.vcRef.createEmbeddedView(this.tplRef);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Pipe({name: 'double'})
|
@Pipe({name: 'double'})
|
||||||
class DoublePipe implements PipeTransform, OnDestroy {
|
class DoublePipe implements PipeTransform, OnDestroy {
|
||||||
ngOnDestroy() {}
|
ngOnDestroy() {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user