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

Add option explicitAmpersand on @emotion/cache to handle :is and :where, etc #3210

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
simplify implementation
  • Loading branch information
Andarist committed Jul 17, 2024
commit 9d502cd5a119c599db0ea5207a7b6f301e28f203
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
Loading