-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Inplement runtime portion of RFC #931 #20776
Merged
Merged
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
2f5e698
Initial commit
wycats ac17dc5
Use pnpm 8
wycats 9933294
Write some tests and fix implementation
wycats 7f7ac06
Implement explicit scope
wycats 7dcb7f5
Update pnpm-lock.yaml
wycats 309bbe8
Fix type errors
wycats 4f274e5
Disable unused locals in tsconfig
wycats 9cd8d5d
Reorganize compiler entry points to type check
wycats f528512
Document type signature and consolidate plugins
wycats 90ce57d
Start writing better type tests
wycats 49c88fd
Newline after return bites again!
wycats 1580b97
Make strict mode the default for template()
wycats 38930ae
Avoid variable stripping
wycats c4a987c
Try using new headless mode
wycats 3030bb3
Remove accidental `headless: 'new'`
wycats ff558d2
Avoid scope sharing in dev vite build
wycats c125851
Properly hide on and fn in those tests
wycats bf0a914
Remove unused assert
wycats 66e8841
Fix some edge-cases with classic builds
wycats d67607d
Lint fix
wycats fc51f7d
Clean up barrel type failure
wycats ef708e2
Another attempt to fix barrel.ts
wycats e18e3ad
Always preserve modules
wycats ee3f8d1
Update renamed-modules
wycats 33aa98a
Add @ember/test-waiters to app-template
NullVoxPopuli 83810af
Merge pull request #20780 from NullVoxPopuli/maybe-fix
wycats 30db3c1
Merge branch 'main' into feature/rfc-0931
wycats fb1c533
Merge remote-tracking branch 'origin/main' into feature/rfc-0931
wycats File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
338 changes: 338 additions & 0 deletions
338
...internals/glimmer/tests/integration/components/runtime-template-compiler-explicit-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,338 @@ | ||
import { template } from '@ember/template-compiler/runtime'; | ||
import { RenderingTestCase, defineSimpleModifier, moduleFor } from 'internal-test-helpers'; | ||
import GlimmerishComponent from '../../utils/glimmerish-component'; | ||
import { on } from '@ember/modifier/on'; | ||
import { fn } from '@ember/helper'; | ||
|
||
moduleFor( | ||
'Strict Mode - Runtime Template Compiler (explicit)', | ||
class extends RenderingTestCase { | ||
async '@test Can use a component in scope'() { | ||
await this.renderComponentModule(() => { | ||
let Foo = template('Hello, world!'); | ||
|
||
return template('<Foo />', { | ||
scope: () => ({ Foo }), | ||
}); | ||
}); | ||
|
||
this.assertHTML('Hello, world!'); | ||
this.assertStableRerender(); | ||
} | ||
|
||
async '@test Can use a custom helper in scope (in append position)'() { | ||
await this.renderComponentModule(() => { | ||
let foo = () => 'Hello, world!'; | ||
|
||
return template('{{foo}}', { | ||
scope: () => ({ foo }), | ||
}); | ||
}); | ||
|
||
this.assertHTML('Hello, world!'); | ||
this.assertStableRerender(); | ||
} | ||
|
||
async '@test Can use a custom modifier in scope'() { | ||
await this.renderComponentModule(() => { | ||
let foo = defineSimpleModifier((element: Element) => (element.innerHTML = 'Hello, world!')); | ||
return template('<div {{foo}}></div>', { | ||
scope: () => ({ foo }), | ||
}); | ||
}); | ||
|
||
this.assertHTML('<div>Hello, world!</div>'); | ||
this.assertStableRerender(); | ||
} | ||
|
||
async '@test Can shadow keywords'() { | ||
await this.renderComponentModule(() => { | ||
let each = template(`{{yield}}`); | ||
|
||
return template(`{{#each}}Hello, world!{{/each}}`, { | ||
scope: () => ({ each }), | ||
}); | ||
}); | ||
|
||
this.assertHTML('Hello, world!'); | ||
this.assertStableRerender(); | ||
} | ||
|
||
async '@test Can use constant values in ambiguous helper/component position'() { | ||
await this.renderComponentModule(() => { | ||
let value = 'Hello, world!'; | ||
|
||
return template(`{{value}}`, { | ||
scope: () => ({ value }), | ||
}); | ||
}); | ||
|
||
this.assertHTML('Hello, world!'); | ||
this.assertStableRerender(); | ||
} | ||
|
||
async '@test Can use inline if and unless in strict mode templates'() { | ||
await this.renderComponentModule(() => { | ||
return template('{{if true "foo" "bar"}}{{unless true "foo" "bar"}}'); | ||
}); | ||
|
||
this.assertHTML('foobar'); | ||
this.assertStableRerender(); | ||
} | ||
|
||
async '@test Can use a dynamic component definition'() { | ||
await this.renderComponentModule(() => { | ||
let Foo = template('Hello, world!'); | ||
|
||
return class extends GlimmerishComponent { | ||
static { | ||
template('<this.Foo />', { | ||
component: this, | ||
}); | ||
} | ||
|
||
Foo = Foo; | ||
}; | ||
}); | ||
|
||
this.assertHTML('Hello, world!'); | ||
this.assertStableRerender(); | ||
} | ||
|
||
async '@test Can use a dynamic component definition (curly)'() { | ||
await this.renderComponentModule(() => { | ||
let Foo = template('Hello, world!'); | ||
|
||
return class extends GlimmerishComponent { | ||
static { | ||
template('{{this.Foo}}', { | ||
component: this, | ||
}); | ||
} | ||
|
||
Foo = Foo; | ||
}; | ||
}); | ||
|
||
this.assertHTML('Hello, world!'); | ||
this.assertStableRerender(); | ||
} | ||
|
||
async '@test Can use a dynamic helper definition'() { | ||
await this.renderComponentModule(() => { | ||
let foo = () => 'Hello, world!'; | ||
|
||
return class extends GlimmerishComponent { | ||
static { | ||
template('{{this.foo}}', { | ||
component: this, | ||
}); | ||
} | ||
|
||
foo = foo; | ||
}; | ||
}); | ||
|
||
this.assertHTML('Hello, world!'); | ||
this.assertStableRerender(); | ||
} | ||
|
||
async '@test Can use a curried dynamic helper'() { | ||
await this.renderComponentModule(() => { | ||
let foo = (v: string) => v; | ||
|
||
let Foo = template('{{@value}}'); | ||
|
||
return template('<Foo @value={{helper foo "Hello, world!"}}/>', { | ||
scope: () => ({ foo, Foo }), | ||
}); | ||
}); | ||
this.assertHTML('Hello, world!'); | ||
this.assertStableRerender(); | ||
} | ||
|
||
async '@test Can use a curried dynamic modifier'() { | ||
await this.renderComponentModule(() => { | ||
let foo = defineSimpleModifier( | ||
(element: Element, [text]: [string]) => (element.innerHTML = text) | ||
); | ||
|
||
let Foo = template('<div {{@value}}></div>'); | ||
|
||
return template('<Foo @value={{modifier foo "Hello, world!"}}/>', { | ||
scope: () => ({ foo, Foo }), | ||
}); | ||
}); | ||
this.assertHTML('<div>Hello, world!</div>'); | ||
this.assertStableRerender(); | ||
} | ||
} | ||
); | ||
|
||
moduleFor( | ||
'Strict Mode - Runtime Template Compiler (explicit) - built ins', | ||
class extends RenderingTestCase { | ||
async '@test Can use Input'() { | ||
const { Input } = await import('@ember/component'); | ||
|
||
await this.renderComponentModule(() => { | ||
return template('<Input/>', { | ||
scope: () => ({ | ||
Input, | ||
}), | ||
}); | ||
}); | ||
|
||
this.assertComponentElement(this.firstChild, { | ||
tagName: 'input', | ||
attrs: { | ||
type: 'text', | ||
class: 'ember-text-field ember-view', | ||
}, | ||
}); | ||
this.assertStableRerender(); | ||
} | ||
|
||
async '@test Can use Textarea'() { | ||
const { Textarea } = await import('@ember/component'); | ||
|
||
await this.renderComponentModule(() => { | ||
return template('<Textarea/>', { | ||
scope: () => ({ | ||
Textarea, | ||
}), | ||
}); | ||
}); | ||
|
||
this.assertComponentElement(this.firstChild, { | ||
tagName: 'textarea', | ||
attrs: { | ||
class: 'ember-text-area ember-view', | ||
}, | ||
}); | ||
this.assertStableRerender(); | ||
} | ||
|
||
async '@test Can use hash'() { | ||
const { hash } = await import('@glimmer/runtime'); | ||
|
||
await this.renderComponentModule(() => { | ||
return template('{{#let (hash value="Hello, world!") as |hash|}}{{hash.value}}{{/let}}', { | ||
scope: () => ({ hash }), | ||
}); | ||
}); | ||
|
||
this.assertHTML('Hello, world!'); | ||
this.assertStableRerender(); | ||
} | ||
|
||
async '@test Can use array'() { | ||
const { array } = await import('@glimmer/runtime'); | ||
|
||
await this.renderComponentModule(() => { | ||
return template('{{#each (array "Hello, world!") as |value|}}{{value}}{{/each}}', { | ||
scope: () => ({ array }), | ||
}); | ||
}); | ||
this.assertHTML('Hello, world!'); | ||
this.assertStableRerender(); | ||
} | ||
|
||
async '@test Can use concat'() { | ||
const { concat } = await import('@glimmer/runtime'); | ||
|
||
await this.renderComponentModule(() => { | ||
return template('{{(concat "Hello" ", " "world!")}}', { | ||
scope: () => ({ concat }), | ||
}); | ||
}); | ||
|
||
this.assertHTML('Hello, world!'); | ||
this.assertStableRerender(); | ||
} | ||
|
||
async '@test Can use get'() { | ||
const { hash, get } = await import('@glimmer/runtime'); | ||
|
||
await this.renderComponentModule(() => { | ||
return template( | ||
'{{#let (hash value="Hello, world!") as |hash|}}{{(get hash "value")}}{{/let}}', | ||
{ | ||
scope: () => ({ hash, get }), | ||
} | ||
); | ||
}); | ||
|
||
this.assertHTML('Hello, world!'); | ||
this.assertStableRerender(); | ||
} | ||
|
||
async '@test Can use on and fn'(assert: QUnit['assert']) { | ||
assert.expect(1); | ||
|
||
await this.renderComponentModule(() => { | ||
let handleClick = (value: unknown) => { | ||
assert.equal(value, 123); | ||
}; | ||
|
||
return template('<button {{on "click" (fn handleClick 123)}}>Click</button>', { | ||
scope: () => ({ handleClick, on, fn }), | ||
}); | ||
}); | ||
|
||
this.click('button'); | ||
} | ||
|
||
// Test some of the additional keywords not built-in to glimmer-vm (those | ||
// we specifically enable them when calling `precompile`) | ||
|
||
// Ember currently uses AST plugins to implement certain features that | ||
// glimmer-vm does not natively provide, such as {{#each-in}}, {{outlet}} | ||
// {{mount}} and some features in {{#in-element}}. These rewrites the AST | ||
// and insert private keywords e.g. `{{#each (-each-in)}}`. These tests | ||
// ensures we have _some_ basic coverage for those features in strict mode. | ||
// | ||
// Ultimately, our test coverage for strict mode is quite inadequate. This | ||
// is particularly important as we expect more apps to start adopting the | ||
// feature. Ideally we would run our entire/most of our test suite against | ||
// both strict and resolution modes, and these things would be implicitly | ||
// covered elsewhere, but until then, these coverage are essential. | ||
|
||
async '@test Can use each-in'() { | ||
let obj = { | ||
foo: 'FOO', | ||
bar: 'BAR', | ||
}; | ||
|
||
await this.renderComponentModule(() => { | ||
return template('{{#each-in obj as |k v|}}[{{k}}:{{v}}]{{/each-in}}', { | ||
scope: () => ({ obj }), | ||
}); | ||
}); | ||
|
||
this.assertHTML('[foo:FOO][bar:BAR]'); | ||
this.assertStableRerender(); | ||
} | ||
|
||
async '@test Can use in-element'() { | ||
const fixture = document.querySelector('#qunit-fixture')!; | ||
const element: HTMLTemplateElement = document.createElement('template'); | ||
element.innerHTML = '[<div id="in-element-test"></div>]'; | ||
fixture.appendChild(element.content); | ||
|
||
const getElement = (id: string) => document.querySelector(`#${id}`)!; | ||
|
||
await this.renderComponentModule(() => { | ||
return template( | ||
'{{#in-element (getElement "in-element-test")}}before{{/in-element}}after', | ||
{ | ||
scope: () => ({ getElement }), | ||
} | ||
); | ||
}); | ||
|
||
this.assertText('[before]after'); | ||
this.assertStableRerender(); | ||
} | ||
} | ||
); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just tested and this new stuff is not available outside of embroider 👍