fix(57386): Invalid use of 'eval' when defining a namespaced eval function (#57391)

This commit is contained in:
Oleksandr T 2024-03-02 01:14:27 +02:00 committed by GitHub
parent 5d17aa7eb9
commit 8ada4ef44f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 63 additions and 1 deletions

View File

@ -2563,7 +2563,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
}
function checkStrictModeFunctionName(node: FunctionLikeDeclaration) {
if (inStrictMode) {
if (inStrictMode && !(node.flags & NodeFlags.Ambient)) {
// It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a strict mode FunctionDeclaration or FunctionExpression (13.1))
checkStrictModeEvalOrArguments(node, node.name);
}

View File

@ -0,0 +1,25 @@
//// [tests/cases/compiler/evalOrArgumentsInDeclarationFunctions.ts] ////
=== /a.d.ts ===
declare global {
>global : Symbol(global, Decl(a.d.ts, 0, 0))
export namespace ns {
>ns : Symbol(ns, Decl(a.d.ts, 0, 16))
export function eval(): void;
>eval : Symbol(eval, Decl(a.d.ts, 1, 25))
export function arguments(): void;
>arguments : Symbol(arguments, Decl(a.d.ts, 2, 37))
}
}
declare function eval(): void;
>eval : Symbol(eval, Decl(a.d.ts, 5, 1))
declare function arguments(): void;
>arguments : Symbol(arguments, Decl(a.d.ts, 7, 30))
export {}

View File

@ -0,0 +1,25 @@
//// [tests/cases/compiler/evalOrArgumentsInDeclarationFunctions.ts] ////
=== /a.d.ts ===
declare global {
>global : typeof global
export namespace ns {
>ns : typeof ns
export function eval(): void;
>eval : () => void
export function arguments(): void;
>arguments : () => void
}
}
declare function eval(): void;
>eval : () => void
declare function arguments(): void;
>arguments : () => void
export {}

View File

@ -0,0 +1,12 @@
// @filename: /a.d.ts
declare global {
export namespace ns {
export function eval(): void;
export function arguments(): void;
}
}
declare function eval(): void;
declare function arguments(): void;
export {}