Skip to content

Commit

Permalink
fix(cli): add hygiene pass to transpile pipeline (#8586)
Browse files Browse the repository at this point in the history
Co-authored-by: Bartek Iwańczuk <[email protected]>
  • Loading branch information
jveres and bartlomieju authored Dec 2, 2020
1 parent 95ccc1a commit 93d9f51
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cli/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -305,6 +306,7 @@ impl ParsedModule {
helpers::inject_helpers(),
typescript::strip(),
fixer(Some(&self.comments)),
hygiene(),
);

let program = swc_common::GLOBALS.set(&Globals::new(), || {
Expand Down
5 changes: 5 additions & 0 deletions cli/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
42 changes: 42 additions & 0 deletions cli/tests/runtime_decorators.ts
Original file line number Diff line number Diff line change
@@ -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();
7 changes: 7 additions & 0 deletions cli/tests/runtime_decorators.ts.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@A evaluated
@B evaluated
@B called
@A called
fn() called from @A
fn() called from @B
C.test() called

0 comments on commit 93d9f51

Please sign in to comment.