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

Panic: "called Option::unwrap() on a None value" #18

Open
charlyisidore opened this issue Jan 11, 2024 · 1 comment · May be fixed by #19
Open

Panic: "called Option::unwrap() on a None value" #18

charlyisidore opened this issue Jan 11, 2024 · 1 comment · May be fixed by #19

Comments

@charlyisidore
Copy link

I am using the current git version of minify-js. The following issue happens from version 0.6.0 (0.5.6 works fine).

When I try minify the code if (a) a, I get the following error with RUST_BACKTRACE=1:

thread 'main' panicked at /home/user/.cargo/git/checkouts/minify-js-4f5cda0ad742d80b/77dae36/rust/src/minify/pass1.rs:379:81:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0: rust_begin_unwind
             at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_fmt
             at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/core/src/panicking.rs:72:14
   2: core::panicking::panic
             at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/core/src/panicking.rs:144:5
   3: core::option::Option<T>::unwrap
             at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/core/src/option.rs:931:21
   4: <minify_js::minify::pass1::Pass1 as parse_js::visit::Visitor>::on_syntax_up
             at /home/user/.cargo/git/checkouts/minify-js-4f5cda0ad742d80b/77dae36/rust/src/minify/pass1.rs:379:33
   5: parse_js::visit::Visitor::visit
             at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/parse-js-0.21.0/src/visit.rs:475:7
   6: parse_js::visit::Visitor::visit
             at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/parse-js-0.21.0/src/visit.rs:77:11
   7: minify_js::minify::minify_js
             at /home/user/.cargo/git/checkouts/minify-js-4f5cda0ad742d80b/77dae36/rust/src/minify/mod.rs:36:3
   8: minify_js::minify
             at /home/user/.cargo/git/checkouts/minify-js-4f5cda0ad742d80b/77dae36/rust/src/lib.rs:50:3
   9: minify_js_bugfix::main
             at ./src/main.rs:9:5
  10: core::ops::function::FnOnce::call_once
             at /rustc/e51e98dde6a60637b6a71b8105245b629ac3fe77/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

The error happens here:

let closure_scope = scope.find_self_or_ancestor(|t| t.is_closure()).unwrap();

Please find below the code to reproduce the error:

  • src/main.rs:
use minify_js::{minify, Session, TopLevelMode};

fn main() -> anyhow::Result<()> {
    let input: &str = "if (a) a";

    let session = Session::new();
    let mut output = Vec::new();

    minify(
        &session,
        TopLevelMode::Global,
        input.as_bytes(),
        &mut output,
    ).map_err(|e| anyhow::anyhow!(e.to_string()))?;

    println!("{}", String::from_utf8(output)?);

    Ok(())
}
  • Cargo.toml:
[package]
name = "minify_js_issue"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
anyhow = "1.0.79"
minify-js = { git = "https://github.com/wilsonzlin/minify-js", version = "0.6.0" }

Many thanks for this great library.

@RuairidhWilliamson RuairidhWilliamson linked a pull request Jan 28, 2024 that will close this issue
@organnerx
Copy link

Same problem. Until it get fixed you can modify input js file to have 1 big IIFE:
"use strict";
(() => {
// your code goes here;
})();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants