Skip to content

Commit 8e66ae4

Browse files
helixbassGeoffreyBooth
authored andcommitted
fix JSX expression indentation bug (#5056)
* fix JSX expression indentation bug * fixes from code review * tweak test
1 parent 7beb631 commit 8e66ae4

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

lib/coffeescript/lexer.js

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lexer.coffee

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,8 @@ exports.Lexer = class Lexer
794794

795795
# Remove leading `'TERMINATOR'` (if any).
796796
nested.splice 1, 1 if nested[1]?[0] is 'TERMINATOR'
797+
# Remove trailing `'INDENT'/'OUTDENT'` pair (if any).
798+
nested.splice -3, 2 if nested[nested.length - 3]?[0] is 'INDENT' and nested[nested.length - 2][0] is 'OUTDENT'
797799

798800
unless braceInterpolator
799801
# We are not using `{` and `}`, so wrap the interpolated tokens instead.

test/csx.coffee

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,3 +786,38 @@ test 'JSX fragments: fragment with component nodes', ->
786786
</Fragment>;
787787
};
788788
'''
789+
790+
test '#5055: JSX expression indentation bug', ->
791+
eqJS '''
792+
<div>
793+
{someCondition &&
794+
<span />
795+
}
796+
</div>
797+
''', '''
798+
<div>
799+
{someCondition && <span />}
800+
</div>;
801+
'''
802+
803+
eqJS '''
804+
<div>{someString +
805+
"abc"
806+
}
807+
</div>
808+
''', '''
809+
<div>{someString + "abc"}
810+
</div>;
811+
'''
812+
813+
eqJS '''
814+
<div>
815+
{a ?
816+
<span />
817+
}
818+
</div>
819+
''', '''
820+
<div>
821+
{typeof a !== "undefined" && a !== null ? a : <span />}
822+
</div>;
823+
'''

0 commit comments

Comments
 (0)