From 87558873b5f6fec59b811dec189b8d532908f722 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Sun, 8 Apr 2018 00:53:28 +0300 Subject: [PATCH] Fix source element for JsSwitch generated from 'when' Before this change we set JsSwitch source to subject's JsExpression. We ignore these types of source elements during: 1. js ast serialization (see 'JsAstSerializer.extractLocation'); 2. source map generation (see 'SourceMapBuilderConsumer.addMapping'). However we might add indent during source generation (see 'JsToStringGenerationVisitor.pushSourceInfo'). That seemingly broken 'testEnumEntryRemoved' in 'IncrementalJsCompilerRunnerTestGenerated.ClassHierarchyAffected', because deserialized ast during incremental build would not have source element at all (JsExpression was ignored), but ast during rebuild would have JsExpression source element. --- .../jetbrains/kotlin/js/translate/expression/WhenTranslator.kt | 2 +- .../testData/lineNumbers/whenEntryWithMultipleConditions.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/expression/WhenTranslator.kt b/js/js.translator/src/org/jetbrains/kotlin/js/translate/expression/WhenTranslator.kt index 34e70d69a99..6e193e12348 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/expression/WhenTranslator.kt +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/expression/WhenTranslator.kt @@ -163,7 +163,7 @@ private constructor(private val whenExpression: KtWhenExpression, context: Trans lastEntry.statements += JsBreak().apply { source = entry } members } - Pair(JsSwitch(subjectSupplier(), switchEntries).apply { source = expression }, nextIndex) + Pair(JsSwitch(subjectSupplier(), switchEntries).apply { source = whenExpression }, nextIndex) } else { null diff --git a/js/js.translator/testData/lineNumbers/whenEntryWithMultipleConditions.kt b/js/js.translator/testData/lineNumbers/whenEntryWithMultipleConditions.kt index 43a4560d54e..e8ff31e3d36 100644 --- a/js/js.translator/testData/lineNumbers/whenEntryWithMultipleConditions.kt +++ b/js/js.translator/testData/lineNumbers/whenEntryWithMultipleConditions.kt @@ -18,4 +18,4 @@ fun box(x: Int) { ) } -// LINES: 19 4 4 3 4 6 9 9 6 11 13 13 11 16 16 3 2 \ No newline at end of file +// LINES: 19 4 4 3 3 4 6 9 9 6 11 13 13 11 16 16 3 2 \ No newline at end of file