How to use @glimmer/syntax - 10 common examples

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 linkedin / css-blocks / packages / @css-blocks / glimmer / src / ClassnamesHelperGenerator.ts View on Github external
function constructSwitch(stateExpr: Switch & HasGroup & HasAttrValue, rewrite: IndexedClassRewrite
github brodybits / prettierx / src / language-handlebars / parser-glimmer.js View on Github external
function parse(text) {
  try {
    const glimmer = require("@glimmer/syntax").preprocess;
    return glimmer(text, {
      plugins: {
        ast: [removeWhiteSpace]
      }
    });
    /* istanbul ignore next */
  } catch (error) {
    const matches = error.message.match(/on line (\d+)/);
    if (matches) {
      throw createError(error.message, {
        start: { line: Number(matches[1]), column: 0 }
      });
    } else {
      throw error;
    }
  }
}
github glimmerjs / glimmer-vm / packages / @glimmer / compiler / lib / template-compiler.ts View on Github external
function assertValidPartial(statement: AST.MustacheStatement) /* : expr */ {
  let { params, hash, escaped, loc } = statement;

  if (params && params.length !== 1) {
    throw new SyntaxError(
      `Partial found with no arguments. You must specify a template name. (on line ${loc.start.line})`,
      statement.loc
    );
  } else if (hash && hash.pairs.length > 0) {
    throw new SyntaxError(
      `partial does not take any named arguments (on line ${loc.start.line})`,
      statement.loc
    );
  } else if (!escaped) {
    throw new SyntaxError(
      `{{{partial ...}}} is not supported, please use {{partial ...}} instead (on line ${loc.start.line})`,
      statement.loc
    );
  }

  return params;
github glimmerjs / glimmer-vm / packages / @glimmer / compiler / lib / strict-template-compiler.ts View on Github external
function assertValidPartial(statement: AST.MustacheStatement) /* : expr */ {
  let { params, hash, escaped, loc } = statement;

  if (params && params.length !== 1) {
    throw new SyntaxError(
      `Partial found with no arguments. You must specify a template name. (on line ${
        loc.start.line
      })`,
      statement.loc
    );
  } else if (hash && hash.pairs.length > 0) {
    throw new SyntaxError(
      `partial does not take any named arguments (on line ${loc.start.line})`,
      statement.loc
    );
  } else if (!escaped) {
    throw new SyntaxError(
      `{{{partial ...}}} is not supported, please use {{partial ...}} instead (on line ${
        loc.start.line
      })`,
      statement.loc
    );
  }

  return params;
}
github linkedin / css-blocks / packages / @css-blocks / glimmer / src / Analyzer.ts View on Github external
// component exists, does not exist, stop.
    let block: Block | undefined = await this.resolveBlock(dir, componentName);
    if (!block) { return analysis; }

    self.debug(`Analyzing ${componentName}. Got block for component.`);

    // Add all transitive block dependencies
    let localBlockNames: string[] = [];
    block.eachBlockExport((name, refBlock) => {
      analysis.addBlock(name, refBlock);
      localBlockNames.push(name);
    });
    self.debug(`Analyzing ${componentName}. ${localBlockNames.length} blocks in scope: ${localBlockNames.join(", ")}.`);

    let elementAnalyzer = new ElementAnalyzer(analysis, this.cssBlocksOptions);
    traverse(ast, {
      MustacheStatement(node: AST.MustacheStatement) {
        const name = node.path.original;
        if (!isEmberBuiltIn(name)) { return; }
        elementCount++;
        const atRootElement = (elementCount === 1);
        const element = elementAnalyzer.analyze(node, atRootElement);
        if (self.debug.enabled) self.debug(`{{${name}}} analyzed:`, element.class.forOptimizer(self.cssBlocksOptions).toString());
      },

      BlockStatement(node: AST.BlockStatement) {
        const name = node.path.original;
        if (!isEmberBuiltIn(name)) { return; }
        elementCount++;
        const atRootElement = (elementCount === 1);
        const element = elementAnalyzer.analyze(node, atRootElement);
        if (self.debug.enabled) self.debug(`{{#${name}}} analyzed:`, element.class.forOptimizer(self.cssBlocksOptions).toString());
github danakt / handlebars-to-jsx / dist / pathsPrepare.js View on Github external
exports.prepareProgramPaths = function (program, isComponent) {
    var namespaces = createNamespaceStack();
    // Global component namespace
    if (isComponent) {
        namespaces.push({ node: program, name: 'props' });
    }
    var eachStatementEntered = false;
    syntax_1.traverse(program, {
        // Process block statements
        All: {
            enter: function (node) {
                if (node.type === 'Program' && eachStatementEntered) {
                    namespaces.push({ node: node });
                    eachStatementEntered = false;
                }
                if (isEachStatement(node)) {
                    eachStatementEntered = true;
                }
            },
            exit: function (node) {
                // Exit from namespace
                if (namespaces.length > 0 && node === namespaces.head().node) {
                    namespaces.pop();
                }
github linkedin / css-blocks / packages / @css-blocks / glimmer / src / ClassnamesHelperGenerator.ts View on Github external
function constructSwitch(stateExpr: Switch & HasGroup & HasAttrValue, rewrite: IndexedClassRewrite
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 fkling / astexplorer / website / src / parsers / handlebars / transformers / glimmer / index.js View on Github external
import compileModule from '../../../utils/compileModule';
import pkg from '@glimmer/syntax/package.json';

const ID = 'glimmer';

export default {
  id: ID,
  displayName: ID,
  version: pkg.version,
  homepage: pkg.homepage || 'https://github.com/glimmerjs/glimmer-vm',

  defaultParserID: 'glimmer',

  loadTransformer(callback) {
    require(
      ['../../../transpilers/babel', '@glimmer/syntax'],
      (transpile, glimmer) => callback({ transpile: transpile.default, glimmer }),
    );
  },

  transform({ transpile, glimmer }, transformCode, code) {
    transformCode = transpile(transformCode);
    const transformModule = compileModule(transformCode);

    // allow "export default" instead of "module.exports = "
    const transform = transformModule.__esModule ?