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 1759d78fb3e7ef144809583e208b8e174380fd3b Author: Josh Tynjala <[email protected]> AuthorDate: Wed Nov 6 14:56:11 2024 -0800 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 --- .../internal/parsing/as/StreamingASTokenizer.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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 3bcd4107e..f2461cca7 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 @@ public class StreamingASTokenizer implements ASTokenTypes, IASTokenizer, Closeab //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 @@ public class StreamingASTokenizer implements ASTokenTypes, IASTokenizer, Closeab { 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 @@ public class StreamingASTokenizer implements ASTokenTypes, IASTokenizer, Closeab } 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:
