How to use the @emotion/babel-utils.getSourceMap 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 / emotion / next-packages / babel-plugin-core / src / index.js View on Github external
) {
          let expressionPath = path.get('value.expression')
          if (expressionPath.isPure()) {
            if (!state.cssIdentifier) {
              state.cssIdentifier = addDefault(path, '@emotion/css', {
                nameHint: 'css'
              })
            }
            expressionPath.replaceWith(
              t.callExpression(
                t.identifier(state.cssIdentifier.name),
                [
                  path.node.value.expression,
                  state.emotionSourceMap &&
                    path.node.loc !== undefined &&
                    t.stringLiteral(getSourceMap(path.node.loc.start, state))
                ].filter(Boolean)
              )
            )
            transformCssCallExpression({
              babel,
              state,
              path: expressionPath
            })
            // if (expressionPath.isCallExpression()) {
            //   if (
            //     expressionPath.node.arguments.length === 1 &&
            //     t.isArrayExpression(expressionPath.node.arguments[0])
            //   ) {
            //     // expressionPath.replaceWith(expressionPath.arguments[0])
            //   } else {
            //     expressionPath.replaceWith(
github emotion-js / next / packages / babel-plugin-core / src / styled-macro.js View on Github external
} 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([
          t.objectProperty(
            t.identifier('target'),
            t.stringLiteral(getTargetClassName(state, t))
          ),
          t.objectProperty(
            t.identifier('label'),
            t.stringLiteral(getLabelFromPath(reference.parentPath, t))
          )
github emotion-js / next / packages / babel-plugin-core / src / index.js View on Github external
) {
          let expressionPath = path.get('value.expression')
          if (expressionPath.isPure()) {
            if (!state.cssIdentifier) {
              state.cssIdentifier = addDefault(path, '@emotion/css', {
                nameHint: 'css'
              })
            }
            expressionPath.replaceWith(
              t.callExpression(
                t.cloneDeep(state.cssIdentifier),
                [
                  path.node.value.expression,
                  state.emotionSourceMap &&
                    path.node.loc !== undefined &&
                    t.stringLiteral(getSourceMap(path.node.loc.start, state))
                ].filter(Boolean)
              )
            )
            transformCssCallExpression({
              babel,
              state,
              path: expressionPath
            })
          }
        }
      }
    }
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))
      }
github emotion-js / next / packages / babel-plugin-core / src / css-macro.js View on Github external
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) {
      if (!sourceMap && path.node.loc !== undefined) {
        sourceMap = getSourceMap(path.node.loc.start, state)
      }
      appendStringToExpressions(path.node.arguments, sourceMap, t)
    }

    path.node.arguments = joinStringLiterals(path.node.arguments, t)

    if (
      path.node.arguments.length === 1 &&
      t.isStringLiteral(path.node.arguments[0])
    ) {
      let cssString = path.node.arguments[0].value
      let res = css(cssString)

      path.replaceWith(
        t.objectExpression([
          t.objectProperty(t.identifier('name'), t.stringLiteral(res.name)),
github emotion-js / next / packages / babel-plugin-core / src / styled-macro.js View on Github external
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(
            reference.parentPath.parentPath.node.arguments,
            sourceMap,
            t
          )
        }
      }
    })
  }