mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 14:43:33 +03:00
fix(es/parser): Allow parsing import.meta
as an expression (#6783)
This commit is contained in:
parent
70c3126771
commit
ff8facef64
@ -442,7 +442,11 @@ macro_rules! expose {
|
||||
};
|
||||
}
|
||||
|
||||
expose!(parse_file_as_expr, Box<Expr>, |p| { p.parse_expr() });
|
||||
expose!(parse_file_as_expr, Box<Expr>, |p| {
|
||||
// This allow to parse `import.meta`
|
||||
p.input().ctx.can_be_module = true;
|
||||
p.parse_expr()
|
||||
});
|
||||
expose!(parse_file_as_module, Module, |p| { p.parse_module() });
|
||||
expose!(parse_file_as_script, Script, |p| { p.parse_script() });
|
||||
expose!(parse_file_as_program, Program, |p| { p.parse_program() });
|
||||
|
@ -2,12 +2,12 @@ extern crate test;
|
||||
|
||||
use std::hint::black_box;
|
||||
|
||||
use swc_common::DUMMY_SP as span;
|
||||
use swc_common::{FileName, SourceMap, DUMMY_SP as span};
|
||||
use swc_ecma_visit::assert_eq_ignore_span;
|
||||
use test::Bencher;
|
||||
|
||||
use super::*;
|
||||
use crate::EsConfig;
|
||||
use crate::{parse_file_as_expr, EsConfig};
|
||||
|
||||
fn syntax() -> Syntax {
|
||||
Syntax::Es(EsConfig {
|
||||
@ -519,6 +519,22 @@ fn issue_5947() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn issue_6781() {
|
||||
let cm = SourceMap::default();
|
||||
let fm = cm.new_source_file(FileName::Anon, "import.meta.env".to_string());
|
||||
let mut errors = vec![];
|
||||
let expr = parse_file_as_expr(
|
||||
&fm,
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
None,
|
||||
&mut errors,
|
||||
);
|
||||
assert!(expr.is_ok());
|
||||
assert!(errors.is_empty());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_new_expr_ts(b: &mut Bencher) {
|
||||
bench_parser(
|
||||
|
Loading…
Reference in New Issue
Block a user