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

Improve labels and upgrade @emotion/stylis #741

Merged
merged 2 commits into from
Jun 21, 2018
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
1 change: 1 addition & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

[options]
suppress_comment=.*\\$FlowFixMe
module.name_mapper='^\(@emotion/babel-utils\)$' -> '<PROJECT_ROOT>/test/empty.js'
module.name_mapper='^\(create-emotion\)$' -> '<PROJECT_ROOT>/packages/\1/src'
module.name_mapper='^\(create-emotion-styled\)$' -> '<PROJECT_ROOT>/packages/\1/src'
module.name_mapper='^\(react-emotion\)$' -> '<PROJECT_ROOT>/packages/\1/src'
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-plugin-emotion/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
},
"dependencies": {
"@babel/helper-module-imports": "7.0.0-beta.40",
"@emotion/babel-utils": "^0.5.3",
"@emotion/babel-utils": "^0.6.4",
"@emotion/hash": "^0.6.2",
"@emotion/memoize": "^0.6.1",
"@emotion/stylis": "^0.6.5",
"@emotion/stylis": "^0.6.10",
"babel-plugin-macros": "^2.0.0",
"babel-plugin-syntax-jsx": "^6.18.0",
"convert-source-map": "^1.5.0",
Expand Down
43 changes: 3 additions & 40 deletions packages/babel-plugin-emotion/src/babel-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,12 @@ import { hashArray } from './index'
import type { BabelPath, EmotionBabelPluginPass } from './index'
import type { Types, Identifier } from 'babel-flow-types'

export { getLabelFromPath as getIdentifierName } from '@emotion/babel-utils'

function cloneNode(t, node) {
return (typeof t.cloneNode === 'function' ? t.cloneNode : t.cloneDeep)(node)
}

function getDeclaratorName(path: BabelPath, t: Types) {
// $FlowFixMe
const parent = path.findParent(p => p.isVariableDeclarator())
return parent && t.isIdentifier(parent.node.id) ? parent.node.id.name : ''
}

export function getIdentifierName(path: BabelPath, t: Types) {
let classParent
if (path) {
// $FlowFixMe
classParent = path.findParent(p => t.isClass(p))
}
if (classParent && classParent.node.id) {
return t.isIdentifier(classParent.node.id) ? classParent.node.id.name : ''
} else if (
classParent &&
classParent.node.superClass &&
classParent.node.superClass.name
) {
return `${getDeclaratorName(path, t)}(${classParent.node.superClass.name})`
}

return getDeclaratorName(path, t)
}

export function getRuntimeImportPath(path: BabelPath, t: Types) {
// $FlowFixMe
const binding = path.scope.getBinding(path.node.name)
Expand Down Expand Up @@ -155,18 +132,4 @@ export function omit(
return target
}

export const appendStringToExpressions = (
expressions: Array<*>,
string: string,
t: *
) => {
if (!string) {
return expressions
}
if (t.isStringLiteral(expressions[expressions.length - 1])) {
expressions[expressions.length - 1].value += string
} else {
expressions.push(t.stringLiteral(string))
}
return expressions
}
export { appendStringToExpressions } from '@emotion/babel-utils'
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ exports[`babel css prop inline babel 6 label in higher order component 1`] = `

const foo = W => class extends Component {
render() {
return <div className={/*#__PURE__*/_css(\\"color:brown;label:foo(Component);\\")}>Hello</div>;
return <div className={/*#__PURE__*/_css(\\"color:brown;label:foo;\\")}>Hello</div>;
}
};"
`;
Expand Down Expand Up @@ -288,7 +288,7 @@ const foo = W => class extends Component {
render() {
return <div className={
/*#__PURE__*/
_css(\\"color:brown;label:foo(Component);\\")}>Hello</div>;
Copy link
Member Author

@emmatown emmatown Jun 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would have broken before since class names can't have brackets

_css(\\"color:brown;label:foo;\\")}>Hello</div>;
}

};"
Expand Down
40 changes: 40 additions & 0 deletions packages/babel-plugin-emotion/test/__snapshots__/css.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,18 @@ exports[`babel css inline babel 6 nested expanded properties 1`] = `
/*#__PURE__*/css(\\"margin:12px 48px;& .div{display:flex;}\\");"
`;

exports[`babel css inline babel 6 object label 1`] = `
"
let obj = {
someProp: /*#__PURE__*/css({ color: 'green' }, 'label:someProp;'),
'anotherProp': /*#__PURE__*/css({ color: 'hotpink' }, 'label:anotherProp;')
};
class Thing {
static Prop = /*#__PURE__*/css({ color: 'yellow' }, 'label:Prop;');
BadIdea = /*#__PURE__*/css({ color: 'red' }, 'label:BadIdea;');
}"
`;

exports[`babel css inline babel 6 object with a bunch of stuff 1`] = `
"
const cls2 = /*#__PURE__*/css({
Expand Down Expand Up @@ -552,6 +564,34 @@ exports[`babel css inline babel 7 nested expanded properties 1`] = `
css(\\"margin:12px 48px;& .div{display:flex;}\\");"
`;

exports[`babel css inline babel 7 object label 1`] = `
"let obj = {
someProp:
/*#__PURE__*/
css({
color: 'green'
}, \\"label:someProp;\\"),
'anotherProp':
/*#__PURE__*/
css({
color: 'hotpink'
}, \\"label:anotherProp;\\")
};

