@@ -20,7 +20,12 @@ pub trait Binder<'a> {
2020
2121impl < ' a > Binder < ' a > for VariableDeclarator < ' a > {
2222 fn bind ( & self , builder : & mut SemanticBuilder < ' a > ) {
23- let ( includes, excludes) = match self . kind {
23+ let is_declare = builder
24+ . nodes
25+ . parent_kind ( builder. current_node_id )
26+ . is_some_and ( |kind| matches ! ( kind, AstKind :: VariableDeclaration ( decl) if decl. declare) ) ;
27+
28+ let ( mut includes, excludes) = match self . kind {
2429 VariableDeclarationKind :: Const
2530 | VariableDeclarationKind :: Using
2631 | VariableDeclarationKind :: AwaitUsing => (
@@ -35,6 +40,10 @@ impl<'a> Binder<'a> for VariableDeclarator<'a> {
3540 }
3641 } ;
3742
43+ if is_declare {
44+ includes |= SymbolFlags :: Ambient ;
45+ }
46+
3847 if self . kind . is_lexical ( ) {
3948 self . id . bound_names ( & mut |ident| {
4049 let symbol_id = builder. declare_symbol ( ident. span , & ident. name , includes, excludes) ;
@@ -117,13 +126,14 @@ impl<'a> Binder<'a> for VariableDeclarator<'a> {
117126
118127impl < ' a > Binder < ' a > for Class < ' a > {
119128 fn bind ( & self , builder : & mut SemanticBuilder ) {
129+ let includes = if self . declare {
130+ SymbolFlags :: Class | SymbolFlags :: Ambient
131+ } else {
132+ SymbolFlags :: Class
133+ } ;
120134 let Some ( ident) = & self . id else { return } ;
121- let symbol_id = builder. declare_symbol (
122- ident. span ,
123- & ident. name ,
124- SymbolFlags :: Class ,
125- SymbolFlags :: ClassExcludes ,
126- ) ;
135+ let symbol_id =
136+ builder. declare_symbol ( ident. span , & ident. name , includes, SymbolFlags :: ClassExcludes ) ;
127137 ident. symbol_id . set ( Some ( symbol_id) ) ;
128138 }
129139}
@@ -152,30 +162,32 @@ fn is_function_part_of_if_statement(function: &Function, builder: &SemanticBuild
152162
153163impl < ' a > Binder < ' a > for Function < ' a > {
154164 fn bind ( & self , builder : & mut SemanticBuilder ) {
165+ let includes = if self . declare {
166+ SymbolFlags :: Function | SymbolFlags :: Ambient
167+ } else {
168+ SymbolFlags :: Function
169+ } ;
170+
155171 if let Some ( ident) = & self . id {
156172 if is_function_part_of_if_statement ( self , builder) {
157173 let symbol_id = builder. scoping . create_symbol (
158174 ident. span ,
159175 ident. name . into ( ) ,
160- SymbolFlags :: Function ,
176+ includes ,
161177 ScopeId :: new ( u32:: MAX - 1 ) , // Not bound to any scope.
162178 builder. current_node_id ,
163179 ) ;
164180 ident. symbol_id . set ( Some ( symbol_id) ) ;
165181 } else {
166- let symbol_id = builder. declare_symbol (
167- ident. span ,
168- & ident. name ,
169- SymbolFlags :: Function ,
170- if builder. source_type . is_typescript ( ) {
171- SymbolFlags :: FunctionExcludes
172- } else {
173- // `var x; function x() {}` is valid in non-strict mode, but `TypeScript`
174- // doesn't care about non-strict mode, so we need to exclude this,
175- // and further check in checker.
176- SymbolFlags :: FunctionExcludes - SymbolFlags :: FunctionScopedVariable
177- } ,
178- ) ;
182+ let excludes = if builder. source_type . is_typescript ( ) {
183+ SymbolFlags :: FunctionExcludes
184+ } else {
185+ // `var x; function x() {}` is valid in non-strict mode, but `TypeScript`
186+ // doesn't care about non-strict mode, so we need to exclude this,
187+ // and further check in checker.
188+ SymbolFlags :: FunctionExcludes - SymbolFlags :: FunctionScopedVariable
189+ } ;
190+ let symbol_id = builder. declare_symbol ( ident. span , & ident. name , includes, excludes) ;
179191 ident. symbol_id . set ( Some ( symbol_id) ) ;
180192 }
181193 }
@@ -336,10 +348,15 @@ impl<'a> Binder<'a> for TSImportEqualsDeclaration<'a> {
336348
337349impl < ' a > Binder < ' a > for TSTypeAliasDeclaration < ' a > {
338350 fn bind ( & self , builder : & mut SemanticBuilder ) {
351+ let includes = if self . declare {
352+ SymbolFlags :: TypeAlias | SymbolFlags :: Ambient
353+ } else {
354+ SymbolFlags :: TypeAlias
355+ } ;
339356 let symbol_id = builder. declare_symbol (
340357 self . id . span ,
341358 & self . id . name ,
342- SymbolFlags :: TypeAlias ,
359+ includes ,
343360 SymbolFlags :: TypeAliasExcludes ,
344361 ) ;
345362 self . id . symbol_id . set ( Some ( symbol_id) ) ;
@@ -348,10 +365,15 @@ impl<'a> Binder<'a> for TSTypeAliasDeclaration<'a> {
348365
349366impl < ' a > Binder < ' a > for TSInterfaceDeclaration < ' a > {
350367 fn bind ( & self , builder : & mut SemanticBuilder ) {
368+ let includes = if self . declare {
369+ SymbolFlags :: Interface | SymbolFlags :: Ambient
370+ } else {
371+ SymbolFlags :: Interface
372+ } ;
351373 let symbol_id = builder. declare_symbol (
352374 self . id . span ,
353375 & self . id . name ,
354- SymbolFlags :: Interface ,
376+ includes ,
355377 SymbolFlags :: InterfaceExcludes ,
356378 ) ;
357379 self . id . symbol_id . set ( Some ( symbol_id) ) ;
@@ -361,11 +383,11 @@ impl<'a> Binder<'a> for TSInterfaceDeclaration<'a> {
361383impl < ' a > Binder < ' a > for TSEnumDeclaration < ' a > {
362384 fn bind ( & self , builder : & mut SemanticBuilder ) {
363385 let is_const = self . r#const ;
364- let includes = if is_const { SymbolFlags :: ConstEnum } else { SymbolFlags :: RegularEnum } ;
365- let excludes = if is_const {
366- SymbolFlags :: ConstEnumExcludes
386+ let includes = if self . declare { SymbolFlags :: Ambient } else { SymbolFlags :: empty ( ) } ;
387+ let ( includes , excludes) = if is_const {
388+ ( SymbolFlags :: ConstEnum | includes , SymbolFlags :: ConstEnumExcludes )
367389 } else {
368- SymbolFlags :: RegularEnumExcludes
390+ ( SymbolFlags :: RegularEnum | includes , SymbolFlags :: RegularEnumExcludes )
369391 } ;
370392 let symbol_id = builder. declare_symbol ( self . id . span , & self . id . name , includes, excludes) ;
371393 self . id . symbol_id . set ( Some ( symbol_id) ) ;
@@ -392,16 +414,16 @@ impl<'a> Binder<'a> for TSModuleDeclaration<'a> {
392414 let TSModuleDeclarationName :: Identifier ( id) = & self . id else { return } ;
393415 let instantiated =
394416 get_module_instance_state ( builder, self , builder. current_node_id ) . is_instantiated ( ) ;
395- let ( includes, excludes) = if instantiated {
417+ let ( mut includes, excludes) = if instantiated {
396418 ( SymbolFlags :: ValueModule , SymbolFlags :: ValueModuleExcludes )
397419 } else {
398420 ( SymbolFlags :: NameSpaceModule , SymbolFlags :: NamespaceModuleExcludes )
399421 } ;
400422
401- // At declaration time a module has no value declaration it is only when a value declaration
402- // is made inside a the scope of a module that the symbol is modified
403- let ambient = if self . declare { SymbolFlags :: Ambient } else { SymbolFlags :: None } ;
404- let symbol_id = builder. declare_symbol ( id. span , & id. name , includes | ambient , excludes) ;
423+ if self . declare {
424+ includes |= SymbolFlags :: Ambient ;
425+ }
426+ let symbol_id = builder. declare_symbol ( id. span , & id. name , includes, excludes) ;
405427
406428 id. set_symbol_id ( symbol_id) ;
407429 }
0 commit comments