JS: make JsEmpty singleton
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
package com.google.dart.compiler.backend.js.ast
|
||||
|
||||
public class JsEmpty : SourceInfoAwareJsNode(), JsStatement {
|
||||
public object JsEmpty : SourceInfoAwareJsNode(), JsStatement {
|
||||
|
||||
override fun accept(v: JsVisitor) {
|
||||
v.visitEmpty(this)
|
||||
|
||||
@@ -26,7 +26,7 @@ public class JsEmptyExpression extends JsExpressionImpl {
|
||||
@Override
|
||||
@NotNull
|
||||
public JsStatement makeStmt() {
|
||||
return new JsEmpty();
|
||||
return JsEmpty.INSTANCE$;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,8 +18,6 @@ import static com.google.dart.compiler.backend.js.ast.JsNumberLiteral.JsIntLiter
|
||||
* A JavaScript program.
|
||||
*/
|
||||
public final class JsProgram extends SourceInfoAwareJsNode {
|
||||
@NotNull
|
||||
private final JsEmpty emptyStatement;
|
||||
@NotNull final JsExpression emptyExpression;
|
||||
|
||||
private JsProgramFragment[] fragments;
|
||||
@@ -36,15 +34,9 @@ public final class JsProgram extends SourceInfoAwareJsNode {
|
||||
topScope = new JsObjectScope(rootScope, "Global", unitId);
|
||||
setFragmentCount(1);
|
||||
|
||||
emptyStatement = new JsEmpty();
|
||||
emptyExpression = new JsEmptyExpression();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JsEmpty getEmptyStatement() {
|
||||
return emptyStatement;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JsExpression getEmptyExpression() {
|
||||
return emptyExpression;
|
||||
|
||||
@@ -283,12 +283,6 @@ public class JsInliner extends JsVisitorWithContextImpl {
|
||||
return getLastStatementLevelContext();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected JsStatement getEmptyStatement() {
|
||||
return getFunctionContext().getEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shiftCurrentStatementForward() {
|
||||
super.shiftCurrentStatementForward();
|
||||
|
||||
@@ -52,10 +52,6 @@ abstract class FunctionContext(
|
||||
return getFunctionDefinitionImpl(call) != null
|
||||
}
|
||||
|
||||
public fun getEmpty(): JsEmpty {
|
||||
return getScope().getProgram()?.getEmptyStatement()!!
|
||||
}
|
||||
|
||||
public fun getScope(): JsScope {
|
||||
return function.getScope()
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.js.inline.context
|
||||
|
||||
import com.google.dart.compiler.backend.js.ast.JsContext
|
||||
import com.google.dart.compiler.backend.js.ast.JsEmpty
|
||||
import com.google.dart.compiler.backend.js.ast.JsStatement
|
||||
|
||||
abstract class StatementContext {
|
||||
@@ -28,20 +29,18 @@ abstract class StatementContext {
|
||||
|
||||
public fun removeCurrentStatement() {
|
||||
val statementContext = getCurrentStatementContext()
|
||||
statementContext.replaceMe(getEmptyStatement())
|
||||
statementContext.replaceMe(JsEmpty)
|
||||
}
|
||||
|
||||
open public fun shiftCurrentStatementForward() {
|
||||
val statementContext = getCurrentStatementContext()
|
||||
val currentStatement = getCurrentStatement()
|
||||
statementContext.insertAfter(currentStatement)
|
||||
statementContext.replaceMe(getEmptyStatement())
|
||||
statementContext.replaceMe(JsEmpty)
|
||||
}
|
||||
|
||||
public fun getCurrentStatement(): JsStatement {
|
||||
val statementContext = getCurrentStatementContext()
|
||||
return statementContext.getCurrentNode() as JsStatement
|
||||
}
|
||||
|
||||
protected abstract fun getEmptyStatement(): JsStatement
|
||||
}
|
||||
|
||||
@@ -517,7 +517,7 @@ public class JsAstMapper {
|
||||
toForIn.setBody(bodyStmt);
|
||||
}
|
||||
else {
|
||||
toForIn.setBody(program.getEmptyStatement());
|
||||
toForIn.setBody(JsEmpty.INSTANCE$);
|
||||
}
|
||||
|
||||
return toForIn;
|
||||
@@ -545,7 +545,7 @@ public class JsAstMapper {
|
||||
toFor.setBody(bodyStmt);
|
||||
}
|
||||
else {
|
||||
toFor.setBody(program.getEmptyStatement());
|
||||
toFor.setBody(JsEmpty.INSTANCE$);
|
||||
}
|
||||
return toFor;
|
||||
}
|
||||
@@ -892,7 +892,7 @@ public class JsAstMapper {
|
||||
else {
|
||||
// When map() returns null, we return an empty statement.
|
||||
//
|
||||
return program.getEmptyStatement();
|
||||
return JsEmpty.INSTANCE$;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -302,11 +302,6 @@ public class TranslationContext {
|
||||
return dynamicContext.jsBlock();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JsEmpty getEmptyStatement() {
|
||||
return program().getEmptyStatement();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JsExpression getEmptyExpression() {
|
||||
return program().getEmptyExpression();
|
||||
|
||||
+1
-1
@@ -154,7 +154,7 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
if (expressionInside != null) {
|
||||
return Translation.translateExpression(expressionInside, context);
|
||||
}
|
||||
return context.getEmptyStatement();
|
||||
return JsEmpty.INSTANCE$;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -45,7 +45,7 @@ public fun createWhile(doWhile: Boolean, expression: JetWhileExpressionBase, con
|
||||
if (body != null)
|
||||
Translation.translateAsStatementAndMergeInBlockIfNeeded(body, context)
|
||||
else
|
||||
context.getEmptyStatement()
|
||||
JsEmpty
|
||||
|
||||
if (!conditionBlock.isEmpty()) {
|
||||
val breakIfConditionIsFalseStatement = JsIf(not(jsCondition), JsBreak())
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@ public final class WhenTranslator extends AbstractTranslator {
|
||||
|
||||
private JsStatement translate() {
|
||||
if (expressionToMatch != null && JsAstUtils.isEmptyExpression(expressionToMatch)) {
|
||||
return context().getEmptyStatement();
|
||||
return JsEmpty.INSTANCE$;
|
||||
}
|
||||
|
||||
JsIf currentIf = null;
|
||||
|
||||
Reference in New Issue
Block a user