Skip to content

Commit

Permalink
fix(57386): Invalid use of 'eval' when defining a namespaced eval fun…
Browse files Browse the repository at this point in the history
…ction (microsoft#57391)
  • Loading branch information
a-tarasyuk authored Mar 1, 2024
1 parent 5d17aa7 commit 8ada4ef
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {}

Original file line number Diff line number Diff line change
@@ -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 {}

12 changes: 12 additions & 0 deletions tests/cases/compiler/evalOrArgumentsInDeclarationFunctions.ts
Original file line number Diff line number Diff line change
@@ -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 {}

0 comments on commit 8ada4ef

Please sign in to comment.