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

decorators code tranform seems to run before the plugin transform #9767

Closed
mantou132 opened this issue Nov 28, 2024 · 1 comment
Closed

decorators code tranform seems to run before the plugin transform #9767

mantou132 opened this issue Nov 28, 2024 · 1 comment
Labels

Comments

@mantou132
Copy link

mantou132 commented Nov 28, 2024

Describe the bug

I want to rewrite the decorators device through the plugin to meet the decorators specifications, but it has been rewritten by SWC before the plugin

Input code

source code:

@customElement("page-home")
@adoptedStyle(style)
export class PageHomeElement extends GemElement {
  @memo()
  get #content() {
    return 0;
  }
}

plugin:

impl VisitMut for TransformVisitor {
    noop_visit_mut_type!();

    fn visit_mut_private_method(&mut self, node: &mut PrivateMethod) {
        panic!("{:?}", node);  
    }
}


### Config

```json
{
  "$schema": "https://swc.rs/schema.json",
  "env": {
    "targets": {
      "chrome": "110"
    }
  },
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "decorators": true
    },
    "transform": {
      "decoratorVersion": "2022-03"
    },
    "experimental": {
      "plugins": [["./swc_plugin_gem.wasm"]]
    }
  }
}

Playground link (or link to the minimal reproduction)

https://github.com/mantou132/gem/blob/37045dbac0ea07f984db250a5dfe8628bd1b87c7/crates/swc-plugin-gem/src/visitors/memo.rs#L78

SWC Info output

PrivateMethod { span: 157..254, key: PrivateName { span: 171..179, name: "content" }, function: Function { params: [], decorators: [], span: 157..254, ctxt: #3, body: Some(BlockStmt { span: 0..0, ctxt: #0, stmts: [Return(ReturnStmt { span: 
0..0, arg: Some(Call(CallExpr { span: 0..0, ctxt: #0, callee: Expr(Ident(Ident { span: 0..0, ctxt: #15, sym: "_call_content", optional: false })), args: [ExprOrSpread { spread: None, expr: This(ThisExpr { span: 0..0 }) }], type_args: None })) })] }), is_generator: false, is_async: false, type_params: None, return_type: None }, kind: Getter, is_static: false, accessibility: None, is_abstract: false, is_optional: false, is_override: false }

Expected behavior

function body is "return 0;"

Actual behavior

No response

Version

1.9.3

Additional context

swc_core = "5.0.0"
swc_ecma_parser = "5.0.0"
swc_ecma_visit = "4.0.0"
swc_ecma_ast = "4.0.0"
swc_common = "4.0.0"

@kdy1
Copy link
Member

kdy1 commented Nov 28, 2024

swc/packages/types/index.ts

Lines 670 to 675 in b83c44f

/**
* Run Wasm plugins before stripping TypeScript or decorators.
*
* See https://github.com/swc-project/swc/issues/9132 for more details.
*/
runPluginFirst?: boolean;

@kdy1 kdy1 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 28, 2024
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