Skip to content

Commit 0f1eb6d

Browse files
committed
Assume we're trying to match a static in-scope identifier if available
1 parent bbff1ec commit 0f1eb6d

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

packages/core/__tests__/language-server/completions.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,7 @@ describe('Language Server: Completions', () => {
170170
});
171171
});
172172

173-
// Currently this test and the 'globals' one above can't both pass at the same time,
174-
// because if we see an unknown identifier we have to choose whether to emit it as
175-
// `partialIden` or `Globals['partialIden']`, and we can't get completions for both
176-
// free-floating identifiers and keys on `Globals`.
177-
test.skip('referencing module-scope identifiers', async () => {
173+
test('referencing module-scope identifiers', async () => {
178174
let code = stripIndent`
179175
import Component, { hbs } from '@glint/environment-glimmerx/component';
180176

packages/transform/src/scope-stack.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ export default class ScopeStack {
2828
return this.top.has(identifier);
2929
}
3030

31+
public hasMatchingBinding(prefix: string): boolean {
32+
if (this.hasBinding(prefix)) {
33+
return true;
34+
}
35+
36+
for (let identifier of this.top) {
37+
if (identifier.startsWith(prefix)) {
38+
return true;
39+
}
40+
}
41+
42+
return false;
43+
}
44+
3145
private get top(): Set<string> {
3246
return this.stack[0];
3347
}

packages/transform/src/template-to-typescript.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ export function templateToTypescript(
278278
}
279279

280280
function emitIdentifierReference(name: string, hbsOffset: number, hbsLength?: number): void {
281-
if (scope.hasBinding(name)) {
281+
if (scope.hasMatchingBinding(name)) {
282282
emit.identifier(name, hbsOffset, hbsLength);
283283
} else {
284284
emit.text('χ.Globals["');

0 commit comments

Comments
 (0)