chore: use CompositeBlock instead of GlobalBlock.

This commit is contained in:
Artem Kobzar
2022-03-16 16:18:19 +01:00
committed by teamcity
parent c6136619d2
commit 7ef14fc11b
28 changed files with 374 additions and 1049 deletions
@@ -1275,14 +1275,15 @@ public class JsToStringGenerationVisitor extends JsVisitor {
sourceLocationConsumer.pushSourceInfo(null);
boolean needBraces = !x.isGlobalBlock() && !x.isVirtualBlock();
boolean needBraces = !x.isTransparent();
if (needBraces) {
blockOpen();
}
Iterator<JsStatement> iterator = x.getStatements().iterator();
while (iterator.hasNext()) {
boolean isGlobal = x.isGlobalBlock() || globalBlocks.contains(x);
boolean isGlobal = x.isTransparent() || globalBlocks.contains(x);
JsStatement statement = iterator.next();
if (statement instanceof JsEmpty) {
@@ -43,12 +43,10 @@ public class JsBlock extends SourceInfoAwareJsNode implements JsStatement {
return statements.isEmpty();
}
public boolean isGlobalBlock() {
public boolean isTransparent() {
return false;
}
public boolean isVirtualBlock() { return false; }
@Override
public void accept(JsVisitor v) {
v.visitBlock(this);
@@ -18,5 +18,5 @@ package org.jetbrains.kotlin.js.backend.ast
class JsClassModel(val name: JsName, val superName: JsName?) {
val interfaces: MutableSet<JsName> = mutableSetOf()
val postDeclarationBlock = JsGlobalBlock()
val postDeclarationBlock = JsCompositeBlock()
}
@@ -7,15 +7,15 @@ import org.jetbrains.kotlin.js.util.AstUtil;
/**
* Represents a JavaScript block in the global scope.
* Represents a JavaScript block which could not be rendered into a material one.
*/
class JsVirtualBlock(statements: List<JsStatement> = emptyList()) : JsBlock(statements) {
override fun isVirtualBlock(): Boolean {
class JsCompositeBlock(statements: List<JsStatement> = mutableListOf()) : JsBlock(statements) {
override fun isTransparent(): Boolean {
return true
}
override fun deepCopy(): JsVirtualBlock {
val globalBlockCopy = JsVirtualBlock()
override fun deepCopy(): JsCompositeBlock {
val globalBlockCopy = JsCompositeBlock()
val statementscopy = AstUtil.deepCopy(statements);
globalBlockCopy.statements.addAll(statementscopy);
return globalBlockCopy.withMetadataFrom(this);
@@ -1,29 +0,0 @@
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
package org.jetbrains.kotlin.js.backend.ast;
import org.jetbrains.kotlin.js.util.AstUtil;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* Represents a JavaScript block in the global scope.
*/
public class JsGlobalBlock extends JsBlock {
@Override
public boolean isGlobalBlock() {
return true;
}
@NotNull
@Override
public JsGlobalBlock deepCopy() {
JsGlobalBlock globalBlockCopy = new JsGlobalBlock();
List<JsStatement> statementscopy = AstUtil.deepCopy(getStatements());
globalBlockCopy.getStatements().addAll(statementscopy);
return globalBlockCopy.withMetadataFrom(this);
}
}
@@ -10,7 +10,7 @@ import org.jetbrains.annotations.NotNull;
* A JavaScript program.
*/
public final class JsProgram extends SourceInfoAwareJsNode {
private final JsGlobalBlock globalBlock = new JsGlobalBlock();
private final JsCompositeBlock globalBlock = new JsCompositeBlock();
private final JsRootScope rootScope;
private final JsObjectScope topScope;
@@ -20,7 +20,7 @@ public final class JsProgram extends SourceInfoAwareJsNode {
topScope = new JsObjectScope(rootScope, "Global");
}
public JsGlobalBlock getGlobalBlock() {
public JsCompositeBlock getGlobalBlock() {
return globalBlock;
}
@@ -9,13 +9,13 @@ import java.util.*
class JsProgramFragment(val scope: JsScope, val packageFqn: String) {
val importedModules = mutableListOf<JsImportedModule>()
val imports: MutableMap<String, JsExpression> = LinkedHashMap()
val declarationBlock = JsGlobalBlock()
val exportBlock = JsGlobalBlock()
val initializerBlock = JsGlobalBlock()
val declarationBlock = JsCompositeBlock()
val exportBlock = JsCompositeBlock()
val initializerBlock = JsCompositeBlock()
val nameBindings = mutableListOf<JsNameBinding>()
val classes: MutableMap<JsName, JsClassModel> = LinkedHashMap()
val inlineModuleMap: MutableMap<String, JsExpression> = LinkedHashMap()
var tests: JsStatement? = null
var mainFunction: JsStatement? = null
val inlinedLocalDeclarations = mutableMapOf<String, JsGlobalBlock>()
val inlinedLocalDeclarations = mutableMapOf<String, JsCompositeBlock>()
}