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

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

Issue 1082333004: fixes #145, optional params+initializing formals+private fields (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 8 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 | « no previous file | test/codegen/expect/temps.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) 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 library dev_compiler.src.codegen.js_codegen; 5 library dev_compiler.src.codegen.js_codegen;
6 6
7 import 'dart:collection' show HashSet, HashMap; 7 import 'dart:collection' show HashSet, HashMap;
8 8
9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator;
10 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator; 10 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator;
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 return parameters.parameters.any((p) => p.kind != ParameterKind.REQUIRED); 878 return parameters.parameters.any((p) => p.kind != ParameterKind.REQUIRED);
879 } 879 }
880 880
881 JS.Statement _emitArgumentInitializers(FormalParameterList parameters) { 881 JS.Statement _emitArgumentInitializers(FormalParameterList parameters) {
882 if (parameters == null || !_hasArgumentInitializers(parameters)) { 882 if (parameters == null || !_hasArgumentInitializers(parameters)) {
883 return null; 883 return null;
884 } 884 }
885 885
886 var body = []; 886 var body = [];
887 for (var param in parameters.parameters) { 887 for (var param in parameters.parameters) {
888 // TODO(justinfagnani): rename identifier if necessary 888 var jsParam = _visit(param.identifier);
889 var name = param.identifier.name;
890 889
891 if (param.kind == ParameterKind.NAMED) { 890 if (param.kind == ParameterKind.NAMED) {
891 // Parameters will be passed using their real names, not the (possibly
892 // renamed) local variable.
893 var paramName = js.string(param.identifier.name, "'");
892 body.add(js.statement('let # = # && # in # ? #.# : #;', [ 894 body.add(js.statement('let # = # && # in # ? #.# : #;', [
893 name, 895 jsParam,
894 _namedArgTemp, 896 _namedArgTemp,
895 js.string(name, "'"), 897 paramName,
896 _namedArgTemp, 898 _namedArgTemp,
897 _namedArgTemp, 899 _namedArgTemp,
898 name, 900 paramName,
899 _defaultParamValue(param), 901 _defaultParamValue(param),
900 ])); 902 ]));
901 } else if (param.kind == ParameterKind.POSITIONAL) { 903 } else if (param.kind == ParameterKind.POSITIONAL) {
902 body.add(js.statement('if (# === void 0) # = #;', [ 904 body.add(js.statement('if (# === void 0) # = #;', [
903 name, 905 jsParam,
904 name, 906 jsParam,
905 _defaultParamValue(param) 907 _defaultParamValue(param)
906 ])); 908 ]));
907 } 909 }
908 } 910 }
909 return _statement(body); 911 return _statement(body);
910 } 912 }
911 913
912 JS.Expression _defaultParamValue(FormalParameter param) { 914 JS.Expression _defaultParamValue(FormalParameter param) {
913 if (param is DefaultFormalParameter && param.defaultValue != null) { 915 if (param is DefaultFormalParameter && param.defaultValue != null) {
914 return _visit(param.defaultValue); 916 return _visit(param.defaultValue);
(...skipping 1469 matching lines...) Expand 10 before | Expand all | Expand 10 after
2384 return filepath; 2386 return filepath;
2385 } 2387 }
2386 2388
2387 // TODO(jmesserly): validate the library. See issue #135. 2389 // TODO(jmesserly): validate the library. See issue #135.
2388 bool _isJsNameAnnotation(DartObjectImpl value) => value.type.name == 'JsName'; 2390 bool _isJsNameAnnotation(DartObjectImpl value) => value.type.name == 'JsName';
2389 2391
2390 // TODO(jacobr): we would like to do something like the following 2392 // TODO(jacobr): we would like to do something like the following
2391 // but we don't have summary support yet. 2393 // but we don't have summary support yet.
2392 // bool _supportJsExtensionMethod(AnnotatedNode node) => 2394 // bool _supportJsExtensionMethod(AnnotatedNode node) =>
2393 // _getAnnotation(node, "SupportJsExtensionMethod") != null; 2395 // _getAnnotation(node, "SupportJsExtensionMethod") != null;
OLDNEW
« no previous file with comments | « no previous file | test/codegen/expect/temps.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698