From 8be362807422bf9cb7364157abb824d9cddf2f5f Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Fri, 13 Mar 2015 15:48:49 +0300 Subject: [PATCH] JS: removed comma expression decomposition from InlineMetadata There are used to be two inline tags (corresponding to start, end of inline function). An expression like "startTag, function, endTag" was parsed into comma expression, then decomposed. Now, it's just one tag at start, and parser can read function, then stop. Thus, there is no need to decompose comma expressions. --- .../js/translate/expression/InlineMetadata.kt | 31 +++---------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/expression/InlineMetadata.kt b/js/js.translator/src/org/jetbrains/kotlin/js/translate/expression/InlineMetadata.kt index 185054080c2..a3c84767e5a 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/expression/InlineMetadata.kt +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/expression/InlineMetadata.kt @@ -38,7 +38,6 @@ public class InlineMetadata(val tag: JsStringLiteral, val function: JsFunction) platformStatic fun decompose(expression: JsExpression?): InlineMetadata? = when (expression) { - is JsBinaryOperation -> decomposeCommaExpression(expression) is JsInvocation -> decomposeCreateFunctionCall(expression) else -> null } @@ -46,33 +45,11 @@ public class InlineMetadata(val tag: JsStringLiteral, val function: JsFunction) private fun decomposeCreateFunctionCall(call: JsInvocation): InlineMetadata? { if (Namer.CREATE_INLINE_FUNCTION != call.getQualifier()) return null - return decomposePropertiesList(call.getArguments()) - } + val arguments = call.getArguments() + if (arguments.size() != METADATA_PROPERTIES_COUNT) return null - private fun decomposeCommaExpression(expression: JsExpression): InlineMetadata? { - val properties = arrayListOf() - var decomposable: JsExpression? = expression - - while (decomposable is JsExpression) { - val binOp = decomposable as? JsBinaryOperation - - if (JsBinaryOperator.COMMA == binOp?.getOperator()) { - properties.add(binOp?.getArg2()) - decomposable = binOp?.getArg1() - } else { - properties.add(decomposable) - break - } - } - - return decomposePropertiesList(properties.reverse()) - } - - private fun decomposePropertiesList(properties: List): InlineMetadata? { - if (properties.size() != METADATA_PROPERTIES_COUNT) return null - - val tag = properties[0] as? JsStringLiteral - val function = properties[1] as? JsFunction + val tag = arguments[0] as? JsStringLiteral + val function = arguments[1] as? JsFunction if (tag == null || function == null) return null return InlineMetadata(tag, function)