-
-
Notifications
You must be signed in to change notification settings - Fork 480
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(ecmascript): move tests to
oxc_minifier
due to cyclic dependen…
…cy with `oxc_parser` (#7542)
- Loading branch information
Showing
9 changed files
with
88 additions
and
100 deletions.
There are no files selected for viewing
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,5 @@ | ||
# `oxc_ecmascript` | ||
|
||
ECMAScript Operations defined in the spec https://tc39.es/ecma262/ | ||
|
||
Tests reside in `crates/oxc_minifier/tests/ecmascript` due to cyclic dependency with `oxc_parser`. |
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
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,41 @@ | ||
use oxc_allocator::{Allocator, CloneIn}; | ||
use oxc_ast::{ast::*, AstBuilder}; | ||
use oxc_ecmascript::ArrayJoin; | ||
use oxc_span::SPAN; | ||
|
||
#[test] | ||
fn test() { | ||
let allocator = Allocator::default(); | ||
let ast = AstBuilder::new(&allocator); | ||
let mut elements = ast.vec(); | ||
elements.push(ast.array_expression_element_elision(SPAN)); | ||
elements.push(ArrayExpressionElement::NullLiteral(ast.alloc(ast.null_literal(SPAN)))); | ||
elements.push(ArrayExpressionElement::NumericLiteral(ast.alloc(ast.numeric_literal( | ||
SPAN, | ||
42f64, | ||
"42", | ||
NumberBase::Decimal, | ||
)))); | ||
elements.push(ArrayExpressionElement::StringLiteral( | ||
ast.alloc(ast.string_literal(SPAN, "foo", None)), | ||
)); | ||
elements | ||
.push(ArrayExpressionElement::BooleanLiteral(ast.alloc(ast.boolean_literal(SPAN, true)))); | ||
elements.push(ArrayExpressionElement::BigIntLiteral(ast.alloc(ast.big_int_literal( | ||
SPAN, | ||
"42n", | ||
BigintBase::Decimal, | ||
)))); | ||
let array = ast.array_expression(SPAN, elements.clone_in(&allocator), None); | ||
let mut array2 = array.clone_in(&allocator); | ||
array2.elements.push(ArrayExpressionElement::ArrayExpression(ast.alloc(array))); | ||
array2.elements.push(ArrayExpressionElement::ObjectExpression( | ||
ast.alloc(ast.object_expression(SPAN, ast.vec(), None)), | ||
)); | ||
let joined = array2.array_join(Some("_")); | ||
assert_eq!(joined, Some("__42_foo_true_42n_,,42,foo,true,42n_[object Object]".to_string())); | ||
|
||
let joined2 = array2.array_join(None); | ||
// By default, in `Array.prototype.toString`, the separator is a comma. However, in `Array.prototype.join`, the separator is none if not given. | ||
assert_eq!(joined2, Some(",,42,foo,true,42n,,,42,foo,true,42n,[object Object]".to_string())); | ||
} |
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,2 @@ | ||
mod array_join; | ||
mod prop_name; |
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,39 @@ | ||
use oxc_allocator::Allocator; | ||
use oxc_ast::{ast::ObjectExpression, Visit}; | ||
use oxc_ecmascript::PropName; | ||
use oxc_parser::Parser; | ||
use oxc_span::SourceType; | ||
|
||
#[test] | ||
fn test_prop_name() { | ||
#[derive(Debug, Default)] | ||
struct TestVisitor; | ||
|
||
impl<'a> Visit<'a> for TestVisitor { | ||
fn visit_object_expression(&mut self, obj_expr: &ObjectExpression<'a>) { | ||
assert_eq!("a", obj_expr.properties[0].prop_name().unwrap().0); | ||
assert_eq!("b", obj_expr.properties[1].prop_name().unwrap().0); | ||
assert_eq!("c", obj_expr.properties[2].prop_name().unwrap().0); | ||
assert_eq!("d", obj_expr.properties[3].prop_name().unwrap().0); | ||
assert_eq!(None, obj_expr.properties[4].prop_name()); | ||
} | ||
} | ||
|
||
let allocator = Allocator::default(); | ||
let source_type = SourceType::default(); | ||
let source = r" | ||
const obj = { | ||
a() {}, | ||
get b() {}, | ||
set c(_) {}, | ||
d: 1, | ||
[e]() {}, | ||
} | ||
"; | ||
let ret = Parser::new(&allocator, source, source_type).parse(); | ||
assert!(!ret.program.is_empty()); | ||
assert!(ret.errors.is_empty()); | ||
|
||
let mut visitor = TestVisitor; | ||
visitor.visit_program(&ret.program); | ||
} |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
mod ast_passes; | ||
mod ecmascript; | ||
mod mangler; | ||
|
||
use oxc_allocator::Allocator; | ||
|