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

feat: add emitDecoratorMetadata config #1420

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions crates/mako/src/build/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,12 @@ impl Transform {

// folders
let mut folders: Vec<Box<dyn Fold>> = vec![];
// decorators should go before preset_env, when compile down to es5, classes become functions, then the decorators on the functions will be removed silently.
// decorators should go before preset_env, when compile down to es5,
// classes become functions, then the decorators on the functions
// will be removed silently.
folders.push(Box::new(decorators(decorators::Config {
legacy: true,
emit_metadata: false,
emit_metadata: context.config.emit_decorator_metadata,
..Default::default()
})));
let comments = origin_comments.get_swc_comments().clone();
Expand Down
2 changes: 2 additions & 0 deletions crates/mako/src/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ pub struct Config {
pub experimental: ExperimentalConfig,
pub watch: WatchConfig,
pub use_define_for_class_fields: bool,
pub emit_decorator_metadata: bool,
}

#[derive(Deserialize, Serialize, Clone, Debug, Default)]
Expand Down Expand Up @@ -717,6 +718,7 @@ const DEFAULT_CONFIG: &str = r#"
"detectLoop": { "ignoreNodeModules": true, "graphviz": false }
},
"useDefineForClassFields": true,
"emitDecoratorMetadata": false,
"watch": { "ignorePaths": [] },
"devServer": { "host": "127.0.0.1", "port": 3000 }
}
Expand Down
9 changes: 8 additions & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ import("./a.js");

Whether to output assets files. Usually set to `false` when building a pure server-side rendering project, because assets files are not needed at this time.

### emitDecoratorMetadata

- Type: `boolean`
- Default: `false`

Whether to emit decorator metadata.

### emotion

- Type: `boolean`
Expand Down Expand Up @@ -691,7 +698,7 @@ Whether to output umd format.
### useDefineForClassFields

- Type: `boolean`
- Default: `false`
- Default: `true`

Whether to use `defineProperty` to define class fields.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const assert = require("assert");
const { parseBuildResult, trim, moduleReg, injectSimpleJest } = require("../../../scripts/test-utils");
const { files } = parseBuildResult(__dirname);

const content = files["index.js"];
assert(
content.includes(`_ts_metadata._("design:type", Function),`),
`emitDecoratorMetadata works`,
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"emitDecoratorMetadata": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@Decorate
class MyClass {
constructor(
private generic: Generic<A>,
generic2: Generic<A, B>
) {}

@Run
method(
generic: Inter<A>,
@Arg() generic2: InterGen<A, B>
) {}
}
Loading