Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(minifier): correct the reference link #6283

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions crates/oxc_minifier/src/ast_passes/exploit_assigns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
48 changes: 48 additions & 0 deletions crates/oxc_minifier/src/ast_passes/peephole_remove_dead_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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;");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down