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.
This commit is contained in:
Donny/강동윤 2024-05-23 14:18:32 +09:00 committed by GitHub
parent 0d1c3b91c9
commit 95472e4037
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 92 additions and 3 deletions

3
.gitmodules vendored
View File

@ -8,3 +8,6 @@
url = https://github.com/html5lib/html5lib-tests.git
shallow = true
ignore = dirty
[submodule "crates/swc_ecma_transforms_proposal/tests/decorator-tests"]
path = crates/swc_ecma_transforms_proposal/tests/decorator-tests
url = https://github.com/evanw/decorator-tests

View File

@ -19,7 +19,8 @@
"git.autoRepositoryDetection": false,
"git.ignoredRepositories": [
"crates/swc_ecma_parser/tests/test262-parser",
"crates/swc_html_parser/tests/html5lib-tests"
"crates/swc_html_parser/tests/html5lib-tests",
"crates/swc_ecma_transforms_proposal/tests/decorator-tests"
],
"eslint.enable": false,
"rust-analyzer.check.command": "clippy",

1
Cargo.lock generated
View File

@ -4785,6 +4785,7 @@ dependencies = [
"swc_atoms",
"swc_common",
"swc_ecma_ast",
"swc_ecma_codegen",
"swc_ecma_loader",
"swc_ecma_parser",
"swc_ecma_transforms_base",

View File

@ -35,6 +35,7 @@ swc_ecma_visit = { version = "0.99.1", path = "../swc_ecma_visit" }
[dev-dependencies]
serde_json = { workspace = true }
swc_ecma_codegen = { version = "0.149.1", path = "../swc_ecma_codegen" }
swc_ecma_parser = { version = "0.144.1", path = "../swc_ecma_parser" }
swc_ecma_transforms_compat = { version = "0.164.1", path = "../swc_ecma_transforms_compat" }
swc_ecma_transforms_testing = { version = "0.141.1", path = "../swc_ecma_transforms_testing" }

View File

@ -0,0 +1 @@
run-decorator-tests.js

@ -0,0 +1 @@
Subproject commit 8e9c0b0fb3d548f378420aabbd351087efb5d5e5

View File

@ -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()
}