feat: support filter exec snap (#1084)

Co-authored-by: Boshen <boshenc@gmail.com>
This commit is contained in:
Wenzhe Wang 2023-10-29 13:39:32 +08:00 committed by GitHub
parent 1704a76f6f
commit 094dfa5604
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 11 deletions

View file

@ -2128,7 +2128,26 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for Vec<'a, Decorator<'a>> {
impl<'a, const MINIFY: bool> Gen<MINIFY> for Decorator<'a> {
fn gen(&self, p: &mut Codegen<{ MINIFY }>, _ctx: Context) {
fn need_wrap(expr: &Expression) -> bool {
match expr {
// "@foo"
Expression::Identifier(_) => false,
Expression::MemberExpression(member_expr) => {
// "@foo.bar"
// "@(foo['bar'])"
matches!(&**member_expr, MemberExpression::ComputedMemberExpression(_))
}
Expression::CallExpression(call_expr) => need_wrap(&call_expr.callee),
// "@(foo + bar)"
// "@(() => {})"
_ => true,
}
}
p.print(b'@');
self.expression.gen_expr(p, Precedence::Assign, Context::default());
let wrap = need_wrap(&self.expression);
p.wrap(wrap, |p| {
self.expression.gen_expr(p, Precedence::Assign, Context::default());
});
}
}

View file

@ -1,6 +1,6 @@
codegen_typescript Summary:
AST Parsed : 5063/5063 (100.00%)
Positive Passed: 5041/5063 (99.57%)
Positive Passed: 5043/5063 (99.60%)
Expect to Parse: "compiler/binopAssignmentShouldHaveType.ts"
Expect to Parse: "compiler/castExpressionParentheses.ts"
Expect to Parse: "compiler/elidedEmbeddedStatementsReplacedWithSemicolon.ts"
@ -13,8 +13,6 @@ Expect to Parse: "compiler/localClassesInLoop_ES6.ts"
Expect to Parse: "compiler/typeAliasDeclarationEmit3.ts"
Expect to Parse: "conformance/constEnums/constEnum4.ts"
Expect to Parse: "conformance/decorators/legacyDecorators-contextualTypes.ts"
Expect to Parse: "conformance/es6/yieldExpressions/generatorTypeCheck59.ts"
Expect to Parse: "conformance/es6/yieldExpressions/generatorTypeCheck61.ts"
Expect to Parse: "conformance/esDecorators/esDecorators-contextualTypes.ts"
Expect to Parse: "conformance/expressions/asOperator/asOpEmitParens.ts"
Expect to Parse: "conformance/expressions/elementAccess/letIdentifierInElementAccess01.ts"

View file

@ -220,7 +220,7 @@ impl TestRunnerEnv {
)
}
fn run_test(path: &Path) -> bool {
fn get_test_result(path: &Path) -> String {
let output = Command::new("bun")
.current_dir(path.parent().unwrap())
.args(["test", path.file_name().unwrap().to_string_lossy().as_ref()])
@ -228,8 +228,10 @@ impl TestRunnerEnv {
.expect("Try install bun: https://bun.sh/docs/installation");
let content = if output.stderr.is_empty() { &output.stdout } else { &output.stderr };
let content = String::from_utf8_lossy(content);
String::from_utf8_lossy(content).to_string()
}
content.contains("1 pass")
fn run_test(path: &Path) -> bool {
Self::get_test_result(path).contains("1 pass")
}
}

View file

@ -29,8 +29,7 @@ impl TestCaseKind {
pub fn test(&self, filter: Option<&str>) -> bool {
match self {
Self::Transform(test_case) => test_case.test(filter),
// not support filter yet.
Self::Exec(test_case) => test_case.test(None),
Self::Exec(test_case) => test_case.test(filter),
}
}
@ -267,9 +266,20 @@ impl TestCase for ExecTestCase {
Self { path, options }
}
fn test(&self, _filter: Option<&str>) -> bool {
fn test(&self, filter: Option<&str>) -> bool {
let filtered = filter.is_some_and(|f| self.path.to_string_lossy().as_ref().contains(f));
let result = self.transform(&self.path);
let target_path = self.write_to_test_files(&result);
Self::run_test(&target_path)
let passed = Self::run_test(&target_path);
if filtered {
println!("input_path: {:?}", &self.path);
println!("target_path: {:?}", &target_path);
println!("Input:\n{}\n", fs::read_to_string(&self.path).unwrap());
println!("Transformed:\n{result}\n");
println!("Test Result:\n{}\n", TestRunnerEnv::get_test_result(&target_path));
}
passed
}
}