Skip to content

Commit

Permalink
Merge pull request #4 from a1dancole/comments-bug
Browse files Browse the repository at this point in the history
Remove code comments when extracting variables.
  • Loading branch information
modery authored Jan 30, 2024
2 parents 0fd5d11 + f50a5ab commit 5f77476
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions PowerDocu.Common/AppParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ private void addScreenNavigation(ControlEntity controlEntity, string destination

private void CheckForVariables(ControlEntity controlEntity, string input)
{
if (hasCodeComments(input))
{
input = stripCodeComments(input);
}
//Reference: https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/working-with-variables#types-of-variables
string code = input.Replace("\n", "").Replace("\r", "");
MatchCollection matches;
Expand Down Expand Up @@ -537,6 +541,18 @@ private bool isWithinCodeComment(string code)
return !(lastOpeningCommentBrackets == -1 || lastOpeningCommentBrackets < lastClosingCommentBrackets);
}

private bool hasCodeComments(string code)
{
var regex = @"(@(?:""[^""]*"")+|""(?:[^""\n\\]+|\\.)*""|'(?:[^'\n\\]+|\\.)*')|//.*|/\*(?s:.*?)\*/";
return Regex.Match(code, regex).Success;
}

private string stripCodeComments(string code)
{
var regex = @"(@(?:""[^""]*"")+|""(?:[^""\n\\]+|\\.)*""|'(?:[^'\n\\]+|\\.)*')|//.*|/\*(?s:.*?)\*/";
return Regex.Replace(code, regex, "$1");
}

private void parseAppDataSources(Stream appArchive)
{
ZipArchiveEntry dataSourceFile = ZipHelper.getFileFromZip(appArchive, "References\\DataSources.json");
Expand Down

0 comments on commit 5f77476

Please sign in to comment.