Skip to content

Commit 2b681b2

Browse files
author
Dan Rubel
committed
Disable scanning of &&= and ||= assignment operators
Fix #30340 Change-Id: Id27f37af9805ca09deaa3c6252817e3d9a926216 Reviewed-on: https://dart-review.googlesource.com/17361 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
1 parent 542083e commit 2b681b2

File tree

4 files changed

+35
-14
lines changed

4 files changed

+35
-14
lines changed

pkg/analyzer/test/generated/parser_test.dart

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import 'package:analyzer/src/generated/parser.dart';
1717
import 'package:analyzer/src/generated/source.dart';
1818
import 'package:analyzer/src/generated/testing/token_factory.dart';
1919
import 'package:analyzer/src/generated/utilities_dart.dart';
20+
import 'package:front_end/src/fasta/scanner/abstract_scanner.dart';
2021
import 'package:front_end/src/scanner/scanner.dart' as fe;
2122
import 'package:test/test.dart';
2223
import 'package:test_reflective_loader/test_reflective_loader.dart';
@@ -5628,13 +5629,15 @@ abstract class ExpressionParserTestMixin implements AbstractParserTestCase {
56285629
}
56295630

56305631
void test_parseExpression_assign_compound() {
5631-
enableLazyAssignmentOperators = true;
5632-
Expression expression = parseExpression('x ||= y');
5633-
var assignmentExpression = expression as AssignmentExpression;
5634-
expect(assignmentExpression.leftHandSide, isNotNull);
5635-
expect(assignmentExpression.operator, isNotNull);
5636-
expect(assignmentExpression.operator.type, TokenType.BAR_BAR_EQ);
5637-
expect(assignmentExpression.rightHandSide, isNotNull);
5632+
if (usingFastaParser && AbstractScanner.LAZY_ASSIGNMENT_ENABLED) {
5633+
enableLazyAssignmentOperators = true;
5634+
Expression expression = parseExpression('x ||= y');
5635+
var assignmentExpression = expression as AssignmentExpression;
5636+
expect(assignmentExpression.leftHandSide, isNotNull);
5637+
expect(assignmentExpression.operator, isNotNull);
5638+
expect(assignmentExpression.operator.type, TokenType.BAR_BAR_EQ);
5639+
expect(assignmentExpression.rightHandSide, isNotNull);
5640+
}
56385641
}
56395642

56405643
void test_parseExpression_comparison() {

pkg/front_end/lib/src/fasta/scanner/abstract_scanner.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ import 'token_constants.dart';
3232
import 'characters.dart';
3333

3434
abstract class AbstractScanner implements Scanner {
35+
/**
36+
* A flag indicating whether character sequences `&&=` and `||=`
37+
* should be tokenized as the assignment operators
38+
* [AMPERSAND_AMPERSAND_EQ_TOKEN] and [BAR_BAR_EQ_TOKEN] respectively.
39+
* See issue https://github.com/dart-lang/sdk/issues/30340
40+
*/
41+
static const bool LAZY_ASSIGNMENT_ENABLED = false;
42+
3543
final bool includeComments;
3644

3745
/**
@@ -510,7 +518,7 @@ abstract class AbstractScanner implements Scanner {
510518
next = advance();
511519
if (identical(next, $BAR)) {
512520
next = advance();
513-
if (identical(next, $EQ)) {
521+
if (LAZY_ASSIGNMENT_ENABLED && identical(next, $EQ)) {
514522
appendPrecedenceToken(TokenType.BAR_BAR_EQ);
515523
return advance();
516524
}
@@ -530,7 +538,7 @@ abstract class AbstractScanner implements Scanner {
530538
next = advance();
531539
if (identical(next, $AMPERSAND)) {
532540
next = advance();
533-
if (identical(next, $EQ)) {
541+
if (LAZY_ASSIGNMENT_ENABLED && identical(next, $EQ)) {
534542
appendPrecedenceToken(TokenType.AMPERSAND_AMPERSAND_EQ);
535543
return advance();
536544
}

pkg/front_end/test/precedence_info_test.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'package:front_end/src/fasta/scanner/abstract_scanner.dart'
6+
show AbstractScanner;
57
import 'package:front_end/src/fasta/scanner/string_scanner.dart';
68
import 'package:front_end/src/fasta/scanner/token.dart' as fasta;
79
import 'package:front_end/src/scanner/token.dart';
@@ -35,8 +37,10 @@ class PrecedenceInfoTest {
3537
assertLexeme('#!/'); // SCRIPT_TAG
3638
assertLexeme('"foo"'); // STRING
3739
assertLexeme('bar'); // IDENTIFIER
38-
assertLexeme('&&=');
39-
assertLexeme('||=');
40+
if (AbstractScanner.LAZY_ASSIGNMENT_ENABLED) {
41+
assertLexeme('&&=');
42+
assertLexeme('||=');
43+
}
4044
}
4145

4246
void test_isOperator() {

pkg/front_end/test/scanner_test.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import 'package:front_end/src/base/errors.dart';
66
import 'package:front_end/src/base/jenkins_smi_hash.dart';
7+
import 'package:front_end/src/fasta/scanner/abstract_scanner.dart'
8+
show AbstractScanner;
79
import 'package:front_end/src/scanner/errors.dart';
810
import 'package:front_end/src/scanner/reader.dart';
911
import 'package:front_end/src/scanner/scanner.dart';
@@ -153,8 +155,10 @@ abstract class ScannerTestBase {
153155
}
154156

155157
void test_ampersand_ampersand_eq() {
156-
_assertToken(TokenType.AMPERSAND_AMPERSAND_EQ, "&&=",
157-
lazyAssignmentOperators: true);
158+
if (AbstractScanner.LAZY_ASSIGNMENT_ENABLED) {
159+
_assertToken(TokenType.AMPERSAND_AMPERSAND_EQ, "&&=",
160+
lazyAssignmentOperators: true);
161+
}
158162
}
159163

160164
void test_ampersand_eq() {
@@ -211,7 +215,9 @@ abstract class ScannerTestBase {
211215
}
212216

213217
void test_bar_bar_eq() {
214-
_assertToken(TokenType.BAR_BAR_EQ, "||=", lazyAssignmentOperators: true);
218+
if (AbstractScanner.LAZY_ASSIGNMENT_ENABLED) {
219+
_assertToken(TokenType.BAR_BAR_EQ, "||=", lazyAssignmentOperators: true);
220+
}
215221
}
216222

217223
void test_bar_eq() {

0 commit comments

Comments
 (0)