feat(es/parser): Reject 'use strict' with non-simple params list in TS (#4416)

This commit is contained in:
Pig Fang 2022-04-24 11:04:38 +08:00 committed by GitHub
parent 63efd0089b
commit 6dc64c9ca0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 2 deletions

View File

@ -1527,7 +1527,7 @@ impl<I: Tokens> FnBodyParser<BlockStmtOrExpr> for Parser<I> {
};
let result = self.with_ctx(ctx).parse_block(false);
result.map(|block_stmt| {
if !self.input.syntax().typescript() && !is_simple_parameter_list {
if !is_simple_parameter_list {
if let Some(span) = has_use_strict(&block_stmt) {
self.emit_err(span, SyntaxError::IllegalLanguageModeDirective);
}
@ -1558,7 +1558,7 @@ impl<I: Tokens> FnBodyParser<Option<BlockStmt>> for Parser<I> {
}
let block = self.include_in_expr(true).parse_block(true);
block.map(|block_stmt| {
if !self.input.syntax().typescript() && !is_simple_parameter_list {
if !is_simple_parameter_list {
if let Some(span) = has_use_strict(&block_stmt) {
self.emit_err(span, SyntaxError::IllegalLanguageModeDirective);
}

View File

@ -0,0 +1 @@
const f = ([x]: string) => { 'use strict' }

View File

@ -0,0 +1,6 @@
x Illegal 'use strict' directive in function with non-simple parameter list.
,-[$DIR/tests/typescript-errors/use-strict/arrow-fn-expr/input.ts:1:1]
1 | const f = ([x]: string) => { 'use strict' }
: ^^^^^^^^^^^^
`----

View File

@ -0,0 +1 @@
function f([x]: string) { 'use strict' }

View File

@ -0,0 +1,6 @@
x Illegal 'use strict' directive in function with non-simple parameter list.
,-[$DIR/tests/typescript-errors/use-strict/fn-block/input.ts:1:1]
1 | function f([x]: string) { 'use strict' }
: ^^^^^^^^^^^^
`----