Fix #631 more disallowed operators (#638)
Fix #631 more disallowed operators
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c9a401a..658e73d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,8 @@
- Fixed issues with `<ng-container>`, which resulted in the inner content simply
being ignored instead of being validated (and also caused some problems
with finding inner `<ng-content>` tags).
+- More checks for rejected operators like `+=`, `++` other unary operators and
+ compound assignments.
## 0.0.17+3
diff --git a/angular_analyzer_plugin/lib/src/resolver.dart b/angular_analyzer_plugin/lib/src/resolver.dart
index 1aa4a94..f555881 100644
--- a/angular_analyzer_plugin/lib/src/resolver.dart
+++ b/angular_analyzer_plugin/lib/src/resolver.dart
@@ -146,6 +146,9 @@
@override
void visitAssignmentExpression(AssignmentExpression exp) {
+ if (exp.operator.type != TokenType.EQ) {
+ _reportUnacceptableNode(exp, 'Compound assignment');
+ }
// Only block reassignment of locals, not poperties. Resolve elements to
// check that.
exp.leftHandSide.accept(elementResolver);
@@ -183,6 +186,18 @@
_reportUnacceptableNode(exp, "Named arguments");
@override
+ void visitPostfixExpression(PostfixExpression exp) {
+ _reportUnacceptableNode(exp, exp.operator.lexeme);
+ }
+
+ @override
+ void visitPrefixExpression(PrefixExpression exp) {
+ if (exp.operator.type != TokenType.MINUS) {
+ _reportUnacceptableNode(exp, exp.operator.lexeme);
+ }
+ }
+
+ @override
void visitSuperExpression(SuperExpression exp) =>
_reportUnacceptableNode(exp, "Super references");
diff --git a/angular_analyzer_plugin/test/resolver_test.dart b/angular_analyzer_plugin/test/resolver_test.dart
index 9a2537a..d87e724 100644
--- a/angular_analyzer_plugin/test/resolver_test.dart
+++ b/angular_analyzer_plugin/test/resolver_test.dart
@@ -2090,6 +2090,22 @@
}
// ignore: non_constant_identifier_names
+ Future test_expression_unaryMinus_allowed() async {
+ _addDartSource(r'''
+@Component(selector: 'test-panel', templateUrl: 'test_panel.html')
+class TestPanel {
+ int x;
+}
+''');
+ final code = r"""
+{{-x}}
+""";
+ _addHtmlSource(code);
+ await _resolveSingleTemplate(dartSource);
+ errorListener.assertNoErrors();
+ }
+
+ // ignore: non_constant_identifier_names
Future test_expressionNotAllowed_as() async {
_addDartSource(r'''
@Component(selector: 'test-panel', templateUrl: 'test_panel.html')
@@ -2195,6 +2211,23 @@
}
// ignore: non_constant_identifier_names
+ Future test_expressionNotAllowed_minusEq() async {
+ _addDartSource(r'''
+@Component(selector: 'test-panel', templateUrl: 'test_panel.html')
+class TestPanel {
+ int x;
+}
+''');
+ final code = r"""
+<h1 (click)="x -= 1"></h1>
+""";
+ _addHtmlSource(code);
+ await _resolveSingleTemplate(dartSource);
+ assertErrorInCodeAtPosition(
+ AngularWarningCode.DISALLOWED_EXPRESSION, code, 'x -= 1');
+ }
+
+ // ignore: non_constant_identifier_names
Future test_expressionNotAllowed_namedArgs() async {
_addDartSource(r'''
@Component(selector: 'test-panel', templateUrl: 'test_panel.html')
@@ -2245,6 +2278,89 @@
AngularWarningCode.DISALLOWED_EXPRESSION, code, "new String()");
}
+ Future test_expressionNotAllowed_plusEq() async {
+ _addDartSource(r'''
+@Component(selector: 'test-panel', templateUrl: 'test_panel.html')
+class TestPanel {
+ int x;
+}
+''');
+ final code = r"""
+<h1 (click)="x += 1"></h1>
+""";
+ _addHtmlSource(code);
+ await _resolveSingleTemplate(dartSource);
+ assertErrorInCodeAtPosition(
+ AngularWarningCode.DISALLOWED_EXPRESSION, code, 'x += 1');
+ }
+
+ Future test_expressionNotAllowed_postfixMinusMinus() async {
+ _addDartSource(r'''
+@Component(selector: 'test-panel', templateUrl: 'test_panel.html')
+class TestPanel {
+ int x;
+}
+''');
+ final code = r"""
+<h1 (click)="x--"></h1>
+""";
+ _addHtmlSource(code);
+ await _resolveSingleTemplate(dartSource);
+ assertErrorInCodeAtPosition(
+ AngularWarningCode.DISALLOWED_EXPRESSION, code, 'x--');
+ }
+
+ // ignore: non_constant_identifier_names
+ Future test_expressionNotAllowed_postfixPlusPlus() async {
+ _addDartSource(r'''
+@Component(selector: 'test-panel', templateUrl: 'test_panel.html')
+class TestPanel {
+ int x;
+}
+''');
+ final code = r"""
+<h1 (click)="x++"></h1>
+""";
+ _addHtmlSource(code);
+ await _resolveSingleTemplate(dartSource);
+ assertErrorInCodeAtPosition(
+ AngularWarningCode.DISALLOWED_EXPRESSION, code, 'x++');
+ }
+
+ // ignore: non_constant_identifier_names
+ Future test_expressionNotAllowed_prefixMinusMinus() async {
+ _addDartSource(r'''
+@Component(selector: 'test-panel', templateUrl: 'test_panel.html')
+class TestPanel {
+ int x;
+}
+''');
+ final code = r"""
+<h1 (click)="--x"></h1>
+""";
+ _addHtmlSource(code);
+ await _resolveSingleTemplate(dartSource);
+ assertErrorInCodeAtPosition(
+ AngularWarningCode.DISALLOWED_EXPRESSION, code, '--x');
+ }
+
+ // ignore: non_constant_identifier_names
+ Future test_expressionNotAllowed_prefixPlusPlus() async {
+ _addDartSource(r'''
+@Component(selector: 'test-panel', templateUrl: 'test_panel.html')
+class TestPanel {
+ int x;
+}
+''');
+ final code = r"""
+<h1 (click)="++x"></h1>
+""";
+ _addHtmlSource(code);
+ await _resolveSingleTemplate(dartSource);
+ assertErrorInCodeAtPosition(
+ AngularWarningCode.DISALLOWED_EXPRESSION, code, '++x');
+ }
+
// ignore: non_constant_identifier_names
Future test_expressionNotAllowed_referenceAssignment() async {
_addDartSource(r'''