Skip to content

Commit

Permalink
Merge pull request #74 from typed-ember/privatize
Browse files Browse the repository at this point in the history
  • Loading branch information
dfreeman authored Mar 19, 2021
2 parents 26ea3a5 + 9915d50 commit c3e3c24
Show file tree
Hide file tree
Showing 108 changed files with 498 additions and 512 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export default class Greeting extends Component<GreetingSignature> {

Because Ember's template resolution occurs dynamically at runtime today, Glint needs a way of mapping the names used in your templates to the actual backing value they'll be resolved to. This takes the form of a "type registry" similar to the one that powers Ember Data's types.

The recommended approach is to include a declaration in each component, modifier or helper module that adds it to the registry, which is the default export of `@glint/environment-ember-loose/types/registry`.
The recommended approach is to include a declaration in each component, modifier or helper module that adds it to the registry, which is the default export of `@glint/environment-ember-loose/registry`.

```ts
// app/components/greeting.ts
Expand All @@ -228,7 +228,7 @@ export default class Greeting extends Component {
// ...
}

declare module '@glint/environment-ember-loose/types/registry' {
declare module '@glint/environment-ember-loose/registry' {
export default interface Registry {
Greeting: typeof Greeting;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/config/__tests__/environment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('Environments', () => {

test('getting specified template tag config', () => {
let tags = {
'@glimmerx/component': { hbs: { typesSource: '@glint/environment-glimmerx/types' } },
'@glimmerx/component': { hbs: { typesSource: '@glint/environment-glimmerx/-private/dsl' } },
};

let env = new GlintEnvironment('test-env', { tags });
Expand Down
2 changes: 1 addition & 1 deletion packages/core/__tests__/cli/declaration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('CLI: emitting declarations', () => {
Args: ApplicationArgs;
}> {
private startupTime;
static template: import(\\"@glint/environment-glimmerx/types\\").Template;
static template: void;
}
"
`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import * as VM from '@glint/template/-private/keywords';

import { ActionKeyword } from './intrinsics/action';
import { ComponentKeyword } from './intrinsics/component';
import { ConcatHelper } from './intrinsics/concat';
import { EachInKeyword } from './intrinsics/each-in';
import { FnHelper } from './intrinsics/fn';
import { GetHelper } from './intrinsics/get';
import { InputComponent } from './intrinsics/input';
import { LinkToKeyword, LinkToComponent } from './intrinsics/link-to';
import { LogHelper } from './intrinsics/log';
import { MountKeyword } from './intrinsics/mount';
import { MutKeyword } from './intrinsics/mut';
import { OnModifier } from './intrinsics/on';
import { OutletKeyword } from './intrinsics/outlet';
import { TextareaComponent } from './intrinsics/textarea';
import { UnboundKeyword } from './intrinsics/unbound';

import Registry from './registry';
import { ActionKeyword } from '../intrinsics/action';
import { ComponentKeyword } from '../intrinsics/component';
import { ConcatHelper } from '../intrinsics/concat';
import { EachInKeyword } from '../intrinsics/each-in';
import { FnHelper } from '../intrinsics/fn';
import { GetHelper } from '../intrinsics/get';
import { InputComponent } from '../intrinsics/input';
import { LinkToKeyword, LinkToComponent } from '../intrinsics/link-to';
import { LogHelper } from '../intrinsics/log';
import { MountKeyword } from '../intrinsics/mount';
import { MutKeyword } from '../intrinsics/mut';
import { OnModifier } from '../intrinsics/on';
import { OutletKeyword } from '../intrinsics/outlet';
import { TextareaComponent } from '../intrinsics/textarea';
import { UnboundKeyword } from '../intrinsics/unbound';

import Registry from '../../registry';

// The keyword vs global breakdown here is loosely matched with
// the listing in http://emberjs.github.io/rfcs/0496-handlebars-strict-mode.html
Expand Down
2 changes: 2 additions & 0 deletions packages/environment-ember-loose/-private/dsl/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from '@glint/template/-private/dsl';
export { Globals } from './globals';
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { GlintEnvironmentConfig } from '@glint/config';
export default function glimmerxEnvironment(): GlintEnvironmentConfig {
return {
template: {
typesPath: '@glint/environment-ember-loose/types',
typesPath: '@glint/environment-ember-loose/-private/dsl',

getPossibleScriptPaths(templatePath) {
if (/[\\/]template\.hbs$/.test(templatePath)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DirectInvokable } from '@glint/template/-private/resolution';
import { DirectInvokable } from '@glint/template/-private/integration';

export type ActionNamedArgs<T> = {
value?: keyof T;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { AcceptsBlocks, AnyBlocks, EmptyObject } from '@glint/template/-private/signature';
import { DirectInvokable, Invokable } from '@glint/template/-private/resolution';
import {
AcceptsBlocks,
AnyBlocks,
EmptyObject,
DirectInvokable,
Invokable,
} from '@glint/template/-private/integration';

type RegistryComponentArgs<Registry, T extends keyof Registry> = Registry[T] extends new (
...args: any
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { DirectInvokable, EmptyObject } from '@glint/template/-private/integration';

export type ConcatHelper = DirectInvokable<{
(args: EmptyObject, ...params: unknown[]): string;
}>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { AcceptsBlocks, DirectInvokable, EmptyObject } from '@glint/template/-private/integration';

export type EachInKeyword = DirectInvokable<{
<T>(args: EmptyObject, object: T): AcceptsBlocks<{
default: [key: keyof T, value: T[keyof T]];
}>;
}>;
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { DirectInvokable } from '@glint/template/-private/resolution';
import { EmptyObject } from '@glint/template/-private/signature';
import { DirectInvokable, EmptyObject } from '@glint/template/-private/integration';
import { Mut } from './mut';

export type FnHelper = DirectInvokable<{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { DirectInvokable } from '@glint/template/-private/resolution';
import { EmptyObject } from '@glint/template/-private/signature';
import { DirectInvokable, EmptyObject } from '@glint/template/-private/integration';

export type GetHelper = DirectInvokable<{
<T, K extends keyof T>(args: EmptyObject, obj: T, key: K): T[K];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { AcceptsBlocks } from '@glint/template/-private';
import { DirectInvokable } from '@glint/template/-private/resolution';
import { EmptyObject } from '@glint/template/-private/signature';
import { AcceptsBlocks, DirectInvokable, EmptyObject } from '@glint/template/-private/integration';

export interface CheckboxInputArgs {
type: 'checkbox';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { AcceptsBlocks, NoNamedArgs } from '@glint/template/-private';
import { DirectInvokable } from '@glint/template/-private/resolution';
import { AcceptsBlocks, DirectInvokable, EmptyObject } from '@glint/template/-private/integration';

export type LinkToKeyword = DirectInvokable<{
(args: NoNamedArgs, route: string, ...params: unknown[]): AcceptsBlocks<{
(args: EmptyObject, route: string, ...params: unknown[]): AcceptsBlocks<{
default?: [];
}>;
}>;
Expand Down
5 changes: 5 additions & 0 deletions packages/environment-ember-loose/-private/intrinsics/log.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { DirectInvokable, EmptyObject } from '@glint/template/-private/integration';

export type LogHelper = DirectInvokable<{
(args: EmptyObject, ...params: unknown[]): void;
}>;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DirectInvokable } from '@glint/template/-private/resolution';
import { DirectInvokable } from '@glint/template/-private/integration';

export type MountKeyword = DirectInvokable<{
(args: { model?: unknown }, engine: string): void;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { DirectInvokable } from '@glint/template/-private/resolution';
import { EmptyObject } from '@glint/template/-private/signature';
import { DirectInvokable, EmptyObject } from '@glint/template/-private/integration';

declare const Mut: unique symbol;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { CreatesModifier } from '@glint/template/-private';
import { DirectInvokable } from '@glint/template/-private/resolution';
import { BoundModifier, DirectInvokable } from '@glint/template/-private/integration';

export interface OnModifierArgs {
capture?: boolean;
Expand All @@ -12,10 +11,10 @@ export type OnModifier = DirectInvokable<{
args: OnModifierArgs,
name: Name,
callback: (event: HTMLElementEventMap[Name]) => void
): CreatesModifier<HTMLElement>;
): BoundModifier<HTMLElement>;
(
args: OnModifierArgs,
name: string,
callback: (event: Event) => void
): CreatesModifier<HTMLElement>;
): BoundModifier<HTMLElement>;
}>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { DirectInvokable, EmptyObject } from '@glint/template/-private/integration';

export type OutletKeyword = DirectInvokable<{
(args: EmptyObject, name?: string): void;
}>;
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { AcceptsBlocks } from '@glint/template/-private';
import { DirectInvokable } from '@glint/template/-private/resolution';
import { EmptyObject } from '@glint/template/-private/signature';
import { AcceptsBlocks, DirectInvokable, EmptyObject } from '@glint/template/-private/integration';

export interface TextareaArgs {
value?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { DirectInvokable, EmptyObject } from '@glint/template/-private/integration';

export type UnboundKeyword = DirectInvokable<{
<T>(args: EmptyObject, value: T): T;
}>;
4 changes: 3 additions & 1 deletion packages/environment-ember-loose/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
*.d.ts
tsconfig.tsbuildinfo

!types/**/*.d.ts
!registry/**/*.d.ts
!-private/dsl/**/*.d.ts
!-private/intrinsics/**/*.d.ts
8 changes: 6 additions & 2 deletions packages/environment-ember-loose/.prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
/*/*.js
/*/*.d.ts
/**/*.js
/**/*.d.ts

!/registry/**/*.d.ts
!/-private/dsl/**/*.d.ts
!/-private/intrinsics/**/*.d.ts
4 changes: 2 additions & 2 deletions packages/environment-ember-loose/__tests__/component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
resolve,
ResolveContext,
yieldToBlock,
} from '@glint/environment-ember-loose/types';
import { EmptyObject } from '@glint/template/-private/signature';
} from '@glint/environment-ember-loose/-private/dsl';
import { EmptyObject } from '@glint/template/-private/integration';
import { expectTypeOf } from 'expect-type';

{
Expand Down
6 changes: 3 additions & 3 deletions packages/environment-ember-loose/__tests__/helper.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import Helper, { helper } from '@glint/environment-ember-loose/ember-component/helper';
import { resolve } from '@glint/environment-ember-loose/types';
import { resolve } from '@glint/environment-ember-loose/-private/dsl';
import { expectTypeOf } from 'expect-type';
import { NoNamedArgs } from '@glint/template/-private';
import { EmptyObject } from '@glint/template/-private/integration';

// Functional helper: positional params
{
let definition = helper(<T, U>([a, b]: [T, U]) => a || b);
let or = resolve(definition);

expectTypeOf(or).toEqualTypeOf<<T, U>(args: NoNamedArgs, t: T, u: U) => T | U>();
expectTypeOf(or).toEqualTypeOf<<T, U>(args: EmptyObject, t: T, u: U) => T | U>();

// @ts-expect-error: extra named arg
or({ hello: true }, 'a', 'b');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expectTypeOf } from 'expect-type';
import { Globals, resolve } from '@glint/environment-ember-loose/types';
import { Globals, resolve } from '@glint/environment-ember-loose/-private/dsl';

let action = resolve(Globals['action']);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expectTypeOf } from 'expect-type';
import { resolve, invokeBlock } from '@glint/template';
import { resolve, invokeBlock } from '@glint/environment-ember-loose/-private/dsl';
import Component from '@glint/environment-ember-loose/ember-component';
import { ComponentKeyword } from '../../types/intrinsics/component';
import { ComponentKeyword } from '@glint/environment-ember-loose/-private/intrinsics/component';

const componentKeyword = resolve({} as ComponentKeyword<LocalRegistry>);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expectTypeOf } from 'expect-type';
import { Globals, resolve } from '@glint/environment-ember-loose/types';
import { Globals, resolve } from '@glint/environment-ember-loose/-private/dsl';

let concat = resolve(Globals['concat']);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expectTypeOf } from 'expect-type';
import { Globals, resolve, invokeBlock } from '@glint/environment-ember-loose/types';
import { Globals, resolve, invokeBlock } from '@glint/environment-ember-loose/-private/dsl';

let eachIn = resolve(Globals['each-in']);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expectTypeOf } from 'expect-type';
import { Globals, resolve } from '@glint/environment-ember-loose/types';
import { Globals, resolve } from '@glint/environment-ember-loose/-private/dsl';

let fn = resolve(Globals['fn']);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expectTypeOf } from 'expect-type';
import { Globals, resolve } from '@glint/environment-ember-loose/types';
import { Globals, resolve } from '@glint/environment-ember-loose/-private/dsl';

let get = resolve(Globals['get']);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expectTypeOf } from 'expect-type';
import { Globals, resolve } from '@glint/environment-ember-loose/types';
import { Globals, resolve } from '@glint/environment-ember-loose/-private/dsl';

let input = resolve(Globals['input']);
let Input = resolve(Globals['Input']);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Globals, resolve, invokeBlock } from '@glint/environment-ember-loose/types';
import { Globals, resolve, invokeBlock } from '@glint/environment-ember-loose/-private/dsl';

let linkTo = resolve(Globals['link-to']);
let LinkTo = resolve(Globals['LinkTo']);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Globals, resolve } from '@glint/environment-ember-loose/types';
import { Globals, resolve } from '@glint/environment-ember-loose/-private/dsl';

let log = resolve(Globals['log']);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expectTypeOf } from 'expect-type';
import { Globals, resolve } from '@glint/environment-ember-loose/types';
import { Globals, resolve } from '@glint/environment-ember-loose/-private/dsl';

