Skip to content

RFC#562 - {{and}}, {{or}}, {{not}} as keywords#21310

Open
NullVoxPopuli-ai-agent wants to merge 1 commit intoemberjs:mainfrom
NullVoxPopuli-ai-agent:nvp/and-or-not-as-keyword
Open

RFC#562 - {{and}}, {{or}}, {{not}} as keywords#21310
NullVoxPopuli-ai-agent wants to merge 1 commit intoemberjs:mainfrom
NullVoxPopuli-ai-agent:nvp/and-or-not-as-keyword

Conversation

@NullVoxPopuli-ai-agent
Copy link
Copy Markdown
Contributor

@NullVoxPopuli-ai-agent NullVoxPopuli-ai-agent commented Apr 10, 2026

Summary

Implements RFC #562 — adds and, or, not as new helpers and strict-mode keywords.

  • Implements three logical helpers as plain functions in @glimmer/runtime
  • Uses toBool from @glimmer/global-context for Handlebars truthiness (empty arrays are falsy)
  • and returns the first falsy value or the right-most value if all are truthy
  • or returns the first truthy value or the right-most value if all are falsy
  • not returns the boolean negation of its argument
  • Re-exports from @ember/helper with YUIDoc and Opaque type interfaces
  • Registers as keywords in the template compiler (strict-mode only, not available in loose mode)
  • and/or throw in DEBUG mode if called with fewer than two arguments
  • not throws in DEBUG mode if called with more than one argument

New files

  • packages/@glimmer/runtime/lib/helpers/{and,or,not}.ts — helper implementations
  • packages/@glimmer-workspace/integration-tests/test/keywords/{and,or,not}-test.ts — tests with explicit scope
  • packages/@glimmer-workspace/integration-tests/test/keywords/{and,or,not}-runtime-test.ts — runtime keyword tests

Modified files

  • packages/@glimmer/runtime/index.ts — exports
  • packages/@ember/helper/index.ts — re-exports with docs
  • packages/@ember/template-compiler/lib/compile-options.ts — keyword registration
  • packages/@ember/template-compiler/lib/plugins/auto-import-builtins.ts — AST rewriting

Test plan

  • and: returns right-most truthy, first falsy, empty array as falsy
  • or: returns first truthy, right-most falsy, empty array as falsy
  • not: negates truthy/falsy, works as MustacheStatement
  • Runtime keyword tests (explicit scope, eval)
  • DEBUG arity error tests for all three
  • Uses Handlebars truthiness (empty arrays are falsy)

🤖 Generated with Claude Code

@NullVoxPopuli NullVoxPopuli marked this pull request as draft April 10, 2026 15:39
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this test should be split in to 3 files, one for and, one for or, and one for not

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same split here

import { createComputeRef, valueForRef } from '@glimmer/reference';
import { internalHelper } from './internal-helper';

export const and = internalHelper(({ positional }: CapturedArguments) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this can just be a simple function -- we don't need to use internalHelper, createComputeRef, or valueForRef.

we can do:

export const and = (...args: unknown[]) => args.every(Boolean);

the same shortcut/shorthand can be used for all of these functions

@NullVoxPopuli-ai-agent NullVoxPopuli-ai-agent force-pushed the nvp/and-or-not-as-keyword branch 2 times, most recently from da32ad1 to ae2f0b2 Compare April 10, 2026 17:01
NullVoxPopuli
NullVoxPopuli previously approved these changes Apr 10, 2026
@NullVoxPopuli NullVoxPopuli marked this pull request as ready for review April 10, 2026 18:20
NullVoxPopuli
NullVoxPopuli previously approved these changes Apr 10, 2026
NullVoxPopuli
NullVoxPopuli previously approved these changes Apr 10, 2026
Add boolean logic helpers and register them as built-in keywords
so they no longer need to be imported in strict-mode (gjs/gts) templates.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants