ember-source
Version:
A JavaScript framework for creating ambitious web applications
51 lines (44 loc) • 1.44 kB
JavaScript
import '../../../debug/index.js';
import { isPath } from './utils.js';
import { assert } from '../../../debug/lib/assert.js';
/**
@module ember
*/
/**
A Glimmer2 AST transformation that handles the public `{{in-element}}` as per RFC287.
Issues a build time assertion for:
```handlebars
{{#in-element someElement insertBefore="some-none-null-value"}}
{{modal-display text=text}}
{{/in-element}}
```
@private
@class TransformInElement
*/
function transformInElement(env) {
let {
builders: b
} = env.syntax;
return {
name: 'transform-in-element',
visitor: {
BlockStatement(node) {
if (!isPath(node.path)) return;
if (node.path.original === 'in-element') {
let originalValue = node.params[0];
if (originalValue && !env.isProduction) {
let subExpr = b.sexpr('-in-el-null', [originalValue]);
node.params.shift();
node.params.unshift(subExpr);
}
node.hash.pairs.forEach(pair => {
if (pair.key === 'insertBefore') {
(!(pair.value.type === 'NullLiteral' || pair.value.type === 'UndefinedLiteral') && assert(`Can only pass null to insertBefore in in-element, received: ${JSON.stringify(pair.value)}`, pair.value.type === 'NullLiteral' || pair.value.type === 'UndefinedLiteral'));
}
});
}
}
}
};
}
export { transformInElement as default };