mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
fix(minifier): correct the reference link (#6283)
These are minor changes, and recently I’ve been learning and trying to implement some features of `oxc_minifier`, which feels a bit complex. By the way, I’m wondering whether we should gradually add test cases during the feature implementation process or just copy all the corresponding tests directly? Perhaps we could implement something like `rulegen` similar to `linter`?
This commit is contained in:
parent
f0a74ca7c6
commit
d953a6be02
6 changed files with 55 additions and 4 deletions
|
|
@ -7,6 +7,7 @@ use crate::{CompressOptions, CompressorPass};
|
|||
/// Collapse variable declarations.
|
||||
///
|
||||
/// `var a; var b = 1; var c = 2` => `var a, b = 1; c = 2`
|
||||
/// <https://github.com/google/closure-compiler/blob/master/src/com/google/javascript/jscomp/CollapseVariableDeclarations.java>
|
||||
pub struct CollapseVariableDeclarations {
|
||||
options: CompressOptions,
|
||||
|
||||
|
|
@ -99,7 +100,7 @@ impl<'a> CollapseVariableDeclarations {
|
|||
}
|
||||
}
|
||||
|
||||
/// <https://github.com/google/closure-compiler/blob/master/test/com/google/javascript/jscomp/CollapseVariableDeclarations.java>
|
||||
/// <https://github.com/google/closure-compiler/blob/master/test/com/google/javascript/jscomp/CollapseVariableDeclarationsTest.java>
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use oxc_allocator::Allocator;
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ impl ExploitAssigns {
|
|||
}
|
||||
}
|
||||
|
||||
/// <https://github.com/google/closure-compiler/blob/master/test/com/google/javascript/jscomp/ExploitAssignsTest.java>
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use oxc_allocator::Allocator;
|
||||
|
|
|
|||
|
|
@ -867,7 +867,7 @@ impl<'a> PeepholeFoldConstants {
|
|||
}
|
||||
}
|
||||
|
||||
/// <https://github.com/google/closure-compiler/blob/master/test/com/google/javascript/jscomp/PeepholeFoldConstants.java>
|
||||
/// <https://github.com/google/closure-compiler/blob/master/test/com/google/javascript/jscomp/PeepholeFoldConstantsTest.java>
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use oxc_allocator::Allocator;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ use crate::{keep_var::KeepVar, node_util::NodeUtil, tri::Tri, CompressorPass};
|
|||
/// Terser option: `dead_code: true`.
|
||||
///
|
||||
/// See `KeepVar` at the end of this file for `var` hoisting logic.
|
||||
/// <https://github.com/google/closure-compiler/blob/master/src/com/google/javascript/jscomp/PeepholeRemoveDeadCode.java>
|
||||
pub struct PeepholeRemoveDeadCode {
|
||||
changed: bool,
|
||||
}
|
||||
|
|
@ -183,3 +184,50 @@ impl<'a> PeepholeRemoveDeadCode {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <https://github.com/google/closure-compiler/blob/master/test/com/google/javascript/jscomp/PeepholeRemoveDeadCodeTest.java>
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use oxc_allocator::Allocator;
|
||||
|
||||
use crate::tester;
|
||||
|
||||
fn test(source_text: &str, positive: &str) {
|
||||
let allocator = Allocator::default();
|
||||
let mut pass = super::PeepholeRemoveDeadCode::new();
|
||||
tester::test(&allocator, source_text, positive, &mut pass);
|
||||
}
|
||||
|
||||
fn test_same(source_text: &str) {
|
||||
test(source_text, source_text);
|
||||
}
|
||||
|
||||
fn fold_same(js: &str) {
|
||||
test_same(js);
|
||||
}
|
||||
|
||||
fn fold(js: &str, expected: &str) {
|
||||
test(js, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn test_remove_no_op_labelled_statement() {
|
||||
fold("a: break a;", "");
|
||||
fold("a: { break a; }", "");
|
||||
|
||||
fold(
|
||||
//
|
||||
"a: { break a; console.log('unreachable'); }", //
|
||||
"",
|
||||
);
|
||||
fold(
|
||||
//
|
||||
"a: { break a; var x = 1; } x = 2;", //
|
||||
"var x; x = 2;",
|
||||
);
|
||||
|
||||
fold_same("b: { var x = 1; } x = 2;");
|
||||
fold_same("a: b: { var x = 1; } x = 2;");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use oxc_traverse::{Traverse, TraverseCtx};
|
|||
use crate::CompressorPass;
|
||||
|
||||
/// Minimize With Known Methods
|
||||
/// <https://github.com/google/closure-compiler/blob/master/src/com/google/javascript/jscomp/PeepholeMinimizeReplacements.java>
|
||||
/// <https://github.com/google/closure-compiler/blob/master/src/com/google/javascript/jscomp/PeepholeReplaceKnownMethods.java>
|
||||
pub struct PeepholeReplaceKnownMethods {
|
||||
changed: bool,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ use crate::{node_util::NodeUtil, CompressOptions, CompressorPass};
|
|||
/// A peephole optimization that minimizes code by simplifying conditional
|
||||
/// expressions, replacing IFs with HOOKs, replacing object constructors
|
||||
/// with literals, and simplifying returns.
|
||||
/// <https://github.com/google/closure-compiler/blob/master/src/com/google/javascript/jscomp/PeepholeSubstituteAlternateSyntax.java>
|
||||
pub struct PeepholeSubstituteAlternateSyntax {
|
||||
options: CompressOptions,
|
||||
in_define_export: bool,
|
||||
|
|
@ -329,7 +330,7 @@ impl<'a> PeepholeSubstituteAlternateSyntax {
|
|||
}
|
||||
}
|
||||
|
||||
/// <https://github.com/google/closure-compiler/blob/master/test/com/google/javascript/jscomp/PeepholeSubstituteAlternateSyntax.java>
|
||||
/// <https://github.com/google/closure-compiler/blob/master/test/com/google/javascript/jscomp/PeepholeSubstituteAlternateSyntaxTest.java>
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use oxc_allocator::Allocator;
|
||||
|
|
|
|||
Loading…
Reference in a new issue