JS: minor review fixes
This commit is contained in:
@@ -19,8 +19,7 @@ package org.jetbrains.kotlin.js.coroutine
|
||||
import org.jetbrains.kotlin.js.backend.ast.*
|
||||
import org.jetbrains.kotlin.js.backend.ast.metadata.coroutineMetadata
|
||||
import org.jetbrains.kotlin.js.backend.ast.metadata.isInlineableCoroutineBody
|
||||
import org.jetbrains.kotlin.js.inline.InlineSuspendFunctionSplitter
|
||||
import org.jetbrains.kotlin.js.inline.ImportInfoFragmentInliningScope
|
||||
import org.jetbrains.kotlin.js.inline.ImportIntoFragmentInliningScope
|
||||
import org.jetbrains.kotlin.js.translate.declaration.transformCoroutineMetadataToSpecialFunctions
|
||||
import org.jetbrains.kotlin.js.translate.expression.InlineMetadata
|
||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils
|
||||
@@ -72,7 +71,7 @@ class CoroutineTransformer : JsVisitorWithContextImpl() {
|
||||
fun transformCoroutines(fragments: Iterable<JsProgramFragment>) {
|
||||
val coroutineTransformer = CoroutineTransformer()
|
||||
for (fragment in fragments) {
|
||||
ImportInfoFragmentInliningScope.process(fragment) { scope ->
|
||||
ImportIntoFragmentInliningScope.process(fragment) { scope ->
|
||||
coroutineTransformer.accept(scope.allCode)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,14 +8,13 @@ package org.jetbrains.kotlin.js.inline
|
||||
import org.jetbrains.kotlin.js.backend.ast.*
|
||||
import org.jetbrains.kotlin.js.backend.ast.metadata.coroutineMetadata
|
||||
import org.jetbrains.kotlin.js.backend.ast.metadata.isInlineableCoroutineBody
|
||||
import org.jetbrains.kotlin.js.inline.util.FunctionWithWrapper
|
||||
import org.jetbrains.kotlin.js.translate.expression.InlineMetadata
|
||||
|
||||
// Goes through `suspend inline` function definitions and transforms into two entities:
|
||||
// 1. A `suspend` function definition, which could be invoked at run time
|
||||
// 2. A `suspend inline` function definition, which doesn't work at run time, but is understood by the inliner.
|
||||
class InlineSuspendFunctionSplitter(
|
||||
val scope: ImportInfoFragmentInliningScope
|
||||
val scope: ImportIntoFragmentInliningScope
|
||||
) : JsVisitorWithContextImpl() {
|
||||
|
||||
override fun visit(x: JsInvocation, ctx: JsContext<JsNode>): Boolean {
|
||||
|
||||
@@ -144,7 +144,7 @@ sealed class InliningScope {
|
||||
}
|
||||
}
|
||||
|
||||
class ImportInfoFragmentInliningScope private constructor(
|
||||
class ImportIntoFragmentInliningScope private constructor(
|
||||
override val fragment: JsProgramFragment
|
||||
) : InliningScope() {
|
||||
|
||||
@@ -231,8 +231,8 @@ class ImportInfoFragmentInliningScope private constructor(
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun process(fragment: JsProgramFragment, fn: (ImportInfoFragmentInliningScope) -> Unit) {
|
||||
val scope = ImportInfoFragmentInliningScope(fragment)
|
||||
fun process(fragment: JsProgramFragment, fn: (ImportIntoFragmentInliningScope) -> Unit) {
|
||||
val scope = ImportIntoFragmentInliningScope(fragment)
|
||||
fn(scope)
|
||||
|
||||
scope.apply {
|
||||
|
||||
@@ -27,7 +27,7 @@ class JsInliner(
|
||||
|
||||
fun process() {
|
||||
for (fragment in translationResult.newFragments) {
|
||||
ImportInfoFragmentInliningScope.process(fragment) { fragmentScope ->
|
||||
ImportIntoFragmentInliningScope.process(fragment) { fragmentScope ->
|
||||
InlineAstVisitor(this, fragmentScope).accept(fragmentScope.allCode)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +136,8 @@ fun collectDefinedNamesInAllScopes(scope: JsNode): Set<JsName> {
|
||||
|
||||
override fun visitFunction(x: JsFunction) {
|
||||
super.visitFunction(x)
|
||||
// TODO This is a hack
|
||||
// The order is important. `function foo` and `var foo = wrapfunction(..)` should yield JsName's in the same order.
|
||||
// TODO make more robust
|
||||
names += x.parameters.map { it.name }
|
||||
x.name?.let { names += it }
|
||||
}
|
||||
|
||||
@@ -169,6 +169,7 @@ class K2JSTranslator @JvmOverloads constructor(
|
||||
bindingTrace: BindingTrace,
|
||||
moduleDescriptor: ModuleDescriptor
|
||||
) {
|
||||
// TODO Maybe switch validation on for recompile
|
||||
if (incrementalResults == null && !shouldValidateJsAst) return
|
||||
|
||||
val serializer = JsAstSerializer(if (shouldValidateJsAst) ::validateJsAst else null) { file ->
|
||||
|
||||
Reference in New Issue
Block a user