feat(es/parser): Disallow tagged tpl in optional chaining (#7515)

This commit is contained in:
Pig Fang 2023-06-12 09:37:39 +08:00 committed by GitHub
parent b46bcf3f50
commit 6c00a2422a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 0 deletions

View File

@ -195,6 +195,7 @@ pub enum SyntaxError {
TsBindingPatCannotBeOptional,
SuperCallOptional,
OptChainCannotFollowConstructorCall,
TaggedTplInOptChain,
TrailingCommaInsideImport,
@ -470,6 +471,9 @@ impl SyntaxError {
SyntaxError::OptChainCannotFollowConstructorCall => {
"Constructor in/after an optional chaining is not allowed.".into()
}
SyntaxError::TaggedTplInOptChain => {
"Tagged template literal is not allowed in optional chain.".into()
}
SyntaxError::TsInvalidParamPropPat => {
"Typescript parameter property must be an identifier or assignment pattern".into()
}

View File

@ -1060,6 +1060,11 @@ impl<I: Tokens> Parser<I> {
let tpl = Box::new(self.parse_tpl(true)?);
let span = span!(self, tagged_tpl_start);
if tag.is_opt_chain() {
self.emit_err(span, SyntaxError::TaggedTplInOptChain);
}
Ok(TaggedTpl {
span,
tag,

View File

@ -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``
: ^^^^^^
`----