diff --git a/build.gradle.kts b/build.gradle.kts index c986096c99c..e07e642b9bb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -252,6 +252,7 @@ extra["compilerModules"] = arrayOf( ":compiler:incremental-compilation-impl", ":compiler:compiler.version", ":js:js.ast", + ":js:js.sourcemap", ":js:js.serializer", ":js:js.parser", ":js:js.config", diff --git a/compiler/cli/cli-js/build.gradle.kts b/compiler/cli/cli-js/build.gradle.kts index 5b0714676de..29bbfbecbeb 100644 --- a/compiler/cli/cli-js/build.gradle.kts +++ b/compiler/cli/cli-js/build.gradle.kts @@ -17,6 +17,7 @@ dependencies { compile(project(":js:js.translator")) compile(project(":js:js.serializer")) compile(project(":js:js.dce")) + compile(project(":js:js.sourcemap")) compileOnly(intellijCoreDep()) { includeJars("intellij-core") } } diff --git a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/dce/K2JSDce.kt b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/dce/K2JSDce.kt index bec311e0b37..269ebeb322b 100644 --- a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/dce/K2JSDce.kt +++ b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/dce/K2JSDce.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -13,7 +13,7 @@ import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.config.Services import org.jetbrains.kotlin.js.dce.* -import org.jetbrains.kotlin.js.inline.util.RelativePathCalculator +import org.jetbrains.kotlin.js.sourceMap.RelativePathCalculator import org.jetbrains.kotlin.js.parser.sourcemaps.* import java.io.* import java.util.zip.ZipFile diff --git a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/internal/JSStdlibLinker.kt b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/internal/JSStdlibLinker.kt index c9cfdd23a6c..b678fbd1112 100644 --- a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/internal/JSStdlibLinker.kt +++ b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/internal/JSStdlibLinker.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -9,7 +9,7 @@ package org.jetbrains.kotlin.cli.js.internal import com.google.gwt.dev.js.ThrowExceptionOnErrorReporter import org.jetbrains.kotlin.js.backend.JsToStringGenerationVisitor import org.jetbrains.kotlin.js.backend.ast.* -import org.jetbrains.kotlin.js.facade.SourceMapBuilderConsumer +import org.jetbrains.kotlin.js.sourceMap.SourceMapBuilderConsumer import org.jetbrains.kotlin.js.inline.util.fixForwardNameReferences import org.jetbrains.kotlin.js.parser.parse import org.jetbrains.kotlin.js.parser.sourcemaps.* @@ -17,7 +17,6 @@ import org.jetbrains.kotlin.js.sourceMap.SourceFilePathResolver import org.jetbrains.kotlin.js.sourceMap.SourceMap3Builder import org.jetbrains.kotlin.js.util.TextOutputImpl import java.io.File -import java.io.StringReader import kotlin.system.exitProcess fun main(args: Array) { @@ -133,4 +132,4 @@ private fun collectFiles(rootFile: File, target: MutableList) { } else if (rootFile.extension == "js") { target += rootFile } -} \ No newline at end of file +} diff --git a/js/js.dce/build.gradle.kts b/js/js.dce/build.gradle.kts index d49789c44d2..96c2d034a5c 100644 --- a/js/js.dce/build.gradle.kts +++ b/js/js.dce/build.gradle.kts @@ -8,6 +8,7 @@ dependencies { compile(project(":compiler:util")) compile(project(":js:js.ast")) compile(project(":js:js.translator")) + compileOnly(project(":js:js.sourcemap")) compileOnly(intellijCoreDep()) { includeJars("intellij-core") } compileOnly(intellijDep()) { includeJars("guava", rootProject = rootProject) } } diff --git a/js/js.dce/src/org/jetbrains/kotlin/js/dce/DeadCodeElimination.kt b/js/js.dce/src/org/jetbrains/kotlin/js/dce/DeadCodeElimination.kt index 789c5f2e815..7693534b680 100644 --- a/js/js.dce/src/org/jetbrains/kotlin/js/dce/DeadCodeElimination.kt +++ b/js/js.dce/src/org/jetbrains/kotlin/js/dce/DeadCodeElimination.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.js.dce @@ -24,7 +13,7 @@ import org.jetbrains.kotlin.js.backend.ast.JsGlobalBlock import org.jetbrains.kotlin.js.backend.ast.JsNode import org.jetbrains.kotlin.js.backend.ast.JsProgram import org.jetbrains.kotlin.js.dce.Context.Node -import org.jetbrains.kotlin.js.facade.SourceMapBuilderConsumer +import org.jetbrains.kotlin.js.sourceMap.SourceMapBuilderConsumer import org.jetbrains.kotlin.js.inline.util.collectDefinedNames import org.jetbrains.kotlin.js.inline.util.fixForwardNameReferences import org.jetbrains.kotlin.js.parser.parse @@ -159,4 +148,4 @@ class DeadCodeElimination( } } } -} \ No newline at end of file +} diff --git a/js/js.inliner/src/org/jetbrains/kotlin/js/inline/FunctionReader.kt b/js/js.inliner/src/org/jetbrains/kotlin/js/inline/FunctionReader.kt index 6fce51360b4..942eefe6c4b 100644 --- a/js/js.inliner/src/org/jetbrains/kotlin/js/inline/FunctionReader.kt +++ b/js/js.inliner/src/org/jetbrains/kotlin/js/inline/FunctionReader.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.js.inline @@ -29,6 +18,7 @@ import org.jetbrains.kotlin.js.inline.util.* import org.jetbrains.kotlin.js.parser.OffsetToSourceMapping import org.jetbrains.kotlin.js.parser.parseFunction import org.jetbrains.kotlin.js.parser.sourcemaps.* +import org.jetbrains.kotlin.js.sourceMap.RelativePathCalculator import org.jetbrains.kotlin.js.translate.context.Namer import org.jetbrains.kotlin.js.translate.expression.InlineMetadata import org.jetbrains.kotlin.js.translate.utils.JsAstUtils diff --git a/js/js.sourcemap/build.gradle.kts b/js/js.sourcemap/build.gradle.kts new file mode 100644 index 00000000000..4b64d759441 --- /dev/null +++ b/js/js.sourcemap/build.gradle.kts @@ -0,0 +1,17 @@ +plugins { + kotlin("jvm") + id("jps-compatible") +} + +dependencies { + compileOnly(project(":js:js.ast")) + compileOnly(project(":js:js.parser")) // TODO remove, required for JSON AST + compileOnly(project(":js:js.frontend")) // TODO remove + compileOnly(intellijCoreDep()) { includeJars("intellij-core") } + compileOnly(intellijDep()) { includeJars("trove4j") } +} + +sourceSets { + "main" { projectDefault() } + "test" {} +} diff --git a/js/js.sourcemap/src/org/jetbrains/kotlin/js/sourceMap/PsiUtils.java b/js/js.sourcemap/src/org/jetbrains/kotlin/js/sourceMap/PsiUtils.java new file mode 100644 index 00000000000..8abbaddbe77 --- /dev/null +++ b/js/js.sourcemap/src/org/jetbrains/kotlin/js/sourceMap/PsiUtils.java @@ -0,0 +1,35 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.js.sourceMap; + +import com.intellij.openapi.editor.Document; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.kotlin.js.backend.ast.JsLocation; + +import java.io.File; +import java.io.IOException; + +public final class PsiUtils { + + private PsiUtils() { + } + + @NotNull + public static JsLocation extractLocationFromPsi(@NotNull PsiElement element, @NotNull SourceFilePathResolver pathResolver) + throws IOException { + PsiFile psiFile = element.getContainingFile(); + int offset = element.getNode().getStartOffset(); + Document document = psiFile.getViewProvider().getDocument(); + assert document != null; + int sourceLine = document.getLineNumber(offset); + int sourceColumn = offset - document.getLineStartOffset(sourceLine); + + File file = new File(psiFile.getViewProvider().getVirtualFile().getPath()); + return new JsLocation(pathResolver.getPathRelativeToSourceRoots(file), sourceLine, sourceColumn); + } +} diff --git a/js/js.inliner/src/org/jetbrains/kotlin/js/inline/util/RelativePathCalculator.kt b/js/js.sourcemap/src/org/jetbrains/kotlin/js/sourceMap/RelativePathCalculator.kt similarity index 55% rename from js/js.inliner/src/org/jetbrains/kotlin/js/inline/util/RelativePathCalculator.kt rename to js/js.sourcemap/src/org/jetbrains/kotlin/js/sourceMap/RelativePathCalculator.kt index 00365482762..53ee42952d1 100644 --- a/js/js.inliner/src/org/jetbrains/kotlin/js/inline/util/RelativePathCalculator.kt +++ b/js/js.sourcemap/src/org/jetbrains/kotlin/js/sourceMap/RelativePathCalculator.kt @@ -1,20 +1,9 @@ /* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -package org.jetbrains.kotlin.js.inline.util +package org.jetbrains.kotlin.js.sourceMap import java.io.File @@ -38,4 +27,4 @@ class RelativePathCalculator(baseDir: File) { return sb.toString() } -} \ No newline at end of file +} diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/sourceMap/SourceFilePathResolver.java b/js/js.sourcemap/src/org/jetbrains/kotlin/js/sourceMap/SourceFilePathResolver.java similarity index 81% rename from js/js.translator/src/org/jetbrains/kotlin/js/sourceMap/SourceFilePathResolver.java rename to js/js.sourcemap/src/org/jetbrains/kotlin/js/sourceMap/SourceFilePathResolver.java index 7f10a1386ab..abcf1f7a219 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/sourceMap/SourceFilePathResolver.java +++ b/js/js.sourcemap/src/org/jetbrains/kotlin/js/sourceMap/SourceFilePathResolver.java @@ -1,17 +1,6 @@ /* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.js.sourceMap; @@ -21,7 +10,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.js.config.JSConfigurationKeys; import org.jetbrains.kotlin.js.config.JsConfig; -import org.jetbrains.kotlin.js.inline.util.RelativePathCalculator; import java.io.File; import java.io.IOException; diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/sourceMap/SourceMap3Builder.java b/js/js.sourcemap/src/org/jetbrains/kotlin/js/sourceMap/SourceMap3Builder.java similarity index 93% rename from js/js.translator/src/org/jetbrains/kotlin/js/sourceMap/SourceMap3Builder.java rename to js/js.sourcemap/src/org/jetbrains/kotlin/js/sourceMap/SourceMap3Builder.java index f01d500e0b0..e9ccf129e7d 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/sourceMap/SourceMap3Builder.java +++ b/js/js.sourcemap/src/org/jetbrains/kotlin/js/sourceMap/SourceMap3Builder.java @@ -1,17 +1,6 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.js.sourceMap; diff --git a/js/js.sourcemap/src/org/jetbrains/kotlin/js/sourceMap/SourceMapBuilder.java b/js/js.sourcemap/src/org/jetbrains/kotlin/js/sourceMap/SourceMapBuilder.java new file mode 100644 index 00000000000..f0a7ea73ef9 --- /dev/null +++ b/js/js.sourcemap/src/org/jetbrains/kotlin/js/sourceMap/SourceMapBuilder.java @@ -0,0 +1,18 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.js.sourceMap; + +import java.io.File; + +public interface SourceMapBuilder extends SourceMapMappingConsumer { + void skipLinesAtBeginning(int count); + + void addLink(); + + File getOutFile(); + + String build(); +} diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/facade/SourceMapBuilderConsumer.java b/js/js.sourcemap/src/org/jetbrains/kotlin/js/sourceMap/SourceMapBuilderConsumer.java similarity index 84% rename from js/js.translator/src/org/jetbrains/kotlin/js/facade/SourceMapBuilderConsumer.java rename to js/js.sourcemap/src/org/jetbrains/kotlin/js/sourceMap/SourceMapBuilderConsumer.java index b6a63e6a5eb..66f6452d87c 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/facade/SourceMapBuilderConsumer.java +++ b/js/js.sourcemap/src/org/jetbrains/kotlin/js/sourceMap/SourceMapBuilderConsumer.java @@ -1,20 +1,9 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -package org.jetbrains.kotlin.js.facade; +package org.jetbrains.kotlin.js.sourceMap; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; @@ -23,9 +12,6 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.js.backend.SourceLocationConsumer; import org.jetbrains.kotlin.js.backend.ast.JsLocation; 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.*; diff --git a/js/js.sourcemap/src/org/jetbrains/kotlin/js/sourceMap/SourceMapMappingConsumer.java b/js/js.sourcemap/src/org/jetbrains/kotlin/js/sourceMap/SourceMapMappingConsumer.java new file mode 100644 index 00000000000..d2294bcfdff --- /dev/null +++ b/js/js.sourcemap/src/org/jetbrains/kotlin/js/sourceMap/SourceMapMappingConsumer.java @@ -0,0 +1,23 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.js.sourceMap; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.io.Reader; +import java.util.function.Supplier; + +public interface SourceMapMappingConsumer { + void newLine(); + + void addMapping( + @NotNull String source, @Nullable Object sourceIdentity, @NotNull Supplier sourceSupplier, + int sourceLine, int sourceColumn + ); + + void addEmptyMapping(); +} diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicBoxTest.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicBoxTest.kt index 7f99df4035f..5b3f3357ffa 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicBoxTest.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicBoxTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -41,6 +41,7 @@ import org.jetbrains.kotlin.js.parser.sourcemaps.SourceMapParser import org.jetbrains.kotlin.js.parser.sourcemaps.SourceMapSuccess import org.jetbrains.kotlin.js.sourceMap.SourceFilePathResolver import org.jetbrains.kotlin.js.sourceMap.SourceMap3Builder +import org.jetbrains.kotlin.js.sourceMap.SourceMapBuilderConsumer import org.jetbrains.kotlin.js.test.utils.* import org.jetbrains.kotlin.js.util.TextOutputImpl import org.jetbrains.kotlin.metadata.DebugProtoBuf diff --git a/js/js.translator/build.gradle.kts b/js/js.translator/build.gradle.kts index a7b7095a635..d00ab322ef8 100644 --- a/js/js.translator/build.gradle.kts +++ b/js/js.translator/build.gradle.kts @@ -14,6 +14,7 @@ dependencies { compile(project(":js:js.ast")) compile(project(":js:js.frontend")) compile(project(":js:js.parser")) + compileOnly(project(":js:js.sourcemap")) compileOnly(intellijCoreDep()) { includeJars("intellij-core") } compileOnly(intellijDep()) { includeJars("trove4j", "guava", rootProject = rootProject) } } @@ -30,4 +31,4 @@ configure { module { excludeDirs = excludeDirs + files("testData/out", "testData/out-min") } -} \ No newline at end of file +} diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/facade/TranslationResult.kt b/js/js.translator/src/org/jetbrains/kotlin/js/facade/TranslationResult.kt index 268260a1a62..9dbd8a7c1d6 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/facade/TranslationResult.kt +++ b/js/js.translator/src/org/jetbrains/kotlin/js/facade/TranslationResult.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.js.facade @@ -31,6 +20,7 @@ import org.jetbrains.kotlin.js.config.JsConfig import org.jetbrains.kotlin.js.config.SourceMapSourceEmbedding import org.jetbrains.kotlin.js.sourceMap.SourceFilePathResolver import org.jetbrains.kotlin.js.sourceMap.SourceMap3Builder +import org.jetbrains.kotlin.js.sourceMap.SourceMapBuilderConsumer import org.jetbrains.kotlin.js.util.TextOutput import org.jetbrains.kotlin.js.util.TextOutputImpl import org.jetbrains.kotlin.name.FqName @@ -185,4 +175,4 @@ abstract class TranslationResult protected constructor(val diagnostics: Diagnost return SimpleOutputFileCollection(metadataFiles(outputFile)) } } -} \ No newline at end of file +} diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/sourceMap/SourceMapBuilder.java b/js/js.translator/src/org/jetbrains/kotlin/js/sourceMap/SourceMapBuilder.java deleted file mode 100644 index 7838c224975..00000000000 --- a/js/js.translator/src/org/jetbrains/kotlin/js/sourceMap/SourceMapBuilder.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.js.sourceMap; - -import java.io.File; - -public interface SourceMapBuilder extends SourceMapMappingConsumer { - void skipLinesAtBeginning(int count); - - void addLink(); - - File getOutFile(); - - String build(); -} diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/sourceMap/SourceMapMappingConsumer.java b/js/js.translator/src/org/jetbrains/kotlin/js/sourceMap/SourceMapMappingConsumer.java deleted file mode 100644 index 057b4c3f428..00000000000 --- a/js/js.translator/src/org/jetbrains/kotlin/js/sourceMap/SourceMapMappingConsumer.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.js.sourceMap; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.io.IOException; -import java.io.Reader; -import java.util.function.Supplier; - -public interface SourceMapMappingConsumer { - void newLine(); - - void addMapping( - @NotNull String source, @Nullable Object sourceIdentity, @NotNull Supplier sourceSupplier, - int sourceLine, int sourceColumn - ); - - void addEmptyMapping(); -} diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/reference/CallExpressionTranslator.java b/js/js.translator/src/org/jetbrains/kotlin/js/translate/reference/CallExpressionTranslator.java index 497714af80e..fb4776664ac 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/reference/CallExpressionTranslator.java +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/reference/CallExpressionTranslator.java @@ -1,17 +1,6 @@ /* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.js.translate.reference; @@ -29,9 +18,9 @@ import org.jetbrains.kotlin.js.inline.util.RewriteUtilsKt; import org.jetbrains.kotlin.js.parser.ParserUtilsKt; import org.jetbrains.kotlin.js.resolve.BindingContextSlicesJsKt; import org.jetbrains.kotlin.js.resolve.diagnostics.JsCallChecker; +import org.jetbrains.kotlin.js.sourceMap.PsiUtils; import org.jetbrains.kotlin.js.translate.callTranslator.CallTranslator; import org.jetbrains.kotlin.js.translate.context.TranslationContext; -import org.jetbrains.kotlin.js.translate.utils.PsiUtils; import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.psi.KtCallExpression; import org.jetbrains.kotlin.psi.KtExpression; diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/PsiUtils.java b/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/PsiUtils.java index 3081fbb68aa..f1ae68fe25f 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/PsiUtils.java +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/PsiUtils.java @@ -1,38 +1,20 @@ /* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.js.translate.utils; -import com.intellij.openapi.editor.Document; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; import com.intellij.psi.tree.IElementType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.descriptors.CallableDescriptor; -import org.jetbrains.kotlin.js.backend.ast.JsLocation; -import org.jetbrains.kotlin.js.sourceMap.SourceFilePathResolver; import org.jetbrains.kotlin.lexer.KtToken; import org.jetbrains.kotlin.lexer.KtTokens; import org.jetbrains.kotlin.psi.*; import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall; import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall; -import java.io.File; -import java.io.IOException; import java.util.Collections; import java.util.List; @@ -120,18 +102,4 @@ public final class PsiUtils { return resolvedCall.getCandidateDescriptor(); } - - @NotNull - public static JsLocation extractLocationFromPsi(@NotNull PsiElement element, @NotNull SourceFilePathResolver pathResolver) - throws IOException { - PsiFile psiFile = element.getContainingFile(); - int offset = element.getNode().getStartOffset(); - Document document = psiFile.getViewProvider().getDocument(); - assert document != null; - int sourceLine = document.getLineNumber(offset); - int sourceColumn = offset - document.getLineStartOffset(sourceLine); - - File file = new File(psiFile.getViewProvider().getVirtualFile().getPath()); - return new JsLocation(pathResolver.getPathRelativeToSourceRoots(file), sourceLine, sourceColumn); - } } diff --git a/settings.gradle b/settings.gradle index cfac40a06d0..bca01c8804c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -133,6 +133,7 @@ include ":benchmarks", ":compiler:tests-for-compiler-generator", ":dukat", ":js:js.ast", + ":js:js.sourcemap", ":js:js.serializer", ":js:js.parser", ":js:js.config",