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

Unified Diff: lib/src/js/builder.dart

Issue 1522793002: MiniJsParser: fix a regression + support computed props + add tests (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « no previous file | test/all_tests.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/js/builder.dart
diff --git a/lib/src/js/builder.dart b/lib/src/js/builder.dart
index 9643f7847cd89ce2572f71b4429468434baddfea..5037a3f0ef142003125f4e83838acf2d5f2f8dba 100644
--- a/lib/src/js/builder.dart
+++ b/lib/src/js/builder.dart
@@ -1152,11 +1152,19 @@ class MiniJsParser {
}
/** Parse a variable declaration list, with `var` or `let` [keyword] */
- VariableDeclarationList parseVariableDeclarationList(String keyword) {
+ VariableDeclarationList parseVariableDeclarationList(
+ String keyword, [String firstIdentifier]) {
var initialization = [];
do {
- var declarator = parseVariableBinding();
+ var declarator;
+ if (firstIdentifier != null) {
+ declarator = new Identifier(firstIdentifier);
+ firstIdentifier = null;
+ } else {
+ declarator = parseVariableBinding();
+ }
+
var initializer = acceptString("=") ? parseAssignment() : null;
initialization.add(new VariableInitialization(declarator, initializer));
} while (acceptCategory(COMMA));
@@ -1456,7 +1464,7 @@ class MiniJsParser {
iterableExpression,
body);
}
- var declarations = parseVariableDeclarationList(keyword);
+ var declarations = parseVariableDeclarationList(keyword, identifier);
expectCategory(SEMICOLON);
return finishFor(declarations);
}
@@ -1588,10 +1596,18 @@ class MiniJsParser {
Property parseMethodOrProperty({bool onlyMethods: false}) {
bool isStatic = acceptString('static');
- bool isGetter = false;
- bool isSetter = false;
+ bool isGetter = lastToken == 'get';
+ bool isSetter = lastToken == 'set';
Expression name = null;
- bool propertyNameIsIdentifier = lastCategory == ALPHA;
+ if (isGetter || isSetter) {
+ var token = lastToken;
+ getToken();
+ if (lastCategory == COLON) {
+ // That wasn't a accessor but the 'get' or 'set' property: retropedal.
+ isGetter = isSetter = false;
+ name = new LiteralString('"$token"');
+ }
+ }
if (acceptCategory(HASH)) {
if (lastCategory != LPAREN && (onlyMethods || lastCategory != COLON)) {
// Interpolated method
@@ -1601,18 +1617,7 @@ class MiniJsParser {
}
name = parseInterpolatedExpression();
} else {
- name = parsePropertyName();
- }
-
- // Allow get or set to be followed by another property name.
- if (propertyNameIsIdentifier &&
- (lastCategory == ALPHA || lastCategory == HASH)) {
- LiteralString p = name;
- isGetter = p.value == '"get"';
- isSetter = p.value == '"set"';
- if (isGetter || isSetter) {
- name = parsePropertyName();
- }
+ name ??= parsePropertyName();
}
if (!onlyMethods && acceptCategory(COLON)) {
« no previous file with comments | « no previous file | test/all_tests.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698