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 part of dart2js.js_emitter; | 5 part of dart2js.js_emitter; |
6 | 6 |
7 | 7 |
8 class OldEmitter implements Emitter { | 8 class OldEmitter implements Emitter { |
9 final Compiler compiler; | 9 final Compiler compiler; |
10 final CodeEmitterTask task; | 10 final CodeEmitterTask task; |
(...skipping 1275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1286 [ constructorName, js.string(constructorName), | 1286 [ constructorName, js.string(constructorName), |
1287 constructorName, | 1287 constructorName, |
1288 constructorName, js.string(constructorName), | 1288 constructorName, js.string(constructorName), |
1289 constructorName, | 1289 constructorName, |
1290 constructorName | 1290 constructorName |
1291 ])); | 1291 ])); |
1292 | 1292 |
1293 cspPrecompiledConstructorNamesFor(outputUnit).add(js('#', constructorName)); | 1293 cspPrecompiledConstructorNamesFor(outputUnit).add(js('#', constructorName)); |
1294 } | 1294 } |
1295 | 1295 |
1296 /// Returns a name composed of the main output file name and [name]. | 1296 /// Extracts the output name of the compiler's outputUri. |
1297 String deferredPartFileName(OutputUnit outputUnit, | 1297 String deferredPartFileName(OutputUnit outputUnit, |
1298 {bool addExtension: true}) { | 1298 {bool addExtension: true}) { |
1299 String outPath = compiler.outputUri != null | 1299 String outPath = compiler.outputUri != null |
1300 ? compiler.outputUri.path | 1300 ? compiler.outputUri.path |
1301 : "out"; | 1301 : "out"; |
1302 String outName = outPath.substring(outPath.lastIndexOf('/') + 1); | 1302 String outName = outPath.substring(outPath.lastIndexOf('/') + 1); |
1303 String extension = addExtension ? ".part.js" : ""; | 1303 String extension = addExtension ? ".part.js" : ""; |
1304 if (outputUnit == compiler.deferredLoadTask.mainOutputUnit) { | 1304 if (outputUnit == compiler.deferredLoadTask.mainOutputUnit) { |
1305 return "$outName$extension"; | 1305 return "$outName$extension"; |
1306 } else { | 1306 } else { |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1639 if (compiler.useContentSecurityPolicy) { | 1639 if (compiler.useContentSecurityPolicy) { |
1640 mainBuffer.write( | 1640 mainBuffer.write( |
1641 jsAst.prettyPrint( | 1641 jsAst.prettyPrint( |
1642 precompiledFunctionAst, | 1642 precompiledFunctionAst, |
1643 compiler, | 1643 compiler, |
1644 monitor: compiler.dumpInfoTask, | 1644 monitor: compiler.dumpInfoTask, |
1645 allowVariableMinification: false).getText()); | 1645 allowVariableMinification: false).getText()); |
1646 } | 1646 } |
1647 | 1647 |
1648 String assembledCode = mainBuffer.getText(); | 1648 String assembledCode = mainBuffer.getText(); |
1649 String sourceMapTags = ""; | |
1650 if (generateSourceMap) { | 1649 if (generateSourceMap) { |
1651 outputSourceMap(assembledCode, mainBuffer, '', | 1650 outputSourceMap(assembledCode, mainBuffer, '', |
1652 compiler.sourceMapUri, compiler.outputUri); | 1651 compiler.sourceMapUri, compiler.outputUri); |
1653 sourceMapTags = | 1652 mainBuffer.add( |
1654 generateSourceMapTag(compiler.sourceMapUri, compiler.outputUri); | 1653 generateSourceMapTag(compiler.sourceMapUri, compiler.outputUri)); |
1654 assembledCode = mainBuffer.getText(); | |
1655 } | 1655 } |
1656 mainBuffer.add(sourceMapTags); | 1656 |
1657 assembledCode = mainBuffer.getText(); | |
1658 compiler.outputProvider('', 'js') | 1657 compiler.outputProvider('', 'js') |
1659 ..add(assembledCode) | 1658 ..add(assembledCode) |
1660 ..close(); | 1659 ..close(); |
1661 compiler.assembledCode = assembledCode; | 1660 compiler.assembledCode = assembledCode; |
1662 | 1661 |
1663 if (!compiler.useContentSecurityPolicy) { | 1662 if (!compiler.useContentSecurityPolicy) { |
1664 CodeBuffer cspBuffer = new CodeBuffer(); | 1663 CodeBuffer cspBuffer = new CodeBuffer(); |
1665 cspBuffer.add(mainBuffer); | 1664 cspBuffer.add(mainBuffer); |
1666 cspBuffer.write(""" | 1665 cspBuffer.write(""" |
1667 { | 1666 { |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1877 jsAst.FunctionDeclaration precompiledFunctionAst = | 1876 jsAst.FunctionDeclaration precompiledFunctionAst = |
1878 buildCspPrecompiledFunctionFor(outputUnit); | 1877 buildCspPrecompiledFunctionFor(outputUnit); |
1879 | 1878 |
1880 outputBuffer.write( | 1879 outputBuffer.write( |
1881 jsAst.prettyPrint( | 1880 jsAst.prettyPrint( |
1882 precompiledFunctionAst, compiler, | 1881 precompiledFunctionAst, compiler, |
1883 monitor: compiler.dumpInfoTask, | 1882 monitor: compiler.dumpInfoTask, |
1884 allowVariableMinification: false).getText()); | 1883 allowVariableMinification: false).getText()); |
1885 } | 1884 } |
1886 | 1885 |
1887 String code = outputBuffer.getText(); | |
1888 | |
1889 // Make a unique hash of the code (before the sourcemaps are added) | 1886 // Make a unique hash of the code (before the sourcemaps are added) |
1890 // This will be used to retrieve the initializing function from the global | 1887 // This will be used to retrieve the initializing function from the global |
1891 // variable. | 1888 // variable. |
1892 String hash = hashOfString(code); | 1889 String hash = hashOfString(outputBuffer.getText()); |
1890 | |
1891 outputBuffer.add('${deferredInitializers}["$hash"]$_=$_' | |
1892 '${deferredInitializers}.current$N'); | |
1893 | |
1894 if (generateSourceMap) { | |
1895 String partName = | |
1896 '${deferredPartFileName(outputUnit, addExtension: false)}.part'; | |
1897 | |
1898 String mapFileName = partName + ".js.map"; | |
1899 List<String> mapSegments = compiler.sourceMapUri.pathSegments.toList(); | |
1900 mapSegments[mapSegments.length - 1] = mapFileName; | |
1901 Uri mapUri = compiler.sourceMapUri.replace(pathSegments: mapSegments); | |
1902 | |
1903 String partFileName = partName + ".js"; | |
1904 List<String> partSegments = compiler.outputUri.pathSegments.toList(); | |
1905 partSegments[mapSegments.length - 1] = partFileName; | |
1906 Uri partUri = compiler.outputUri.replace(pathSegments: partSegments); | |
1907 | |
1908 outputSourceMap(outputBuffer.getText(), outputBuffer, partName, | |
1909 mapUri, partUri); | |
1910 outputBuffer.add(generateSourceMapTag(mapUri, partUri)); | |
1911 } | |
1893 | 1912 |
1894 outputBuffers[outputUnit] = outputBuffer; | 1913 outputBuffers[outputUnit] = outputBuffer; |
1895 compiler.outputProvider( | 1914 compiler.outputProvider( |
1896 deferredPartFileName(outputUnit, addExtension: false), 'part.js') | 1915 deferredPartFileName(outputUnit, addExtension: false), 'part.js') |
Johnni Winther
2014/10/14 07:46:41
Store `deferredPartFileName(...)` is local variabl
floitsch
2014/10/14 09:34:06
Done.
| |
1897 ..add(code) | 1916 ..add(outputBuffer.getText()) |
1898 ..add('${deferredInitializers}["$hash"]$_=$_' | |
1899 '${deferredInitializers}.current$N') | |
1900 ..close(); | 1917 ..close(); |
1901 | 1918 |
1902 hunkHashes[outputUnit] = hash; | 1919 hunkHashes[outputUnit] = hash; |
1903 // TODO(johnniwinther): Support source maps for deferred code. | |
1904 } | 1920 } |
1905 return hunkHashes; | 1921 return hunkHashes; |
1906 } | 1922 } |
1907 | 1923 |
1908 String buildGeneratedBy() { | 1924 String buildGeneratedBy() { |
1909 var suffix = ''; | 1925 var suffix = ''; |
1910 if (compiler.hasBuildId) suffix = ' version: ${compiler.buildId}'; | 1926 if (compiler.hasBuildId) suffix = ' version: ${compiler.buildId}'; |
1911 return '// Generated by dart2js, the Dart to JavaScript compiler$suffix.\n'; | 1927 return '// Generated by dart2js, the Dart to JavaScript compiler$suffix.\n'; |
1912 } | 1928 } |
1913 | 1929 |
(...skipping 18 matching lines...) Expand all Loading... | |
1932 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 1948 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { |
1933 if (element.isInstanceMember) { | 1949 if (element.isInstanceMember) { |
1934 cachedClassBuilders.remove(element.enclosingClass); | 1950 cachedClassBuilders.remove(element.enclosingClass); |
1935 | 1951 |
1936 nativeEmitter.cachedBuilders.remove(element.enclosingClass); | 1952 nativeEmitter.cachedBuilders.remove(element.enclosingClass); |
1937 | 1953 |
1938 } | 1954 } |
1939 } | 1955 } |
1940 } | 1956 } |
1941 } | 1957 } |
OLD | NEW |