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:
@ -24,7 +24,9 @@ export class Text extends NodeWithI18n {
|
||||
constructor(public value: string, sourceSpan: ParseSourceSpan, i18n?: I18nMeta) {
|
||||
super(sourceSpan, i18n);
|
||||
}
|
||||
visit(visitor: Visitor, context: any): any { return visitor.visitText(this, context); }
|
||||
visit(visitor: Visitor, context: any): any {
|
||||
return visitor.visitText(this, context);
|
||||
}
|
||||
}
|
||||
|
||||
export class Expansion extends NodeWithI18n {
|
||||
@ -33,7 +35,9 @@ export class Expansion extends NodeWithI18n {
|
||||
sourceSpan: ParseSourceSpan, public switchValueSourceSpan: ParseSourceSpan, i18n?: I18nMeta) {
|
||||
super(sourceSpan, i18n);
|
||||
}
|
||||
visit(visitor: Visitor, context: any): any { return visitor.visitExpansion(this, context); }
|
||||
visit(visitor: Visitor, context: any): any {
|
||||
return visitor.visitExpansion(this, context);
|
||||
}
|
||||
}
|
||||
|
||||
export class ExpansionCase implements Node {
|
||||
@ -41,7 +45,9 @@ export class ExpansionCase implements Node {
|
||||
public value: string, public expression: Node[], public sourceSpan: ParseSourceSpan,
|
||||
public valueSourceSpan: ParseSourceSpan, public expSourceSpan: ParseSourceSpan) {}
|
||||
|
||||
visit(visitor: Visitor, context: any): any { return visitor.visitExpansionCase(this, context); }
|
||||
visit(visitor: Visitor, context: any): any {
|
||||
return visitor.visitExpansionCase(this, context);
|
||||
}
|
||||
}
|
||||
|
||||
export class Attribute extends NodeWithI18n {
|
||||
@ -50,7 +56,9 @@ export class Attribute extends NodeWithI18n {
|
||||
public valueSpan?: ParseSourceSpan, i18n?: I18nMeta) {
|
||||
super(sourceSpan, i18n);
|
||||
}
|
||||
visit(visitor: Visitor, context: any): any { return visitor.visitAttribute(this, context); }
|
||||
visit(visitor: Visitor, context: any): any {
|
||||
return visitor.visitAttribute(this, context);
|
||||
}
|
||||
}
|
||||
|
||||
export class Element extends NodeWithI18n {
|
||||
@ -60,12 +68,16 @@ export class Element extends NodeWithI18n {
|
||||
public endSourceSpan: ParseSourceSpan|null = null, i18n?: I18nMeta) {
|
||||
super(sourceSpan, i18n);
|
||||
}
|
||||
visit(visitor: Visitor, context: any): any { return visitor.visitElement(this, context); }
|
||||
visit(visitor: Visitor, context: any): any {
|
||||
return visitor.visitElement(this, context);
|
||||
}
|
||||
}
|
||||
|
||||
export class Comment implements Node {
|
||||
constructor(public value: string|null, public sourceSpan: ParseSourceSpan) {}
|
||||
visit(visitor: Visitor, context: any): any { return visitor.visitComment(this, context); }
|
||||
visit(visitor: Visitor, context: any): any {
|
||||
return visitor.visitComment(this, context);
|
||||
}
|
||||
}
|
||||
|
||||
export interface Visitor {
|
||||
@ -85,7 +97,7 @@ export function visitAll(visitor: Visitor, nodes: Node[], context: any = null):
|
||||
const result: any[] = [];
|
||||
|
||||
const visit = visitor.visit ?
|
||||
(ast: Node) => visitor.visit !(ast, context) || ast.visit(visitor, context) :
|
||||
(ast: Node) => visitor.visit!(ast, context) || ast.visit(visitor, context) :
|
||||
(ast: Node) => ast.visit(visitor, context);
|
||||
nodes.forEach(ast => {
|
||||
const astResult = visit(ast);
|
||||
@ -111,7 +123,9 @@ export class RecursiveVisitor implements Visitor {
|
||||
visitComment(ast: Comment, context: any): any {}
|
||||
|
||||
visitExpansion(ast: Expansion, context: any): any {
|
||||
return this.visitChildren(context, visit => { visit(ast.cases); });
|
||||
return this.visitChildren(context, visit => {
|
||||
visit(ast.cases);
|
||||
});
|
||||
}
|
||||
|
||||
visitExpansionCase(ast: ExpansionCase, context: any): any {}
|
||||
@ -120,7 +134,7 @@ export class RecursiveVisitor implements Visitor {
|
||||
context: any, cb: (visit: (<V extends Node>(children: V[]|undefined) => void)) => void) {
|
||||
let results: any[][] = [];
|
||||
let t = this;
|
||||
function visit<T extends Node>(children: T[] | undefined) {
|
||||
function visit<T extends Node>(children: T[]|undefined) {
|
||||
if (children) results.push(visitAll(t, children, context));
|
||||
}
|
||||
cb(visit);
|
||||
|
@ -8,12 +8,14 @@
|
||||
|
||||
import {getHtmlTagDefinition} from './html_tags';
|
||||
import {TokenizeOptions} from './lexer';
|
||||
import {ParseTreeResult, Parser} from './parser';
|
||||
import {Parser, ParseTreeResult} from './parser';
|
||||
|
||||
export {ParseTreeResult, TreeError} from './parser';
|
||||
|
||||
export class HtmlParser extends Parser {
|
||||
constructor() { super(getHtmlTagDefinition); }
|
||||
constructor() {
|
||||
super(getHtmlTagDefinition);
|
||||
}
|
||||
|
||||
parse(source: string, url: string, options?: TokenizeOptions): ParseTreeResult {
|
||||
return super.parse(source, url, options);
|
||||
|
@ -18,16 +18,21 @@ export class HtmlTagDefinition implements TagDefinition {
|
||||
ignoreFirstLf: boolean;
|
||||
canSelfClose: boolean = false;
|
||||
|
||||
constructor(
|
||||
{closedByChildren, implicitNamespacePrefix, contentType = TagContentType.PARSABLE_DATA,
|
||||
closedByParent = false, isVoid = false, ignoreFirstLf = false}: {
|
||||
closedByChildren?: string[],
|
||||
closedByParent?: boolean,
|
||||
implicitNamespacePrefix?: string,
|
||||
contentType?: TagContentType,
|
||||
isVoid?: boolean,
|
||||
ignoreFirstLf?: boolean
|
||||
} = {}) {
|
||||
constructor({
|
||||
closedByChildren,
|
||||
implicitNamespacePrefix,
|
||||
contentType = TagContentType.PARSABLE_DATA,
|
||||
closedByParent = false,
|
||||
isVoid = false,
|
||||
ignoreFirstLf = false
|
||||
}: {
|
||||
closedByChildren?: string[],
|
||||
closedByParent?: boolean,
|
||||
implicitNamespacePrefix?: string,
|
||||
contentType?: TagContentType,
|
||||
isVoid?: boolean,
|
||||
ignoreFirstLf?: boolean
|
||||
} = {}) {
|
||||
if (closedByChildren && closedByChildren.length > 0) {
|
||||
closedByChildren.forEach(tagName => this.closedByChildren[tagName] = true);
|
||||
}
|
||||
@ -43,11 +48,11 @@ export class HtmlTagDefinition implements TagDefinition {
|
||||
}
|
||||
}
|
||||
|
||||
let _DEFAULT_TAG_DEFINITION !: HtmlTagDefinition;
|
||||
let _DEFAULT_TAG_DEFINITION!: HtmlTagDefinition;
|
||||
|
||||
// see http://www.w3.org/TR/html51/syntax.html#optional-tags
|
||||
// This implementation does not fully conform to the HTML5 spec.
|
||||
let TAG_DEFINITIONS !: {[key: string]: HtmlTagDefinition};
|
||||
let TAG_DEFINITIONS!: {[key: string]: HtmlTagDefinition};
|
||||
|
||||
export function getHtmlTagDefinition(tagName: string): HtmlTagDefinition {
|
||||
if (!TAG_DEFINITIONS) {
|
||||
|
@ -81,11 +81,17 @@ export class WhitespaceVisitor implements html.Visitor {
|
||||
return null;
|
||||
}
|
||||
|
||||
visitComment(comment: html.Comment, context: any): any { return comment; }
|
||||
visitComment(comment: html.Comment, context: any): any {
|
||||
return comment;
|
||||
}
|
||||
|
||||
visitExpansion(expansion: html.Expansion, context: any): any { return expansion; }
|
||||
visitExpansion(expansion: html.Expansion, context: any): any {
|
||||
return expansion;
|
||||
}
|
||||
|
||||
visitExpansionCase(expansionCase: html.ExpansionCase, context: any): any { return expansionCase; }
|
||||
visitExpansionCase(expansionCase: html.ExpansionCase, context: any): any {
|
||||
return expansionCase;
|
||||
}
|
||||
}
|
||||
|
||||
export function removeWhitespaces(htmlAstWithErrors: ParseTreeResult): ParseTreeResult {
|
||||
|
@ -46,7 +46,9 @@ export class ExpansionResult {
|
||||
}
|
||||
|
||||
export class ExpansionError extends ParseError {
|
||||
constructor(span: ParseSourceSpan, errorMsg: string) { super(span, errorMsg); }
|
||||
constructor(span: ParseSourceSpan, errorMsg: string) {
|
||||
super(span, errorMsg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,11 +66,17 @@ class _Expander implements html.Visitor {
|
||||
element.startSourceSpan, element.endSourceSpan);
|
||||
}
|
||||
|
||||
visitAttribute(attribute: html.Attribute, context: any): any { return attribute; }
|
||||
visitAttribute(attribute: html.Attribute, context: any): any {
|
||||
return attribute;
|
||||
}
|
||||
|
||||
visitText(text: html.Text, context: any): any { return text; }
|
||||
visitText(text: html.Text, context: any): any {
|
||||
return text;
|
||||
}
|
||||
|
||||
visitComment(comment: html.Comment, context: any): any { return comment; }
|
||||
visitComment(comment: html.Comment, context: any): any {
|
||||
return comment;
|
||||
}
|
||||
|
||||
visitExpansion(icu: html.Expansion, context: any): any {
|
||||
this.isExpanded = true;
|
||||
@ -87,7 +95,7 @@ function _expandPluralForm(ast: html.Expansion, errors: ParseError[]): html.Elem
|
||||
if (PLURAL_CASES.indexOf(c.value) == -1 && !c.value.match(/^=\d+$/)) {
|
||||
errors.push(new ExpansionError(
|
||||
c.valueSourceSpan,
|
||||
`Plural cases should be "=<number>" or one of ${PLURAL_CASES.join(", ")}`));
|
||||
`Plural cases should be "=<number>" or one of ${PLURAL_CASES.join(', ')}`));
|
||||
}
|
||||
|
||||
const expansionResult = expandNodes(c.expression);
|
||||
|
@ -764,7 +764,7 @@ function mergeTextTokens(srcTokens: Token[]): Token[] {
|
||||
for (let i = 0; i < srcTokens.length; i++) {
|
||||
const token = srcTokens[i];
|
||||
if (lastDstToken && lastDstToken.type == TokenType.TEXT && token.type == TokenType.TEXT) {
|
||||
lastDstToken.parts[0] ! += token.parts[0];
|
||||
lastDstToken.parts[0]! += token.parts[0];
|
||||
lastDstToken.sourceSpan.end = token.sourceSpan.end;
|
||||
} else {
|
||||
lastDstToken = token;
|
||||
@ -849,15 +849,27 @@ class PlainCharacterCursor implements CharacterCursor {
|
||||
}
|
||||
}
|
||||
|
||||
clone(): PlainCharacterCursor { return new PlainCharacterCursor(this); }
|
||||
clone(): PlainCharacterCursor {
|
||||
return new PlainCharacterCursor(this);
|
||||
}
|
||||
|
||||
peek() { return this.state.peek; }
|
||||
charsLeft() { return this.end - this.state.offset; }
|
||||
diff(other: this) { return this.state.offset - other.state.offset; }
|
||||
peek() {
|
||||
return this.state.peek;
|
||||
}
|
||||
charsLeft() {
|
||||
return this.end - this.state.offset;
|
||||
}
|
||||
diff(other: this) {
|
||||
return this.state.offset - other.state.offset;
|
||||
}
|
||||
|
||||
advance(): void { this.advanceState(this.state); }
|
||||
advance(): void {
|
||||
this.advanceState(this.state);
|
||||
}
|
||||
|
||||
init(): void { this.updatePeek(this.state); }
|
||||
init(): void {
|
||||
this.updatePeek(this.state);
|
||||
}
|
||||
|
||||
getSpan(start?: this, leadingTriviaCodePoints?: number[]): ParseSourceSpan {
|
||||
start = start || this;
|
||||
@ -880,7 +892,9 @@ class PlainCharacterCursor implements CharacterCursor {
|
||||
return this.input.substring(start.state.offset, this.state.offset);
|
||||
}
|
||||
|
||||
charAt(pos: number): number { return this.input.charCodeAt(pos); }
|
||||
charAt(pos: number): number {
|
||||
return this.input.charCodeAt(pos);
|
||||
}
|
||||
|
||||
protected advanceState(state: CursorState) {
|
||||
if (state.offset >= this.end) {
|
||||
@ -913,7 +927,7 @@ class EscapedCharacterCursor extends PlainCharacterCursor {
|
||||
super(fileOrCursor);
|
||||
this.internalState = {...fileOrCursor.internalState};
|
||||
} else {
|
||||
super(fileOrCursor, range !);
|
||||
super(fileOrCursor, range!);
|
||||
this.internalState = this.state;
|
||||
}
|
||||
}
|
||||
@ -929,7 +943,9 @@ class EscapedCharacterCursor extends PlainCharacterCursor {
|
||||
this.processEscapeSequence();
|
||||
}
|
||||
|
||||
clone(): EscapedCharacterCursor { return new EscapedCharacterCursor(this); }
|
||||
clone(): EscapedCharacterCursor {
|
||||
return new EscapedCharacterCursor(this);
|
||||
}
|
||||
|
||||
getChars(start: this): string {
|
||||
const cursor = start.clone();
|
||||
|
@ -10,7 +10,7 @@ import {ParseError, ParseSourceSpan} from '../parse_util';
|
||||
|
||||
import * as html from './ast';
|
||||
import * as lex from './lexer';
|
||||
import {TagDefinition, getNsPrefix, isNgContainer, mergeNsAndName} from './tags';
|
||||
import {getNsPrefix, isNgContainer, mergeNsAndName, TagDefinition} from './tags';
|
||||
|
||||
export class TreeError extends ParseError {
|
||||
static create(elementName: string|null, span: ParseSourceSpan, msg: string): TreeError {
|
||||
@ -43,7 +43,7 @@ export class Parser {
|
||||
class _TreeBuilder {
|
||||
private _index: number = -1;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
private _peek !: lex.Token;
|
||||
private _peek!: lex.Token;
|
||||
|
||||
private _rootNodes: html.Node[] = [];
|
||||
private _errors: TreeError[] = [];
|
||||
@ -283,7 +283,7 @@ class _TreeBuilder {
|
||||
endTagToken.parts[0], endTagToken.parts[1], this._getParentElement());
|
||||
|
||||
if (this._getParentElement()) {
|
||||
this._getParentElement() !.endSourceSpan = endTagToken.sourceSpan;
|
||||
this._getParentElement()!.endSourceSpan = endTagToken.sourceSpan;
|
||||
}
|
||||
|
||||
if (this.getTagDefinition(fullName).isVoid) {
|
||||
@ -291,8 +291,8 @@ class _TreeBuilder {
|
||||
fullName, endTagToken.sourceSpan,
|
||||
`Void elements do not have end tags "${endTagToken.parts[1]}"`));
|
||||
} else if (!this._popElement(fullName)) {
|
||||
const errMsg =
|
||||
`Unexpected closing tag "${fullName}". It may happen when the tag has already been closed by another tag. For more info see https://www.w3.org/TR/html5/syntax.html#closing-elements-that-have-implied-end-tags`;
|
||||
const errMsg = `Unexpected closing tag "${
|
||||
fullName}". It may happen when the tag has already been closed by another tag. For more info see https://www.w3.org/TR/html5/syntax.html#closing-elements-that-have-implied-end-tags`;
|
||||
this._errors.push(TreeError.create(fullName, endTagToken.sourceSpan, errMsg));
|
||||
}
|
||||
}
|
||||
@ -316,7 +316,7 @@ class _TreeBuilder {
|
||||
const fullName = mergeNsAndName(attrName.parts[0], attrName.parts[1]);
|
||||
let end = attrName.sourceSpan.end;
|
||||
let value = '';
|
||||
let valueSpan: ParseSourceSpan = undefined !;
|
||||
let valueSpan: ParseSourceSpan = undefined!;
|
||||
if (this._peek.type === lex.TokenType.ATTR_QUOTE) {
|
||||
this._advance();
|
||||
}
|
||||
@ -344,7 +344,7 @@ class _TreeBuilder {
|
||||
* `<ng-container>` elements are skipped as they are not rendered as DOM element.
|
||||
*/
|
||||
private _getParentElementSkippingContainers():
|
||||
{parent: html.Element | null, container: html.Element|null} {
|
||||
{parent: html.Element|null, container: html.Element|null} {
|
||||
let container: html.Element|null = null;
|
||||
|
||||
for (let i = this._elementStack.length - 1; i >= 0; i--) {
|
||||
|
@ -23,7 +23,7 @@ export interface TagDefinition {
|
||||
isClosedByChild(name: string): boolean;
|
||||
}
|
||||
|
||||
export function splitNsName(elementName: string): [string | null, string] {
|
||||
export function splitNsName(elementName: string): [string|null, string] {
|
||||
if (elementName[0] != ':') {
|
||||
return [null, elementName];
|
||||
}
|
||||
@ -54,7 +54,7 @@ export function isNgTemplate(tagName: string): boolean {
|
||||
|
||||
export function getNsPrefix(fullName: string): string;
|
||||
export function getNsPrefix(fullName: null): null;
|
||||
export function getNsPrefix(fullName: string | null): string|null {
|
||||
export function getNsPrefix(fullName: string|null): string|null {
|
||||
return fullName === null ? null : splitNsName(fullName)[0];
|
||||
}
|
||||
|
||||
|
@ -7,13 +7,15 @@
|
||||
*/
|
||||
|
||||
import {TokenizeOptions} from './lexer';
|
||||
import {ParseTreeResult, Parser} from './parser';
|
||||
import {Parser, ParseTreeResult} from './parser';
|
||||
import {getXmlTagDefinition} from './xml_tags';
|
||||
|
||||
export {ParseTreeResult, TreeError} from './parser';
|
||||
|
||||
export class XmlParser extends Parser {
|
||||
constructor() { super(getXmlTagDefinition); }
|
||||
constructor() {
|
||||
super(getXmlTagDefinition);
|
||||
}
|
||||
|
||||
parse(source: string, url: string, options?: TokenizeOptions): ParseTreeResult {
|
||||
return super.parse(source, url, options);
|
||||
|
@ -11,19 +11,23 @@ import {TagContentType, TagDefinition} from './tags';
|
||||
export class XmlTagDefinition implements TagDefinition {
|
||||
closedByParent: boolean = false;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
requiredParents !: {[key: string]: boolean};
|
||||
requiredParents!: {[key: string]: boolean};
|
||||
// TODO(issue/24571): remove '!'.
|
||||
parentToAdd !: string;
|
||||
parentToAdd!: string;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
implicitNamespacePrefix !: string;
|
||||
implicitNamespacePrefix!: string;
|
||||
contentType: TagContentType = TagContentType.PARSABLE_DATA;
|
||||
isVoid: boolean = false;
|
||||
ignoreFirstLf: boolean = false;
|
||||
canSelfClose: boolean = true;
|
||||
|
||||
requireExtraParent(currentParent: string): boolean { return false; }
|
||||
requireExtraParent(currentParent: string): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
isClosedByChild(name: string): boolean { return false; }
|
||||
isClosedByChild(name: string): boolean {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const _TAG_DEFINITION = new XmlTagDefinition();
|
||||
|
Reference in New Issue
Block a user