Sha256: dbf818955b161b764a33b84abcd321857a08bbae1e3d4f553c9f77916f2e726c

Contents?: true

Size: 1.51 KB

Versions: 3

Compression:

Stored size: 1.51 KB

Contents

import { assert } from '@ember/debug';
import calculateLocationDisplay from '../system/calculate-location-display';
export default function assertIfHelperWithoutArguments(env) {
    let { moduleName } = env.meta;
    return {
        name: 'assert-if-helper-without-arguments',
        visitor: {
            BlockStatement(node) {
                if (isInvalidBlockIf(node)) {
                    assert(`${blockAssertMessage(node.path.original)} ${calculateLocationDisplay(moduleName, node.loc)}`);
                }
            },
            MustacheStatement(node) {
                if (isInvalidInlineIf(node)) {
                    assert(`${inlineAssertMessage(node.path.original)} ${calculateLocationDisplay(moduleName, node.loc)}`);
                }
            },
            SubExpression(node) {
                if (isInvalidInlineIf(node)) {
                    assert(`${inlineAssertMessage(node.path.original)} ${calculateLocationDisplay(moduleName, node.loc)}`);
                }
            },
        },
    };
}
function blockAssertMessage(original) {
    return `#${original} requires a single argument.`;
}
function inlineAssertMessage(original) {
    return `The inline form of the '${original}' helper expects two or three arguments.`;
}
function isInvalidInlineIf(node) {
    return (node.path.original === 'if' &&
        (!node.params || node.params.length < 2 || node.params.length > 3));
}
function isInvalidBlockIf(node) {
    return node.path.original === 'if' && (!node.params || node.params.length !== 1);
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
discourse-ember-source-3.6.0.0 dist/es/ember-template-compiler/lib/plugins/assert-if-helper-without-arguments.js
discourse-ember-source-3.5.1.1 dist/es/ember-template-compiler/lib/plugins/assert-if-helper-without-arguments.js
discourse-ember-source-3.5.1.0 dist/dist/es/ember-template-compiler/lib/plugins/assert-if-helper-without-arguments.js