Skip to content
This repository was archived by the owner on Apr 3, 2025. It is now read-only.
This repository was archived by the owner on Apr 3, 2025. It is now read-only.

The syntax should be scoped to a block instead of a module #40

Open

Activity

  1. ljharb commented on Jan 30, 2021

    @ljharb
    Member

    I don’t find bundler flaws a compelling motivation whatsoever, but i do like that it makes the scope where the magic operator applies much more explicit and clear.

  2. littledan commented on Jan 31, 2021

    @littledan
    Member

    The idea of this writeup is that it is scoped to the enclosing block, not the whole module. I agree that this is an important property, including to enable bundling. The README should probably be clarified on this point.

  3. alexrock commented on Apr 20, 2021

    @alexrock

    How would I declare an exported class that uses overloaded operators from another class in an idiomatic way and using blocks?

    Example not using blocks:

    import { Vector } from './vector'
    
    with operators from Vector
    
    export class Foo {
      bar() {
        3 * new Vector([1, 2, 3])
      }
    
      // ... more methods using overloaded operators
    }
    
  4. Jack-Works commented on Apr 21, 2021

    @Jack-Works
    MemberAuthor

    I think now this issue can be resolved by the module fragments proposal even it is module scoped.

  5. jhmaster2000 commented on Feb 9, 2022

    @jhmaster2000

    How would I declare an exported class that uses overloaded operators from another class in an idiomatic way and using blocks?

    Example not using blocks:

    import { Vector } from './vector'
    
    with operators from Vector
    
    export class Foo {
      bar() {
        3 * new Vector([1, 2, 3])
      }
    
      // ... more methods using overloaded operators
    }
    

    If that class is the only one in the file, you can just use it like that without issues since operators dont get imported automatically through modules.

    If you wanted to put other things besides that class in that same file, and those other things for some reason break with Vector operators overloaded, with the current proposal you'd have to use the with operators statement on every method of Foo using them I guess. Perhaps decorators could aid in declaring class-level overload usage like so:

    import { Vector } from './vector';
    
    @Operators from Vector;
    export class Foo {
      bar() {
        3 * new Vector([1, 2, 3]); // overloaded
      }
      // ... more methods using overloaded operators
    }
    
    3 * new Vector([1, 2, 3]); // not overloaded
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions