diff --git a/jael/README.md b/jael/README.md index 207cfc67..d9bdcf9f 100644 --- a/jael/README.md +++ b/jael/README.md @@ -33,9 +33,9 @@ void myFunction() { '''; - var buf = new CodeBuffer(); + var buf = CodeBuffer(); var document = jael.parseDocument(template, sourceUrl: 'test.jael', asDSX: false); - var scope = new SymbolTable(values: { + var scope = SymbolTable(values: { 'profile': { 'avatar': 'thosakwe.png', } diff --git a/jael/example/main.dart b/jael/example/main.dart index f78e3c93..4f4e4762 100644 --- a/jael/example/main.dart +++ b/jael/example/main.dart @@ -6,7 +6,7 @@ import 'package:symbol_table/symbol_table.dart'; main() { while (true) { - var buf = new StringBuffer(); + var buf = StringBuffer(); int ch; print('Enter lines of Jael text, terminated by CTRL^D.'); print('All environment variables are injected into the template scope.'); @@ -24,11 +24,11 @@ main() { if (document == null) { stderr.writeln('Could not parse the given text.'); } else { - var output = new CodeBuffer(); + var output = CodeBuffer(); const jael.Renderer().render( document, output, - new SymbolTable(values: Platform.environment), + SymbolTable(values: Platform.environment), strictResolution: false, ); print('GENERATED HTML:\n$output'); diff --git a/jael/lib/src/ast/binary.dart b/jael/lib/src/ast/binary.dart index 222f2d62..75ed2261 100644 --- a/jael/lib/src/ast/binary.dart +++ b/jael/lib/src/ast/binary.dart @@ -37,7 +37,7 @@ class BinaryExpression extends Expression { case TokenType.elvis: return l ?? r; default: - throw new UnsupportedError( + throw UnsupportedError( 'Unsupported binary operator: "${operator?.span?.text ?? ""}".'); } } diff --git a/jael/lib/src/ast/call.dart b/jael/lib/src/ast/call.dart index 75822bf2..0e1272a9 100644 --- a/jael/lib/src/ast/call.dart +++ b/jael/lib/src/ast/call.dart @@ -28,7 +28,7 @@ class Call extends Expression { Map computeNamed(SymbolTable scope) { return namedArguments.fold>({}, (out, a) { - return out..[new Symbol(a.name.name)] = a.value.compute(scope); + return out..[Symbol(a.name.name)] = a.value.compute(scope); }); } diff --git a/jael/lib/src/ast/document.dart b/jael/lib/src/ast/document.dart index e6324f65..b59a371e 100644 --- a/jael/lib/src/ast/document.dart +++ b/jael/lib/src/ast/document.dart @@ -46,8 +46,9 @@ class Doctype extends AstNode { @override FileSpan get span { - if (public == null) + if (public == null) { return lt.span.expand(doctype.span).expand(html.span).expand(gt.span); + } return lt.span .expand(doctype.span) .expand(html.span) diff --git a/jael/lib/src/ast/element.dart b/jael/lib/src/ast/element.dart index a8b8c2a0..bdfb5653 100644 --- a/jael/lib/src/ast/element.dart +++ b/jael/lib/src/ast/element.dart @@ -16,7 +16,7 @@ class TextNode extends ElementChild { } abstract class Element extends ElementChild { - static const List selfClosing = const [ + static const List selfClosing = [ 'include', 'base', 'basefont', diff --git a/jael/lib/src/ast/identifier.dart b/jael/lib/src/ast/identifier.dart index 47e2f76d..e2f8c6fd 100644 --- a/jael/lib/src/ast/identifier.dart +++ b/jael/lib/src/ast/identifier.dart @@ -21,8 +21,7 @@ class Identifier extends Expression { var symbol = scope.resolve(name); if (symbol == null) { if (scope.resolve('!strict!')?.value == false) return null; - throw new ArgumentError( - 'The name "$name" does not exist in this scope.'); + throw ArgumentError('The name "$name" does not exist in this scope.'); } return scope.resolve(name).value; } @@ -43,6 +42,6 @@ class SyntheticIdentifier extends Identifier { @override FileSpan get span { if (id != null) return id.span; - throw new UnsupportedError('Cannot get the span of a SyntheticIdentifier.'); + throw UnsupportedError('Cannot get the span of a SyntheticIdentifier.'); } } diff --git a/jael/lib/src/ast/member.dart b/jael/lib/src/ast/member.dart index 01e996bb..1bac5e50 100644 --- a/jael/lib/src/ast/member.dart +++ b/jael/lib/src/ast/member.dart @@ -16,7 +16,7 @@ class MemberExpression extends Expression { compute(SymbolTable scope) { var target = expression.compute(scope); if (op.span.text == '?.' && target == null) return null; - return reflect(target).getField(new Symbol(name.name)).reflectee; + return reflect(target).getField(Symbol(name.name)).reflectee; } @override diff --git a/jael/lib/src/ast/new.dart b/jael/lib/src/ast/new.dart index d29b1e45..d13892ce 100644 --- a/jael/lib/src/ast/new.dart +++ b/jael/lib/src/ast/new.dart @@ -21,11 +21,12 @@ class NewExpression extends Expression { var named = call.computeNamed(scope); var name = ''; - if (call.target is MemberExpression) + if (call.target is MemberExpression) { name = (call.target as MemberExpression).name.name; + } return reflectClass(targetType as Type) - .newInstance(new Symbol(name), positional, named) + .newInstance(Symbol(name), positional, named) .reflectee; } } diff --git a/jael/lib/src/ast/string.dart b/jael/lib/src/ast/string.dart index 2586c77e..cf7163e3 100644 --- a/jael/lib/src/ast/string.dart +++ b/jael/lib/src/ast/string.dart @@ -14,7 +14,7 @@ class StringLiteral extends Literal { static String parseValue(Token string) { var text = string.span.text.substring(1, string.span.text.length - 1); var codeUnits = text.codeUnits; - var buf = new StringBuffer(); + var buf = StringBuffer(); for (int i = 0; i < codeUnits.length; i++) { var ch = codeUnits[i]; @@ -25,9 +25,9 @@ class StringLiteral extends Literal { c2 = codeUnits[++i], c3 = codeUnits[++i], c4 = codeUnits[++i]; - var hexString = new String.fromCharCodes([c1, c2, c3, c4]); + var hexString = String.fromCharCodes([c1, c2, c3, c4]); var hexNumber = int.parse(hexString, radix: 16); - buf.write(new String.fromCharCode(hexNumber)); + buf.write(String.fromCharCode(hexNumber)); continue; } @@ -53,9 +53,10 @@ class StringLiteral extends Literal { default: buf.writeCharCode(next); } - } else - throw new JaelError(JaelErrorSeverity.error, + } else { + throw JaelError(JaelErrorSeverity.error, 'Unexpected "\\" in string literal.', string.span); + } } else { buf.writeCharCode(ch); } diff --git a/jael/lib/src/formatter.dart b/jael/lib/src/formatter.dart index 6fd319ac..9b62f9e2 100644 --- a/jael/lib/src/formatter.dart +++ b/jael/lib/src/formatter.dart @@ -5,12 +5,12 @@ class JaelFormatter { final num tabSize; final bool insertSpaces; final int maxLineLength; - var _buffer = new StringBuffer(); + var _buffer = StringBuffer(); int _level = 0; String _spaces; static String _spaceString(int tabSize) { - var b = new StringBuffer(); + var b = StringBuffer(); for (int i = 0; i < tabSize; i++) { b.write(' '); } @@ -30,7 +30,9 @@ class JaelFormatter { } void _applySpacing() { - for (int i = 0; i < _level; i++) _buffer.write(_spaces); + for (int i = 0; i < _level; i++) { + _buffer.write(_spaces); + } } int get _spaceLength { @@ -62,9 +64,9 @@ class JaelFormatter { int _formatChild(ElementChild child, int lineLength, {bool isFirst = false, bool isLast = false}) { - if (child == null) + if (child == null) { return lineLength; - else if (child is Element) return _formatElement(child, lineLength); + } else if (child is Element) return _formatElement(child, lineLength); String s; if (child is Interpolation) { var b = StringBuffer('{{'); diff --git a/jael/lib/src/renderer.dart b/jael/lib/src/renderer.dart index 098ffd76..62b36442 100644 --- a/jael/lib/src/renderer.dart +++ b/jael/lib/src/renderer.dart @@ -7,21 +7,21 @@ import 'text/scanner.dart'; /// Parses a Jael document. Document parseDocument(String text, - {sourceUrl, bool asDSX: false, void onError(JaelError error)}) { + {sourceUrl, bool asDSX = false, void onError(JaelError error)}) { var scanner = scan(text, sourceUrl: sourceUrl, asDSX: asDSX); //scanner.tokens.forEach(print); - if (scanner.errors.isNotEmpty && onError != null) + if (scanner.errors.isNotEmpty && onError != null) { scanner.errors.forEach(onError); - else if (scanner.errors.isNotEmpty) throw scanner.errors.first; + } else if (scanner.errors.isNotEmpty) throw scanner.errors.first; - var parser = new Parser(scanner, asDSX: asDSX); + var parser = Parser(scanner, asDSX: asDSX); var doc = parser.parseDocument(); - if (parser.errors.isNotEmpty && onError != null) + if (parser.errors.isNotEmpty && onError != null) { parser.errors.forEach(onError); - else if (parser.errors.isNotEmpty) throw parser.errors.first; + } else if (parser.errors.isNotEmpty) throw parser.errors.first; return doc; } @@ -80,7 +80,7 @@ class Renderer { /// If [strictResolution] is `false` (default: `true`), then undefined identifiers will return `null` /// instead of throwing. void render(Document document, CodeBuffer buffer, SymbolTable scope, - {bool strictResolution: true}) { + {bool strictResolution = true}) { scope.create('!strict!', value: strictResolution != false); if (document.doctype != null) buffer.writeln(document.doctype.span.text); @@ -126,17 +126,18 @@ class Renderer { buffer.write(' ${attribute.name}'); - if (value == true) + if (value == true) { continue; - else + } else { buffer.write('="'); + } String msg; if (value is Iterable) { msg = value.join(' '); } else if (value is Map) { - msg = value.keys.fold(new StringBuffer(), (buf, k) { + msg = value.keys.fold(StringBuffer(), (buf, k) { var v = value[k]; if (v == null) return buf; return buf..write('$k: $v;'); @@ -150,10 +151,11 @@ class Renderer { } if (element is SelfClosingElement) { - if (html5) + if (html5) { buffer.writeln('>'); - else + } else { buffer.writeln('/>'); + } } else { buffer.writeln('>'); buffer.indent(); @@ -185,11 +187,11 @@ class Renderer { (a) => a.name != 'for-each' && a.name != 'as' && a.name != 'index-as'); Element strippedElement; - if (element is SelfClosingElement) - strippedElement = new SelfClosingElement(element.lt, element.tagName, + if (element is SelfClosingElement) { + strippedElement = SelfClosingElement(element.lt, element.tagName, otherAttributes, element.slash, element.gt); - else if (element is RegularElement) - strippedElement = new RegularElement( + } else if (element is RegularElement) { + strippedElement = RegularElement( element.lt, element.tagName, otherAttributes, @@ -199,6 +201,7 @@ class Renderer { element.slash, element.tagName2, element.gt2); + } int i = 0; for (var item in attribute.value.compute(scope)) { @@ -224,11 +227,11 @@ class Renderer { var otherAttributes = element.attributes.where((a) => a.name != 'if'); Element strippedElement; - if (element is SelfClosingElement) - strippedElement = new SelfClosingElement(element.lt, element.tagName, + if (element is SelfClosingElement) { + strippedElement = SelfClosingElement(element.lt, element.tagName, otherAttributes, element.slash, element.gt); - else if (element is RegularElement) - strippedElement = new RegularElement( + } else if (element is RegularElement) { + strippedElement = RegularElement( element.lt, element.tagName, otherAttributes, @@ -238,6 +241,7 @@ class Renderer { element.slash, element.tagName2, element.gt2); + } renderElement(strippedElement, buffer, scope, html5); } @@ -298,20 +302,22 @@ class Renderer { void renderElementChild(Element parent, ElementChild child, CodeBuffer buffer, SymbolTable scope, bool html5, int index, int total) { if (child is Text && parent?.tagName?.name != 'textarea') { - if (index == 0) + if (index == 0) { buffer.write(child.span.text.trimLeft()); - else if (index == total - 1) + } else if (index == total - 1) { buffer.write(child.span.text.trimRight()); - else + } else { buffer.write(child.span.text); + } } else if (child is Interpolation) { var value = child.expression.compute(scope); if (value != null) { - if (child.isRaw) + if (child.isRaw) { buffer.write(value); - else + } else { buffer.write(htmlEscape.convert(value.toString())); + } } } else if (child is Element) { if (buffer?.lastLine?.text?.isNotEmpty == true) buffer.writeln(); @@ -324,14 +330,14 @@ class Renderer { void registerCustomElement( Element element, CodeBuffer buffer, SymbolTable scope, bool html5) { if (element is! RegularElement) { - throw new JaelError(JaelErrorSeverity.error, + throw JaelError(JaelErrorSeverity.error, "Custom elements cannot be self-closing.", element.span); } var name = element.getAttribute('name')?.value?.compute(scope)?.toString(); if (name == null) { - throw new JaelError( + throw JaelError( JaelErrorSeverity.error, "Attribute 'name' is required when registering a custom element.", element.tagName.span); @@ -341,7 +347,7 @@ class Renderer { var p = scope.isRoot ? scope : scope.parent; p.create(customElementName(name), value: element, constant: true); } on StateError { - throw new JaelError( + throw JaelError( JaelErrorSeverity.error, "Cannot re-define element '$name' in this scope.", element.getAttribute('name').span); @@ -371,16 +377,16 @@ class Renderer { } else { var tagName = renderAs?.toString() ?? 'div'; - var syntheticElement = new RegularElement( + var syntheticElement = RegularElement( template.lt, - new SyntheticIdentifier(tagName), + SyntheticIdentifier(tagName), element.attributes .where((a) => a.name != 'as' && !a.name.startsWith('@')), template.gt, template.children, template.lt2, template.slash, - new SyntheticIdentifier(tagName), + SyntheticIdentifier(tagName), template.gt2); renderElement(syntheticElement, buffer, scope, html5); diff --git a/jael/lib/src/text/parselet/infix.dart b/jael/lib/src/text/parselet/infix.dart index 56f18842..9c52e6af 100644 --- a/jael/lib/src/text/parselet/infix.dart +++ b/jael/lib/src/text/parselet/infix.dart @@ -1,24 +1,24 @@ part of jael.src.text.parselet; -const Map infixParselets = const { - TokenType.lParen: const CallParselet(), - TokenType.elvis_dot: const MemberParselet(), - TokenType.dot: const MemberParselet(), - TokenType.lBracket: const IndexerParselet(), - TokenType.asterisk: const BinaryParselet(14), - TokenType.slash: const BinaryParselet(14), - TokenType.percent: const BinaryParselet(14), - TokenType.plus: const BinaryParselet(13), - TokenType.minus: const BinaryParselet(13), - TokenType.lt: const BinaryParselet(11), - TokenType.lte: const BinaryParselet(11), - TokenType.gt: const BinaryParselet(11), - TokenType.gte: const BinaryParselet(11), - TokenType.equ: const BinaryParselet(10), - TokenType.nequ: const BinaryParselet(10), - TokenType.question: const ConditionalParselet(), - TokenType.equals: const BinaryParselet(3), - TokenType.elvis: const BinaryParselet(3), +const Map infixParselets = { + TokenType.lParen: CallParselet(), + TokenType.elvis_dot: MemberParselet(), + TokenType.dot: MemberParselet(), + TokenType.lBracket: IndexerParselet(), + TokenType.asterisk: BinaryParselet(14), + TokenType.slash: BinaryParselet(14), + TokenType.percent: BinaryParselet(14), + TokenType.plus: BinaryParselet(13), + TokenType.minus: BinaryParselet(13), + TokenType.lt: BinaryParselet(11), + TokenType.lte: BinaryParselet(11), + TokenType.gt: BinaryParselet(11), + TokenType.gte: BinaryParselet(11), + TokenType.equ: BinaryParselet(10), + TokenType.nequ: BinaryParselet(10), + TokenType.question: ConditionalParselet(), + TokenType.equals: BinaryParselet(3), + TokenType.elvis: BinaryParselet(3), }; class ConditionalParselet implements InfixParselet { @@ -32,13 +32,13 @@ class ConditionalParselet implements InfixParselet { var ifTrue = parser.parseExpression(0); if (ifTrue == null) { - parser.errors.add(new JaelError(JaelErrorSeverity.error, + parser.errors.add(JaelError(JaelErrorSeverity.error, 'Missing expression in conditional expression.', token.span)); return null; } if (!parser.next(TokenType.colon)) { - parser.errors.add(new JaelError(JaelErrorSeverity.error, + parser.errors.add(JaelError(JaelErrorSeverity.error, 'Missing ":" in conditional expression.', ifTrue.span)); return null; } @@ -47,12 +47,12 @@ class ConditionalParselet implements InfixParselet { var ifFalse = parser.parseExpression(0); if (ifFalse == null) { - parser.errors.add(new JaelError(JaelErrorSeverity.error, + parser.errors.add(JaelError(JaelErrorSeverity.error, 'Missing expression in conditional expression.', colon.span)); return null; } - return new Conditional(left, token, ifTrue, colon, ifFalse); + return Conditional(left, token, ifTrue, colon, ifFalse); } } @@ -66,15 +66,16 @@ class BinaryParselet implements InfixParselet { var right = parser.parseExpression(precedence); if (right == null) { - if (token.type != TokenType.gt) - parser.errors.add(new JaelError( + if (token.type != TokenType.gt) { + parser.errors.add(JaelError( JaelErrorSeverity.error, 'Missing expression after operator "${token.span.text}", following expression ${left.span.text}.', token.span)); + } return null; } - return new BinaryExpression(left, token, right); + return BinaryExpression(left, token, right); } } @@ -109,12 +110,12 @@ class CallParselet implements InfixParselet { if (!parser.next(TokenType.rParen)) { var lastSpan = arguments.isEmpty ? null : arguments.last.span; lastSpan ??= token.span; - parser.errors.add(new JaelError(JaelErrorSeverity.error, + parser.errors.add(JaelError(JaelErrorSeverity.error, 'Missing ")" after argument list.', lastSpan)); return null; } - return new Call(left, token, parser.current, arguments, namedArguments); + return Call(left, token, parser.current, arguments, namedArguments); } } @@ -129,18 +130,18 @@ class IndexerParselet implements InfixParselet { var indexer = parser.parseExpression(0); if (indexer == null) { - parser.errors.add(new JaelError( + parser.errors.add(JaelError( JaelErrorSeverity.error, 'Missing expression after "[".', left.span)); return null; } if (!parser.next(TokenType.rBracket)) { parser.errors.add( - new JaelError(JaelErrorSeverity.error, 'Missing "]".', indexer.span)); + JaelError(JaelErrorSeverity.error, 'Missing "]".', indexer.span)); return null; } - return new IndexerExpression(left, token, indexer, parser.current); + return IndexerExpression(left, token, indexer, parser.current); } } @@ -155,11 +156,11 @@ class MemberParselet implements InfixParselet { var name = parser.parseIdentifier(); if (name == null) { - parser.errors.add(new JaelError(JaelErrorSeverity.error, + parser.errors.add(JaelError(JaelErrorSeverity.error, 'Expected the name of a property following "."', token.span)); return null; } - return new MemberExpression(left, token, name); + return MemberExpression(left, token, name); } } diff --git a/jael/lib/src/text/parselet/prefix.dart b/jael/lib/src/text/parselet/prefix.dart index 0dfb0bc8..cea9bb49 100644 --- a/jael/lib/src/text/parselet/prefix.dart +++ b/jael/lib/src/text/parselet/prefix.dart @@ -1,15 +1,15 @@ part of jael.src.text.parselet; -const Map prefixParselets = const { - TokenType.exclamation: const NotParselet(), - TokenType.$new: const NewParselet(), - TokenType.number: const NumberParselet(), - TokenType.hex: const HexParselet(), - TokenType.string: const StringParselet(), - TokenType.lCurly: const MapParselet(), - TokenType.lBracket: const ArrayParselet(), - TokenType.id: const IdentifierParselet(), - TokenType.lParen: const ParenthesisParselet(), +const Map prefixParselets = { + TokenType.exclamation: NotParselet(), + TokenType.$new: NewParselet(), + TokenType.number: NumberParselet(), + TokenType.hex: HexParselet(), + TokenType.string: StringParselet(), + TokenType.lCurly: MapParselet(), + TokenType.lBracket: ArrayParselet(), + TokenType.id: IdentifierParselet(), + TokenType.lParen: ParenthesisParselet(), }; class NotParselet implements PrefixParselet { @@ -20,11 +20,11 @@ class NotParselet implements PrefixParselet { var expression = parser.parseExpression(0); if (expression == null) { - parser.errors.add(new JaelError(JaelErrorSeverity.error, + parser.errors.add(JaelError(JaelErrorSeverity.error, 'Missing expression after "!" in negation expression.', token.span)); } - return new Negation(token, expression); + return Negation(token, expression); } } @@ -36,15 +36,15 @@ class NewParselet implements PrefixParselet { var call = parser.parseExpression(0); if (call == null) { - parser.errors.add(new JaelError( + parser.errors.add(JaelError( JaelErrorSeverity.error, '"new" must precede a call expression. Nothing was found.', call.span)); return null; } else if (call is Call) { - return new NewExpression(token, call); + return NewExpression(token, call); } else { - parser.errors.add(new JaelError( + parser.errors.add(JaelError( JaelErrorSeverity.error, '"new" must precede a call expression, not a(n) ${call.runtimeType}.', call.span)); @@ -57,14 +57,14 @@ class NumberParselet implements PrefixParselet { const NumberParselet(); @override - Expression parse(Parser parser, Token token) => new NumberLiteral(token); + Expression parse(Parser parser, Token token) => NumberLiteral(token); } class HexParselet implements PrefixParselet { const HexParselet(); @override - Expression parse(Parser parser, Token token) => new HexLiteral(token); + Expression parse(Parser parser, Token token) => HexLiteral(token); } class StringParselet implements PrefixParselet { @@ -72,7 +72,7 @@ class StringParselet implements PrefixParselet { @override Expression parse(Parser parser, Token token) => - new StringLiteral(token, StringLiteral.parseValue(token)); + StringLiteral(token, StringLiteral.parseValue(token)); } class ArrayParselet implements PrefixParselet { @@ -93,12 +93,12 @@ class ArrayParselet implements PrefixParselet { if (!parser.next(TokenType.rBracket)) { var lastSpan = items.isEmpty ? null : items.last.span; lastSpan ??= token.span; - parser.errors.add(new JaelError(JaelErrorSeverity.error, + parser.errors.add(JaelError(JaelErrorSeverity.error, 'Missing "]" to terminate array literal.', lastSpan)); return null; } - return new Array(token, parser.current, items); + return Array(token, parser.current, items); } } @@ -119,12 +119,12 @@ class MapParselet implements PrefixParselet { if (!parser.next(TokenType.rCurly)) { var lastSpan = pairs.isEmpty ? token.span : pairs.last.span; - parser.errors.add(new JaelError( + parser.errors.add(JaelError( JaelErrorSeverity.error, 'Missing "}" in map literal.', lastSpan)); return null; } - return new MapLiteral(token, pairs, parser.current); + return MapLiteral(token, pairs, parser.current); } } @@ -132,7 +132,7 @@ class IdentifierParselet implements PrefixParselet { const IdentifierParselet(); @override - Expression parse(Parser parser, Token token) => new Identifier(token); + Expression parse(Parser parser, Token token) => Identifier(token); } class ParenthesisParselet implements PrefixParselet { @@ -143,14 +143,14 @@ class ParenthesisParselet implements PrefixParselet { var expression = parser.parseExpression(0); if (expression == null) { - parser.errors.add(new JaelError(JaelErrorSeverity.error, + parser.errors.add(JaelError(JaelErrorSeverity.error, 'Missing expression after "(".', token.span)); return null; } if (!parser.next(TokenType.rParen)) { - parser.errors.add(new JaelError( - JaelErrorSeverity.error, 'Missing ")".', expression.span)); + parser.errors.add( + JaelError(JaelErrorSeverity.error, 'Missing ")".', expression.span)); return null; } diff --git a/jael/lib/src/text/parser.dart b/jael/lib/src/text/parser.dart index 1b127985..9225726f 100644 --- a/jael/lib/src/text/parser.dart +++ b/jael/lib/src/text/parser.dart @@ -10,7 +10,7 @@ class Parser { Token _current; int _index = -1; - Parser(this.scanner, {this.asDSX: false}); + Parser(this.scanner, {this.asDSX = false}); Token get current => _current; @@ -52,18 +52,18 @@ class Parser { if (doctype == null) { var root = parseElement(); if (root == null) return null; - return new Document(null, root); + return Document(null, root); } var root = parseElement(); if (root == null) { - errors.add(new JaelError(JaelErrorSeverity.error, + errors.add(JaelError(JaelErrorSeverity.error, 'Missing root element after !DOCTYPE declaration.', doctype.span)); return null; } - return new Document(doctype, root); + return Document(doctype, root); } StringLiteral implicitString() { @@ -88,7 +88,7 @@ class Parser { } var doctype = _current, html = parseIdentifier(); if (html?.span?.text?.toLowerCase() != 'html') { - errors.add(new JaelError( + errors.add(JaelError( JaelErrorSeverity.error, 'Expected "html" in doctype declaration.', html?.span ?? doctype.span)); @@ -98,16 +98,16 @@ class Parser { var public = parseIdentifier(); if (public == null) { if (!next(TokenType.gt)) { - errors.add(new JaelError(JaelErrorSeverity.error, + errors.add(JaelError(JaelErrorSeverity.error, 'Expected ">" in doctype declaration.', html.span)); return null; } - return new Doctype(lt, doctype, html, null, null, null, _current); + return Doctype(lt, doctype, html, null, null, null, _current); } if (public?.span?.text?.toLowerCase() != 'public') { - errors.add(new JaelError( + errors.add(JaelError( JaelErrorSeverity.error, 'Expected "public" in doctype declaration.', public?.span ?? html.span)); @@ -117,7 +117,7 @@ class Parser { var stringParser = prefixParselets[TokenType.string]; if (!next(TokenType.string)) { - errors.add(new JaelError(JaelErrorSeverity.error, + errors.add(JaelError(JaelErrorSeverity.error, 'Expected string in doctype declaration.', public.span)); return null; } @@ -125,7 +125,7 @@ class Parser { var name = stringParser.parse(this, _current) as StringLiteral; if (!next(TokenType.string)) { - errors.add(new JaelError(JaelErrorSeverity.error, + errors.add(JaelError(JaelErrorSeverity.error, 'Expected string in doctype declaration.', name.span)); return null; } @@ -133,12 +133,12 @@ class Parser { var url = stringParser.parse(this, _current) as StringLiteral; if (!next(TokenType.gt)) { - errors.add(new JaelError(JaelErrorSeverity.error, + errors.add(JaelError(JaelErrorSeverity.error, 'Expected ">" in doctype declaration.', url.span)); return null; } - return new Doctype(lt, doctype, html, public, name, url, _current); + return Doctype(lt, doctype, html, public, name, url, _current); } ElementChild parseElementChild() => @@ -148,9 +148,9 @@ class Parser { parseElement(); HtmlComment parseHtmlComment() => - next(TokenType.htmlComment) ? new HtmlComment(_current) : null; + next(TokenType.htmlComment) ? HtmlComment(_current) : null; - Text parseText() => next(TokenType.text) ? new Text(_current) : null; + Text parseText() => next(TokenType.text) ? Text(_current) : null; Interpolation parseInterpolation() { if (!next(asDSX ? TokenType.lCurly : TokenType.lDoubleCurly)) return null; @@ -159,19 +159,19 @@ class Parser { var expression = parseExpression(0); if (expression == null) { - errors.add(new JaelError(JaelErrorSeverity.error, + errors.add(JaelError(JaelErrorSeverity.error, 'Missing expression in interpolation.', doubleCurlyL.span)); return null; } if (!next(asDSX ? TokenType.rCurly : TokenType.rDoubleCurly)) { var expected = asDSX ? '}' : '}}'; - errors.add(new JaelError(JaelErrorSeverity.error, + errors.add(JaelError(JaelErrorSeverity.error, 'Missing closing "$expected" in interpolation.', expression.span)); return null; } - return new Interpolation(doubleCurlyL, expression, _current); + return Interpolation(doubleCurlyL, expression, _current); } Element parseElement() { @@ -188,7 +188,7 @@ class Parser { if (tagName == null) { errors.add( - new JaelError(JaelErrorSeverity.error, 'Missing tag name.', lt.span)); + JaelError(JaelErrorSeverity.error, 'Missing tag name.', lt.span)); return null; } @@ -205,16 +205,16 @@ class Parser { var slash = _current; if (!next(TokenType.gt)) { - errors.add(new JaelError(JaelErrorSeverity.error, + errors.add(JaelError(JaelErrorSeverity.error, 'Missing ">" in self-closing "${tagName.name}" tag.', slash.span)); return null; } - return new SelfClosingElement(lt, tagName, attributes, slash, _current); + return SelfClosingElement(lt, tagName, attributes, slash, _current); } if (!next(TokenType.gt)) { - errors.add(new JaelError( + errors.add(JaelError( JaelErrorSeverity.error, 'Missing ">" in "${tagName.name}" tag.', attributes.isEmpty ? tagName.span : attributes.last.span)); @@ -225,7 +225,7 @@ class Parser { // Implicit self-closing if (Element.selfClosing.contains(tagName.name)) { - return new SelfClosingElement(lt, tagName, attributes, null, gt); + return SelfClosingElement(lt, tagName, attributes, null, gt); } List children = []; @@ -239,7 +239,7 @@ class Parser { // Parse closing tag if (!next(TokenType.lt)) { - errors.add(new JaelError( + errors.add(JaelError( JaelErrorSeverity.error, 'Missing closing tag for "${tagName.name}" tag.', children.isEmpty ? tagName.span : children.last.span)); @@ -249,7 +249,7 @@ class Parser { var lt2 = _current; if (!next(TokenType.slash)) { - errors.add(new JaelError(JaelErrorSeverity.error, + errors.add(JaelError(JaelErrorSeverity.error, 'Missing "/" in "${tagName.name}" closing tag.', lt2.span)); return null; } @@ -257,7 +257,7 @@ class Parser { var slash = _current, tagName2 = parseIdentifier(); if (tagName2 == null) { - errors.add(new JaelError( + errors.add(JaelError( JaelErrorSeverity.error, 'Missing "${tagName.name}" in "${tagName.name}" closing tag.', slash.span)); @@ -265,7 +265,7 @@ class Parser { } if (tagName2.name != tagName.name) { - errors.add(new JaelError( + errors.add(JaelError( JaelErrorSeverity.error, 'Mismatched closing tags. Expected "${tagName.span.text}"; got "${tagName2.name}" instead.', lt2.span)); @@ -273,12 +273,12 @@ class Parser { } if (!next(TokenType.gt)) { - errors.add(new JaelError(JaelErrorSeverity.error, + errors.add(JaelError(JaelErrorSeverity.error, 'Missing ">" in "${tagName.name}" closing tag.', tagName2.span)); return null; } - return new RegularElement( + return RegularElement( lt, tagName, attributes, gt, children, lt2, slash, tagName2, _current); } @@ -289,7 +289,7 @@ class Parser { if ((id = parseIdentifier()) != null) { // Nothing } else if (next(TokenType.string)) { - string = new StringLiteral(_current, StringLiteral.parseValue(_current)); + string = StringLiteral(_current, StringLiteral.parseValue(_current)); } else { return null; } @@ -301,35 +301,34 @@ class Parser { } else if (!asDSX && next(TokenType.nequ)) { nequ = _current; } else { - return new Attribute(id, string, null, null, null); + return Attribute(id, string, null, null, null); } if (!asDSX) { var value = parseExpression(0); if (value == null) { - errors.add(new JaelError(JaelErrorSeverity.error, + errors.add(JaelError(JaelErrorSeverity.error, 'Missing expression in attribute.', equals?.span ?? nequ.span)); return null; } - return new Attribute(id, string, equals, nequ, value); + return Attribute(id, string, equals, nequ, value); } else { // Find either a string, or an interpolation. var value = implicitString(); if (value != null) { - return new Attribute(id, string, equals, nequ, value); + return Attribute(id, string, equals, nequ, value); } var interpolation = parseInterpolation(); if (interpolation != null) { - return new Attribute( - id, string, equals, nequ, interpolation.expression); + return Attribute(id, string, equals, nequ, interpolation.expression); } - errors.add(new JaelError(JaelErrorSeverity.error, + errors.add(JaelError(JaelErrorSeverity.error, 'Missing expression in attribute.', equals?.span ?? nequ.span)); return null; } @@ -374,23 +373,23 @@ class Parser { } Identifier parseIdentifier() => - next(TokenType.id) ? new Identifier(_current) : null; + next(TokenType.id) ? Identifier(_current) : null; KeyValuePair parseKeyValuePair() { var key = parseExpression(0); if (key == null) return null; - if (!next(TokenType.colon)) return new KeyValuePair(key, null, null); + if (!next(TokenType.colon)) return KeyValuePair(key, null, null); var colon = _current, value = parseExpression(0); if (value == null) { - errors.add(new JaelError(JaelErrorSeverity.error, + errors.add(JaelError(JaelErrorSeverity.error, 'Missing expression in key-value pair.', colon.span)); return null; } - return new KeyValuePair(key, colon, value); + return KeyValuePair(key, colon, value); } NamedArgument parseNamedArgument() { @@ -398,7 +397,7 @@ class Parser { if (name == null) return null; if (!next(TokenType.colon)) { - errors.add(new JaelError(JaelErrorSeverity.error, + errors.add(JaelError(JaelErrorSeverity.error, 'Missing ":" in named argument.', name.span)); return null; } @@ -406,11 +405,11 @@ class Parser { var colon = _current, value = parseExpression(0); if (value == null) { - errors.add(new JaelError(JaelErrorSeverity.error, + errors.add(JaelError(JaelErrorSeverity.error, 'Missing expression in named argument.', colon.span)); return null; } - return new NamedArgument(name, colon, value); + return NamedArgument(name, colon, value); } } diff --git a/jael/lib/src/text/scanner.dart b/jael/lib/src/text/scanner.dart index f1beabc6..964368ae 100644 --- a/jael/lib/src/text/scanner.dart +++ b/jael/lib/src/text/scanner.dart @@ -3,17 +3,17 @@ import 'package:charcode/ascii.dart'; import 'package:string_scanner/string_scanner.dart'; import '../ast/ast.dart'; -final RegExp _whitespace = new RegExp(r'[ \n\r\t]+'); +final RegExp _whitespace = RegExp(r'[ \n\r\t]+'); final RegExp _id = - new RegExp(r'@?(([A-Za-z][A-Za-z0-9_]*-)*([A-Za-z][A-Za-z0-9_]*))'); -final RegExp _string1 = new RegExp( + RegExp(r'@?(([A-Za-z][A-Za-z0-9_]*-)*([A-Za-z][A-Za-z0-9_]*))'); +final RegExp _string1 = RegExp( r"'((\\(['\\/bfnrt]|(u[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])))|([^'\\]))*'"); -final RegExp _string2 = new RegExp( +final RegExp _string2 = RegExp( r'"((\\(["\\/bfnrt]|(u[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])))|([^"\\]))*"'); -Scanner scan(String text, {sourceUrl, bool asDSX: false}) => - new _Scanner(text, sourceUrl)..scan(asDSX: asDSX); +Scanner scan(String text, {sourceUrl, bool asDSX = false}) => + _Scanner(text, sourceUrl)..scan(asDSX: asDSX); abstract class Scanner { List get errors; @@ -21,7 +21,7 @@ abstract class Scanner { List get tokens; } -final RegExp _htmlComment = new RegExp(r''); +final RegExp _htmlComment = RegExp(r''); final Map _expressionPatterns = { //final Map _htmlPatterns = { @@ -74,8 +74,8 @@ final Map _expressionPatterns = { '==': TokenType.equ, '!=': TokenType.nequ, '=': TokenType.equals, - new RegExp(r'-?[0-9]+(\.[0-9]+)?([Ee][0-9]+)?'): TokenType.number, - new RegExp(r'0x[A-Fa-f0-9]+'): TokenType.hex, + RegExp(r'-?[0-9]+(\.[0-9]+)?([Ee][0-9]+)?'): TokenType.number, + RegExp(r'0x[A-Fa-f0-9]+'): TokenType.hex, _string1: TokenType.string, _string2: TokenType.string, _id: TokenType.id, @@ -85,15 +85,15 @@ class _Scanner implements Scanner { final List errors = []; final List tokens = []; _ScannerState state = _ScannerState.html; - final Queue openTags = new Queue(); + final Queue openTags = Queue(); SpanScanner _scanner; _Scanner(String text, sourceUrl) { - _scanner = new SpanScanner(text, sourceUrl: sourceUrl); + _scanner = SpanScanner(text, sourceUrl: sourceUrl); } - void scan({bool asDSX: false}) { + void scan({bool asDSX = false}) { while (!_scanner.isDone) { if (state == _ScannerState.html) { scanHtml(asDSX); @@ -164,14 +164,15 @@ class _Scanner implements Scanner { var span = _scanner.spanFrom(start, end); - if (span.text.isNotEmpty) - tokens.add(new Token(TokenType.text, span, null)); + if (span.text.isNotEmpty) { + tokens.add(Token(TokenType.text, span, null)); + } } } } void scanHtml(bool asDSX) { - var brackets = new Queue(); + var brackets = Queue(); do { // Only continue if we find a left bracket @@ -184,9 +185,9 @@ class _Scanner implements Scanner { _scanner.scan(_whitespace); _expressionPatterns.forEach((pattern, type) { - if (_scanner.matches(pattern)) - potential - .add(new Token(type, _scanner.lastSpan, _scanner.lastMatch)); + if (_scanner.matches(pattern)) { + potential.add(Token(type, _scanner.lastSpan, _scanner.lastMatch)); + } }); potential.sort((a, b) => b.span.length.compareTo(a.span.length)); diff --git a/jael/test/render/custom_element_test.dart b/jael/test/render/custom_element_test.dart index 2546b34f..303c1627 100644 --- a/jael/test/render/custom_element_test.dart +++ b/jael/test/render/custom_element_test.dart @@ -107,7 +107,7 @@ void main() { String render(String template, [Map values]) { var doc = jael.parseDocument(template, onError: (e) => throw e); - var buffer = new CodeBuffer(); - const jael.Renderer().render(doc, buffer, new SymbolTable(values: values)); + var buffer = CodeBuffer(); + const jael.Renderer().render(doc, buffer, SymbolTable(values: values)); return buffer.toString(); } diff --git a/jael/test/render/dsx_test.dart b/jael/test/render/dsx_test.dart index 87925998..8c47ed7f 100644 --- a/jael/test/render/dsx_test.dart +++ b/jael/test/render/dsx_test.dart @@ -18,7 +18,7 @@ void main() { foo .getAttribute('yes') .value - .compute(new SymbolTable(values: {'no': 'maybe'})), + .compute(SymbolTable(values: {'no': 'maybe'})), 'maybe'); }); diff --git a/jael/test/render/render_test.dart b/jael/test/render/render_test.dart index 7df8fea2..b9a60e07 100644 --- a/jael/test/render/render_test.dart +++ b/jael/test/render/render_test.dart @@ -15,13 +15,13 @@ main() { '''; - var buf = new CodeBuffer(); + var buf = CodeBuffer(); jael.Document document; SymbolTable scope; try { document = jael.parseDocument(template, sourceUrl: 'test.jael'); - scope = new SymbolTable(values: { + scope = SymbolTable(values: { 'csrf_token': 'foo', 'profile': { 'avatar': 'thosakwe.png', @@ -64,10 +64,10 @@ main() { '''; - var buf = new CodeBuffer(); + var buf = CodeBuffer(); //jael.scan(template, sourceUrl: 'test.jael').tokens.forEach(print); var document = jael.parseDocument(template, sourceUrl: 'test.jael'); - var scope = new SymbolTable(values: { + var scope = SymbolTable(values: { 'pokemon': const _Pokemon('Darkrai', 'Dark'), }); @@ -105,9 +105,9 @@ main() { '''; - var buf = new CodeBuffer(); + var buf = CodeBuffer(); var document = jael.parseDocument(template, sourceUrl: 'test.jael'); - var scope = new SymbolTable(values: { + var scope = SymbolTable(values: { 'starters': starters, }); @@ -150,9 +150,9 @@ main() { '''; - var buf = new CodeBuffer(); + var buf = CodeBuffer(); var document = jael.parseDocument(template, sourceUrl: 'test.jael'); - var scope = new SymbolTable(values: { + var scope = SymbolTable(values: { 'starters': starters, }); @@ -196,9 +196,9 @@ main() { '''; - var buf = new CodeBuffer(); + var buf = CodeBuffer(); var document = jael.parseDocument(template, sourceUrl: 'test.jael'); - var scope = new SymbolTable(); + var scope = SymbolTable(); const jael.Renderer().render(document, buf, scope); print(buf); @@ -242,9 +242,9 @@ main() { '''; - var buf = new CodeBuffer(); + var buf = CodeBuffer(); var document = jael.parseDocument(template, sourceUrl: 'test.jael'); - var scope = new SymbolTable(); + var scope = SymbolTable(); const jael.Renderer().render(document, buf, scope); print(buf); @@ -267,9 +267,9 @@ main() { '''; - var buf = new CodeBuffer(); + var buf = CodeBuffer(); var document = jael.parseDocument(template, sourceUrl: 'test.jael'); - var scope = new SymbolTable(); + var scope = SymbolTable(); const jael.Renderer().render(document, buf, scope); print(buf); @@ -298,10 +298,10 @@ main() { '''; - var buf = new CodeBuffer(); + var buf = CodeBuffer(); var document = jael.parseDocument(template, sourceUrl: 'test.jael'); - var scope = new SymbolTable(values: { - 'account': new _Account(isDisabled: true), + var scope = SymbolTable(values: { + 'account': _Account(isDisabled: true), }); const jael.Renderer().render(document, buf, scope); @@ -325,10 +325,10 @@ main() { '''; - var buf = new CodeBuffer(); + var buf = CodeBuffer(); var document = jael.parseDocument(template, sourceUrl: 'test.jael'); - var scope = new SymbolTable(values: { - 'account': new _Account(isDisabled: null), + var scope = SymbolTable(values: { + 'account': _Account(isDisabled: null), }); const jael.Renderer().render(document, buf, scope); @@ -338,10 +338,10 @@ main() { }); } -const List<_Pokemon> starters = const [ - const _Pokemon('Bulbasaur', 'Grass'), - const _Pokemon('Charmander', 'Fire'), - const _Pokemon('Squirtle', 'Water'), +const List<_Pokemon> starters = [ + _Pokemon('Bulbasaur', 'Grass'), + _Pokemon('Charmander', 'Fire'), + _Pokemon('Squirtle', 'Water'), ]; class _Pokemon { diff --git a/jael/test/text/common.dart b/jael/test/text/common.dart index 7d7108f4..5fb71587 100644 --- a/jael/test/text/common.dart +++ b/jael/test/text/common.dart @@ -1,7 +1,7 @@ import 'package:matcher/matcher.dart'; import 'package:jael/src/ast/token.dart'; -Matcher isToken(TokenType type, [String text]) => new _IsToken(type, text); +Matcher isToken(TokenType type, [String text]) => _IsToken(type, text); class _IsToken extends Matcher { final TokenType type; diff --git a/jael_web/example/stateful.dart b/jael_web/example/stateful.dart index f2190320..617c7bd2 100644 --- a/jael_web/example/stateful.dart +++ b/jael_web/example/stateful.dart @@ -19,7 +19,7 @@ class StatefulApp extends Component<_AppState> with _StatefulAppJaelTemplate { Timer _timer; StatefulApp() { - state =_AppState(ticks: 0); + state = _AppState(ticks: 0); _timer = Timer.periodic(Duration(seconds: 1), (t) { setState(state.copyWith(ticks: t.tick)); }); diff --git a/jael_web/lib/builder.dart b/jael_web/lib/builder.dart index 0c9f4b71..1d848d2e 100644 --- a/jael_web/lib/builder.dart +++ b/jael_web/lib/builder.dart @@ -1 +1 @@ -export 'src/builder/builder.dart'; \ No newline at end of file +export 'src/builder/builder.dart'; diff --git a/jael_web/lib/elements.dart b/jael_web/lib/elements.dart index 01ea2e52..c97cfa6d 100644 --- a/jael_web/lib/elements.dart +++ b/jael_web/lib/elements.dart @@ -1 +1 @@ -export 'src/elements.dart'; \ No newline at end of file +export 'src/elements.dart'; diff --git a/jael_web/lib/src/dom_node.dart b/jael_web/lib/src/dom_node.dart index 4da291df..e35e6ff9 100644 --- a/jael_web/lib/src/dom_node.dart +++ b/jael_web/lib/src/dom_node.dart @@ -1,3 +1 @@ -abstract class DomNode { - -} \ No newline at end of file +abstract class DomNode {} diff --git a/jael_web/lib/src/elements.dart b/jael_web/lib/src/elements.dart index c20a99f3..c304842d 100644 --- a/jael_web/lib/src/elements.dart +++ b/jael_web/lib/src/elements.dart @@ -2033,4 +2033,4 @@ DomNode wbr( Iterable c: const [], @deprecated Iterable children: const []}) => h('wbr', _apply([p, props], {'id': id, 'class': className, 'style': style}), - []..addAll(c ?? [])..addAll(children ?? [])); \ No newline at end of file + []..addAll(c ?? [])..addAll(children ?? [])); diff --git a/jael_web/lib/src/fn.dart b/jael_web/lib/src/fn.dart index 9d7d4ca5..6a87c5b6 100644 --- a/jael_web/lib/src/fn.dart +++ b/jael_web/lib/src/fn.dart @@ -1,4 +1,4 @@ -// TODO: Lambda/anonymous component +// TODO: Lambda/anonymous component // // import 'component.dart'; // import 'dom_node.dart'; @@ -7,4 +7,4 @@ // final DomNode Function(T) f; // Fn(this.f); -// } \ No newline at end of file +// }