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 2021/10/06 22:31:38 UTC
[royale-compiler] 01/04: formatter: don't insert space before ...
if it's the first parameter
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 92c3ecaee893d9b3cce24ffaaad12f64f4c88a43
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Wed Oct 6 14:12:31 2021 -0700
formatter: don't insert space before ... if it's the first parameter
---
.../org/apache/royale/formatter/FORMATTER.java | 5 ++-
.../royale/formatter/TestFunctionDeclaration.java | 50 ++++++++++++++++++++++
2 files changed, 54 insertions(+), 1 deletion(-)
diff --git a/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java b/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
index ab2983e..51cddb5 100644
--- a/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
+++ b/formatter/src/main/java/org/apache/royale/formatter/FORMATTER.java
@@ -737,7 +737,10 @@ class FORMATTER {
break;
}
case ASTokenTypes.TOKEN_ELLIPSIS: {
- requiredSpace = true;
+ boolean isFirstArg = prevToken == null || prevToken.getType() == ASTokenTypes.TOKEN_PAREN_OPEN;
+ if (!isFirstArg) {
+ requiredSpace = true;
+ }
break;
}
case ASTokenTypes.TOKEN_KEYWORD_DEFAULT:
diff --git a/formatter/src/test/java/org/apache/royale/formatter/TestFunctionDeclaration.java b/formatter/src/test/java/org/apache/royale/formatter/TestFunctionDeclaration.java
index af3eec3..50729e2 100644
--- a/formatter/src/test/java/org/apache/royale/formatter/TestFunctionDeclaration.java
+++ b/formatter/src/test/java/org/apache/royale/formatter/TestFunctionDeclaration.java
@@ -220,4 +220,54 @@ public class TestFunctionDeclaration extends BaseFormatterTests {
// @formatter:on
result);
}
+
+ @Test
+ public void testParametersWithRest() {
+ FORMATTER formatter = new FORMATTER();
+ formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
+ formatter.placeOpenBraceOnNewLine = true;
+ formatter.insertSpaces = false;
+ String result = formatter.formatText(
+ // @formatter:off
+ "function myFunction(p1:String, ...rest)\n" +
+ "{\n" +
+ "\tstatement;\n" +
+ "}",
+ // @formatter:on
+ problems
+ );
+ assertEquals(
+ // @formatter:off
+ "function myFunction(p1:String, ...rest)\n" +
+ "{\n" +
+ "\tstatement;\n" +
+ "}",
+ // @formatter:on
+ result);
+ }
+
+ @Test
+ public void testParametersRestOnly() {
+ FORMATTER formatter = new FORMATTER();
+ formatter.insertSpaceAfterKeywordsInControlFlowStatements = true;
+ formatter.placeOpenBraceOnNewLine = true;
+ formatter.insertSpaces = false;
+ String result = formatter.formatText(
+ // @formatter:off
+ "function myFunction(...rest)\n" +
+ "{\n" +
+ "\tstatement;\n" +
+ "}",
+ // @formatter:on
+ problems
+ );
+ assertEquals(
+ // @formatter:off
+ "function myFunction(...rest)\n" +
+ "{\n" +
+ "\tstatement;\n" +
+ "}",
+ // @formatter:on
+ result);
+ }
}