let mount = resolve(Globals['mount']);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expectTypeOf } from 'expect-type';
import { Globals, resolve } from '@glint/environment-ember-loose/types';
import { Mut } from '../../types/intrinsics/mut';
import { Globals, resolve } from '@glint/environment-ember-loose/-private/dsl';
import { Mut } from '@glint/environment-ember-loose/-private/intrinsics/mut';

let fn = resolve(Globals['fn']);
let mut = resolve(Globals['mut']);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expectTypeOf } from 'expect-type';
import { Globals, applyModifier, resolve } from '@glint/environment-ember-loose/types';
import { Globals, applyModifier, resolve } from '@glint/environment-ember-loose/-private/dsl';

const on = resolve(Globals['on']);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expectTypeOf } from 'expect-type';
import { Globals, resolve } from '@glint/environment-ember-loose/types';
import { Globals, resolve } from '@glint/environment-ember-loose/-private/dsl';

let outlet = resolve(Globals['outlet']);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expectTypeOf } from 'expect-type';
import { Globals, resolve } from '@glint/environment-ember-loose/types';
import { Globals, resolve } from '@glint/environment-ember-loose/-private/dsl';

let textarea = resolve(Globals['textarea']);
let Textarea = resolve(Globals['Textarea']);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expectTypeOf } from 'expect-type';
import { Globals, resolve } from '@glint/environment-ember-loose/types';
import { Globals, resolve } from '@glint/environment-ember-loose/-private/dsl';

