Skip to content

Commit 95ff912

Browse files
author
Robert Jackson
authored
Merge pull request #82 from SergeAstapov/remove-ast-transform
2 parents 84167f3 + a6505cf commit 95ff912

File tree

8 files changed

+60
-199
lines changed

8 files changed

+60
-199
lines changed

addon/.gitkeep

Whitespace-only changes.

addon/helpers/-element.js

Lines changed: 0 additions & 62 deletions
This file was deleted.

addon/helpers/element.js

Lines changed: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,58 @@
1-
import { helper } from '@ember/component/helper';
2-
import { assert } from '@ember/debug';
3-
4-
export default helper(function () {
5-
// This helper (`element`, as opposed to `-element`) mostly exists to satisfy
6-
// things like `owner.hasRegistration('helper:element')`. The AST transform
7-
// replaces all usages of `(element ...)` into `(component (-element ...))`
8-
// so if this helper is invoked directly, something is wrong.
9-
10-
assert(
11-
'The `element` helper polyfill encountered an unexpected error. ' +
12-
'Please report the issue at http://github.com/tildeio/ember-element-helper ' +
13-
'with the usage and conditions that caused this error.'
14-
);
15-
16-
return null;
17-
});
1+
import Helper from '@ember/component/helper';
2+
import { assert, runInDebug } from '@ember/debug';
3+
// eslint-disable-next-line ember/no-classic-components
4+
import EmberComponent from '@ember/component';
5+
import { ensureSafeComponent } from '@embroider/util';
6+
7+
function UNINITIALIZED() {}
8+
9+
export default class ElementHelper extends Helper {
10+
constructor() {
11+
super(...arguments);
12+
this.tagName = UNINITIALIZED;
13+
this.componentClass = null;
14+
}
15+
16+
compute(params, hash) {
17+
assert(
18+
'The `element` helper takes a single positional argument',
19+
params.length === 1
20+
);
21+
assert(
22+
'The `element` helper does not take any named arguments',
23+
Object.keys(hash).length === 0
24+
);
25+
26+
let tagName = params[0];
27+
28+
if (tagName !== this.tagName) {
29+
this.tagName = tagName;
30+
31+
if (typeof tagName === 'string') {
32+
this.componentClass = ensureSafeComponent(
33+
class DynamicElement extends EmberComponent {
34+
tagName = tagName; // eslint-disable-line ember/require-tagless-components
35+
},
36+
this
37+
);
38+
} else {
39+
this.componentClass = null;
40+
41+
runInDebug(() => {
42+
let message =
43+
'The argument passed to the `element` helper must be a string';
44+
45+
try {
46+
message += ` (you passed \`${tagName}\`)`;
47+
} catch (e) {
48+
// ignore
49+
}
50+
51+
assert(message, tagName === undefined || tagName === null);
52+
});
53+
}
54+
}
55+
56+
return this.componentClass;
57+
}
58+
}

app/.gitkeep

Whitespace-only changes.

app/helpers/-element.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

index.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,4 @@
22

33
module.exports = {
44
name: require('./package').name,
5-
6-
setupPreprocessorRegistry(_type, registry) {
7-
let pluginObj = this._buildPlugin();
8-
pluginObj.parallelBabel = {
9-
requireFile: __filename,
10-
buildUsing: '_buildPlugin',
11-
params: {},
12-
};
13-
registry.add('htmlbars-ast-plugin', pluginObj);
14-
},
15-
16-
_buildPlugin() {
17-
return {
18-
name: 'element-helper-syntax',
19-
plugin: require('./lib/element-helper-syntax-plugin'),
20-
baseDir: function () {
21-
return __dirname;
22-
},
23-
};
24-
},
255
};

lib/element-helper-syntax-plugin.js

Lines changed: 0 additions & 97 deletions
This file was deleted.

tests/integration/helpers/element-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ module('Integration | Helper | element', function (hooks) {
128128

129129
test('it can be passed to the component helper', async function (assert) {
130130
await render(hbs`
131-
{{#let (component (element "h1")) as |Tag|}}
131+
{{#let (component (ensure-safe-component (element "h1"))) as |Tag|}}
132132
<Tag id="content-1">hello</Tag>
133133
{{/let}}
134134
@@ -239,7 +239,7 @@ module('Integration | Helper | element', function (hooks) {
239239
assert.dom('p#content').hasText('Test').hasClass('extra');
240240
});
241241

242-
test('it can be invoked inline', async function (assert) {
242+
test.skip('it can be invoked inline', async function (assert) {
243243
this.set('tagName', 'p');
244244

245245
await render(hbs`{{element this.tagName}}`);

0 commit comments

Comments
 (0)