|
|
@ -1,6 +1,9 @@ |
|
|
|
use crate::syntax::{ |
|
|
|
use crate::syntax::{ |
|
|
|
ast::{ |
|
|
|
ast::{ |
|
|
|
node::{Block, Catch, Declaration, DeclarationList, Finally, Identifier, Try}, |
|
|
|
node::{ |
|
|
|
|
|
|
|
declaration::{BindingPatternTypeArray, BindingPatternTypeObject}, |
|
|
|
|
|
|
|
Block, Catch, Declaration, DeclarationList, Finally, Try, |
|
|
|
|
|
|
|
}, |
|
|
|
Const, |
|
|
|
Const, |
|
|
|
}, |
|
|
|
}, |
|
|
|
parser::tests::{check_invalid, check_parser}, |
|
|
|
parser::tests::{check_invalid, check_parser}, |
|
|
@ -10,7 +13,15 @@ use crate::syntax::{ |
|
|
|
fn check_inline_with_empty_try_catch() { |
|
|
|
fn check_inline_with_empty_try_catch() { |
|
|
|
check_parser( |
|
|
|
check_parser( |
|
|
|
"try { } catch(e) {}", |
|
|
|
"try { } catch(e) {}", |
|
|
|
vec![Try::new(vec![], Some(Catch::new("e", vec![])), None).into()], |
|
|
|
vec![Try::new( |
|
|
|
|
|
|
|
vec![], |
|
|
|
|
|
|
|
Some(Catch::new( |
|
|
|
|
|
|
|
Declaration::new_with_identifier("e", None), |
|
|
|
|
|
|
|
vec![], |
|
|
|
|
|
|
|
)), |
|
|
|
|
|
|
|
None, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.into()], |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -27,7 +38,10 @@ fn check_inline_with_var_decl_inside_try() { |
|
|
|
.into(), |
|
|
|
.into(), |
|
|
|
) |
|
|
|
) |
|
|
|
.into()], |
|
|
|
.into()], |
|
|
|
Some(Catch::new("e", vec![])), |
|
|
|
Some(Catch::new( |
|
|
|
|
|
|
|
Declaration::new_with_identifier("e", None), |
|
|
|
|
|
|
|
vec![], |
|
|
|
|
|
|
|
)), |
|
|
|
None, |
|
|
|
None, |
|
|
|
) |
|
|
|
) |
|
|
|
.into()], |
|
|
|
.into()], |
|
|
@ -48,7 +62,7 @@ fn check_inline_with_var_decl_inside_catch() { |
|
|
|
) |
|
|
|
) |
|
|
|
.into()], |
|
|
|
.into()], |
|
|
|
Some(Catch::new( |
|
|
|
Some(Catch::new( |
|
|
|
"e", |
|
|
|
Declaration::new_with_identifier("e", None), |
|
|
|
vec![DeclarationList::Var( |
|
|
|
vec![DeclarationList::Var( |
|
|
|
vec![Declaration::new_with_identifier( |
|
|
|
vec![Declaration::new_with_identifier( |
|
|
|
"x", |
|
|
|
"x", |
|
|
@ -70,7 +84,10 @@ fn check_inline_with_empty_try_catch_finally() { |
|
|
|
"try {} catch(e) {} finally {}", |
|
|
|
"try {} catch(e) {} finally {}", |
|
|
|
vec![Try::new( |
|
|
|
vec![Try::new( |
|
|
|
vec![], |
|
|
|
vec![], |
|
|
|
Some(Catch::new("e", vec![])), |
|
|
|
Some(Catch::new( |
|
|
|
|
|
|
|
Declaration::new_with_identifier("e", None), |
|
|
|
|
|
|
|
vec![], |
|
|
|
|
|
|
|
)), |
|
|
|
Some(Finally::from(vec![])), |
|
|
|
Some(Finally::from(vec![])), |
|
|
|
) |
|
|
|
) |
|
|
|
.into()], |
|
|
|
.into()], |
|
|
@ -111,7 +128,7 @@ fn check_inline_empty_try_paramless_catch() { |
|
|
|
"try {} catch { var x = 1; }", |
|
|
|
"try {} catch { var x = 1; }", |
|
|
|
vec![Try::new( |
|
|
|
vec![Try::new( |
|
|
|
Block::from(vec![]), |
|
|
|
Block::from(vec![]), |
|
|
|
Some(Catch::new::<_, Identifier, _>( |
|
|
|
Some(Catch::new::<_, Declaration, _>( |
|
|
|
None, |
|
|
|
None, |
|
|
|
vec![DeclarationList::Var( |
|
|
|
vec![DeclarationList::Var( |
|
|
|
vec![Declaration::new_with_identifier( |
|
|
|
vec![Declaration::new_with_identifier( |
|
|
@ -128,6 +145,64 @@ fn check_inline_empty_try_paramless_catch() { |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn check_inline_with_binding_pattern_object() { |
|
|
|
|
|
|
|
check_parser( |
|
|
|
|
|
|
|
"try {} catch ({ a, b: c }) {}", |
|
|
|
|
|
|
|
vec![Try::new( |
|
|
|
|
|
|
|
Block::from(vec![]), |
|
|
|
|
|
|
|
Some(Catch::new::<_, Declaration, _>( |
|
|
|
|
|
|
|
Some(Declaration::new_with_object_pattern( |
|
|
|
|
|
|
|
vec![ |
|
|
|
|
|
|
|
BindingPatternTypeObject::SingleName { |
|
|
|
|
|
|
|
ident: "a".into(), |
|
|
|
|
|
|
|
property_name: "a".into(), |
|
|
|
|
|
|
|
default_init: None, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
BindingPatternTypeObject::SingleName { |
|
|
|
|
|
|
|
ident: "c".into(), |
|
|
|
|
|
|
|
property_name: "b".into(), |
|
|
|
|
|
|
|
default_init: None, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
None, |
|
|
|
|
|
|
|
)), |
|
|
|
|
|
|
|
vec![], |
|
|
|
|
|
|
|
)), |
|
|
|
|
|
|
|
None, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.into()], |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn check_inline_with_binding_pattern_array() { |
|
|
|
|
|
|
|
check_parser( |
|
|
|
|
|
|
|
"try {} catch ([a, b]) {}", |
|
|
|
|
|
|
|
vec![Try::new( |
|
|
|
|
|
|
|
Block::from(vec![]), |
|
|
|
|
|
|
|
Some(Catch::new::<_, Declaration, _>( |
|
|
|
|
|
|
|
Some(Declaration::new_with_array_pattern( |
|
|
|
|
|
|
|
vec![ |
|
|
|
|
|
|
|
BindingPatternTypeArray::SingleName { |
|
|
|
|
|
|
|
ident: "a".into(), |
|
|
|
|
|
|
|
default_init: None, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
BindingPatternTypeArray::SingleName { |
|
|
|
|
|
|
|
ident: "b".into(), |
|
|
|
|
|
|
|
default_init: None, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
None, |
|
|
|
|
|
|
|
)), |
|
|
|
|
|
|
|
vec![], |
|
|
|
|
|
|
|
)), |
|
|
|
|
|
|
|
None, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.into()], |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn check_inline_invalid_catch() { |
|
|
|
fn check_inline_invalid_catch() { |
|
|
|
check_invalid("try {} catch"); |
|
|
|
check_invalid("try {} catch"); |
|
|
@ -144,6 +219,26 @@ fn check_inline_invalid_catch_parameter() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn check_invalide_try_no_catch_finally() { |
|
|
|
fn check_invalid_try_no_catch_finally() { |
|
|
|
check_invalid("try {} let a = 10;"); |
|
|
|
check_invalid("try {} let a = 10;"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn check_invalid_catch_with_empty_paren() { |
|
|
|
|
|
|
|
check_invalid("try {} catch() {}"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn check_invalid_catch_with_duplicate_params() { |
|
|
|
|
|
|
|
check_invalid("try {} catch({ a, b: a }) {}"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn check_invalid_catch_with_lexical_redeclaration() { |
|
|
|
|
|
|
|
check_invalid("try {} catch(e) { let e = 'oh' }"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn check_invalid_catch_with_var_redeclaration() { |
|
|
|
|
|
|
|
check_invalid("try {} catch(e) { var e = 'oh' }"); |
|
|
|
|
|
|
|
} |
|
|
|