mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
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:
parent
93897c530c
commit
d3eb1c3318
2 changed files with 13 additions and 1 deletions
|
|
@ -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));
|
||||||
|
|
|
||||||
|
|
@ -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; }")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue