Skip to content
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

export htmlAstToRender3Ast #37

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/angular-html-parser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,5 @@ export {
ParseSourceFile,
} from "../../compiler/src/parse_util.js";
export { getHtmlTagDefinition } from "../../compiler/src/ml_parser/html_tags.js";
export { htmlAstToRender3Ast } from '../../compiler/src/render3/r3_template_transform.js';
export { makeBindingParser } from '../../compiler/src/render3/view/template';
5 changes: 5 additions & 0 deletions packages/compiler/src/i18n/i18n_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ class _I18nVisitor implements html.Visitor {
private _expressionParser: ExpressionParser,
private _interpolationConfig: InterpolationConfig) {}

// implements html.Visitor
visit?(node: html.Node, context: any) {}
visitCdata(text: html.CDATA, context: any) {}
visitDocType(docType: html.DocType, context: any) {}

public toI18nMessage(
nodes: html.Node[], meaning = '', description = '', customId = '',
visitNodeFn: VisitNodeFn|undefined): i18n.Message {
Expand Down
6 changes: 3 additions & 3 deletions packages/compiler/src/ml_parser/html_whitespaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ export class WhitespaceVisitor implements html.Visitor {
// but still visit all attributes to eliminate one used as a market to preserve WS
return new html.Element(
element.name, html.visitAll(this, element.attrs), element.children, element.sourceSpan,
element.startSourceSpan, element.endSourceSpan, element.i18n);
element.startSourceSpan, element.endSourceSpan, null);
}

return new html.Element(
element.name, element.attrs, visitAllWithSiblings(this, element.children),
element.sourceSpan, element.startSourceSpan, element.endSourceSpan, element.i18n);
element.sourceSpan, element.startSourceSpan, element.endSourceSpan, null);
}

visitAttribute(attribute: html.Attribute, context: any): any {
Expand Down Expand Up @@ -91,7 +91,7 @@ export class WhitespaceVisitor implements html.Visitor {

if (isNotBlank) {
return new html.CDATA(
replaceNgsp(cdata.value).replace(WS_REPLACE_REGEXP, ' '), cdata.sourceSpan);
replaceNgsp(cdata.value).replace(WS_REPLACE_REGEXP, ' '), cdata.sourceSpan, []);
}

return null;
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/src/render3/r3_control_flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export function createSwitchBlock(
}

if ((node.name !== 'case' || node.parameters.length === 0) && node.name !== 'default') {
unknownBlocks.push(new t.UnknownBlock(node.name, node.sourceSpan, node.nameSpan));
unknownBlocks.push(new t.UnknownBlock(node.name, node.sourceSpan, node.sourceSpan));
continue;
}

Expand Down
12 changes: 11 additions & 1 deletion packages/compiler/src/render3/r3_template_transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ class HtmlAstToIvyAst implements html.Visitor {

constructor(private bindingParser: BindingParser, private options: Render3ParseOptions) {}

// implements html.Visitor
visit?(node: html.Node, context: any) {}
visitCdata(text: html.CDATA, context: any) {}
visitDocType(docType: html.DocType, context: any) {}

// HTML visitor
visitElement(element: html.Element): t.Node|null {
const isI18nRootElement = isI18nRootNode(element.i18n);
Expand Down Expand Up @@ -383,7 +388,7 @@ class HtmlAstToIvyAst implements html.Visitor {
}

result = {
node: new t.UnknownBlock(block.name, block.sourceSpan, block.nameSpan),
node: new t.UnknownBlock(block.name, block.sourceSpan, block.sourceSpan),
errors: [new ParseError(block.sourceSpan, errorMessage)],
};
break;
Expand Down Expand Up @@ -618,6 +623,11 @@ class HtmlAstToIvyAst implements html.Visitor {
}

class NonBindableVisitor implements html.Visitor {
// implements html.Visitor
visit?(node: html.Node, context: any) {}
visitCdata(text: html.CDATA, context: any) {}
visitDocType(docType: html.DocType, context: any) {}

visitElement(ast: html.Element): t.Element|null {
const preparsedElement = preparseElement(ast);
if (preparsedElement.type === PreparsedElementType.SCRIPT ||
Expand Down
5 changes: 5 additions & 0 deletions packages/compiler/src/render3/view/i18n/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ export class I18nMetaVisitor implements html.Visitor {
private interpolationConfig: InterpolationConfig = DEFAULT_INTERPOLATION_CONFIG,
private keepI18nAttrs = false, private enableI18nLegacyMessageIdFormat = false) {}

// implements html.Visitor
visit?(node: html.Node, context: any) {}
visitCdata(text: html.CDATA, context: any) {}
visitDocType(docType: html.DocType, context: any) {}

private _generateI18nMessage(
nodes: html.Node[], meta: string|i18n.I18nMeta = '',
visitNodeFn?: VisitNodeFn): i18n.Message {
Expand Down