| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 dart2js.js_emitter.full_emitter; | 5 library dart2js.js_emitter.full_emitter; |
| 6 | 6 |
| 7 import 'dart:collection' show HashMap; | 7 import 'dart:collection' show HashMap; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 | 9 |
| 10 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; | 10 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; |
| 11 import 'package:js_runtime/shared/embedded_names.dart' | 11 import 'package:js_runtime/shared/embedded_names.dart' |
| 12 show JsBuiltin, JsGetName; | 12 show JsBuiltin, JsGetName; |
| 13 | 13 |
| 14 import '../../../compiler_new.dart'; |
| 14 import '../../common.dart'; | 15 import '../../common.dart'; |
| 15 import '../../compiler.dart' show Compiler; | 16 import '../../compiler.dart' show Compiler; |
| 16 import '../../constants/values.dart'; | 17 import '../../constants/values.dart'; |
| 17 import '../../core_types.dart' show CommonElements; | 18 import '../../core_types.dart' show CommonElements; |
| 18 import '../../elements/resolution_types.dart' show ResolutionDartType; | 19 import '../../elements/resolution_types.dart' show ResolutionDartType; |
| 19 import '../../deferred_load.dart' show OutputUnit; | 20 import '../../deferred_load.dart' show OutputUnit; |
| 20 import '../../elements/elements.dart' | 21 import '../../elements/elements.dart' |
| 21 show | 22 show |
| 22 ClassElement, | 23 ClassElement, |
| 23 Element, | 24 Element, |
| (...skipping 1497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1521 | 1522 |
| 1522 void emitMainOutputUnit(OutputUnit mainOutputUnit, jsAst.Program program) { | 1523 void emitMainOutputUnit(OutputUnit mainOutputUnit, jsAst.Program program) { |
| 1523 LineColumnCollector lineColumnCollector; | 1524 LineColumnCollector lineColumnCollector; |
| 1524 List<CodeOutputListener> codeOutputListeners; | 1525 List<CodeOutputListener> codeOutputListeners; |
| 1525 if (generateSourceMap) { | 1526 if (generateSourceMap) { |
| 1526 lineColumnCollector = new LineColumnCollector(); | 1527 lineColumnCollector = new LineColumnCollector(); |
| 1527 codeOutputListeners = <CodeOutputListener>[lineColumnCollector]; | 1528 codeOutputListeners = <CodeOutputListener>[lineColumnCollector]; |
| 1528 } | 1529 } |
| 1529 | 1530 |
| 1530 CodeOutput mainOutput = new StreamCodeOutput( | 1531 CodeOutput mainOutput = new StreamCodeOutput( |
| 1531 compiler.outputProvider('', 'js'), codeOutputListeners); | 1532 compiler.outputProvider('', 'js', OutputType.js), codeOutputListeners); |
| 1532 outputBuffers[mainOutputUnit] = mainOutput; | 1533 outputBuffers[mainOutputUnit] = mainOutput; |
| 1533 | 1534 |
| 1534 mainOutput.addBuffer(jsAst.createCodeBuffer(program, compiler, | 1535 mainOutput.addBuffer(jsAst.createCodeBuffer(program, compiler, |
| 1535 monitor: compiler.dumpInfoTask)); | 1536 monitor: compiler.dumpInfoTask)); |
| 1536 | 1537 |
| 1537 if (compiler.options.deferredMapUri != null) { | 1538 if (compiler.options.deferredMapUri != null) { |
| 1538 outputDeferredMap(); | 1539 outputDeferredMap(); |
| 1539 } | 1540 } |
| 1540 | 1541 |
| 1541 if (generateSourceMap) { | 1542 if (generateSourceMap) { |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1851 | 1852 |
| 1852 LineColumnCollector lineColumnCollector; | 1853 LineColumnCollector lineColumnCollector; |
| 1853 if (generateSourceMap) { | 1854 if (generateSourceMap) { |
| 1854 lineColumnCollector = new LineColumnCollector(); | 1855 lineColumnCollector = new LineColumnCollector(); |
| 1855 outputListeners.add(lineColumnCollector); | 1856 outputListeners.add(lineColumnCollector); |
| 1856 } | 1857 } |
| 1857 | 1858 |
| 1858 String partPrefix = | 1859 String partPrefix = |
| 1859 backend.deferredPartFileName(outputUnit.name, addExtension: false); | 1860 backend.deferredPartFileName(outputUnit.name, addExtension: false); |
| 1860 CodeOutput output = new StreamCodeOutput( | 1861 CodeOutput output = new StreamCodeOutput( |
| 1861 compiler.outputProvider(partPrefix, 'part.js'), outputListeners); | 1862 compiler.outputProvider(partPrefix, 'part.js', OutputType.jsPart), |
| 1863 outputListeners); |
| 1862 | 1864 |
| 1863 outputBuffers[outputUnit] = output; | 1865 outputBuffers[outputUnit] = output; |
| 1864 | 1866 |
| 1865 output.addBuffer(jsAst.createCodeBuffer(outputAsts[outputUnit], compiler, | 1867 output.addBuffer(jsAst.createCodeBuffer(outputAsts[outputUnit], compiler, |
| 1866 monitor: compiler.dumpInfoTask)); | 1868 monitor: compiler.dumpInfoTask)); |
| 1867 | 1869 |
| 1868 // Make a unique hash of the code (before the sourcemaps are added) | 1870 // Make a unique hash of the code (before the sourcemaps are added) |
| 1869 // This will be used to retrieve the initializing function from the global | 1871 // This will be used to retrieve the initializing function from the global |
| 1870 // variable. | 1872 // variable. |
| 1871 String hash = hasher.getHash(); | 1873 String hash = hasher.getHash(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1918 void outputSourceMap( | 1920 void outputSourceMap( |
| 1919 CodeOutput output, LineColumnProvider lineColumnProvider, String name, | 1921 CodeOutput output, LineColumnProvider lineColumnProvider, String name, |
| 1920 [Uri sourceMapUri, Uri fileUri]) { | 1922 [Uri sourceMapUri, Uri fileUri]) { |
| 1921 if (!generateSourceMap) return; | 1923 if (!generateSourceMap) return; |
| 1922 // Create a source file for the compilation output. This allows using | 1924 // Create a source file for the compilation output. This allows using |
| 1923 // [:getLine:] to transform offsets to line numbers in [SourceMapBuilder]. | 1925 // [:getLine:] to transform offsets to line numbers in [SourceMapBuilder]. |
| 1924 SourceMapBuilder sourceMapBuilder = | 1926 SourceMapBuilder sourceMapBuilder = |
| 1925 new SourceMapBuilder(sourceMapUri, fileUri, lineColumnProvider); | 1927 new SourceMapBuilder(sourceMapUri, fileUri, lineColumnProvider); |
| 1926 output.forEachSourceLocation(sourceMapBuilder.addMapping); | 1928 output.forEachSourceLocation(sourceMapBuilder.addMapping); |
| 1927 String sourceMap = sourceMapBuilder.build(); | 1929 String sourceMap = sourceMapBuilder.build(); |
| 1928 compiler.outputProvider(name, 'js.map') | 1930 compiler.outputProvider(name, 'js.map', OutputType.sourceMap) |
| 1929 ..add(sourceMap) | 1931 ..add(sourceMap) |
| 1930 ..close(); | 1932 ..close(); |
| 1931 } | 1933 } |
| 1932 | 1934 |
| 1933 void outputDeferredMap() { | 1935 void outputDeferredMap() { |
| 1934 Map<String, dynamic> mapping = new Map<String, dynamic>(); | 1936 Map<String, dynamic> mapping = new Map<String, dynamic>(); |
| 1935 // Json does not support comments, so we embed the explanation in the | 1937 // Json does not support comments, so we embed the explanation in the |
| 1936 // data. | 1938 // data. |
| 1937 mapping["_comment"] = "This mapping shows which compiled `.js` files are " | 1939 mapping["_comment"] = "This mapping shows which compiled `.js` files are " |
| 1938 "needed for a given deferred library import."; | 1940 "needed for a given deferred library import."; |
| 1939 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); | 1941 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); |
| 1940 compiler.outputProvider( | 1942 compiler.outputProvider( |
| 1941 compiler.options.deferredMapUri.path, 'deferred_map') | 1943 compiler.options.deferredMapUri.path, '', OutputType.info) |
| 1942 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) | 1944 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) |
| 1943 ..close(); | 1945 ..close(); |
| 1944 } | 1946 } |
| 1945 } | 1947 } |
| OLD | NEW |