From 586d03868e191f26c50a9e383f8ec14a5f531c13 Mon Sep 17 00:00:00 2001 From: Chad Hietala Date: Thu, 2 Mar 2017 14:32:51 -0800 Subject: [PATCH] Bumping @glimmer packages to 0.22.0 --- package.json | 14 +-- packages/ember-glimmer/lib/utils/bindings.js | 7 +- .../lib/plugins/index.js | 2 + .../transform-dot-component-invocation.js | 107 ++++++++++++++++++ 4 files changed, 121 insertions(+), 9 deletions(-) create mode 100644 packages/ember-template-compiler/lib/plugins/transform-dot-component-invocation.js diff --git a/package.json b/package.json index 679ec8fc5c7..f48a481242f 100644 --- a/package.json +++ b/package.json @@ -35,12 +35,12 @@ "link:glimmer": "node bin/yarn-link-glimmer.js" }, "dependencies": { - "@glimmer/compiler": "^0.21.1", - "@glimmer/di": "0.1.8", - "@glimmer/node": "^0.21.1", - "@glimmer/reference": "^0.21.0", - "@glimmer/runtime": "^0.21.1", - "@glimmer/util": "^0.21.0", + "@glimmer/compiler": "^0.22.0", + "@glimmer/di": "^0.1.8", + "@glimmer/node": "^0.22.0", + "@glimmer/reference": "^0.22.0", + "@glimmer/runtime": "^0.22.0", + "@glimmer/util": "^0.22.0", "broccoli-funnel": "^1.0.6", "broccoli-merge-trees": "^1.1.4", "ember-cli-get-component-path-option": "^1.0.0", @@ -58,7 +58,7 @@ "simple-html-tokenizer": "^0.3.0" }, "devDependencies": { - "@glimmer/test-helpers": "^0.21.1", + "@glimmer/test-helpers": "^0.22.0", "aws-sdk": "~2.2.43", "babel-plugin-feature-flags": "^0.2.3", "babel-plugin-filter-imports": "~0.2.0", diff --git a/packages/ember-glimmer/lib/utils/bindings.js b/packages/ember-glimmer/lib/utils/bindings.js index fc0ce9ae280..53a5d0671cf 100644 --- a/packages/ember-glimmer/lib/utils/bindings.js +++ b/packages/ember-glimmer/lib/utils/bindings.js @@ -4,6 +4,9 @@ import { map, referenceFromParts } from '@glimmer/reference'; +import { + Ops +} from '@glimmer/wire-format'; import { get, assert } from 'ember-metal'; import { String as StringUtils } from 'ember-runtime'; import { ROOT_REF } from '../component'; @@ -40,11 +43,11 @@ export function wrapComponentClassAttribute(hash) { if (index !== -1) { let [ type ] = values[index]; - if (type === 'get') { + if (type === Ops.Get) { let getExp = values[index]; let path = getExp[1]; let propName = path[path.length - 1]; - hash[1][index] = ['helper', ['-class'], [getExp, propName]]; + hash[1][index] = [Ops.Helper, ['-class'], [getExp, propName]]; } } diff --git a/packages/ember-template-compiler/lib/plugins/index.js b/packages/ember-template-compiler/lib/plugins/index.js index 9a671ab53b2..0af948ce040 100644 --- a/packages/ember-template-compiler/lib/plugins/index.js +++ b/packages/ember-template-compiler/lib/plugins/index.js @@ -14,8 +14,10 @@ import TransformInputTypeSyntax from './transform-input-type-syntax'; import TransformAttrsIntoArgs from './transform-attrs-into-args'; import TransformEachInIntoEach from './transform-each-in-into-each'; import TransformHasBlockSyntax from './transform-has-block-syntax'; +import TransformDotComponentInvocation from './transform-dot-component-invocation'; export default Object.freeze([ + TransformDotComponentInvocation, TransformOldBindingSyntax, TransformItemClass, TransformAngleBracketComponents, diff --git a/packages/ember-template-compiler/lib/plugins/transform-dot-component-invocation.js b/packages/ember-template-compiler/lib/plugins/transform-dot-component-invocation.js new file mode 100644 index 00000000000..79085738e31 --- /dev/null +++ b/packages/ember-template-compiler/lib/plugins/transform-dot-component-invocation.js @@ -0,0 +1,107 @@ + +/** + Transforms dot invocation of closure components to be wrapped + with the component helper. This allows for a more static invocation + of the component. + + ```handlebars + {{#my-component as |comps|}} + {{comp.dropdown isOpen=false}} + {{/my-component}} + ``` + + with + + ```handlebars + {{#my-component as |comps|}} + {{component comp.dropdown isOpen=false}} + {{/my-component}} + ``` + and + + ```handlebars + {{#my-component as |comps|}} + {{comp.dropdown isOpen}} + {{/my-component}} + ``` + + with + + ```handlebars + {{#my-component as |comps|}} + {{component comp.dropdown isOpen}} + {{/my-component}} + ``` + + and + + ```handlebars + {{#my-component as |comps|}} + {{#comp.dropdown}}Open{{/comp.dropdown}} + {{/my-component}} + ``` + + with + + ```handlebars + {{#my-component as |comps|}} + {{#component comp.dropdown}}Open{{/component}} + {{/my-component}} + ``` + + @private + @class TransFormDotComponentInvocation +*/ +export default class TransFormDotComponentInvocation { + + _isMulipartPath(path) { + return path.parts.length > 1; + } + + _isInlineInvocation(path, params, hash) { + if (this._isMulipartPath(path)) { + if (params.length > 0 || hash.pairs.length > 0) { + return true; + } + } + + return false; + } + + _wrapInComponent(node, builder) { + let component = node.path; + let componentHelper = builder.path('component'); + node.path = componentHelper; + node.params.unshift(component); + } + + transform(ast) { + let { traverse, builders: b } = this.syntax; + + traverse(ast, { + BlockStatement: (node) => { + node.program.body = node.program.body.map((_node) => { + switch(_node.type) { + case 'MustacheStatement': + if (this._isInlineInvocation(_node.path, _node.params, _node.hash)) { + this._wrapInComponent(_node, b); + } + break; + case 'BlockStatement': + if (this._isMulipartPath(_node.path)) { + this._wrapInComponent(_node, b) + } + break; + } + + return _node; + }); + + return node; + } + }); + + return ast; + } +} +