test(es/minifier): Enable non esm mode for tests (#8472)

This commit is contained in:
Austaras 2024-01-02 12:33:39 +08:00 committed by GitHub
parent 327bba294b
commit 1120336f23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 38 additions and 38 deletions

View File

@ -146,7 +146,7 @@ fn run(
config: &str,
mangle: Option<TestMangleOptions>,
skip_hygiene: bool,
) -> Option<Module> {
) -> Option<Program> {
HANDLER.set(handler, || {
let disable_hygiene = mangle.is_some() || skip_hygiene;
@ -194,15 +194,15 @@ fn run(
let mut parser = Parser::new_from(lexer);
let program = parser
.parse_module()
.parse_program()
.map_err(|err| {
err.into_diagnostic(handler).emit();
})
.map(|mut module| {
module.visit_mut_with(&mut paren_remover(Some(&comments)));
module.visit_mut_with(&mut resolver(unresolved_mark, top_level_mark, false));
.map(|mut program| {
program.visit_mut_with(&mut paren_remover(Some(&comments)));
program.visit_mut_with(&mut resolver(unresolved_mark, top_level_mark, false));
module
program
});
// Ignore parser errors.
@ -215,7 +215,7 @@ fn run(
let optimization_start = Instant::now();
let mut output = optimize(
program.into(),
program,
cm,
Some(&comments),
None,
@ -240,8 +240,7 @@ fn run(
unresolved_mark,
top_level_mark,
},
)
.expect_module();
);
let end = Instant::now();
tracing::info!(
"optimize({}) took {:?}",
@ -469,12 +468,12 @@ fn fixture(input: PathBuf) {
let mangle: Option<TestMangleOptions> = mangle.map(|s| TestMangleOptions::parse(&s));
let output = run(cm.clone(), &handler, &input, &config, mangle, false);
let output_module = match output {
let output_program = match output {
Some(v) => v,
None => return Ok(()),
};
let output = print(cm.clone(), &[output_module.clone()], false, false);
let output = print(cm.clone(), &[output_program.clone()], false, false);
eprintln!("---- {} -----\n{}", Color::Green.paint("Output"), output);
@ -488,19 +487,24 @@ fn fixture(input: PathBuf) {
None,
);
let mut parser = Parser::new_from(lexer);
let expected = parser.parse_module().map_err(|err| {
let expected = parser.parse_program().map_err(|err| {
err.into_diagnostic(&handler).emit();
})?;
let mut expected = expected.fold_with(&mut fixer(None));
expected = drop_span(expected);
expected
.body
.retain(|s| !matches!(s, ModuleItem::Stmt(Stmt::Empty(..))));
match &mut expected {
Program::Module(m) => {
m.body
.retain(|s| !matches!(s, ModuleItem::Stmt(Stmt::Empty(..))));
}
Program::Script(s) => s.body.retain(|s| !matches!(s, Stmt::Empty(..))),
}
let mut normalized_expected = expected.clone();
normalized_expected.visit_mut_with(&mut DropParens);
let mut actual = output_module.clone();
let mut actual = output_program.clone();
actual.visit_mut_with(&mut DropParens);
if actual.eq_ignore_span(&normalized_expected)
@ -531,21 +535,25 @@ fn fixture(input: PathBuf) {
);
let mut parser = Parser::new_from(lexer);
let expected = parser
.parse_module()
.parse_program()
.map_err(|err| {
err.into_diagnostic(&handler).emit();
})
.ok()?;
let mut expected = expected.fold_with(&mut fixer(None));
expected = drop_span(expected);
expected
.body
.retain(|s| !matches!(s, ModuleItem::Stmt(Stmt::Empty(..))));
match &mut expected {
Program::Module(m) => {
m.body
.retain(|s| !matches!(s, ModuleItem::Stmt(Stmt::Empty(..))));
}
Program::Script(s) => s.body.retain(|s| !matches!(s, Stmt::Empty(..))),
}
let mut normalized_expected = expected.clone();
normalized_expected.visit_mut_with(&mut DropParens);
let mut actual = output_module.clone();
let mut actual = output_program.clone();
actual.visit_mut_with(&mut DropParens);
if actual.eq_ignore_span(&normalized_expected)
@ -607,7 +615,7 @@ fn fixture(input: PathBuf) {
}
}
let output_str = print(cm, &[drop_span(output_module)], false, false);
let output_str = print(cm, &[drop_span(output_program)], false, false);
if env::var("UPDATE").map(|s| s == "1").unwrap_or(false) {
let _ = catch_unwind(|| {

View File

@ -3,7 +3,7 @@ switch(function() {
}){
case xxx:
for(; console.log("FAIL");){
function xxx1() {}
function xxx() {}
}
break;
}

View File

@ -2,6 +2,6 @@ switch(function() {
return xxx;
}){
case xxx:
if (console.log("FAIL")) function xxx1() {}
if (console.log("FAIL")) function xxx() {}
break;
}

View File

@ -1,3 +1,3 @@
var unused;
const CONST_FOO = !1;
var moo;
var moo, bar;

View File

@ -1,16 +1,8 @@
var foo = 0,
async = 1,
await = 2,
implements = 3,
package = 4,
private = 5,
protected = 6,
static = 7,
yield = 8;
var foo = 0, async = 1, await = 2, implements = 3, package = 4, private = 5, protected = 6, static = 7, yield = 8;
console.log({
foo,
0: 0,
NaN: NaN,
NaN,
async,
await,
false: false,
@ -22,6 +14,6 @@ console.log({
static: static,
this: this,
true: true,
undefined: void 0,
yield,
undefined,
yield
});

View File

@ -54,7 +54,7 @@ use testing::assert_eq;
// should error
"blocks/issue_1672_if_strict",
"blocks/issue_1672_for_strict",
// need support for script mode
// annex B
"blocks/issue_1672_if",
"blocks/issue_1672_for",
)