mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
fix(minifier): do not join require calls for cjs-module-lexer (#4875)
This commit is contained in:
parent
0813af9d30
commit
879a271d47
4 changed files with 43 additions and 0 deletions
|
|
@ -285,6 +285,14 @@ impl<'a> Expression<'a> {
|
|||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_require_call(&self) -> bool {
|
||||
if let Self::CallExpression(call_expr) = self {
|
||||
call_expr.is_require_call()
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IdentifierName<'a> {
|
||||
|
|
|
|||
|
|
@ -43,6 +43,15 @@ impl<'a> Collapse<'a> {
|
|||
Statement::VariableDeclaration(prev_decl),
|
||||
) = (cur, prev)
|
||||
{
|
||||
// Do not join `require` calls for cjs-module-lexer.
|
||||
if cur_decl
|
||||
.declarations
|
||||
.first()
|
||||
.and_then(|d| d.init.as_ref())
|
||||
.is_some_and(Expression::is_require_call)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if cur_decl.kind == prev_decl.kind {
|
||||
if i - 1 != range.end {
|
||||
range.start = i - 1;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
//! <https://github.com/google/closure-compiler/blob/master/test/com/google/javascript/jscomp/CollapseVariableDeclarations.java>
|
||||
|
||||
use crate::CompressOptions;
|
||||
|
||||
fn test(source_text: &str, expected: &str) {
|
||||
let options = CompressOptions::all_true();
|
||||
crate::test(source_text, expected, options);
|
||||
}
|
||||
|
||||
fn test_same(source_text: &str) {
|
||||
test(source_text, source_text);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cjs() {
|
||||
// Do not join `require` calls for cjs-module-lexer.
|
||||
test_same(
|
||||
"
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
var compilerDom = require('@vue/compiler-dom');
|
||||
var runtimeDom = require('@vue/runtime-dom');
|
||||
var shared = require('@vue/shared');
|
||||
",
|
||||
);
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
mod collapse_variable_declarations;
|
||||
mod fold_conditions;
|
||||
mod fold_constants;
|
||||
mod remove_dead_code;
|
||||
|
|
|
|||
Loading…
Reference in a new issue