Skip to content

Commit 8ada4ef

Browse files
authored
fix(57386): Invalid use of 'eval' when defining a namespaced eval function (microsoft#57391)
1 parent 5d17aa7 commit 8ada4ef

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

src/compiler/binder.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2563,7 +2563,7 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
25632563
}
25642564

25652565
function checkStrictModeFunctionName(node: FunctionLikeDeclaration) {
2566-
if (inStrictMode) {
2566+
if (inStrictMode && !(node.flags & NodeFlags.Ambient)) {
25672567
// It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a strict mode FunctionDeclaration or FunctionExpression (13.1))
25682568
checkStrictModeEvalOrArguments(node, node.name);
25692569
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//// [tests/cases/compiler/evalOrArgumentsInDeclarationFunctions.ts] ////
2+
3+
=== /a.d.ts ===
4+
declare global {
5+
>global : Symbol(global, Decl(a.d.ts, 0, 0))
6+
7+
export namespace ns {
8+
>ns : Symbol(ns, Decl(a.d.ts, 0, 16))
9+
10+
export function eval(): void;
11+
>eval : Symbol(eval, Decl(a.d.ts, 1, 25))
12+
13+
export function arguments(): void;
14+
>arguments : Symbol(arguments, Decl(a.d.ts, 2, 37))
15+
}
16+
}
17+
18+
declare function eval(): void;
19+
>eval : Symbol(eval, Decl(a.d.ts, 5, 1))
20+
21+
declare function arguments(): void;
22+
>arguments : Symbol(arguments, Decl(a.d.ts, 7, 30))
23+
24+
export {}
25+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//// [tests/cases/compiler/evalOrArgumentsInDeclarationFunctions.ts] ////
2+
3+
=== /a.d.ts ===
4+
declare global {
5+
>global : typeof global
6+
7+
export namespace ns {
8+
>ns : typeof ns
9+
10+
export function eval(): void;
11+
>eval : () => void
12+
13+
export function arguments(): void;
14+
>arguments : () => void
15+
}
16+
}
17+
18+
declare function eval(): void;
19+
>eval : () => void
20+
21+
declare function arguments(): void;
22+
>arguments : () => void
23+
24+
export {}
25+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// @filename: /a.d.ts
2+
declare global {
3+
export namespace ns {
4+
export function eval(): void;
5+
export function arguments(): void;
6+
}
7+
}
8+
9+
declare function eval(): void;
10+
declare function arguments(): void;
11+
12+
export {}

0 commit comments

Comments
 (0)