-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Describe the feature
Support pass a callback or a Option<HashSet>
for swc_ecma_parser::Parser
to collect the BytePos
position of automatically inserted semicolons
Babel plugin or link to the feature description
Additional context
The background is when I trying to solve web-infra-dev/rspack#11551, I notice that the swc_ecma_parser::Lexer
will output different tokens when using it in parse()
and .collect_vec()
For example:
import {assert} from './a'
const labelType = `${node}Label`
const node = []
assert(labelType)
In parse()
this will have correct tokens, but using with .collect_vec()
(or Iterator) it will have a lexing error: Error { error: (60..97, UnterminatedTpl) }
(and the lexing error causes Rspack collected the wrong semicolons, which is used for Rspack to add ;
at proper position to generate the correct code)
So it will be great for correctness and performance if the ASI position can be collected by SWC when parsing (currently Rspack lexes twice, once for parse and once for collecting ASI positions)
Or provide an API that I can get the correct tokens without parsing, which is a workable alternative solution.