Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed an issue with dev-only labels not being added when source maps were disabled #2081

Merged
merged 1 commit into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ export default () => <Global styles={{ color: 'hotpink' }} />

↓ ↓ ↓ ↓ ↓ ↓

function _EMOTION_STRINGIFIED_CSS_ERROR__() { return \\"You have tried to stringify object returned from \`css\` function. It isn't supposed to be used directly (e.g. as value of the \`className\` prop), but rather handed to emotion so it can handle it (e.g. as value of \`css\` prop).\\"; }

import * as React from 'react';
import { Global } from '@emotion/react';
var _ref = {

var _ref = process.env.NODE_ENV === \\"production\\" ? {
name: \\"3sn2xs\\",
styles: \\"color:hotpink\\"
} : {
name: \\"3sn2xs\\",
styles: \\"color:hotpink\\",
toString: _EMOTION_STRINGIFIED_CSS_ERROR__
};

export default (() => <Global styles={_ref} />);"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,16 @@ styled.h1\`color:blue;\`

import _styled from \\"@emotion/styled/base\\";

function _EMOTION_STRINGIFIED_CSS_ERROR__() { return \\"You have tried to stringify object returned from \`css\` function. It isn't supposed to be used directly (e.g. as value of the \`className\` prop), but rather handed to emotion so it can handle it (e.g. as value of \`css\` prop).\\"; }

_styled(\\"h1\\", {
target: \\"e8evh370\\"
})({
})(process.env.NODE_ENV === \\"production\\" ? {
name: \\"117wnve\\",
styles: \\"color:blue\\"
} : {
name: \\"117wnve\\",
styles: \\"color:blue\\",
toString: _EMOTION_STRINGIFIED_CSS_ERROR__
});"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ let style = css({ color: 'hotpink' })

↓ ↓ ↓ ↓ ↓ ↓

function _EMOTION_STRINGIFIED_CSS_ERROR__() { return \\"You have tried to stringify object returned from \`css\` function. It isn't supposed to be used directly (e.g. as value of the \`className\` prop), but rather handed to emotion so it can handle it (e.g. as value of \`css\` prop).\\"; }

import { css } from '@emotion/react';
let style = {
let style = process.env.NODE_ENV === \\"production\\" ? {
name: \\"3sn2xs\\",
styles: \\"color:hotpink\\"
} : {
name: \\"1gfxf27-style\\",
styles: \\"color:hotpink;label:style;\\",
toString: _EMOTION_STRINGIFIED_CSS_ERROR__
};"
`;

Expand All @@ -25,12 +31,18 @@ let Comp = styled.div({ color: 'hotpink' })

import _styled from \\"@emotion/styled/base\\";

function _EMOTION_STRINGIFIED_CSS_ERROR__() { return \\"You have tried to stringify object returned from \`css\` function. It isn't supposed to be used directly (e.g. as value of the \`className\` prop), but rather handed to emotion so it can handle it (e.g. as value of \`css\` prop).\\"; }

let Comp = _styled(\\"div\\", {
target: \\"eggnygh0\\",
label: \\"Comp\\"
})({
})(process.env.NODE_ENV === \\"production\\" ? {
name: \\"3sn2xs\\",
styles: \\"color:hotpink\\"
} : {
name: \\"3sn2xs\\",
styles: \\"color:hotpink\\",
toString: _EMOTION_STRINGIFIED_CSS_ERROR__
});"
`;

Expand All @@ -42,9 +54,15 @@ let cls = css({ color: 'hotpink' })

↓ ↓ ↓ ↓ ↓ ↓

function _EMOTION_STRINGIFIED_CSS_ERROR__() { return \\"You have tried to stringify object returned from \`css\` function. It isn't supposed to be used directly (e.g. as value of the \`className\` prop), but rather handed to emotion so it can handle it (e.g. as value of \`css\` prop).\\"; }

import { css } from '@emotion/css';
let cls = /*#__PURE__*/css({
let cls = /*#__PURE__*/css(process.env.NODE_ENV === \\"production\\" ? {
name: \\"3sn2xs\\",
styles: \\"color:hotpink\\"
} : {
name: \\"6kh100-cls\\",
styles: \\"color:hotpink;label:cls;\\",
toString: _EMOTION_STRINGIFIED_CSS_ERROR__
});"
`;
52 changes: 26 additions & 26 deletions packages/babel-plugin/src/utils/transform-expression-with-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,41 +95,41 @@ export let transformExpressionWithStyles = ({
t.objectProperty(t.identifier('name'), t.stringLiteral(res.name)),
t.objectProperty(t.identifier('styles'), t.stringLiteral(res.styles))
])
let node = prodNode
if (sourceMap) {
if (!state.emotionStringifiedCssId) {
const uid = state.file.scope.generateUidIdentifier(
'__EMOTION_STRINGIFIED_CSS_ERROR__'
)
state.emotionStringifiedCssId = uid
const cssObjectToString = t.functionDeclaration(
uid,
[],
t.blockStatement([
t.returnStatement(t.stringLiteral(CSS_OBJECT_STRINGIFIED_ERROR))
])
)
cssObjectToString._compact = true
state.file.path.unshiftContainer('body', [cssObjectToString])
}

if (label && autoLabel === 'dev-only') {
res = serializeStyles([`${cssString};label:${label};`])
}
if (!state.emotionStringifiedCssId) {
const uid = state.file.scope.generateUidIdentifier(
'__EMOTION_STRINGIFIED_CSS_ERROR__'
)
state.emotionStringifiedCssId = uid
const cssObjectToString = t.functionDeclaration(
uid,
[],
t.blockStatement([
t.returnStatement(t.stringLiteral(CSS_OBJECT_STRINGIFIED_ERROR))
])
)
cssObjectToString._compact = true
state.file.path.unshiftContainer('body', [cssObjectToString])
}

let devNode = t.objectExpression([
if (label && autoLabel === 'dev-only') {
res = serializeStyles([`${cssString};label:${label};`])
}

let devNode = t.objectExpression(
[
t.objectProperty(t.identifier('name'), t.stringLiteral(res.name)),
t.objectProperty(t.identifier('styles'), t.stringLiteral(res.styles)),
t.objectProperty(t.identifier('map'), t.stringLiteral(sourceMap)),
sourceMap &&
t.objectProperty(t.identifier('map'), t.stringLiteral(sourceMap)),
t.objectProperty(
t.identifier('toString'),
t.cloneNode(state.emotionStringifiedCssId)
)
])
node = createNodeEnvConditional(t, prodNode, devNode)
}
].filter(Boolean)
)

return node
return createNodeEnvConditional(t, prodNode, devNode)
}

if (canAppendStrings && label) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@ const Component = props => <div css={[{ color: 'green' }]} {...props} />

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _EMOTION_STRINGIFIED_CSS_ERROR__() { return \\"You have tried to stringify object returned from \`css\` function. It isn't supposed to be used directly (e.g. as value of the \`className\` prop), but rather handed to emotion so it can handle it (e.g. as value of \`css\` prop).\\"; }

import * as React from 'react';
import { jsx as ___EmotionJSX } from \\"@emotion/react\\";
var _ref = {

var _ref = process.env.NODE_ENV === \\"production\\" ? {
name: \\"v98kxt\\",
styles: \\"color:green\\"
} : {
name: \\"vplqcj-__fixtures__--array-css-prop--Component\\",
styles: \\"color:green;label:__fixtures__--array-css-prop--Component;\\",
toString: _EMOTION_STRINGIFIED_CSS_ERROR__
};

const Component = props => ___EmotionJSX(\\"div\\", _extends({
Expand Down Expand Up @@ -43,12 +50,20 @@ export let Button = props => {

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _EMOTION_STRINGIFIED_CSS_ERROR__() { return \\"You have tried to stringify object returned from \`css\` function. It isn't supposed to be used directly (e.g. as value of the \`className\` prop), but rather handed to emotion so it can handle it (e.g. as value of \`css\` prop).\\"; }

import * as React from 'react';
import { jsx as ___EmotionJSX } from \\"@emotion/react\\";
var _ref = {

var _ref = process.env.NODE_ENV === \\"production\\" ? {
name: \\"3sn2xs\\",
styles: \\"color:hotpink\\"
} : {
name: \\"17qglar-__fixtures__--__fixtures__--Button\\",
styles: \\"color:hotpink;label:__fixtures__--__fixtures__--Button;\\",
toString: _EMOTION_STRINGIFIED_CSS_ERROR__
};

export let Button = props => {
return ___EmotionJSX(React.Fragment, null, ___EmotionJSX(\\"button\\", _extends({
css: _ref
Expand Down