Git Product home page Git Product logo

Comments (3)

Dunqing avatar Dunqing commented on August 16, 2024

Ah, Haha. This is also a bit confusing for visit orders. I thought about it again. We can defer binding FunctionExpression and ClassExpression and bind them when we visit BindingIdentifier.

from oxc.

overlookmotel avatar overlookmotel commented on August 16, 2024

@Dunqing Just to throw in my 2 cents, I wonder if FunctionExpression and FunctionDeclaration should be separate types (and each type would have Function as a field within it). The 2 have various significant differences:

  1. One is a Statement, the other an Expression.
  2. FunctionExpression's name field should be an Option, whereas it's compulsory in FunctionDeclaration.
  3. Scope should be entered before name for FunctionExpression and after name for FunctionDeclaration.

We could also have a separate type for ObjectMethod (whose name isn't a binding at all).

At present, it's possible to create non-sensical AST nodes (e.g. a FunctionDeclaration with no name) - it'd be good to make this impossible through the type system.

from oxc.

Dunqing avatar Dunqing commented on August 16, 2024

@Dunqing Just to throw in my 2 cents, I wonder if FunctionExpression and FunctionDeclaration should be separate types (and each type would have Function as a field within it). The 2 have various significant differences:

  1. One is a Statement, the other an Expression.
  2. FunctionExpression's name field should be an Option, whereas it's compulsory in FunctionDeclaration.
  3. Scope should be entered before name for FunctionExpression and after name for FunctionDeclaration.

We could also have a separate type for ObjectMethod (whose name isn't a binding at all).

At present, it's possible to create non-sensical AST nodes (e.g. a FunctionDeclaration with no name) - it'd be good to make this impossible through the type system.

Yes, I talked with @Boshen about the above. Since they are not very different, they have been combined into one type. I agree we should have different types for FunctionExpression and FunctionDeclaration, and also class should be ClassExpression and ClassDeclaration

  1. Scope should be entered before name for FunctionExpression and after name for FunctionDeclaration.

We bind in enter_node. So we have to switch the order of enter_node and enter_scope to bind it to the corresponding scope. Or do something like #4195 (comment).

from oxc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.