From 93d9f51d16711e6ec0763e1189eb1a57a5ba8e3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos=20Veres?= Date: Wed, 2 Dec 2020 20:26:04 +0100 Subject: fix(cli): add hygiene pass to transpile pipeline (#8586) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bartek IwaƄczuk --- cli/ast.rs | 2 ++ cli/tests/integration_tests.rs | 5 +++++ cli/tests/runtime_decorators.ts | 42 +++++++++++++++++++++++++++++++++++++ cli/tests/runtime_decorators.ts.out | 7 +++++++ 4 files changed, 56 insertions(+) create mode 100644 cli/tests/runtime_decorators.ts create mode 100644 cli/tests/runtime_decorators.ts.out (limited to 'cli') diff --git a/cli/ast.rs b/cli/ast.rs index ab32e4301..10d7b5383 100644 --- a/cli/ast.rs +++ b/cli/ast.rs @@ -42,6 +42,7 @@ use swc_ecmascript::parser::Syntax; use swc_ecmascript::parser::TsConfig; use swc_ecmascript::transforms::fixer; use swc_ecmascript::transforms::helpers; +use swc_ecmascript::transforms::hygiene; use swc_ecmascript::transforms::pass::Optional; use swc_ecmascript::transforms::proposals; use swc_ecmascript::transforms::react; @@ -305,6 +306,7 @@ impl ParsedModule { helpers::inject_helpers(), typescript::strip(), fixer(Some(&self.comments)), + hygiene(), ); let program = swc_common::GLOBALS.set(&Globals::new(), || { diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index c99033020..aca2df99c 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -2927,6 +2927,11 @@ itest!(no_check_decorators { output: "no_check_decorators.ts.out", }); +itest!(runtime_decorators { + args: "run --quiet --reload --no-check runtime_decorators.ts", + output: "runtime_decorators.ts.out", +}); + itest!(lib_ref { args: "run --quiet --unstable --reload lib_ref.ts", output: "lib_ref.ts.out", diff --git a/cli/tests/runtime_decorators.ts b/cli/tests/runtime_decorators.ts new file mode 100644 index 000000000..5da109110 --- /dev/null +++ b/cli/tests/runtime_decorators.ts @@ -0,0 +1,42 @@ +// deno-lint-ignore-file +function A() { + console.log("@A evaluated"); + return function ( + target: any, + propertyKey: string, + descriptor: PropertyDescriptor, + ) { + console.log("@A called"); + const fn = descriptor.value; + descriptor.value = function () { + console.log("fn() called from @A"); + fn(); + }; + }; +} + +function B() { + console.log("@B evaluated"); + return function ( + target: any, + propertyKey: string, + descriptor: PropertyDescriptor, + ) { + console.log("@B called"); + const fn = descriptor.value; + descriptor.value = function () { + console.log("fn() called from @B"); + fn(); + }; + }; +} + +class C { + @A() + @B() + static test() { + console.log("C.test() called"); + } +} + +C.test(); diff --git a/cli/tests/runtime_decorators.ts.out b/cli/tests/runtime_decorators.ts.out new file mode 100644 index 000000000..0fc1d4590 --- /dev/null +++ b/cli/tests/runtime_decorators.ts.out @@ -0,0 +1,7 @@ +@A evaluated +@B evaluated +@B called +@A called +fn() called from @A +fn() called from @B +C.test() called -- cgit v1.2.3