Skip to content

Commit 8bf5c14

Browse files
committed
IDE-2470: support for JSX spread in transpiler (temporary)
1 parent f7268de commit 8bf5c14

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

plugins/eu.numberfour.n4js.transpiler.es/src/eu/numberfour/n4js/transpiler/es/transform/JSXTransformation.xtend

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import eu.numberfour.n4jsx.n4JSX.JSXPropertyAttribute
2323
import eu.numberfour.n4jsx.n4JSX.JSXSpreadAttribute
2424

2525
import static eu.numberfour.n4js.transpiler.TranspilerBuilderBlocks.*
26+
import eu.numberfour.n4js.utils.N4JSLanguageUtils
2627

2728
/**
2829
*
@@ -81,7 +82,7 @@ class JSXTransformation extends Transformation {
8182
attr.valueExpressionFromPropertyAttribute)
8283
}
8384
JSXSpreadAttribute:
84-
throw new UnsupportedOperationException
85+
_PropertyNameValuePair(N4JSLanguageUtils.SPREAD_IN_OJECT_LITERAL_WORK_AROUND, attr.expression)
8586
}
8687
}
8788

plugins/eu.numberfour.n4js.transpiler/src/eu/numberfour/n4js/transpiler/print/PrettyPrinterSwitch.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,11 @@ public Boolean casePropertyAssignmentAnnotationList(PropertyAssignmentAnnotation
659659

660660
@Override
661661
public Boolean casePropertyNameValuePair(PropertyNameValuePair original) {
662+
if (N4JSLanguageUtils.SPREAD_IN_OJECT_LITERAL_WORK_AROUND.equals(original.getName())) {
663+
write("... ");
664+
process(original.getExpression());
665+
return DONE;
666+
}
662667
processPropertyName(original);
663668
write(": ");
664669
process(original.getExpression());

plugins/eu.numberfour.n4js/src/eu/numberfour/n4js/utils/N4JSLanguageUtils.xtend

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ class N4JSLanguageUtils {
102102
*/
103103
public static final String SYMBOL_IDENTIFIER_PREFIX = ComputedPropertyNameValueConverter.SYMBOL_IDENTIFIER_PREFIX;
104104

105+
/**
106+
* Temporary hack to be able to support spread operator in the JSX transpiler support.
107+
* This is required, because the ES6 spread operator is not yet supported in the N4JS grammar.
108+
* TODO IDE-2471 remove this and add proper support for spread in object literals to grammar/parser
109+
*/
110+
public static final String SPREAD_IN_OJECT_LITERAL_WORK_AROUND = "MISSING_SPREAD_WORK_AROUND";
111+
105112
/**
106113
* If the given function definition is asynchronous, will wrap given return type into a Promise.
107114
* Otherwise, returns given return type unchanged. A return type of <code>void</code> is changed to

0 commit comments

Comments
 (0)