OLD | NEW |
---|---|
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 ddc.src.codegen.js_codegen; | 5 library ddc.src.codegen.js_codegen; |
6 | 6 |
7 import 'dart:io' show Directory, File; | 7 import 'dart:io' show Directory, File; |
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; |
11 import 'package:analyzer/src/generated/constant.dart'; | 11 import 'package:analyzer/src/generated/constant.dart'; |
12 import 'package:analyzer/src/generated/element.dart'; | 12 import 'package:analyzer/src/generated/element.dart'; |
13 import 'package:analyzer/src/generated/scanner.dart' | 13 import 'package:analyzer/src/generated/scanner.dart' |
14 show StringToken, Token, TokenType; | 14 show StringToken, Token, TokenType; |
15 import 'package:source_maps/source_maps.dart' as srcmaps show Printer; | 15 import 'package:source_maps/source_maps.dart' as srcmaps show Printer; |
16 import 'package:source_maps/source_maps.dart' show SourceMapSpan; | 16 import 'package:source_maps/source_maps.dart' show SourceMapSpan; |
17 import 'package:source_span/source_span.dart' show SourceLocation; | |
18 import 'package:path/path.dart' as path; | 17 import 'package:path/path.dart' as path; |
19 | 18 |
20 // TODO(jmesserly): import from its own package | 19 // TODO(jmesserly): import from its own package |
21 import 'package:dev_compiler/src/js/js_ast.dart' as JS; | 20 import 'package:dev_compiler/src/js/js_ast.dart' as JS; |
22 import 'package:dev_compiler/src/js/js_ast.dart' show js; | 21 import 'package:dev_compiler/src/js/js_ast.dart' show js; |
23 | 22 |
24 import 'package:dev_compiler/src/checker/rules.dart'; | 23 import 'package:dev_compiler/src/checker/rules.dart'; |
25 import 'package:dev_compiler/src/info.dart'; | 24 import 'package:dev_compiler/src/info.dart'; |
26 import 'package:dev_compiler/src/options.dart'; | 25 import 'package:dev_compiler/src/options.dart'; |
27 import 'package:dev_compiler/src/report.dart'; | 26 import 'package:dev_compiler/src/report.dart'; |
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
966 var methods = []; | 965 var methods = []; |
967 for (var node in fields) { | 966 for (var node in fields) { |
968 var name = node.name.name; | 967 var name = node.name.name; |
969 methods.add(new JS.Method(new JS.PropertyName(name), | 968 methods.add(new JS.Method(new JS.PropertyName(name), |
970 js.call('function() { return #; }', _visit(node.initializer)), | 969 js.call('function() { return #; }', _visit(node.initializer)), |
971 isGetter: true)); | 970 isGetter: true)); |
972 | 971 |
973 // TODO(jmesserly): use a dummy setter to indicate writable. | 972 // TODO(jmesserly): use a dummy setter to indicate writable. |
974 if (!node.isFinal) { | 973 if (!node.isFinal) { |
975 methods.add(new JS.Method( | 974 methods.add(new JS.Method( |
976 new JS.PropertyName(name), js.call('function() {}'), | 975 new JS.PropertyName(name), js.call('function(_) {}'), |
Siggi Cherem (dart-lang)
2015/03/03 01:34:14
@jmesserly - I thought this change to remove the a
Jennifer Messerly
2015/03/03 02:24:21
yeah, seems that 1 arg is required for the setter
| |
977 isSetter: true)); | 976 isSetter: true)); |
978 } | 977 } |
979 } | 978 } |
980 | 979 |
981 return js.statement( | 980 return js.statement( |
982 'dart.defineLazyProperties(#, { # })', [objExpr, methods]); | 981 'dart.defineLazyProperties(#, { # })', [objExpr, methods]); |
983 } | 982 } |
984 | 983 |
985 void _flushLibraryProperties(List<JS.Statement> body) { | 984 void _flushLibraryProperties(List<JS.Statement> body) { |
986 if (_properties.isEmpty) return; | 985 if (_properties.isEmpty) return; |
(...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1779 | 1778 |
1780 void enterNode(JS.Node jsNode) { | 1779 void enterNode(JS.Node jsNode) { |
1781 AstNode node = jsNode.sourceInformation; | 1780 AstNode node = jsNode.sourceInformation; |
1782 if (node is CompilationUnit) { | 1781 if (node is CompilationUnit) { |
1783 unit = node; | 1782 unit = node; |
1784 uri = _makeRelativeUri(unit.element.source.uri); | 1783 uri = _makeRelativeUri(unit.element.source.uri); |
1785 return; | 1784 return; |
1786 } | 1785 } |
1787 if (unit == null || node == null || node.offset == -1) return; | 1786 if (unit == null || node == null || node.offset == -1) return; |
1788 | 1787 |
1789 var loc = _location(node.offset); | 1788 var loc = locationFor(unit, uri, node.offset); |
1790 var name = _getIdentifier(node); | 1789 var name = _getIdentifier(node); |
1791 if (name != null) { | 1790 if (name != null) { |
1792 // TODO(jmesserly): mark only uses the beginning of the span, but | 1791 // TODO(jmesserly): mark only uses the beginning of the span, but |
1793 // we're required to pass this as a valid span. | 1792 // we're required to pass this as a valid span. |
1794 var end = _location(node.end); | 1793 var end = locationFor(unit, uri, node.end); |
1795 printer.mark(new SourceMapSpan(loc, end, name, isIdentifier: true)); | 1794 printer.mark(new SourceMapSpan(loc, end, name, isIdentifier: true)); |
1796 } else { | 1795 } else { |
1797 printer.mark(loc); | 1796 printer.mark(loc); |
1798 } | 1797 } |
1799 } | 1798 } |
1800 | 1799 |
1801 SourceLocation _location(int offset) { | |
Jennifer Messerly
2015/03/03 02:24:21
seems worth keeping this, but simplify impl?
_loc
Siggi Cherem (dart-lang)
2015/03/04 04:44:23
Done.
| |
1802 var lineInfo = unit.lineInfo.getLocation(offset); | |
1803 return new SourceLocation(offset, | |
1804 sourceUrl: uri, | |
1805 line: lineInfo.lineNumber - 1, | |
1806 column: lineInfo.columnNumber - 1); | |
1807 } | |
1808 | |
1809 Uri _makeRelativeUri(Uri src) { | 1800 Uri _makeRelativeUri(Uri src) { |
1810 return new Uri(path: path.relative(src.path, from: outputDir)); | 1801 return new Uri(path: path.relative(src.path, from: outputDir)); |
1811 } | 1802 } |
1812 | 1803 |
1813 void exitNode(JS.Node jsNode) { | 1804 void exitNode(JS.Node jsNode) { |
1814 AstNode node = jsNode.sourceInformation; | 1805 AstNode node = jsNode.sourceInformation; |
1815 if (node is CompilationUnit) { | 1806 if (node is CompilationUnit) { |
1816 unit = null; | 1807 unit = null; |
1817 uri = null; | 1808 uri = null; |
1818 return; | 1809 return; |
1819 } | 1810 } |
1820 if (unit == null || node == null || node.offset == -1) return; | 1811 if (unit == null || node == null || node.offset == -1) return; |
1821 | 1812 |
1822 // TODO(jmesserly): in many cases marking the end will be unncessary. | 1813 // TODO(jmesserly): in many cases marking the end will be unncessary. |
1823 printer.mark(_location(node.end)); | 1814 printer.mark(locationFor(unit, uri, node.end)); |
1824 } | 1815 } |
1825 | 1816 |
1826 String _getIdentifier(AstNode node) { | 1817 String _getIdentifier(AstNode node) { |
1827 if (node is SimpleIdentifier) return node.name; | 1818 if (node is SimpleIdentifier) return node.name; |
1828 return null; | 1819 return null; |
1829 } | 1820 } |
1830 } | 1821 } |
OLD | NEW |