parent
84f024309a
commit
6ff164be0e
|
@ -124,6 +124,7 @@ export class BindingParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse an inline template binding. ie `<tag *prefixToken="<value>">`
|
||||||
parseInlineTemplateBinding(
|
parseInlineTemplateBinding(
|
||||||
prefixToken: string, value: string, sourceSpan: ParseSourceSpan,
|
prefixToken: string, value: string, sourceSpan: ParseSourceSpan,
|
||||||
targetMatchableAttrs: string[][], targetProps: BoundProperty[], targetVars: VariableAst[]) {
|
targetMatchableAttrs: string[][], targetProps: BoundProperty[], targetVars: VariableAst[]) {
|
||||||
|
@ -387,7 +388,8 @@ export class BindingParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _checkPipes(ast: ASTWithSource, sourceSpan: ParseSourceSpan) {
|
// Make sure all the used pipes are known in `this.pipesByName`
|
||||||
|
private _checkPipes(ast: ASTWithSource, sourceSpan: ParseSourceSpan): void {
|
||||||
if (ast) {
|
if (ast) {
|
||||||
const collector = new PipeCollector();
|
const collector = new PipeCollector();
|
||||||
ast.visit(collector);
|
ast.visit(collector);
|
||||||
|
|
|
@ -254,7 +254,7 @@ class TemplateParseVisitor implements html.Visitor {
|
||||||
|
|
||||||
visitElement(element: html.Element, parent: ElementContext): any {
|
visitElement(element: html.Element, parent: ElementContext): any {
|
||||||
const queryStartIndex = this.contentQueryStartId;
|
const queryStartIndex = this.contentQueryStartId;
|
||||||
const nodeName = element.name;
|
const elName = element.name;
|
||||||
const preparsedElement = preparseElement(element);
|
const preparsedElement = preparseElement(element);
|
||||||
if (preparsedElement.type === PreparsedElementType.SCRIPT ||
|
if (preparsedElement.type === PreparsedElementType.SCRIPT ||
|
||||||
preparsedElement.type === PreparsedElementType.STYLE) {
|
preparsedElement.type === PreparsedElementType.STYLE) {
|
||||||
|
@ -318,7 +318,7 @@ class TemplateParseVisitor implements html.Visitor {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const elementCssSelector = createElementCssSelector(nodeName, matchableAttrs);
|
const elementCssSelector = createElementCssSelector(elName, matchableAttrs);
|
||||||
const {directives: directiveMetas, matchElement} =
|
const {directives: directiveMetas, matchElement} =
|
||||||
this._parseDirectives(this.selectorMatcher, elementCssSelector);
|
this._parseDirectives(this.selectorMatcher, elementCssSelector);
|
||||||
const references: ReferenceAst[] = [];
|
const references: ReferenceAst[] = [];
|
||||||
|
@ -341,13 +341,14 @@ class TemplateParseVisitor implements html.Visitor {
|
||||||
isTemplateElement ? parent.providerContext ! : providerContext));
|
isTemplateElement ? parent.providerContext ! : providerContext));
|
||||||
providerContext.afterElement();
|
providerContext.afterElement();
|
||||||
// Override the actual selector when the `ngProjectAs` attribute is provided
|
// Override the actual selector when the `ngProjectAs` attribute is provided
|
||||||
const projectionSelector = preparsedElement.projectAs != null ?
|
const projectionSelector = preparsedElement.projectAs != '' ?
|
||||||
CssSelector.parse(preparsedElement.projectAs)[0] :
|
CssSelector.parse(preparsedElement.projectAs)[0] :
|
||||||
elementCssSelector;
|
elementCssSelector;
|
||||||
const ngContentIndex = parent.findNgContentIndex(projectionSelector) !;
|
const ngContentIndex = parent.findNgContentIndex(projectionSelector) !;
|
||||||
let parsedElement: TemplateAst;
|
let parsedElement: TemplateAst;
|
||||||
|
|
||||||
if (preparsedElement.type === PreparsedElementType.NG_CONTENT) {
|
if (preparsedElement.type === PreparsedElementType.NG_CONTENT) {
|
||||||
|
// `<ng-content>` element
|
||||||
if (element.children && !element.children.every(_isEmptyTextNode)) {
|
if (element.children && !element.children.every(_isEmptyTextNode)) {
|
||||||
this._reportError(`<ng-content> element cannot have content.`, element.sourceSpan !);
|
this._reportError(`<ng-content> element cannot have content.`, element.sourceSpan !);
|
||||||
}
|
}
|
||||||
|
@ -356,6 +357,7 @@ class TemplateParseVisitor implements html.Visitor {
|
||||||
this.ngContentCount++, hasInlineTemplates ? null ! : ngContentIndex,
|
this.ngContentCount++, hasInlineTemplates ? null ! : ngContentIndex,
|
||||||
element.sourceSpan !);
|
element.sourceSpan !);
|
||||||
} else if (isTemplateElement) {
|
} else if (isTemplateElement) {
|
||||||
|
// `<ng-template>` element
|
||||||
this._assertAllEventsPublishedByDirectives(directiveAsts, events);
|
this._assertAllEventsPublishedByDirectives(directiveAsts, events);
|
||||||
this._assertNoComponentsNorElementBindingsOnTemplate(
|
this._assertNoComponentsNorElementBindingsOnTemplate(
|
||||||
directiveAsts, elementProps, element.sourceSpan !);
|
directiveAsts, elementProps, element.sourceSpan !);
|
||||||
|
@ -366,30 +368,30 @@ class TemplateParseVisitor implements html.Visitor {
|
||||||
providerContext.queryMatches, children, hasInlineTemplates ? null ! : ngContentIndex,
|
providerContext.queryMatches, children, hasInlineTemplates ? null ! : ngContentIndex,
|
||||||
element.sourceSpan !);
|
element.sourceSpan !);
|
||||||
} else {
|
} else {
|
||||||
|
// element other than `<ng-content>` and `<ng-template>`
|
||||||
this._assertElementExists(matchElement, element);
|
this._assertElementExists(matchElement, element);
|
||||||
this._assertOnlyOneComponent(directiveAsts, element.sourceSpan !);
|
this._assertOnlyOneComponent(directiveAsts, element.sourceSpan !);
|
||||||
|
|
||||||
const ngContentIndex =
|
const ngContentIndex =
|
||||||
hasInlineTemplates ? null : parent.findNgContentIndex(projectionSelector);
|
hasInlineTemplates ? null : parent.findNgContentIndex(projectionSelector);
|
||||||
parsedElement = new ElementAst(
|
parsedElement = new ElementAst(
|
||||||
nodeName, attrs, elementProps, events, references,
|
elName, attrs, elementProps, events, references, providerContext.transformedDirectiveAsts,
|
||||||
providerContext.transformedDirectiveAsts, providerContext.transformProviders,
|
providerContext.transformProviders, providerContext.transformedHasViewContainer,
|
||||||
providerContext.transformedHasViewContainer, providerContext.queryMatches, children,
|
providerContext.queryMatches, children, hasInlineTemplates ? null : ngContentIndex,
|
||||||
hasInlineTemplates ? null : ngContentIndex, element.sourceSpan,
|
element.sourceSpan, element.endSourceSpan || null);
|
||||||
element.endSourceSpan || null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasInlineTemplates) {
|
if (hasInlineTemplates) {
|
||||||
|
// The element as a *-attribute
|
||||||
const templateQueryStartIndex = this.contentQueryStartId;
|
const templateQueryStartIndex = this.contentQueryStartId;
|
||||||
const templateSelector = createElementCssSelector('ng-template', templateMatchableAttrs);
|
const templateSelector = createElementCssSelector('ng-template', templateMatchableAttrs);
|
||||||
const {directives: templateDirectiveMetas} =
|
const {directives} = this._parseDirectives(this.selectorMatcher, templateSelector);
|
||||||
this._parseDirectives(this.selectorMatcher, templateSelector);
|
|
||||||
const templateBoundDirectivePropNames = new Set<string>();
|
const templateBoundDirectivePropNames = new Set<string>();
|
||||||
const templateDirectiveAsts = this._createDirectiveAsts(
|
const templateDirectiveAsts = this._createDirectiveAsts(
|
||||||
true, element.name, templateDirectiveMetas, templateElementOrDirectiveProps, [],
|
true, elName, directives, templateElementOrDirectiveProps, [], element.sourceSpan !, [],
|
||||||
element.sourceSpan !, [], templateBoundDirectivePropNames);
|
templateBoundDirectivePropNames);
|
||||||
const templateElementProps: BoundElementPropertyAst[] = this._createElementPropertyAsts(
|
const templateElementProps: BoundElementPropertyAst[] = this._createElementPropertyAsts(
|
||||||
element.name, templateElementOrDirectiveProps, templateBoundDirectivePropNames);
|
elName, templateElementOrDirectiveProps, templateBoundDirectivePropNames);
|
||||||
this._assertNoComponentsNorElementBindingsOnTemplate(
|
this._assertNoComponentsNorElementBindingsOnTemplate(
|
||||||
templateDirectiveAsts, templateElementProps, element.sourceSpan !);
|
templateDirectiveAsts, templateElementProps, element.sourceSpan !);
|
||||||
const templateProviderContext = new ProviderElementContext(
|
const templateProviderContext = new ProviderElementContext(
|
||||||
|
|
|
@ -24,7 +24,7 @@ export function preparseElement(ast: html.Element): PreparsedElement {
|
||||||
let hrefAttr: string = null !;
|
let hrefAttr: string = null !;
|
||||||
let relAttr: string = null !;
|
let relAttr: string = null !;
|
||||||
let nonBindable = false;
|
let nonBindable = false;
|
||||||
let projectAs: string = null !;
|
let projectAs = '';
|
||||||
ast.attrs.forEach(attr => {
|
ast.attrs.forEach(attr => {
|
||||||
const lcAttrName = attr.name.toLowerCase();
|
const lcAttrName = attr.name.toLowerCase();
|
||||||
if (lcAttrName == NG_CONTENT_SELECT_ATTR) {
|
if (lcAttrName == NG_CONTENT_SELECT_ATTR) {
|
||||||
|
|
Loading…
Reference in New Issue