@@ -829,10 +829,11 @@ fun Block.nexOuterLanguageBlock(block: Block): RootBlockWrapper? {
829829 return null
830830}
831831
832- open class SyntheticBlockWrapper (_block : Block , val hbsBlock : Block ? , val styleSettings : CodeStyleSettings ): Block by _block {
832+ open class SyntheticBlockWrapper (_block : Block , val hbsBlock : Block ? , val _parent : Block ? , val styleSettings : CodeStyleSettings ): Block by _block {
833833
834834 init {
835835 this .block = _block
836+ this .parent = _parent
836837 }
837838
838839 private var cachedBlocks: MutableList <Block >? = null
@@ -866,12 +867,12 @@ open class SyntheticBlockWrapper(_block: Block, val hbsBlock: Block?, val styleS
866867 return mapToWrapper(block.original)
867868 }
868869 if (block is RootBlockWrapper .SynteticBlockWrapper ) {
869- return JSAstBlockWrapper (block, block.parent.node!! , this , hbsBlock, styleSettings)
870+ return JSAstBlockWrapper (block, ( block.parent as RootBlockWrapper ) .node!! , this , hbsBlock, styleSettings)
870871 }
871872 if (block is JSBlock ) {
872- return JsBlockWrapper (block, block.node, this , hbsBlock, styleSettings)
873+ return JsBlockWrapper (block, block.node, block.parent , hbsBlock, styleSettings)
873874 }
874- return SyntheticBlockWrapper (block, hbsBlock, styleSettings)
875+ return SyntheticBlockWrapper (block, hbsBlock, this , styleSettings)
875876 }
876877
877878 override fun getSubBlocks (): MutableList <Block > {
@@ -937,19 +938,21 @@ open class JsBlockWrapper(_block: Block, nnode: ASTNode, _parent: Block?, var hb
937938 }
938939
939940 fun mapToWrapper (block : Block , hbsBlock : Block ? ): Block ? {
941+
940942 if (block is ASTBlock && block.node != null ) {
941943 return JSAstBlockWrapper (block, block.node!! , this , hbsBlock, styleSettings)
942944 }
943945 if (block is DataLanguageBlockWrapper ) {
944946 return mapToWrapper(block.original, hbsBlock)
945947 }
946948 if (block is RootBlockWrapper .SynteticBlockWrapper ) {
947- return JSAstBlockWrapper (block, block.parent.node!! , this , hbsBlock, styleSettings)
949+ return JSAstBlockWrapper (block, ( block.parent as RootBlockWrapper ) .node!! , this , hbsBlock, styleSettings)
948950 }
949951 if (block is JSBlock ) {
950952 return JsBlockWrapper (block, block.node, this , hbsBlock, styleSettings)
951953 }
952- return SyntheticBlockWrapper (block, hbsBlock, styleSettings)
954+
955+ return SyntheticBlockWrapper (block, hbsBlock, this , styleSettings)
953956 }
954957
955958 override fun getSubBlocks (): MutableList <Block > {
@@ -966,6 +969,7 @@ open class JsBlockWrapper(_block: Block, nnode: ASTNode, _parent: Block?, var hb
966969 }
967970
968971 val psiElement = this .node.psi
972+
969973 if (psiElement is JSVariable || (psiElement is JSExpressionStatement ) && psiElement.children.find { it is JSAssignmentExpression } != null ) {
970974 val last = PsiTreeUtil .collectElements(psiElement) { it is JSLiteralExpression }.lastOrNull()
971975 if (last is JSLiteralExpression && last.textLength == 0 && last.textOffset == psiElement.endOffset) {
@@ -985,13 +989,16 @@ class JSAstBlockWrapper(block: Block, nnode: ASTNode, parent: Block?, hbsBlock:
985989
986990}
987991
988- class RootBlockWrapper (val block : DataLanguageBlockWrapper , val policy : HtmlPolicy ): ASTBlock by block {
992+ class RootBlockWrapper (val _block : DataLanguageBlockWrapper , val policy : HtmlPolicy ): ASTBlock by _block {
989993
990994 var patched = false
991- var parent: Block ? = null
995+
996+ init {
997+ this .block = _block
998+ }
992999
9931000 override fun getDebugName (): String? {
994- return block .original.javaClass.simpleName
1001+ return _block .original.javaClass.simpleName
9951002 }
9961003
9971004 override fun getIndent (): Indent ? {
@@ -1002,27 +1009,32 @@ class RootBlockWrapper(val block: DataLanguageBlockWrapper, val policy: HtmlPoli
10021009 return NoWrap
10031010 }
10041011
1005- class SynteticBlockWrapper (val subblock : Block , val parent : RootBlockWrapper , val index : Any , val subblocks : MutableList <Block >): Block by subblock {
1012+ class SynteticBlockWrapper (val subblock : Block , val _parent : RootBlockWrapper , val index : Any , val subblocks : MutableList <Block >): Block by subblock {
1013+
1014+ init {
1015+ this .parent = _parent
1016+ }
10061017
10071018 override fun getWrap (): Wrap ? {
10081019 return NoWrap
10091020 }
10101021
10111022 override fun getIndent (): Indent {
1012- val shouldIndent = subblock.javaClass.simpleName == " HandlebarsBlock" || subblock.javaClass.simpleName == " HandlebarsTagBlock"
1013- var indent = parent.getBaseIndent(shouldIndent)
1023+ var shouldIndent = subblock.javaClass.simpleName == " HandlebarsBlock" || subblock.javaClass.simpleName == " HandlebarsTagBlock"
1024+ shouldIndent = shouldIndent || (subblock as ? DataLanguageBlockWrapper )?.original is SyntheticBlock
1025+ var indent = _parent .getBaseIndent(shouldIndent)
10141026 if (index == 0 ) {
1015- indent = parent .getBaseIndent()
1027+ indent = _parent .getBaseIndent()
10161028 }
10171029 if (index == subblocks.lastIndex) {
1018- indent = parent .getBaseIndent()
1030+ indent = _parent .getBaseIndent()
10191031 }
10201032 return indent!!
10211033 }
10221034 }
10231035
10241036 override fun getSubBlocks (): MutableList <Block > {
1025- val subblocks = (block.parent == null ).ifTrue { block .original.subBlocks } ? : block.subBlocks
1037+ val subblocks = (block.parent == null ).ifTrue { _block .original.subBlocks } ? : block.subBlocks
10261038 return subblocks.mapIndexed { index, it ->
10271039 SynteticBlockWrapper (it, this , index, subblocks)
10281040 }.toMutableList()
0 commit comments