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

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

Issue 1263583005: implement exports, fixes #141 (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: rebase Created 5 years, 4 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_printer; 5 library dev_compiler.src.codegen.js_printer;
6 6
7 import 'dart:io' show Directory, File; 7 import 'dart:io' show Directory, File, Platform, Process;
8 import 'package:analyzer/src/generated/ast.dart'; 8 import 'package:analyzer/src/generated/ast.dart';
9 import 'package:path/path.dart' as path; 9 import 'package:path/path.dart' as path;
10 import 'package:source_maps/source_maps.dart' as srcmaps show Printer; 10 import 'package:source_maps/source_maps.dart' as srcmaps show Printer;
11 import 'package:source_maps/source_maps.dart' show SourceMapSpan; 11 import 'package:source_maps/source_maps.dart' show SourceMapSpan;
12 import 'package:source_span/source_span.dart' show SourceLocation; 12 import 'package:source_span/source_span.dart' show SourceLocation;
13 13
14 import 'package:dev_compiler/src/js/js_ast.dart' as JS; 14 import 'package:dev_compiler/src/js/js_ast.dart' as JS;
15 import 'package:dev_compiler/src/utils.dart' 15 import 'package:dev_compiler/src/utils.dart'
16 show computeHash, locationForOffset; 16 show computeHash, locationForOffset;
17 17
(...skipping 23 matching lines...) Expand all
41 if (context is SourceMapPrintingContext) { 41 if (context is SourceMapPrintingContext) {
42 var printer = context.printer; 42 var printer = context.printer;
43 printer.add('//# sourceMappingURL=$outFilename.map'); 43 printer.add('//# sourceMappingURL=$outFilename.map');
44 // Write output file and source map 44 // Write output file and source map
45 text = printer.text; 45 text = printer.text;
46 new File('$outputPath.map').writeAsStringSync(printer.map); 46 new File('$outputPath.map').writeAsStringSync(printer.map);
47 } else { 47 } else {
48 text = (context as JS.SimpleJavaScriptPrintingContext).getText(); 48 text = (context as JS.SimpleJavaScriptPrintingContext).getText();
49 } 49 }
50 new File(outputPath).writeAsStringSync(text); 50 new File(outputPath).writeAsStringSync(text);
51 if (jsTree.scriptTag != null) {
52 // Mark executable.
53 // TODO(jmesserly): should only do this if the input file was executable?
54 if (!Platform.isWindows) Process.runSync('chmod', ['+x', outputPath]);
55 }
56
51 return computeHash(text); 57 return computeHash(text);
52 } 58 }
53 59
54 class SourceMapPrintingContext extends JS.JavaScriptPrintingContext { 60 class SourceMapPrintingContext extends JS.JavaScriptPrintingContext {
55 final srcmaps.Printer printer; 61 final srcmaps.Printer printer;
56 final String outputDir; 62 final String outputDir;
57 63
58 CompilationUnit unit; 64 CompilationUnit unit;
59 Uri uri; 65 Uri uri;
60 66
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 109
104 // TODO(jmesserly): in many cases marking the end will be unnecessary. 110 // TODO(jmesserly): in many cases marking the end will be unnecessary.
105 printer.mark(_location(node.end)); 111 printer.mark(_location(node.end));
106 } 112 }
107 113
108 String _getIdentifier(AstNode node) { 114 String _getIdentifier(AstNode node) {
109 if (node is SimpleIdentifier) return node.name; 115 if (node is SimpleIdentifier) return node.name;
110 return null; 116 return null;
111 } 117 }
112 } 118 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698