mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 14:16:12 +03:00
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:
parent
0d1c3b91c9
commit
95472e4037
5
.gitmodules
vendored
5
.gitmodules
vendored
@ -7,4 +7,7 @@
|
||||
path = crates/swc_html_parser/tests/html5lib-tests
|
||||
url = https://github.com/html5lib/html5lib-tests.git
|
||||
shallow = true
|
||||
ignore = dirty
|
||||
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
|
||||
|
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@ -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",
|
||||
@ -35,4 +36,4 @@
|
||||
"rkyv-impl",
|
||||
"debug"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -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",
|
||||
|
@ -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" }
|
||||
|
1
crates/swc_ecma_transforms_proposal/tests/.gitignore
vendored
Normal file
1
crates/swc_ecma_transforms_proposal/tests/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
run-decorator-tests.js
|
@ -0,0 +1 @@
|
||||
Subproject commit 8e9c0b0fb3d548f378420aabbd351087efb5d5e5
|
@ -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()
|
||||
}
|
Loading…
Reference in New Issue
Block a user