fix(semantic): flag function expressions with SymbolFlags::Function (#2891)

# What This PR Does

Consider the following code snippet

```js
const x = function y () {{
```

`y` will now be flagged with `SymbolFlags::Function`. This follow's
tsc's behavior.

- [Example in OXC
Playground](https://oxc-project.github.io/oxc/playground/?code=3YCAAICagICAgICAgICxG0qZRraXZOpcCHVsSRwDq2kRR0HprsTfRRT5WMw%2Ff2epoIA%3D)
- [Example in TypeScript AST
Viewer](https://ts-ast-viewer.com/#code/MYewdgzgLgBAHjAvDAZgVzMKBLcMCeAFAJQwDeAvgFBA)
This commit is contained in:
Don Isaac 2024-04-02 22:42:11 -04:00 committed by GitHub
parent 93897c530c
commit d3eb1c3318
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 1 deletions

View file

@ -146,7 +146,7 @@ impl<'a> Binder for Function<'a> {
let symbol_id = builder.declare_symbol( let symbol_id = builder.declare_symbol(
ident.span, ident.span,
&ident.name, &ident.name,
SymbolFlags::empty(), SymbolFlags::Function,
SymbolFlags::empty(), SymbolFlags::empty(),
); );
ident.symbol_id.set(Some(symbol_id)); ident.symbol_id.set(Some(symbol_id));

View file

@ -26,6 +26,18 @@ fn test_function_simple() {
.test(); .test();
} }
#[test]
fn test_function_expressions() {
SemanticTester::js("const x = function y() {}")
.has_some_symbol("y")
.contains_flags(SymbolFlags::Function)
.test();
SemanticTester::js("const x = () => {}")
.has_some_symbol("x")
.contains_flags(SymbolFlags::BlockScopedVariable | SymbolFlags::ConstVariable)
.test();
}
#[test] #[test]
fn test_var_simple() { fn test_var_simple() {
SemanticTester::js("let x; { let y; }") SemanticTester::js("let x; { let y; }")