Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Unified Diff: pkg/compiler/lib/src/parser/parser.dart

Issue 2068003002: dart2js: allow trailing commas in parameter and argument lists (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: respond to comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/parser/parser.dart
diff --git a/pkg/compiler/lib/src/parser/parser.dart b/pkg/compiler/lib/src/parser/parser.dart
index 821fcad03d8d64496ba4c78f3bc4c16fab8fa862..3ac49006fca4ced5645be4cc628275731eece1d8 100644
--- a/pkg/compiler/lib/src/parser/parser.dart
+++ b/pkg/compiler/lib/src/parser/parser.dart
@@ -424,13 +424,12 @@ class Parser {
listener.beginFormalParameters(begin);
expect('(', token);
int parameterCount = 0;
- if (optional(')', token.next)) {
- listener.endFormalParameters(parameterCount, begin, token.next);
- return token.next.next;
- }
do {
- ++parameterCount;
token = token.next;
+ if (optional(')', token)) {
+ break;
+ }
+ ++parameterCount;
String value = token.stringValue;
if (identical(value, '[')) {
token = parseOptionalFormalParameters(token, false);
@@ -495,11 +494,23 @@ class Parser {
int parameterCount = 0;
do {
token = token.next;
+ if (isNamed && optional('}', token)) {
+ break;
+ } else if (!isNamed && optional(']', token)) {
+ break;
+ }
var type =
isNamed ? FormalParameterType.NAMED : FormalParameterType.POSITIONAL;
token = parseFormalParameter(token, type);
++parameterCount;
} while (optional(',', token));
+ if (parameterCount == 0) {
+ listener.reportError(
+ token,
+ isNamed
+ ? MessageKind.EMPTY_NAMED_PARAMETER_LIST
+ : MessageKind.EMPTY_OPTIONAL_PARAMETER_LIST);
+ }
listener.endOptionalFormalParameters(parameterCount, begin, token);
if (isNamed) {
return expect('}', token);
@@ -2565,6 +2576,10 @@ class Parser {
bool old = mayParseFunctionExpressions;
mayParseFunctionExpressions = true;
do {
+ if (optional(')', token.next)) {
+ token = token.next;
+ break;
+ }
Token colon = null;
if (optional(':', token.next.next)) {
token = parseIdentifier(token.next);
« no previous file with comments | « pkg/compiler/lib/src/diagnostics/messages.dart ('k') | tests/compiler/dart2js_extra/invalid_annotation2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698