How to use the @glimmer/syntax.print function in @glimmer/syntax

To help you get started, we’ve selected a few @glimmer/syntax examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github danakt / handlebars-to-jsx / dist / styles.js View on Github external
exports.createStyleObject = function (hbsStatement) {
    var rawHbsStatement = hbsStatement.type === 'TextNode' ? hbsStatement.chars : syntax_1.print(hbsStatement).slice(1, -1);
    var objectProps = rawHbsStatement
        .split(';')
        .filter(function (item) { return item.length !== 0; })
        .map(function (cssRule) {
        var _a = cssRule.split(':').map(function (str) { return str.trim(); }), rawKey = _a[0], rawValue = _a[1];
        var _b = [rawKey, rawValue].map(function (item) {
            return syntax_1.preprocess(item || '').body.filter(function (item) { return item.type === 'MustacheStatement' || item.type === 'TextNode'; });
        }), hbsKey = _b[0], hbsValue = _b[1];
        var key = hbsKey.length === 1
            ? hbsKey[0].type === 'TextNode'
                ? Babel.stringLiteral(exports.camelizePropName(hbsKey[0].chars)) // Capitalize key name
                : expressions_1.resolveStatement(hbsKey[0])
            : expressions_1.createConcat(hbsKey);
        var value = hbsValue.length === 1 ? expressions_1.resolveStatement(hbsValue[0]) : expressions_1.createConcat(hbsValue);
        var isComputed = hbsKey.length > 1;
        return Babel.objectProperty(key, value, isComputed);
github ember-codemods / ember-angle-brackets-codemod / transforms / angle-brackets / angle-brackets-syntax.js View on Github external
ElementNode(node) {
      node.attributes.forEach(a => {
        if (a.value && a.value.chars === '') {
          a.value = b.text(_EMPTY_STRING_);
        }
      });
    },
  });

  let attrEqualEmptyString = new RegExp(_EMPTY_STRING_, 'gi');
  let dataEqualsNoValue = /(data-\S+)=""/gim;

  // Haxx out valueless data-* and args with the empty string

  let uglySource = glimmer.print(ast).replace(attrEqualEmptyString, '');
  let dataOk = uglySource.replace(dataEqualsNoValue, '$1');
  return prettier.format(dataOk, { parser: 'glimmer' });
};
github cardstack / cardstack / packages / rendering / node-tests / template-helper.js View on Github external
visitors: {
                  Program: function(node) {
                    let plugin = new Plugin(env);
                    plugin.syntax = env.syntax;
                    return plugin.transform(node);
                  },
                },
              };
            },
          ],
        },
      },
      opts
    )
  );
  return print(newAst);
};
github danakt / handlebars-to-jsx / src / styles.ts View on Github external
export const createStyleObject = (hbsStatement: Glimmer.TextNode | Glimmer.ConcatStatement): Babel.ObjectExpression => {
  const rawHbsStatement: string
    = hbsStatement.type === 'TextNode' ? hbsStatement.chars : print(hbsStatement).slice(1, -1)

  const objectProps: Array = rawHbsStatement
    .split(';')
    .filter(item => item.length !== 0)
    .map(cssRule => {
      const [rawKey, rawValue]: (string | undefined)[] = cssRule.split(':').map(str => str.trim())

      const [hbsKey, hbsValue] = [rawKey, rawValue].map(
        item =>
          preprocess(item || '').body.filter(
            item => item.type === 'MustacheStatement' || item.type === 'TextNode'
          ) as Array
      )

      const key
        = hbsKey.length === 1
github linkedin / css-blocks / packages / @css-blocks / glimmer / src / ElementAnalyzer.ts View on Github external
      startTag = `{{${node.path.original} ${node.params.map(a => print(a)).join(" ")} ${node.hash.pairs.map((h) => print(h)).join(" ")}}}`;
      debug(`Component ${startTag} is ${atRootElement ? "the root " : "a sub"}element at ${this.debugTemplateLocation(node)}`);
github linkedin / css-blocks / packages / @css-blocks / glimmer / src / ElementAnalyzer.ts View on Github external
      startTag = `<${node.tag} ${node.attributes.map(a => print(a)).join(" ")}>`;
      debug(`Element ${startTag} is ${atRootElement ? "the root " : "a sub"}element at ${this.debugTemplateLocation(node)}`);