refactor(parser)!: treat unambiguous files containing TS export assignments as modules (#6253)

An "unambiguous" TS source which contains an `export = <value>;` statement should be interpreted as an ES module.

This is in line with [this Babel test case](94e166782a/packages/babel-parser/test/fixtures/typescript/export/equals-in-unambiguous) which has [input option of `sourceType: "unambiguous"`](94e166782a/packages/babel-parser/test/fixtures/typescript/export/equals-in-unambiguous/options.json (L2)), and [outputs an AST with `sourceType: "module"`](94e166782a/packages/babel-parser/test/fixtures/typescript/export/equals-in-unambiguous/output.json (L7)).
This commit is contained in:
overlookmotel 2024-10-03 00:28:00 +00:00
parent 4f6bc79734
commit 32d972e2a4

View file

@ -187,6 +187,7 @@ impl<'a> ParserImpl<'a> {
self.expect(Kind::Eq)?;
let expression = self.parse_assignment_expression_or_higher()?;
self.asi()?;
self.set_source_type_to_module_if_unambiguous();
Ok(self.ast.alloc_ts_export_assignment(self.end_span(start_span), expression))
}