How to use the @emotion/babel-utils.getLabelFromPath 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)) {
        node.replaceWith(simplifyObject(node.node, t))
      }
    })
    if (label) {
      appendStringToExpressions(path.node.arguments, `label:${label};`, t)
    }

    if (state.emotionSourceMap) {
github emotion-js / next / packages / babel-plugin-core / src / styled-macro.js View on Github external
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([
          t.objectProperty(
            t.identifier('target'),
            t.stringLiteral(getTargetClassName(state, t))
          ),
          t.objectProperty(
            t.identifier('label'),
            t.stringLiteral(getLabelFromPath(reference.parentPath, t))
          )
        ])
      }
      if (t.isCallExpression(reference.parentPath.parentPath)) {
        if (state.emotionSourceMap) {
          if (
            !sourceMap &&
            reference.parentPath.parentPath.node.loc !== undefined
          ) {
            sourceMap = getSourceMap(
              reference.parentPath.parentPath.node.loc.start,
              state
            )
          }

          appendStringToExpressions(