-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1dbb355
commit 03a6aa2
Showing
40 changed files
with
3,393 additions
and
74 deletions.
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
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,3 +1,5 @@ | ||
ember-this-fallback-plugin.log | ||
|
||
# compiled output | ||
/dist/ | ||
/tmp/ | ||
|
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,3 +1,5 @@ | ||
ember-this-fallback-plugin.log | ||
|
||
# unconventional js | ||
/blueprints/*/files/ | ||
/vendor/ | ||
|
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { getOwner as deprecatedGetOwner } from '@ember/application'; | ||
import type Owner from '@ember/owner'; | ||
|
||
/** | ||
* Re-export of the `getOwner` export from `@ember/application`. | ||
* This export is deprecated as of | ||
* [Ember 4.10](https://github.com/emberjs/ember.js/releases/tag/v4.10.0) | ||
* but we need to support Ember versions prior to 4.10 also. | ||
*/ | ||
export function getOwner(object: object): Owner | undefined { | ||
return deprecatedGetOwner(object); | ||
} |
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,26 @@ | ||
import Helper from '@ember/component/helper'; | ||
import { getOwner } from '../../get-owner'; | ||
import { assertExists } from '../../types/util'; | ||
|
||
type Positional = [name: string]; | ||
|
||
interface IsHelperSignature { | ||
Args: { | ||
Positional: Positional; | ||
}; | ||
Return: boolean; | ||
} | ||
|
||
export default class IsHelper extends Helper<IsHelperSignature> { | ||
compute([name]: Positional): boolean { | ||
const owner = assertExists(getOwner(this), 'Could not find owner'); | ||
return Boolean(owner.factoryFor(`helper:${name}`)); | ||
} | ||
} | ||
|
||
declare module '@glint/environment-ember-loose/registry' { | ||
export default interface Registry { | ||
/** Checks if a helper with the provided name exists. */ | ||
'this-fallback/is-helper': typeof IsHelper; | ||
} | ||
} |
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,29 @@ | ||
import Helper from '@ember/component/helper'; | ||
import { getOwner } from '../../get-owner'; | ||
import { assertExists } from '../../types/util'; | ||
|
||
type Positional = [name: string]; | ||
|
||
interface IsInvocableSignature { | ||
Args: { | ||
Positional: Positional; | ||
}; | ||
Return: boolean; | ||
} | ||
|
||
export default class IsInvocable extends Helper<IsInvocableSignature> { | ||
compute([name]: Positional): boolean { | ||
const owner = assertExists(getOwner(this), 'Could not find owner'); | ||
return ( | ||
Boolean(owner.factoryFor(`component:${name}`)) || | ||
Boolean(owner.factoryFor(`helper:${name}`)) | ||
); | ||
} | ||
} | ||
|
||
declare module '@glint/environment-ember-loose/registry' { | ||
export default interface Registry { | ||
/** Checks if a component or helper with the provided name exists. */ | ||
'this-fallback/is-invocable': typeof IsInvocable; | ||
} | ||
} |
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,34 @@ | ||
import Helper from '@ember/component/helper'; | ||
import { assert } from '@ember/debug'; | ||
import { type HelperLike } from '@glint/template'; | ||
import { getOwner } from '../../get-owner'; | ||
import { assertExists } from '../../types/util'; | ||
|
||
type Positional = [name: string]; | ||
|
||
interface LookupHelperSignature { | ||
Args: { | ||
Positional: Positional; | ||
}; | ||
Return: HelperLike; | ||
} | ||
|
||
export default class LookupHelper extends Helper<LookupHelperSignature> { | ||
compute([name]: Positional): HelperLike { | ||
const owner = assertExists(getOwner(this), 'Could not find owner'); | ||
const helper = owner.lookup(`helper:${name}`); | ||
assert(`Expected to find helper with name ${name}`, helper); | ||
return helper as HelperLike; | ||
} | ||
} | ||
|
||
declare module '@glint/environment-ember-loose/registry' { | ||
export default interface Registry { | ||
/** | ||
* Returns the helper with the provided name. Asserts it's existence. | ||
* Similar to `helper` helper, but avoids build-time errors for | ||
* this-fallback invocations. | ||
*/ | ||
'this-fallback/lookup-helper': typeof LookupHelper; | ||
} | ||
} |
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,10 @@ | ||
import { assert } from '@ember/debug'; | ||
|
||
/** Asserts that the given value is not undefined. */ | ||
export function assertExists<T>( | ||
value: T | undefined, | ||
message = 'assertExists failed' | ||
): T { | ||
assert(message, value !== undefined); | ||
return value; | ||
} |
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 @@ | ||
export { default } from 'ember-this-fallback/helpers/this-fallback/is-helper'; |
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 @@ | ||
export { default } from 'ember-this-fallback/helpers/this-fallback/is-invocable'; |
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 @@ | ||
export { default } from 'ember-this-fallback/helpers/this-fallback/lookup-helper'; |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
modulePathIgnorePatterns: ['<rootDir>/.node_modules'], | ||
}; |
This file was deleted.
Oops, something went wrong.
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,44 @@ | ||
import { type AST, type WalkerPath } from '@glimmer/syntax'; | ||
|
||
/** | ||
* Replaces the given node with the given replacement. | ||
* | ||
* @param node The child node to replace | ||
* @param path The path containing the parentNode within which we will replace | ||
* the child | ||
* @param replacement The Statement node with which to replace the child node | ||
*/ | ||
export function replaceChild<N extends AST.Statement>( | ||
node: N, | ||
path: WalkerPath<N>, | ||
replacement: AST.Statement | ||
): void { | ||
const parent = path.parentNode; | ||
if (parent) { | ||
const parentChildren = getChildren(parent); | ||
const index = parentChildren.indexOf(node); | ||
if (index === -1) { | ||
throw new Error('could not find given node in parent children'); | ||
} | ||
parentChildren.splice(index, 1, replacement); | ||
} else { | ||
throw new Error('expected node to have a parent node'); | ||
} | ||
} | ||
|
||
function getChildren(node: AST.Node): AST.Statement[] { | ||
switch (node.type) { | ||
case 'Block': | ||
case 'Template': { | ||
return node.body; | ||
} | ||
case 'ElementNode': { | ||
return node.children; | ||
} | ||
default: { | ||
throw new Error( | ||
`could not find children for node with type ${node.type}` | ||
); | ||
} | ||
} | ||
} |
Oops, something went wrong.