1- var traceur = require ( 'traceur/src/node/traceur.js' ) ;
2- var ParseTreeVisitor = System . get ( System . map . traceur + '/src/syntax/ParseTreeVisitor' ) . ParseTreeVisitor ;
31var file2modulename = require ( '../../../tools/build/file2modulename' ) ;
42/**
53 * Wrapper around traceur that can parse the contents of a file
64 */
7- module . exports = function atParser ( log ) {
5+ module . exports = function atParser ( AttachCommentTreeVisitor , SourceFile , TraceurParser , traceurOptions , log ) {
86
97 var service = {
108 /**
@@ -33,16 +31,16 @@ module.exports = function atParser(log) {
3331 function parseModule ( fileInfo ) {
3432
3533 var moduleName = file2modulename ( fileInfo . relativePath ) ;
36- var sourceFile = new traceur . syntax . SourceFile ( moduleName , fileInfo . content ) ;
37- var parser = new traceur . syntax . Parser ( sourceFile ) ;
34+ var sourceFile = new SourceFile ( moduleName , fileInfo . content ) ;
3835 var comments = [ ] ;
3936 var moduleTree ;
37+ var parser = new TraceurParser ( sourceFile ) ;
4038
4139 // Configure the parser
4240 parser . handleComment = function ( range ) {
4341 comments . push ( { range : range } ) ;
4442 } ;
45- traceur . options . setFromObject ( service . traceurOptions ) ;
43+ traceurOptions . setFromObject ( service . traceurOptions ) ;
4644
4745 try {
4846 // Parse the file as a module, attaching the comments
@@ -69,29 +67,8 @@ module.exports = function atParser(log) {
6967 // attach the comments to their nearest code tree
7068 function attachComments ( tree , comments ) {
7169
72- var visitor = new ParseTreeVisitor ( ) ;
73- var index = 0 ;
74- var currentComment = comments [ index ] ;
75-
76- if ( currentComment ) log . silly ( 'comment: ' + currentComment . range . start . line + ' - ' + currentComment . range . end . line ) ;
77-
78- // Really we ought to subclass ParseTreeVisitor but this is fiddly in ES5 so
79- // it is easier to simply override the prototype's method on the instance
80- visitor . visitAny = function ( tree ) {
81- if ( tree && tree . location && tree . location . start && currentComment ) {
82- if ( currentComment . range . end . offset < tree . location . start . offset ) {
83- log . silly ( 'tree: ' + tree . constructor . name + ' - ' + tree . location . start . line ) ;
84- tree . commentBefore = currentComment ;
85- currentComment . treeAfter = tree ;
86- index ++ ;
87- currentComment = comments [ index ] ;
88- if ( currentComment ) log . silly ( 'comment: ' + currentComment . range . start . line + ' - ' + currentComment . range . end . line ) ;
89- }
90- }
91- return ParseTreeVisitor . prototype . visitAny . call ( this , tree ) ;
92- } ;
93-
70+ var visitor = new AttachCommentTreeVisitor ( ) ;
9471 // Visit every node of the tree using our custom method
95- visitor . visit ( tree ) ;
72+ visitor . visit ( tree , comments ) ;
9673 }
9774} ;
0 commit comments