-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
7f24e42
Copy contents from https://github.com/jmurphyau/ember-truth-helpers/p…
NullVoxPopuli ba8ac40
and
NullVoxPopuli 5e30144
eq
NullVoxPopuli 557ff7b
gt
NullVoxPopuli 1c8ba28
gte
NullVoxPopuli 0b89b30
is-array
NullVoxPopuli 19d10cb
is-empty
NullVoxPopuli f0b46e7
is-equal
NullVoxPopuli 290f72f
lt
NullVoxPopuli e6314cf
lte
NullVoxPopuli 4b22c67
not-eq
NullVoxPopuli 245e82a
not
NullVoxPopuli 52e9a16
xor
NullVoxPopuli 9f7347f
Add polyfill to support 3.28+
NullVoxPopuli ce51051
andfix
NullVoxPopuli b21676d
We no longer need sed to fix /// referenecs
NullVoxPopuli b8e90e2
make `and` and `or` helpers class based
7b251ea
add short-circuit tests for `and` and `or` helpers
9766373
add Glint check for inferred type of `and` and `or` helpers
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
import { helper } from '@ember/component/helper'; | ||
import Helper from '@ember/component/helper'; | ||
import truthConvert from '../utils/truth-convert.ts'; | ||
import type { MaybeTruth } from '../utils/truth-convert.ts'; | ||
|
||
export interface AndSignature { | ||
interface AndSignature<T extends unknown[]> { | ||
Args: { | ||
Positional: MaybeTruth[]; | ||
Positional: T; | ||
}; | ||
Return: boolean; | ||
Return: T[number]; | ||
} | ||
|
||
export default helper<AndSignature>((params) => { | ||
for (let i = 0, len = params.length; i < len; i++) { | ||
if (truthConvert(params[i]) === false) { | ||
return params[i] as boolean; | ||
// We use class-based helper to ensure arguments are lazy-evaluated | ||
// and helper short-circuits like native JavaScript `&&` (logical AND). | ||
export default class AndHelper<T extends unknown[]> extends Helper< | ||
AndSignature<T> | ||
> { | ||
public compute(params: T): T[number] { | ||
for (let i = 0, len = params.length; i < len; i++) { | ||
if (truthConvert(params[i]) === false) { | ||
return params[i]; | ||
} | ||
} | ||
return params[params.length - 1]; | ||
} | ||
return params[params.length - 1] as boolean; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
import { helper } from '@ember/component/helper'; | ||
import truthConvert from '../utils/truth-convert.ts'; | ||
import type { MaybeTruth } from '../utils/truth-convert.ts'; | ||
import Helper from '@ember/component/helper'; | ||
|
||
export interface OrSignature { | ||
interface OrSignature<T extends unknown[]> { | ||
Args: { | ||
Positional: MaybeTruth[]; | ||
Positional: T; | ||
}; | ||
Return: boolean; | ||
Return: T[number]; | ||
} | ||
|
||
export default helper<OrSignature>((params) => { | ||
for (let i = 0, len = params.length; i < len; i++) { | ||
if (truthConvert(params[i]) === true) { | ||
return params[i] as boolean; | ||
// We use class-based helper to ensure arguments are lazy-evaluated | ||
// and helper short-circuits like native JavaScript `||` (logical OR). | ||
export default class OrHelper<T extends unknown[]> extends Helper< | ||
OrSignature<T> | ||
> { | ||
public compute(params: T): T[number] { | ||
for (let i = 0, len = params.length; i < len; i++) { | ||
if (truthConvert(params[i]) === true) { | ||
return params[i]; | ||
} | ||
} | ||
return params[params.length - 1]; | ||
} | ||
return params[params.length - 1] as boolean; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,5 @@ | ||
import { helper } from '@ember/component/helper'; | ||
import truthConvert from '../utils/truth-convert.ts'; | ||
|
||
export interface XorSignature { | ||
Args: { | ||
Positional: [unknown, unknown]; | ||
}; | ||
Return: boolean; | ||
export default function xor(left: unknown, right: unknown) { | ||
return truthConvert(left) !== truthConvert(right); | ||
} | ||
|
||
export default helper<XorSignature>((params) => { | ||
return truthConvert(params[0]) !== truthConvert(params[1]); | ||
}); |
4 changes: 4 additions & 0 deletions
4
packages/modern-test-app/app/components/and-or-type-checking.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div> | ||
{{log @andArg}} | ||
{{log @orArg}} | ||
</div> |
19 changes: 19 additions & 0 deletions
19
packages/modern-test-app/app/components/and-or-type-checking.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import templateOnly from '@ember/component/template-only'; | ||
|
||
interface Signature { | ||
Element: HTMLDivElement; | ||
Args: { | ||
andArg: object | boolean; | ||
orArg: object | boolean; | ||
}; | ||
} | ||
|
||
const AndOrTypeChecking = templateOnly<Signature>(); | ||
|
||
export default AndOrTypeChecking; | ||
|
||
declare module '@glint/environment-ember-loose/registry' { | ||
export default interface Registry { | ||
AndOrTypeChecking: typeof AndOrTypeChecking; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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