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

Upgrade flow-bin to 0.131.0 and migrate types #1382

Merged
merged 5 commits into from Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions .flowconfig
Expand Up @@ -6,6 +6,4 @@

[options]
include_warnings=true
esproposal.export_star_as=enable
suppress_comment= \\(.\\|\n\\)*\\$FlowFixMe
suppress_comment= \\(.\\|\n\\)*\\$FlowIgnore
esproposal.export_star_as=enable
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -69,7 +69,7 @@
"eslint-config-jss": "^5.0.1",
"eslint-config-prettier": "^2.9.0",
"expect.js": "^0.3.1",
"flow-bin": "^0.98.0",
"flow-bin": "^0.131.0",
"json-loader": "^0.5.4",
"karma": "^1.3.0",
"karma-benchmark": "^0.6.0",
Expand Down
10 changes: 6 additions & 4 deletions packages/css-jss/src/createCss.js
Expand Up @@ -54,20 +54,22 @@ const createCss = (jss: Jss = defaultJss): Css => {
const labels = []

for (let i = 0; i < flatArgs.length; i++) {
let style = flatArgs[i]
const style = flatArgs[i]
if (!style) continue
let styleObject = style
// It can be a class name that css() has previously generated.
if (typeof style === 'string') {
// eslint-disable-next-line no-shadow
const cached = cache.get(style)
if (cached) {
// eslint-disable-next-line prefer-spread
if (cached.labels.length) labels.push.apply(labels, cached.labels)
style = cached.style
styleObject = cached.style
}
}
if (style.label && labels.indexOf(style.label) === -1) labels.push(style.label)
Object.assign(mergedStyle, style)
if (styleObject.label && labels.indexOf(styleObject.label) === -1)
labels.push(styleObject.label)
Object.assign(mergedStyle, styleObject)
}
delete mergedStyle.label
const label = labels.length === 0 ? 'css' : labels.join('-')
Expand Down
2 changes: 1 addition & 1 deletion packages/css-jss/src/createCss.test.js
Expand Up @@ -10,7 +10,7 @@ describe('css-jss', () => {

beforeEach(() => {
const jss = createJss({createGenerateId})
css = createCss(jss)
css = ((createCss(jss): any): Function)
kof marked this conversation as resolved.
Show resolved Hide resolved
})

it('should accept a single style object argument', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/jss-plugin-extend/src/index.js
Expand Up @@ -107,6 +107,7 @@ export default function jssExtend(): Plugin {
if (typeof value === 'object') {
// $FlowFixMe: This will be an object
for (const key in value) {
// $FlowFixMe: This will be an object
rule.prop(key, value[key])
}

Expand Down
4 changes: 3 additions & 1 deletion packages/jss/src/Jss.js
Expand Up @@ -110,12 +110,14 @@ export default class Jss {
* Create a rule without a Style Sheet.
* [Deprecated] will be removed in the next major version.
*/
createRule(name?: string, style?: JssStyle = {}, options?: RuleFactoryOptions = {}): Rule | null {
createRule(name: string, style?: JssStyle = {}, options?: RuleFactoryOptions = {}): Rule | null {
// Enable rule without name for inline styles.
if (typeof name === 'object') {
// $FlowIgnore
return this.createRule(undefined, name, style)
}

// $FlowIgnore
const ruleOptions: RuleOptions = {...options, name, jss: this, Renderer: this.options.Renderer}

if (!ruleOptions.generateId) ruleOptions.generateId = this.generateId
Expand Down
2 changes: 2 additions & 0 deletions packages/jss/src/RuleList.js
Expand Up @@ -68,6 +68,8 @@ export default class RuleList {
generateId,
scoped,
name,
keyframes: this.keyframes,
selector: undefined,
...ruleOptions
}

Expand Down
2 changes: 1 addition & 1 deletion packages/jss/src/SheetsRegistry.js
Expand Up @@ -56,7 +56,7 @@ export default class SheetsRegistry {
/**
* Convert all attached sheets to a CSS string.
*/
toString({attached, ...options}: {attached?: boolean, ...ToCssOptions} = {}): string {
toString({attached, ...options}: {|attached?: boolean|} & ToCssOptions = {}): string {
kof marked this conversation as resolved.
Show resolved Hide resolved
let css = ''
for (let i = 0; i < this.registry.length; i++) {
const sheet = this.registry[i]
Expand Down
10 changes: 5 additions & 5 deletions packages/jss/src/types/jss.js
Expand Up @@ -111,7 +111,7 @@ export interface ContainerRule extends BaseRule {
export type RuleOptions = {
selector?: string,
scoped?: boolean,
sheet?: StyleSheet,
sheet: StyleSheet,
index?: number,
parent?: ContainerRule | StyleSheet,
classes: Classes,
Expand Down Expand Up @@ -177,7 +177,7 @@ export type StyleSheetFactoryOptions = {
classNamePrefix?: string
}

export type StyleSheetOptions = {|
export type StyleSheetOptions = {
media?: string,
meta?: string,
link?: boolean,
Expand All @@ -188,9 +188,9 @@ export type StyleSheetOptions = {|
Renderer?: Class<Renderer> | null,
insertionPoint?: InsertionPoint,
jss: Jss
|}
}
kof marked this conversation as resolved.
Show resolved Hide resolved

export type InternalStyleSheetOptions = {|
export type InternalStyleSheetOptions = {
media?: string,
meta?: string,
link?: boolean,
Expand All @@ -205,4 +205,4 @@ export type InternalStyleSheetOptions = {|
parent: ConditionalRule | KeyframesRule | StyleSheet,
classes: Classes,
keyframes: KeyframesMap
|}
}
2 changes: 1 addition & 1 deletion packages/react-jss/src/JssProvider.js
Expand Up @@ -79,7 +79,7 @@ export default class JssProvider extends Component<Props> {
}

if (classNamePrefix) {
context.classNamePrefix += classNamePrefix
context.classNamePrefix = (context.classNamePrefix || '') + classNamePrefix
}

if (media !== undefined) {
Expand Down
3 changes: 1 addition & 2 deletions packages/react-jss/src/jsx.js
Expand Up @@ -4,8 +4,7 @@ import React from 'react'
import defaultCss, {type Css} from 'css-jss'

export const create = (css: Css = defaultCss) =>
// $FlowIgnore we don't care about the types here, since this is going to be called by the build tool.
function createElement(type, props) {
function createElement(type: string, props: Object | null /* :: , ..._args: any */) {
const args = arguments
if (props && props.css) {
const className = css(props.css)
Expand Down
1 change: 1 addition & 0 deletions packages/react-jss/src/styled-props-filter.test.js
Expand Up @@ -182,6 +182,7 @@ describe('React-JSS: styled props filter', () => {
})
})

// $FlowIgnore
it.skip('no prop filtering on string tags started with upper case', () => {
const Link = styled('SomeCustomLink')({color: 'green'})

Expand Down
2 changes: 2 additions & 0 deletions packages/react-jss/src/styled.test.js
Expand Up @@ -300,6 +300,7 @@ describe('React-JSS: styled', () => {
})
})

// $FlowIgnore
it.skip('should target another styled component (not sure if we really need this)', () => {
const Span = styled('span')({color: 'red'})
const Div = styled('div')({
Expand Down Expand Up @@ -340,6 +341,7 @@ describe('React-JSS: styled', () => {
`)
})

// $FlowIgnore
it.skip('should override theme over props', () => {})

it('should render label', () => {
Expand Down
14 changes: 7 additions & 7 deletions packages/react-jss/src/utils/sheetsMeta.js
@@ -1,16 +1,16 @@
// @flow
import type {StyleSheet} from 'jss'
import type {StaticStyles} from '../types'
import type {StaticStyles, DynamicStyle} from '../types'

type SheetMeta = {|
styles: StaticStyles,
dynamicStyles: StaticStyles
type SheetMeta<Theme> = {|
styles: $ReadOnly<StaticStyles>,
dynamicStyles: $ReadOnly<{[key: string]: DynamicStyle<Theme>}>
|}

const sheetsMeta = new WeakMap<StyleSheet, SheetMeta>()
const sheetsMeta = new WeakMap<StyleSheet, SheetMeta<any>>()

export const getMeta = (sheet: StyleSheet): SheetMeta | void => sheetsMeta.get(sheet)
export const getMeta = <Theme>(sheet: StyleSheet): SheetMeta<Theme> | void => sheetsMeta.get(sheet)

export const addMeta = (sheet: StyleSheet, meta: SheetMeta) => {
export const addMeta = <Theme>(sheet: StyleSheet, meta: SheetMeta<Theme>) => {
sheetsMeta.set(sheet, meta)
}
3 changes: 2 additions & 1 deletion packages/react-jss/tests/styledSystem.js
Expand Up @@ -180,7 +180,8 @@ describe('React-JSS: styled-system', () => {
expect(className).to.be('css-0 css-d0-1')
expect(classes).to.be(undefined)
})

// $FlowIgnore
it.skip('should handle the propTypes/meta for validation from function rules', () => {})
// $FlowIgnore
it.skip('should do compose() automatically', () => {})
})
8 changes: 4 additions & 4 deletions yarn.lock
Expand Up @@ -4267,10 +4267,10 @@ flat-cache@^1.2.1:
graceful-fs "^4.1.2"
write "^0.2.1"

flow-bin@^0.98.0:
version "0.98.1"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.98.1.tgz#a8d781621c91703df69928acc83c9777e2fcbb49"
integrity sha512-y1YzQgbFUX4EG6h2EO8PhyJeS0VxNgER8XsTwU8IXw4KozfneSmGVgw8y3TwAOza7rVhTlHEoli1xNuNW1rhPw==
flow-bin@^0.131.0:
version "0.131.0"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.131.0.tgz#d4228b6070afdf3b2a76acdee77a7f3f8e8f5133"
integrity sha512-fZmoIBcDrtLhy/NNMxwJysSYzMr1ksRcAOMi3AHSoYXfcuQqTvhGJx+wqjlIOqIwz8RRYm8J4V4JrSJbIKP+Xg==

flush-write-stream@^1.0.0:
version "1.0.3"
Expand Down