From bbfa97a475fdfe18fe9e3ea29329ecb39ed2ddac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Wed, 11 Jan 2023 16:42:09 +0900 Subject: [PATCH] fix(es/decorator): Fix type detection for template literal types (#6786) **Related issue:** - Closes https://github.com/swc-project/swc/issues/6682. --- .../tests/fixture/legacy-metadata/issues/6683/input.ts | 8 ++++++++ .../fixture/legacy-metadata/issues/6683/output.ts | 10 ++++++++++ .../src/decorators/legacy/metadata.rs | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 crates/swc_ecma_transforms/tests/fixture/legacy-metadata/issues/6683/input.ts create mode 100644 crates/swc_ecma_transforms/tests/fixture/legacy-metadata/issues/6683/output.ts diff --git a/crates/swc_ecma_transforms/tests/fixture/legacy-metadata/issues/6683/input.ts b/crates/swc_ecma_transforms/tests/fixture/legacy-metadata/issues/6683/input.ts new file mode 100644 index 000000000000..ab2c33cd4959 --- /dev/null +++ b/crates/swc_ecma_transforms/tests/fixture/legacy-metadata/issues/6683/input.ts @@ -0,0 +1,8 @@ +function decorator(): PropertyDecorator { + return () => null +} + +class Example { + @decorator() + value?: `prefix${string}`; +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms/tests/fixture/legacy-metadata/issues/6683/output.ts b/crates/swc_ecma_transforms/tests/fixture/legacy-metadata/issues/6683/output.ts new file mode 100644 index 000000000000..de0e34126dc1 --- /dev/null +++ b/crates/swc_ecma_transforms/tests/fixture/legacy-metadata/issues/6683/output.ts @@ -0,0 +1,10 @@ +function decorator(): PropertyDecorator { + return ()=>null; +} +class Example { + value?: `prefix${string}`; +} +__decorate([ + decorator(), + __metadata("design:type", String) +], Example.prototype, "value", void 0); diff --git a/crates/swc_ecma_transforms_proposal/src/decorators/legacy/metadata.rs b/crates/swc_ecma_transforms_proposal/src/decorators/legacy/metadata.rs index eb80dc56fd0a..c68e7bc8f6a6 100644 --- a/crates/swc_ecma_transforms_proposal/src/decorators/legacy/metadata.rs +++ b/crates/swc_ecma_transforms_proposal/src/decorators/legacy/metadata.rs @@ -511,7 +511,7 @@ fn get_type_ann_of_pat(p: &Pat) -> Option<&TsTypeAnn> { fn is_str(ty: &TsType) -> bool { match ty { TsType::TsLitType(TsLitType { - lit: TsLit::Str(..), + lit: TsLit::Str(..) | TsLit::Tpl(..), .. }) | TsType::TsKeywordType(TsKeywordType {