Skip to content

Bindings declared with using should be block scoped and const #9666

@overlookmotel

Description

@overlookmotel

Explicit resource management proposal describes using as describing "a synchronously-disposed, block-scoped resource". The intent of using is that the resource is automatically disposed of at the end of the enclosing block, so block scoping makes sense.

Additionally, the proposal shows equivalent transpiled code as using a const binding.

Currently Oxc generates a binding with symbol flags FunctionScopedVariable, and hoists the binding to scope of enclosing function (like var). I believe it should behave like const - flags BlockScopedVariable | ConstVariable, and the binding should not be hoisted.

function f() {
  {
    using x = 123;
  }
}

Playground

In the above example, the binding x should not be hoisted to top level of function f.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions