@@ -1651,11 +1651,17 @@ namespace ts {
1651
1651
function emitPropertyAccessExpression ( node : PropertyAccessExpression ) {
1652
1652
let indentBeforeDot = false ;
1653
1653
let indentAfterDot = false ;
1654
+ const dotRangeFirstCommentStart = skipTrivia (
1655
+ currentSourceFile ! . text ,
1656
+ node . expression . end ,
1657
+ /*stopAfterLineBreak*/ false ,
1658
+ /*stopAtComments*/ true
1659
+ ) ;
1660
+ const dotRangeStart = skipTrivia ( currentSourceFile ! . text , dotRangeFirstCommentStart ) ;
1661
+ const dotRangeEnd = dotRangeStart + 1 ;
1654
1662
if ( ! ( getEmitFlags ( node ) & EmitFlags . NoIndentation ) ) {
1655
- const dotRangeStart = node . expression . end ;
1656
- const dotRangeEnd = skipTrivia ( currentSourceFile ! . text , node . expression . end ) + 1 ;
1657
1663
const dotToken = createToken ( SyntaxKind . DotToken ) ;
1658
- dotToken . pos = dotRangeStart ;
1664
+ dotToken . pos = node . expression . end ;
1659
1665
dotToken . end = dotRangeEnd ;
1660
1666
indentBeforeDot = needsIndentation ( node , node . expression , dotToken ) ;
1661
1667
indentAfterDot = needsIndentation ( node , dotToken , node . name ) ;
@@ -1664,7 +1670,8 @@ namespace ts {
1664
1670
emitExpression ( node . expression ) ;
1665
1671
increaseIndentIf ( indentBeforeDot , /*writeSpaceIfNotIndenting*/ false ) ;
1666
1672
1667
- const shouldEmitDotDot = ! indentBeforeDot && needsDotDotForPropertyAccess ( node . expression ) ;
1673
+ const dotHasCommentTrivia = dotRangeFirstCommentStart !== dotRangeStart ;
1674
+ const shouldEmitDotDot = ! indentBeforeDot && needsDotDotForPropertyAccess ( node . expression , dotHasCommentTrivia ) ;
1668
1675
if ( shouldEmitDotDot ) {
1669
1676
writePunctuation ( "." ) ;
1670
1677
}
@@ -1677,13 +1684,15 @@ namespace ts {
1677
1684
1678
1685
// 1..toString is a valid property access, emit a dot after the literal
1679
1686
// Also emit a dot if expression is a integer const enum value - it will appear in generated code as numeric literal
1680
- function needsDotDotForPropertyAccess ( expression : Expression ) {
1687
+ function needsDotDotForPropertyAccess ( expression : Expression , dotHasTrivia : boolean ) {
1681
1688
expression = skipPartiallyEmittedExpressions ( expression ) ;
1682
1689
if ( isNumericLiteral ( expression ) ) {
1683
1690
// check if numeric literal is a decimal literal that was originally written with a dot
1684
1691
const text = getLiteralTextOfNode ( < LiteralExpression > expression , /*neverAsciiEscape*/ true ) ;
1685
- return ! expression . numericLiteralFlags
1686
- && ! stringContains ( text , tokenToString ( SyntaxKind . DotToken ) ! ) ;
1692
+ // If he number will be printed verbatim and it doesn't already contain a dot, add one
1693
+ // if the expression doesn't have any comments that will be emitted.
1694
+ return ! expression . numericLiteralFlags && ! stringContains ( text , tokenToString ( SyntaxKind . DotToken ) ! ) &&
1695
+ ( ! dotHasTrivia || printerOptions . removeComments ) ;
1687
1696
}
1688
1697
else if ( isPropertyAccessExpression ( expression ) || isElementAccessExpression ( expression ) ) {
1689
1698
// check if constant enum value is integer
0 commit comments