Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import ScopeStack from './scope-stack.js';
import { GlintEmitMetadata, GlintSpecialForm } from '@glint/core/config-types';
import { TextContent } from './glimmer-ast-mapping-tree.js';
import { Directive } from './transformed-module.js';

Check warning on line 7 in packages/core/src/transform/template/template-to-typescript.ts

View workflow job for this annotation

GitHub Actions / Lint

'Directive' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 7 in packages/core/src/transform/template/template-to-typescript.ts

View workflow job for this annotation

GitHub Actions / Lint

'Directive' is defined but never used. Allowed unused vars must match /^_/u
import { DirectiveKind } from './transformed-module.js';

const SPLATTRIBUTES = '...attributes';
Expand Down Expand Up @@ -574,10 +574,10 @@
function treatAsGlobal(name: string): boolean {
if (globals) {
// If we have a known set of global identifiers, we should only treat
// members of that set as global and assume everything else is local.
// This is typically true in environments that capture scope, like
// strict-mode Ember.
return globals.includes(name);
// members of that set as global, unless the identifier is in scope,
// and assume everything else is local. This is typically true in
// environments that capture scope, like strict-mode Ember.
return globals.includes(name) && !scope.hasBinding(name);
} else {
// Otherwise, we assume everything is global unless we can see it
// in scope as a block variable. This is the case in resolver-based
Expand Down Expand Up @@ -926,7 +926,7 @@

function emitPlainAttributes(
node: AST.ElementNode,
directivesWeakMap: WeakMap<AST.Node, DirectiveKind>,

Check warning on line 929 in packages/core/src/transform/template/template-to-typescript.ts

View workflow job for this annotation

GitHub Actions / Lint

'directivesWeakMap' is defined but never used

Check warning on line 929 in packages/core/src/transform/template/template-to-typescript.ts

View workflow job for this annotation

GitHub Actions / Lint

'directivesWeakMap' is defined but never used
): void {
let attributes = node.attributes.filter(
(attr) => !attr.name.startsWith('@') && attr.name !== SPLATTRIBUTES,
Expand Down Expand Up @@ -994,7 +994,7 @@

function emitModifiers(
node: AST.ElementNode,
directivesWeakMap: WeakMap<AST.Node, DirectiveKind>,

Check warning on line 997 in packages/core/src/transform/template/template-to-typescript.ts

View workflow job for this annotation

GitHub Actions / Lint

'directivesWeakMap' is defined but never used

Check warning on line 997 in packages/core/src/transform/template/template-to-typescript.ts

View workflow job for this annotation

GitHub Actions / Lint

'directivesWeakMap' is defined but never used
): void {
for (let modifier of node.modifiers) {
mapper.forNode(modifier, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1491,4 +1491,26 @@ describe('Transform: rewriteTemplate', () => {
]);
});
});

describe('global variables', () => {
test('uses vaariable in scope over global variable', () => {
let template = `
{{action "action"}}
{{#each actions as |action|}}
{{action}}
{{/each}}`;

expect(templateBody(template, { globals: ['action'] })).toMatchInlineSnapshot(`
"__glintDSL__.emitContent(__glintDSL__.resolve(__glintDSL__.Globals["action"])("action"));
{
const __glintY__ = __glintDSL__.emitComponent(__glintDSL__.resolve(each)(actions));
{
const [action] = __glintY__.blockParams["default"];
__glintDSL__.emitContent(__glintDSL__.resolveOrReturn(action)());
}
each;
}"
`);
});
});
});
Loading