@@ -13,7 +13,7 @@ use oxc_syntax::{
1313 number:: NumberBase ,
1414 operator:: { AssignmentOperator , UnaryOperator } ,
1515 scope:: { ScopeFlags , ScopeId } ,
16- symbol:: SymbolFlags ,
16+ symbol:: { SymbolFlags , SymbolId } ,
1717} ;
1818
1919use crate :: { IsGlobalReference , builder:: SemanticBuilder , diagnostics:: redeclaration} ;
@@ -98,9 +98,15 @@ pub const STRICT_MODE_NAMES: Set<&'static str> = phf_set! {
9898 "yield" ,
9999} ;
100100
101- pub fn check_identifier ( name : & str , span : Span , ctx : & SemanticBuilder < ' _ > ) {
102- // ts module block allows revered keywords
103- if ctx. current_scope_flags ( ) . is_ts_module_block ( ) {
101+ pub fn check_identifier (
102+ name : & str ,
103+ span : Span ,
104+ symbol_id : Option < SymbolId > ,
105+ ctx : & SemanticBuilder < ' _ > ,
106+ ) {
107+ // reserved keywords are allowed in ambient contexts
108+ if ctx. source_type . is_typescript_definition ( ) || is_current_node_ambient_binding ( symbol_id, ctx)
109+ {
104110 return ;
105111 }
106112 if name == "await" {
@@ -120,6 +126,24 @@ pub fn check_identifier(name: &str, span: Span, ctx: &SemanticBuilder<'_>) {
120126 }
121127}
122128
129+ fn is_current_node_ambient_binding ( symbol_id : Option < SymbolId > , ctx : & SemanticBuilder < ' _ > ) -> bool {
130+ if ctx. current_scope_flags ( ) . is_ts_module_block ( ) {
131+ return true ;
132+ }
133+
134+ if let Some ( symbol_id) = symbol_id
135+ && ctx. scoping . symbol_flags ( symbol_id) . contains ( SymbolFlags :: Ambient )
136+ {
137+ true
138+ } else if let AstKind :: BindingIdentifier ( id) = ctx. nodes . kind ( ctx. current_node_id )
139+ && let Some ( symbol_id) = id. symbol_id . get ( )
140+ {
141+ ctx. scoping . symbol_flags ( symbol_id) . contains ( SymbolFlags :: Ambient )
142+ } else {
143+ false
144+ }
145+ }
146+
123147fn unexpected_identifier_assign ( x0 : & str , span1 : Span ) -> OxcDiagnostic {
124148 OxcDiagnostic :: error ( format ! ( "Cannot assign to '{x0}' in strict mode" ) ) . with_label ( span1)
125149}
0 commit comments