Sha256: 3ad8fc6e141e7811f86deb9b22e822f3616088eee6ca78e0d42de72b67960250

Contents?: true

Size: 1.25 KB

Versions: 3

Compression:

Stored size: 1.25 KB

Contents

/**
 @module ember
*/
/**
  A Glimmer2 AST transformation that replaces all instances of

  ```handlebars
 {{input type=boundType}}
  ```

  with

  ```handlebars
 {{input (-input-type boundType) type=boundType}}
  ```

  Note that the type parameters is not removed as the -input-type helpers
  is only used to select the component class. The component still needs
  the type parameter to function.

  @private
  @class TransformInputTypeSyntax
*/
export default function transformInputTypeSyntax(env) {
    let b = env.syntax.builders;
    return {
        name: 'transform-input-type-syntax',
        visitor: {
            MustacheStatement(node) {
                if (isInput(node)) {
                    insertTypeHelperParameter(node, b);
                }
            },
        },
    };
}
function isInput(node) {
    return node.path.original === 'input';
}
function insertTypeHelperParameter(node, builders) {
    let pairs = node.hash.pairs;
    let pair = null;
    for (let i = 0; i < pairs.length; i++) {
        if (pairs[i].key === 'type') {
            pair = pairs[i];
            break;
        }
    }
    if (pair && pair.value.type !== 'StringLiteral') {
        node.params.unshift(builders.sexpr('-input-type', [pair.value], undefined, pair.loc));
    }
}

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/transform-input-type-syntax.js
discourse-ember-source-3.5.1.1 dist/es/ember-template-compiler/lib/plugins/transform-input-type-syntax.js
discourse-ember-source-3.5.1.0 dist/dist/es/ember-template-compiler/lib/plugins/transform-input-type-syntax.js