let unbound = resolve(Globals['unbound']);

Expand Down
12 changes: 6 additions & 6 deletions packages/environment-ember-loose/__tests__/modifier.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Modifier, { modifier } from '@glint/environment-ember-loose/ember-modifier';
import { resolve } from '@glint/environment-ember-loose/types';
import { resolve } from '@glint/environment-ember-loose/-private/dsl';
import { expectTypeOf } from 'expect-type';
import { CreatesModifier } from '@glint/template/-private';
import { BoundModifier } from '@glint/template/-private/integration';

// Class-based modifier
{
Expand Down Expand Up @@ -39,8 +39,8 @@ import { CreatesModifier } from '@glint/template/-private';

let neat = resolve(NeatModifier);

expectTypeOf(neat({}, 'hello')).toEqualTypeOf<CreatesModifier<HTMLImageElement>>();
expectTypeOf(neat({ multiplier: 3 }, 'hello')).toEqualTypeOf<CreatesModifier<HTMLImageElement>>();
expectTypeOf(neat({}, 'hello')).toEqualTypeOf<BoundModifier<HTMLImageElement>>();
expectTypeOf(neat({ multiplier: 3 }, 'hello')).toEqualTypeOf<BoundModifier<HTMLImageElement>>();

// @ts-expect-error: missing required positional arg
neat({});
Expand Down Expand Up @@ -69,8 +69,8 @@ import { CreatesModifier } from '@glint/template/-private';

let neat = resolve(definition);

expectTypeOf(neat({}, 'hello')).toEqualTypeOf<CreatesModifier<HTMLAudioElement>>();
expectTypeOf(neat({ multiplier: 3 }, 'hello')).toEqualTypeOf<CreatesModifier<HTMLAudioElement>>();
expectTypeOf(neat({}, 'hello')).toEqualTypeOf<BoundModifier<HTMLAudioElement>>();
expectTypeOf(neat({ multiplier: 3 }, 'hello')).toEqualTypeOf<BoundModifier<HTMLAudioElement>>();

// @ts-expect-error: missing required positional arg
neat({});
Expand Down
Loading

0 comments on commit c3e3c24

Please sign in to comment.