You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 3, 2025. It is now read-only.
Repository navigation
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
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.
Reacted by Jack Works, Jo Colina, Gianmarco, csha and jhmaster
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.
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
}
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
Activity
ljharb commentedon Jan 30, 2021
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.
littledan commentedon Jan 31, 2021
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.
alexrock commentedon Apr 20, 2021
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:
Jack-Works commentedon Apr 21, 2021
I think now this issue can be resolved by the module fragments proposal even it is module scoped.
jhmaster2000 commentedon Feb 9, 2022
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 operatorsstatement on every method ofFoousing them I guess. Perhaps decorators could aid in declaring class-level overload usage like so: