Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: use js-tokens instead of acorn (#6)
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
- Loading branch information
1 parent
0e97234
commit bad0e6f
Showing
20 changed files
with
158 additions
and
425 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,44 +1,19 @@ | ||
import { _stripLiteralAcorn } from './acorn' | ||
import { stripLiteralRegex } from './regex' | ||
import { stripLiteralJsTokens } from './js-tokens' | ||
import type { StripLiteralOptions } from './types' | ||
|
||
export { stripLiteralAcorn, createIsLiteralPositionAcorn } from './acorn' | ||
export { stripLiteralRegex } from './regex' | ||
export { stripLiteralJsTokens } from './js-tokens' | ||
export * from './types' | ||
|
||
/** | ||
* Strip literal from code. | ||
* | ||
* Using Acorn's tokenizer first, and fallback to Regex if Acorn fails. | ||
*/ | ||
export function stripLiteral(code: string, options?: StripLiteralOptions) { | ||
return stripLiteralDetailed(code, options).result | ||
} | ||
|
||
/** | ||
* Strip literal from code, return more detailed information. | ||
* | ||
* Using Acorn's tokenizer first, and fallback to Regex if Acorn fails. | ||
*/ | ||
export function stripLiteralDetailed(code: string, options?: StripLiteralOptions): { | ||
mode: 'acorn' | 'regex' | ||
result: string | ||
acorn: { | ||
tokens: any[] | ||
error?: any | ||
} | ||
} { | ||
const acorn = _stripLiteralAcorn(code, options) | ||
if (!acorn.error) { | ||
return { | ||
mode: 'acorn', | ||
result: acorn.result, | ||
acorn, | ||
} | ||
} | ||
return { | ||
mode: 'regex', | ||
result: stripLiteralRegex(acorn.result + code.slice(acorn.result.length), options), | ||
acorn, | ||
} | ||
export function stripLiteralDetailed(code: string, options?: StripLiteralOptions) { | ||
return stripLiteralJsTokens(code, options) | ||
} |
Oops, something went wrong.