From 9d502cd5a119c599db0ea5207a7b6f301e28f203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Wed, 17 Jul 2024 17:00:38 +0200 Subject: [PATCH] simplify implementation --- packages/cache/src/index.js | 4 +++- packages/cache/src/stylis-plugins.js | 12 +++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/cache/src/index.js b/packages/cache/src/index.js index 0b5712e81..dcdb52c6e 100644 --- a/packages/cache/src/index.js +++ b/packages/cache/src/index.js @@ -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( diff --git a/packages/cache/src/stylis-plugins.js b/packages/cache/src/stylis-plugins.js index 092cf84f1..1c1bbb821 100644 --- a/packages/cache/src/stylis-plugins.js +++ b/packages/cache/src/stylis-plugins.js @@ -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 @@ -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 @@ -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 || @@ -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++) {