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

Unexpected output with decorators #26

Closed
KerryRitter opened this issue Feb 6, 2021 · 3 comments
Closed

Unexpected output with decorators #26

KerryRitter opened this issue Feb 6, 2021 · 3 comments

Comments

@KerryRitter
Copy link

KerryRitter commented Feb 6, 2021

Hi there!

I don't rule out user-error so I apologize if this is the wrong forum, but I'm building a CLI and I want to append a new item to an array in a decorator object. When I parse the below code, it produces an output that places the export keyword in front of the decorator instead of in front of the class keyword.

import { parse, print } from "https://x.nest.land/swc@0.0.6/mod.ts";

const ast = parse(`
import { MvModule } from "./deps.ts";

class Test {}

@MvModule({
  providers: []
})
export class TestModule {}
`,{
  syntax: "typescript",
  decorators: true,
});

const { code } = print(ast, {
  jsc: {
    parser: {
      syntax: 'typescript',
      decorators: true,
    }
  }
});
Deno.writeTextFileSync('test.ts', code);

/* Outputs
import { MvModule } from "./deps.ts";
class Test {
}
export @MvModule({
    providers: [
        Test
    ]
})
class TestModule {
}
*/
@littledivy
Copy link
Owner

Hi @KerryRitter Sorry for the late reply! This is likely to be an old swc bug. We are still locked to an older version of SWC at the moment. Should be fixed after updating 👍

@tamusjroyce
Copy link
Contributor

@KerryRitter, give master a try now?

@littledivy
Copy link
Owner

@KerryRitter The code you are trying to parse is valid TS but in JS export must be before the decorator (export @dec class) and so the transformed source is correct.

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

No branches or pull requests

3 participants