How to use the @emotion/babel-utils.getExpressionsFromTemplateLiteral function in @emotion/babel-utils

To help you get started, we’ve selected a few @emotion/babel-utils 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 emotion-js / next / packages / babel-plugin-core / src / css-macro.js View on Github external
export const transformCssCallExpression = ({ babel, state, path }: *) => {
  let t = babel.types
  let sourceMap = ''
  if (t.isTaggedTemplateExpression(path)) {
    const expressions = getExpressionsFromTemplateLiteral(path.node.quasi, t)
    if (state.emotionSourceMap && path.node.quasi.loc !== undefined) {
      sourceMap = getSourceMap(path.node.quasi.loc.start, state)
    }
    path.replaceWith(t.callExpression(path.node.tag, expressions))
  }

  if (t.isCallExpression(path)) {
    const label = getLabelFromPath(path, t)

    let isPure = true

    path.get('arguments').forEach(node => {
      if (!node.isPure()) {
        isPure = false
      }
      if (t.isObjectExpression(node)) {
github emotion-js / next / packages / babel-plugin-core / src / styled-macro.js View on Github external
})
      }
      if (t.isMemberExpression(reference.parent)) {
        reference.parentPath.replaceWith(
          t.callExpression(t.cloneDeep(styledIdentifier), [
            t.stringLiteral(reference.parent.property.name)
          ])
        )
      } else {
        reference.replaceWith(t.cloneDeep(styledIdentifier))
      }
      let sourceMap = ''
      if (reference.parentPath && reference.parentPath.parentPath) {
        const styledCallPath = reference.parentPath.parentPath
        if (t.isTaggedTemplateExpression(styledCallPath)) {
          const expressions = getExpressionsFromTemplateLiteral(
            styledCallPath.node.quasi,
            t
          )
          if (
            state.emotionSourceMap &&
            styledCallPath.node.quasi.loc !== undefined
          ) {
            sourceMap = getSourceMap(styledCallPath.node.quasi.loc.start, state)
          }
          styledCallPath.replaceWith(
            t.callExpression(styledCallPath.node.tag, expressions)
          )
        }
      }
      if (t.isCallExpression(reference.parentPath)) {
        reference.parentPath.node.arguments[1] = t.objectExpression([