class Thing {
static Prop =
/*#__PURE__*/
css({
color: 'yellow'
}, \\"label:Prop;\\");
BadIdea =
/*#__PURE__*/
css({
color: 'red'
}, \\"label:BadIdea;\\");
}"
`;

exports[`babel css inline babel 7 object with a bunch of stuff 1`] = `
"const cls2 =
/*#__PURE__*/
Expand Down
15 changes: 15 additions & 0 deletions packages/babel-plugin-emotion/test/css.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,21 @@ function test () {
\`

`
},
'object label': {
code: `
let obj = {
someProp: css({color:'green'}),
'anotherProp': css({color:'hotpink'})
}
class Thing {
static Prop = css({color:'yellow'})
BadIdea = css({color:'red'})
}
`,
opts: {
autoLabel: true
}
}
}
createInlineTests('babel css inline', inline)
Expand Down
1 change: 1 addition & 0 deletions packages/babel-plugin-emotion/test/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const createInlineTester = babel => opts => {
const { code, ast } = babel.transform(opts.code, {
plugins: [
stage2,
require('babel-plugin-syntax-class-properties'),
[
plugin,
{
Expand Down
2 changes: 1 addition & 1 deletion packages/create-emotion/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"dependencies": {
"@emotion/hash": "^0.6.2",
"@emotion/memoize": "^0.6.1",
"@emotion/stylis": "^0.6.5",
"@emotion/stylis": "^0.6.10",
"@emotion/unitless": "^0.6.2",
"csstype": "^2.5.2",
"stylis": "^3.5.0",
Expand Down
1 change: 1 addition & 0 deletions test/empty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// used to alias flow files that error
71 changes: 61 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -777,11 +777,18 @@
unist-util-remove-position "^1.1.1"
xtend "^4.0.1"

"@emotion/babel-utils@^0.5.3":
version "0.5.3"
resolved "https://registry.yarnpkg.com/@emotion/babel-utils/-/babel-utils-0.5.3.tgz#6be6dd7a480fdbdfb6cbba7f4f6d9361744b8d6e"
"@emotion/babel-utils@^0.6.4":
version "0.6.4"
resolved "https://registry.yarnpkg.com/@emotion/babel-utils/-/babel-utils-0.6.4.tgz#2eac69eb31ae944fbe4a2a0e736a35db5f810866"
dependencies:
"@emotion/hash" "^0.6.3"
"@emotion/memoize" "^0.6.2"
"@emotion/serialize" "^0.8.2"
convert-source-map "^1.5.1"
find-root "^1.1.0"
source-map "^0.7.2"

"@emotion/hash@^0.6.2":
"@emotion/hash@^0.6.2", "@emotion/hash@^0.6.3":
version "0.6.3"
resolved "https://registry.yarnpkg.com/@emotion/hash/-/hash-0.6.3.tgz#0e7a5604626fc6c6d4ac4061a2f5ac80d50262a4"

Expand All @@ -795,14 +802,27 @@
version "0.6.2"
resolved "https://registry.yarnpkg.com/@emotion/memoize/-/memoize-0.6.2.tgz#138e00b332d519b4e307bded6159e5ba48aba3ae"

"@emotion/stylis@^0.6.5":
version "0.6.8"
resolved "https://registry.yarnpkg.com/@emotion/stylis/-/stylis-0.6.8.tgz#6ad4e8d32b19b440efa4481bbbcb98a8c12765bb"
"@emotion/serialize@^0.8.2":
version "0.8.2"
resolved "https://registry.yarnpkg.com/@emotion/serialize/-/serialize-0.8.2.tgz#d3b2caddfc93107d63c79fc6bbc11e555e3b762e"
dependencies:
"@emotion/hash" "^0.6.3"
"@emotion/memoize" "^0.6.2"
"@emotion/unitless" "^0.6.3"
"@emotion/utils" "^0.7.1"

"@emotion/stylis@^0.6.10":
version "0.6.10"
resolved "https://registry.yarnpkg.com/@emotion/stylis/-/stylis-0.6.10.tgz#7d321e639ebc8ba23ace5990c20e94dcebb8f3dd"

"@emotion/unitless@^0.6.2":
"@emotion/unitless@^0.6.2", "@emotion/unitless@^0.6.3":
version "0.6.3"
resolved "https://registry.yarnpkg.com/@emotion/unitless/-/unitless-0.6.3.tgz#65682e68a82701c70eefb38d7f941a2c0bfa90de"

"@emotion/utils@^0.7.1":
version "0.7.1"
resolved "https://registry.yarnpkg.com/@emotion/utils/-/utils-0.7.1.tgz#e44e596d03c9f16ba3b127ad333a8a072bcb5a0a"

"@types/configstore@^2.1.1":
version "2.1.1"
resolved "https://registry.yarnpkg.com/@types/configstore/-/configstore-2.1.1.tgz#cd1e8553633ad3185c3f2f239ecff5d2643e92b6"
Expand Down Expand Up @@ -3772,6 +3792,14 @@ create-hmac@^1.1.0, create-hmac@^1.1.2, create-hmac@^1.1.4:
safe-buffer "^5.0.1"
sha.js "^2.4.8"

create-react-class@^15.6.0:
version "15.6.3"
resolved "https://registry.yarnpkg.com/create-react-class/-/create-react-class-15.6.3.tgz#2d73237fb3f970ae6ebe011a9e66f46dbca80036"
dependencies:
fbjs "^0.8.9"
loose-envify "^1.3.1"
object-assign "^4.1.1"

cross-env@^3.1.1:
version "3.2.4"
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-3.2.4.tgz#9e0585f277864ed421ce756f81a980ff0d698aba"
Expand Down Expand Up @@ -11625,7 +11653,16 @@ react-dev-utils@^4.2.1:
strip-ansi "3.0.1"
text-table "0.2.0"

react-dom@^15.6.0, react-dom@^16.0.0, react-dom@^16.2.0:
react-dom@^15.6.0:
version "15.6.2"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-15.6.2.tgz#41cfadf693b757faf2708443a1d1fd5a02bef730"
dependencies:
fbjs "^0.8.9"
loose-envify "^1.1.0"
object-assign "^4.1.0"
prop-types "^15.5.10"

react-dom@^16.0.0, react-dom@^16.2.0:
version "16.4.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.4.0.tgz#099f067dd5827ce36a29eaf9a6cdc7cbf6216b1e"
dependencies:
Expand Down Expand Up @@ -11746,7 +11783,17 @@ react-test-renderer@^16.0.0-0, react-test-renderer@^16.2.0:
prop-types "^15.6.0"
react-is "^16.4.0"

react@^15.6.0, react@^16.0.0, react@^16.2.0:
react@^15.6.0:
version "15.6.2"
resolved "https://registry.yarnpkg.com/react/-/react-15.6.2.tgz#dba0434ab439cfe82f108f0f511663908179aa72"
dependencies:
create-react-class "^15.6.0"
fbjs "^0.8.9"
loose-envify "^1.1.0"
object-assign "^4.1.0"
prop-types "^15.5.10"

react@^16.0.0, react@^16.2.0:
version "16.4.0"
resolved "https://registry.yarnpkg.com/react/-/react-16.4.0.tgz#402c2db83335336fba1962c08b98c6272617d585"
dependencies:
Expand Down Expand Up @@ -13194,6 +13241,10 @@ source-map@^0.6.1, source-map@~0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"

source-map@^0.7.2:
version "0.7.3"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.3.tgz#5302f8169031735226544092e64981f751750383"

sourcemapped-stacktrace@^1.1.6:
version "1.1.8"
resolved "https://registry.yarnpkg.com/sourcemapped-stacktrace/-/sourcemapped-stacktrace-1.1.8.tgz#6b7a3f1a6fb15f6d40e701e23ce404553480d688"
Expand Down