refactor(): use const and let instead of var
This commit is contained in:

committed by
Victor Berchet

parent
73593d4bf3
commit
77ee27c59e
@ -12,7 +12,7 @@ import {getHtmlTagDefinition} from '@angular/compiler/src/ml_parser/html_tags';
|
||||
|
||||
export function main() {
|
||||
describe('Node serializer', () => {
|
||||
var parser: HtmlParser;
|
||||
let parser: HtmlParser;
|
||||
|
||||
beforeEach(() => { parser = new HtmlParser(); });
|
||||
|
||||
|
@ -12,7 +12,7 @@ import {ParseLocation} from '../../src/parse_util';
|
||||
|
||||
export function humanizeDom(parseResult: ParseTreeResult, addSourceSpan: boolean = false): any[] {
|
||||
if (parseResult.errors.length > 0) {
|
||||
var errorString = parseResult.errors.join('\n');
|
||||
const errorString = parseResult.errors.join('\n');
|
||||
throw new Error(`Unexpected parse errors:\n${errorString}`);
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ export function humanizeDomSourceSpans(parseResult: ParseTreeResult): any[] {
|
||||
}
|
||||
|
||||
export function humanizeNodes(nodes: html.Node[], addSourceSpan: boolean = false): any[] {
|
||||
var humanizer = new _Humanizer(addSourceSpan);
|
||||
const humanizer = new _Humanizer(addSourceSpan);
|
||||
html.visitAll(humanizer, nodes);
|
||||
return humanizer.result;
|
||||
}
|
||||
@ -40,7 +40,7 @@ class _Humanizer implements html.Visitor {
|
||||
constructor(private includeSourceSpan: boolean){};
|
||||
|
||||
visitElement(element: html.Element, context: any): any {
|
||||
var res = this._appendContext(element, [html.Element, element.name, this.elDepth++]);
|
||||
const res = this._appendContext(element, [html.Element, element.name, this.elDepth++]);
|
||||
this.result.push(res);
|
||||
html.visitAll(this, element.attrs);
|
||||
html.visitAll(this, element.children);
|
||||
@ -48,22 +48,22 @@ class _Humanizer implements html.Visitor {
|
||||
}
|
||||
|
||||
visitAttribute(attribute: html.Attribute, context: any): any {
|
||||
var res = this._appendContext(attribute, [html.Attribute, attribute.name, attribute.value]);
|
||||
const res = this._appendContext(attribute, [html.Attribute, attribute.name, attribute.value]);
|
||||
this.result.push(res);
|
||||
}
|
||||
|
||||
visitText(text: html.Text, context: any): any {
|
||||
var res = this._appendContext(text, [html.Text, text.value, this.elDepth]);
|
||||
const res = this._appendContext(text, [html.Text, text.value, this.elDepth]);
|
||||
this.result.push(res);
|
||||
}
|
||||
|
||||
visitComment(comment: html.Comment, context: any): any {
|
||||
var res = this._appendContext(comment, [html.Comment, comment.value, this.elDepth]);
|
||||
const res = this._appendContext(comment, [html.Comment, comment.value, this.elDepth]);
|
||||
this.result.push(res);
|
||||
}
|
||||
|
||||
visitExpansion(expansion: html.Expansion, context: any): any {
|
||||
var res = this._appendContext(
|
||||
const res = this._appendContext(
|
||||
expansion, [html.Expansion, expansion.switchValue, expansion.type, this.elDepth++]);
|
||||
this.result.push(res);
|
||||
html.visitAll(this, expansion.cases);
|
||||
@ -71,7 +71,7 @@ class _Humanizer implements html.Visitor {
|
||||
}
|
||||
|
||||
visitExpansionCase(expansionCase: html.ExpansionCase, context: any): any {
|
||||
var res =
|
||||
const res =
|
||||
this._appendContext(expansionCase, [html.ExpansionCase, expansionCase.value, this.elDepth]);
|
||||
this.result.push(res);
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ import {humanizeDom, humanizeDomSourceSpans, humanizeLineColumn} from './ast_spe
|
||||
|
||||
export function main() {
|
||||
describe('HtmlParser', () => {
|
||||
var parser: HtmlParser;
|
||||
let parser: HtmlParser;
|
||||
|
||||
beforeEach(() => { parser = new HtmlParser(); });
|
||||
|
||||
@ -193,7 +193,7 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should match closing tags case sensitive', () => {
|
||||
let errors = parser.parse('<DiV><P></p></dIv>', 'TestComp').errors;
|
||||
const errors = parser.parse('<DiV><P></p></dIv>', 'TestComp').errors;
|
||||
expect(errors.length).toEqual(2);
|
||||
expect(humanizeErrors(errors)).toEqual([
|
||||
['p', 'Unexpected closing tag "p"', '0:8'],
|
||||
@ -279,7 +279,7 @@ export function main() {
|
||||
|
||||
describe('expansion forms', () => {
|
||||
it('should parse out expansion forms', () => {
|
||||
let parsed = parser.parse(
|
||||
const parsed = parser.parse(
|
||||
`<div>before{messages.length, plural, =0 {You have <b>no</b> messages} =1 {One {{message}}}}after</div>`,
|
||||
'TestComp', true);
|
||||
|
||||
@ -291,7 +291,7 @@ export function main() {
|
||||
[html.ExpansionCase, '=1', 2],
|
||||
[html.Text, 'after', 1],
|
||||
]);
|
||||
let cases = (<any>parsed.rootNodes[0]).children[1].cases;
|
||||
const cases = (<any>parsed.rootNodes[0]).children[1].cases;
|
||||
|
||||
expect(humanizeDom(new ParseTreeResult(cases[0].expression, []))).toEqual([
|
||||
[html.Text, 'You have ', 0],
|
||||
@ -305,14 +305,14 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should parse out nested expansion forms', () => {
|
||||
let parsed = parser.parse(
|
||||
const parsed = parser.parse(
|
||||
`{messages.length, plural, =0 { {p.gender, select, male {m}} }}`, 'TestComp', true);
|
||||
expect(humanizeDom(parsed)).toEqual([
|
||||
[html.Expansion, 'messages.length', 'plural', 0],
|
||||
[html.ExpansionCase, '=0', 1],
|
||||
]);
|
||||
|
||||
let firstCase = (<any>parsed.rootNodes[0]).cases[0];
|
||||
const firstCase = (<any>parsed.rootNodes[0]).cases[0];
|
||||
|
||||
expect(humanizeDom(new ParseTreeResult(firstCase.expression, []))).toEqual([
|
||||
[html.Expansion, 'p.gender', 'select', 0],
|
||||
@ -322,21 +322,21 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should error when expansion form is not closed', () => {
|
||||
let p = parser.parse(`{messages.length, plural, =0 {one}`, 'TestComp', true);
|
||||
const p = parser.parse(`{messages.length, plural, =0 {one}`, 'TestComp', true);
|
||||
expect(humanizeErrors(p.errors)).toEqual([
|
||||
[null, 'Invalid ICU message. Missing \'}\'.', '0:34']
|
||||
]);
|
||||
});
|
||||
|
||||
it('should error when expansion case is not closed', () => {
|
||||
let p = parser.parse(`{messages.length, plural, =0 {one`, 'TestComp', true);
|
||||
const p = parser.parse(`{messages.length, plural, =0 {one`, 'TestComp', true);
|
||||
expect(humanizeErrors(p.errors)).toEqual([
|
||||
[null, 'Invalid ICU message. Missing \'}\'.', '0:29']
|
||||
]);
|
||||
});
|
||||
|
||||
it('should error when invalid html in the case', () => {
|
||||
let p = parser.parse(`{messages.length, plural, =0 {<b/>}`, 'TestComp', true);
|
||||
const p = parser.parse(`{messages.length, plural, =0 {<b/>}`, 'TestComp', true);
|
||||
expect(humanizeErrors(p.errors)).toEqual([
|
||||
['b', 'Only void and foreign elements can be self closed "b"', '0:30']
|
||||
]);
|
||||
@ -358,7 +358,7 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should set the start and end source spans', () => {
|
||||
let node = <html.Element>parser.parse('<div>a</div>', 'TestComp').rootNodes[0];
|
||||
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);
|
||||
@ -456,19 +456,19 @@ export function main() {
|
||||
|
||||
describe('errors', () => {
|
||||
it('should report unexpected closing tags', () => {
|
||||
let errors = parser.parse('<div></p></div>', 'TestComp').errors;
|
||||
const errors = parser.parse('<div></p></div>', 'TestComp').errors;
|
||||
expect(errors.length).toEqual(1);
|
||||
expect(humanizeErrors(errors)).toEqual([['p', 'Unexpected closing tag "p"', '0:5']]);
|
||||
});
|
||||
|
||||
it('should report subsequent open tags without proper close tag', () => {
|
||||
let errors = parser.parse('<div</div>', 'TestComp').errors;
|
||||
const errors = parser.parse('<div</div>', 'TestComp').errors;
|
||||
expect(errors.length).toEqual(1);
|
||||
expect(humanizeErrors(errors)).toEqual([['div', 'Unexpected closing tag "div"', '0:4']]);
|
||||
});
|
||||
|
||||
it('should report closing tag for void elements', () => {
|
||||
let errors = parser.parse('<input></input>', 'TestComp').errors;
|
||||
const errors = parser.parse('<input></input>', 'TestComp').errors;
|
||||
expect(errors.length).toEqual(1);
|
||||
expect(humanizeErrors(errors)).toEqual([
|
||||
['input', 'Void elements do not have end tags "input"', '0:7']
|
||||
@ -476,7 +476,7 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should report self closing html element', () => {
|
||||
let errors = parser.parse('<p />', 'TestComp').errors;
|
||||
const errors = parser.parse('<p />', 'TestComp').errors;
|
||||
expect(errors.length).toEqual(1);
|
||||
expect(humanizeErrors(errors)).toEqual([
|
||||
['p', 'Only void and foreign elements can be self closed "p"', '0:0']
|
||||
@ -484,7 +484,7 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should report self closing custom element', () => {
|
||||
let errors = parser.parse('<my-cmp />', 'TestComp').errors;
|
||||
const errors = parser.parse('<my-cmp />', 'TestComp').errors;
|
||||
expect(errors.length).toEqual(1);
|
||||
expect(humanizeErrors(errors)).toEqual([
|
||||
['my-cmp', 'Only void and foreign elements can be self closed "my-cmp"', '0:0']
|
||||
@ -492,7 +492,7 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should also report lexer errors', () => {
|
||||
let errors = parser.parse('<!-err--><div></p></div>', 'TestComp').errors;
|
||||
const errors = parser.parse('<!-err--><div></p></div>', 'TestComp').errors;
|
||||
expect(errors.length).toEqual(2);
|
||||
expect(humanizeErrors(errors)).toEqual([
|
||||
[TokenType.COMMENT_START, 'Unexpected character "e"', '0:3'],
|
||||
|
@ -738,11 +738,11 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should include 2 lines of context in message', () => {
|
||||
let src = '111\n222\n333\nE\n444\n555\n666\n';
|
||||
let file = new ParseSourceFile(src, 'file://');
|
||||
let location = new ParseLocation(file, 12, 123, 456);
|
||||
let span = new ParseSourceSpan(location, location);
|
||||
let error = new lex.TokenError('**ERROR**', null, span);
|
||||
const src = '111\n222\n333\nE\n444\n555\n666\n';
|
||||
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);
|
||||
expect(error.toString())
|
||||
.toEqual(`**ERROR** ("\n222\n333\n[ERROR ->]E\n444\n555\n"): file://@123:456`);
|
||||
});
|
||||
@ -766,7 +766,7 @@ export function main() {
|
||||
function tokenizeWithoutErrors(
|
||||
input: string, tokenizeExpansionForms: boolean = false,
|
||||
interpolationConfig?: InterpolationConfig): lex.Token[] {
|
||||
var tokenizeResult = lex.tokenize(
|
||||
const tokenizeResult = lex.tokenize(
|
||||
input, 'someUrl', getHtmlTagDefinition, tokenizeExpansionForms, interpolationConfig);
|
||||
|
||||
if (tokenizeResult.errors.length > 0) {
|
||||
|
Reference in New Issue
Block a user