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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/full_emitter/emitter.dart

Issue 2690083002: Add MultiSourceInformationStrategy (Closed)
Patch Set: Cleanup. Created 3 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
OLDNEW
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;
(...skipping 1522 matching lines...) Expand 10 before | Expand all | Expand 10 after
1533 outputBuffers[mainOutputUnit] = mainOutput; 1533 outputBuffers[mainOutputUnit] = mainOutput;
1534 1534
1535 mainOutput.addBuffer(jsAst.createCodeBuffer(program, compiler, 1535 mainOutput.addBuffer(jsAst.createCodeBuffer(program, compiler,
1536 monitor: compiler.dumpInfoTask)); 1536 monitor: compiler.dumpInfoTask));
1537 1537
1538 if (compiler.options.deferredMapUri != null) { 1538 if (compiler.options.deferredMapUri != null) {
1539 outputDeferredMap(); 1539 outputDeferredMap();
1540 } 1540 }
1541 1541
1542 if (generateSourceMap) { 1542 if (generateSourceMap) {
1543 mainOutput.add(generateSourceMapTag( 1543 mainOutput.add(SourceMapBuilder.generateSourceMapTag(
1544 compiler.options.sourceMapUri, compiler.options.outputUri)); 1544 compiler.options.sourceMapUri, compiler.options.outputUri));
1545 } 1545 }
1546 1546
1547 mainOutput.close(); 1547 mainOutput.close();
1548 1548
1549 if (generateSourceMap) { 1549 if (generateSourceMap) {
1550 outputSourceMap(mainOutput, lineColumnCollector, '', 1550 SourceMapBuilder.outputSourceMap(
1551 compiler.options.sourceMapUri, compiler.options.outputUri); 1551 mainOutput,
1552 lineColumnCollector,
1553 '',
1554 compiler.options.sourceMapUri,
1555 compiler.options.outputUri,
1556 compiler.outputProvider);
1552 } 1557 }
1553 } 1558 }
1554 1559
1555 Map<OutputUnit, jsAst.Expression> buildDescriptorsForOutputUnits( 1560 Map<OutputUnit, jsAst.Expression> buildDescriptorsForOutputUnits(
1556 Program program) { 1561 Program program) {
1557 Map<OutputUnit, jsAst.Expression> outputs = 1562 Map<OutputUnit, jsAst.Expression> outputs =
1558 new Map<OutputUnit, jsAst.Expression>(); 1563 new Map<OutputUnit, jsAst.Expression>();
1559 1564
1560 for (Fragment fragment in program.deferredFragments) { 1565 for (Fragment fragment in program.deferredFragments) {
1561 OutputUnit outputUnit = fragment.outputUnit; 1566 OutputUnit outputUnit = fragment.outputUnit;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1632 }); 1637 });
1633 emitMainOutputUnit(program.mainFragment.outputUnit, mainOutput); 1638 emitMainOutputUnit(program.mainFragment.outputUnit, mainOutput);
1634 1639
1635 if (backend.requiresPreamble && !backend.htmlLibraryIsLoaded) { 1640 if (backend.requiresPreamble && !backend.htmlLibraryIsLoaded) {
1636 reporter.reportHintMessage(NO_LOCATION_SPANNABLE, MessageKind.PREAMBLE); 1641 reporter.reportHintMessage(NO_LOCATION_SPANNABLE, MessageKind.PREAMBLE);
1637 } 1642 }
1638 // Return the total program size. 1643 // Return the total program size.
1639 return outputBuffers.values.fold(0, (a, b) => a + b.length); 1644 return outputBuffers.values.fold(0, (a, b) => a + b.length);
1640 } 1645 }
1641 1646
1642 String generateSourceMapTag(Uri sourceMapUri, Uri fileUri) {
1643 if (sourceMapUri != null && fileUri != null) {
1644 String sourceMapFileName = relativize(fileUri, sourceMapUri, false);
1645 return '''
1646
1647 //# sourceMappingURL=$sourceMapFileName
1648 ''';
1649 }
1650 return '';
1651 }
1652
1653 ClassBuilder getElementDescriptor(Element element, Fragment fragment) { 1647 ClassBuilder getElementDescriptor(Element element, Fragment fragment) {
1654 Element owner = element.library; 1648 Element owner = element.library;
1655 if (!element.isLibrary && 1649 if (!element.isLibrary &&
1656 !element.isTopLevel && 1650 !element.isTopLevel &&
1657 !backend.isNative(element)) { 1651 !backend.isNative(element)) {
1658 // For static (not top level) elements, record their code in a buffer 1652 // For static (not top level) elements, record their code in a buffer
1659 // specific to the class. For now, not supported for native classes and 1653 // specific to the class. For now, not supported for native classes and
1660 // native elements. 1654 // native elements.
1661 ClassElement cls = element.enclosingClassOrCompilationUnit.declaration; 1655 ClassElement cls = element.enclosingClassOrCompilationUnit.declaration;
1662 if (compiler.codegenWorldBuilder.directlyInstantiatedClasses 1656 if (compiler.codegenWorldBuilder.directlyInstantiatedClasses
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
1891 } 1885 }
1892 1886
1893 if (outputUri != null) { 1887 if (outputUri != null) {
1894 String partFileName = partName + ".js"; 1888 String partFileName = partName + ".js";
1895 List<String> partSegments = outputUri.pathSegments.toList(); 1889 List<String> partSegments = outputUri.pathSegments.toList();
1896 partSegments[partSegments.length - 1] = partFileName; 1890 partSegments[partSegments.length - 1] = partFileName;
1897 partUri = 1891 partUri =
1898 compiler.options.outputUri.replace(pathSegments: partSegments); 1892 compiler.options.outputUri.replace(pathSegments: partSegments);
1899 } 1893 }
1900 1894
1901 output.add(generateSourceMapTag(mapUri, partUri)); 1895 output.add(SourceMapBuilder.generateSourceMapTag(mapUri, partUri));
1902 output.close(); 1896 output.close();
1903 outputSourceMap(output, lineColumnCollector, partName, mapUri, partUri); 1897 SourceMapBuilder.outputSourceMap(output, lineColumnCollector, partName,
1898 mapUri, partUri, compiler.outputProvider);
1904 } else { 1899 } else {
1905 output.close(); 1900 output.close();
1906 } 1901 }
1907 1902
1908 hunkHashes[outputUnit] = hash; 1903 hunkHashes[outputUnit] = hash;
1909 } 1904 }
1910 return hunkHashes; 1905 return hunkHashes;
1911 } 1906 }
1912 1907
1913 jsAst.Comment buildGeneratedBy() { 1908 jsAst.Comment buildGeneratedBy() {
1914 List<String> options = []; 1909 List<String> options = [];
1915 if (compiler.commonElements.mirrorsLibrary != null) options.add('mirrors'); 1910 if (compiler.commonElements.mirrorsLibrary != null) options.add('mirrors');
1916 if (compiler.options.useContentSecurityPolicy) options.add("CSP"); 1911 if (compiler.options.useContentSecurityPolicy) options.add("CSP");
1917 return new jsAst.Comment(generatedBy(compiler, flavor: options.join(", "))); 1912 return new jsAst.Comment(generatedBy(compiler, flavor: options.join(", ")));
1918 } 1913 }
1919 1914
1920 void outputSourceMap(
1921 CodeOutput output, LineColumnProvider lineColumnProvider, String name,
1922 [Uri sourceMapUri, Uri fileUri]) {
1923 if (!generateSourceMap) return;
1924 // Create a source file for the compilation output. This allows using
1925 // [:getLine:] to transform offsets to line numbers in [SourceMapBuilder].
1926 SourceMapBuilder sourceMapBuilder =
1927 new SourceMapBuilder(sourceMapUri, fileUri, lineColumnProvider);
1928 output.forEachSourceLocation(sourceMapBuilder.addMapping);
1929 String sourceMap = sourceMapBuilder.build();
1930 compiler.outputProvider(name, 'js.map', OutputType.js_map)
1931 ..add(sourceMap)
1932 ..close();
1933 }
1934
1935 void outputDeferredMap() { 1915 void outputDeferredMap() {
1936 Map<String, dynamic> mapping = new Map<String, dynamic>(); 1916 Map<String, dynamic> mapping = new Map<String, dynamic>();
1937 // Json does not support comments, so we embed the explanation in the 1917 // Json does not support comments, so we embed the explanation in the
1938 // data. 1918 // data.
1939 mapping["_comment"] = "This mapping shows which compiled `.js` files are " 1919 mapping["_comment"] = "This mapping shows which compiled `.js` files are "
1940 "needed for a given deferred library import."; 1920 "needed for a given deferred library import.";
1941 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); 1921 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap());
1942 compiler.outputProvider( 1922 compiler.outputProvider(
1943 compiler.options.deferredMapUri.path, '', OutputType.info) 1923 compiler.options.deferredMapUri.path, '', OutputType.info)
1944 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) 1924 ..add(const JsonEncoder.withIndent(" ").convert(mapping))
1945 ..close(); 1925 ..close();
1946 } 1926 }
1947 } 1927 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/backend.dart ('k') | pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698