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

Side by Side Diff: lib/src/codegen/js_codegen.dart

Issue 1611753002: fixes #415, correct type for map literals (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: add TODO Created 4 years, 10 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 unified diff | Download patch
« no previous file with comments | « lib/runtime/dart/html.js ('k') | test/codegen/expect/collection/src/wrappers.txt » ('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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 import 'dart:collection' show HashSet, HashMap, SplayTreeSet; 5 import 'dart:collection' show HashSet, HashMap, SplayTreeSet;
6 6
7 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; 7 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator;
8 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator; 8 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator;
9 import 'package:analyzer/src/generated/constant.dart'; 9 import 'package:analyzer/src/generated/constant.dart';
10 import 'package:analyzer/src/generated/element.dart'; 10 import 'package:analyzer/src/generated/element.dart';
(...skipping 3186 matching lines...) Expand 10 before | Expand all | Expand 10 after
3197 if (node.constKeyword != null) return _emitConst(emitList); 3197 if (node.constKeyword != null) return _emitConst(emitList);
3198 return emitList(); 3198 return emitList();
3199 } 3199 }
3200 3200
3201 @override 3201 @override
3202 visitMapLiteral(MapLiteral node) { 3202 visitMapLiteral(MapLiteral node) {
3203 // TODO(jmesserly): we can likely make these faster. 3203 // TODO(jmesserly): we can likely make these faster.
3204 JS.Expression emitMap() { 3204 JS.Expression emitMap() {
3205 var entries = node.entries; 3205 var entries = node.entries;
3206 var mapArguments = null; 3206 var mapArguments = null;
3207 if (entries.isEmpty) { 3207 var typeArgs = node.typeArguments;
3208 if (entries.isEmpty && typeArgs == null) {
3208 mapArguments = []; 3209 mapArguments = [];
3209 } else if (entries.every((e) => e.key is StringLiteral)) { 3210 } else if (entries.every((e) => e.key is StringLiteral)) {
3210 // Use JS object literal notation if possible, otherwise use an array. 3211 // Use JS object literal notation if possible, otherwise use an array.
3211 // We could do this any time all keys are non-nullable String type. 3212 // We could do this any time all keys are non-nullable String type.
3212 // For now, support StringLiteral as the common non-nullable String case . 3213 // For now, support StringLiteral as the common non-nullable String case .
3213 var props = <JS.Property>[]; 3214 var props = <JS.Property>[];
3214 for (var e in entries) { 3215 for (var e in entries) {
3215 props.add(new JS.Property(_visit(e.key), _visit(e.value))); 3216 props.add(new JS.Property(_visit(e.key), _visit(e.value)));
3216 } 3217 }
3217 mapArguments = new JS.ObjectInitializer(props); 3218 mapArguments = new JS.ObjectInitializer(props);
3218 } else { 3219 } else {
3219 var values = <JS.Expression>[]; 3220 var values = <JS.Expression>[];
3220 for (var e in entries) { 3221 for (var e in entries) {
3221 values.add(_visit(e.key)); 3222 values.add(_visit(e.key));
3222 values.add(_visit(e.value)); 3223 values.add(_visit(e.value));
3223 } 3224 }
3224 mapArguments = new JS.ArrayInitializer(values); 3225 mapArguments = new JS.ArrayInitializer(values);
3225 } 3226 }
3226 // TODO(jmesserly): add generic types args. 3227 var types = <JS.Expression>[];
3227 return js.call('dart.map(#)', [mapArguments]); 3228 if (typeArgs != null) {
3229 types.addAll(typeArgs.arguments.map((e) => _emitTypeName(e.type)));
3230 }
3231 return js.call('dart.map(#, #)', [mapArguments, types]);
3228 } 3232 }
3229 if (node.constKeyword != null) return _emitConst(emitMap); 3233 if (node.constKeyword != null) return _emitConst(emitMap);
3230 return emitMap(); 3234 return emitMap();
3231 } 3235 }
3232 3236
3233 @override 3237 @override
3234 JS.LiteralString visitSimpleStringLiteral(SimpleStringLiteral node) => 3238 JS.LiteralString visitSimpleStringLiteral(SimpleStringLiteral node) =>
3235 js.escapedString(node.value, node.isSingleQuoted ? "'" : '"'); 3239 js.escapedString(node.value, node.isSingleQuoted ? "'" : '"');
3236 3240
3237 @override 3241 @override
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
3585 3589
3586 /// A special kind of element created by the compiler, signifying a temporary 3590 /// A special kind of element created by the compiler, signifying a temporary
3587 /// variable. These objects use instance equality, and should be shared 3591 /// variable. These objects use instance equality, and should be shared
3588 /// everywhere in the tree where they are treated as the same variable. 3592 /// everywhere in the tree where they are treated as the same variable.
3589 class TemporaryVariableElement extends LocalVariableElementImpl { 3593 class TemporaryVariableElement extends LocalVariableElementImpl {
3590 TemporaryVariableElement.forNode(Identifier name) : super.forNode(name); 3594 TemporaryVariableElement.forNode(Identifier name) : super.forNode(name);
3591 3595
3592 int get hashCode => identityHashCode(this); 3596 int get hashCode => identityHashCode(this);
3593 bool operator ==(Object other) => identical(this, other); 3597 bool operator ==(Object other) => identical(this, other);
3594 } 3598 }
OLDNEW
« no previous file with comments | « lib/runtime/dart/html.js ('k') | test/codegen/expect/collection/src/wrappers.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698