-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feat]: equality operators #1277
base: main
Are you sure you want to change the base?
Conversation
df5c627
to
a40dc36
Compare
The resolved helper must win (we can't assume that a resolved helper named
RE: when to issue a deprecation: I think we would only want to issue a deprecation if our implementation returns a different result than the resolved helper version. RE: how to issue a deprecation: there is a nice deprecation system already built out, you import the deprecate function from global context and then invoke it. Ember has a hook into those deprecations and can augment the deprecation options (e.g. to add |
a40dc36
to
be501f0
Compare
@@ -34,7 +34,8 @@ class KeywordImpl< | |||
constructor( | |||
protected keyword: S, | |||
type: KeywordType, | |||
private delegate: KeywordDelegate<KeywordMatches[K], Param, Out> | |||
private delegate: KeywordDelegate<KeywordMatches[K], Param, Out>, | |||
private options?: { strictOnly: boolean } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't sure if this anonymous type was ok with you. (we could share an actual interface in multiple spots)
aa76473
to
7710fc0
Compare
function assertEqualKeyword(node: GenericKeywordNode): Result<ASTv2.PositionalArguments> { | ||
let { | ||
args: { named, positional }, | ||
} = node; | ||
|
||
if (named && !named.isEmpty()) { | ||
return Err(generateSyntaxError(`(eq) does not take any named arguments`, node.loc)); | ||
} | ||
|
||
return Ok(positional); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we also need to assert if you use more than two positional arguments
{{eq}}
Binary operation. Throws an error if not called with exactly two arguments. Equivalent of === This is identical to the eq helper in ember-truth-helpers
function assertNotEqualKeyword(node: GenericKeywordNode): Result<ASTv2.PositionalArguments> { | ||
let { | ||
args: { named, positional }, | ||
} = node; | ||
|
||
if (named && !named.isEmpty()) { | ||
return Err(generateSyntaxError(`(neq) does not take any named arguments`, node.loc)); | ||
} | ||
|
||
return Ok(positional); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to assert RE: more than two positional params
{{neq}}
Binary operation. Throws an error if not called with exactly two arguments. Equivalent of !== This is identical to the not-eq helper in ember-truth-helpers, except for the name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we also need to update https://github.com/glimmerjs/glimmer-vm/blob/master/packages/@glimmer/vm/lib/opcodes.toml for these new opcodes.
|
||
@test | ||
['it works multiple arguments eq']() { | ||
const AComponent = defineComponent({}, '{{eq 1 1 1}}'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is not supposed to work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rwjblue easy enough to support multiple I imagine. What do you think?
What else does this PR need to land? I would love love love to see this land. <3 Thank you all for working on it! |
@MelSumner part of the reason this has been blocked is because of v4 prep, we didn't want to land more changes in the VM before the last 3.x LTS was fully stable, in case we had to backport more fixes (there have been a few already). Once that's done, I think the biggest issue is we need to actually change the way this is implemented so that in |
@pzuraq perfect, thanks for clarifying! |
It has been a while so I may have this wrong but I I think one workaround that we talked about and I put into this PR was a flag RE: comments |
656676e
to
3e0a222
Compare
3e0a222
to
75a7746
Compare
What's left here? It's been a couple months |
@NullVoxPopuli I believe nothing. I'm excited about this but I'll need some help from either @chancancode and/or @rwjblue to review. I've addressed the comments so far... |
I'll ping them |
@wycats has thoughts on the strict vs loose difference (he don't think it is correct that we should have to handle them differently). He'll comment later. As for Regarding >2 arguments for |
does anything need to be done? |
75a7746
to
c4948ec
Compare
Sounds like we have a few steps.
|
Sounds good to me, pretty easy to change/fix later |
This has been updated with strict 2 arguments to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking forward to this 👍
return Err( | ||
generateSyntaxError( | ||
`(eq) must receive two positional parameters. Received ${ | ||
positional?.size ?? 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
positional?.size ?? 0 | |
positional.size ?? 0 |
Since we already do positional.size
on line 18?
return Err( | ||
generateSyntaxError( | ||
`(neq) must receive two positional parameters. Received ${ | ||
positional?.size ?? 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
positional?.size ?? 0 | |
positional.size ?? 0 |
Since we already do positional.size
on line 59?
RFC: emberjs/rfcs#560
eq
neq
Related pkg - https://github.com/jmurphyau/ember-truth-helpers/blob/master/addon/helpers/equal.js
Some outstanding questions:
Willfeature flagloose mode
will compile this keyword into a helper, calling the existing (addon such as ember-truth-helpers or other) if present. Should we add a deprecation at this point.strictOnly
addedneq
tonot-eq
. Happy to open an another RFC or amendment to resolve. This would also align us and allow us to deprecate ember-truth-helpers as well.Other upstream PRs to be merged first are here, starting with logical operators. - snewcomer#1 snewcomer#3