Skip to content

Commit

Permalink
simplify implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist committed Jul 17, 2024
1 parent ba45f6d commit 9d502cd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 3 additions & 1 deletion packages/cache/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ let createCache = (options /*: Options */) /*: EmotionCache */ => {
sheet: StyleSheet,
shouldCache: boolean
) => string | void */
const omnipresentPlugins = [compat(options), removeLabel]
const omnipresentPlugins = options.explicitAmpersand
? [removeLabel]
: [compat, removeLabel]

if (process.env.NODE_ENV !== 'production') {
omnipresentPlugins.push(
Expand Down
12 changes: 5 additions & 7 deletions packages/cache/src/stylis-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ const identifierWithPointTracking = (begin, points, index) => {
return slice(begin, position)
}

const toRules = (parsed, points, options) => {
const { explicitAmpersand = false } = options || {}
const toRules = (parsed, points) => {
// pretend we've started with a comma
let index = -1
let character = 44
Expand All @@ -66,7 +65,7 @@ const toRules = (parsed, points, options) => {
break
case 4:
// comma
if (character === 44 && !explicitAmpersand) {
if (character === 44) {
// colon
parsed[++index] = peek() === 58 ? '&\f' : ''
points[index] = parsed[index].length
Expand All @@ -81,13 +80,12 @@ const toRules = (parsed, points, options) => {
return parsed
}

const getRules = (value, points, options) =>
dealloc(toRules(alloc(value), points, options))
const getRules = (value, points) => dealloc(toRules(alloc(value), points))

// WeakSet would be more appropriate, but only WeakMap is supported in IE11
const fixedElements = /* #__PURE__ */ new WeakMap()

export let compat = options => element => {
export let compat = element => {
if (
element.type !== 'rule' ||
!element.parent ||
Expand Down Expand Up @@ -125,7 +123,7 @@ export let compat = options => element => {
fixedElements.set(element, true)

const points = []
const rules = getRules(value, points, options)
const rules = getRules(value, points)
const parentRules = parent.props

for (let i = 0, k = 0; i < rules.length; i++) {
Expand Down

0 comments on commit 9d502cd

Please sign in to comment.