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

Side by Side Diff: lib/src/js/builder.dart

Issue 1483813002: Use const for const/final top-levels, types, symbols. (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Rebased after vsm's regen 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 unified diff | Download patch
« no previous file with comments | « lib/src/codegen/js_codegen.dart ('k') | test/codegen/expect/DeltaBlue.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // Utilities for building JS ASTs at runtime. Contains a builder class 5 // Utilities for building JS ASTs at runtime. Contains a builder class
6 // and a parser that parses part of the language. 6 // and a parser that parses part of the language.
7 7
8 part of js_ast; 8 part of js_ast;
9 9
10 10
(...skipping 1158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 declare(firstVariable); 1169 declare(firstVariable);
1170 while (acceptCategory(COMMA)) { 1170 while (acceptCategory(COMMA)) {
1171 String variable = lastToken; 1171 String variable = lastToken;
1172 expectCategory(ALPHA); 1172 expectCategory(ALPHA);
1173 declare(variable); 1173 declare(variable);
1174 } 1174 }
1175 return new VariableDeclarationList(keyword, initialization); 1175 return new VariableDeclarationList(keyword, initialization);
1176 } 1176 }
1177 1177
1178 Expression parseVarDeclarationOrExpression() { 1178 Expression parseVarDeclarationOrExpression() {
1179 var keyword = acceptVarOrLet(); 1179 var keyword = acceptVarLetOrConst();
1180 if (keyword != null) { 1180 if (keyword != null) {
1181 return parseVariableDeclarationList(keyword); 1181 return parseVariableDeclarationList(keyword);
1182 } else { 1182 } else {
1183 return parseExpression(); 1183 return parseExpression();
1184 } 1184 }
1185 } 1185 }
1186 1186
1187 /** Accepts a `var` or `let` keyword. If neither is found, returns null. */ 1187 /** Accepts a `var` or `let` keyword. If neither is found, returns null. */
1188 String acceptVarOrLet() { 1188 String acceptVarLetOrConst() {
1189 if (acceptString('var')) return 'var'; 1189 if (acceptString('var')) return 'var';
1190 if (acceptString('let')) return 'let'; 1190 if (acceptString('let')) return 'let';
1191 if (acceptString('const')) return 'const';
1191 return null; 1192 return null;
1192 } 1193 }
1193 1194
1194 Expression expression() { 1195 Expression expression() {
1195 Expression expression = parseVarDeclarationOrExpression(); 1196 Expression expression = parseVarDeclarationOrExpression();
1196 if (lastCategory != NONE || position != src.length) { 1197 if (lastCategory != NONE || position != src.length) {
1197 error("Unparsed junk: ${categoryToString(lastCategory)}"); 1198 error("Unparsed junk: ${categoryToString(lastCategory)}");
1198 } 1199 }
1199 return expression; 1200 return expression;
1200 } 1201 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1239 if (acceptString('if')) return parseIfThenElse(); 1240 if (acceptString('if')) return parseIfThenElse();
1240 1241
1241 if (acceptString('for')) return parseFor(); 1242 if (acceptString('for')) return parseFor();
1242 1243
1243 if (acceptString('function')) return parseFunctionDeclaration(); 1244 if (acceptString('function')) return parseFunctionDeclaration();
1244 1245
1245 if (acceptString('class')) return new ClassDeclaration(parseClass()); 1246 if (acceptString('class')) return new ClassDeclaration(parseClass());
1246 1247
1247 if (acceptString('try')) return parseTry(); 1248 if (acceptString('try')) return parseTry();
1248 1249
1249 var keyword = acceptVarOrLet(); 1250 var keyword = acceptVarLetOrConst();
1250 if (keyword != null) { 1251 if (keyword != null) {
1251 Expression declarations = parseVariableDeclarationList(keyword); 1252 Expression declarations = parseVariableDeclarationList(keyword);
1252 expectSemicolon(); 1253 expectSemicolon();
1253 return new ExpressionStatement(declarations); 1254 return new ExpressionStatement(declarations);
1254 } 1255 }
1255 1256
1256 if (acceptString('while')) return parseWhile(); 1257 if (acceptString('while')) return parseWhile();
1257 1258
1258 if (acceptString('do')) return parseDo(); 1259 if (acceptString('do')) return parseDo();
1259 1260
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1365 } 1366 }
1366 Statement body = parseStatement(); 1367 Statement body = parseStatement();
1367 return new For(init, condition, update, body); 1368 return new For(init, condition, update, body);
1368 } 1369 }
1369 1370
1370 expectCategory(LPAREN); 1371 expectCategory(LPAREN);
1371 if (acceptCategory(SEMICOLON)) { 1372 if (acceptCategory(SEMICOLON)) {
1372 return finishFor(null); 1373 return finishFor(null);
1373 } 1374 }
1374 1375
1375 var keyword = acceptVarOrLet(); 1376 var keyword = acceptVarLetOrConst();
1376 if (keyword != null) { 1377 if (keyword != null) {
1377 String identifier = lastToken; 1378 String identifier = lastToken;
1378 expectCategory(ALPHA); 1379 expectCategory(ALPHA);
1379 1380
1380 if (acceptString('in')) { 1381 if (acceptString('in')) {
1381 Expression objectExpression = parseExpression(); 1382 Expression objectExpression = parseExpression();
1382 expectCategory(RPAREN); 1383 expectCategory(RPAREN);
1383 Statement body = parseStatement(); 1384 Statement body = parseStatement();
1384 return new ForIn( 1385 return new ForIn(
1385 _createVariableDeclarationList(keyword, identifier), 1386 _createVariableDeclarationList(keyword, identifier),
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1583 expectCategory(RSQUARE); 1584 expectCategory(RSQUARE);
1584 return expr; 1585 return expr;
1585 } else if (acceptCategory(HASH)) { 1586 } else if (acceptCategory(HASH)) {
1586 return parseInterpolatedExpression(); 1587 return parseInterpolatedExpression();
1587 } else { 1588 } else {
1588 error('Expected property name'); 1589 error('Expected property name');
1589 return null; 1590 return null;
1590 } 1591 }
1591 } 1592 }
1592 } 1593 }
OLDNEW
« no previous file with comments | « lib/src/codegen/js_codegen.dart ('k') | test/codegen/expect/DeltaBlue.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698