Skip to content

Assert the compiled scope independently of the wire format's shape - #121

Open
NullVoxPopuli wants to merge 3 commits into
mainfrom
object-scope-test-coverage
Open

Assert the compiled scope independently of the wire format's shape#121
NullVoxPopuli wants to merge 3 commits into
mainfrom
object-scope-test-coverage

Conversation

@NullVoxPopuli

@NullVoxPopuli NullVoxPopuli commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Test-only. Extracted from #120 so that PR can be purely the fix it describes.

Older compilers emit the wire format's scope as an array (scope: () => [Setup]); newer ones emit an object (scope: () => ({ Foo: Setup })). Verified against both:

ember-source 6.9.0:  scope: () => [Setup]      id: "Ug1Ts6YJ"
ember-source 7.2.0:  scope: () => ({Setup})    id: null

Both shapes carry the same information — the names the template uses, mapped to the JS they resolve to — but the array form leaves the names implicit, in the locals we hand the compiler.

This adds a wireScope helper that reads either shape back into the same mapping, pairing an array-form scope with those locals. A test can then assert on the compiled scope without caring which ember-source is installed, which matters because the try scenarios float that dependency from 3.28 through beta. It also makes failures legible:

AssertionError: expected { Setup: 'Setup' } to deeply equal { Foo: 'Setup' }

Green on main as-is — no implementation change. #120 uses the same helper to show a case that isn't handled correctly today.

🤖 Generated with Claude Code

Older compilers emit the wire format's scope as an array
(`scope: () => [Setup]`); newer ones emit an object
(`scope: () => ({ Foo: Setup })`). Both carry the same information — the names
the template uses, mapped to the JS they resolve to — but the array form leaves
the names implicit, in the `locals` we handed the compiler.

Add a `wireScope` helper that reads either shape back into the same mapping, by
pairing an array-form scope with those locals. That lets a test assert on the
compiled scope without caring which ember-source is installed, which matters
because the try scenarios float that dependency from 3.28 through beta.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@NullVoxPopuli
NullVoxPopuli force-pushed the object-scope-test-coverage branch from 5ee859f to 176cf7c Compare August 12, 2026 18:29
@NullVoxPopuli NullVoxPopuli changed the title Cover compilers that emit an object-form wire scope Assert the compiled scope independently of the wire format's shape Aug 12, 2026
Comment thread __tests__/all.test.ts

let source = (node: babel.types.Node) => src.slice(node.start!, node.end!);

if (t.isObjectExpression(value.body)) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

new

Comment thread __tests__/all.test.ts
return [name, source(prop.value)];
})
);
} else if (t.isArrayExpression(value.body)) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

old

Comment thread __tests__/all.test.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant