Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update getExpr to account for an elif comment block #14

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/get-expr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,24 @@ const skipBracket = (expr: string, start: number, stack: string[]) => {
return ch ? start + 1 : expr.length
}

/**
* Handles the extraction of an expression with a comment block slash or regular
* comment slash.
*
* @param expr Raw expression
* @param index Position of this slash
*/
const handleSlashExtraction = function (expr: string, index: number) {
if (expr[index + 1] === '/') {
return expr.slice(0, index)
}

if (expr[index - 1] === '*') {
return expr.slice(0, index - 1)
}
return null
}

/**
* To find the comment (//), it is necessary to skip strings, es6 tl,
* brackets, and regexes
Expand Down Expand Up @@ -99,8 +117,9 @@ const extractExpr = function (expr: string, start: number) {
re.lastIndex = skipES6TL(expr, mm.index, stack)
break
case '/':
if (expr[mm.index + 1] === '/') {
return expr.slice(0, mm.index)
const result = handleSlashExtraction(expr, mm.index)
if (result) {
return result
}
re.lastIndex = skipRegex(expr, mm.index)
}
Expand Down