-
Notifications
You must be signed in to change notification settings - Fork 95
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
Fix Glint types by converting helpers to plain functions #188
Changes from 16 commits
7f24e42
ba8ac40
5e30144
557ff7b
1c8ba28
0b89b30
19d10cb
f0b46e7
290f72f
e6314cf
4b22c67
245e82a
52e9a16
9f7347f
ce51051
b21676d
b8e90e2
7b251ea
9766373
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,11 @@ | ||
import { helper } from '@ember/component/helper'; | ||
import truthConvert from '../utils/truth-convert.ts'; | ||
import type { MaybeTruth } from '../utils/truth-convert.ts'; | ||
|
||
export interface AndSignature { | ||
Args: { | ||
Positional: MaybeTruth[]; | ||
}; | ||
Return: boolean; | ||
} | ||
|
||
export default helper<AndSignature>((params) => { | ||
export default function and<T extends MaybeTruth[]>(...params: [...T]) { | ||
NullVoxPopuli marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @NullVoxPopuli using spread causes an issue - today, arguments gets lazily evaluated and spread makes it process eager. e.g. imagine use case {{and (foo "A") (bar "B")}} today, if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's just how plain functions work though: https://github.com/glimmerjs/glimmer-vm/blob/68d371bdccb41bc239b8f70d832e956ce6c349d8/packages/%40glimmer/manager/lib/internal/defaults.ts#L38 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to make There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if |
||
for (let i = 0, len = params.length; i < len; i++) { | ||
if (truthConvert(params[i]) === false) { | ||
return params[i] as boolean; | ||
} | ||
} | ||
return params[params.length - 1] as boolean; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. keeping the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (not that this PR needs to solve that too) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,3 @@ | ||
import { helper } from '@ember/component/helper'; | ||
|
||
export interface EqSignature { | ||
Args: { | ||
Positional: [unknown, unknown]; | ||
}; | ||
Return: boolean; | ||
export default function eq(left: unknown, right: unknown): boolean { | ||
return left === right; | ||
} | ||
|
||
export default helper<EqSignature>((params) => { | ||
return params[0] === params[1]; | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,5 @@ | ||
import { helper } from '@ember/component/helper'; | ||
import { isArray } from '@ember/array'; | ||
import type EmberArray from '@ember/array'; | ||
import { isArray as isEmberArray } from '@ember/array'; | ||
|
||
export interface IsArraySignature { | ||
Args: { | ||
Positional: unknown[] | EmberArray<unknown>; | ||
}; | ||
Return: boolean; | ||
export default function isArray(...params: unknown[]) { | ||
return params.every(isEmberArray); | ||
} | ||
|
||
export default helper<IsArraySignature>((params) => { | ||
return params.every(isArray); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,3 @@ | ||
import { helper } from '@ember/component/helper'; | ||
import { isEmpty } from '@ember/utils'; | ||
|
||
export interface IsEmptySignature { | ||
Args: { | ||
Positional: [unknown]; | ||
}; | ||
Return: boolean; | ||
} | ||
|
||
export default helper<IsEmptySignature>(([obj]) => { | ||
return isEmpty(obj); | ||
}); | ||
export default isEmpty; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,3 @@ | ||
import { helper } from '@ember/component/helper'; | ||
import { isEqual } from '@ember/utils'; | ||
|
||
export interface IsEqualSignature { | ||
Args: { | ||
Positional: [unknown, unknown]; | ||
}; | ||
Return: boolean; | ||
} | ||
|
||
export default helper<IsEqualSignature>(([a, b]) => { | ||
return isEqual(a, b); | ||
}); | ||
export default isEqual; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,3 @@ | ||
import { helper } from '@ember/component/helper'; | ||
|
||
export interface NotEqSignature { | ||
Args: { | ||
Positional: [unknown, unknown]; | ||
}; | ||
Return: boolean; | ||
export default function notEq(left: unknown, right: unknown) { | ||
return left !== right; | ||
} | ||
|
||
export default helper<NotEqSignature>((params) => { | ||
return params[0] !== params[1]; | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,6 @@ | ||
import { helper } from '@ember/component/helper'; | ||
import truthConvert from '../utils/truth-convert.ts'; | ||
import type { MaybeTruth } from '../utils/truth-convert.ts'; | ||
|
||
export interface NotSignature { | ||
Args: { | ||
Positional: MaybeTruth[]; | ||
}; | ||
Return: boolean; | ||
} | ||
|
||
export default helper<NotSignature>((params) => { | ||
export default function not(...params: MaybeTruth[]) { | ||
return params.every((param) => !truthConvert(param)); | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,29 @@ | ||
import { helper } from '@ember/component/helper'; | ||
import truthConvert from '../utils/truth-convert.ts'; | ||
import type { MaybeTruth } from '../utils/truth-convert.ts'; | ||
|
||
export interface OrSignature { | ||
Args: { | ||
Positional: MaybeTruth[]; | ||
}; | ||
Return: boolean; | ||
} | ||
|
||
export default helper<OrSignature>((params) => { | ||
export default function or<T extends MaybeTruth[]>(...params: [...T]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same issue here as in |
||
for (let i = 0, len = params.length; i < len; i++) { | ||
if (truthConvert(params[i]) === true) { | ||
return params[i] as boolean; | ||
return params[i] as FirstNonFalsy<T>; | ||
} | ||
} | ||
return params[params.length - 1] as boolean; | ||
}); | ||
return params[params.length - 1] as Last<T>; | ||
} | ||
|
||
type FirstNonFalsy<T extends any[]> = T extends [infer K] | ||
? K | ||
: T extends [infer A, ...infer R] | ||
? Truthy<A> extends true | ||
? A | ||
: FirstNonFalsy<R> | ||
: never; | ||
|
||
type Last<T extends any[]> = T extends [infer K] | ||
? K | ||
: T extends [...infer Q, infer L] | ||
? L | ||
: never; | ||
|
||
type Truthy<T> = T extends Falsy ? false : true; | ||
|
||
type Falsy = false | 0 | '' | null | undefined | { isTruthy: false } | []; |
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.
this is fixed