You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by jo...@apache.org on 2022/12/06 17:52:40 UTC

[royale-compiler] branch develop updated (b3f358240 -> 78fb8f1ac)

This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a change to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git


    from b3f358240 formatter: tests for member access and null conditional
     new edc2b2dda formatter: fix ternary inside if condition
     new 78fb8f1ac formatter: remove debugging output

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../apache/royale/formatter/ASTokenFormatter.java   |  9 ++++-----
 .../royale/formatter/TestTernaryStatement.java      | 21 +++++++++++++++++++++
 2 files changed, 25 insertions(+), 5 deletions(-)


[royale-compiler] 01/02: formatter: fix ternary inside if condition

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit edc2b2dda352f8c0c96a2259145030b70bf047c9
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Tue Dec 6 09:39:09 2022 -0800

    formatter: fix ternary inside if condition
---
 .../apache/royale/formatter/ASTokenFormatter.java   |  8 ++++----
 .../royale/formatter/TestTernaryStatement.java      | 21 +++++++++++++++++++++
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/formatter/src/main/java/org/apache/royale/formatter/ASTokenFormatter.java b/formatter/src/main/java/org/apache/royale/formatter/ASTokenFormatter.java
index 3513d2d38..5b2eee400 100644
--- a/formatter/src/main/java/org/apache/royale/formatter/ASTokenFormatter.java
+++ b/formatter/src/main/java/org/apache/royale/formatter/ASTokenFormatter.java
@@ -770,7 +770,10 @@ public class ASTokenFormatter extends BaseTokenFormatter {
 						break;
 					}
 					case ASTokenTypes.TOKEN_COLON: {
-						if (!inControlFlowStatement && !inVarOrConstDeclaration && !inFunctionDeclaration) {
+						if (ternaryStack > 0) {
+							ternaryStack--;
+							requiredSpace = true;
+						} else if (!inControlFlowStatement && !inVarOrConstDeclaration && !inFunctionDeclaration) {
 							if (inCaseOrDefaultClause) {
 								inCaseOrDefaultClause = false;
 								caseOrDefaultBlockOpenPending = true;
@@ -798,9 +801,6 @@ public class ASTokenFormatter extends BaseTokenFormatter {
 										numRequiredNewLines = Math.max(numRequiredNewLines, 1);
 									}
 								}
-							} else if (ternaryStack > 0) {
-								ternaryStack--;
-								requiredSpace = true;
 							} else {
 								requiredSpace = true;
 							}
diff --git a/formatter/src/test/java/org/apache/royale/formatter/TestTernaryStatement.java b/formatter/src/test/java/org/apache/royale/formatter/TestTernaryStatement.java
index b324d9baa..9c15b1f13 100644
--- a/formatter/src/test/java/org/apache/royale/formatter/TestTernaryStatement.java
+++ b/formatter/src/test/java/org/apache/royale/formatter/TestTernaryStatement.java
@@ -82,4 +82,25 @@ public class TestTernaryStatement extends BaseFormatterTests {
 				// @formatter:on
 				result);
 	}
+
+	@Test
+	public void testInsideConditional() {
+		FormatterSettings settings = new FormatterSettings();
+		settings.insertSpaceAfterKeywordsInControlFlowStatements = true;
+		settings.placeOpenBraceOnNewLine = true;
+		settings.insertSpaces = false;
+		settings.collapseEmptyBlocks = true;
+		ASTokenFormatter formatter = new ASTokenFormatter(settings);
+		String result = formatter.format("file.as",
+		// @formatter:off
+			"if (condition ? statement : statement) {}",
+			// @formatter:on
+			problems
+		);
+		assertEquals(
+		// @formatter:off
+			"if (condition ? statement : statement) {}",
+				// @formatter:on
+				result);
+	}
 }


[royale-compiler] 02/02: formatter: remove debugging output

Posted by jo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit 78fb8f1ac80b64c4da587b4feaeadc3871fa3355
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Tue Dec 6 09:39:24 2022 -0800

    formatter: remove debugging output
---
 .../src/main/java/org/apache/royale/formatter/ASTokenFormatter.java      | 1 -
 1 file changed, 1 deletion(-)

diff --git a/formatter/src/main/java/org/apache/royale/formatter/ASTokenFormatter.java b/formatter/src/main/java/org/apache/royale/formatter/ASTokenFormatter.java
index 5b2eee400..0aafcecd4 100644
--- a/formatter/src/main/java/org/apache/royale/formatter/ASTokenFormatter.java
+++ b/formatter/src/main/java/org/apache/royale/formatter/ASTokenFormatter.java
@@ -1234,7 +1234,6 @@ public class ASTokenFormatter extends BaseTokenFormatter {
 
 	private String formatLiteralString(IASToken token) {
 		String string = token.getText();
-		System.err.println("*** " + string);
 		String charsToEscape = "\b\t\n\f\r\\";
 		String escapeChars = "btnfr\\";
 		int escapeIndex = -1;