From 39b4e79b0c291030a94c6401effb2a7c90f60f07 Mon Sep 17 00:00:00 2001 From: mmews Date: Tue, 13 Feb 2024 15:15:46 +0100 Subject: [PATCH] fix missing value for boolean prop --- .../es/transform/JSXTransformation.java | 17 ++++++++++++++++- .../n4js/cli/helper/SystemOutRedirecter.java | 2 ++ .../tests/helper/server/AbstractIdeTest.java | 16 ++-------------- .../jsx_transpile_properties.n4jsx.xt | 5 +++++ 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/plugins/org.eclipse.n4js.transpiler.es/src/org/eclipse/n4js/transpiler/es/transform/JSXTransformation.java b/plugins/org.eclipse.n4js.transpiler.es/src/org/eclipse/n4js/transpiler/es/transform/JSXTransformation.java index 837bde64e1..bd05bafea6 100644 --- a/plugins/org.eclipse.n4js.transpiler.es/src/org/eclipse/n4js/transpiler/es/transform/JSXTransformation.java +++ b/plugins/org.eclipse.n4js.transpiler.es/src/org/eclipse/n4js/transpiler/es/transform/JSXTransformation.java @@ -21,6 +21,7 @@ import static org.eclipse.n4js.transpiler.TranspilerBuilderBlocks._PropertyNameValuePair; import static org.eclipse.n4js.transpiler.TranspilerBuilderBlocks._PropertySpread; import static org.eclipse.n4js.transpiler.TranspilerBuilderBlocks._StringLiteral; +import static org.eclipse.n4js.transpiler.TranspilerBuilderBlocks._TRUE; import static org.eclipse.xtext.xbase.lib.IterableExtensions.filter; import static org.eclipse.xtext.xbase.lib.IterableExtensions.map; import static org.eclipse.xtext.xbase.lib.IterableExtensions.toList; @@ -261,7 +262,9 @@ private Expression convertJSXAttributes(List attrs, List if (REACT_ELEMENT_PROPERTY_KEY_NAME.equals(pAttr.getPropertyAsText())) { continue; } - pas.add(_PropertyNameValuePair(pAttr.getPropertyAsText(), pAttr.getJsxAttributeValue())); + pas.add(_PropertyNameValuePair( + getNameFromPropertyAttribute(pAttr), + getValueExpressionFromPropertyAttribute(pAttr))); } } @@ -304,4 +307,16 @@ private Expression getTagNameFromElement(JSXElement elem) { } return nameExpr; } + + private String getNameFromPropertyAttribute(JSXPropertyAttribute attr) { + IdentifiableElement prop = attr.getProperty(); + if (prop != null && !prop.eIsProxy()) { + return prop.getName(); + } + return attr.getPropertyAsText(); + } + + private Expression getValueExpressionFromPropertyAttribute(JSXPropertyAttribute attr) { + return attr.getJsxAttributeValue() != null ? attr.getJsxAttributeValue() : _TRUE(); + } } diff --git a/testhelpers/org.eclipse.n4js.cli.tests.helper/src/org/eclipse/n4js/cli/helper/SystemOutRedirecter.java b/testhelpers/org.eclipse.n4js.cli.tests.helper/src/org/eclipse/n4js/cli/helper/SystemOutRedirecter.java index efe5f5c36a..5cf60a3744 100644 --- a/testhelpers/org.eclipse.n4js.cli.tests.helper/src/org/eclipse/n4js/cli/helper/SystemOutRedirecter.java +++ b/testhelpers/org.eclipse.n4js.cli.tests.helper/src/org/eclipse/n4js/cli/helper/SystemOutRedirecter.java @@ -97,6 +97,7 @@ public PrintStream getOriginalSystemErr() { public void clearSystemOut() { ByteArrayOutputStream baos = redirectOut; if (baos != null) { + System.out.flush(); baos.reset(); } } @@ -117,6 +118,7 @@ public String getSystemOut() { public void clearSystemErr() { ByteArrayOutputStream baos = redirectErr; if (baos != null) { + System.err.flush(); baos.reset(); } } diff --git a/testhelpers/org.eclipse.n4js.ide.tests.helper/src/org/eclipse/n4js/ide/tests/helper/server/AbstractIdeTest.java b/testhelpers/org.eclipse.n4js.ide.tests.helper/src/org/eclipse/n4js/ide/tests/helper/server/AbstractIdeTest.java index e685512ae6..2d286c9542 100644 --- a/testhelpers/org.eclipse.n4js.ide.tests.helper/src/org/eclipse/n4js/ide/tests/helper/server/AbstractIdeTest.java +++ b/testhelpers/org.eclipse.n4js.ide.tests.helper/src/org/eclipse/n4js/ide/tests/helper/server/AbstractIdeTest.java @@ -203,18 +203,6 @@ static final public void restoreGlobalRegistries() { oldGlobalState.restoreGlobalState(); } - /** Catch outputs on console to an internal buffer */ - @BeforeClass - static final public void redirectPrintStreams() { - SYSTEM_OUT_REDIRECTER.set(false); - } - - /** Reset redirection */ - @AfterClass - static final public void resetPrintStreams() { - SYSTEM_OUT_REDIRECTER.unset(); - } - /** */ @Inject protected BuilderFrontend lspBuilder; @@ -267,6 +255,7 @@ public void cleanupTestDataFolder() throws IOException { if (root.exists()) { FileUtils.delete(root); } + SYSTEM_OUT_REDIRECTER.set(false); } /** Deletes the test project in case it exists. */ @@ -281,8 +270,7 @@ final public void deleteTestProject() throws IOException { if (languageServer != null) { // only if LSP server was started shutdownLspServer(); } - SYSTEM_OUT_REDIRECTER.clearSystemOut(); - SYSTEM_OUT_REDIRECTER.clearSystemErr(); + SYSTEM_OUT_REDIRECTER.unset(); // note that thrown exceptions will now be written to System.err // clear the state related to the test testWorkspaceManager.deleteTestFromDiskIfCreated(); } diff --git a/tests/org.eclipse.n4js.spec.tests/xt-tests/react_transpile/jsx_transpile_properties.n4jsx.xt b/tests/org.eclipse.n4js.spec.tests/xt-tests/react_transpile/jsx_transpile_properties.n4jsx.xt index 52d08d37d8..55395be4cb 100644 --- a/tests/org.eclipse.n4js.spec.tests/xt-tests/react_transpile/jsx_transpile_properties.n4jsx.xt +++ b/tests/org.eclipse.n4js.spec.tests/xt-tests/react_transpile/jsx_transpile_properties.n4jsx.xt @@ -53,6 +53,8 @@ const props6 = {a1: 1, a2: 2} const MyDiv6 =
; MyDiv6; +const MyDiv7 =
; +MyDiv7; /* XPECT compileResult --- @@ -101,5 +103,8 @@ const props6 = { }; const MyDiv6 = $jsx('div', props6); MyDiv6; +const MyDiv7 = $jsx('div', { + trueProp: true +}); //# sourceMappingURL=jsx_transpile_properties.map --- */