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

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

Issue 1643523008: fix #43, remove => workaround (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: 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/src/codegen/js_codegen.dart ('k') | lib/src/js/nodes.dart » ('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:convert' show JSON, JsonEncoder; 5 import 'dart:convert' show JSON, JsonEncoder;
6 import 'dart:io' show Directory, File, Platform, Process; 6 import 'dart:io' show Directory, File, Platform, Process;
7 7
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 '../js/js_ast.dart' as JS; 14 import '../js/js_ast.dart' as JS;
15 import '../utils.dart' show computeHash, locationForOffset; 15 import '../utils.dart' show computeHash, locationForOffset;
16 16
17 import 'js_names.dart' show TemporaryNamer; 17 import 'js_names.dart' show TemporaryNamer;
18 18
19 String writeJsLibrary( 19 String writeJsLibrary(
20 JS.Program jsTree, String outputPath, String inputDir, Uri serverUri, 20 JS.Program jsTree, String outputPath, String inputDir, Uri serverUri,
21 {bool emitSourceMaps: false, bool arrowFnBindThisWorkaround: false}) { 21 {bool emitSourceMaps: false}) {
22 var outFilename = path.basename(outputPath); 22 var outFilename = path.basename(outputPath);
23 var outDir = path.dirname(outputPath); 23 var outDir = path.dirname(outputPath);
24 new Directory(outDir).createSync(recursive: true); 24 new Directory(outDir).createSync(recursive: true);
25 25
26 JS.JavaScriptPrintingContext context; 26 JS.JavaScriptPrintingContext context;
27 if (emitSourceMaps) { 27 if (emitSourceMaps) {
28 var printer = new srcmaps.Printer(outFilename); 28 var printer = new srcmaps.Printer(outFilename);
29 context = 29 context =
30 new SourceMapPrintingContext(printer, outDir, inputDir, serverUri); 30 new SourceMapPrintingContext(printer, outDir, inputDir, serverUri);
31 } else { 31 } else {
32 context = new JS.SimpleJavaScriptPrintingContext(); 32 context = new JS.SimpleJavaScriptPrintingContext();
33 } 33 }
34 34
35 var opts = new JS.JavaScriptPrintingOptions( 35 var opts = new JS.JavaScriptPrintingOptions(
36 allowKeywordsInProperties: true, 36 allowKeywordsInProperties: true, allowSingleLineIfStatements: true);
37 allowSingleLineIfStatements: true,
38 arrowFnBindThisWorkaround: arrowFnBindThisWorkaround);
39 var jsNamer = new TemporaryNamer(jsTree); 37 var jsNamer = new TemporaryNamer(jsTree);
40 jsTree.accept(new JS.Printer(opts, context, localNamer: jsNamer)); 38 jsTree.accept(new JS.Printer(opts, context, localNamer: jsNamer));
41 39
42 String text; 40 String text;
43 if (context is SourceMapPrintingContext) { 41 if (context is SourceMapPrintingContext) {
44 var printer = context.printer; 42 var printer = context.printer;
45 printer.add('//# sourceMappingURL=$outFilename.map\n'); 43 printer.add('//# sourceMappingURL=$outFilename.map\n');
46 // Write output file and source map 44 // Write output file and source map
47 text = printer.text; 45 text = printer.text;
48 var sourceMap = JSON.decode(printer.map); 46 var sourceMap = JSON.decode(printer.map);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 _currentTopLevelDeclaration == null; 143 _currentTopLevelDeclaration == null;
146 return; 144 return;
147 } 145 }
148 } 146 }
149 147
150 String _getIdentifier(AstNode node) { 148 String _getIdentifier(AstNode node) {
151 if (node is SimpleIdentifier) return node.name; 149 if (node is SimpleIdentifier) return node.name;
152 return null; 150 return null;
153 } 151 }
154 } 152 }
OLDNEW
« no previous file with comments | « lib/src/codegen/js_codegen.dart ('k') | lib/src/js/nodes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698