mirror of
https://github.com/swc-project/swc.git
synced 2024-11-28 02:29:04 +03:00
feat(es/parser): Disallow tagged tpl in optional chaining (#7515)
This commit is contained in:
parent
b46bcf3f50
commit
6c00a2422a
@ -195,6 +195,7 @@ pub enum SyntaxError {
|
|||||||
TsBindingPatCannotBeOptional,
|
TsBindingPatCannotBeOptional,
|
||||||
SuperCallOptional,
|
SuperCallOptional,
|
||||||
OptChainCannotFollowConstructorCall,
|
OptChainCannotFollowConstructorCall,
|
||||||
|
TaggedTplInOptChain,
|
||||||
|
|
||||||
TrailingCommaInsideImport,
|
TrailingCommaInsideImport,
|
||||||
|
|
||||||
@ -470,6 +471,9 @@ impl SyntaxError {
|
|||||||
SyntaxError::OptChainCannotFollowConstructorCall => {
|
SyntaxError::OptChainCannotFollowConstructorCall => {
|
||||||
"Constructor in/after an optional chaining is not allowed.".into()
|
"Constructor in/after an optional chaining is not allowed.".into()
|
||||||
}
|
}
|
||||||
|
SyntaxError::TaggedTplInOptChain => {
|
||||||
|
"Tagged template literal is not allowed in optional chain.".into()
|
||||||
|
}
|
||||||
SyntaxError::TsInvalidParamPropPat => {
|
SyntaxError::TsInvalidParamPropPat => {
|
||||||
"Typescript parameter property must be an identifier or assignment pattern".into()
|
"Typescript parameter property must be an identifier or assignment pattern".into()
|
||||||
}
|
}
|
||||||
|
@ -1060,6 +1060,11 @@ impl<I: Tokens> Parser<I> {
|
|||||||
let tpl = Box::new(self.parse_tpl(true)?);
|
let tpl = Box::new(self.parse_tpl(true)?);
|
||||||
|
|
||||||
let span = span!(self, tagged_tpl_start);
|
let span = span!(self, tagged_tpl_start);
|
||||||
|
|
||||||
|
if tag.is_opt_chain() {
|
||||||
|
self.emit_err(span, SyntaxError::TaggedTplInOptChain);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(TaggedTpl {
|
Ok(TaggedTpl {
|
||||||
span,
|
span,
|
||||||
tag,
|
tag,
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
a?.b``
|
@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
x Tagged template literal is not allowed in optional chain.
|
||||||
|
,-[$DIR/tests/errors/optional-chaining/tagged-template.js:1:1]
|
||||||
|
1 | a?.b``
|
||||||
|
: ^^^^^^
|
||||||
|
`----
|
Loading…
Reference in New Issue
Block a user