OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library js.source_mapping; |
| 6 |
| 7 import 'js.dart'; |
| 8 import '../io/code_output.dart' show SourceLocations; |
| 9 import '../io/source_information.dart' show |
| 10 SourceLocation, |
| 11 SourceInformation, |
| 12 SourceInformationStrategy; |
| 13 |
| 14 /// [SourceInformationStrategy] that can associate source information with |
| 15 /// JavaScript output. |
| 16 class JavaScriptSourceInformationStrategy |
| 17 extends SourceInformationStrategy { |
| 18 const JavaScriptSourceInformationStrategy(); |
| 19 |
| 20 /// Creates a processor that can associate source information on [Node] with |
| 21 /// code offsets in the [sourceMapper]. |
| 22 SourceInformationProcessor createProcessor(SourceMapper sourceMapper) { |
| 23 return const SourceInformationProcessor(); |
| 24 } |
| 25 } |
| 26 |
| 27 /// An observer of code positions of printed JavaScript [Node]s. |
| 28 class CodePositionListener { |
| 29 const CodePositionListener(); |
| 30 |
| 31 /// Called to associate [node] with the provided start, end and closing |
| 32 /// positions. |
| 33 void onPositions( |
| 34 Node node, |
| 35 int startPosition, |
| 36 int endPosition, |
| 37 int closingPosition) {} |
| 38 } |
| 39 |
| 40 /// An interface for mapping code offsets with [SourceLocation]s for JavaScript |
| 41 /// [Node]s. |
| 42 abstract class SourceMapper { |
| 43 /// Associate [codeOffset] with [sourceLocation] for [node]. |
| 44 void register(Node node, int codeOffset, SourceLocation sourceLocation); |
| 45 } |
| 46 |
| 47 /// An implementation of [SourceMapper] that stores the information directly |
| 48 /// into a [SourceLocations] object. |
| 49 class SourceLocationsMapper implements SourceMapper { |
| 50 final SourceLocations sourceLocations; |
| 51 |
| 52 SourceLocationsMapper(this.sourceLocations); |
| 53 |
| 54 @override |
| 55 void register(Node node, int codeOffset, SourceLocation sourceLocation) { |
| 56 sourceLocations.addSourceLocation(codeOffset, sourceLocation); |
| 57 } |
| 58 } |
| 59 |
| 60 /// A processor that associates [SourceInformation] with code position of |
| 61 /// JavaScript [Node]s. |
| 62 class SourceInformationProcessor extends CodePositionListener { |
| 63 const SourceInformationProcessor(); |
| 64 |
| 65 /// Process the source information and code positions for the [node] and all |
| 66 /// its children. |
| 67 void process(Node node) {} |
| 68 } |
OLD | NEW |