From c96b712f6bcaf58a10525ddabfb9e207229c1444 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Wed, 18 Sep 2024 14:03:03 +0000 Subject: [PATCH] refactor(syntax)!: remove `SymbolFlags::ArrowFunction` (#5857) `SymbolFlags::ArrowFunction` is an oddity, as whether a symbol is an arrow function is not statically knowable. In the following cases, `f` symbol did not have `ArrowFunction` flag set: ```js const {f} = {f: () => {}}; ``` ```js let f = 123; f = () => {}; ``` `SymbolFlags::ArrowFunction` is therefore not particularly useful, and possibly misleading. Having it complicates the transformer, and it's not used anywhere in Oxc. This PR removes it. --- crates/oxc_semantic/src/binder.rs | 8 +--- .../tests/fixtures/oxc/jsx/element-name.snap | 2 +- .../call-expression/call-expression.snap | 2 +- .../readable-ref-body-shadow.snap | 2 +- .../default-params/readable-ref-const.snap | 2 +- .../default-params/readable-ref-let.snap | 2 +- .../readable-ref-nested-body-shadow.snap | 2 +- .../default-params/readable-ref-nested.snap | 2 +- .../readable-ref-param-shadow.snap | 2 +- .../default-params/readable-ref-partial.snap | 2 +- .../arrow/default-params/writable-ref.snap | 2 +- .../functions/arrow/scope.snap | 2 +- .../arrow/type-parameters/body-reference.snap | 2 +- .../type-parameters/param-reference.snap | 2 +- .../return-value-reference.snap | 2 +- .../type-parameters/type-param-reference.snap | 2 +- .../type-parameter-declaration.snap | 2 +- .../arrow/type-predicate-asserts1.snap | 2 +- .../arrow/type-predicate-asserts2.snap | 2 +- .../functions/arrow/type-predicate1.snap | 2 +- .../functions/arrow/type-predicate2.snap | 2 +- .../module/variable-decl-const.snap | 2 +- .../module/variable-decl-let.snap | 2 +- .../module/variable-decl-var.snap | 2 +- .../script/variable-decl-const.snap | 2 +- .../script/variable-decl-let.snap | 2 +- .../script/variable-decl-var.snap | 2 +- crates/oxc_syntax/src/symbol.rs | 39 ++++++------------- .../src/es2015/arrow_functions.rs | 14 ------- crates/oxc_transformer/src/es2015/mod.rs | 10 ----- crates/oxc_transformer/src/lib.rs | 8 ---- tasks/coverage/semantic_typescript.snap | 20 +++++----- 32 files changed, 49 insertions(+), 102 deletions(-) diff --git a/crates/oxc_semantic/src/binder.rs b/crates/oxc_semantic/src/binder.rs index b3e4b9f2f31d3..bae7ff38a68ca 100644 --- a/crates/oxc_semantic/src/binder.rs +++ b/crates/oxc_semantic/src/binder.rs @@ -23,7 +23,7 @@ pub(crate) trait Binder<'a> { impl<'a> Binder<'a> for VariableDeclarator<'a> { fn bind(&self, builder: &mut SemanticBuilder<'a>) { - let (mut includes, excludes) = match self.kind { + let (includes, excludes) = match self.kind { VariableDeclarationKind::Const => ( SymbolFlags::BlockScopedVariable | SymbolFlags::ConstVariable, SymbolFlags::BlockScopedVariableExcludes, @@ -38,12 +38,6 @@ impl<'a> Binder<'a> for VariableDeclarator<'a> { } }; - if self.init.as_ref().is_some_and(|init| { - matches!(init.get_inner_expression(), Expression::ArrowFunctionExpression(_)) - }) { - includes |= SymbolFlags::ArrowFunction; - } - if self.kind.is_lexical() { self.id.bound_names(&mut |ident| { let symbol_id = builder.declare_symbol(ident.span, &ident.name, includes, excludes); diff --git a/crates/oxc_semantic/tests/fixtures/oxc/jsx/element-name.snap b/crates/oxc_semantic/tests/fixtures/oxc/jsx/element-name.snap index c98655bc0197b..5fc6d7e796213 100644 --- a/crates/oxc_semantic/tests/fixtures/oxc/jsx/element-name.snap +++ b/crates/oxc_semantic/tests/fixtures/oxc/jsx/element-name.snap @@ -18,7 +18,7 @@ input_file: crates/oxc_semantic/tests/fixtures/oxc/jsx/element-name.jsx "node": "Program", "symbols": [ { - "flags": "SymbolFlags(BlockScopedVariable | ArrowFunction)", + "flags": "SymbolFlags(BlockScopedVariable)", "id": 0, "name": "Component", "node": "VariableDeclarator(Component)", diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/call-expression/call-expression.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/call-expression/call-expression.snap index dff558aa270c8..3569953092a34 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/call-expression/call-expression.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/call-expression/call-expression.snap @@ -18,7 +18,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/call-expression "node": "Program", "symbols": [ { - "flags": "SymbolFlags(BlockScopedVariable | ConstVariable | ArrowFunction)", + "flags": "SymbolFlags(BlockScopedVariable | ConstVariable)", "id": 0, "name": "foo", "node": "VariableDeclarator(foo)", diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/default-params/readable-ref-body-shadow.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/default-params/readable-ref-body-shadow.snap index cf9a4be1bc48b..a00ab7e2f4d67 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/default-params/readable-ref-body-shadow.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/default-params/readable-ref-body-shadow.snap @@ -47,7 +47,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow ] }, { - "flags": "SymbolFlags(BlockScopedVariable | ArrowFunction)", + "flags": "SymbolFlags(BlockScopedVariable)", "id": 1, "name": "foo", "node": "VariableDeclarator(foo)", diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/default-params/readable-ref-const.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/default-params/readable-ref-const.snap index 9f92b2eb4440a..032178283cc7e 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/default-params/readable-ref-const.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/default-params/readable-ref-const.snap @@ -40,7 +40,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow ] }, { - "flags": "SymbolFlags(BlockScopedVariable | ArrowFunction)", + "flags": "SymbolFlags(BlockScopedVariable)", "id": 1, "name": "foo", "node": "VariableDeclarator(foo)", diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/default-params/readable-ref-let.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/default-params/readable-ref-let.snap index cf7b31adcbbcf..6de2b071c4f26 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/default-params/readable-ref-let.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/default-params/readable-ref-let.snap @@ -40,7 +40,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow ] }, { - "flags": "SymbolFlags(BlockScopedVariable | ArrowFunction)", + "flags": "SymbolFlags(BlockScopedVariable)", "id": 1, "name": "foo", "node": "VariableDeclarator(foo)", diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/default-params/readable-ref-nested-body-shadow.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/default-params/readable-ref-nested-body-shadow.snap index 6a25abd95d310..436d36f7b0cda 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/default-params/readable-ref-nested-body-shadow.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/default-params/readable-ref-nested-body-shadow.snap @@ -55,7 +55,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow ] }, { - "flags": "SymbolFlags(BlockScopedVariable | ArrowFunction)", + "flags": "SymbolFlags(BlockScopedVariable)", "id": 1, "name": "foo", "node": "VariableDeclarator(foo)", diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/default-params/readable-ref-nested.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/default-params/readable-ref-nested.snap index d1d5f04c64ffa..deda613955457 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/default-params/readable-ref-nested.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/default-params/readable-ref-nested.snap @@ -48,7 +48,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow ] }, { - "flags": "SymbolFlags(BlockScopedVariable | ArrowFunction)", + "flags": "SymbolFlags(BlockScopedVariable)", "id": 1, "name": "foo", "node": "VariableDeclarator(foo)", diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/default-params/readable-ref-param-shadow.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/default-params/readable-ref-param-shadow.snap index 3f6b337fc2210..366e44ea1d2a3 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/default-params/readable-ref-param-shadow.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/default-params/readable-ref-param-shadow.snap @@ -47,7 +47,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow "references": [] }, { - "flags": "SymbolFlags(BlockScopedVariable | ArrowFunction)", + "flags": "SymbolFlags(BlockScopedVariable)", "id": 1, "name": "foo", "node": "VariableDeclarator(foo)", diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/default-params/readable-ref-partial.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/default-params/readable-ref-partial.snap index 75afde02ee168..25a868edd14c9 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/default-params/readable-ref-partial.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/default-params/readable-ref-partial.snap @@ -40,7 +40,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow ] }, { - "flags": "SymbolFlags(BlockScopedVariable | ArrowFunction)", + "flags": "SymbolFlags(BlockScopedVariable)", "id": 1, "name": "foo", "node": "VariableDeclarator(foo)", diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/default-params/writable-ref.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/default-params/writable-ref.snap index 8a71b0c966968..f203762d93a86 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/default-params/writable-ref.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/default-params/writable-ref.snap @@ -33,7 +33,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow "node": "Program", "symbols": [ { - "flags": "SymbolFlags(BlockScopedVariable | ArrowFunction)", + "flags": "SymbolFlags(BlockScopedVariable)", "id": 0, "name": "foo", "node": "VariableDeclarator(foo)", diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/scope.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/scope.snap index 6a760fa558855..28003cfd654a4 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/scope.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/scope.snap @@ -40,7 +40,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow "node": "Program", "symbols": [ { - "flags": "SymbolFlags(BlockScopedVariable | ConstVariable | ArrowFunction)", + "flags": "SymbolFlags(BlockScopedVariable | ConstVariable)", "id": 0, "name": "arrow", "node": "VariableDeclarator(arrow)", diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/body-reference.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/body-reference.snap index 8c26f3de77856..78298d6cdc34f 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/body-reference.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/body-reference.snap @@ -40,7 +40,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow "node": "Program", "symbols": [ { - "flags": "SymbolFlags(BlockScopedVariable | ConstVariable | ArrowFunction)", + "flags": "SymbolFlags(BlockScopedVariable | ConstVariable)", "id": 0, "name": "foo", "node": "VariableDeclarator(foo)", diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/param-reference.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/param-reference.snap index e13e12041c785..55ab7bf2ba9d7 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/param-reference.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/param-reference.snap @@ -40,7 +40,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow "node": "Program", "symbols": [ { - "flags": "SymbolFlags(BlockScopedVariable | ConstVariable | ArrowFunction)", + "flags": "SymbolFlags(BlockScopedVariable | ConstVariable)", "id": 0, "name": "foo", "node": "VariableDeclarator(foo)", diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/return-value-reference.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/return-value-reference.snap index 77dffc7b2c3fc..6eb897b0cca7e 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/return-value-reference.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/return-value-reference.snap @@ -33,7 +33,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow "node": "Program", "symbols": [ { - "flags": "SymbolFlags(BlockScopedVariable | ConstVariable | ArrowFunction)", + "flags": "SymbolFlags(BlockScopedVariable | ConstVariable)", "id": 0, "name": "foo", "node": "VariableDeclarator(foo)", diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/type-param-reference.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/type-param-reference.snap index 2614cd3ecd698..439eaea9c281f 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/type-param-reference.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/type-param-reference.snap @@ -40,7 +40,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow "node": "Program", "symbols": [ { - "flags": "SymbolFlags(BlockScopedVariable | ConstVariable | ArrowFunction)", + "flags": "SymbolFlags(BlockScopedVariable | ConstVariable)", "id": 0, "name": "foo", "node": "VariableDeclarator(foo)", diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/type-parameter-declaration.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/type-parameter-declaration.snap index c7ac24261a457..693e95288c397 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/type-parameter-declaration.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-parameters/type-parameter-declaration.snap @@ -33,7 +33,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow "node": "Program", "symbols": [ { - "flags": "SymbolFlags(BlockScopedVariable | ConstVariable | ArrowFunction)", + "flags": "SymbolFlags(BlockScopedVariable | ConstVariable)", "id": 0, "name": "foo", "node": "VariableDeclarator(foo)", diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-predicate-asserts1.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-predicate-asserts1.snap index f1bbb07757331..e3c2e7f5c2ab6 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-predicate-asserts1.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-predicate-asserts1.snap @@ -26,7 +26,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow "node": "Program", "symbols": [ { - "flags": "SymbolFlags(BlockScopedVariable | ConstVariable | ArrowFunction)", + "flags": "SymbolFlags(BlockScopedVariable | ConstVariable)", "id": 0, "name": "foo", "node": "VariableDeclarator(foo)", diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-predicate-asserts2.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-predicate-asserts2.snap index dc76b47bb4bde..7036dd1b24725 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-predicate-asserts2.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-predicate-asserts2.snap @@ -47,7 +47,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow ] }, { - "flags": "SymbolFlags(BlockScopedVariable | ConstVariable | ArrowFunction)", + "flags": "SymbolFlags(BlockScopedVariable | ConstVariable)", "id": 1, "name": "foo", "node": "VariableDeclarator(foo)", diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-predicate1.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-predicate1.snap index ab0e0ce6dce32..68da9d5ec8122 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-predicate1.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-predicate1.snap @@ -33,7 +33,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow "node": "Program", "symbols": [ { - "flags": "SymbolFlags(BlockScopedVariable | ConstVariable | ArrowFunction)", + "flags": "SymbolFlags(BlockScopedVariable | ConstVariable)", "id": 0, "name": "foo", "node": "VariableDeclarator(foo)", diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-predicate2.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-predicate2.snap index 34e32379fb01f..7ee3ecebb65e0 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-predicate2.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow/type-predicate2.snap @@ -54,7 +54,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/functions/arrow ] }, { - "flags": "SymbolFlags(BlockScopedVariable | ConstVariable | ArrowFunction)", + "flags": "SymbolFlags(BlockScopedVariable | ConstVariable)", "id": 1, "name": "foo", "node": "VariableDeclarator(foo)", diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/global-resolution/module/variable-decl-const.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/global-resolution/module/variable-decl-const.snap index d4a18b6bb0412..2021815ce1444 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/global-resolution/module/variable-decl-const.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/global-resolution/module/variable-decl-const.snap @@ -18,7 +18,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/global-resoluti "node": "Program", "symbols": [ { - "flags": "SymbolFlags(BlockScopedVariable | ConstVariable | ArrowFunction)", + "flags": "SymbolFlags(BlockScopedVariable | ConstVariable)", "id": 0, "name": "top", "node": "VariableDeclarator(top)", diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/global-resolution/module/variable-decl-let.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/global-resolution/module/variable-decl-let.snap index 43e15f5efc9cc..b24985e2d519c 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/global-resolution/module/variable-decl-let.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/global-resolution/module/variable-decl-let.snap @@ -18,7 +18,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/global-resoluti "node": "Program", "symbols": [ { - "flags": "SymbolFlags(BlockScopedVariable | ArrowFunction)", + "flags": "SymbolFlags(BlockScopedVariable)", "id": 0, "name": "top", "node": "VariableDeclarator(top)", diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/global-resolution/module/variable-decl-var.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/global-resolution/module/variable-decl-var.snap index 66ec302f1c2fd..f474ff8dd22dc 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/global-resolution/module/variable-decl-var.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/global-resolution/module/variable-decl-var.snap @@ -18,7 +18,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/global-resoluti "node": "Program", "symbols": [ { - "flags": "SymbolFlags(FunctionScopedVariable | ArrowFunction)", + "flags": "SymbolFlags(FunctionScopedVariable)", "id": 0, "name": "top", "node": "VariableDeclarator(top)", diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/global-resolution/script/variable-decl-const.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/global-resolution/script/variable-decl-const.snap index 7d2f3941b95d2..391b8697e14e6 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/global-resolution/script/variable-decl-const.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/global-resolution/script/variable-decl-const.snap @@ -18,7 +18,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/global-resoluti "node": "Program", "symbols": [ { - "flags": "SymbolFlags(BlockScopedVariable | ConstVariable | ArrowFunction)", + "flags": "SymbolFlags(BlockScopedVariable | ConstVariable)", "id": 0, "name": "top", "node": "VariableDeclarator(top)", diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/global-resolution/script/variable-decl-let.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/global-resolution/script/variable-decl-let.snap index ed061693060e3..25086578c9dde 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/global-resolution/script/variable-decl-let.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/global-resolution/script/variable-decl-let.snap @@ -18,7 +18,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/global-resoluti "node": "Program", "symbols": [ { - "flags": "SymbolFlags(BlockScopedVariable | ArrowFunction)", + "flags": "SymbolFlags(BlockScopedVariable)", "id": 0, "name": "top", "node": "VariableDeclarator(top)", diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/global-resolution/script/variable-decl-var.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/global-resolution/script/variable-decl-var.snap index 1688b6e33673c..70455e2e0b24c 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/global-resolution/script/variable-decl-var.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/global-resolution/script/variable-decl-var.snap @@ -18,7 +18,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/global-resoluti "node": "Program", "symbols": [ { - "flags": "SymbolFlags(FunctionScopedVariable | ArrowFunction)", + "flags": "SymbolFlags(FunctionScopedVariable)", "id": 0, "name": "top", "node": "VariableDeclarator(top)", diff --git a/crates/oxc_syntax/src/symbol.rs b/crates/oxc_syntax/src/symbol.rs index b2eabbac486e0..776127733eaf5 100644 --- a/crates/oxc_syntax/src/symbol.rs +++ b/crates/oxc_syntax/src/symbol.rs @@ -82,24 +82,22 @@ bitflags! { const CatchVariable = 1 << 6; /// A function declaration or expression const Function = 1 << 7; - /// A function or block-scoped variable initialized to an arrow function - const ArrowFunction = 1 << 8; /// Imported ESM binding - const Import = 1 << 9; + const Import = 1 << 8; /// Imported ESM type-only binding - const TypeImport = 1 << 10; + const TypeImport = 1 << 9; // Type specific symbol flags - const TypeAlias = 1 << 11; - const Interface = 1 << 12; - const RegularEnum = 1 << 13; - const ConstEnum = 1 << 14; - const EnumMember = 1 << 15; - const TypeLiteral = 1 << 16; - const TypeParameter = 1 << 17; - const NameSpaceModule = 1 << 18; - const ValueModule = 1 << 19; + const TypeAlias = 1 << 10; + const Interface = 1 << 11; + const RegularEnum = 1 << 12; + const ConstEnum = 1 << 13; + const EnumMember = 1 << 14; + const TypeLiteral = 1 << 15; + const TypeParameter = 1 << 16; + const NameSpaceModule = 1 << 17; + const ValueModule = 1 << 18; // In a dts file or there is a declare flag - const Ambient = 1 << 20; + const Ambient = 1 << 19; const Enum = Self::ConstEnum.bits() | Self::RegularEnum.bits(); @@ -158,24 +156,11 @@ impl SymbolFlags { } /// Returns `true` if this symbol is a function declaration or expression. - /// - /// Use [`SymbolFlags::is_function_like`] to check if this symbol is a function or an arrow function. #[inline] pub fn is_function(&self) -> bool { self.contains(Self::Function) } - #[inline] - pub fn is_arrow_function(&self) -> bool { - self.contains(Self::ArrowFunction) - } - - /// Returns `true` if this symbol is an arrow function or a function declaration/expression. - #[inline] - pub fn is_function_like(&self) -> bool { - self.intersects(Self::Function | Self::ArrowFunction) - } - #[inline] pub fn is_class(&self) -> bool { self.contains(Self::Class) diff --git a/crates/oxc_transformer/src/es2015/arrow_functions.rs b/crates/oxc_transformer/src/es2015/arrow_functions.rs index 89ee8f5ddfa85..1311dcf0e774d 100644 --- a/crates/oxc_transformer/src/es2015/arrow_functions.rs +++ b/crates/oxc_transformer/src/es2015/arrow_functions.rs @@ -246,20 +246,6 @@ impl<'a> Traverse<'a> for ArrowFunctions<'a> { *expr = self.transform_arrow_function_expression(arrow_function_expr.unbox(), ctx); } } - - fn enter_variable_declarator( - &mut self, - node: &mut VariableDeclarator<'a>, - ctx: &mut TraverseCtx<'a>, - ) { - if !matches!(node.init, Some(Expression::ArrowFunctionExpression(_))) { - return; - } - - let Some(id) = node.id.get_binding_identifier() else { return }; - *ctx.symbols_mut().get_flags_mut(id.symbol_id.get().unwrap()) &= - !SymbolFlags::ArrowFunction; - } } impl<'a> ArrowFunctions<'a> { diff --git a/crates/oxc_transformer/src/es2015/mod.rs b/crates/oxc_transformer/src/es2015/mod.rs index e1a007dedac9b..2d49e79924e8e 100644 --- a/crates/oxc_transformer/src/es2015/mod.rs +++ b/crates/oxc_transformer/src/es2015/mod.rs @@ -107,16 +107,6 @@ impl<'a> Traverse<'a> for ES2015<'a> { } } - fn enter_variable_declarator( - &mut self, - node: &mut VariableDeclarator<'a>, - ctx: &mut TraverseCtx<'a>, - ) { - if self.options.arrow_function.is_some() { - self.arrow_functions.enter_variable_declarator(node, ctx); - } - } - fn enter_jsx_element_name(&mut self, node: &mut JSXElementName<'a>, ctx: &mut TraverseCtx<'a>) { if self.options.arrow_function.is_some() { self.arrow_functions.enter_jsx_element_name(node, ctx); diff --git a/crates/oxc_transformer/src/lib.rs b/crates/oxc_transformer/src/lib.rs index bcde55095e51c..13c158d448beb 100644 --- a/crates/oxc_transformer/src/lib.rs +++ b/crates/oxc_transformer/src/lib.rs @@ -388,14 +388,6 @@ impl<'a> Traverse<'a> for Transformer<'a> { self.x2_es2019.enter_catch_clause(clause, ctx); } - fn enter_variable_declarator( - &mut self, - node: &mut VariableDeclarator<'a>, - ctx: &mut TraverseCtx<'a>, - ) { - self.x3_es2015.enter_variable_declarator(node, ctx); - } - fn enter_import_declaration( &mut self, node: &mut ImportDeclaration<'a>, diff --git a/tasks/coverage/semantic_typescript.snap b/tasks/coverage/semantic_typescript.snap index 64a0ac1dd6d17..00ef96263acf1 100644 --- a/tasks/coverage/semantic_typescript.snap +++ b/tasks/coverage/semantic_typescript.snap @@ -8272,8 +8272,8 @@ Bindings mismatch: after transform: ScopeId(4): ["a", "b", "p"] rebuilt : ScopeId(2): ["a", "b"] Symbol flags mismatch: -after transform: SymbolId(0): SymbolFlags(BlockScopedVariable | ConstVariable | Export | ArrowFunction | Interface) -rebuilt : SymbolId(0): SymbolFlags(BlockScopedVariable | ConstVariable | Export | ArrowFunction) +after transform: SymbolId(0): SymbolFlags(BlockScopedVariable | ConstVariable | Export | Interface) +rebuilt : SymbolId(0): SymbolFlags(BlockScopedVariable | ConstVariable | Export) Symbol span mismatch: after transform: SymbolId(0): Span { start: 17, end: 22 } rebuilt : SymbolId(0): Span { start: 171, end: 176 } @@ -8284,8 +8284,8 @@ Symbol redeclarations mismatch: after transform: SymbolId(0): [Span { start: 171, end: 176 }] rebuilt : SymbolId(0): [] Symbol flags mismatch: -after transform: SymbolId(1): SymbolFlags(BlockScopedVariable | ConstVariable | Export | ArrowFunction | Interface) -rebuilt : SymbolId(3): SymbolFlags(BlockScopedVariable | ConstVariable | Export | ArrowFunction) +after transform: SymbolId(1): SymbolFlags(BlockScopedVariable | ConstVariable | Export | Interface) +rebuilt : SymbolId(3): SymbolFlags(BlockScopedVariable | ConstVariable | Export) Symbol span mismatch: after transform: SymbolId(1): Span { start: 93, end: 97 } rebuilt : SymbolId(3): Span { start: 237, end: 241 } @@ -17662,8 +17662,8 @@ semantic error: Scope children mismatch: after transform: ScopeId(0): [ScopeId(1), ScopeId(2)] rebuilt : ScopeId(0): [ScopeId(1)] Symbol flags mismatch: -after transform: SymbolId(0): SymbolFlags(BlockScopedVariable | ConstVariable | Export | ArrowFunction | Interface) -rebuilt : SymbolId(0): SymbolFlags(BlockScopedVariable | ConstVariable | Export | ArrowFunction) +after transform: SymbolId(0): SymbolFlags(BlockScopedVariable | ConstVariable | Export | Interface) +rebuilt : SymbolId(0): SymbolFlags(BlockScopedVariable | ConstVariable | Export) Symbol span mismatch: after transform: SymbolId(0): Span { start: 10, end: 20 } rebuilt : SymbolId(0): Span { start: 52, end: 62 } @@ -39879,8 +39879,8 @@ Symbol reference IDs mismatch: after transform: SymbolId(2): [ReferenceId(1), ReferenceId(5)] rebuilt : SymbolId(0): [ReferenceId(2)] Symbol flags mismatch: -after transform: SymbolId(9): SymbolFlags(BlockScopedVariable | ConstVariable | ArrowFunction | Interface) -rebuilt : SymbolId(7): SymbolFlags(BlockScopedVariable | ConstVariable | ArrowFunction) +after transform: SymbolId(9): SymbolFlags(BlockScopedVariable | ConstVariable | Interface) +rebuilt : SymbolId(7): SymbolFlags(BlockScopedVariable | ConstVariable) Symbol span mismatch: after transform: SymbolId(9): Span { start: 247, end: 256 } rebuilt : SymbolId(7): Span { start: 287, end: 296 } @@ -59054,8 +59054,8 @@ Bindings mismatch: after transform: ScopeId(20): ["T", "f"] rebuilt : ScopeId(9): ["f"] Symbol flags mismatch: -after transform: SymbolId(70): SymbolFlags(BlockScopedVariable | ConstVariable | ArrowFunction | TypeAlias) -rebuilt : SymbolId(32): SymbolFlags(BlockScopedVariable | ConstVariable | ArrowFunction) +after transform: SymbolId(70): SymbolFlags(BlockScopedVariable | ConstVariable | TypeAlias) +rebuilt : SymbolId(32): SymbolFlags(BlockScopedVariable | ConstVariable) Symbol span mismatch: after transform: SymbolId(70): Span { start: 1594, end: 1596 } rebuilt : SymbolId(32): Span { start: 1621, end: 1627 }