Skip to content
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

Fix: 'this' is undefined #18

Merged
merged 2 commits into from
Dec 29, 2023
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
1 change: 1 addition & 0 deletions src/parser/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ module.exports.convertAst = function convertAst(result, preprocessedResult, visi
* it's NOT a standard html tag, it should have a referenced variable
*/
if (
n.name !== 'this' &&
Copy link
Collaborator

@patricklx patricklx Dec 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are also ignoring this on mustache paths

!n.name.startsWith(':') &&
scope &&
(variable ||
Expand Down
49 changes: 49 additions & 0 deletions test-projects/gts/src/await.gts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { isDestroyed, isDestroying } from '@ember/destroyable';
import { waitForPromise } from '@ember/test-waiters';

import type { ComponentLike } from '@glint/template';

interface Args {
promise: Promise<ComponentLike | undefined>;
}

export class Await extends Component<Args> {
@tracked resolved?: ComponentLike;
@tracked error?: Error;

constructor(owner: unknown, args: Args) {
super(owner, args);

let promise = args.promise
.then((resolved) => {
if (isDestroying(this) || isDestroyed(this)) return;

this.resolved = resolved;
})
.catch((error) => {
if (isDestroying(this) || isDestroyed(this)) return;

this.error = error;
this.resolved = undefined;
});

waitForPromise(promise);
}

get isPending() {
return !this.resolved;
}

<template>
{{#if this.error}}
Error:
{{this.error.toString}}
{{else if this.isPending}}
Building...
{{else}}
<this.resolved />
{{/if}}
</template>
}
Loading