style(compiler): reformat of codebase with new clang-format version (#36520)
This commit reformats the packages/compiler tree using the new version of clang-format. PR Close #36520
This commit is contained in:
@ -13,7 +13,9 @@ import {serializeNodes} from './util/util';
|
||||
describe('Node serializer', () => {
|
||||
let parser: HtmlParser;
|
||||
|
||||
beforeEach(() => { parser = new HtmlParser(); });
|
||||
beforeEach(() => {
|
||||
parser = new HtmlParser();
|
||||
});
|
||||
|
||||
it('should support element', () => {
|
||||
const html = '<p></p>';
|
||||
|
@ -78,7 +78,7 @@ class _Humanizer implements html.Visitor {
|
||||
|
||||
private _appendContext(ast: html.Node, input: any[]): any[] {
|
||||
if (!this.includeSourceSpan) return input;
|
||||
input.push(ast.sourceSpan !.toString());
|
||||
input.push(ast.sourceSpan!.toString());
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,9 @@ import {humanizeDom, humanizeDomSourceSpans, humanizeLineColumn} from './ast_spe
|
||||
describe('HtmlParser', () => {
|
||||
let parser: HtmlParser;
|
||||
|
||||
beforeEach(() => { parser = new HtmlParser(); });
|
||||
beforeEach(() => {
|
||||
parser = new HtmlParser();
|
||||
});
|
||||
|
||||
describe('parse', () => {
|
||||
describe('text nodes', () => {
|
||||
@ -77,11 +79,20 @@ import {humanizeDom, humanizeDomSourceSpans, humanizeLineColumn} from './ast_spe
|
||||
// <meta> - it can be present in head only
|
||||
// <command> - obsolete
|
||||
// <keygen> - obsolete
|
||||
['<map><area></map>', '<div><br></div>', '<colgroup><col></colgroup>',
|
||||
'<div><embed></div>', '<div><hr></div>', '<div><img></div>', '<div><input></div>',
|
||||
'<object><param>/<object>', '<audio><source></audio>', '<audio><track></audio>',
|
||||
['<map><area></map>',
|
||||
'<div><br></div>',
|
||||
'<colgroup><col></colgroup>',
|
||||
'<div><embed></div>',
|
||||
'<div><hr></div>',
|
||||
'<div><img></div>',
|
||||
'<div><input></div>',
|
||||
'<object><param>/<object>',
|
||||
'<audio><source></audio>',
|
||||
'<audio><track></audio>',
|
||||
'<p><wbr></p>',
|
||||
].forEach((html) => { expect(parser.parse(html, 'TestComp').errors).toEqual([]); });
|
||||
].forEach((html) => {
|
||||
expect(parser.parse(html, 'TestComp').errors).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
it('should close void elements on text nodes', () => {
|
||||
@ -189,7 +200,6 @@ import {humanizeDom, humanizeDomSourceSpans, humanizeLineColumn} from './ast_spe
|
||||
[html.Text, '\n', 1],
|
||||
]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('attributes', () => {
|
||||
@ -263,8 +273,9 @@ import {humanizeDom, humanizeDomSourceSpans, humanizeLineColumn} from './ast_spe
|
||||
[html.Text, ' messages', 0],
|
||||
]);
|
||||
|
||||
expect(humanizeDom(new ParseTreeResult(cases[1].expression, [
|
||||
]))).toEqual([[html.Text, 'One {{message}}', 0]]);
|
||||
expect(humanizeDom(new ParseTreeResult(cases[1].expression, []))).toEqual([
|
||||
[html.Text, 'One {{message}}', 0]
|
||||
]);
|
||||
});
|
||||
|
||||
it('should parse out expansion forms', () => {
|
||||
@ -367,11 +378,11 @@ import {humanizeDom, humanizeDomSourceSpans, humanizeLineColumn} from './ast_spe
|
||||
it('should set the start and end source spans', () => {
|
||||
const node = <html.Element>parser.parse('<div>a</div>', 'TestComp').rootNodes[0];
|
||||
|
||||
expect(node.startSourceSpan !.start.offset).toEqual(0);
|
||||
expect(node.startSourceSpan !.end.offset).toEqual(5);
|
||||
expect(node.startSourceSpan!.start.offset).toEqual(0);
|
||||
expect(node.startSourceSpan!.end.offset).toEqual(5);
|
||||
|
||||
expect(node.endSourceSpan !.start.offset).toEqual(6);
|
||||
expect(node.endSourceSpan !.end.offset).toEqual(12);
|
||||
expect(node.endSourceSpan!.start.offset).toEqual(6);
|
||||
expect(node.endSourceSpan!.end.offset).toEqual(12);
|
||||
});
|
||||
|
||||
it('should support expansion form', () => {
|
||||
@ -393,15 +404,15 @@ import {humanizeDom, humanizeDomSourceSpans, humanizeLineColumn} from './ast_spe
|
||||
it('should report a value span for an attribute with a value', () => {
|
||||
const ast = parser.parse('<div bar="12"></div>', 'TestComp');
|
||||
const attr = (ast.rootNodes[0] as html.Element).attrs[0];
|
||||
expect(attr.valueSpan !.start.offset).toEqual(10);
|
||||
expect(attr.valueSpan !.end.offset).toEqual(12);
|
||||
expect(attr.valueSpan!.start.offset).toEqual(10);
|
||||
expect(attr.valueSpan!.end.offset).toEqual(12);
|
||||
});
|
||||
|
||||
it('should report a value span for an unquoted attribute value', () => {
|
||||
const ast = parser.parse('<div bar=12></div>', 'TestComp');
|
||||
const attr = (ast.rootNodes[0] as html.Element).attrs[0];
|
||||
expect(attr.valueSpan !.start.offset).toEqual(9);
|
||||
expect(attr.valueSpan !.end.offset).toEqual(11);
|
||||
expect(attr.valueSpan!.start.offset).toEqual(9);
|
||||
expect(attr.valueSpan!.end.offset).toEqual(11);
|
||||
});
|
||||
});
|
||||
|
||||
@ -426,7 +437,9 @@ import {humanizeDom, humanizeDomSourceSpans, humanizeLineColumn} from './ast_spe
|
||||
parser.parse('<div id="foo"><span id="bar">a</span><span>b</span></div>', 'TestComp');
|
||||
const accumulator: html.Node[] = [];
|
||||
const visitor = new class {
|
||||
visit(node: html.Node, context: any) { accumulator.push(node); }
|
||||
visit(node: html.Node, context: any) {
|
||||
accumulator.push(node);
|
||||
}
|
||||
visitElement(element: html.Element, context: any): any {
|
||||
html.visitAll(this, element.attrs);
|
||||
html.visitAll(this, element.children);
|
||||
@ -449,13 +462,21 @@ import {humanizeDom, humanizeDomSourceSpans, humanizeLineColumn} from './ast_spe
|
||||
|
||||
it('should skip typed visit if visit() returns a truthy value', () => {
|
||||
const visitor = new class {
|
||||
visit(node: html.Node, context: any) { return true; }
|
||||
visitElement(element: html.Element, context: any): any { throw Error('Unexpected'); }
|
||||
visit(node: html.Node, context: any) {
|
||||
return true;
|
||||
}
|
||||
visitElement(element: html.Element, context: any): any {
|
||||
throw Error('Unexpected');
|
||||
}
|
||||
visitAttribute(attribute: html.Attribute, context: any): any {
|
||||
throw Error('Unexpected');
|
||||
}
|
||||
visitText(text: html.Text, context: any): any { throw Error('Unexpected'); }
|
||||
visitComment(comment: html.Comment, context: any): any { throw Error('Unexpected'); }
|
||||
visitText(text: html.Text, context: any): any {
|
||||
throw Error('Unexpected');
|
||||
}
|
||||
visitComment(comment: html.Comment, context: any): any {
|
||||
throw Error('Unexpected');
|
||||
}
|
||||
visitExpansion(expansion: html.Expansion, context: any): any {
|
||||
throw Error('Unexpected');
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import {humanizeDom} from './ast_spec_utils';
|
||||
|
||||
{
|
||||
describe('removeWhitespaces', () => {
|
||||
|
||||
function parseAndRemoveWS(template: string, options?: TokenizeOptions): any[] {
|
||||
return humanizeDom(removeWhitespaces(new HtmlParser().parse(template, 'TestComp', options)));
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
import * as html from '../../src/ml_parser/ast';
|
||||
import {HtmlParser} from '../../src/ml_parser/html_parser';
|
||||
import {ExpansionResult, expandNodes} from '../../src/ml_parser/icu_ast_expander';
|
||||
import {expandNodes, ExpansionResult} from '../../src/ml_parser/icu_ast_expander';
|
||||
import {ParseError} from '../../src/parse_util';
|
||||
|
||||
import {humanizeNodes} from './ast_spec_utils';
|
||||
@ -56,28 +56,28 @@ import {humanizeNodes} from './ast_spec_utils';
|
||||
const nodes = expand(`{messages.length, plural,=0 {<b>bold</b>}}`).nodes;
|
||||
|
||||
const container: html.Element = <html.Element>nodes[0];
|
||||
expect(container.sourceSpan !.start.col).toEqual(0);
|
||||
expect(container.sourceSpan !.end.col).toEqual(42);
|
||||
expect(container.startSourceSpan !.start.col).toEqual(0);
|
||||
expect(container.startSourceSpan !.end.col).toEqual(42);
|
||||
expect(container.endSourceSpan !.start.col).toEqual(0);
|
||||
expect(container.endSourceSpan !.end.col).toEqual(42);
|
||||
expect(container.sourceSpan!.start.col).toEqual(0);
|
||||
expect(container.sourceSpan!.end.col).toEqual(42);
|
||||
expect(container.startSourceSpan!.start.col).toEqual(0);
|
||||
expect(container.startSourceSpan!.end.col).toEqual(42);
|
||||
expect(container.endSourceSpan!.start.col).toEqual(0);
|
||||
expect(container.endSourceSpan!.end.col).toEqual(42);
|
||||
|
||||
const switchExp = container.attrs[0];
|
||||
expect(switchExp.sourceSpan.start.col).toEqual(1);
|
||||
expect(switchExp.sourceSpan.end.col).toEqual(16);
|
||||
|
||||
const template: html.Element = <html.Element>container.children[0];
|
||||
expect(template.sourceSpan !.start.col).toEqual(25);
|
||||
expect(template.sourceSpan !.end.col).toEqual(41);
|
||||
expect(template.sourceSpan!.start.col).toEqual(25);
|
||||
expect(template.sourceSpan!.end.col).toEqual(41);
|
||||
|
||||
const switchCheck = template.attrs[0];
|
||||
expect(switchCheck.sourceSpan.start.col).toEqual(25);
|
||||
expect(switchCheck.sourceSpan.end.col).toEqual(28);
|
||||
|
||||
const b: html.Element = <html.Element>template.children[0];
|
||||
expect(b.sourceSpan !.start.col).toEqual(29);
|
||||
expect(b.endSourceSpan !.end.col).toEqual(40);
|
||||
expect(b.sourceSpan!.start.col).toEqual(29);
|
||||
expect(b.endSourceSpan!.end.col).toEqual(40);
|
||||
});
|
||||
|
||||
it('should handle other special forms', () => {
|
||||
|
@ -232,7 +232,6 @@ import {ParseLocation, ParseSourceFile, ParseSourceSpan} from '../../src/parse_u
|
||||
[lex.TokenType.EOF, ''],
|
||||
]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('attributes', () => {
|
||||
@ -400,7 +399,6 @@ import {ParseLocation, ParseSourceFile, ParseSourceSpan} from '../../src/parse_u
|
||||
[lex.TokenType.ATTR_VALUE, 'Unexpected character "EOF"', '0:8'],
|
||||
]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('closing tags', () => {
|
||||
@ -729,7 +727,6 @@ import {ParseLocation, ParseSourceFile, ParseSourceSpan} from '../../src/parse_u
|
||||
[lex.TokenType.EOF, ''],
|
||||
]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('expansion forms', () => {
|
||||
@ -898,7 +895,7 @@ import {ParseLocation, ParseSourceFile, ParseSourceSpan} from '../../src/parse_u
|
||||
const file = new ParseSourceFile(src, 'file://');
|
||||
const location = new ParseLocation(file, 12, 123, 456);
|
||||
const span = new ParseSourceSpan(location, location);
|
||||
const error = new lex.TokenError('**ERROR**', null !, span);
|
||||
const error = new lex.TokenError('**ERROR**', null!, span);
|
||||
expect(error.toString())
|
||||
.toEqual(`**ERROR** ("\n222\n333\n[ERROR ->]E\n444\n555\n"): file://@123:456`);
|
||||
});
|
||||
|
@ -15,16 +15,21 @@ class _SerializerVisitor implements html.Visitor {
|
||||
return `<${element.name}${this._visitAll(element.attrs, ' ')}/>`;
|
||||
}
|
||||
|
||||
return `<${element.name}${this._visitAll(element.attrs, ' ')}>${this._visitAll(element.children)}</${element.name}>`;
|
||||
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; }
|
||||
visitText(text: html.Text, context: any): any {
|
||||
return text.value;
|
||||
}
|
||||
|
||||
visitComment(comment: html.Comment, context: any): any { return `<!--${comment.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)}}`;
|
||||
|
Reference in New Issue
Block a user