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

[swc plugin] The handler.struct_span_warn does not emit warnings if the plugin transform completes without errors #9887

Open
gaoachao opened this issue Jan 16, 2025 · 0 comments
Labels
Milestone

Comments

@gaoachao
Copy link

gaoachao commented Jan 16, 2025

Describe the bug

How to run the demo

demo: https://github.com/gaoachao/swc-plugin-demo

pnpm install
pnpm run build
npx swc ./index.js

Current behavior

  • When the transform is successful, warnings are not printed.
  • When there is an error during the transform, warnings are printed.

Expected behavior

When npx swc index.js succeeds, warnings should still be printed in the terminal.

How to Reproduce the Issue

Here is my code, and no warnings are printed.

"createSelectorQuery" => {
    HANDLER.with(|handler| {
        handler
            .struct_span_warn(
                n.span,
                format!(
                    "WARNING: {} is deprecated.",
                    id.sym.to_string()
                )
                .as_str(),
            )
            .emit()
    });
}
"getElementById" => {
    HANDLER.with(|handler| {
        handler
            .struct_span_warn(
                n.span,
                format!(
                    "WARNING: {} is deprecated.",
                    id.sym.to_string()
                )
                .as_str(),
            )
            .emit()
    });
}

If I change one of the struct_span_warn calls to struct_span_err, both warnings and errors will be printed on the terminal.

"createSelectorQuery" => {
    HANDLER.with(|handler| {
        handler
            .struct_span_err(
                n.span,
                format!(
                    "WARNING: {} is deprecated.",
                    id.sym.to_string()
                )
                .as_str(),
            )
            .emit()
    });
}
"getElementById" => {
    HANDLER.with(|handler| {
        handler
            .struct_span_warn(
                n.span,
                format!(
                    "WARNING: {} is deprecated.",
                    id.sym.to_string()
                )
                .as_str(),
            )
            .emit()
    });
}

Input code

this.createSelectorQuery();
this.getElementById();

Config

{
  "$schema": "https://swc.rs/schema.json",
  "isModule": true,
  "jsc": {
    "parser": {
      "syntax": "ecmascript"
    },
    "target": "es2022",
    "experimental": {
      "plugins": [["./my_first_plugin.wasm", {}]]
    }
  }
}

Playground link (or link to the minimal reproduction)

https://github.com/gaoachao/swc-plugin-demo

SWC Info output

No response

Expected behavior

When the transform is successful, warnings should still be printed in the terminal.

Actual behavior

No response

Version

swc_core = { version = "9.0.*", features = ["ecma_plugin_transform"] }

Additional context

No response

@gaoachao gaoachao added the C-bug label Jan 16, 2025
@gaoachao gaoachao changed the title [swc plugin] The handler.struct_span_warn does not emit warnings if the plugin transformation completes without errors [swc plugin] The handler.struct_span_warn does not emit warnings if the plugin transform completes without errors Jan 16, 2025
@kdy1 kdy1 added this to the Planned milestone Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants