mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 22:56:11 +03:00
feat(es): Expose stage 3 decorator (#7220)
This commit is contained in:
parent
4b9cfbb4dd
commit
a7a53c6208
@ -703,11 +703,20 @@ impl Options {
|
||||
})),
|
||||
// Decorators may use type information
|
||||
Optional::new(
|
||||
decorators(decorators::Config {
|
||||
legacy: transform.legacy_decorator.into_bool(),
|
||||
emit_metadata: transform.decorator_metadata.into_bool(),
|
||||
use_define_for_class_fields: !assumptions.set_public_class_fields
|
||||
}),
|
||||
match transform.decorator_version.unwrap_or_default() {
|
||||
DecoratorVersion::V202112 => {
|
||||
Either::Left(decorators(decorators::Config {
|
||||
legacy: transform.legacy_decorator.into_bool(),
|
||||
emit_metadata: transform.decorator_metadata.into_bool(),
|
||||
use_define_for_class_fields: !assumptions.set_public_class_fields,
|
||||
}))
|
||||
}
|
||||
DecoratorVersion::V202203 => {
|
||||
Either::Right(
|
||||
swc_ecma_transforms::proposals::decorator_2022_03::decorator_2022_03(),
|
||||
)
|
||||
}
|
||||
},
|
||||
syntax.decorators()
|
||||
),
|
||||
// The transform strips import assertions, so it's only enabled if
|
||||
@ -1552,6 +1561,20 @@ pub struct TransformConfig {
|
||||
|
||||
#[serde(default)]
|
||||
pub use_define_for_class_fields: BoolConfig<true>,
|
||||
|
||||
#[serde(default)]
|
||||
pub decorator_version: Option<DecoratorVersion>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Copy, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields, rename_all = "camelCase")]
|
||||
pub enum DecoratorVersion {
|
||||
#[default]
|
||||
#[serde(rename = "2021-12")]
|
||||
V202112,
|
||||
|
||||
#[serde(rename = "2022-03")]
|
||||
V202203,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Serialize, Deserialize, Merge)]
|
||||
|
11
crates/swc/tests/fixture/issues-7xxx/7220/1/input/.swcrc
Normal file
11
crates/swc/tests/fixture/issues-7xxx/7220/1/input/.swcrc
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"jsc": {
|
||||
"parser": {
|
||||
"syntax": "ecmascript",
|
||||
"decorators": true
|
||||
},
|
||||
"transform": {
|
||||
"decoratorVersion": "2022-03"
|
||||
}
|
||||
}
|
||||
}
|
14
crates/swc/tests/fixture/issues-7xxx/7220/1/input/index.js
Normal file
14
crates/swc/tests/fixture/issues-7xxx/7220/1/input/index.js
Normal file
@ -0,0 +1,14 @@
|
||||
const _BOUND_FUNCTIONS = {};
|
||||
|
||||
export class BackgroundJob {
|
||||
}
|
||||
|
||||
class TestClass {
|
||||
calls = [];
|
||||
|
||||
@BackgroundJob.bind
|
||||
success(s, n) {
|
||||
this.calls.push(`success(${s}, ${n})`);
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
40
crates/swc/tests/fixture/issues-7xxx/7220/1/output/index.js
Normal file
40
crates/swc/tests/fixture/issues-7xxx/7220/1/output/index.js
Normal file
@ -0,0 +1,40 @@
|
||||
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
||||
import { _ as _create_class } from "@swc/helpers/_/_create_class";
|
||||
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
||||
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
||||
import { _ as _apply_decs_2203_r } from "@swc/helpers/_/_apply_decs_2203_r";
|
||||
var _dec, _initProto;
|
||||
var _BOUND_FUNCTIONS = {};
|
||||
export var BackgroundJob = function BackgroundJob() {
|
||||
"use strict";
|
||||
_class_call_check(this, BackgroundJob);
|
||||
};
|
||||
_dec = BackgroundJob.bind;
|
||||
var TestClass = /*#__PURE__*/ function() {
|
||||
"use strict";
|
||||
function TestClass() {
|
||||
_class_call_check(this, TestClass);
|
||||
_define_property(this, "calls", []);
|
||||
_initProto(this);
|
||||
}
|
||||
_create_class(TestClass, [
|
||||
{
|
||||
key: "success",
|
||||
value: function success(s, n) {
|
||||
this.calls.push("success(".concat(s, ", ").concat(n, ")"));
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
]);
|
||||
return TestClass;
|
||||
}();
|
||||
(function() {
|
||||
var ref, ref1;
|
||||
ref = _apply_decs_2203_r(TestClass, [
|
||||
[
|
||||
_dec,
|
||||
2,
|
||||
"success"
|
||||
]
|
||||
], []), ref1 = _sliced_to_array(ref.e, 1), _initProto = ref1[0], ref1, ref;
|
||||
})();
|
Loading…
Reference in New Issue
Block a user