-
-
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.
Merge pull request #20410 from NullVoxPopuli/add-ember-template-compi…
…lation [BUGFIX types] Add missing type declarations in the preview types for @ember/template-compilation
- Loading branch information
Showing
5 changed files
with
70 additions
and
5 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { precompileTemplate } from '@ember/template-compilation'; | ||
import { setComponentTemplate } from '@ember/component'; | ||
import templateOnly from '@ember/component/template-only'; | ||
|
||
import { expectTypeOf } from 'expect-type'; | ||
|
||
// Valid usages | ||
precompileTemplate(`Hello World`, { moduleName: 'foo' }); | ||
precompileTemplate(`Hello World`, { moduleName: 'foo', strictMode: false }); | ||
precompileTemplate(`Hello World`, { strictMode: false }); | ||
precompileTemplate(`Hello World`, { strictMode: true, scope: () => ({}) }); | ||
precompileTemplate(`Hello World`, { strictMode: true, scope: () => ({ setComponentTemplate }) }); | ||
precompileTemplate(`Hello World`, { strictMode: true, moduleName: 'hello', scope: () => ({}) }); | ||
|
||
// Integration, since this is the primary use case for precompileTemplate | ||
expectTypeOf(setComponentTemplate(precompileTemplate(`Hello World`), templateOnly())).toBeObject(); | ||
|
||
// @ts-expect-error scope is required when strictMode is true | ||
precompileTemplate(`Hello World`, { strictMode: true }); | ||
|
||
// @ts-expect-error scope must be a function | ||
precompileTemplate(`Hello World`, { strictMode: true, scope: {} }); | ||
|
||
// @ts-expect-error scope must return an object | ||
precompileTemplate(`Hello World`, { strictMode: true, scope: () => {} }); | ||
|
||
// @ts-expect-error scope must return an object and arrays are not the kind of object we want | ||
precompileTemplate(`Hello World`, { strictMode: true, scope: () => [] }); | ||
|
||
// @ts-expect-error scope has no purpose when strictMode is false | ||
precompileTemplate(`Hello World`, { strictMode: false, scope: () => ({}) }); |
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,28 @@ | ||
/** | ||
* References: | ||
* - https://github.com/emberjs/rfcs/pull/496 | ||
* - https://github.com/emberjs/rfcs/pull/779 | ||
*/ | ||
declare module '@ember/template-compilation' { | ||
import type { TemplateFactory } from '@ember/component/-private/glimmer-interfaces'; | ||
|
||
interface MaybeModuleName { | ||
moduleName?: string; | ||
} | ||
|
||
interface LooseMode extends MaybeModuleName { | ||
strictMode?: false; | ||
} | ||
|
||
interface StrictMode extends MaybeModuleName { | ||
strictMode: true; | ||
scope: () => Record<string, unknown>; | ||
} | ||
|
||
type PrecompileTemplateOptions = LooseMode | StrictMode; | ||
|
||
export function precompileTemplate( | ||
template: string, | ||
options?: PrecompileTemplateOptions | ||
): TemplateFactory; | ||
} |
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