From 7f6bf59a98710ce7964e99ab621a68dc729c021d Mon Sep 17 00:00:00 2001 From: Alexander Akait <4567934+alexander-akait@users.noreply.github.com> Date: Fri, 18 Nov 2022 05:32:55 +0300 Subject: [PATCH] feat(html/minifier): Use the latest `EsVersion` (#6453) --- crates/swc_html_minifier/src/lib.rs | 4 ++-- .../script-group-respect-codegen-1/config.json | 12 ++++++++++++ .../script-group-respect-codegen-1/input.html | 14 ++++++++++++++ .../output.min.html | 5 +++++ .../script-group-respect-codegen-2/config.json | 3 +++ .../script-group-respect-codegen-2/input.html | 16 ++++++++++++++++ .../output.min.html | 11 +++++++++++ .../script-group-respect-codegen/config.json | 7 +++++++ .../script-group-respect-codegen/input.html | 14 ++++++++++++++ .../script-group-respect-codegen/output.min.html | 5 +++++ 10 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 crates/swc_html_minifier/tests/fixture/element/script-group-respect-codegen-1/config.json create mode 100644 crates/swc_html_minifier/tests/fixture/element/script-group-respect-codegen-1/input.html create mode 100644 crates/swc_html_minifier/tests/fixture/element/script-group-respect-codegen-1/output.min.html create mode 100644 crates/swc_html_minifier/tests/fixture/element/script-group-respect-codegen-2/config.json create mode 100644 crates/swc_html_minifier/tests/fixture/element/script-group-respect-codegen-2/input.html create mode 100644 crates/swc_html_minifier/tests/fixture/element/script-group-respect-codegen-2/output.min.html create mode 100644 crates/swc_html_minifier/tests/fixture/element/script-group-respect-codegen/config.json create mode 100644 crates/swc_html_minifier/tests/fixture/element/script-group-respect-codegen/input.html create mode 100644 crates/swc_html_minifier/tests/fixture/element/script-group-respect-codegen/output.min.html diff --git a/crates/swc_html_minifier/src/lib.rs b/crates/swc_html_minifier/src/lib.rs index bf6f343c271..ff4c362f7ca 100644 --- a/crates/swc_html_minifier/src/lib.rs +++ b/crates/swc_html_minifier/src/lib.rs @@ -1988,8 +1988,8 @@ impl Minifier<'_> { let mut left_errors: Vec<_> = vec![]; let left_fm = cm.new_source_file(FileName::Anon, left); let syntax = swc_ecma_parser::Syntax::default(); - // TODO improve me using options - let target = swc_ecma_ast::EsVersion::default(); + // Use the latest target for merging + let target = swc_ecma_ast::EsVersion::latest(); let mut left_program = if is_modules { match swc_ecma_parser::parse_file_as_module( diff --git a/crates/swc_html_minifier/tests/fixture/element/script-group-respect-codegen-1/config.json b/crates/swc_html_minifier/tests/fixture/element/script-group-respect-codegen-1/config.json new file mode 100644 index 00000000000..5cd57afede4 --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/element/script-group-respect-codegen-1/config.json @@ -0,0 +1,12 @@ +{ + "minifyJs": { + "parser": { + "comments": true, + "syntax": "ecmascript", + "target": "es2022" + }, + "codegen": { + "asciiOnly": false + } + } +} diff --git a/crates/swc_html_minifier/tests/fixture/element/script-group-respect-codegen-1/input.html b/crates/swc_html_minifier/tests/fixture/element/script-group-respect-codegen-1/input.html new file mode 100644 index 00000000000..4c24f91c65c --- /dev/null +++ b/crates/swc_html_minifier/tests/fixture/element/script-group-respect-codegen-1/input.html @@ -0,0 +1,14 @@ + + +
+