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

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

Issue 1767803002: a few small refactorings to closure workarounds (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 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
« no previous file with comments | « lib/src/codegen/js_metalet.dart ('k') | lib/src/codegen/side_effect_analysis.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 FileSystem, computeHash, locationForOffset; 15 import '../utils.dart' show FileSystem, 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, FileSystem fileSystem}) { 21 {bool emitSourceMaps: false,
22 bool emitTypes: false,
23 FileSystem fileSystem}) {
22 var outFilename = path.basename(outputPath); 24 var outFilename = path.basename(outputPath);
23 var outDir = path.dirname(outputPath); 25 var outDir = path.dirname(outputPath);
24 26
25 JS.JavaScriptPrintingContext context; 27 JS.JavaScriptPrintingContext context;
26 if (emitSourceMaps) { 28 if (emitSourceMaps) {
27 var printer = new srcmaps.Printer(outFilename); 29 var printer = new srcmaps.Printer(outFilename);
28 context = 30 context =
29 new SourceMapPrintingContext(printer, outDir, inputDir, serverUri); 31 new SourceMapPrintingContext(printer, outDir, inputDir, serverUri);
30 } else { 32 } else {
31 context = new JS.SimpleJavaScriptPrintingContext(); 33 context = new JS.SimpleJavaScriptPrintingContext();
32 } 34 }
33 35
34 var opts = new JS.JavaScriptPrintingOptions( 36 var opts = new JS.JavaScriptPrintingOptions(
35 shouldEmitTypes: true, 37 emitTypes: emitTypes,
36 allowKeywordsInProperties: true, 38 allowKeywordsInProperties: true,
37 allowSingleLineIfStatements: true); 39 allowSingleLineIfStatements: true);
38 var jsNamer = new TemporaryNamer(jsTree); 40 var jsNamer = new TemporaryNamer(jsTree);
39 jsTree.accept(new JS.Printer(opts, context, localNamer: jsNamer)); 41 jsTree.accept(new JS.Printer(opts, context, localNamer: jsNamer));
40 42
41 String text; 43 String text;
42 if (context is SourceMapPrintingContext) { 44 if (context is SourceMapPrintingContext) {
43 var printer = context.printer; 45 var printer = context.printer;
44 printer.add('//# sourceMappingURL=$outFilename.map\n'); 46 printer.add('//# sourceMappingURL=$outFilename.map\n');
45 // Write output file and source map 47 // Write output file and source map
46 text = printer.text; 48 text = printer.text;
47 var sourceMap = JSON.decode(printer.map); 49 var sourceMap = JSON.decode(printer.map);
50 // TODO(jmesserly): I'm not sure where this logic came from, but we should
51 // upstream this, rather than workaround source_map's formatting ourselves.
48 var sourceMapText = new JsonEncoder.withIndent(' ').convert(sourceMap); 52 var sourceMapText = new JsonEncoder.withIndent(' ').convert(sourceMap);
49 // Convert: 53 // Convert:
50 // "names": [ 54 // "names": [
51 // "state", 55 // "state",
52 // "print" 56 // "print"
53 // ] 57 // ]
54 // to: 58 // to:
55 // "names": ["state","print"] 59 // "names": ["state","print"]
56 sourceMapText = 60 sourceMapText =
57 sourceMapText.replaceAll('\n ', '').replaceAll('\n ]', ']'); 61 sourceMapText.replaceAll('\n ', '').replaceAll('\n ]', ']');
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 _currentTopLevelDeclaration == null; 148 _currentTopLevelDeclaration == null;
145 return; 149 return;
146 } 150 }
147 } 151 }
148 152
149 String _getIdentifier(AstNode node) { 153 String _getIdentifier(AstNode node) {
150 if (node is SimpleIdentifier) return node.name; 154 if (node is SimpleIdentifier) return node.name;
151 return null; 155 return null;
152 } 156 }
153 } 157 }
OLDNEW
« no previous file with comments | « lib/src/codegen/js_metalet.dart ('k') | lib/src/codegen/side_effect_analysis.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698