[JS BE] Do not produce source mapping for fake KtElement

Fix [KT-26701], [KT-12935]
This commit is contained in:
Roman Artemev
2019-07-12 18:38:47 +03:00
committed by romanart
parent 12736edfc1
commit af45e1c5dc
7 changed files with 18 additions and 8 deletions
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.resolve.calls.callUtil
import com.intellij.psi.PsiElement
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.incremental.KotlinLookupLocation
@@ -246,6 +247,9 @@ val KtElement.isFakeElement: Boolean
return file is KtFile && file.doNotAnalyze != null
}
val PsiElement.isFakePsiElement: Boolean
get() = this is KtElement && isFakeElement
fun Call.isSafeCall(): Boolean {
if (this is CallTransformer.CallForImplicitInvoke) {
//implicit safe 'invoke'
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.js.backend.ast.JsImportedModule
import org.jetbrains.kotlin.js.backend.ast.metadata.*
import org.jetbrains.kotlin.js.backend.ast.metadata.LocalAlias
import org.jetbrains.kotlin.js.backend.ast.metadata.SpecialFunction
import org.jetbrains.kotlin.resolve.calls.callUtil.isFakePsiElement
import org.jetbrains.kotlin.serialization.js.ast.JsAstProtoBuf.*
import org.jetbrains.kotlin.serialization.js.ast.JsAstProtoBuf.BinaryOperation.Type.*
import org.jetbrains.kotlin.serialization.js.ast.JsAstProtoBuf.UnaryOperation.Type.*
@@ -666,7 +667,7 @@ class JsAstSerializer(private val jsAstValidator: ((JsProgramFragment, Set<JsNam
val source = node.source
return when (source) {
is JsLocationWithSource -> source.asSimpleLocation()
is PsiElement -> extractLocation(source)
is PsiElement -> if (!source.isFakePsiElement) extractLocation(source) else null
else -> null
}
}
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.js.test.utils
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.js.backend.ast.*
import org.jetbrains.kotlin.resolve.calls.callUtil.isFakePsiElement
class LineCollector : RecursiveJsVisitor() {
val lines = mutableListOf<Int?>()
@@ -34,10 +35,12 @@ class LineCollector : RecursiveJsVisitor() {
val source = node.source
val line = when (source) {
is PsiElement -> {
val file = source.containingFile
val offset = source.node.startOffset
val document = file.viewProvider.document!!
document.getLineNumber(offset)
if (!source.isFakePsiElement) {
val file = source.containingFile
val offset = source.node.startOffset
val document = file.viewProvider.document!!
document.getLineNumber(offset)
} else null
}
is JsLocationWithSource -> {
source.startLine
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.js.backend.ast.JsLocationWithSource;
import org.jetbrains.kotlin.js.sourceMap.SourceFilePathResolver;
import org.jetbrains.kotlin.js.sourceMap.SourceMapMappingConsumer;
import org.jetbrains.kotlin.js.translate.utils.PsiUtils;
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt;
import java.io.*;
import java.nio.charset.Charset;
@@ -87,6 +88,7 @@ public class SourceMapBuilderConsumer implements SourceLocationConsumer {
}
if (sourceInfo instanceof PsiElement) {
PsiElement element = (PsiElement) sourceInfo;
if (CallUtilKt.isFakePsiElement(element)) return;
try {
JsLocation location = PsiUtils.extractLocationFromPsi(element, pathResolver);
PsiFile psiFile = element.getContainingFile();
+1 -1
View File
@@ -14,4 +14,4 @@ suspend fun bar(): Unit {
println(a + b)
}
// LINES: 38 4 4 4 5 5 44 44 5 89 44 5 5 6 4 4 4 15 9 9 9 * 15 10 10 11 11 11 2 11 11 * 11 12 12 13 13 13 2 13 13 13 13 14 14 * 15 9 9 9 9
// LINES: 38 4 4 4 5 5 44 44 5 89 44 5 5 6 4 4 4 15 9 9 9 * 15 10 10 11 11 11 11 11 * 11 12 12 13 13 13 13 13 13 13 14 14 * 15 9 9 9 9
@@ -8,4 +8,4 @@ suspend fun foo() {
suspend fun delay() {
}
// LINES: 6 1 1 * 6 2 2 2 2 2 * 3 3 4 4 4 2 4 4 5 5 * 6 1 1 1 1 9
// LINES: 6 1 1 * 6 2 2 2 2 2 * 3 3 4 4 4 4 4 5 5 * 6 1 1 1 1 9
+1 -1
View File
@@ -15,4 +15,4 @@ class B {
}
}
// LINES: 3 4 5 * 4 4 4 2 * 8 11 10 10 15 14 14
// LINES: 3 4 5 * 4 4 4 * 8 11 10 10 15 14 14