test(ivy): update //packages/compiler tests for Ivy (#27301)
Most of the specs in these tests are not relevant to Ivy: //packages/compiler/test:test //packages/compiler/test:test_web_chromium-local However, a few test pieces of the compiler infrastructure that are used in Ivy, and new BUILD.bazel files are created to separate them from the above disabled targets: //packages/compiler/test/css_parser:css_parser //packages/compiler/test/css_parser:css_parser_web //packages/compiler/test/expression_parser:expression_parser //packages/compiler/test/expression_parser:expression_parser_web //packages/compiler/test/ml_parser:ml_parser //packages/compiler/test/ml_parser:ml_parser_web //packages/compiler/test/selector:selector //packages/compiler/test/selector:selector_web PR Close #27301
This commit is contained in:

committed by
Igor Minar

parent
49537458ea
commit
4effb89ae8
@ -6,9 +6,8 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import * as html from '@angular/compiler/src/ml_parser/ast';
|
||||
import {HtmlParser} from '@angular/compiler/src/ml_parser/html_parser';
|
||||
import {getHtmlTagDefinition} from '@angular/compiler/src/ml_parser/html_tags';
|
||||
import {serializeNodes} from './util/util';
|
||||
|
||||
{
|
||||
describe('Node serializer', () => {
|
||||
@ -59,42 +58,3 @@ import {getHtmlTagDefinition} from '@angular/compiler/src/ml_parser/html_tags';
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
class _SerializerVisitor implements html.Visitor {
|
||||
visitElement(element: html.Element, context: any): any {
|
||||
if (getHtmlTagDefinition(element.name).isVoid) {
|
||||
return `<${element.name}${this._visitAll(element.attrs, ' ')}/>`;
|
||||
}
|
||||
|
||||
return `<${element.name}${this._visitAll(element.attrs, ' ')}>${this._visitAll(element.children)}</${element.name}>`;
|
||||
}
|
||||
|
||||
visitAttribute(attribute: html.Attribute, context: any): any {
|
||||
return `${attribute.name}="${attribute.value}"`;
|
||||
}
|
||||
|
||||
visitText(text: html.Text, context: any): any { return text.value; }
|
||||
|
||||
visitComment(comment: html.Comment, context: any): any { return `<!--${comment.value}-->`; }
|
||||
|
||||
visitExpansion(expansion: html.Expansion, context: any): any {
|
||||
return `{${expansion.switchValue}, ${expansion.type},${this._visitAll(expansion.cases)}}`;
|
||||
}
|
||||
|
||||
visitExpansionCase(expansionCase: html.ExpansionCase, context: any): any {
|
||||
return ` ${expansionCase.value} {${this._visitAll(expansionCase.expression)}}`;
|
||||
}
|
||||
|
||||
private _visitAll(nodes: html.Node[], join: string = ''): string {
|
||||
if (nodes.length == 0) {
|
||||
return '';
|
||||
}
|
||||
return join + nodes.map(a => a.visit(this, null)).join(join);
|
||||
}
|
||||
}
|
||||
|
||||
const serializerVisitor = new _SerializerVisitor();
|
||||
|
||||
export function serializeNodes(nodes: html.Node[]): string[] {
|
||||
return nodes.map(node => node.visit(serializerVisitor, null));
|
||||
}
|
||||
|
Reference in New Issue
Block a user