fix(compiler): support <ng-container> whatever the namespace

fixes #14257
This commit is contained in:
Victor Berchet
2017-04-13 10:37:45 -07:00
committed by Tobias Bosch
parent 268884296a
commit 5b141fbf27
7 changed files with 60 additions and 28 deletions

View File

@ -11,7 +11,7 @@ import {ParseError, ParseSourceSpan} from '../parse_util';
import * as html from './ast';
import {DEFAULT_INTERPOLATION_CONFIG, InterpolationConfig} from './interpolation_config';
import * as lex from './lexer';
import {TagDefinition, getNsPrefix, mergeNsAndName} from './tags';
import {TagDefinition, getNsPrefix, isNgContainer, mergeNsAndName} from './tags';
export class TreeError extends ParseError {
static create(elementName: string|null, span: ParseSourceSpan, msg: string): TreeError {
@ -352,11 +352,12 @@ class _TreeBuilder {
*
* `<ng-container>` elements are skipped as they are not rendered as DOM element.
*/
private _getParentElementSkippingContainers(): {parent: html.Element, container: html.Element} {
let container: html.Element = null !;
private _getParentElementSkippingContainers():
{parent: html.Element, container: html.Element|null} {
let container: html.Element|null = null;
for (let i = this._elementStack.length - 1; i >= 0; i--) {
if (this._elementStack[i].name !== 'ng-container') {
if (!isNgContainer(this._elementStack[i].name)) {
return {parent: this._elementStack[i], container};
}
container = this._elementStack[i];
@ -382,7 +383,7 @@ class _TreeBuilder {
* @internal
*/
private _insertBeforeContainer(
parent: html.Element, container: html.Element, node: html.Element) {
parent: html.Element, container: html.Element|null, node: html.Element) {
if (!container) {
this._addToParent(node);
this._elementStack.push(node);

View File

@ -12,7 +12,6 @@ export enum TagContentType {
PARSABLE_DATA
}
// TODO(vicb): read-only when TS supports it
export interface TagDefinition {
closedByParent: boolean;
requiredParents: {[key: string]: boolean};
@ -42,6 +41,21 @@ export function splitNsName(elementName: string): [string | null, string] {
return [elementName.slice(1, colonIndex), elementName.slice(colonIndex + 1)];
}
// `<ng-container>` tags work the same regardless the namespace
export function isNgContainer(tagName: string): boolean {
return splitNsName(tagName)[1] === 'ng-container';
}
// `<ng-content>` tags work the same regardless the namespace
export function isNgContent(tagName: string): boolean {
return splitNsName(tagName)[1] === 'ng-content';
}
// `<ng-template>` tags work the same regardless the namespace
export function isNgTemplate(tagName: string): boolean {
return splitNsName(tagName)[1] === 'ng-template';
}
export function getNsPrefix(fullName: string): string
export function getNsPrefix(fullName: null): null;
export function getNsPrefix(fullName: string | null): string |