-
-
Notifications
You must be signed in to change notification settings - Fork 879
Description
Currently Transformer::new takes a source_type param:
oxc/crates/oxc_transformer/src/lib.rs
Lines 76 to 86 in bc757c8
| pub fn new( | |
| allocator: &'a Allocator, | |
| source_path: &Path, | |
| source_type: SourceType, | |
| source_text: &'a str, | |
| trivias: Trivias, | |
| options: TransformOptions, | |
| ) -> Self { | |
| let ctx = TransformCtx::new(source_path, source_type, source_text, trivias, &options); | |
| Self { ctx, options, allocator } | |
| } |
Can we get rid of it? source_type is present in Program and parser updates it from "unambiguous" to either "script" or "module".
It seems to make more sense to use the value of source_type present in Program, than allow user to over-ride it.
I can't see any circumstance in which that's a useful thing to do, and it's a potential footgun. It's confusing that in transformer it's possible that self.ctx.source_type.is_script() != !self.ctx.source_type.is_module(), because it can also be "unambiguous". That's not theoretical - I hit this problem while trying to pass some TypeScript tests.
If for some obscure reason, the user does want to override it, they can always alter the value of Program::source_type before passing Program to transformer.