Skip to content
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 28 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2f5e698
Initial commit
wycats Oct 10, 2024
ac17dc5
Use pnpm 8
wycats Oct 10, 2024
9933294
Write some tests and fix implementation
wycats Oct 11, 2024
7f7ac06
Implement explicit scope
wycats Oct 11, 2024
7dcb7f5
Update pnpm-lock.yaml
wycats Oct 11, 2024
309bbe8
Fix type errors
wycats Oct 11, 2024
4f274e5
Disable unused locals in tsconfig
wycats Oct 11, 2024
9cd8d5d
Reorganize compiler entry points to type check
wycats Oct 11, 2024
f528512
Document type signature and consolidate plugins
wycats Oct 11, 2024
90ce57d
Start writing better type tests
wycats Oct 11, 2024
49c88fd
Newline after return bites again!
wycats Oct 16, 2024
1580b97
Make strict mode the default for template()
wycats Oct 16, 2024
38930ae
Avoid variable stripping
wycats Oct 17, 2024
c4a987c
Try using new headless mode
wycats Oct 17, 2024
3030bb3
Remove accidental `headless: 'new'`
wycats Oct 17, 2024
ff558d2
Avoid scope sharing in dev vite build
wycats Oct 17, 2024
c125851
Properly hide on and fn in those tests
wycats Oct 17, 2024
bf0a914
Remove unused assert
wycats Oct 17, 2024
66e8841
Fix some edge-cases with classic builds
wycats Oct 17, 2024
d67607d
Lint fix
wycats Oct 17, 2024
fc51f7d
Clean up barrel type failure
wycats Oct 17, 2024
ef708e2
Another attempt to fix barrel.ts
wycats Oct 18, 2024
e18e3ad
Always preserve modules
wycats Oct 18, 2024
ee3f8d1
Update renamed-modules
wycats Oct 18, 2024
33aa98a
Add @ember/test-waiters to app-template
NullVoxPopuli Oct 21, 2024
83810af
Merge pull request #20780 from NullVoxPopuli/maybe-fix
wycats Oct 21, 2024
30db3c1
Merge branch 'main' into feature/rfc-0931
wycats Oct 21, 2024
fb1c533
Merge remote-tracking branch 'origin/main' into feature/rfc-0931
wycats Oct 29, 2024
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
24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,30 @@
"@ember/runloop/index.js": "ember-source/@ember/runloop/index.js",
"@ember/service/index.js": "ember-source/@ember/service/index.js",
"@ember/template-compilation/index.js": "ember-source/@ember/template-compilation/index.js",
"@ember/template-compiler/-internal-primitives.js": "ember-source/@ember/template-compiler/-internal-primitives.js",
Copy link
Contributor

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 👍

"@ember/template-compiler/-internal-utils.js": "ember-source/@ember/template-compiler/-internal-utils.js",
"@ember/template-compiler/index.js": "ember-source/@ember/template-compiler/index.js",
"@ember/template-compiler/lib/-internal/primitives.js": "ember-source/@ember/template-compiler/lib/-internal/primitives.js",
"@ember/template-compiler/lib/compile-options.js": "ember-source/@ember/template-compiler/lib/compile-options.js",
"@ember/template-compiler/lib/dasherize-component-name.js": "ember-source/@ember/template-compiler/lib/dasherize-component-name.js",
"@ember/template-compiler/lib/plugins/assert-against-attrs.js": "ember-source/@ember/template-compiler/lib/plugins/assert-against-attrs.js",
"@ember/template-compiler/lib/plugins/assert-against-named-outlets.js": "ember-source/@ember/template-compiler/lib/plugins/assert-against-named-outlets.js",
"@ember/template-compiler/lib/plugins/assert-input-helper-without-block.js": "ember-source/@ember/template-compiler/lib/plugins/assert-input-helper-without-block.js",
"@ember/template-compiler/lib/plugins/assert-reserved-named-arguments.js": "ember-source/@ember/template-compiler/lib/plugins/assert-reserved-named-arguments.js",
"@ember/template-compiler/lib/plugins/index.js": "ember-source/@ember/template-compiler/lib/plugins/index.js",
"@ember/template-compiler/lib/plugins/transform-action-syntax.js": "ember-source/@ember/template-compiler/lib/plugins/transform-action-syntax.js",
"@ember/template-compiler/lib/plugins/transform-each-in-into-each.js": "ember-source/@ember/template-compiler/lib/plugins/transform-each-in-into-each.js",
"@ember/template-compiler/lib/plugins/transform-each-track-array.js": "ember-source/@ember/template-compiler/lib/plugins/transform-each-track-array.js",
"@ember/template-compiler/lib/plugins/transform-in-element.js": "ember-source/@ember/template-compiler/lib/plugins/transform-in-element.js",
"@ember/template-compiler/lib/plugins/transform-quoted-bindings-into-just-bindings.js": "ember-source/@ember/template-compiler/lib/plugins/transform-quoted-bindings-into-just-bindings.js",
"@ember/template-compiler/lib/plugins/transform-resolutions.js": "ember-source/@ember/template-compiler/lib/plugins/transform-resolutions.js",
"@ember/template-compiler/lib/plugins/transform-wrap-mount-and-outlet.js": "ember-source/@ember/template-compiler/lib/plugins/transform-wrap-mount-and-outlet.js",
"@ember/template-compiler/lib/plugins/utils.js": "ember-source/@ember/template-compiler/lib/plugins/utils.js",
"@ember/template-compiler/lib/public-api.js": "ember-source/@ember/template-compiler/lib/public-api.js",
"@ember/template-compiler/lib/runtime.js": "ember-source/@ember/template-compiler/lib/runtime.js",
"@ember/template-compiler/lib/system/calculate-location-display.js": "ember-source/@ember/template-compiler/lib/system/calculate-location-display.js",
"@ember/template-compiler/lib/template.js": "ember-source/@ember/template-compiler/lib/template.js",
"@ember/template-compiler/runtime.js": "ember-source/@ember/template-compiler/runtime.js",
"@ember/template-factory/index.js": "ember-source/@ember/template-factory/index.js",
"@ember/template/index.js": "ember-source/@ember/template/index.js",
"@ember/test/adapter.js": "ember-source/@ember/test/adapter.js",
Expand Down
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();
}
}
);
Loading
Loading