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

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

Issue 997143003: Fix for conditional expressions (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 9 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
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; 7 import 'dart:collection' show HashSet;
8 import 'dart:io' show Directory, File; 8 import 'dart:io' show Directory, File;
9 9
10 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; 10 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator;
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 // var result = []; 953 // var result = [];
954 // result.length = length; 954 // result.length = length;
955 var savedCascadeTemp = _cascadeTarget; 955 var savedCascadeTemp = _cascadeTarget;
956 _cascadeTarget = last.name; 956 _cascadeTarget = last.name;
957 957
958 variables = _visitList(node.variables.take(node.variables.length - 1)); 958 variables = _visitList(node.variables.take(node.variables.length - 1));
959 variables.add(new JS.VariableInitialization( 959 variables.add(new JS.VariableInitialization(
960 new JS.VariableDeclaration(last.name.name), 960 new JS.VariableDeclaration(last.name.name),
961 _visit(lastInitializer.target))); 961 _visit(lastInitializer.target)));
962 962
963 var result = 963 var result = <JS.Expression>[
Siggi Cherem (dart-lang) 2015/03/16 15:11:40 I think you might have an older version of the for
vsm 2015/03/16 15:30:38 You are right. Upgrading and rerunning. We proba
964 <JS.Expression>[new JS.VariableDeclarationList('let', variables)]; 964 new JS.VariableDeclarationList('let', variables)
965 ];
965 result.addAll(_visitList(lastInitializer.cascadeSections)); 966 result.addAll(_visitList(lastInitializer.cascadeSections));
966 _cascadeTarget = savedCascadeTemp; 967 _cascadeTarget = savedCascadeTemp;
967 return _statement(result.map((e) => new JS.ExpressionStatement(e))); 968 return _statement(result.map((e) => new JS.ExpressionStatement(e)));
968 } else { 969 } else {
969 variables = _visitList(node.variables); 970 variables = _visitList(node.variables);
970 } 971 }
971 972
972 return new JS.VariableDeclarationList('let', variables); 973 return new JS.VariableDeclarationList('let', variables);
973 } 974 }
974 975
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 isSetter: true)); 1010 isSetter: true));
1010 } 1011 }
1011 } 1012 }
1012 1013
1013 return js.statement( 1014 return js.statement(
1014 'dart.defineLazyProperties(#, { # })', [objExpr, methods]); 1015 'dart.defineLazyProperties(#, { # })', [objExpr, methods]);
1015 } 1016 }
1016 1017
1017 void _flushLibraryProperties(List<JS.Statement> body) { 1018 void _flushLibraryProperties(List<JS.Statement> body) {
1018 if (_properties.isEmpty) return; 1019 if (_properties.isEmpty) return;
1019 body.add(js.statement('dart.copyProperties($_EXPORTS, { # });', 1020 body.add(js.statement('dart.copyProperties($_EXPORTS, { # });', [
1020 [_properties.map(_emitTopLevelProperty)])); 1021 _properties.map(_emitTopLevelProperty)
1022 ]));
1021 _properties.clear(); 1023 _properties.clear();
1022 } 1024 }
1023 1025
1024 @override 1026 @override
1025 JS.Statement visitVariableDeclarationStatement( 1027 JS.Statement visitVariableDeclarationStatement(
1026 VariableDeclarationStatement node) => 1028 VariableDeclarationStatement node) =>
1027 _expressionStatement(_visit(node.variables)); 1029 _expressionStatement(_visit(node.variables));
1028 1030
1029 @override 1031 @override
1030 visitConstructorName(ConstructorName node) { 1032 visitConstructorName(ConstructorName node) {
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
1602 1604
1603 @override 1605 @override
1604 visitDoubleLiteral(DoubleLiteral node) => js.number(node.value); 1606 visitDoubleLiteral(DoubleLiteral node) => js.number(node.value);
1605 1607
1606 @override 1608 @override
1607 visitNullLiteral(NullLiteral node) => new JS.LiteralNull(); 1609 visitNullLiteral(NullLiteral node) => new JS.LiteralNull();
1608 1610
1609 @override 1611 @override
1610 visitListLiteral(ListLiteral node) { 1612 visitListLiteral(ListLiteral node) {
1611 // TODO(jmesserly): make this faster. We're wasting an array. 1613 // TODO(jmesserly): make this faster. We're wasting an array.
1612 var list = js.call('new List.from(#)', 1614 var list = js.call('new List.from(#)', [
1613 [new JS.ArrayInitializer(_visitList(node.elements))]); 1615 new JS.ArrayInitializer(_visitList(node.elements))
1616 ]);
1614 if (node.constKeyword != null) { 1617 if (node.constKeyword != null) {
1615 list = js.commentExpression('Unimplemented const', list); 1618 list = js.commentExpression('Unimplemented const', list);
1616 } 1619 }
1617 return list; 1620 return list;
1618 } 1621 }
1619 1622
1620 @override 1623 @override
1621 visitMapLiteral(MapLiteral node) { 1624 visitMapLiteral(MapLiteral node) {
1622 var entries = node.entries; 1625 var entries = node.entries;
1623 var mapArguments = null; 1626 var mapArguments = null;
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
1929 CheckerReporter reporter) { 1932 CheckerReporter reporter) {
1930 JS.Program jsTree = 1933 JS.Program jsTree =
1931 new JSCodegenVisitor(info, rules).generateLibrary(units, reporter); 1934 new JSCodegenVisitor(info, rules).generateLibrary(units, reporter);
1932 1935
1933 var outputPath = path.join(outDir, jsOutputPath(info, root)); 1936 var outputPath = path.join(outDir, jsOutputPath(info, root));
1934 new Directory(path.dirname(outputPath)).createSync(recursive: true); 1937 new Directory(path.dirname(outputPath)).createSync(recursive: true);
1935 1938
1936 if (options.emitSourceMaps) { 1939 if (options.emitSourceMaps) {
1937 var outFilename = path.basename(outputPath); 1940 var outFilename = path.basename(outputPath);
1938 var printer = new srcmaps.Printer(outFilename); 1941 var printer = new srcmaps.Printer(outFilename);
1939 _writeNode( 1942 _writeNode(new SourceMapPrintingContext(
1940 new SourceMapPrintingContext(printer, path.dirname(outputPath)), 1943 printer, path.dirname(outputPath)), jsTree);
1941 jsTree);
1942 printer.add('//# sourceMappingURL=$outFilename.map'); 1944 printer.add('//# sourceMappingURL=$outFilename.map');
1943 // Write output file and source map 1945 // Write output file and source map
1944 var text = printer.text; 1946 var text = printer.text;
1945 new File(outputPath).writeAsStringSync(text); 1947 new File(outputPath).writeAsStringSync(text);
1946 new File('$outputPath.map').writeAsStringSync(printer.map); 1948 new File('$outputPath.map').writeAsStringSync(printer.map);
1947 return computeHash(text); 1949 return computeHash(text);
1948 } else { 1950 } else {
1949 var text = jsNodeToString(jsTree); 1951 var text = jsNodeToString(jsTree);
1950 new File(outputPath).writeAsStringSync(text); 1952 new File(outputPath).writeAsStringSync(text);
1951 return computeHash(text); 1953 return computeHash(text);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
2039 2041
2040 // TODO(jmesserly): in many cases marking the end will be unncessary. 2042 // TODO(jmesserly): in many cases marking the end will be unncessary.
2041 printer.mark(_location(node.end)); 2043 printer.mark(_location(node.end));
2042 } 2044 }
2043 2045
2044 String _getIdentifier(AstNode node) { 2046 String _getIdentifier(AstNode node) {
2045 if (node is SimpleIdentifier) return node.name; 2047 if (node is SimpleIdentifier) return node.name;
2046 return null; 2048 return null;
2047 } 2049 }
2048 } 2050 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698