-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
f5f2506
commit 077f80e
Showing
3 changed files
with
12,809 additions
and
9,782 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1 @@ | ||
import { setComponentTemplate } from '@ember/component'; | ||
import templateOnly from '@ember/component/template-only'; | ||
import { precompileTemplate } from '@ember/template-compilation'; | ||
// TODO: internalize these types and re-export from @glint/template. | ||
// @ts-expect-error these types are too useful to be external | ||
import type { ComponentLike } from '@glint/template'; | ||
|
||
interface Params<ComponentClass extends abstract new (...args: any) => any> { | ||
component?: ComponentClass; | ||
strict?: boolean; | ||
moduleName?: string; | ||
eval?: () => Record<string, unknown>; | ||
scope?: ( | ||
instance: ComponentClass extends ComponentLike<any> ? InstanceType<ComponentClass> : never | ||
) => Record<string, unknown>; | ||
} | ||
|
||
export function template<Signature>( | ||
templateContent: string, | ||
params?: Params<never> | ||
): ComponentLike<Signature>; | ||
|
||
export function template<ComponentDefinition extends ComponentLike<any>>( | ||
templateContent: string, | ||
params: Params<ComponentDefinition> | ||
): ComponentDefinition; | ||
|
||
export function template(templateContent: string, config?: Params<ComponentLike<any>>) { | ||
let strictMode = config?.strict ?? true; | ||
|
||
let compiled = precompileTemplate(templateContent, { | ||
strictMode, | ||
// TODO: this implementation needs updated, | ||
// because *this* scope doesn't pass the instance argument back. | ||
// This is needed for private variable access. | ||
// @ts-expect-error see above | ||
scope: config?.scope, | ||
}); | ||
|
||
let context = config?.component ? config.component : templateOnly(); | ||
|
||
setComponentTemplate(compiled, context); | ||
|
||
return context; | ||
} | ||
export { template } from './runtime'; |
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,48 @@ | ||
import { setComponentTemplate } from '@ember/component'; | ||
import templateOnly from '@ember/component/template-only'; | ||
import { precompile as glimmerPrecomile } from '@glimmer/compiler'; | ||
import type { ComponentLike } from '@glint/template'; | ||
import { default as compileOptions } from 'ember-template-compiler/lib/system/compile-options'; | ||
|
||
interface Params<ComponentClass extends abstract new (...args: any) => any> { | ||
component?: ComponentClass; | ||
strict?: boolean; | ||
moduleName?: string; | ||
eval?: () => Record<string, unknown>; | ||
scope?: ( | ||
instance: ComponentClass extends ComponentLike<any> ? InstanceType<ComponentClass> : never | ||
) => Record<string, unknown>; | ||
} | ||
|
||
export function template<Signature>( | ||
templateContent: string, | ||
params?: Params<never> | ||
): ComponentLike<Signature>; | ||
|
||
export function template<ComponentDefinition extends ComponentLike<any>>( | ||
templateContent: string, | ||
params: Params<ComponentDefinition> | ||
): ComponentDefinition; | ||
|
||
export function template(templateContent: string, config?: Params<ComponentLike<any>>) { | ||
let strictMode = config?.strict ?? true; | ||
|
||
let compiled = glimmerPrecomile( | ||
templateContent, | ||
// TODO: this implementation needs updated, | ||
// because *this* scope doesn't pass the instance argument back. | ||
// This is needed for private variable access. | ||
{ | ||
...compileOptions({}), | ||
strictMode, | ||
// @ts-expect-error, see above | ||
scope: config?.scope, | ||
} | ||
); | ||
|
||
let context = config?.component ? config.component : templateOnly(); | ||
|
||
setComponentTemplate(compiled, context); | ||
|
||
return context; | ||
} |
Oops, something went wrong.