-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(es/decorators): Add tests written by evanw (#8967)
**Description:** Add https://github.com/evanw/decorator-tests as partially ignored tests so we can work on decorator fixes gradually.
- Loading branch information
Showing
7 changed files
with
92 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
run-decorator-tests.js |
Submodule decorator-tests
added at
8e9c0b
81 changes: 81 additions & 0 deletions
81
crates/swc_ecma_transforms_proposal/tests/decorator_esbuild.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
use std::{fs, process::Command}; | ||
|
||
use swc_common::Mark; | ||
use swc_ecma_ast::EsVersion; | ||
use swc_ecma_codegen::to_code; | ||
use swc_ecma_parser::parse_file_as_program; | ||
use swc_ecma_transforms_base::{ | ||
fixer::fixer, | ||
helpers::{inject_helpers, Helpers, HELPERS}, | ||
hygiene::hygiene, | ||
resolver, | ||
}; | ||
use swc_ecma_transforms_proposal::decorator_2022_03::decorator_2022_03; | ||
use swc_ecma_visit::VisitMutWith; | ||
use testing::find_executable; | ||
|
||
#[test] | ||
#[ignore = "TODO: Fix this test"] | ||
fn execute() { | ||
testing::run_test(false, |cm, handler| { | ||
let node = find_executable("node").expect("node not found"); | ||
|
||
let fm = cm | ||
.load_file("tests/decorator-tests/decorator-tests.js".as_ref()) | ||
.expect("failed to load file"); | ||
|
||
let code = { | ||
// Transpile with swc | ||
let mut errors = vec![]; | ||
|
||
let program = parse_file_as_program( | ||
&fm, | ||
swc_ecma_parser::Syntax::Es(swc_ecma_parser::EsConfig { | ||
decorators: true, | ||
auto_accessors: true, | ||
..Default::default() | ||
}), | ||
EsVersion::EsNext, | ||
None, | ||
&mut errors, | ||
); | ||
|
||
let mut program = match program { | ||
Ok(v) => v, | ||
Err(e) => { | ||
e.into_diagnostic(handler).emit(); | ||
return Err(()); | ||
} | ||
}; | ||
|
||
for e in errors { | ||
e.into_diagnostic(handler).emit(); | ||
} | ||
HELPERS.set(&Helpers::new(false), || { | ||
let unresolved_mark = Mark::new(); | ||
let top_level_mark = Mark::new(); | ||
program.visit_mut_with(&mut resolver(unresolved_mark, top_level_mark, false)); | ||
|
||
program.visit_mut_with(&mut decorator_2022_03()); | ||
|
||
program.visit_mut_with(&mut inject_helpers(unresolved_mark)); | ||
program.visit_mut_with(&mut hygiene()); | ||
program.visit_mut_with(&mut fixer(None)); | ||
}); | ||
|
||
to_code(&program) | ||
}; | ||
|
||
fs::write("tests/run-decorator-tests.js", code).expect("failed to write file"); | ||
|
||
let status = Command::new(node) | ||
.arg("tests/run-decorator-tests.js") | ||
.status() | ||
.expect("failed to execute process"); | ||
|
||
assert!(status.success()); | ||
|
||
Ok(()) | ||
}) | ||
.unwrap() | ||
} |