@@ -822,11 +822,11 @@ function handleWhileComments(
822822 return false ;
823823}
824824
825- // https://github.com/prettier/prettier/blob/master /src/main/comments.js#L335
826- function printComment ( commentPath , options ) {
827- const comment = commentPath . getValue ( ) ;
825+ // https://github.com/prettier/prettier/blob/c01661f311a2e1e033f1f9cb127882cc13e293bd /src/main/comments/print .js#L23
826+ function printComment ( path , options ) {
827+ const comment = path . node ;
828828 comment . printed = true ;
829- return options . printer . printComment ( commentPath , options ) ;
829+ return options . printer . printComment ( path , options ) ;
830830}
831831
832832// https://github.com/prettier/prettier/blob/master/src/main/comments.js#L440
@@ -838,15 +838,15 @@ function printDanglingComments(path, options, sameIndent, filter) {
838838 return "" ;
839839 }
840840
841- path . each ( ( commentPath ) => {
842- const comment = commentPath . getValue ( ) ;
841+ path . each ( ( ) => {
842+ const comment = path . node ;
843843 if (
844844 comment &&
845845 ! comment . leading &&
846846 ! comment . trailing &&
847847 ( ! filter || filter ( comment ) )
848848 ) {
849- parts . push ( printComment ( commentPath , options ) ) ;
849+ parts . push ( printComment ( path , options ) ) ;
850850 }
851851 } , "comments" ) ;
852852
@@ -917,21 +917,22 @@ function canAttachComment(node) {
917917// Based on https://github.com/prettier/prettier/blob/master/src/main/comments.js
918918// TODO remove after https://github.com/prettier/prettier/issues/5087
919919function prependCursorPlaceholder ( path , options , printed ) {
920- if ( path . getNode ( ) === options . cursorNode && path . getValue ( ) ) {
920+ const { node } = path ;
921+ if ( node && node === options . cursorNode ) {
921922 return [ cursor , printed , cursor ] ;
922923 }
923924
924925 return printed ;
925926}
926927
927- function printLeadingComment ( commentPath , print , options ) {
928- const comment = commentPath . getValue ( ) ;
929- const contents = printComment ( commentPath , options ) ;
928+ function printLeadingComment ( path , print , options ) {
929+ const contents = printComment ( path , options ) ;
930930
931931 if ( ! contents ) {
932932 return "" ;
933933 }
934934
935+ const comment = path . node ;
935936 const isBlock =
936937 options . printer . isBlockComment && options . printer . isBlockComment ( comment ) ;
937938
@@ -949,12 +950,13 @@ function printLeadingComment(commentPath, print, options) {
949950 return [ contents , hardline ] ;
950951}
951952
952- function printTrailingComment ( commentPath , print , options ) {
953- const comment = commentPath . getValue ( ) ;
954- const contents = printComment ( commentPath , options ) ;
953+ function printTrailingComment ( path , print , options ) {
954+ const contents = printComment ( path , options ) ;
955955 if ( ! contents ) {
956956 return "" ;
957957 }
958+
959+ const comment = path . node ;
958960 const isBlock =
959961 options . printer . isBlockComment && options . printer . isBlockComment ( comment ) ;
960962
@@ -991,9 +993,9 @@ function printTrailingComment(commentPath, print, options) {
991993}
992994
993995function printAllComments ( path , print , options , needsSemi ) {
994- const value = path . getValue ( ) ;
996+ const { node } = path ;
995997 const printed = print ( path ) ;
996- const comments = value && value . comments ;
998+ const comments = node && node . comments ;
997999
9981000 if ( ! comments || comments . length === 0 ) {
9991001 return prependCursorPlaceholder ( path , options , printed ) ;
@@ -1002,12 +1004,11 @@ function printAllComments(path, print, options, needsSemi) {
10021004 const leadingParts = [ ] ;
10031005 const trailingParts = [ needsSemi ? ";" : "" , printed ] ;
10041006
1005- path . each ( ( commentPath ) => {
1006- const comment = commentPath . getValue ( ) ;
1007+ path . each ( ( { node : comment } ) => {
10071008 const { leading, trailing } = comment ;
10081009
10091010 if ( leading ) {
1010- const contents = printLeadingComment ( commentPath , print , options ) ;
1011+ const contents = printLeadingComment ( path , print , options ) ;
10111012 if ( ! contents ) {
10121013 return ;
10131014 }
@@ -1018,7 +1019,7 @@ function printAllComments(path, print, options, needsSemi) {
10181019 leadingParts . push ( hardline ) ;
10191020 }
10201021 } else if ( trailing ) {
1021- trailingParts . push ( printTrailingComment ( commentPath , print , options ) ) ;
1022+ trailingParts . push ( printTrailingComment ( path , print , options ) ) ;
10221023 }
10231024 } , "comments" ) ;
10241025
0 commit comments