Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions crates/oxc_semantic/src/checker/javascript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ fn is_current_node_ambient_binding(symbol_id: Option<SymbolId>, ctx: &SemanticBu
}

pub fn check_binding_identifier(ident: &BindingIdentifier, ctx: &SemanticBuilder<'_>) {
// `.d.ts` files are allowed to use `eval` and `arguments` as binding identifiers
if ctx.source_type.is_typescript_definition() {
return;
}

if ctx.strict_mode() {
// In strict mode, `eval` and `arguments` are banned as identifiers.
if matches!(ident.name.as_str(), "eval" | "arguments") {
Expand All @@ -184,24 +189,11 @@ pub fn check_binding_identifier(ident: &BindingIdentifier, ctx: &SemanticBuilder
AstKind::Function(func) => matches!(func.r#type, FunctionType::TSDeclareFunction),
AstKind::FormalParameter(_) | AstKind::FormalParameterRest(_) => {
is_declare_function(&ctx.nodes.parent_kind(parent.id()))
|| ctx.nodes.ancestor_kinds(parent.id()).nth(1).is_some_and(|node| {
matches!(
node,
AstKind::TSFunctionType(_) | AstKind::TSMethodSignature(_)
)
})
}
AstKind::BindingRestElement(_) => {
let grand_parent = ctx.nodes.parent_node(parent.id());
is_declare_function(&ctx.nodes.parent_kind(grand_parent.id()))
|| ctx.nodes.ancestor_kinds(grand_parent.id()).nth(1).is_some_and(|node| {
matches!(
node,
AstKind::TSFunctionType(_) | AstKind::TSMethodSignature(_)
)
})
}
AstKind::TSTypeAliasDeclaration(_) | AstKind::TSInterfaceDeclaration(_) => true,
_ => false,
};

Expand Down Expand Up @@ -233,6 +225,11 @@ pub fn check_binding_identifier(ident: &BindingIdentifier, ctx: &SemanticBuilder
}

pub fn check_identifier_reference(ident: &IdentifierReference, ctx: &SemanticBuilder<'_>) {
// `.d.ts` files are allowed to use `eval` and `arguments` as identifier references
if ctx.source_type.is_typescript_definition() {
return;
}

// Static Semantics: AssignmentTargetType
// 1. If this IdentifierReference is contained in strict mode code and StringValue of Identifier is "eval" or "arguments", return invalid.
if ctx.strict_mode() && matches!(ident.name.as_str(), "arguments" | "eval") {
Expand Down
5 changes: 5 additions & 0 deletions tasks/coverage/misc/pass/arguments-eval.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ declare namespace foo2 {
interface arguments {}
interface eval {}
}

declare global {
function arguments(...arguments: any[]): typeof arguments;
function eval(...eval: any[]): typeof eval;
}
Loading