-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Stylis v4 #1817
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
Merged
Stylis v4 #1817
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
78afccd
Stylis v4 tryout
Andarist 2d95e2c
Move @import rules in test to be first
Andarist 174395a
Improved compat plugin
Andarist 87bd0ba
Add tests for orphanated pseudos
Andarist 4477c6a
orphanated -> orphaned
Andarist 24f0d0d
Upgrade stylis and improve compat plugin
Andarist 3833179
Improve compat plugin - avoid double compilation
Andarist 85b523b
Shorten compat plugin a little bit
Andarist 79a679a
Add guard for global top-level rules in the compat plugin
Andarist c6a79be
Fix tagged templates minifier (#1836)
Andarist 48629c7
Make compat plugin be always included
Andarist 06dd9c2
move removeLabel into omnipresentPlugins
Andarist 4ab60ed
Stop special-casing @import insertion
Andarist c45a983
fix getServerStylisCache
Andarist d6bb08d
Remove outdated docs around stylisPlugins and prefix options
Andarist faa8163
Add changesets
Andarist 0654b2a
Add note about prefixer being just a plugin to stylisPlugins docs
Andarist 5e39d81
Actually use officially published Stylis v4
Andarist a1d7173
Improve error message about incorrect @import insertion
Andarist 345827d
Fix flow errors
Andarist f561e5c
Reword error messages and changeset content
Andarist 35baa12
update snapshots
Andarist c076015
Remove mention of `@import` not being usable in `css` calls as it was…
Andarist 703b1dd
Add mention to the changeset about where one can find a prefixer
Andarist 2ec872c
Update .changeset/warm-ties-drop.md
emmatown File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,89 +1,47 @@ | ||
| // @flow | ||
| // https://github.com/thysultan/stylis.js/tree/master/plugins/rule-sheet | ||
| // inlined to avoid umd wrapper and peerDep warnings/installing stylis | ||
| // since we use stylis after closure compiler | ||
| const last = arr => (arr.length ? arr[arr.length - 1] : null) | ||
|
|
||
| import type { StylisPlugin } from './types' | ||
|
|
||
| const delimiter = '/*|*/' | ||
| const needle = delimiter + '}' | ||
|
|
||
| function toSheet(block) { | ||
| if (block) { | ||
| Sheet.current.insert(block + '}') | ||
| export let removeLabel = element => { | ||
| if (element.type === 'decl') { | ||
| var value = element.value | ||
| if ( | ||
| // charcode for l | ||
| value.charCodeAt(0) === 108 && | ||
| // charcode for b | ||
| value.charCodeAt(2) === 98 | ||
| ) { | ||
| // this ignores label | ||
| element.return = '' | ||
| element.value = '' | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export let Sheet: { current: { +insert: string => void } } = { | ||
| current: (null: any) | ||
| } | ||
| const ignoreFlag = | ||
| 'emotion-disable-server-rendering-unsafe-selector-warning-please-do-not-use-this-the-warning-exists-for-a-reason' | ||
|
|
||
| export let ruleSheet: StylisPlugin = ( | ||
| context, | ||
| content, | ||
| selectors, | ||
| parents, | ||
| line, | ||
| column, | ||
| length, | ||
| ns, | ||
| depth, | ||
| at | ||
| ) => { | ||
| switch (context) { | ||
| // property | ||
| case 1: { | ||
| switch (content.charCodeAt(0)) { | ||
| case 64: { | ||
| // @import | ||
| Sheet.current.insert(content + ';') | ||
| return '' | ||
| } | ||
| // charcode for l | ||
| case 108: { | ||
| // charcode for b | ||
| // this ignores label | ||
| if (content.charCodeAt(2) === 98) { | ||
| return '' | ||
| } | ||
| } | ||
| } | ||
| break | ||
| } | ||
| // selector | ||
| case 2: { | ||
| if (ns === 0) return content + delimiter | ||
| break | ||
| } | ||
| // at-rule | ||
| case 3: { | ||
| switch (ns) { | ||
| // @font-face, @page | ||
| case 102: | ||
| case 112: { | ||
| Sheet.current.insert(selectors[0] + content) | ||
| return '' | ||
| } | ||
| default: { | ||
| return content + (at === 0 ? delimiter : '') | ||
| } | ||
| } | ||
| } | ||
| case -2: { | ||
| content.split(needle).forEach(toSheet) | ||
| } | ||
| } | ||
| } | ||
| const isIgnoringComment = element => | ||
| !!element && | ||
| element.type === 'comm' && | ||
| element.children.indexOf(ignoreFlag) > -1 | ||
|
|
||
| export let removeLabel: StylisPlugin = (context, content) => { | ||
| if ( | ||
| context === 1 && | ||
| // charcode for l | ||
| content.charCodeAt(0) === 108 && | ||
| // charcode for b | ||
| content.charCodeAt(2) === 98 | ||
| // this ignores label | ||
| ) { | ||
| return '' | ||
| export let createUnsafeSelectorsAlarm = cache => (element, index, children) => { | ||
Andarist marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (element.type !== 'rule') return | ||
|
|
||
| const unsafePseudoClasses = element.value.match( | ||
| /(:first|:nth|:nth-last)-child/g | ||
| ) | ||
|
|
||
| if (unsafePseudoClasses && cache.compat !== true) { | ||
| const prevElement = index > 0 ? children[index - 1] : null | ||
| if (prevElement && isIgnoringComment(last(prevElement.children))) { | ||
| return | ||
| } | ||
| unsafePseudoClasses.forEach(unsafePseudoClass => { | ||
| console.error( | ||
| `The pseudo class "${unsafePseudoClass}" is potentially unsafe when doing server-side rendering. Try changing it to "${ | ||
| unsafePseudoClass.split('-child')[0] | ||
| }-of-type".` | ||
| ) | ||
| }) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,26 @@ | ||
| // @flow | ||
|
|
||
| export type StylisPlugin = ( | ||
| context: -2 | -1 | 0 | 1 | 2 | 3, | ||
| content: string, | ||
| selectors: Array<string>, | ||
| parents: Array<string>, | ||
| export type StylisElement = { | ||
| type: string, | ||
| value: string, | ||
| props: Array<string>, | ||
| root: StylisElement | null, | ||
| children: Array<StylisElement>, | ||
| line: number, | ||
| column: number, | ||
| length: number, | ||
| at: number, | ||
| depth: number | ||
| ) => mixed | ||
| return: string | ||
| } | ||
| export type StylisPluginCallback = ( | ||
| element: StylisElement, | ||
| index: number, | ||
| children: Array<StylisElement>, | ||
| callback: StylisPluginCallback | ||
| ) => string | void | ||
|
|
||
| export type StylisPlugin = ( | ||
| element: StylisElement, | ||
| index: number, | ||
| children: Array<StylisElement>, | ||
| callback: StylisPluginCallback | ||
| ) => string | void |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.