-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
2,226 additions
and
3,764 deletions.
There are no files selected for viewing
This file contains 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 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) => { | ||
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 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
Oops, something went wrong.