diff --git a/.eslintrc.js b/.eslintrc.js index ad754cbe7..6279f93ad 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -30,6 +30,7 @@ module.exports = { 'webpack.config.js', 'packages/babel-plugins/**/*.js', 'packages/@glimmer/blueprint/index.js', + '**/babel-plugins.js' ], env: { es6: true, diff --git a/package.json b/package.json index 39c3acdfa..e5a6bb491 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "problems": "tsc -p tsconfig.json --noEmit", "start": "webpack-dev-server", "test": "npm-run-all lint test:browsers test:babel-plugins test:types", - "test:babel-plugins": "mocha -r esm --timeout 5000 test/babel-plugins.js", + "test:babel-plugins": "yarn workspace @glimmer/babel-preset test", "test:browsers": "testem ci", "test:ember": "yarn workspace @glimmer/component ember try:one", "test:types": "dtslint test/types", diff --git a/packages/@glimmer/blueprint/files/.babelrc.js b/packages/@glimmer/blueprint/files/.babelrc.js index 48dbfd929..297598661 100644 --- a/packages/@glimmer/blueprint/files/.babelrc.js +++ b/packages/@glimmer/blueprint/files/.babelrc.js @@ -1,11 +1,5 @@ -module.exports = function (api) { +module.exports = function () { return { - plugins: [ - ['@glimmer/babel-plugin-glimmer-env', { DEBUG: !api.env('production') }], - '@glimmer/babel-plugin-strict-template-precompile', - ['@babel/plugin-proposal-decorators', { legacy: true }], - '@babel/plugin-proposal-class-properties', - ], - presets: ['@babel/preset-env', '@babel/preset-typescript'], + presets: ['@glimmer/babel-preset', '@babel/preset-env', '@babel/preset-typescript'], }; }; diff --git a/packages/@glimmer/blueprint/files/package.json b/packages/@glimmer/blueprint/files/package.json index 965fe0aa0..690f43687 100644 --- a/packages/@glimmer/blueprint/files/package.json +++ b/packages/@glimmer/blueprint/files/package.json @@ -16,18 +16,15 @@ }, "devDependencies": { "@babel/core": "^7.9.0", - "@babel/plugin-proposal-class-properties": "^7.8.3", - "@babel/plugin-proposal-decorators": "^7.8.3", "@babel/preset-env": "^7.9.0", "@babel/preset-typescript": "^7.9.0", - "@glimmer/babel-plugin-glimmer-env": "~2.0.0-beta.12", - "@glimmer/babel-plugin-strict-template-precompile": "~2.0.0-beta.12", "@glimmer/blueprint": "~2.0.0-beta.12", "@glimmer/component": "~2.0.0-beta.12", "@glimmer/core": "~2.0.0-beta.12", "@glimmer/env": "^0.1.7", "@glimmer/helper": "~2.0.0-beta.12", "@glimmer/modifier": "~2.0.0-beta.12", + "@glimmer/babel-preset": "~2.0.0-beta.12", "@types/qunit": "^2.9.1", "@typescript-eslint/eslint-plugin": "^2.26.0", "@typescript-eslint/parser": "^2.26.0", diff --git a/packages/@glimmer/blueprint/files/src/App.js b/packages/@glimmer/blueprint/files/src/App.js index bdab40f68..5305e8a69 100644 --- a/packages/@glimmer/blueprint/files/src/App.js +++ b/packages/@glimmer/blueprint/files/src/App.js @@ -1,5 +1,5 @@ import Component from '@glimmer/component'; -import { setComponentTemplate, createTemplate } from '@glimmer/core'; +import { setComponentTemplate, precompileTemplate } from '@glimmer/core'; import logo from './logo.svg'; import './App.css'; @@ -9,7 +9,8 @@ export default class App extends Component { } setComponentTemplate( - createTemplate(` + precompileTemplate( + `
@@ -19,6 +20,8 @@ setComponentTemplate( and run tests by visiting /tests
- `), + `, + { strictMode: true } + ), App ); diff --git a/packages/@glimmer/component/test/interactive/args-test.ts b/packages/@glimmer/component/test/interactive/args-test.ts index 2c127f12c..0d548b24e 100644 --- a/packages/@glimmer/component/test/interactive/args-test.ts +++ b/packages/@glimmer/component/test/interactive/args-test.ts @@ -1,7 +1,7 @@ import Component from '@glimmer/component'; import { tracked } from '@glimmer/tracking'; -import { setComponentTemplate, createTemplate } from '@glimmer/core'; +import { setComponentTemplate, precompileTemplate } from '@glimmer/core'; import { test, render, settled } from '@glimmer/core/test/utils'; QUnit.module('[@glimmer/component] Component Arguments', () => { @@ -27,14 +27,17 @@ QUnit.module('[@glimmer/component] Component Arguments', () => { } setComponentTemplate( - createTemplate( - { ChildComponent }, - '' + precompileTemplate( + '', + { strictMode: true, scope: { ChildComponent } } ), ParentComponent ); - setComponentTemplate(createTemplate('{{this.name}} {{@status}}'), ChildComponent); + setComponentTemplate( + precompileTemplate('{{this.name}} {{@status}}', { strictMode: true }), + ChildComponent + ); assert.equal(await render(ParentComponent), 'Tom Dale is dope'); diff --git a/packages/@glimmer/component/test/interactive/lifecycle-hook-test.ts b/packages/@glimmer/component/test/interactive/lifecycle-hook-test.ts index 62aafc866..3d3cba88b 100644 --- a/packages/@glimmer/component/test/interactive/lifecycle-hook-test.ts +++ b/packages/@glimmer/component/test/interactive/lifecycle-hook-test.ts @@ -2,7 +2,7 @@ import Component from '@glimmer/component'; import { tracked } from '@glimmer/tracking'; import { test, render, settled } from '@glimmer/core/test/utils'; -import { setComponentTemplate, createTemplate } from '@glimmer/core'; +import { setComponentTemplate, precompileTemplate } from '@glimmer/core'; QUnit.module('[@glimmer/component] Lifecycle Hooks', () => { test('Lifecycle hook ordering', async function (assert) { @@ -37,31 +37,37 @@ QUnit.module('[@glimmer/component] Lifecycle Hooks', () => { class Component5 extends HookLoggerComponent {} setComponentTemplate( - createTemplate( - { Component2, Component3 }, + precompileTemplate( ` {{#if this.showChildren}} {{/if}} - ` + `, + { + strictMode: true, + scope: { Component2, Component3 }, + } ), Component1 ); setComponentTemplate( - createTemplate( - { Component4, Component5 }, + precompileTemplate( ` {{@firstName}} - ` + `, + { + strictMode: true, + scope: { Component4, Component5 }, + } ), Component2 ); - const emptyTemplate = createTemplate(''); + const emptyTemplate = precompileTemplate(''); setComponentTemplate(emptyTemplate, Component3); setComponentTemplate(emptyTemplate, Component4); diff --git a/packages/@glimmer/core/index.ts b/packages/@glimmer/core/index.ts index 52eec018c..f56c35f28 100644 --- a/packages/@glimmer/core/index.ts +++ b/packages/@glimmer/core/index.ts @@ -16,19 +16,19 @@ export type { HelperManager, } from '@glimmer/interfaces'; +export { templateFactory as createTemplateFactory } from '@glimmer/opcode-compiler'; export { templateOnlyComponent } from '@glimmer/runtime'; -export { TemplateArgs } from './src/interfaces'; - export { setComponentManager, setModifierManager, - modifierCapabilities, setHelperManager, componentCapabilities, + modifierCapabilities, helperCapabilities, + setComponentTemplate, } from '@glimmer/manager'; export { getOwner, setOwner } from '@glimmer/owner'; -export { createTemplate, setComponentTemplate } from './src/template'; +export { precompileTemplate } from './src/template'; diff --git a/packages/@glimmer/core/src/interfaces.ts b/packages/@glimmer/core/src/interfaces.ts deleted file mode 100644 index 50fc3e6eb..000000000 --- a/packages/@glimmer/core/src/interfaces.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Dict } from '@glimmer/interfaces'; - -export interface TemplateArgs< - Positional extends unknown[] = unknown[], - Named extends Dict = Dict -> { - named: Named; - positional: Positional; -} diff --git a/packages/@glimmer/core/src/template.ts b/packages/@glimmer/core/src/template.ts index c11de33a1..5334db094 100644 --- a/packages/@glimmer/core/src/template.ts +++ b/packages/@glimmer/core/src/template.ts @@ -1,25 +1,19 @@ import { DEBUG } from '@glimmer/env'; -import { setComponentTemplate as vmSetComponentTemplate } from '@glimmer/manager'; -import { SerializedTemplateWithLazyBlock, Dict } from '@glimmer/interfaces'; -import { templateFactory } from '@glimmer/opcode-compiler'; +import { TemplateFactory } from '@glimmer/interfaces'; -// This is provided by the `babel-plugin-strict-template-precompile` plugin -export let createTemplate: ( - scopeOrTemplate: Dict | string, - template?: string -) => SerializedTemplateWithLazyBlock; +// This is provided by `@glimmer/babel-preset` +export let precompileTemplate: ( + template: string, + options?: { + strictMode?: boolean; + scope?: Record; + } +) => TemplateFactory; if (DEBUG) { - createTemplate = (): SerializedTemplateWithLazyBlock => { + precompileTemplate = (): TemplateFactory => { throw new Error( - 'createTemplate() is meant to be preprocessed with a babel plugin, @glimmer/babel-plugin-strict-template-precompile. If you are seeing this error message, it means that you do not have this babel plugin installed, or it is not enabled correctly' + 'precompileTemplate() is meant to be preprocessed with babel, using @glimmer/babel-preset. If you are seeing this error message, it means that you do not have this babel preset installed, or it is not enabled correctly' ); }; } - -export function setComponentTemplate( - template: SerializedTemplateWithLazyBlock, - ComponentClass: object -): object { - return vmSetComponentTemplate(templateFactory(template), ComponentClass); -} diff --git a/packages/@glimmer/core/test/interactive/fn-test.ts b/packages/@glimmer/core/test/interactive/fn-test.ts index 862812690..dc26ad23b 100644 --- a/packages/@glimmer/core/test/interactive/fn-test.ts +++ b/packages/@glimmer/core/test/interactive/fn-test.ts @@ -3,7 +3,7 @@ import Component from '@glimmer/component'; import { fn } from '@glimmer/helper'; import { on, action } from '@glimmer/modifier'; -import { setComponentTemplate, createTemplate, templateOnlyComponent } from '@glimmer/core'; +import { setComponentTemplate, precompileTemplate, templateOnlyComponent } from '@glimmer/core'; QUnit.module('[@glimmer/core] interactive - {{fn}}', () => { test('can curry arguments via fn', async function (assert) { @@ -29,9 +29,12 @@ QUnit.module('[@glimmer/core] interactive - {{fn}}', () => { } setComponentTemplate( - createTemplate( - { on, fn }, - '' + precompileTemplate( + '', + { + strictMode: true, + scope: { on, fn }, + } ), HelloWorld ); @@ -82,23 +85,26 @@ QUnit.module('[@glimmer/core] interactive - {{fn}}', () => { } const Grandchild = setComponentTemplate( - createTemplate({ on, fn }, ''), + precompileTemplate('', { + strictMode: true, + scope: { on, fn }, + }), templateOnlyComponent() ); const Child = setComponentTemplate( - createTemplate( - { Grandchild, fn }, - '
' - ), + precompileTemplate('
', { + strictMode: true, + scope: { Grandchild, fn }, + }), templateOnlyComponent() ); setComponentTemplate( - createTemplate( - { Child, fn }, - '
' - ), + precompileTemplate('
', { + strictMode: true, + scope: { Child, fn }, + }), ParentComponent ); @@ -116,7 +122,10 @@ QUnit.module('[@glimmer/core] interactive - {{fn}}', () => { class Parent extends Component {} setComponentTemplate( - createTemplate({ on, fn }, ''), + precompileTemplate('', { + strictMode: true, + scope: { on, fn }, + }), Parent ); diff --git a/packages/@glimmer/core/test/interactive/modifier-test.ts b/packages/@glimmer/core/test/interactive/modifier-test.ts index 1a12237e6..048fb5a20 100644 --- a/packages/@glimmer/core/test/interactive/modifier-test.ts +++ b/packages/@glimmer/core/test/interactive/modifier-test.ts @@ -2,7 +2,7 @@ import { test, render, settled, tracked } from '../utils'; import { click } from '../utils/dom'; import { on, action } from '@glimmer/modifier'; import Component from '@glimmer/component'; -import { setComponentTemplate, createTemplate } from '@glimmer/core'; +import { setComponentTemplate, precompileTemplate } from '@glimmer/core'; QUnit.module('Modifier Tests', () => { test('Supports the on modifier', async (assert) => { @@ -16,9 +16,12 @@ QUnit.module('Modifier Tests', () => { } setComponentTemplate( - createTemplate( - { on }, - `` + precompileTemplate( + ``, + { + strictMode: true, + scope: { on }, + } ), MyComponent ); diff --git a/packages/@glimmer/core/test/interactive/render-test.ts b/packages/@glimmer/core/test/interactive/render-test.ts index 45fbd765d..1769a1959 100644 --- a/packages/@glimmer/core/test/interactive/render-test.ts +++ b/packages/@glimmer/core/test/interactive/render-test.ts @@ -1,4 +1,4 @@ -import { createTemplate } from '@glimmer/core'; +import { precompileTemplate } from '@glimmer/core'; import { test, render } from '../utils'; @@ -11,8 +11,14 @@ QUnit.module(`[@glimmer/core] interactive rendering tests`, () => { const firstContainerElement = document.createElement('div'); const secondContainerElement = document.createElement('div'); - await render(createTemplate(`

Hello Glimmer!

`), firstContainerElement); - await render(createTemplate(`

Hello Robbie!

`), secondContainerElement); + await render( + precompileTemplate(`

Hello Glimmer!

`, { strictMode: true }), + firstContainerElement + ); + await render( + precompileTemplate(`

Hello Robbie!

`, { strictMode: true }), + secondContainerElement + ); assert.equal(firstContainerElement.innerHTML, '

Hello Glimmer!

'); assert.equal(secondContainerElement.innerHTML, '

Hello Robbie!

'); @@ -30,7 +36,10 @@ QUnit.module(`[@glimmer/core] interactive rendering tests`, () => { containerElement.appendChild(previousSibling); containerElement.appendChild(document.createTextNode('bar')); - await render(createTemplate(`

Hello Glimmer!

`), containerElement); + await render( + precompileTemplate(`

Hello Glimmer!

`, { strictMode: true }), + containerElement + ); assert.equal(containerElement.innerHTML, '

foo

bar

Hello Glimmer!

'); }); @@ -40,7 +49,7 @@ QUnit.module(`[@glimmer/core] interactive rendering tests`, () => { containerElement.innerHTML = '

Hello World

'; - await render(createTemplate(`

Hello World

`), { + await render(precompileTemplate(`

Hello World

`, { strictMode: true }), { element: containerElement, rehydrate: true, }); @@ -53,7 +62,7 @@ QUnit.module(`[@glimmer/core] interactive rendering tests`, () => { containerElement.innerHTML = '

Hello World

'; - await render(createTemplate(`

Hello {{@name}}

`), { + await render(precompileTemplate(`

Hello {{@name}}

`, { strictMode: true }), { element: containerElement.querySelector('#test')!, rehydrate: true, args: { diff --git a/packages/@glimmer/core/test/non-interactive/each-test.ts b/packages/@glimmer/core/test/non-interactive/each-test.ts index d013b4c1f..cfffd5f5a 100644 --- a/packages/@glimmer/core/test/non-interactive/each-test.ts +++ b/packages/@glimmer/core/test/non-interactive/each-test.ts @@ -1,7 +1,7 @@ import Component from '@glimmer/component'; import { test, render } from '../utils'; -import { setComponentTemplate, createTemplate } from '@glimmer/core'; +import { setComponentTemplate, precompileTemplate } from '@glimmer/core'; function freeze(array: T[]): ReadonlyArray> { return Object.freeze(array.slice().map(Object.freeze)); @@ -23,8 +23,11 @@ QUnit.module('[@glimmer/core] each helper', () => { const Component = class extends HelloWorld {}; setComponentTemplate( - createTemplate( - `
    {{#each this.strings key="@unknown" as |item|}}
  • {{item}}
  • {{/each}}
` + precompileTemplate( + `
    {{#each this.strings key="@unknown" as |item|}}
  • {{item}}
  • {{/each}}
`, + { + strictMode: true, + } ), Component ); @@ -38,8 +41,11 @@ QUnit.module('[@glimmer/core] each helper', () => { const Component = class extends HelloWorld {}; setComponentTemplate( - createTemplate( - `
    {{#each this.numbers key="@index" as |item|}}
  • {{item}}
  • {{/each}}
` + precompileTemplate( + `
    {{#each this.numbers key="@index" as |item|}}
  • {{item}}
  • {{/each}}
`, + { + strictMode: true, + } ), Component ); @@ -53,8 +59,11 @@ QUnit.module('[@glimmer/core] each helper', () => { const Component = class extends HelloWorld {}; setComponentTemplate( - createTemplate( - `
    {{#each this.frozenNumbers key="@index" as |item|}}
  • {{item}}
  • {{/each}}
` + precompileTemplate( + `
    {{#each this.frozenNumbers key="@index" as |item|}}
  • {{item}}
  • {{/each}}
`, + { + strictMode: true, + } ), Component ); @@ -68,8 +77,11 @@ QUnit.module('[@glimmer/core] each helper', () => { const Component = class extends HelloWorld {}; setComponentTemplate( - createTemplate( - `
    {{#each this.strings key="@index" as |item|}}
  • {{item}}
  • {{/each}}
` + precompileTemplate( + `
    {{#each this.strings key="@index" as |item|}}
  • {{item}}
  • {{/each}}
`, + { + strictMode: true, + } ), Component ); @@ -83,8 +95,11 @@ QUnit.module('[@glimmer/core] each helper', () => { const Component = class extends HelloWorld {}; setComponentTemplate( - createTemplate( - `
    {{#each this.frozenStrings key="@index" as |item|}}
  • {{item}}
  • {{/each}}
` + precompileTemplate( + `
    {{#each this.frozenStrings key="@index" as |item|}}
  • {{item}}
  • {{/each}}
`, + { + strictMode: true, + } ), Component ); @@ -98,8 +113,11 @@ QUnit.module('[@glimmer/core] each helper', () => { const Component = class extends HelloWorld {}; setComponentTemplate( - createTemplate( - `
    {{#each this.objects key="@index" as |item|}}
  • {{item.name}}
  • {{/each}}
` + precompileTemplate( + `
    {{#each this.objects key="@index" as |item|}}
  • {{item.name}}
  • {{/each}}
`, + { + strictMode: true, + } ), Component ); @@ -113,8 +131,11 @@ QUnit.module('[@glimmer/core] each helper', () => { const Component = class extends HelloWorld {}; setComponentTemplate( - createTemplate( - `
    {{#each this.frozenObjects key="@index" as |item|}}
  • {{item.name}}
  • {{/each}}
` + precompileTemplate( + `
    {{#each this.frozenObjects key="@index" as |item|}}
  • {{item.name}}
  • {{/each}}
`, + { + strictMode: true, + } ), Component ); diff --git a/packages/@glimmer/core/test/non-interactive/render-test.ts b/packages/@glimmer/core/test/non-interactive/render-test.ts index 9cc1aad8f..f9717124f 100644 --- a/packages/@glimmer/core/test/non-interactive/render-test.ts +++ b/packages/@glimmer/core/test/non-interactive/render-test.ts @@ -5,7 +5,7 @@ import { on, action } from '@glimmer/modifier'; import { setComponentTemplate, - createTemplate, + precompileTemplate, getOwner, templateOnlyComponent, } from '@glimmer/core'; @@ -16,7 +16,10 @@ QUnit.module(`[@glimmer/core] non-interactive rendering tests`, () => { test('it renders a component', async (assert) => { class MyComponent extends Component {} - setComponentTemplate(createTemplate(`

Hello world

`), MyComponent); + setComponentTemplate( + precompileTemplate(`

Hello world

`, { strictMode: true }), + MyComponent + ); const html = await render(MyComponent); assert.strictEqual(html, '

Hello world

', 'the template was rendered'); @@ -26,11 +29,14 @@ QUnit.module(`[@glimmer/core] non-interactive rendering tests`, () => { test('a component can render a nested component', async (assert) => { class OtherComponent extends Component {} - setComponentTemplate(createTemplate(`Hello world`), OtherComponent); + setComponentTemplate(precompileTemplate(`Hello world`, { strictMode: true }), OtherComponent); class MyComponent extends Component {} setComponentTemplate( - createTemplate({ OtherComponent }, `

`), + precompileTemplate(`

`, { + strictMode: true, + scope: { OtherComponent }, + }), MyComponent ); @@ -41,20 +47,23 @@ QUnit.module(`[@glimmer/core] non-interactive rendering tests`, () => { test('a component can render multiple nested components', async (assert) => { class Foo extends Component {} - setComponentTemplate(createTemplate(`Foo`), Foo); + setComponentTemplate(precompileTemplate(`Foo`), Foo); class Bar extends Component {} - setComponentTemplate(createTemplate(`Bar`), Bar); + setComponentTemplate(precompileTemplate(`Bar`), Bar); class OtherComponent extends Component {} setComponentTemplate( - createTemplate({ Foo, Bar }, `Hello world `), + precompileTemplate(`Hello world `, { strictMode: true, scope: { Foo, Bar } }), OtherComponent ); class MyComponent extends Component {} setComponentTemplate( - createTemplate({ OtherComponent }, `

`), + precompileTemplate(`

`, { + strictMode: true, + scope: { OtherComponent }, + }), MyComponent ); @@ -65,7 +74,7 @@ QUnit.module(`[@glimmer/core] non-interactive rendering tests`, () => { test('custom elements are rendered', async function (assert) { const component = setComponentTemplate( - createTemplate('foo'), + precompileTemplate('foo'), templateOnlyComponent() ); @@ -75,7 +84,10 @@ QUnit.module(`[@glimmer/core] non-interactive rendering tests`, () => { test('a component can render with args', async (assert) => { class MyComponent extends Component {} - setComponentTemplate(createTemplate('

{{@say}}

'), MyComponent); + setComponentTemplate( + precompileTemplate('

{{@say}}

', { strictMode: true }), + MyComponent + ); const renderOptions = { args: { @@ -97,15 +109,15 @@ QUnit.module(`[@glimmer/core] non-interactive rendering tests`, () => { } const HelloWorld = setComponentTemplate( - createTemplate('{{yield @name}}!'), + precompileTemplate('{{yield @name}}!'), templateOnlyComponent() ); setComponentTemplate( - createTemplate( - { HelloWorld }, - '{{name}}' - ), + precompileTemplate('{{name}}', { + strictMode: true, + scope: { HelloWorld }, + }), MainComponent ); @@ -132,7 +144,9 @@ QUnit.module(`[@glimmer/core] non-interactive rendering tests`, () => { } setComponentTemplate( - createTemplate('Hello {{if this.pred this.salutation this.alternative}}!'), + precompileTemplate('Hello {{if this.pred this.salutation this.alternative}}!', { + strictMode: true, + }), Main ); @@ -154,14 +168,14 @@ QUnit.module(`[@glimmer/core] non-interactive rendering tests`, () => { // test('can render a component with the component helper', async function(assert) { // const HelloWorld = templateOnlyComponent(); - // setComponentTemplate(HelloWorld, createTemplate('

Hello {{@name}}!

')); + // setComponentTemplate(HelloWorld, precompileTemplate('

Hello {{@name}}!

', { strictMode: true })); // class MainComponent extends Component { // salutation = 'Glimmer'; // HelloWorld = HelloWorld; // } - // setComponentTemplate(MainComponent, createTemplate('{{component this.HelloWorld name=salutation}}')); + // setComponentTemplate(MainComponent, precompileTemplate('{{component this.HelloWorld name=salutation}}', { strictMode: true })); // assert.equal(await render(MainComponent), 'Hello Glimmer!'); // }); @@ -185,7 +199,10 @@ QUnit.module(`[@glimmer/core] non-interactive rendering tests`, () => { } } - setComponentTemplate(createTemplate('

{{this.myLocale}}

'), MyComponent); + setComponentTemplate( + precompileTemplate('

{{this.myLocale}}

', { strictMode: true }), + MyComponent + ); const html = await render(MyComponent, { owner: new Owner(), @@ -197,7 +214,7 @@ QUnit.module(`[@glimmer/core] non-interactive rendering tests`, () => { test('a component can be rendered more than once', async (assert) => { class MyComponent extends Component {} - setComponentTemplate(createTemplate(`

Bump

`), MyComponent); + setComponentTemplate(precompileTemplate(`

Bump

`, { strictMode: true }), MyComponent); let html = await render(MyComponent); assert.strictEqual(html, '

Bump

', 'the component rendered'); @@ -219,9 +236,9 @@ QUnit.module(`[@glimmer/core] non-interactive rendering tests`, () => { } setComponentTemplate( - createTemplate( - { on }, - `` + precompileTemplate( + ``, + { strictMode: true, scope: { on } } ), MyComponent ); @@ -233,7 +250,10 @@ QUnit.module(`[@glimmer/core] non-interactive rendering tests`, () => { test('it can set a dynamic href on an anchor', async (assert) => { class MyComponent extends Component {} - setComponentTemplate(createTemplate(`Link`), MyComponent); + setComponentTemplate( + precompileTemplate(`Link`, { strictMode: true }), + MyComponent + ); const html = await render(MyComponent, { args: { href: 'www.example.com' } }); assert.strictEqual(html, 'Link', 'the template was rendered'); @@ -242,7 +262,10 @@ QUnit.module(`[@glimmer/core] non-interactive rendering tests`, () => { test('it can set a dynamic src on an img', async (assert) => { class MyComponent extends Component {} - setComponentTemplate(createTemplate(``), MyComponent); + setComponentTemplate( + precompileTemplate(``, { strictMode: true }), + MyComponent + ); const html = await render(MyComponent, { args: { src: './logo.svg' } }); assert.strictEqual(html, '', 'the template was rendered'); diff --git a/packages/@glimmer/core/test/non-interactive/to-bool-test.ts b/packages/@glimmer/core/test/non-interactive/to-bool-test.ts index f30f57b61..4be0f7a76 100644 --- a/packages/@glimmer/core/test/non-interactive/to-bool-test.ts +++ b/packages/@glimmer/core/test/non-interactive/to-bool-test.ts @@ -1,6 +1,6 @@ import Component from '@glimmer/component'; -import { setComponentTemplate, createTemplate } from '@glimmer/core'; +import { setComponentTemplate, precompileTemplate } from '@glimmer/core'; import { test, render } from '../utils'; @@ -13,7 +13,9 @@ QUnit.module(`[@glimmer/core] non-interactive rendering tests`, () => { } setComponentTemplate( - createTemplate('Hello {{if this.pred this.salutation this.alternative}}!'), + precompileTemplate('Hello {{if this.pred this.salutation this.alternative}}!', { + strictMode: true, + }), Main ); @@ -26,7 +28,9 @@ QUnit.module(`[@glimmer/core] non-interactive rendering tests`, () => { } setComponentTemplate( - createTemplate('Hello {{#if this.pred}}Glimmer{{else}}Glimmer.js{{/if}}!'), + precompileTemplate('Hello {{#if this.pred}}Glimmer{{else}}Glimmer.js{{/if}}!', { + strictMode: true, + }), Main ); diff --git a/packages/@glimmer/core/test/utils.ts b/packages/@glimmer/core/test/utils.ts index 78c3b2a50..7ae52394a 100644 --- a/packages/@glimmer/core/test/utils.ts +++ b/packages/@glimmer/core/test/utils.ts @@ -7,7 +7,7 @@ import { templateOnlyComponent, } from '..'; import { renderToString } from '@glimmer/ssr'; -import { SerializedTemplateWithLazyBlock } from '@glimmer/interfaces'; +import { TemplateFactory } from '@glimmer/interfaces'; import { tracked as glimmerTracked } from '@glimmer/tracking'; import TrackedObject from './utils/tracked-object'; @@ -17,10 +17,10 @@ export const test = QUnit.test; const IS_INTERACTIVE = typeof document !== 'undefined'; export async function render( - component: ComponentDefinition | SerializedTemplateWithLazyBlock, + component: ComponentDefinition | TemplateFactory, options?: HTMLElement | Partial ): Promise { - if ('id' in component && 'block' in component) { + if ('__meta' in component) { const template = component; component = setComponentTemplate(template, templateOnlyComponent()); diff --git a/packages/@glimmer/debug/index.ts b/packages/@glimmer/debug/index.ts new file mode 100644 index 000000000..c76092b3d --- /dev/null +++ b/packages/@glimmer/debug/index.ts @@ -0,0 +1 @@ +export { assert, deprecate } from '@glimmer/global-context'; diff --git a/packages/@glimmer/debug/package.json b/packages/@glimmer/debug/package.json new file mode 100644 index 000000000..f5fb7b190 --- /dev/null +++ b/packages/@glimmer/debug/package.json @@ -0,0 +1,18 @@ +{ + "name": "@glimmer/debug", + "version": "2.0.0-beta.12", + "description": "Debug Functionality", + "main": "dist/commonjs/index.js", + "module": "dist/modules/index.js", + "repository": "https://github.com/glimmerjs/glimmer.js/tree/master/packages/@glimmer/debug", + "author": "Tom Dale ", + "license": "MIT", + "private": false, + "dependencies": { + "@glimmer/global-context": "0.77.3" + }, + "volta": { + "node": "12.16.1", + "yarn": "1.22.4" + } +} diff --git a/packages/@glimmer/ssr/test/modifiers-test.ts b/packages/@glimmer/ssr/test/modifiers-test.ts index 33bd3ce44..22615cc44 100644 --- a/packages/@glimmer/ssr/test/modifiers-test.ts +++ b/packages/@glimmer/ssr/test/modifiers-test.ts @@ -1,6 +1,6 @@ import { setComponentTemplate, - createTemplate, + precompileTemplate, templateOnlyComponent, setModifierManager, modifierCapabilities, @@ -45,7 +45,10 @@ QUnit.module('@glimmer/ssr modifiers', () => { const Component = templateOnlyComponent(); setComponentTemplate( - createTemplate({ modifier: Modifier }, '

hello world

'), + precompileTemplate('

hello world

', { + strictMode: true, + scope: { Modifier }, + }), Component ); diff --git a/packages/@glimmer/ssr/test/render-options-tests.ts b/packages/@glimmer/ssr/test/render-options-tests.ts index e0c503fb5..41467ed2f 100644 --- a/packages/@glimmer/ssr/test/render-options-tests.ts +++ b/packages/@glimmer/ssr/test/render-options-tests.ts @@ -1,5 +1,5 @@ import Component from '@glimmer/component'; -import { setComponentTemplate, createTemplate } from '@glimmer/core'; +import { setComponentTemplate, precompileTemplate } from '@glimmer/core'; import HTMLSerializer from '@simple-dom/serializer'; import voidMap from '@simple-dom/void-map'; import { SerializableNode } from '@simple-dom/interface'; @@ -17,7 +17,10 @@ QUnit.module('@glimmer/ssr rendering', () => { const options: RenderOptions = { serializer: new CustomHTMLSerializer(voidMap) }; - setComponentTemplate(createTemplate(`

Hello World

`), MyComponent); + setComponentTemplate( + precompileTemplate(`

Hello World

`, { strictMode: true }), + MyComponent + ); const output = await renderToString(MyComponent, options); @@ -26,7 +29,10 @@ QUnit.module('@glimmer/ssr rendering', () => { QUnit.test('setting rehydrate option outputs the block stacks', async (assert) => { class MyComponent extends Component {} - setComponentTemplate(createTemplate(`

Hello World

`), MyComponent); + setComponentTemplate( + precompileTemplate(`

Hello World

`, { strictMode: true }), + MyComponent + ); const output = await renderToString(MyComponent, { rehydrate: true }); assert.equal( diff --git a/packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/index.js b/packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/index.js deleted file mode 100644 index 930a14913..000000000 --- a/packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/index.js +++ /dev/null @@ -1,25 +0,0 @@ -const babelDebugMacros = require('babel-plugin-debug-macros'); - -module.exports = function macros(babel, options) { - const debugMacros = babelDebugMacros(babel, options); - - const originalProgram = debugMacros.visitor.Program; - - debugMacros.visitor.Program = { - enter(path, state) { - const DEBUG = 'DEBUG' in state.opts ? state.opts.DEBUG : true; - - state.opts = { - flags: [{ source: '@glimmer/env', flags: { DEBUG } }], - }; - - originalProgram.enter.call(this, path, state); - }, - - exit(path, state) { - originalProgram.exit.call(this, path, state); - }, - }; - - return debugMacros; -}; diff --git a/packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/package.json b/packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/package.json deleted file mode 100644 index 9a7445b50..000000000 --- a/packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/package.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name": "@glimmer/babel-plugin-glimmer-env", - "version": "2.0.0-beta.12", - "description": "Compiles Glimmer component templates", - "repository": "https://github.com/glimmerjs/glimmer.js", - "author": "Tom Dale ", - "license": "MIT", - "private": false, - "scripts": { - "test": "mocha -r esm" - }, - "dependencies": { - "@babel/core": "^7.5.5", - "babel-plugin-debug-macros": "^0.3.3" - }, - "devDependencies": { - "@babel/preset-env": "^7.8.3", - "babel-plugin-tester": "^6.4.0", - "esm": "^3.2.25", - "mocha": "^6.2.0" - }, - "volta": { - "node": "12.16.1", - "yarn": "1.22.4" - } -} diff --git a/packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/test/fixtures/basic/code.js b/packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/test/fixtures/basic/code.js deleted file mode 100644 index 36f4a4fcf..000000000 --- a/packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/test/fixtures/basic/code.js +++ /dev/null @@ -1,5 +0,0 @@ -import { DEBUG } from '@glimmer/env'; - -if (DEBUG) { - console.log('foo'); -} diff --git a/packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/test/fixtures/basic/output.js b/packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/test/fixtures/basic/output.js deleted file mode 100644 index cf3d796f3..000000000 --- a/packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/test/fixtures/basic/output.js +++ /dev/null @@ -1,5 +0,0 @@ -if (true -/* DEBUG */ -) { - console.log('foo'); -} diff --git a/packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/test/fixtures/explicit-false/.babelrc b/packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/test/fixtures/explicit-false/.babelrc deleted file mode 100644 index 45af997ab..000000000 --- a/packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/test/fixtures/explicit-false/.babelrc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "plugins": [ - ["@glimmer/babel-plugin-glimmer-env", { "DEBUG": false }] - ] -} diff --git a/packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/test/fixtures/explicit-false/code.js b/packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/test/fixtures/explicit-false/code.js deleted file mode 100644 index 36f4a4fcf..000000000 --- a/packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/test/fixtures/explicit-false/code.js +++ /dev/null @@ -1,5 +0,0 @@ -import { DEBUG } from '@glimmer/env'; - -if (DEBUG) { - console.log('foo'); -} diff --git a/packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/test/fixtures/explicit-false/output.js b/packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/test/fixtures/explicit-false/output.js deleted file mode 100644 index b707e117a..000000000 --- a/packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/test/fixtures/explicit-false/output.js +++ /dev/null @@ -1,5 +0,0 @@ -if (false -/* DEBUG */ -) { - console.log('foo'); -} diff --git a/packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/test/fixtures/explicit-true/.babelrc b/packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/test/fixtures/explicit-true/.babelrc deleted file mode 100644 index f1b39b4e9..000000000 --- a/packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/test/fixtures/explicit-true/.babelrc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "plugins": [ - ["@glimmer/babel-plugin-glimmer-env", { "DEBUG": true }] - ] -} diff --git a/packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/test/fixtures/explicit-true/code.js b/packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/test/fixtures/explicit-true/code.js deleted file mode 100644 index 36f4a4fcf..000000000 --- a/packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/test/fixtures/explicit-true/code.js +++ /dev/null @@ -1,5 +0,0 @@ -import { DEBUG } from '@glimmer/env'; - -if (DEBUG) { - console.log('foo'); -} diff --git a/packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/test/fixtures/explicit-true/output.js b/packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/test/fixtures/explicit-true/output.js deleted file mode 100644 index cf3d796f3..000000000 --- a/packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/test/fixtures/explicit-true/output.js +++ /dev/null @@ -1,5 +0,0 @@ -if (true -/* DEBUG */ -) { - console.log('foo'); -} diff --git a/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/index.js b/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/index.js deleted file mode 100644 index 7a55f4d27..000000000 --- a/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/index.js +++ /dev/null @@ -1,156 +0,0 @@ -const { precompile } = require('@glimmer/compiler'); -const { parse } = require('@babel/parser'); -const { default: generate } = require('@babel/generator'); -const t = require('@babel/types'); - -module.exports = function strictTemplatePrecompile(babel, options) { - const { types: t, parse } = babel; - const { precompile: precompileOptions } = options || {}; - - return { - name: 'babel-plugin-strict-template-precompile', - visitor: { - ImportSpecifier(path, state) { - if (state.templateImportId || path.parent.source.value !== '@glimmer/core') { - return; - } - const importedName = path.node.imported.name; - const localName = path.node.local.name; - - if (importedName === 'createTemplate') { - state.templateImportId = localName; - - // remove the createTemplate named import - if (path.parentPath.node.specifiers.length > 1) { - path.remove(); - } else { - path.parentPath.remove(); - } - } - }, - - CallExpression(path, state) { - if (!state.templateImportId || path.node.callee.name !== state.templateImportId) { - return; - } - - if (path.node.arguments.length === 0 || path.node.arguments.length > 2) { - throw new Error('`createTemplate()` must receive exactly one or two arguments'); - } - - let scopePath, templatePath; - - if (path.node.arguments.length === 1) { - templatePath = path.get('arguments.0'); - } else { - scopePath = path.get('arguments.0'); - templatePath = path.get('arguments.1'); - } - - let scope; - - if (scopePath) { - if (scopePath.type !== 'ObjectExpression') { - throw new Error( - `createTemplate() must receive an object literal with all of the imported values for the template as its scope parameter, received: ${scopePath.type}` - ); - } - - scope = scopePath.node; - } else { - scope = t.objectExpression([]); - } - - const { type } = templatePath.node; - - if (type === 'TemplateLiteral' || type === 'StringLiteral') { - let templateString; - - if (type === 'TemplateLiteral') { - if (templatePath.node.quasis.length > 1 || templatePath.node.expressions.length > 0) { - throw new Error( - 'template strings passed to the `createTemplate()` function may not have any dynamic segments' - ); - } - - templateString = templatePath.node.quasis[0].value.raw; - } else { - templateString = templatePath.node.value; - } - - const ast = _precompileTemplate(parse, templateString, scope, precompileOptions); - - path.replaceWith(ast.program.body[0].expression); - } else { - throw new Error(`createTemplate() must receive a template string, received: ${type}`); - } - }, - }, - }; -}; - -function _precompileTemplate(parse, templateString, scopeNode, precompileOptions) { - const localsMap = scopeNode.properties.reduce((map, property) => { - // Object keys can either be identifiers or literals - const keyName = t.isIdentifier(property.key) - ? property.key.name - : property.key.value.toString(); - if (!t.isIdentifier(property.value)) { - throw new Error( - `Currently the babel-plugin-strict-template-precompile only supports identifiers as values for the imported values object literal. Received: ${property.value.type}` - ); - } - map[keyName] = property.value.name; - return map; - }, {}); - - const compiled = precompile(templateString, { - ...precompileOptions, - strictMode: true, - locals: Object.keys(localsMap), - }); - const ast = parse(`(${compiled})`); - - t.traverseFast(ast, (node) => { - if ( - t.isObjectProperty(node) && - node.key.value === 'scope' && - t.isArrowFunctionExpression(node.value) - ) { - const scopeFnNode = node.value; - const scopeArray = scopeFnNode.body.elements; - scopeArray.forEach((scopeElementNode) => { - if ( - t.isIdentifier(scopeElementNode) && - scopeElementNode.name !== localsMap[scopeElementNode.name] - ) { - scopeElementNode.name = localsMap[scopeElementNode.name]; - } - }); - } - }); - - return ast; -} - -/** - * Allows users to programmatically precompile a template given a list of import - * identifiers and the template string. This is meant for usage in custom - * template transforms and formats. - * - * @public - * @param template string - the template to be compiled - * @param importIdentifiers string[] - the identifiers to import - * @param precompileOptions object - the options to be passed to the compiler - */ -function precompileTemplate(templateString, importIdentifiers = [], precompileOptions = {}) { - const scope = t.objectExpression( - importIdentifiers.map((id) => t.objectProperty(t.identifier(id), t.identifier(id))) - ); - - let ast = _precompileTemplate(parse, templateString, scope, precompileOptions); - - return generate(ast).code; -} -// TODO: Is this still required with the new strict mode precompile function from the vm? -module.exports.precompileTemplate = precompileTemplate; diff --git a/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures-options/errors/non-existent-component/code.js b/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures-options/errors/non-existent-component/code.js deleted file mode 100644 index 93aa35a8c..000000000 --- a/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures-options/errors/non-existent-component/code.js +++ /dev/null @@ -1,3 +0,0 @@ -import { createTemplate } from '@glimmer/core'; - -createTemplate(``); diff --git a/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures-options/precompile/ast-transform/code.js b/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures-options/precompile/ast-transform/code.js deleted file mode 100644 index 65dd9ac17..000000000 --- a/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures-options/precompile/ast-transform/code.js +++ /dev/null @@ -1,3 +0,0 @@ -import { createTemplate } from '@glimmer/core'; - -createTemplate('{{bad}}

Hello world

'); diff --git a/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures-options/precompile/ast-transform/options.js b/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures-options/precompile/ast-transform/options.js deleted file mode 100644 index 5434570f8..000000000 --- a/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures-options/precompile/ast-transform/options.js +++ /dev/null @@ -1,27 +0,0 @@ -// babel-plugin-test only supports options as an options.json file, -// so we have to manually pass this through to our fixture. - -const precompileOptions = { - meta: {}, - plugins: { - ast: [ - () => { - return { - name: 'remove-bad-helper', - visitor: { - MustacheStatement(node) { - if (node.path.original == 'bad') { - return null; - } - }, - }, - }; - }, - ], - }, - mode: 'precompile', -}; - -export default { - precompile: precompileOptions, -}; diff --git a/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures-options/precompile/ast-transform/output.js b/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures-options/precompile/ast-transform/output.js deleted file mode 100644 index 6cabcdfb9..000000000 --- a/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures-options/precompile/ast-transform/output.js +++ /dev/null @@ -1,7 +0,0 @@ -({ - "id": null, - "block": "[[[10,\"h1\"],[12],[1,\"Hello world\"],[13]],[],false,[]]", - "moduleName": "(unknown template module)", - "scope": null, - "isStrictMode": true -}); diff --git a/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures/custom-imports/code.js b/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures/custom-imports/code.js deleted file mode 100644 index 6316d0486..000000000 --- a/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures/custom-imports/code.js +++ /dev/null @@ -1,4 +0,0 @@ -import { createTemplate as foo } from '@glimmer/core'; -import Component from './component'; - -foo({ Component }, ``); diff --git a/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures/custom-imports/output.js b/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures/custom-imports/output.js deleted file mode 100644 index 2b7b0f360..000000000 --- a/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures/custom-imports/output.js +++ /dev/null @@ -1,8 +0,0 @@ -import Component from './component'; -({ - "id": null, - "block": "[[[8,[32,0],null,null,null]],[],false,[]]", - "moduleName": "(unknown template module)", - "scope": () => [Component], - "isStrictMode": true -}); diff --git a/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures/first-parameter/code.js b/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures/first-parameter/code.js deleted file mode 100644 index 61a297625..000000000 --- a/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures/first-parameter/code.js +++ /dev/null @@ -1,5 +0,0 @@ -import { createTemplate } from '@glimmer/core'; - -createTemplate(`

Hello World

`); - -createTemplate('

Hello World

'); diff --git a/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures/first-parameter/output.js b/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures/first-parameter/output.js deleted file mode 100644 index 6482b76f4..000000000 --- a/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures/first-parameter/output.js +++ /dev/null @@ -1,14 +0,0 @@ -({ - "id": null, - "block": "[[[10,\"h1\"],[12],[1,\"Hello World\"],[13]],[],false,[]]", - "moduleName": "(unknown template module)", - "scope": null, - "isStrictMode": true -}); -({ - "id": null, - "block": "[[[10,\"h1\"],[12],[1,\"Hello World\"],[13]],[],false,[]]", - "moduleName": "(unknown template module)", - "scope": null, - "isStrictMode": true -}); diff --git a/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures/rename-scope-variable/code.js b/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures/rename-scope-variable/code.js deleted file mode 100644 index 9fecc88b8..000000000 --- a/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures/rename-scope-variable/code.js +++ /dev/null @@ -1,4 +0,0 @@ -import { createTemplate } from '@glimmer/core'; -import Component from './component'; - -createTemplate({ MyComponent: Component }, ``); diff --git a/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures/rename-scope-variable/output.js b/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures/rename-scope-variable/output.js deleted file mode 100644 index 2b7b0f360..000000000 --- a/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures/rename-scope-variable/output.js +++ /dev/null @@ -1,8 +0,0 @@ -import Component from './component'; -({ - "id": null, - "block": "[[[8,[32,0],null,null,null]],[],false,[]]", - "moduleName": "(unknown template module)", - "scope": () => [Component], - "isStrictMode": true -}); diff --git a/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures/second-parameter/code.js b/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures/second-parameter/code.js deleted file mode 100644 index f7e23614c..000000000 --- a/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures/second-parameter/code.js +++ /dev/null @@ -1,6 +0,0 @@ -import { createTemplate } from '@glimmer/core'; -import Component from './component'; - -createTemplate({ Component }, ``); - -createTemplate({ Component }, ''); diff --git a/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures/second-parameter/output.js b/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures/second-parameter/output.js deleted file mode 100644 index 9f002f541..000000000 --- a/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/fixtures/second-parameter/output.js +++ /dev/null @@ -1,15 +0,0 @@ -import Component from './component'; -({ - "id": null, - "block": "[[[8,[32,0],null,null,null]],[],false,[]]", - "moduleName": "(unknown template module)", - "scope": () => [Component], - "isStrictMode": true -}); -({ - "id": null, - "block": "[[[8,[32,0],null,null,null]],[],false,[]]", - "moduleName": "(unknown template module)", - "scope": () => [Component], - "isStrictMode": true -}); diff --git a/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/index.js b/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/index.js deleted file mode 100644 index 3777b8eaa..000000000 --- a/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test/index.js +++ /dev/null @@ -1,72 +0,0 @@ -import plugin, { precompileTemplate } from '..'; -import pluginTester from 'babel-plugin-tester'; -import path from 'path'; -import astTransformTestPluginOptions from './fixtures-options/precompile/ast-transform/options'; -import { expect } from 'chai'; - -// For correct .babelrc detection inside the fixture directory we need to force babel's cwd and root to be the package root. -// This will ensure that the tests will run correctly from the mono repo root or package root. -const packageRootPath = path.resolve(__dirname, '..'); - -pluginTester({ - plugin, - babelOptions: { - cwd: packageRootPath, - root: packageRootPath, - }, - fixtures: path.join(__dirname, 'fixtures'), - tests: [ - { - title: 'options.precompile : ast transfrom', - fixture: path.join(__dirname, 'fixtures-options/precompile/ast-transform/code.js'), - outputFixture: path.join(__dirname, 'fixtures-options/precompile/ast-transform/output.js'), - pluginOptions: astTransformTestPluginOptions, - }, - { - fixture: path.join(__dirname, 'fixtures-options/errors/non-existent-component/code.js'), - error: /Attempted to invoke a component that was not in scope in a strict mode template, ``. If you wanted to create an element with that name, convert it to lowercase - ``/, - }, - ], -}); - -describe('precompileTemplate', () => { - it('works for basic templates', () => { - let precompiled = precompileTemplate(`

Hello World

`); - - expect(precompiled).to.equal(`({ - "id": null, - "block": "[[[10,\\"h1\\"],[12],[1,\\"Hello World\\"],[13]],[],false,[]]", - "moduleName": "(unknown template module)", - "scope": null, - "isStrictMode": true -});`); - }); - - it('works with imports', () => { - let precompiled = precompileTemplate(``, ['Component']); - - expect(precompiled).to.equal(`({ - "id": null, - "block": "[[[8,[32,0],null,null,null]],[],false,[]]", - "moduleName": "(unknown template module)", - "scope": () => [Component], - "isStrictMode": true -});`); - }); - - it('can apply precompile transforms', () => { - let precompiled = precompileTemplate( - '{{bad}}

Hello world

', - [], - astTransformTestPluginOptions.precompile - ); - - expect(precompiled).to.equal(`({ - "id": null, - "block": "[[[10,\\"h1\\"],[12],[1,\\"Hello world\\"],[13]],[],false,[]]", - "moduleName": "(unknown template module)", - "scope": null, - "isStrictMode": true -});`); - }); -}); diff --git a/packages/babel-plugins/@glimmer/babel-preset/index.js b/packages/babel-plugins/@glimmer/babel-preset/index.js new file mode 100644 index 000000000..43d742346 --- /dev/null +++ b/packages/babel-plugins/@glimmer/babel-preset/index.js @@ -0,0 +1,62 @@ +const generateVmPlugins = require('@glimmer/vm-babel-plugins'); + +function defaultTo(value, defaultVal) { + return value === undefined ? defaultVal : value; +} + +module.exports = function (api, options) { + let isDebug = defaultTo(options.isDebug, api.environment ? !api.environment('production') : true); + let __customInlineTemplateModules = defaultTo(options.__customInlineTemplateModules, {}); + + return { + plugins: [ + ...generateVmPlugins({ isDebug }), + + [ + require.resolve('babel-plugin-debug-macros'), + { + debugTools: { + source: '@glimmer/debug', + isDebug, + }, + externalizeHelpers: { + module: true, + }, + }, + 'glimmer-debug-macros', + ], + + [ + require.resolve('babel-plugin-htmlbars-inline-precompile'), + { + templateCompilerPath: require.resolve('@glimmer/compiler'), + isProduction: !isDebug, + ensureModuleApiPolyfill: false, + moduleOverrides: { + '@ember/component/template-only': { + default: ['templateOnlyComponent', '@glimmer/core'], + }, + '@ember/template-factory': { + createTemplateFactory: ['createTemplateFactory', '@glimmer/core'], + }, + '@ember/component': { + setComponentTemplate: ['setComponentTemplate', '@glimmer/core'], + }, + }, + modules: { + ...__customInlineTemplateModules, + '@glimmer/core': { + export: 'precompileTemplate', + disableTemplateLiteral: true, + shouldParseScope: true, + }, + }, + }, + 'glimmer-inline-precompile', + ], + + [require.resolve('@babel/plugin-proposal-decorators'), { legacy: true }], + require.resolve('@babel/plugin-proposal-class-properties'), + ], + }; +}; diff --git a/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/package.json b/packages/babel-plugins/@glimmer/babel-preset/package.json similarity index 54% rename from packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/package.json rename to packages/babel-plugins/@glimmer/babel-preset/package.json index 77ea7a6c3..d9358986e 100644 --- a/packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/package.json +++ b/packages/babel-plugins/@glimmer/babel-preset/package.json @@ -1,7 +1,7 @@ { - "name": "@glimmer/babel-plugin-strict-template-precompile", + "name": "@glimmer/babel-preset", "version": "2.0.0-beta.12", - "description": "Compiles Glimmer component templates", + "description": "Glimmer.js Babel Preset", "repository": "https://github.com/glimmerjs/glimmer.js", "author": "Tom Dale ", "license": "MIT", @@ -10,15 +10,14 @@ "test": "mocha -r esm" }, "dependencies": { - "@babel/core": "^7.5.5", - "@babel/generator": "^7.9.4", - "@babel/helper-module-imports": "^7.0.0", - "@babel/parser": "^7.9.4", - "@babel/types": "^7.9.0", - "@glimmer/compiler": "0.77.3" + "@babel/plugin-proposal-class-properties": "^7.8.3", + "@babel/plugin-proposal-decorators": "^7.8.3", + "@glimmer/compiler": "0.77.3", + "@glimmer/vm-babel-plugins": "0.77.3", + "babel-plugin-debug-macros": "^0.3.4", + "babel-plugin-htmlbars-inline-precompile": "^5.0.0" }, "devDependencies": { - "@babel/preset-env": "^7.8.3", "babel-plugin-tester": "^6.4.0", "chai": "^4.2.0", "esm": "^3.2.25", diff --git a/packages/babel-plugins/@glimmer/babel-preset/test/fixtures/debug/.babelrc b/packages/babel-plugins/@glimmer/babel-preset/test/fixtures/debug/.babelrc new file mode 100644 index 000000000..c74aa0d9f --- /dev/null +++ b/packages/babel-plugins/@glimmer/babel-preset/test/fixtures/debug/.babelrc @@ -0,0 +1,5 @@ +{ + "presets": [ + ["@glimmer/babel-preset", { "isDebug": true }] + ] +} diff --git a/packages/babel-plugins/@glimmer/babel-preset/test/fixtures/debug/code.js b/packages/babel-plugins/@glimmer/babel-preset/test/fixtures/debug/code.js new file mode 100644 index 000000000..490e5ed30 --- /dev/null +++ b/packages/babel-plugins/@glimmer/babel-preset/test/fixtures/debug/code.js @@ -0,0 +1,18 @@ +import { DEBUG } from '@glimmer/env'; +import { assert, deprecate } from '@glimmer/debug'; +import { precompileTemplate } from '@glimmer/core'; +import { tracked } from '@glimmer/tracking'; + +if (DEBUG) { + console.log('DEBUG!'); +} + +assert(true, 'is true'); +deprecate('this is deprecated', false, { id: 'foo' }); + + +class Test { + @tracked bar = 123; +} + +precompileTemplate('Hello, world!', { strictMode: true, scope: { Test } }); diff --git a/packages/babel-plugins/@glimmer/babel-preset/test/fixtures/debug/output.js b/packages/babel-plugins/@glimmer/babel-preset/test/fixtures/debug/output.js new file mode 100644 index 000000000..fef94e2cf --- /dev/null +++ b/packages/babel-plugins/@glimmer/babel-preset/test/fixtures/debug/output.js @@ -0,0 +1,50 @@ +var _class, _descriptor, _temp; + +import { createTemplateFactory as _createTemplateFactory } from "@glimmer/core"; + +function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); } + +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } + +function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; } + +function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'proposal-class-properties is enabled and runs after the decorators transform.'); } + +import { assert, deprecate } from '@glimmer/debug'; +import { tracked } from '@glimmer/tracking'; + +if (true +/* DEBUG */ +) { + console.log('DEBUG!'); +} + +(true && assert(true, 'is true')); +(true && !(false) && deprecate('this is deprecated', false, { + id: 'foo' +})); +let Test = (_class = (_temp = class Test { + constructor() { + _initializerDefineProperty(this, "bar", _descriptor, this); + } + +}, _temp), (_descriptor = _applyDecoratedDescriptor(_class.prototype, "bar", [tracked], { + configurable: true, + enumerable: true, + writable: true, + initializer: function () { + return 123; + } +})), _class); + +_createTemplateFactory( +/* + Hello, world! +*/ +{ + "id": null, + "block": "[[[1,\"Hello, world!\"]],[],false,[]]", + "moduleName": "(unknown template module)", + "scope": null, + "isStrictMode": true +}); diff --git a/packages/babel-plugins/@glimmer/babel-preset/test/fixtures/production/.babelrc b/packages/babel-plugins/@glimmer/babel-preset/test/fixtures/production/.babelrc new file mode 100644 index 000000000..3b1e4c063 --- /dev/null +++ b/packages/babel-plugins/@glimmer/babel-preset/test/fixtures/production/.babelrc @@ -0,0 +1,5 @@ +{ + "presets": [ + ["@glimmer/babel-preset", { "isDebug": false }] + ] +} diff --git a/packages/babel-plugins/@glimmer/babel-preset/test/fixtures/production/code.js b/packages/babel-plugins/@glimmer/babel-preset/test/fixtures/production/code.js new file mode 100644 index 000000000..490e5ed30 --- /dev/null +++ b/packages/babel-plugins/@glimmer/babel-preset/test/fixtures/production/code.js @@ -0,0 +1,18 @@ +import { DEBUG } from '@glimmer/env'; +import { assert, deprecate } from '@glimmer/debug'; +import { precompileTemplate } from '@glimmer/core'; +import { tracked } from '@glimmer/tracking'; + +if (DEBUG) { + console.log('DEBUG!'); +} + +assert(true, 'is true'); +deprecate('this is deprecated', false, { id: 'foo' }); + + +class Test { + @tracked bar = 123; +} + +precompileTemplate('Hello, world!', { strictMode: true, scope: { Test } }); diff --git a/packages/babel-plugins/@glimmer/babel-preset/test/fixtures/production/output.js b/packages/babel-plugins/@glimmer/babel-preset/test/fixtures/production/output.js new file mode 100644 index 000000000..ee4cfde20 --- /dev/null +++ b/packages/babel-plugins/@glimmer/babel-preset/test/fixtures/production/output.js @@ -0,0 +1,50 @@ +var _class, _descriptor, _temp; + +import { createTemplateFactory as _createTemplateFactory } from "@glimmer/core"; + +function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); } + +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } + +function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; } + +function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'proposal-class-properties is enabled and runs after the decorators transform.'); } + +import { assert, deprecate } from '@glimmer/debug'; +import { tracked } from '@glimmer/tracking'; + +if (false +/* DEBUG */ +) { + console.log('DEBUG!'); +} + +(false && assert(true, 'is true')); +(false && !(false) && deprecate('this is deprecated', false, { + id: 'foo' +})); +let Test = (_class = (_temp = class Test { + constructor() { + _initializerDefineProperty(this, "bar", _descriptor, this); + } + +}, _temp), (_descriptor = _applyDecoratedDescriptor(_class.prototype, "bar", [tracked], { + configurable: true, + enumerable: true, + writable: true, + initializer: function () { + return 123; + } +})), _class); + +_createTemplateFactory( +/* + Hello, world! +*/ +{ + "id": null, + "block": "[[[1,\"Hello, world!\"]],[],false,[]]", + "moduleName": "(unknown template module)", + "scope": null, + "isStrictMode": true +}); diff --git a/packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/test/index.js b/packages/babel-plugins/@glimmer/babel-preset/test/index.js similarity index 88% rename from packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/test/index.js rename to packages/babel-plugins/@glimmer/babel-preset/test/index.js index 94e04164c..7e770f0a2 100644 --- a/packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/test/index.js +++ b/packages/babel-plugins/@glimmer/babel-preset/test/index.js @@ -1,4 +1,3 @@ -import plugin from '..'; import pluginTester from 'babel-plugin-tester'; import path from 'path'; @@ -7,7 +6,11 @@ import path from 'path'; const packageRootPath = path.resolve(__dirname, '..'); pluginTester({ - plugin, + plugin() { + return { + name: 'dummy plugin', + }; + }, babelOptions: { cwd: packageRootPath, root: packageRootPath, diff --git a/packages/example-apps/basic/src/MyComponent.ts b/packages/example-apps/basic/src/MyComponent.ts index 4ffcae4d5..c99aa4050 100644 --- a/packages/example-apps/basic/src/MyComponent.ts +++ b/packages/example-apps/basic/src/MyComponent.ts @@ -1,7 +1,7 @@ import Component from '@glimmer/component'; import { tracked } from '@glimmer/tracking'; import { - createTemplate, + precompileTemplate, setComponentTemplate, getOwner, templateOnlyComponent, @@ -27,7 +27,9 @@ const isCJK = helper(function (_args, _hash, services) { }); const TemplateOnlyComponent = setComponentTemplate( - createTemplate(`

I am rendered by a template only component: {{@name}}

`), + precompileTemplate(`

I am rendered by a template only component: {{@name}}

`, { + strictMode: true, + }), templateOnlyComponent() ); @@ -46,8 +48,7 @@ class MyComponent extends Component { } setComponentTemplate( - createTemplate( - { OtherComponent, TemplateOnlyComponent, myHelper, isCJK, on }, + precompileTemplate( `

Hello {{this.message}}


{{myHelper "foo" greeting="Hello"}} @@ -61,7 +62,8 @@ setComponentTemplate( - ` + `, + { strictMode: true, scope: { OtherComponent, TemplateOnlyComponent, myHelper, isCJK, on } } ), MyComponent ); diff --git a/packages/example-apps/basic/src/OtherComponent.ts b/packages/example-apps/basic/src/OtherComponent.ts index 2bbf37a14..6e29b3311 100644 --- a/packages/example-apps/basic/src/OtherComponent.ts +++ b/packages/example-apps/basic/src/OtherComponent.ts @@ -1,6 +1,9 @@ import Component from '@glimmer/component'; -import { createTemplate, setComponentTemplate } from '@glimmer/core'; +import { precompileTemplate, setComponentTemplate } from '@glimmer/core'; export default class OtherComponent extends Component {} -setComponentTemplate(createTemplate(`Counter Val: {{@count}}`), OtherComponent); +setComponentTemplate( + precompileTemplate(`Counter Val: {{@count}}`, { strictMode: true }), + OtherComponent +); diff --git a/packages/example-apps/partial-rehydration/src/RehydratableCounter.ts b/packages/example-apps/partial-rehydration/src/RehydratableCounter.ts index 9fd23e703..8529ad1fe 100644 --- a/packages/example-apps/partial-rehydration/src/RehydratableCounter.ts +++ b/packages/example-apps/partial-rehydration/src/RehydratableCounter.ts @@ -1,6 +1,6 @@ import Component from '@glimmer/component'; import { tracked } from '@glimmer/tracking'; -import { createTemplate, setComponentTemplate } from '@glimmer/core'; +import { precompileTemplate, setComponentTemplate } from '@glimmer/core'; import { on, action } from '@glimmer/modifier'; import RehydratableRegion from './RehydratableRegion'; @@ -13,15 +13,15 @@ class RehydratableCounter extends Component { } setComponentTemplate( - createTemplate( - { on, RehydratableRegion }, + precompileTemplate( `

{{@message}}

{{@foo.bar}}

You have clicked the button {{this.count}} times.

- ` + `, + { strictMode: true, scope: { on, RehydratableRegion } } ), RehydratableCounter ); diff --git a/packages/example-apps/partial-rehydration/src/RehydratableRegion.ts b/packages/example-apps/partial-rehydration/src/RehydratableRegion.ts index 425fc5706..0bbc95ca1 100644 --- a/packages/example-apps/partial-rehydration/src/RehydratableRegion.ts +++ b/packages/example-apps/partial-rehydration/src/RehydratableRegion.ts @@ -1,17 +1,17 @@ -import { createTemplate, setComponentTemplate, templateOnlyComponent } from '@glimmer/core'; +import { precompileTemplate, setComponentTemplate, templateOnlyComponent } from '@glimmer/core'; function toJSON(args): string { return JSON.stringify(args); } export default setComponentTemplate( - createTemplate( - { toJSON }, + precompileTemplate( `
{{yield}}
- ` + `, + { strictMode: true, scope: { toJSON } } ), templateOnlyComponent() ); diff --git a/packages/example-apps/partial-rehydration/src/StaticComponent.ts b/packages/example-apps/partial-rehydration/src/StaticComponent.ts index a4ca2d770..d9e27ef98 100644 --- a/packages/example-apps/partial-rehydration/src/StaticComponent.ts +++ b/packages/example-apps/partial-rehydration/src/StaticComponent.ts @@ -1,9 +1,8 @@ -import { createTemplate, setComponentTemplate, templateOnlyComponent } from '@glimmer/core'; +import { precompileTemplate, setComponentTemplate, templateOnlyComponent } from '@glimmer/core'; import RehydratableCounter from './RehydratableCounter'; const StaticComponent = setComponentTemplate( - createTemplate( - { RehydratableCounter }, + precompileTemplate( `

Hello I am a static component. I don't change after page load.

@@ -17,7 +16,8 @@ const StaticComponent = setComponentTemplate(
- ` + `, + { strictMode: true, scope: { RehydratableCounter } } ), templateOnlyComponent() ); diff --git a/packages/example-apps/rehydration/src/MyComponent.ts b/packages/example-apps/rehydration/src/MyComponent.ts index a9dc48859..79ec0267a 100644 --- a/packages/example-apps/rehydration/src/MyComponent.ts +++ b/packages/example-apps/rehydration/src/MyComponent.ts @@ -1,6 +1,6 @@ import Component from '@glimmer/component'; import { tracked } from '@glimmer/tracking'; -import { createTemplate, setComponentTemplate } from '@glimmer/core'; +import { precompileTemplate, setComponentTemplate } from '@glimmer/core'; import { on, action } from '@glimmer/modifier'; class MyComponent extends Component { @@ -12,11 +12,11 @@ class MyComponent extends Component { } setComponentTemplate( - createTemplate( - { on }, + precompileTemplate( `

You have clicked the button {{this.count}} times.

- ` + `, + { strictMode: true, scope: { on } } ), MyComponent ); diff --git a/test/babel-plugins.js b/test/babel-plugins.js deleted file mode 100644 index b07f74086..000000000 --- a/test/babel-plugins.js +++ /dev/null @@ -1,2 +0,0 @@ -import '../packages/babel-plugins/@glimmer/babel-plugin-glimmer-env/test'; -import '../packages/babel-plugins/@glimmer/babel-plugin-strict-template-precompile/test'; diff --git a/webpack.config.js b/webpack.config.js index e10b2ae27..2d3744323 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,13 +1,6 @@ const path = require('path'); const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin'); -const commonBabelPlugins = [ - ['@glimmer/babel-plugin-glimmer-env', { DEBUG: true }], - '@glimmer/babel-plugin-strict-template-precompile', - ['@babel/plugin-proposal-decorators', { legacy: true }], - '@babel/plugin-proposal-class-properties', -]; - const commonConfig = { mode: 'development', externals: { @@ -57,8 +50,7 @@ const browserConfig = { use: { loader: 'babel-loader', options: { - plugins: commonBabelPlugins, - presets: ['@babel/preset-typescript', '@babel/preset-env'], + presets: ['@glimmer/babel-preset', '@babel/preset-typescript', '@babel/preset-env'], }, }, }, @@ -89,8 +81,8 @@ const nodeServerConfig = { use: { loader: 'babel-loader', options: { - plugins: commonBabelPlugins, presets: [ + '@glimmer/babel-preset', '@babel/preset-typescript', [ '@babel/preset-env', diff --git a/yarn.lock b/yarn.lock index 72c1139e0..5234485ff 100644 --- a/yarn.lock +++ b/yarn.lock @@ -25,7 +25,7 @@ invariant "^2.2.4" semver "^5.5.0" -"@babel/core@^7.3.4", "@babel/core@^7.5.5", "@babel/core@^7.8.3", "@babel/core@^7.8.4", "@babel/core@^7.9.0": +"@babel/core@^7.3.4", "@babel/core@^7.8.3", "@babel/core@^7.8.4", "@babel/core@^7.9.0": version "7.9.0" resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.9.0.tgz#ac977b538b77e132ff706f3b8a4dbad09c03c56e" integrity sha512-kWc7L0fw1xwvI0zi8OKVBuxRVefwGOrKSQMvrQ3dW+bIIavBY3/NpXmpjMy7bQnLgwgzWQZ8TlM57YHpHNHz4w== @@ -58,7 +58,7 @@ source-map "^0.5.0" trim-right "^1.0.1" -"@babel/generator@^7.9.0", "@babel/generator@^7.9.4": +"@babel/generator@^7.9.0": version "7.9.4" resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.9.4.tgz#12441e90c3b3c4159cdecf312075bf1a8ce2dbce" integrity sha512-rjP8ahaDy/ouhrvCoU1E5mqaitWrxwuNGU+dy1EpaoK48jZay4MdkskKGIMHLZNewg8sAsqpGSREJwP0zH3YQA== @@ -319,7 +319,7 @@ esutils "^2.0.2" js-tokens "^4.0.0" -"@babel/parser@^7.4.5", "@babel/parser@^7.8.6", "@babel/parser@^7.9.0", "@babel/parser@^7.9.4": +"@babel/parser@^7.4.5", "@babel/parser@^7.8.6", "@babel/parser@^7.9.0": version "7.9.4" resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.9.4.tgz#68a35e6b0319bbc014465be43828300113f2f2e8" integrity sha512-bC49otXX6N0/VYhgOMh4gnP26E9xnDZK3TmbNpxYzzz9BQLBosQwfyOe9/cXUU3txYhTzLCbcqd5c8y/OmCjHA== @@ -795,7 +795,7 @@ core-js "^2.6.5" regenerator-runtime "^0.13.2" -"@babel/preset-env@^7.8.3", "@babel/preset-env@^7.8.4", "@babel/preset-env@^7.9.0": +"@babel/preset-env@^7.8.4", "@babel/preset-env@^7.9.0": version "7.9.0" resolved "https://registry.yarnpkg.com/@babel/preset-env/-/preset-env-7.9.0.tgz#a5fc42480e950ae8f5d9f8f2bbc03f52722df3a8" integrity sha512-712DeRXT6dyKAM/FMbQTV/FvRCms2hPCx+3weRjZ8iQVQWZejWWk1wwG6ViWMyqb/ouBbGOl5b6aCk0+j1NmsQ== @@ -1284,6 +1284,13 @@ resolved "https://registry.yarnpkg.com/@glimmer/validator/-/validator-0.44.0.tgz#03d127097dc9cb23052cdb7fcae59d0a9dca53e1" integrity sha512-i01plR0EgFVz69GDrEuFgq1NheIjZcyTy3c7q+w7d096ddPVeVcRzU3LKaqCfovvLJ+6lJx40j45ecycASUUyw== +"@glimmer/vm-babel-plugins@0.77.3": + version "0.77.3" + resolved "https://registry.yarnpkg.com/@glimmer/vm-babel-plugins/-/vm-babel-plugins-0.77.3.tgz#0671fa09828ba0e2c204e4ca2586651928c32ace" + integrity sha512-m1RUfiTlxPSRGML1QkRl5VSjkLHIaFPjeRaz3NzT+B3mjTlEjusCm9q9fQS6doQRGgz4Rwl3vXi9hZHmMJal+Q== + dependencies: + babel-plugin-debug-macros "^0.3.4" + "@glimmer/vm@0.77.3": version "0.77.3" resolved "https://registry.yarnpkg.com/@glimmer/vm/-/vm-0.77.3.tgz#5132d65ef1910beeb300253a3a8b7ed892c12a3f" @@ -2663,6 +2670,13 @@ babel-plugin-debug-macros@^0.3.0, babel-plugin-debug-macros@^0.3.3: dependencies: semver "^5.3.0" +babel-plugin-debug-macros@^0.3.4: + version "0.3.4" + resolved "https://registry.yarnpkg.com/babel-plugin-debug-macros/-/babel-plugin-debug-macros-0.3.4.tgz#22961d0cb851a80654cece807a8b4b73d85c6075" + integrity sha512-wfel/vb3pXfwIDZUrkoDrn5FHmlWI96PCJ3UCDv2a86poJ3EQrnArNW5KfHSVJ9IOgxHbo748cQt7sDU+0KCEw== + dependencies: + semver "^5.3.0" + babel-plugin-dynamic-import-node@^2.3.0: version "2.3.0" resolved "https://registry.yarnpkg.com/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-2.3.0.tgz#f00f507bdaa3c3e3ff6e7e5e98d90a7acab96f7f" @@ -2684,6 +2698,13 @@ babel-plugin-ember-modules-api-polyfill@^2.12.0, babel-plugin-ember-modules-api- dependencies: ember-rfc176-data "^0.3.12" +babel-plugin-ember-modules-api-polyfill@^3.4.0: + version "3.5.0" + resolved "https://registry.yarnpkg.com/babel-plugin-ember-modules-api-polyfill/-/babel-plugin-ember-modules-api-polyfill-3.5.0.tgz#27b6087fac75661f779f32e60f94b14d0e9f6965" + integrity sha512-pJajN/DkQUnStw0Az8c6khVcMQHgzqWr61lLNtVeu0g61LRW0k9jyK7vaedrHDWGe/Qe8sxG5wpiyW9NsMqFzA== + dependencies: + ember-rfc176-data "^0.3.17" + babel-plugin-filter-imports@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/babel-plugin-filter-imports/-/babel-plugin-filter-imports-3.0.0.tgz#a849683837ad29960da17492fb32789ab6b09a11" @@ -2702,6 +2723,13 @@ babel-plugin-htmlbars-inline-precompile@^1.0.0: resolved "https://registry.yarnpkg.com/babel-plugin-htmlbars-inline-precompile/-/babel-plugin-htmlbars-inline-precompile-1.0.0.tgz#a9d2f6eaad8a3f3d361602de593a8cbef8179c22" integrity sha512-4jvKEHR1bAX03hBDZ94IXsYCj3bwk9vYsn6ux6JZNL2U5pvzCWjqyrGahfsGNrhERyxw8IqcirOi9Q6WCo3dkQ== +babel-plugin-htmlbars-inline-precompile@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/babel-plugin-htmlbars-inline-precompile/-/babel-plugin-htmlbars-inline-precompile-5.0.0.tgz#b3a3008bdedbd3543e745fc953769cc10d4a7021" + integrity sha512-ZPIV7zVwVcwRyTWCp29HSwIPcvqX7PoslpKlNu53AzAx5X4QBwuMb9fFsUYY3JcriNZb5xWFOM4AE95XW0UYeA== + dependencies: + babel-plugin-ember-modules-api-polyfill "^3.4.0" + babel-plugin-module-resolver@^3.1.1: version "3.2.0" resolved "https://registry.yarnpkg.com/babel-plugin-module-resolver/-/babel-plugin-module-resolver-3.2.0.tgz#ddfa5e301e3b9aa12d852a9979f18b37881ff5a7" @@ -5628,6 +5656,11 @@ ember-rfc176-data@^0.3.12, ember-rfc176-data@^0.3.5: resolved "https://registry.yarnpkg.com/ember-rfc176-data/-/ember-rfc176-data-0.3.12.tgz#90d82878e69e2ac9a5438e8ce14d12c6031c5bd2" integrity sha512-g9HeZj/gU5bfIIrGXkP7MhS2b3Vu5DfNUrYr14hy99TgIvtZETO+96QF4WOEUXGjIJdfTRjerVnQlqngPQSv1g== +ember-rfc176-data@^0.3.17: + version "0.3.17" + resolved "https://registry.yarnpkg.com/ember-rfc176-data/-/ember-rfc176-data-0.3.17.tgz#d4fc6c33abd6ef7b3440c107a28e04417b49860a" + integrity sha512-EVzTTKqxv9FZbEh6Ktw56YyWRAA0MijKvl7H8C06wVF+8f/cRRz3dXxa4nkwjzyVwx4rzKGuIGq77hxJAQhWWw== + ember-router-generator@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/ember-router-generator/-/ember-router-generator-2.0.0.tgz#d04abfed4ba8b42d166477bbce47fccc672dbde0"