-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: added $capabilities() function * fix: package lock * feat: support single line comments and comments inside strings * fix: remove console.log
- Loading branch information
1 parent
0baa499
commit bf35b6a
Showing
9 changed files
with
99 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* © Copyright Outburn Ltd. 2022-2024 All Rights Reserved | ||
* Project name: FUME-COMMUNITY | ||
*/ | ||
|
||
export const removeComments = (expr: string): string => { | ||
const exprLen: number = expr.length; | ||
if (exprLen === 0) return expr; | ||
let accExpr: string = ''; | ||
let currentChar: string = ''; | ||
let nextChar: string = ''; | ||
let prevChar: string = ''; | ||
let prevPrevChar: string = ''; | ||
let openedQuote: string = ''; | ||
let openedComment: string = ''; | ||
|
||
for (let i = 0; i < exprLen; i++) { | ||
currentChar = expr.charAt(i); | ||
nextChar = i < (exprLen - 1) ? expr.charAt(i + 1) : ''; | ||
prevChar = i > 0 ? expr.charAt(i - 1) : ''; | ||
prevPrevChar = i > 1 ? expr.charAt(i - 2) : ''; | ||
|
||
if (openedComment !== '') { | ||
// inside a comment | ||
const twoChars: string = prevChar + currentChar; | ||
|
||
if (openedComment === '//' && (currentChar === '\r' || currentChar === '\n')) { | ||
// this is the end of the // comment | ||
openedComment = ''; | ||
accExpr += '\n'; | ||
} else { | ||
if (openedComment === '/*' && twoChars === '*/' && prevPrevChar !== '/') { | ||
// this is the end of the /* comment | ||
openedComment = ''; | ||
} | ||
}; | ||
continue; | ||
}; | ||
|
||
// not inside a comment | ||
if ((currentChar === '"' || currentChar === '\'') && prevChar !== '\\') { | ||
// quote sign, unescaped | ||
if (openedQuote === '') { | ||
// it's an opening quote | ||
openedQuote = currentChar; | ||
} else { | ||
// it's a closing quote | ||
if (openedQuote === currentChar) { | ||
openedQuote = ''; | ||
} | ||
} | ||
} else { | ||
// not a quote sign | ||
const twoChars: string = currentChar + nextChar; | ||
if ((twoChars === '/*' || twoChars === '//') && openedQuote === '') { | ||
// opening comment, not inside quotes | ||
openedComment = twoChars; | ||
continue; | ||
} | ||
} | ||
accExpr += currentChar; | ||
}; | ||
|
||
return accExpr; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters