-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from SergeAstapov/remove-ast-transform
- Loading branch information
Showing
8 changed files
with
60 additions
and
199 deletions.
There are no files selected for viewing
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,58 @@ | ||
import { helper } from '@ember/component/helper'; | ||
import { assert } from '@ember/debug'; | ||
|
||
export default helper(function () { | ||
// This helper (`element`, as opposed to `-element`) mostly exists to satisfy | ||
// things like `owner.hasRegistration('helper:element')`. The AST transform | ||
// replaces all usages of `(element ...)` into `(component (-element ...))` | ||
// so if this helper is invoked directly, something is wrong. | ||
|
||
assert( | ||
'The `element` helper polyfill encountered an unexpected error. ' + | ||
'Please report the issue at http://github.com/tildeio/ember-element-helper ' + | ||
'with the usage and conditions that caused this error.' | ||
); | ||
|
||
return null; | ||
}); | ||
import Helper from '@ember/component/helper'; | ||
import { assert, runInDebug } from '@ember/debug'; | ||
// eslint-disable-next-line ember/no-classic-components | ||
import EmberComponent from '@ember/component'; | ||
import { ensureSafeComponent } from '@embroider/util'; | ||
|
||
function UNINITIALIZED() {} | ||
|
||
export default class ElementHelper extends Helper { | ||
constructor() { | ||
super(...arguments); | ||
this.tagName = UNINITIALIZED; | ||
this.componentClass = null; | ||
} | ||
|
||
compute(params, hash) { | ||
assert( | ||
'The `element` helper takes a single positional argument', | ||
params.length === 1 | ||
); | ||
assert( | ||
'The `element` helper does not take any named arguments', | ||
Object.keys(hash).length === 0 | ||
); | ||
|
||
let tagName = params[0]; | ||
|
||
if (tagName !== this.tagName) { | ||
this.tagName = tagName; | ||
|
||
if (typeof tagName === 'string') { | ||
this.componentClass = ensureSafeComponent( | ||
class DynamicElement extends EmberComponent { | ||
tagName = tagName; // eslint-disable-line ember/require-tagless-components | ||
}, | ||
this | ||
); | ||
} else { | ||
this.componentClass = null; | ||
|
||
runInDebug(() => { | ||
let message = | ||
'The argument passed to the `element` helper must be a string'; | ||
|
||
try { | ||
message += ` (you passed \`${tagName}\`)`; | ||
} catch (e) { | ||
// ignore | ||
} | ||
|
||
assert(message, tagName === undefined || tagName === null); | ||
}); | ||
} | ||
} | ||
|
||
return this.componentClass; | ||
} | ||
} |
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters