How to use the @babel/template.smart function in @babel/template

To help you get started, we’ve selected a few @babel/template 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 TradaTech / icetea / icetea / vm / js / babel / loopEntryGuard.js View on Github external
'map', 'filter', 'reduce', 'forEach', 'every', 'some'
  ].includes(property.name))) {
    return
  }

  if (node.arguments.length === 0) {
    return
  }

  const arg = node.arguments[0]
  if (!['ArrowFunctionExpression', 'FunctionExpression'].includes(arg.type)) {
    return
  }

  if (arg.body.type !== 'BlockStatement') {
    const fn = template.smart(`
      {
        return VAR
      }
    `)
    arg.body = fn({
      VAR: arg.body
    })
  }

  _protect(t, path.get('arguments')[0])
}
github codejamninja / react-ast / src / elements / Smart.ts View on Github external
constructor(props: Props, parserOptions: ParserOptions = {}) {
    const baseNode = template.smart(
      props.code,
      _.merge(parserOptions, props.options) as TemplateBuilderOptions
    )(props.replacements as PublicReplacements);
    const scopePath = flattenPath(props.scopePath);
    super(
      props.scopePath && scopePath.length
        ? _.get(baseNode, scopePath)
        : baseNode,
      props,
      {
        bodyPath: props.bodyPath || 'body.body',
        parentBodyPath: props.parentBodyPath
      }
    );
  }
}