StreamingASTokenizer: fix issue where array literal was treated as metadata when comment tokens are included
Previous fix for formatter fixed metadata, but broke arrays, now both should work by tracking the last token that was not a comment too
Followup to d56e53b576ce7502c1bccdc857ff7c9eec538b8e
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/StreamingASTokenizer.java b/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/StreamingASTokenizer.java
index 3bcd410..f2461cc 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/StreamingASTokenizer.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/StreamingASTokenizer.java
@@ -206,6 +206,7 @@
//last token we encountered, used for lookback
private ASToken lastToken;
+ private ASToken lastTokenNotComment;
private int offsetAdjustment; //for offset adjustment
private int lineAdjustment = 0;
@@ -1342,6 +1343,9 @@
{
consumeSemi = false;
lastToken = retVal;
+ if (retVal == null || (retVal.getType() != HIDDEN_TOKEN_SINGLE_LINE_COMMENT && retVal.getType() != HIDDEN_TOKEN_MULTI_LINE_COMMENT)) {
+ lastTokenNotComment = retVal;
+ }
}
return null;
}
@@ -1394,7 +1398,18 @@
}
else
{
- switch (lastToken.getType())
+ ASToken lastTokenToCheck = lastToken;
+ if (lastTokenNotComment != null)
+ {
+ switch (lastTokenToCheck.getType())
+ {
+ case HIDDEN_TOKEN_SINGLE_LINE_COMMENT:
+ case HIDDEN_TOKEN_MULTI_LINE_COMMENT:
+ lastTokenToCheck = lastTokenNotComment;
+ break;
+ }
+ }
+ switch (lastTokenToCheck.getType())
{
case HIDDEN_TOKEN_SINGLE_LINE_COMMENT:
case HIDDEN_TOKEN_MULTI_LINE_COMMENT: