[JS BE] Do not produce source mapping for fake KtElement
Fix [KT-26701], [KT-12935]
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.resolve.calls.callUtil
|
package org.jetbrains.kotlin.resolve.calls.callUtil
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.util.PsiTreeUtil
|
import com.intellij.psi.util.PsiTreeUtil
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.incremental.KotlinLookupLocation
|
import org.jetbrains.kotlin.incremental.KotlinLookupLocation
|
||||||
@@ -246,6 +247,9 @@ val KtElement.isFakeElement: Boolean
|
|||||||
return file is KtFile && file.doNotAnalyze != null
|
return file is KtFile && file.doNotAnalyze != null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val PsiElement.isFakePsiElement: Boolean
|
||||||
|
get() = this is KtElement && isFakeElement
|
||||||
|
|
||||||
fun Call.isSafeCall(): Boolean {
|
fun Call.isSafeCall(): Boolean {
|
||||||
if (this is CallTransformer.CallForImplicitInvoke) {
|
if (this is CallTransformer.CallForImplicitInvoke) {
|
||||||
//implicit safe 'invoke'
|
//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.*
|
||||||
import org.jetbrains.kotlin.js.backend.ast.metadata.LocalAlias
|
import org.jetbrains.kotlin.js.backend.ast.metadata.LocalAlias
|
||||||
import org.jetbrains.kotlin.js.backend.ast.metadata.SpecialFunction
|
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.*
|
||||||
import org.jetbrains.kotlin.serialization.js.ast.JsAstProtoBuf.BinaryOperation.Type.*
|
import org.jetbrains.kotlin.serialization.js.ast.JsAstProtoBuf.BinaryOperation.Type.*
|
||||||
import org.jetbrains.kotlin.serialization.js.ast.JsAstProtoBuf.UnaryOperation.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
|
val source = node.source
|
||||||
return when (source) {
|
return when (source) {
|
||||||
is JsLocationWithSource -> source.asSimpleLocation()
|
is JsLocationWithSource -> source.asSimpleLocation()
|
||||||
is PsiElement -> extractLocation(source)
|
is PsiElement -> if (!source.isFakePsiElement) extractLocation(source) else null
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.js.test.utils
|
|||||||
|
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.js.backend.ast.*
|
import org.jetbrains.kotlin.js.backend.ast.*
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.callUtil.isFakePsiElement
|
||||||
|
|
||||||
class LineCollector : RecursiveJsVisitor() {
|
class LineCollector : RecursiveJsVisitor() {
|
||||||
val lines = mutableListOf<Int?>()
|
val lines = mutableListOf<Int?>()
|
||||||
@@ -34,10 +35,12 @@ class LineCollector : RecursiveJsVisitor() {
|
|||||||
val source = node.source
|
val source = node.source
|
||||||
val line = when (source) {
|
val line = when (source) {
|
||||||
is PsiElement -> {
|
is PsiElement -> {
|
||||||
val file = source.containingFile
|
if (!source.isFakePsiElement) {
|
||||||
val offset = source.node.startOffset
|
val file = source.containingFile
|
||||||
val document = file.viewProvider.document!!
|
val offset = source.node.startOffset
|
||||||
document.getLineNumber(offset)
|
val document = file.viewProvider.document!!
|
||||||
|
document.getLineNumber(offset)
|
||||||
|
} else null
|
||||||
}
|
}
|
||||||
is JsLocationWithSource -> {
|
is JsLocationWithSource -> {
|
||||||
source.startLine
|
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.SourceFilePathResolver;
|
||||||
import org.jetbrains.kotlin.js.sourceMap.SourceMapMappingConsumer;
|
import org.jetbrains.kotlin.js.sourceMap.SourceMapMappingConsumer;
|
||||||
import org.jetbrains.kotlin.js.translate.utils.PsiUtils;
|
import org.jetbrains.kotlin.js.translate.utils.PsiUtils;
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
@@ -87,6 +88,7 @@ public class SourceMapBuilderConsumer implements SourceLocationConsumer {
|
|||||||
}
|
}
|
||||||
if (sourceInfo instanceof PsiElement) {
|
if (sourceInfo instanceof PsiElement) {
|
||||||
PsiElement element = (PsiElement) sourceInfo;
|
PsiElement element = (PsiElement) sourceInfo;
|
||||||
|
if (CallUtilKt.isFakePsiElement(element)) return;
|
||||||
try {
|
try {
|
||||||
JsLocation location = PsiUtils.extractLocationFromPsi(element, pathResolver);
|
JsLocation location = PsiUtils.extractLocationFromPsi(element, pathResolver);
|
||||||
PsiFile psiFile = element.getContainingFile();
|
PsiFile psiFile = element.getContainingFile();
|
||||||
|
|||||||
+1
-1
@@ -14,4 +14,4 @@ suspend fun bar(): Unit {
|
|||||||
println(a + b)
|
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() {
|
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
|
||||||
@@ -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
|
||||||
Reference in New Issue
Block a user