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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart

Issue 189563004: Use '--source-map' and '--out' options to support source maps from non-commandline. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 * Generates the code for all used classes in the program. Static fields (even 8 * Generates the code for all used classes in the program. Static fields (even
9 * in classes) are ignored, since they can be treated as non-class elements. 9 * in classes) are ignored, since they can be treated as non-class elements.
10 * 10 *
(...skipping 1511 matching lines...) Expand 10 before | Expand all | Expand 10 after
1522 1522
1523 emitMain(mainBuffer); 1523 emitMain(mainBuffer);
1524 jsAst.FunctionDeclaration precompiledFunctionAst = 1524 jsAst.FunctionDeclaration precompiledFunctionAst =
1525 buildPrecompiledFunction(); 1525 buildPrecompiledFunction();
1526 emitInitFunction(mainBuffer); 1526 emitInitFunction(mainBuffer);
1527 if (!compiler.deferredLoadTask.splitProgram) { 1527 if (!compiler.deferredLoadTask.splitProgram) {
1528 mainBuffer.add('})()\n'); 1528 mainBuffer.add('})()\n');
1529 } else { 1529 } else {
1530 mainBuffer.add('\n'); 1530 mainBuffer.add('\n');
1531 } 1531 }
1532 compiler.assembledCode = mainBuffer.getText(); 1532 String assembledCode = mainBuffer.getText();
1533 outputSourceMap(compiler.assembledCode, ''); 1533 if (generateSourceMap) {
1534 outputSourceMap(assembledCode, mainBuffer, '',
1535 compiler.sourceMapUri, compiler.outputUri);
1536 assembledCode +=
floitsch 2014/03/07 10:27:24 It seems more efficient if we don't have to create
Johnni Winther 2014/03/07 12:38:48 Done.
1537 generateSourceMapTag(compiler.sourceMapUri, compiler.outputUri);
1538 }
1539 compiler.outputProvider('', 'js')
1540 ..add(assembledCode)
1541 ..close();
1542 compiler.assembledCode = assembledCode;
1534 1543
1535 mainBuffer.write( 1544 mainBuffer.write(
1536 jsAst.prettyPrint( 1545 jsAst.prettyPrint(
1537 precompiledFunctionAst, compiler, 1546 precompiledFunctionAst, compiler,
1538 allowVariableMinification: false).getText()); 1547 allowVariableMinification: false).getText());
1539 1548
1540 compiler.outputProvider('', 'precompiled.js') 1549 compiler.outputProvider('', 'precompiled.js')
1541 ..add(mainBuffer.getText()) 1550 ..add(mainBuffer.getText())
1542 ..close(); 1551 ..close();
1543 1552
1544 emitDeferredCode(); 1553 emitDeferredCode();
1545 1554
1546 }); 1555 });
1547 return compiler.assembledCode; 1556 return compiler.assembledCode;
1548 } 1557 }
1549 1558
1559 String generateSourceMapTag(Uri sourceMapUri, Uri fileUri) {
1560 if (sourceMapUri != null && fileUri != null) {
1561 // Using # is the new proposed standard. @ caused problems in Internet
1562 // Explorer due to "Conditional Compilation Statements" in JScript,
1563 // see:
1564 // http://msdn.microsoft.com/en-us/library/7kx09ct1(v=vs.80).aspx
1565 // About source maps, see:
1566 // https://docs.google.com/a/google.com/document/d/1U1RGAehQwRypUTovF1KRlp iOFze0b-_2gc6fAH0KY0k/edit
1567 // TODO(http://dartbug.com/11914): Remove @ line.
floitsch 2014/03/07 10:27:24 I just tried with Chrome beta, and at least there
Johnni Winther 2014/03/07 12:38:48 Will do it in a separate CL.
1568 String sourceMapFileName = relativize(fileUri, sourceMapUri, false);
1569 return '''
1570
1571 //# sourceMappingURL=$sourceMapFileName
1572 //@ sourceMappingURL=$sourceMapFileName
1573 ''';
1574 }
1575 return '';
1576 }
1577
1550 ClassBuilder getElementDescriptorForOutputUnit(Element element, 1578 ClassBuilder getElementDescriptorForOutputUnit(Element element,
1551 OutputUnit outputUnit) { 1579 OutputUnit outputUnit) {
1552 Map<OutputUnit, ClassBuilder> descriptors = 1580 Map<OutputUnit, ClassBuilder> descriptors =
1553 elementDescriptors.putIfAbsent( 1581 elementDescriptors.putIfAbsent(
1554 element, () => new Map<OutputUnit, ClassBuilder>()); 1582 element, () => new Map<OutputUnit, ClassBuilder>());
1555 return descriptors.putIfAbsent(outputUnit, 1583 return descriptors.putIfAbsent(outputUnit,
1556 () => new ClassBuilder(namer)); 1584 () => new ClassBuilder(namer));
1557 } 1585 }
1558 1586
1559 ClassBuilder getElementDecriptor(Element element) { 1587 ClassBuilder getElementDecriptor(Element element) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1616 classesCollector = oldClassesCollector; 1644 classesCollector = oldClassesCollector;
1617 1645
1618 typeTestEmitter.emitRuntimeTypeSupport(buffer, outputUnit); 1646 typeTestEmitter.emitRuntimeTypeSupport(buffer, outputUnit);
1619 1647
1620 emitCompileTimeConstants(buffer, outputUnit); 1648 emitCompileTimeConstants(buffer, outputUnit);
1621 1649
1622 String code = buffer.getText(); 1650 String code = buffer.getText();
1623 compiler.outputProvider(outputUnit.name, 'js') 1651 compiler.outputProvider(outputUnit.name, 'js')
1624 ..add(code) 1652 ..add(code)
1625 ..close(); 1653 ..close();
1626 outputSourceMap(compiler.assembledCode, outputUnit.name); 1654
1655 // TODO(johnniwinther): Support source maps for deferred code.
1627 } 1656 }
1628 } 1657 }
1629 1658
1630 String buildGeneratedBy() { 1659 String buildGeneratedBy() {
1631 var suffix = ''; 1660 var suffix = '';
1632 if (compiler.hasBuildId) suffix = ' version: ${compiler.buildId}'; 1661 if (compiler.hasBuildId) suffix = ' version: ${compiler.buildId}';
1633 return '// Generated by dart2js, the Dart to JavaScript compiler$suffix.\n'; 1662 return '// Generated by dart2js, the Dart to JavaScript compiler$suffix.\n';
1634 } 1663 }
1635 1664
1636 String buildSourceMap(CodeBuffer buffer, SourceFile compiledFile) { 1665 String buildSourceMap(CodeBuffer buffer,
floitsch 2014/03/07 10:27:24 If buildSourceMap is not used anywhere else I woul
Johnni Winther 2014/03/07 12:38:48 Done.
1666 SourceFile compiledFile,
1667 [Uri sourceMapUri, Uri fileUri]) {
1637 SourceMapBuilder sourceMapBuilder = 1668 SourceMapBuilder sourceMapBuilder =
1638 new SourceMapBuilder(compiler.sourceMapUri); 1669 new SourceMapBuilder(sourceMapUri, fileUri);
1639 buffer.forEachSourceLocation(sourceMapBuilder.addMapping); 1670 buffer.forEachSourceLocation(sourceMapBuilder.addMapping);
1640 return sourceMapBuilder.build(compiledFile); 1671 return sourceMapBuilder.build(compiledFile);
1641 } 1672 }
1642 1673
1643 void outputSourceMap(String code, String name) { 1674 void outputSourceMap(String code, CodeBuffer buffer, String name,
1675 [Uri sourceMapUri, Uri fileUri]) {
1644 if (!generateSourceMap) return; 1676 if (!generateSourceMap) return;
1645 // Create a source file for the compilation output. This allows using 1677 // Create a source file for the compilation output. This allows using
1646 // [:getLine:] to transform offsets to line numbers in [SourceMapBuilder]. 1678 // [:getLine:] to transform offsets to line numbers in [SourceMapBuilder].
1647 SourceFile compiledFile = 1679 SourceFile compiledFile =
1648 new StringSourceFile(null, compiler.assembledCode); 1680 new StringSourceFile(null, code);
1649 String sourceMap = buildSourceMap(mainBuffer, compiledFile); 1681 String sourceMap = buildSourceMap(mainBuffer, compiledFile,
1682 sourceMapUri, fileUri);
1650 compiler.outputProvider(name, 'js.map') 1683 compiler.outputProvider(name, 'js.map')
1651 ..add(sourceMap) 1684 ..add(sourceMap)
1652 ..close(); 1685 ..close();
1653 } 1686 }
1654 1687
1655 void registerReadTypeVariable(TypeVariableElement element) { 1688 void registerReadTypeVariable(TypeVariableElement element) {
1656 readTypeVariables.add(element); 1689 readTypeVariables.add(element);
1657 } 1690 }
1658 } 1691 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698