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:
Alex Rickabaugh
2020-04-08 10:14:18 -07:00
committed by atscott
parent 0a69a2832b
commit 83a9159063
193 changed files with 5904 additions and 4574 deletions

View File

@ -101,14 +101,17 @@ function expectErrorToken(token: Token, index: any, end: number, message: string
expectNumberToken(tokens[0], 0, 2, 88);
});
it('should tokenize numbers within index ops',
() => { expectNumberToken(lex('a[22]')[2], 2, 4, 22); });
it('should tokenize numbers within index ops', () => {
expectNumberToken(lex('a[22]')[2], 2, 4, 22);
});
it('should tokenize simple quoted strings',
() => { expectStringToken(lex('"a"')[0], 0, 3, 'a'); });
it('should tokenize simple quoted strings', () => {
expectStringToken(lex('"a"')[0], 0, 3, 'a');
});
it('should tokenize quoted strings with escaped quotes',
() => { expectStringToken(lex('"a\\""')[0], 0, 5, 'a"'); });
it('should tokenize quoted strings with escaped quotes', () => {
expectStringToken(lex('"a\\""')[0], 0, 5, 'a"');
});
it('should tokenize a string', () => {
const tokens: Token[] = lex('j-a.bc[22]+1.3|f:\'a\\\'c\':"d\\"e"');
@ -213,7 +216,9 @@ function expectErrorToken(token: Token, index: any, end: number, message: string
expectCharacterToken(tokens[13], 16, 17, ')');
});
it('should tokenize number', () => { expectNumberToken(lex('0.5')[0], 0, 3, 0.5); });
it('should tokenize number', () => {
expectNumberToken(lex('0.5')[0], 0, 3, 0.5);
});
it('should tokenize number with exponent', () => {
let tokens: Token[] = lex('0.5E-10');
@ -233,8 +238,9 @@ function expectErrorToken(token: Token, index: any, end: number, message: string
'Lexer Error: Invalid exponent at column 4 in expression [0.5E-A]');
});
it('should tokenize number starting with a dot',
() => { expectNumberToken(lex('.5')[0], 0, 2, 0.5); });
it('should tokenize number starting with a dot', () => {
expectNumberToken(lex('.5')[0], 0, 2, 0.5);
});
it('should throw error on invalid unicode', () => {
expectErrorToken(
@ -242,11 +248,13 @@ function expectErrorToken(token: Token, index: any, end: number, message: string
'Lexer Error: Invalid unicode escape [\\u1\'\'b] at column 2 in expression [\'\\u1\'\'bla\']');
});
it('should tokenize hash as operator',
() => { expectOperatorToken(lex('#')[0], 0, 1, '#'); });
it('should tokenize hash as operator', () => {
expectOperatorToken(lex('#')[0], 0, 1, '#');
});
it('should tokenize ?. as operator',
() => { expectOperatorToken(lex('?.')[0], 0, 2, '?.'); });
it('should tokenize ?. as operator', () => {
expectOperatorToken(lex('?.')[0], 0, 2, '?.');
});
});
});
}

View File

@ -17,16 +17,22 @@ import {validate} from './utils/validator';
describe('parser', () => {
describe('parseAction', () => {
it('should parse numbers', () => { checkAction('1'); });
it('should parse numbers', () => {
checkAction('1');
});
it('should parse strings', () => {
checkAction('\'1\'', '"1"');
checkAction('"1"');
});
it('should parse null', () => { checkAction('null'); });
it('should parse null', () => {
checkAction('null');
});
it('should parse undefined', () => { checkAction('undefined'); });
it('should parse undefined', () => {
checkAction('undefined');
});
it('should parse unary - expressions', () => {
checkAction('-1', '0 - 1');
@ -47,10 +53,13 @@ describe('parser', () => {
checkAction('a!!!!.b');
});
it('should parse multiplicative expressions',
() => { checkAction('3*4/2%5', '3 * 4 / 2 % 5'); });
it('should parse multiplicative expressions', () => {
checkAction('3*4/2%5', '3 * 4 / 2 % 5');
});
it('should parse additive expressions', () => { checkAction('3 + 6 - 2'); });
it('should parse additive expressions', () => {
checkAction('3 + 6 - 2');
});
it('should parse relational expressions', () => {
checkAction('2 < 3');
@ -74,14 +83,21 @@ describe('parser', () => {
checkAction('true || false');
});
it('should parse grouped expressions', () => { checkAction('(1 + 2) * 3', '1 + 2 * 3'); });
it('should parse grouped expressions', () => {
checkAction('(1 + 2) * 3', '1 + 2 * 3');
});
it('should ignore comments in expressions', () => { checkAction('a //comment', 'a'); });
it('should ignore comments in expressions', () => {
checkAction('a //comment', 'a');
});
it('should retain // in string literals',
() => { checkAction(`"http://www.google.com"`, `"http://www.google.com"`); });
it('should retain // in string literals', () => {
checkAction(`"http://www.google.com"`, `"http://www.google.com"`);
});
it('should parse an empty string', () => { checkAction(''); });
it('should parse an empty string', () => {
checkAction('');
});
describe('literals', () => {
it('should parse array', () => {
@ -133,7 +149,9 @@ describe('parser', () => {
});
describe('functional calls', () => {
it('should parse function calls', () => { checkAction('fn()(1, 2)'); });
it('should parse function calls', () => {
checkAction('fn()(1, 2)');
});
});
describe('conditional', () => {
@ -154,20 +172,26 @@ describe('parser', () => {
checkAction('a = 123; b = 234;');
});
it('should report on safe field assignments',
() => { expectActionError('a?.a = 123', 'cannot be used in the assignment'); });
it('should report on safe field assignments', () => {
expectActionError('a?.a = 123', 'cannot be used in the assignment');
});
it('should support array updates', () => { checkAction('a[0] = 200'); });
it('should support array updates', () => {
checkAction('a[0] = 200');
});
});
it('should error when using pipes',
() => { expectActionError('x|blah', 'Cannot have a pipe'); });
it('should error when using pipes', () => {
expectActionError('x|blah', 'Cannot have a pipe');
});
it('should store the source in the result',
() => { expect(parseAction('someExpr', 'someExpr')); });
it('should store the source in the result', () => {
expect(parseAction('someExpr', 'someExpr'));
});
it('should store the passed-in location',
() => { expect(parseAction('someExpr', 'location').location).toBe('location'); });
it('should store the passed-in location', () => {
expect(parseAction('someExpr', 'location').location).toBe('location');
});
it('should report when encountering interpolation', () => {
expectActionError('{{a()}}', 'Got interpolation ({{}}) where expression was expected');
@ -175,11 +199,13 @@ describe('parser', () => {
});
describe('general error handling', () => {
it('should report an unexpected token',
() => { expectActionError('[1,2] trac', 'Unexpected token \'trac\''); });
it('should report an unexpected token', () => {
expectActionError('[1,2] trac', 'Unexpected token \'trac\'');
});
it('should report reasonable error for unconsumed tokens',
() => { expectActionError(')', 'Unexpected token ) at column 1 in [)]'); });
it('should report reasonable error for unconsumed tokens', () => {
expectActionError(')', 'Unexpected token ) at column 1 in [)]');
});
it('should report a missing expected token', () => {
expectActionError('a(b', 'Missing expected ) at the end of the expression [a(b]');
@ -206,12 +232,17 @@ describe('parser', () => {
expectBindingError('"Foo"|"uppercase"', 'identifier or keyword');
});
it('should parse quoted expressions', () => { checkBinding('a:b', 'a:b'); });
it('should parse quoted expressions', () => {
checkBinding('a:b', 'a:b');
});
it('should not crash when prefix part is not tokenizable',
() => { checkBinding('"a:b"', '"a:b"'); });
it('should not crash when prefix part is not tokenizable', () => {
checkBinding('"a:b"', '"a:b"');
});
it('should ignore whitespace around quote prefix', () => { checkBinding(' a :b', 'a:b'); });
it('should ignore whitespace around quote prefix', () => {
checkBinding(' a :b', 'a:b');
});
it('should refuse prefixes that are not single identifiers', () => {
expectBindingError('a + b:c', '');
@ -219,31 +250,41 @@ describe('parser', () => {
});
});
it('should store the source in the result',
() => { expect(parseBinding('someExpr').source).toBe('someExpr'); });
it('should store the source in the result', () => {
expect(parseBinding('someExpr').source).toBe('someExpr');
});
it('should store the passed-in location',
() => { expect(parseBinding('someExpr', 'location').location).toBe('location'); });
it('should store the passed-in location', () => {
expect(parseBinding('someExpr', 'location').location).toBe('location');
});
it('should report chain expressions',
() => { expectError(parseBinding('1;2'), 'contain chained expression'); });
it('should report chain expressions', () => {
expectError(parseBinding('1;2'), 'contain chained expression');
});
it('should report assignment',
() => { expectError(parseBinding('a=2'), 'contain assignments'); });
it('should report assignment', () => {
expectError(parseBinding('a=2'), 'contain assignments');
});
it('should report when encountering interpolation', () => {
expectBindingError('{{a.b}}', 'Got interpolation ({{}}) where expression was expected');
});
it('should parse conditional expression', () => { checkBinding('a < b ? a : b'); });
it('should parse conditional expression', () => {
checkBinding('a < b ? a : b');
});
it('should ignore comments in bindings', () => { checkBinding('a //comment', 'a'); });
it('should ignore comments in bindings', () => {
checkBinding('a //comment', 'a');
});
it('should retain // in string literals',
() => { checkBinding(`"http://www.google.com"`, `"http://www.google.com"`); });
it('should retain // in : microsyntax', () => { checkBinding('one:a//b', 'one:a//b'); });
it('should retain // in string literals', () => {
checkBinding(`"http://www.google.com"`, `"http://www.google.com"`);
});
it('should retain // in : microsyntax', () => {
checkBinding('one:a//b', 'one:a//b');
});
});
describe('parseTemplateBindings', () => {
@ -555,11 +596,12 @@ describe('parser', () => {
});
describe('parseInterpolation', () => {
it('should return null if no interpolation',
() => { expect(parseInterpolation('nothing')).toBe(null); });
it('should return null if no interpolation', () => {
expect(parseInterpolation('nothing')).toBe(null);
});
it('should parse no prefix/suffix interpolation', () => {
const ast = parseInterpolation('{{a}}') !.ast as Interpolation;
const ast = parseInterpolation('{{a}}')!.ast as Interpolation;
expect(ast.strings).toEqual(['', '']);
expect(ast.expressions.length).toEqual(1);
expect(ast.expressions[0].name).toEqual('a');
@ -567,22 +609,23 @@ describe('parser', () => {
it('should parse prefix/suffix with multiple interpolation', () => {
const originalExp = 'before {{ a }} middle {{ b }} after';
const ast = parseInterpolation(originalExp) !.ast;
const ast = parseInterpolation(originalExp)!.ast;
expect(unparse(ast)).toEqual(originalExp);
validate(ast);
});
it('should report empty interpolation expressions', () => {
expectError(
parseInterpolation('{{}}') !,
'Blank expressions are not allowed in interpolated strings');
parseInterpolation('{{}}')!, 'Blank expressions are not allowed in interpolated strings');
expectError(
parseInterpolation('foo {{ }}') !,
parseInterpolation('foo {{ }}')!,
'Parser Error: Blank expressions are not allowed in interpolated strings');
});
it('should parse conditional expression', () => { checkInterpolation('{{ a < b ? a : b }}'); });
it('should parse conditional expression', () => {
checkInterpolation('{{ a < b ? a : b }}');
});
it('should parse expression with newline characters', () => {
checkInterpolation(`{{ 'foo' +\n 'bar' +\r 'baz' }}`, `{{ "foo" + "bar" + "baz" }}`);
@ -591,15 +634,16 @@ describe('parser', () => {
it('should support custom interpolation', () => {
const parser = new Parser(new Lexer());
const ast =
parser.parseInterpolation('{% a %}', null, 0, {start: '{%', end: '%}'}) !.ast as any;
parser.parseInterpolation('{% a %}', null, 0, {start: '{%', end: '%}'})!.ast as any;
expect(ast.strings).toEqual(['', '']);
expect(ast.expressions.length).toEqual(1);
expect(ast.expressions[0].name).toEqual('a');
});
describe('comments', () => {
it('should ignore comments in interpolation expressions',
() => { checkInterpolation('{{a //comment}}', '{{ a }}'); });
it('should ignore comments in interpolation expressions', () => {
checkInterpolation('{{a //comment}}', '{{ a }}');
});
it('should retain // in single quote strings', () => {
checkInterpolation(`{{ 'http://www.google.com' }}`, `{{ "http://www.google.com" }}`);
@ -609,18 +653,19 @@ describe('parser', () => {
checkInterpolation(`{{ "http://www.google.com" }}`, `{{ "http://www.google.com" }}`);
});
it('should ignore comments after string literals',
() => { checkInterpolation(`{{ "a//b" //comment }}`, `{{ "a//b" }}`); });
it('should ignore comments after string literals', () => {
checkInterpolation(`{{ "a//b" //comment }}`, `{{ "a//b" }}`);
});
it('should retain // in complex strings', () => {
checkInterpolation(
`{{"//a\'//b\`//c\`//d\'//e" //comment}}`, `{{ "//a\'//b\`//c\`//d\'//e" }}`);
});
it('should retain // in nested, unterminated strings',
() => { checkInterpolation(`{{ "a\'b\`" //comment}}`, `{{ "a\'b\`" }}`); });
it('should retain // in nested, unterminated strings', () => {
checkInterpolation(`{{ "a\'b\`" //comment}}`, `{{ "a\'b\`" }}`);
});
});
});
describe('parseSimpleBinding', () => {
@ -670,12 +715,12 @@ describe('parser', () => {
describe('offsets', () => {
it('should retain the offsets of an interpolation', () => {
const interpolations = splitInterpolation('{{a}} {{b}} {{c}}') !;
const interpolations = splitInterpolation('{{a}} {{b}} {{c}}')!;
expect(interpolations.offsets).toEqual([2, 9, 16]);
});
it('should retain the offsets into the expression AST of interpolations', () => {
const source = parseInterpolation('{{a}} {{b}} {{c}}') !;
const source = parseInterpolation('{{a}} {{b}} {{c}}')!;
const interpolation = source.ast as Interpolation;
expect(interpolation.expressions.map(e => e.span.start)).toEqual([2, 9, 16]);
});
@ -722,7 +767,7 @@ function parseSimpleBinding(text: string, location: any = null, offset: number =
}
function checkInterpolation(exp: string, expected?: string) {
const ast = parseInterpolation(exp) !;
const ast = parseInterpolation(exp)!;
if (expected == null) expected = exp;
expect(unparse(ast)).toEqual(expected);
validate(ast);

View File

@ -12,9 +12,9 @@ import {DEFAULT_INTERPOLATION_CONFIG, InterpolationConfig} from '../../../src/ml
class Unparser implements AstVisitor {
private static _quoteRegExp = /"/g;
// TODO(issue/24571): remove '!'.
private _expression !: string;
private _expression!: string;
// TODO(issue/24571): remove '!'.
private _interpolationConfig !: InterpolationConfig;
private _interpolationConfig!: InterpolationConfig;
unparse(ast: AST, interpolationConfig: InterpolationConfig) {
this._expression = '';
@ -69,7 +69,7 @@ class Unparser implements AstVisitor {
}
visitFunctionCall(ast: FunctionCall, context: any) {
this._visit(ast.target !);
this._visit(ast.target!);
this._expression += '(';
let isFirst = true;
ast.args.forEach(arg => {
@ -137,7 +137,7 @@ class Unparser implements AstVisitor {
visitLiteralPrimitive(ast: LiteralPrimitive, context: any) {
if (typeof ast.value === 'string') {
this._expression += `"${ast.value.replace( Unparser._quoteRegExp, '\"')}"`;
this._expression += `"${ast.value.replace(Unparser._quoteRegExp, '\"')}"`;
} else {
this._expression += `${ast.value}`;
}
@ -186,7 +186,9 @@ class Unparser implements AstVisitor {
this._expression += `${ast.prefix}:${ast.uninterpretedExpression}`;
}
private _visit(ast: AST) { ast.visit(this); }
private _visit(ast: AST) {
ast.visit(this);
}
}
const sharedUnparser = new Unparser();

View File

@ -22,8 +22,8 @@ class ASTValidator extends RecursiveAstVisitor {
if (!inSpan(ast.span, this.parentSpan)) {
if (this.parentSpan) {
const parentSpan = this.parentSpan as ParseSpan;
throw Error(
`Invalid AST span [expected (${ast.span.start}, ${ast.span.end}) to be in (${parentSpan.start}, ${parentSpan.end}) for ${unparse(ast)}`);
throw Error(`Invalid AST span [expected (${ast.span.start}, ${ast.span.end}) to be in (${
parentSpan.start}, ${parentSpan.end}) for ${unparse(ast)}`);
} else {
throw Error(`Invalid root AST span for ${unparse(ast)}`);
}
@ -111,7 +111,7 @@ class ASTValidator extends RecursiveAstVisitor {
}
}
function inSpan(span: ParseSpan, parentSpan: ParseSpan | undefined): parentSpan is ParseSpan {
function inSpan(span: ParseSpan, parentSpan: ParseSpan|undefined): parentSpan is ParseSpan {
return !parentSpan || (span.start >= parentSpan.start && span.end <= parentSpan.end);
}