Minor refactoring of JS AST nodes representing boolean literals
This commit is contained in:
@@ -121,7 +121,7 @@ class CoroutineBodyTransformer(private val context: CoroutineTransformationConte
|
||||
currentStatements += stateAndJump(bodyEntryBlock, x)
|
||||
|
||||
currentBlock = bodyEntryBlock
|
||||
if (!JsLiteral.isTrueBoolean(x.condition)) {
|
||||
if (!JsBooleanLiteral.isTrue(x.condition)) {
|
||||
currentStatements += JsIf(JsAstUtils.notOptimized(x.condition), JsBlock(stateAndJump(successor, x))).apply { source = x.source }
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ class CoroutineBodyTransformer(private val context: CoroutineTransformationConte
|
||||
x.body.accept(this)
|
||||
}
|
||||
|
||||
if (!JsLiteral.isTrueBoolean(x.condition)) {
|
||||
if (!JsBooleanLiteral.isTrue(x.condition)) {
|
||||
val jsIf = JsIf(JsAstUtils.notOptimized(x.condition), JsBlock(stateAndJump(successor, x))).apply { source = x.source }
|
||||
currentStatements.add(jsIf)
|
||||
}
|
||||
@@ -168,7 +168,7 @@ class CoroutineBodyTransformer(private val context: CoroutineTransformationConte
|
||||
currentStatements += stateAndJump(bodyEntryBlock, x)
|
||||
|
||||
currentBlock = bodyEntryBlock
|
||||
if (x.condition != null && !JsLiteral.isTrueBoolean(x.condition)) {
|
||||
if (x.condition != null && !JsBooleanLiteral.isTrue(x.condition)) {
|
||||
currentStatements += JsIf(JsAstUtils.notOptimized(x.condition), JsBlock(stateAndJump(successor, x))).apply { source = x.source }
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ class WhileConditionFolding(val body: JsBlock) {
|
||||
statement.body = remove(statement.body)
|
||||
val existingCondition = statement.condition
|
||||
statement.condition = when {
|
||||
JsLiteral.isTrueBoolean(existingCondition) -> condition
|
||||
JsBooleanLiteral.isTrue(existingCondition) -> condition
|
||||
else -> combine(existingCondition, condition)
|
||||
}
|
||||
changed = true
|
||||
@@ -142,7 +142,7 @@ class WhileConditionFolding(val body: JsBlock) {
|
||||
// Just a little optimization. When inner statement is a single `break`, `nextCondition` would be false.
|
||||
// However, `A || false` can be rewritten as simply `A`
|
||||
nextCondition == null -> null
|
||||
JsLiteral.isFalseBoolean(nextCondition) -> JsAstUtils.notOptimized(statement.ifExpression)
|
||||
JsBooleanLiteral.isFalse(nextCondition) -> JsAstUtils.notOptimized(statement.ifExpression)
|
||||
else -> JsAstUtils.or(JsAstUtils.notOptimized(statement.ifExpression), nextCondition)
|
||||
}
|
||||
result
|
||||
|
||||
Reference in New Issue
Block a user