Skip to content

Upgrade to TS 4.3 and play nicely with new flags #206

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

Merged
merged 6 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"release-it": "^14.4.1",
"release-it-lerna-changelog": "^3.1.0",
"release-it-yarn-workspaces": "^2.0.0",
"typescript": "^4.1.5"
"typescript": "^4.3.5"
},
"version": "0.5.1"
}
14 changes: 7 additions & 7 deletions packages/config/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,21 @@ export function normalizePath(fileName: string): string {

function validateConfigInput(input: Record<string, unknown>): asserts input is GlintConfigInput {
assert(
typeof input.environment === 'string',
typeof input['environment'] === 'string',
'Glint config must specify an `environment` string'
);

assert(
Array.isArray(input.include)
? input.include.every((item) => typeof item === 'string')
: !input.include || typeof input.include === 'string',
Array.isArray(input['include'])
? input['include'].every((item) => typeof item === 'string')
: !input['include'] || typeof input['include'] === 'string',
'If defined, `include` must be a string or array of strings'
);

assert(
Array.isArray(input.exclude)
? input.exclude.every((item) => typeof item === 'string')
: !input.exclude || typeof input.exclude === 'string',
Array.isArray(input['exclude'])
? input['exclude'].every((item) => typeof item === 'string')
: !input['exclude'] || typeof input['exclude'] === 'string',
'If defined, `exclude` must be a string or array of strings'
);
}
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 @@ -117,7 +117,7 @@ describe('CLI: emitting declarations', () => {
}
export default class ClassComponent extends Component<ClassComponentSignature> {
private startupTime;
protected static '~template': unknown;
protected static '~template:ClassComponent': unknown;
}
"
`);
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/common/transform-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,10 @@ export default class TransformManager {
});
}

private rewriteDiagnostic(
diagnostic: Diagnostic
): { rewrittenDiagnostic?: ts.Diagnostic; appliedDirective?: Directive } {
private rewriteDiagnostic(diagnostic: Diagnostic): {
rewrittenDiagnostic?: ts.Diagnostic;
appliedDirective?: Directive;
} {
if (!diagnostic.file) return {};

// Transform diagnostics are already targeted at the original source and so
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ expectTypeOf(Helper.extend).toEqualTypeOf(UpstreamEmberHelper.extend);
{
type RepeatArgs<T> = { value: T; count?: number };
class RepeatHelper<T> extends Helper<{ NamedArgs: RepeatArgs<T>; Return: Array<T> }> {
compute(_: [], { value, count }: RepeatArgs<T>): Array<T> {
override compute(_: [], { value, count }: RepeatArgs<T>): Array<T> {
return Array.from({ length: count ?? 2 }, () => value);
}
}
Expand Down Expand Up @@ -93,7 +93,7 @@ expectTypeOf(Helper.extend).toEqualTypeOf(UpstreamEmberHelper.extend);
{
type RepeatArgs<T> = [value: T, count?: number | undefined];
class RepeatHelper<T> extends Helper<{ PositionalArgs: RepeatArgs<T>; Return: Array<T> }> {
compute([value, count]: RepeatArgs<T>): Array<T> {
override compute([value, count]: RepeatArgs<T>): Array<T> {
return Array.from({ length: count ?? 2 }, () => value);
}
}
Expand Down Expand Up @@ -128,7 +128,7 @@ expectTypeOf(Helper.extend).toEqualTypeOf(UpstreamEmberHelper.extend);
// Class-based helpers can return undefined
{
class MaybeStringHelper extends Helper<{ Return: string | undefined }> {
compute(): string | undefined {
override compute(): string | undefined {
if (Math.random() > 0.5) {
return 'ok';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { EmptyObject } from '@glint/template/-private/integration';
import { ResolveContext } from '../../-private/dsl';

class TestRoute extends Route {
async model(): Promise<{ message: string }> {
override async model(): Promise<{ message: string }> {
return { message: 'hello' };
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ import { BoundModifier } from '@glint/template/-private/integration';
return this.args.named.multiplier;
}

didReceiveArguments(): void {
override didReceiveArguments(): void {
expectTypeOf(this.element).toEqualTypeOf<HTMLImageElement>();

this.interval = window.setInterval(() => {
alert('this is a typesafe modifier!');
}, this.multiplier * this.lengthOfInput);
}

willDestroy(): void {
override willDestroy(): void {
window.clearInterval(this.interval);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/environment-ember-loose/ember-component/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type HelperFactory = <Positional extends unknown[] = [], Named = EmptyObject, Re
fn: (params: Positional, hash: Named) => Return
) => new () => Invokable<(named: Named, ...positional: Positional) => Return>;

export const helper = (emberHelper as unknown) as HelperFactory;
export const helper = emberHelper as unknown as HelperFactory;

export interface HelperSignature {
NamedArgs?: object;
Expand Down
4 changes: 2 additions & 2 deletions packages/environment-glimmerx/helper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ type FnHelper = DirectInvokable<{
): (...rest: Args) => Ret;
}>;

export const fn = (glimmerxHelper.fn as unknown) as FnHelper;
export const helper = (glimmerxHelper.helper as unknown) as HelperFactory;
export const fn = glimmerxHelper.fn as unknown as FnHelper;
export const helper = glimmerxHelper.helper as unknown as HelperFactory;
2 changes: 1 addition & 1 deletion packages/environment-glimmerx/modifier/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ type OnModifier = DirectInvokable<
) => BoundModifier<HTMLElement>
>;

export const on = (glimmerxModifier.on as unknown) as OnModifier;
export const on = glimmerxModifier.on as unknown as OnModifier;
2 changes: 1 addition & 1 deletion packages/template/__tests__/emit-component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ emitComponent(resolveOrReturn(MaybeMyComponent)({ value: 'hi' }));

// @ts-expect-error: unknown is an invalid component
let unknownComponent = emitComponent({} as unknown);
let [unknownComponentParam] = unknownComponent.blockParams.default;
let [unknownComponentParam] = unknownComponent.blockParams['default'];

expectTypeOf(unknownComponent.element).toBeAny();
expectTypeOf(unknownComponentParam).toBeAny();
Expand Down
4 changes: 1 addition & 3 deletions packages/template/__tests__/resolution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ declare function value<T>(): T;
});
}

type ExpectedSignature = <T>(
args: MyArgs<T>
) => AcceptsBlocks<{
type ExpectedSignature = <T>(args: MyArgs<T>) => AcceptsBlocks<{
body: [boolean, T];
}>;

Expand Down
50 changes: 25 additions & 25 deletions packages/transform/__tests__/debug.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,112 +35,112 @@ describe('Debug utilities', () => {

| Mapping: Template
| hbs(0:123): {{#each (array \\"world\\" \\"planet\\" \\"universe\\") as |target index|}}\\\\n #{{add index 1}}: {{this.message}}, {{target}}!\\\\n{{/each}}
| ts(183:813): ({} as typeof import(\\"@glint/environment-ember-loose/-private/dsl\\")).template(function(𝚪: import(\\"@glint/environment-ember-loose/-private/dsl\\").ResolveContext<MyComponent>, χ: typeof import(\\"@glint/environment-ember-loose/-private/dsl\\")) {\\\\n {\\\\n const 𝛄 = χ.emitComponent(χ.resolve(χ.Globals[\\"each\\"])({}, [\\"world\\", \\"planet\\", \\"universe\\"]));\\\\n {\\\\n const [target, index] = 𝛄.blockParams.default;\\\\n χ.emitValue(χ.resolve(χ.Globals[\\"add\\"])({}, index, 1));\\\\n χ.emitValue(χ.resolveOrReturn(𝚪.this.message)({}));\\\\n χ.emitValue(χ.resolveOrReturn(target)({}));\\\\n }\\\\n χ.Globals[\\"each\\"];\\\\n }\\\\n 𝚪; χ;\\\\n}) as unknown
| ts(195:828): ({} as typeof import(\\"@glint/environment-ember-loose/-private/dsl\\")).template(function(𝚪: import(\\"@glint/environment-ember-loose/-private/dsl\\").ResolveContext<MyComponent>, χ: typeof import(\\"@glint/environment-ember-loose/-private/dsl\\")) {\\\\n {\\\\n const 𝛄 = χ.emitComponent(χ.resolve(χ.Globals[\\"each\\"])({}, [\\"world\\", \\"planet\\", \\"universe\\"]));\\\\n {\\\\n const [target, index] = 𝛄.blockParams[\\"default\\"];\\\\n χ.emitValue(χ.resolve(χ.Globals[\\"add\\"])({}, index, 1));\\\\n χ.emitValue(χ.resolveOrReturn(𝚪.this.message)({}));\\\\n χ.emitValue(χ.resolveOrReturn(target)({}));\\\\n }\\\\n χ.Globals[\\"each\\"];\\\\n }\\\\n 𝚪; χ;\\\\n}) as unknown
|
| | Mapping: Identifier
| | hbs(0:0):
| | ts(343:354): MyComponent
| | ts(355:366): MyComponent
| |
| | Mapping: BlockStatement
| | hbs(0:123): {{#each (array \\"world\\" \\"planet\\" \\"universe\\") as |target index|}}\\\\n #{{add index 1}}: {{this.message}}, {{target}}!\\\\n{{/each}}
| | ts(424:790): {\\\\n const 𝛄 = χ.emitComponent(χ.resolve(χ.Globals[\\"each\\"])({}, [\\"world\\", \\"planet\\", \\"universe\\"]));\\\\n {\\\\n const [target, index] = 𝛄.blockParams.default;\\\\n χ.emitValue(χ.resolve(χ.Globals[\\"add\\"])({}, index, 1));\\\\n χ.emitValue(χ.resolveOrReturn(𝚪.this.message)({}));\\\\n χ.emitValue(χ.resolveOrReturn(target)({}));\\\\n }\\\\n χ.Globals[\\"each\\"];\\\\n }
| | ts(436:805): {\\\\n const 𝛄 = χ.emitComponent(χ.resolve(χ.Globals[\\"each\\"])({}, [\\"world\\", \\"planet\\", \\"universe\\"]));\\\\n {\\\\n const [target, index] = 𝛄.blockParams[\\"default\\"];\\\\n χ.emitValue(χ.resolve(χ.Globals[\\"add\\"])({}, index, 1));\\\\n χ.emitValue(χ.resolveOrReturn(𝚪.this.message)({}));\\\\n χ.emitValue(χ.resolveOrReturn(target)({}));\\\\n }\\\\n χ.Globals[\\"each\\"];\\\\n }
| |
| | | Mapping: PathExpression
| | | hbs(3:7): each
| | | ts(469:486): χ.Globals[\\"each\\"]
| | | ts(481:498): χ.Globals[\\"each\\"]
| | |
| | | | Mapping: Identifier
| | | | hbs(3:7): each
| | | | ts(480:484): each
| | | | ts(492:496): each
| | | |
| | |
| | | Mapping: SubExpression
| | | hbs(8:43): (array \\"world\\" \\"planet\\" \\"universe\\")
| | | ts(492:523): [\\"world\\", \\"planet\\", \\"universe\\"]
| | | ts(504:535): [\\"world\\", \\"planet\\", \\"universe\\"]
| | |
| | | | Mapping: StringLiteral
| | | | hbs(15:22): \\"world\\"
| | | | ts(493:500): \\"world\\"
| | | | ts(505:512): \\"world\\"
| | | |
| | | | Mapping: StringLiteral
| | | | hbs(23:31): \\"planet\\"
| | | | ts(502:510): \\"planet\\"
| | | | ts(514:522): \\"planet\\"
| | | |
| | | | Mapping: StringLiteral
| | | | hbs(32:42): \\"universe\\"
| | | | ts(512:522): \\"universe\\"
| | | | ts(524:534): \\"universe\\"
| | | |
| | |
| | | Mapping: Identifier
| | | hbs(48:54): target
| | | ts(546:552): target
| | | ts(558:564): target
| | |
| | | Mapping: Identifier
| | | hbs(55:60): index
| | | ts(554:559): index
| | | ts(566:571): index
| | |
| | | Mapping: MustacheStatement
| | | hbs(67:82): {{add index 1}}
| | | ts(587:647): χ.emitValue(χ.resolve(χ.Globals[\\"add\\"])({}, index, 1))
| | | ts(602:662): χ.emitValue(χ.resolve(χ.Globals[\\"add\\"])({}, index, 1))
| | |
| | | | Mapping: PathExpression
| | | | hbs(69:72): add
| | | | ts(615:631): χ.Globals[\\"add\\"]
| | | | ts(630:646): χ.Globals[\\"add\\"]
| | | |
| | | | | Mapping: Identifier
| | | | | hbs(69:72): add
| | | | | ts(626:629): add
| | | | | ts(641:644): add
| | | | |
| | | |
| | | | Mapping: PathExpression
| | | | hbs(73:78): index
| | | | ts(637:642): index
| | | | ts(652:657): index
| | | |
| | | | | Mapping: Identifier
| | | | | hbs(73:78): index
| | | | | ts(637:642): index
| | | | | ts(652:657): index
| | | | |
| | | |
| | | | Mapping: NumberLiteral
| | | | hbs(79:80): 1
| | | | ts(644:645): 1
| | | | ts(659:660): 1
| | | |
| | |
| | | Mapping: MustacheStatement
| | | hbs(84:100): {{this.message}}
| | | ts(649:706): χ.emitValue(χ.resolveOrReturn(𝚪.this.message)({}))
| | | ts(664:721): χ.emitValue(χ.resolveOrReturn(𝚪.this.message)({}))
| | |
| | | | Mapping: PathExpression
| | | | hbs(86:98): this.message
| | | | ts(685:700): 𝚪.this.message
| | | | ts(700:715): 𝚪.this.message
| | | |
| | | | | Mapping: Identifier
| | | | | hbs(86:90): this
| | | | | ts(688:692): this
| | | | | ts(703:707): this
| | | | |
| | | | | Mapping: Identifier
| | | | | hbs(91:98): message
| | | | | ts(693:700): message
| | | | | ts(708:715): message
| | | | |
| | | |
| | |
| | | Mapping: MustacheStatement
| | | hbs(102:112): {{target}}
| | | ts(708:756): χ.emitValue(χ.resolveOrReturn(target)({}))
| | | ts(723:771): χ.emitValue(χ.resolveOrReturn(target)({}))
| | |
| | | | Mapping: PathExpression
| | | | hbs(104:110): target
| | | | ts(744:750): target
| | | | ts(759:765): target
| | | |
| | | | | Mapping: Identifier
| | | | | hbs(104:110): target
| | | | | ts(744:750): target
| | | | | ts(759:765): target
| | | | |
| | | |
| | |
| | | Mapping: Identifier
| | | hbs(117:121): each
| | | ts(779:783): each
| | | ts(794:798): each
| | |
| |
|"
Expand Down
10 changes: 5 additions & 5 deletions packages/transform/__tests__/rewrite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ describe('rewriteModule', () => {
expect(transformedModule?.transformedContents).toMatchInlineSnapshot(`
"import Component from '@glimmer/component';
export default class MyComponent extends Component {
protected static '~template' = ({} as typeof import(\\"@glint/environment-ember-loose/-private/dsl\\")).template(function(𝚪: import(\\"@glint/environment-ember-loose/-private/dsl\\").ResolveContext<MyComponent>, χ: typeof import(\\"@glint/environment-ember-loose/-private/dsl\\")) {
protected static '~template:MyComponent' = ({} as typeof import(\\"@glint/environment-ember-loose/-private/dsl\\")).template(function(𝚪: import(\\"@glint/environment-ember-loose/-private/dsl\\").ResolveContext<MyComponent>, χ: typeof import(\\"@glint/environment-ember-loose/-private/dsl\\")) {
𝚪; χ;
}) as unknown;
}"
Expand Down Expand Up @@ -210,7 +210,7 @@ describe('rewriteModule', () => {
expect(transformedModule?.transformedContents).toMatchInlineSnapshot(`
"import Component from '@glimmer/component';
class MyComponent extends Component {
protected static '~template' = ({} as typeof import(\\"@glint/environment-ember-loose/-private/dsl\\")).template(function(𝚪: import(\\"@glint/environment-ember-loose/-private/dsl\\").ResolveContext<MyComponent>, χ: typeof import(\\"@glint/environment-ember-loose/-private/dsl\\")) {
protected static '~template:MyComponent' = ({} as typeof import(\\"@glint/environment-ember-loose/-private/dsl\\")).template(function(𝚪: import(\\"@glint/environment-ember-loose/-private/dsl\\").ResolveContext<MyComponent>, χ: typeof import(\\"@glint/environment-ember-loose/-private/dsl\\")) {
𝚪; χ;
}) as unknown;
}
Expand Down Expand Up @@ -239,7 +239,7 @@ describe('rewriteModule', () => {
expect(transformedModule?.transformedContents).toMatchInlineSnapshot(`
"import Component from '@glimmer/component';
export default class MyComponent<K extends string> extends Component<{ value: K }> {
protected static '~template' = ({} as typeof import(\\"@glint/environment-ember-loose/-private/dsl\\")).template(function<K extends string>(𝚪: import(\\"@glint/environment-ember-loose/-private/dsl\\").ResolveContext<MyComponent<K>>, χ: typeof import(\\"@glint/environment-ember-loose/-private/dsl\\")) {
protected static '~template:MyComponent' = ({} as typeof import(\\"@glint/environment-ember-loose/-private/dsl\\")).template(function<K extends string>(𝚪: import(\\"@glint/environment-ember-loose/-private/dsl\\").ResolveContext<MyComponent<K>>, χ: typeof import(\\"@glint/environment-ember-loose/-private/dsl\\")) {
𝚪; χ;
}) as unknown;
}"
Expand Down Expand Up @@ -277,7 +277,7 @@ describe('rewriteModule', () => {
expect(transformedModule?.transformedContents).toMatchInlineSnapshot(`
"import Component from '@glimmer/component';
export default class extends Component {
protected static '~template' = ({} as typeof import(\\"@glint/environment-ember-loose/-private/dsl\\")).template(function(𝚪, χ: typeof import(\\"@glint/environment-ember-loose/-private/dsl\\")) {
protected static '~template:undefined' = ({} as typeof import(\\"@glint/environment-ember-loose/-private/dsl\\")).template(function(𝚪, χ: typeof import(\\"@glint/environment-ember-loose/-private/dsl\\")) {
𝚪; χ;
});
}"
Expand Down Expand Up @@ -393,7 +393,7 @@ describe('rewriteModule', () => {
expect(transformedModule?.transformedContents).toMatchInlineSnapshot(`
"import Component from '@glimmer/component';
export default class MyComponent extends Component {
protected static '~template' = ({} as typeof import(\\"@glint/environment-ember-loose/-private/dsl\\")).template(function(𝚪: import(\\"@glint/environment-ember-loose/-private/dsl\\").ResolveContext<MyComponent>, χ: typeof import(\\"@glint/environment-ember-loose/-private/dsl\\")) {
protected static '~template:MyComponent' = ({} as typeof import(\\"@glint/environment-ember-loose/-private/dsl\\")).template(function(𝚪: import(\\"@glint/environment-ember-loose/-private/dsl\\").ResolveContext<MyComponent>, χ: typeof import(\\"@glint/environment-ember-loose/-private/dsl\\")) {
𝚪; χ;
}) as unknown;
}
Expand Down
Loading