diff --git a/next-packages/stylis/__tests__/__snapshots__/index.js.snap b/next-packages/stylis/__tests__/__snapshots__/index.js.snap index a7be97261..3bcc26dee 100644 --- a/next-packages/stylis/__tests__/__snapshots__/index.js.snap +++ b/next-packages/stylis/__tests__/__snapshots__/index.js.snap @@ -79,7 +79,7 @@ Array [ ".css-37 .List :global(*) :global(+) :global(*){margin-top:10px;}", ".css-37 .List :global(> *){margin-top:10px;}", ".css-37 .List :global(* + *){margin-top:10px;}", - ".css-37 :global(.foo #bar > baz){color:red;}", + ".css-37:global(.foo #bar > baz){color:red;}", ".css-37 div :global(.react-select .some-child-of-react-select){color:red;}", ".css-37 .root > :global(*):not(header){color:red;}", ".css-37 a:matches( a +b foo:hover :global(marquee) a) > :hover{color:red;}", @@ -89,7 +89,7 @@ Array [ exports[`cascade isolation nesting 1`] = ` Array [ ".css-39{color:red;}", - ".css-39 h1 :global(section){color:red;}", + ".css-39 h1:global(section){color:red;}", ".css-39 h1 h2{color:red;}", ".css-39 div h1,.css-39 span h1{color:red;}", ".css-39 span:hover{color:red;}", @@ -123,7 +123,14 @@ Array [ ] `; -exports[`comments 1`] = `Array []`; +exports[`comments 1`] = ` +Array [ + ".css-7{/*! 1 */color:red;/*! 2 */}", + ".css-7 button{color:blue;}", + ".css-7 button{color:red;}", + ".css-7 h1{/*! 1 */color:red;/*! 2 */color:red;/*! 3 */}", +] +`; exports[`complex nested selector 1`] = ` Array [ @@ -228,8 +235,8 @@ Array [ exports[`nested 1`] = ` Array [ - ".css-28 :global(div) h2{color:red;}", - ".css-28 :global(div) h2 h3{color:blue;}", + ".css-28:global(div) h2{color:red;}", + ".css-28:global(div) h2 h3{color:blue;}", ".foo .css-28{width:1px;}", ".foo .css-28:hover{color:black;}", ".foo .css-28 li{color:white;}", diff --git a/next-packages/stylis/__tests__/index.js b/next-packages/stylis/__tests__/index.js index 26955b8cd..6b027fa7e 100644 --- a/next-packages/stylis/__tests__/index.js +++ b/next-packages/stylis/__tests__/index.js @@ -6,7 +6,8 @@ const specs: Array<{ name: string, sample: string, skip?: boolean, - only?: boolean + only?: boolean, + expected?: string }> = [ { name: 'calc rules', @@ -41,8 +42,34 @@ const specs: Array<{ }, { name: 'comments', - sample: - "// line comment// color: red;/** * removes block comments and line comments, * there's a fire in the house // there is */button /* // what's xxx */{color: blue;}// hellobutton /* 1 */{color: red; /* 2 */}" + sample: ` + // line comment + // color: red; + /** + * removes block comments and line comments, + * there's a fire in the house // there is + */ + button /* + // what's + xxx + */ + {color: blue;} + // hello + button /* 1 */ + { + color: red; /* 2 */ + } + /*! 1 */ + color: red; + /*! 2 */ + h1 { + /*! 1 */ + color: red; + /*! 2 */ + color: red; + /*! 3 */ + } + ` }, { name: '&', @@ -229,6 +256,37 @@ const specs: Array<{ name: 'complex nested selector', sample: '&:hover{color:blue;&:active{color:red;}}font-size:2rem;padding:16px;&:hover{color:pink;&:active{color:purple;}&.some-class{color:yellow;}}' + }, + { + name: 'more comments', + sample: `.a{color:red; /*// */}`, + expected: `.user .a{color:red;}` + }, + { + name: 'comments(context character IV)', + sample: `.a{/**/color:red}`, + expected: `.user .a{color:red;}` + }, + { + name: 'comments(context character V)', + sample: `.a{color:red;/*// + color:blue;*/}`, + expected: `.user .a{color:red;}` + }, + { + name: 'comments(context character VI)', + sample: `background: url("img}.png");.a {background: url("img}.png");}`, + expected: `.user{background:url("img}.png");}.user .a{background:url("img}.png");}` + }, + { + name: 'comments(context character VII)', + sample: `background: url(img}.png);.a {background: url(img}.png);}`, + expected: `.user{background:url(img}.png);}.user .a{background:url(img}.png);}` + }, + { + name: 'comments(context character VIII)', + sample: `background: url[img}.png];.a {background: url[img}.png];}`, + expected: `.user{background:url[img}.png];}.user .a{background:url[img}.png];}` } ] @@ -250,9 +308,14 @@ specs.forEach((spec, i) => { const plugin = stylisRuleSheet(rule => { out.push(rule) }) + let selector = spec.expected ? '.user' : `.css-${i}` stylis.use(null)(plugin) - stylis(`.css-${i}`, spec.sample) - expect(out).toMatchSnapshot() - expect(out.join('')).toEqual(regularStylis(`.css-${i}`, spec.sample)) + stylis(selector, spec.sample) + if (spec.expected) { + expect(out.join('')).toEqual(spec.expected) + } else { + expect(out).toMatchSnapshot() + } + expect(out.join('')).toEqual(regularStylis(selector, spec.sample)) }) }) diff --git a/next-packages/stylis/build.js b/next-packages/stylis/build.js index e4d7ee685..943d0add4 100644 --- a/next-packages/stylis/build.js +++ b/next-packages/stylis/build.js @@ -13,6 +13,7 @@ const recast = require('recast') const readFile = promisify(fs.readFile) const writeFile = promisify(fs.writeFile) +// can be removed after https://github.com/thysultan/stylis.js/pull/111 const removeUselessThingForQuotes = src => j(src) .find(j.SwitchStatement, { @@ -33,6 +34,7 @@ const removeUselessThingForQuotes = src => }) .toSource() +// can be removed after https://github.com/thysultan/stylis.js/pull/112 const removeUselessCasesInProxy = src => j(src) .find(j.FunctionDeclaration, { id: { name: 'proxy' } }) @@ -129,6 +131,7 @@ async function doThing() { 'comment + quote + parentheses + bracket + semicolon === 0', 'true === false' ) + .replace('switch (selector.charCodeAt(1))', 'switch (100)') .replace('(insert === 1)', '(true === false)') .replace('input.charCodeAt(9)*keyed', '0') .replace('switch (cascade + level) {', 'switch (2) {') @@ -161,7 +164,10 @@ async function doThing() { srcWithoutUMDWrapper + '\nexport default ' + (ast.declarations ? ast.declarations[0].id.name : ast.id.name) - await writeFile('./src/stylis.min.js', prettier.format(finalSrc)) + await writeFile( + './src/stylis.min.js', + prettier.format(finalSrc, { semi: false, singleQuote: true }) + ) console.log('done') } diff --git a/next-packages/stylis/package.json b/next-packages/stylis/package.json index 5c78f0930..eef3eb417 100644 --- a/next-packages/stylis/package.json +++ b/next-packages/stylis/package.json @@ -22,7 +22,7 @@ "jscodeshift": "^0.5.0", "request": "^2.85.0", "request-promise-native": "^1.0.5", - "stylis": "^3.5.1" + "stylis": "3.5.3" }, "umd:main": "./dist/index.min.js" } diff --git a/next-packages/stylis/src/stylis.min.js b/next-packages/stylis/src/stylis.min.js index bbaaaede0..c91d12e24 100644 --- a/next-packages/stylis/src/stylis.min.js +++ b/next-packages/stylis/src/stylis.min.js @@ -1,606 +1,632 @@ -var V = function ca(W) { - function M(d, c, f, h, a) { +var W = function da(X) { + function M(d, c, e, h, a) { for ( - var k = 0, + var m = 0, b = 0, - u = 0, - l = 0, - q, - m, - e, - D = 0, - y = 0, - r, - E = (r = q = 0), + v = 0, n = 0, - J = (m = 0), + q, + g, + x = 0, + J = 0, + k, + u = (k = q = 0), + l = 0, + r = 0, + z = 0, t = 0, - K = f.length, - F = K - 1, - w, - g = "", - p = "", - G = "", - H = "", - A; - n < K; + K = e.length, + I = K - 1, + y, + f = '', + p = '', + F = '', + G = '', + C; + l < K; ) { - e = f.charCodeAt(n); - n === F && - 0 !== b + l + u + k && - (0 !== b && (e = 47 === b ? 10 : 47), (l = u = k = 0), K++, F++); - if (0 === b + l + u + k) { - if (n === F && (0 < m && (g = g.replace(N, "")), 0 < g.trim().length)) { - switch (e) { + g = e.charCodeAt(l) + l === I && + 0 !== b + n + v + m && + (0 !== b && (g = 47 === b ? 10 : 47), (n = v = m = 0), K++, I++) + if (0 === b + n + v + m) { + if (l === I && (0 < r && (f = f.replace(N, '')), 0 < f.trim().length)) { + switch (g) { case 32: case 9: case 59: case 13: case 10: - break; + break default: - g += f.charAt(n); + f += e.charAt(l) } - e = 59; + g = 59 } - switch (e) { + switch (g) { case 123: - g = g.trim(); - q = g.charCodeAt(0); - r = 1; - for (t = ++n; n < K; ) { - e = f.charCodeAt(n); - switch (e) { + f = f.trim() + q = f.charCodeAt(0) + k = 1 + for (t = ++l; l < K; ) { + switch ((g = e.charCodeAt(l))) { case 123: - r++; - break; + k++ + break case 125: - r--; + k-- + break + case 47: + switch ((g = e.charCodeAt(l + 1))) { + case 42: + case 47: + a: { + for (u = l + 1; u < I; ++u) + switch (e.charCodeAt(u)) { + case 47: + if ( + 42 === g && + 42 === e.charCodeAt(u - 1) && + l + 2 !== u + ) { + l = u + 1 + break a + } + break + case 10: + if (47 === g) { + l = u + 1 + break a + } + } + l = u + } + } + break + case 91: + g++ + case 40: + g++ + case 34: + case 39: + for (; l++ < I && e.charCodeAt(l) !== g; ); } - if (0 === r) break; - n++; + if (0 === k) break + l++ } - e = f.substring(t, n); - 0 === q && (q = (g = g.replace(da, "").trim()).charCodeAt(0)); + k = e.substring(t, l) + 0 === q && (q = (f = f.replace(ea, '').trim()).charCodeAt(0)) switch (q) { case 64: - 0 < m && (g = g.replace(N, "")); - m = g.charCodeAt(1); - switch (m) { + 0 < r && (f = f.replace(N, '')) + g = f.charCodeAt(1) + switch (g) { case 100: case 109: case 115: case 45: - r = c; - break; + r = c + break default: - r = O; + r = O } - e = M(c, r, e, m, a + 1); - t = e.length; - 0 < z && - ((r = X(O, g, J)), - (A = I(3, e, r, c, B, x, t, m, a, h)), - (g = r.join("")), - void 0 !== A && - 0 === (t = (e = A.trim()).length) && - ((m = 0), (e = ""))); + k = M(c, r, k, g, a + 1) + t = k.length + 0 < B && + ((r = Y(O, f, z)), + (C = H(3, k, r, c, D, A, t, g, a, h)), + (f = r.join('')), + void 0 !== C && + 0 === (t = (k = C.trim()).length) && + ((g = 0), (k = ''))) if (0 < t) - switch (m) { + switch (g) { case 115: - g = g.replace(ea, fa); + f = f.replace(fa, ha) case 100: case 109: case 45: - e = g + "{" + e + "}"; - break; + k = f + '{' + k + '}' + break case 107: - g = g.replace(ha, "$1 $2"); - e = g + "{" + e + "}"; - e = - 1 === v || (2 === v && L("@" + e, 3)) - ? "@-webkit-" + e + "@" + e - : "@" + e; - break; + f = f.replace(ia, '$1 $2') + k = f + '{' + k + '}' + k = + 1 === w || (2 === w && L('@' + k, 3)) + ? '@-webkit-' + k + '@' + k + : '@' + k + break default: - (e = g + e), 112 === h && (e = ((p += e), "")); + ;(k = f + k), 112 === h && (k = ((p += k), '')) } - else e = ""; - break; + else k = '' + break default: - e = M(c, X(c, g, J), e, h, a + 1); + k = M(c, Y(c, f, z), k, h, a + 1) } - G += e; - r = J = m = E = q = 0; - g = ""; - e = f.charCodeAt(++n); - break; + F += k + k = z = r = u = q = 0 + f = '' + g = e.charCodeAt(++l) + break case 125: case 59: - g = (0 < m ? g.replace(N, "") : g).trim(); - if (1 < (t = g.length)) - switch ( - (0 === E && - ((q = g.charCodeAt(0)), 45 === q || (96 < q && 123 > q)) && - (t = (g = g.replace(" ", ":")).length), - 0 < z && - void 0 !== (A = I(1, g, c, d, B, x, p.length, h, a, h)) && - 0 === (t = (g = A.trim()).length) && - (g = "\x00\x00"), - (q = g.charCodeAt(0)), - (m = g.charCodeAt(1)), - q) - ) { + f = (0 < r ? f.replace(N, '') : f).trim() + if (1 < (t = f.length)) + switch ((0 === u && + ((q = f.charCodeAt(0)), 45 === q || (96 < q && 123 > q)) && + (t = (f = f.replace(' ', ':')).length), + 0 < B && + void 0 !== (C = H(1, f, c, d, D, A, p.length, h, a, h)) && + 0 === (t = (f = C.trim()).length) && + (f = '\x00\x00'), + (q = f.charCodeAt(0)), + (g = f.charCodeAt(1)), + q)) { case 0: - break; + break case 64: - if (105 === m || 99 === m) { - H += g + f.charAt(n); - break; + if (105 === g || 99 === g) { + G += f + e.charAt(l) + break } default: - 58 !== g.charCodeAt(t - 1) && - (p += P(g, q, m, g.charCodeAt(2))); + 58 !== f.charCodeAt(t - 1) && + (p += P(f, q, g, f.charCodeAt(2))) } - J = m = E = q = 0; - g = ""; - e = f.charCodeAt(++n); + z = r = u = q = 0 + f = '' + g = e.charCodeAt(++l) } } - switch (e) { + switch (g) { case 13: case 10: 47 === b ? (b = 0) : 0 === 1 + q && 107 !== h && - 0 < g.length && - ((m = 1), (g += "\x00")); - 0 < z * Y && I(0, g, c, d, B, x, p.length, h, a, h); - x = 1; - B++; - break; + 0 < f.length && + ((r = 1), (f += '\x00')) + 0 < B * Z && H(0, f, c, d, D, A, p.length, h, a, h) + A = 1 + D++ + break case 59: case 125: - if (0 === b + l + u + k) { - x++; - break; + if (0 === b + n + v + m) { + A++ + break } default: - x++; - w = f.charAt(n); - switch (e) { + A++ + y = e.charAt(l) + switch (g) { case 9: case 32: - if (0 === l + k + b) - switch (D) { + if (0 === n + m + b) + switch (x) { case 44: case 58: case 9: case 32: - w = ""; - break; + y = '' + break default: - 32 !== e && (w = " "); + 32 !== g && (y = ' ') } - break; + break case 0: - w = "\\0"; - break; + y = '\\0' + break case 12: - w = "\\f"; - break; + y = '\\f' + break case 11: - w = "\\v"; - break; + y = '\\v' + break case 38: - 0 === l + b + k && ((m = J = 1), (w = "\f" + w)); - break; + 0 === n + b + m && ((r = z = 1), (y = '\f' + y)) + break case 108: - if (0 === l + b + k + C && 0 < E) - switch (n - E) { + if (0 === n + b + m + E && 0 < u) + switch (l - u) { case 2: - 112 === D && 58 === f.charCodeAt(n - 3) && (C = D); + 112 === x && 58 === e.charCodeAt(l - 3) && (E = x) case 8: - 111 === y && (C = y); + 111 === J && (E = J) } - break; + break case 58: - 0 === l + b + k && (E = n); - break; + 0 === n + b + m && (u = l) + break case 44: - 0 === b + u + l + k && ((m = 1), (w += "\r")); - break; + 0 === b + v + n + m && ((r = 1), (y += '\r')) + break case 34: case 39: - 0 === b && (l = l === e ? 0 : 0 === l ? e : l); - break; + 0 === b && (n = n === g ? 0 : 0 === n ? g : n) + break case 91: - 0 === l + b + u && k++; - break; + 0 === n + b + v && m++ + break case 93: - 0 === l + b + u && k--; - break; + 0 === n + b + v && m-- + break case 41: - 0 === l + b + k && u--; - break; + 0 === n + b + m && v-- + break case 40: - if (0 === l + b + k) { + if (0 === n + b + m) { if (0 === q) - switch (2 * D + 3 * y) { + switch (2 * x + 3 * J) { case 533: - break; + break default: - q = 1; + q = 1 } - u++; + v++ } - break; + break case 64: - 0 === b + u + l + k + E + r && (r = 1); - break; + 0 === b + v + n + m + u + k && (k = 1) + break case 42: case 47: - if (!(0 < l + k + u)) + if (!(0 < n + m + v)) switch (b) { case 0: - switch (2 * e + 3 * f.charCodeAt(n + 1)) { + switch (2 * g + 3 * e.charCodeAt(l + 1)) { case 235: - b = 47; - break; + b = 47 + break case 220: - (t = n), (b = 42); + ;(t = l), (b = 42) } - break; + break case 42: - 47 === e && - 42 === D && - (33 === f.charCodeAt(t + 2) && - (p += f.substring(t, n + 1)), - (w = ""), - (b = 0)); + 47 === g && + 42 === x && + t + 2 !== l && + (33 === e.charCodeAt(t + 2) && + (p += e.substring(t, l + 1)), + (y = ''), + (b = 0)) } } - 0 === b && (g += w); + 0 === b && (f += y) } - y = D; - D = e; - n++; + J = x + x = g + l++ } - t = p.length; + t = p.length if (0 < t) { - r = c; + r = c if ( - 0 < z && - ((A = I(2, p, r, d, B, x, t, h, a, h)), - void 0 !== A && 0 === (p = A).length) + 0 < B && + ((C = H(2, p, r, d, D, A, t, h, a, h)), + void 0 !== C && 0 === (p = C).length) ) - return H + p + G; - p = r.join(",") + "{" + p + "}"; - if (0 !== v * C) { - 2 !== v || L(p, 2) || (C = 0); - switch (C) { + return G + p + F + p = r.join(',') + '{' + p + '}' + if (0 !== w * E) { + 2 !== w || L(p, 2) || (E = 0) + switch (E) { case 111: - p = p.replace(ia, ":-moz-$1") + p; - break; + p = p.replace(ja, ':-moz-$1') + p + break case 112: p = - p.replace(Q, "::-webkit-input-$1") + - p.replace(Q, "::-moz-$1") + - p.replace(Q, ":-ms-input-$1") + - p; + p.replace(Q, '::-webkit-input-$1') + + p.replace(Q, '::-moz-$1') + + p.replace(Q, ':-ms-input-$1') + + p } - C = 0; + E = 0 } } - return H + p + G; + return G + p + F } - function X(d, c, f) { - var h = c.trim().split(ja); - c = h; + function Y(d, c, e) { + var h = c.trim().split(ka) + c = h var a = h.length, - k = d.length; - switch (k) { + m = d.length + switch (m) { case 0: case 1: - var b = 0; - for (d = 0 === k ? "" : d[0] + " "; b < a; ++b) - c[b] = Z(d, c[b], f, k).trim(); - break; + var b = 0 + for (d = 0 === m ? '' : d[0] + ' '; b < a; ++b) + c[b] = aa(d, c[b], e, m).trim() + break default: - var u = (b = 0); + var v = (b = 0) for (c = []; b < a; ++b) - for (var l = 0; l < k; ++l) c[u++] = Z(d[l] + " ", h[b], f, k).trim(); + for (var n = 0; n < m; ++n) c[v++] = aa(d[n] + ' ', h[b], e, m).trim() } - return c; + return c } - function Z(d, c, f) { - var h = c.charCodeAt(0); - 33 > h && (h = (c = c.trim()).charCodeAt(0)); + function aa(d, c, e) { + var h = c.charCodeAt(0) + 33 > h && (h = (c = c.trim()).charCodeAt(0)) switch (h) { case 38: - return c.replace(F, "$1" + d.trim()); + return c.replace(F, '$1' + d.trim()) case 58: - switch (c.charCodeAt(1)) { - case 103: - break; - default: - return d.trim() + c.replace(F, "$1" + d.trim()); - } + return d.trim() + c.replace(F, '$1' + d.trim()) default: - if (0 < 1 * f && 0 < c.indexOf("\f")) - return c.replace(F, (58 === d.charCodeAt(0) ? "" : "$1") + d.trim()); + if (0 < 1 * e && 0 < c.indexOf('\f')) + return c.replace(F, (58 === d.charCodeAt(0) ? '' : '$1') + d.trim()) } - return d + c; + return d + c } - function P(d, c, f, h) { - var a = d + ";", - k = 2 * c + 3 * f + 4 * h; - if (944 === k) { - d = a.indexOf(":", 9) + 1; - var b = a.substring(d, a.length - 1).trim(); - b = a.substring(0, d).trim() + b + ";"; - return 1 === v || (2 === v && L(b, 1)) ? "-webkit-" + b + b : b; + function P(d, c, e, h) { + var a = d + ';', + m = 2 * c + 3 * e + 4 * h + if (944 === m) { + d = a.indexOf(':', 9) + 1 + var b = a.substring(d, a.length - 1).trim() + b = a.substring(0, d).trim() + b + ';' + return 1 === w || (2 === w && L(b, 1)) ? '-webkit-' + b + b : b } - if (0 === v || (2 === v && !L(a, 1))) return a; - switch (k) { + if (0 === w || (2 === w && !L(a, 1))) return a + switch (m) { case 1015: - return 97 === a.charCodeAt(10) ? "-webkit-" + a + a : a; + return 97 === a.charCodeAt(10) ? '-webkit-' + a + a : a case 951: - return 116 === a.charCodeAt(3) ? "-webkit-" + a + a : a; + return 116 === a.charCodeAt(3) ? '-webkit-' + a + a : a case 963: - return 110 === a.charCodeAt(5) ? "-webkit-" + a + a : a; + return 110 === a.charCodeAt(5) ? '-webkit-' + a + a : a case 1009: - if (100 !== a.charCodeAt(4)) break; + if (100 !== a.charCodeAt(4)) break case 969: case 942: - return "-webkit-" + a + a; + return '-webkit-' + a + a case 978: - return "-webkit-" + a + "-moz-" + a + a; + return '-webkit-' + a + '-moz-' + a + a case 1019: case 983: - return "-webkit-" + a + "-moz-" + a + "-ms-" + a + a; + return '-webkit-' + a + '-moz-' + a + '-ms-' + a + a case 883: - if (45 === a.charCodeAt(8)) return "-webkit-" + a + a; - if (0 < a.indexOf("image-set(", 11)) - return a.replace(ka, "$1-webkit-$2") + a; - break; + if (45 === a.charCodeAt(8)) return '-webkit-' + a + a + if (0 < a.indexOf('image-set(', 11)) + return a.replace(la, '$1-webkit-$2') + a + break case 932: if (45 === a.charCodeAt(4)) switch (a.charCodeAt(5)) { case 103: return ( - "-webkit-box-" + - a.replace("-grow", "") + - "-webkit-" + + '-webkit-box-' + + a.replace('-grow', '') + + '-webkit-' + a + - "-ms-" + - a.replace("grow", "positive") + + '-ms-' + + a.replace('grow', 'positive') + a - ); + ) case 115: return ( - "-webkit-" + a + "-ms-" + a.replace("shrink", "negative") + a - ); + '-webkit-' + a + '-ms-' + a.replace('shrink', 'negative') + a + ) case 98: return ( - "-webkit-" + + '-webkit-' + a + - "-ms-" + - a.replace("basis", "preferred-size") + + '-ms-' + + a.replace('basis', 'preferred-size') + a - ); + ) } - return "-webkit-" + a + "-ms-" + a + a; + return '-webkit-' + a + '-ms-' + a + a case 964: - return "-webkit-" + a + "-ms-flex-" + a + a; + return '-webkit-' + a + '-ms-flex-' + a + a case 1023: - if (99 !== a.charCodeAt(8)) break; + if (99 !== a.charCodeAt(8)) break b = a - .substring(a.indexOf(":", 15)) - .replace("flex-", "") - .replace("space-between", "justify"); - return ( - "-webkit-box-pack" + b + "-webkit-" + a + "-ms-flex-pack" + b + a - ); + .substring(a.indexOf(':', 15)) + .replace('flex-', '') + .replace('space-between', 'justify') + return '-webkit-box-pack' + b + '-webkit-' + a + '-ms-flex-pack' + b + a case 1005: - return la.test(a) - ? a.replace(aa, ":-webkit-") + a.replace(aa, ":-moz-") + a - : a; + return ma.test(a) + ? a.replace(ba, ':-webkit-') + a.replace(ba, ':-moz-') + a + : a case 1e3: - b = a.substring(13).trim(); - c = b.indexOf("-") + 1; + b = a.substring(13).trim() + c = b.indexOf('-') + 1 switch (b.charCodeAt(0) + b.charCodeAt(c)) { case 226: - b = a.replace(G, "tb"); - break; + b = a.replace(G, 'tb') + break case 232: - b = a.replace(G, "tb-rl"); - break; + b = a.replace(G, 'tb-rl') + break case 220: - b = a.replace(G, "lr"); - break; + b = a.replace(G, 'lr') + break default: - return a; + return a } - return "-webkit-" + a + "-ms-" + b + a; + return '-webkit-' + a + '-ms-' + b + a case 1017: - if (-1 === a.indexOf("sticky", 9)) break; + if (-1 === a.indexOf('sticky', 9)) break case 975: - c = (a = d).length - 10; + c = (a = d).length - 10 b = (33 === a.charCodeAt(c) ? a.substring(0, c) : a) - .substring(d.indexOf(":", 7) + 1) - .trim(); - switch ((k = b.charCodeAt(0) + (b.charCodeAt(7) | 0))) { + .substring(d.indexOf(':', 7) + 1) + .trim() + switch ((m = b.charCodeAt(0) + (b.charCodeAt(7) | 0))) { case 203: - if (111 > b.charCodeAt(8)) break; + if (111 > b.charCodeAt(8)) break case 115: - a = a.replace(b, "-webkit-" + b) + ";" + a; - break; + a = a.replace(b, '-webkit-' + b) + ';' + a + break case 207: case 102: a = - a.replace(b, "-webkit-" + (102 < k ? "inline-" : "") + "box") + - ";" + - a.replace(b, "-webkit-" + b) + - ";" + - a.replace(b, "-ms-" + b + "box") + - ";" + - a; + a.replace(b, '-webkit-' + (102 < m ? 'inline-' : '') + 'box') + + ';' + + a.replace(b, '-webkit-' + b) + + ';' + + a.replace(b, '-ms-' + b + 'box') + + ';' + + a } - return a + ";"; + return a + ';' case 938: if (45 === a.charCodeAt(5)) switch (a.charCodeAt(6)) { case 105: return ( - (b = a.replace("-items", "")), - "-webkit-" + a + "-webkit-box-" + b + "-ms-flex-" + b + a - ); + (b = a.replace('-items', '')), + '-webkit-' + a + '-webkit-box-' + b + '-ms-flex-' + b + a + ) case 115: - return "-webkit-" + a + "-ms-flex-item-" + a.replace(ba, "") + a; + return '-webkit-' + a + '-ms-flex-item-' + a.replace(ca, '') + a default: return ( - "-webkit-" + + '-webkit-' + a + - "-ms-flex-line-pack" + - a.replace("align-content", "").replace(ba, "") + + '-ms-flex-line-pack' + + a.replace('align-content', '').replace(ca, '') + a - ); + ) } - break; + break case 973: case 989: - if (45 !== a.charCodeAt(3) || 122 === a.charCodeAt(4)) break; + if (45 !== a.charCodeAt(3) || 122 === a.charCodeAt(4)) break case 931: case 953: - if (!0 === ma.test(d)) - return 115 === (b = d.substring(d.indexOf(":") + 1)).charCodeAt(0) - ? P(d.replace("stretch", "fill-available"), c, f, h).replace( - ":fill-available", - ":stretch" + if (!0 === na.test(d)) + return 115 === (b = d.substring(d.indexOf(':') + 1)).charCodeAt(0) + ? P(d.replace('stretch', 'fill-available'), c, e, h).replace( + ':fill-available', + ':stretch' ) - : a.replace(b, "-webkit-" + b) + - a.replace(b, "-moz-" + b.replace("fill-", "")) + - a; - break; + : a.replace(b, '-webkit-' + b) + + a.replace(b, '-moz-' + b.replace('fill-', '')) + + a + break case 962: if ( ((a = - "-webkit-" + a + (102 === a.charCodeAt(5) ? "-ms-" + a : "") + a), - 211 === f + h && + '-webkit-' + a + (102 === a.charCodeAt(5) ? '-ms-' + a : '') + a), + 211 === e + h && 105 === a.charCodeAt(13) && - 0 < a.indexOf("transform", 10)) + 0 < a.indexOf('transform', 10)) ) return ( - a.substring(0, a.indexOf(";", 27) + 1).replace(na, "$1-webkit-$2") + + a.substring(0, a.indexOf(';', 27) + 1).replace(oa, '$1-webkit-$2') + a - ); + ) } - return a; + return a } function L(d, c) { - var f = d.indexOf(1 === c ? ":" : "{"), - h = d.substring(0, 3 !== c ? f : 10); - f = d.substring(f + 1, d.length - 1); - return H(2 !== c ? h : h.replace(oa, "$1"), f, c); + var e = d.indexOf(1 === c ? ':' : '{'), + h = d.substring(0, 3 !== c ? e : 10) + e = d.substring(e + 1, d.length - 1) + return R(2 !== c ? h : h.replace(pa, '$1'), e, c) } - function fa(d, c) { - var f = P(c, c.charCodeAt(0), c.charCodeAt(1), c.charCodeAt(2)); - return f !== c + ";" - ? f.replace(pa, " or ($1)").substring(4) - : "(" + c + ")"; + function ha(d, c) { + var e = P(c, c.charCodeAt(0), c.charCodeAt(1), c.charCodeAt(2)) + return e !== c + ';' + ? e.replace(qa, ' or ($1)').substring(4) + : '(' + c + ')' } - function I(d, c, f, h, a, k, b, u, l, q) { - for (var m = 0, e = c, v; m < z; ++m) - switch ((v = R[m].call(y, d, e, f, h, a, k, b, u, l, q))) { + function H(d, c, e, h, a, m, b, v, n, q) { + for (var g = 0, x = c, w; g < B; ++g) + switch ((w = S[g].call(z, d, x, e, h, a, m, b, v, n, q))) { case void 0: case !1: case !0: case null: - break; + break default: - e = v; + x = w } - if (e !== c) return e; + if (x !== c) return x } - function S(d) { + function T(d) { switch (d) { case void 0: case null: - z = R.length = 0; - break; + B = S.length = 0 + break default: switch (d.constructor) { case Array: - for (var c = 0, f = d.length; c < f; ++c) S(d[c]); - break; + for (var c = 0, e = d.length; c < e; ++c) T(d[c]) + break case Function: - R[z++] = d; - break; + S[B++] = d + break case Boolean: - Y = !!d | 0; + Z = !!d | 0 } } - return S; + return T } - function T(d) { - d = d.prefix; + function U(d) { + d = d.prefix void 0 !== d && - ((H = null), - d ? ("function" !== typeof d ? (v = 1) : ((v = 2), (H = d))) : (v = 0)); - return T; + ((R = null), + d ? ('function' !== typeof d ? (w = 1) : ((w = 2), (R = d))) : (w = 0)) + return U } - function y(d, c) { - if (void 0 !== this && this.constructor === y) return ca(d); - var f = d; - 33 > f.charCodeAt(0) && (f = f.trim()); - U = f; - f = [U]; - if (0 < z) { - var h = I(-1, c, f, f, B, x, 0, 0, 0, 0); - void 0 !== h && "string" === typeof h && (c = h); + function z(d, c) { + if (void 0 !== this && this.constructor === z) return da(d) + var e = d + 33 > e.charCodeAt(0) && (e = e.trim()) + V = e + e = [V] + if (0 < B) { + var h = H(-1, c, e, e, D, A, 0, 0, 0, 0) + void 0 !== h && 'string' === typeof h && (c = h) } - var a = M(O, f, c, 0, 0); - 0 < z && - ((h = I(-2, a, f, f, B, x, a.length, 0, 0, 0)), void 0 !== h && (a = h)); - U = ""; - C = 0; - x = B = 1; - return a; + var a = M(O, e, c, 0, 0) + 0 < B && + ((h = H(-2, a, e, e, D, A, a.length, 0, 0, 0)), void 0 !== h && (a = h)) + V = '' + E = 0 + A = D = 1 + return a } - var da = /^\0+/g, + var ea = /^\0+/g, N = /[\0\r\f]/g, - aa = /: */g, - la = /zoo|gra/, - na = /([,: ])(transform)/g, - ja = /,\r+?/g, + ba = /: */g, + ma = /zoo|gra/, + oa = /([,: ])(transform)/g, + ka = /,\r+?/g, F = /([\t\r\n ])*\f?&/g, - ha = /@(k\w+)\s*(\S*)\s*/, + ia = /@(k\w+)\s*(\S*)\s*/, Q = /::(place)/g, - ia = /:(read-only)/g, + ja = /:(read-only)/g, G = /[svh]\w+-[tblr]{2}/, - ea = /\(\s*(.*)\s*\)/g, - pa = /([\s\S]*?);/g, - ba = /-self|flex-/g, - oa = /[^]*?(:[rp][el]a[\w-]+)[^]*/, - ma = /stretch|:\s*\w+\-(?:conte|avail)/, - ka = /([^-])(image-set\()/, - x = 1, - B = 1, - C = 0, - v = 1, + fa = /\(\s*(.*)\s*\)/g, + qa = /([\s\S]*?);/g, + ca = /-self|flex-/g, + pa = /[^]*?(:[rp][el]a[\w-]+)[^]*/, + na = /stretch|:\s*\w+\-(?:conte|avail)/, + la = /([^-])(image-set\()/, + A = 1, + D = 1, + E = 0, + w = 1, O = [], - R = [], - z = 0, - H = null, - Y = 0, - U = ""; - y.use = S; - y.set = T; - void 0 !== W && T(W); - return y; -}; + S = [], + B = 0, + R = null, + Z = 0, + V = '' + z.use = T + z.set = U + void 0 !== X && U(X) + return z +} -export default V; +export default W diff --git a/packages/emotion/test/__snapshots__/insertion.test.js.snap b/packages/emotion/test/__snapshots__/insertion.test.js.snap index 827f87a38..3bdc77052 100644 --- a/packages/emotion/test/__snapshots__/insertion.test.js.snap +++ b/packages/emotion/test/__snapshots__/insertion.test.js.snap @@ -104,7 +104,7 @@ Array [ ".css-37 .List :global(*) :global(+) :global(*){margin-top:10px;}", ".css-37 .List :global(> *){margin-top:10px;}", ".css-37 .List :global(* + *){margin-top:10px;}", - ".css-37 :global(.foo #bar > baz){color:red;}", + ".css-37:global(.foo #bar > baz){color:red;}", ".css-37 div :global(.react-select .some-child-of-react-select){color:red;}", ".css-37 .root > :global(*):not(header){color:red;}", ".css-37 a:matches( a +b foo:hover :global(marquee) a) > :hover{color:red;}", @@ -114,7 +114,7 @@ Array [ exports[`cascade isolation nesting 1`] = ` Array [ ".css-39{color:red;}", - ".css-39 h1 :global(section){color:red;}", + ".css-39 h1:global(section){color:red;}", ".css-39 h1 h2{color:red;}", ".css-39 div h1,.css-39 span h1{color:red;}", ".css-39 span:hover{color:red;}", @@ -253,8 +253,8 @@ Array [ exports[`nested 1`] = ` Array [ - ".css-28 :global(div) h2{color:red;}", - ".css-28 :global(div) h2 h3{color:blue;}", + ".css-28:global(div) h2{color:red;}", + ".css-28:global(div) h2 h3{color:blue;}", ".foo .css-28{width:1px;}", ".foo .css-28:hover{color:black;}", ".foo .css-28 li{color:white;}", diff --git a/yarn.lock b/yarn.lock index f22d6f8ad..435bf59f8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2960,7 +2960,21 @@ browserify-zlib@^0.2.0: dependencies: pako "~1.0.5" -browserslist@^1.3.6, browserslist@^1.5.2, browserslist@^1.7.6, browserslist@^2.11.3, browserslist@^3.0.0, browserslist@^3.2.6, browserslist@^3.2.8: +browserslist@^1.3.6, browserslist@^1.5.2, browserslist@^1.7.6: + version "1.7.7" + resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-1.7.7.tgz#0bd76704258be829b2398bb50e4b62d1a166b0b9" + dependencies: + caniuse-db "^1.0.30000639" + electron-to-chromium "^1.2.7" + +browserslist@^2.11.3: + version "2.11.3" + resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-2.11.3.tgz#fe36167aed1bbcde4827ebfe71347a2cc70b99b2" + dependencies: + caniuse-lite "^1.0.30000792" + electron-to-chromium "^1.3.30" + +browserslist@^3.0.0, browserslist@^3.2.6: version "3.2.8" resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-3.2.8.tgz#b0005361d6471f0f5952797a76fc985f1f978fc6" dependencies: @@ -3204,6 +3218,14 @@ caniuse-db@^1.0.30000529, caniuse-db@^1.0.30000634: version "1.0.30000860" resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30000860.tgz#5ceab253aae172b5f0acd0d5428ba501c4b08d41" +caniuse-db@^1.0.30000639: + version "1.0.30000865" + resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30000865.tgz#82ffb64d40f7567620aac02d3a632079689abc6b" + +caniuse-lite@^1.0.30000792: + version "1.0.30000865" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000865.tgz#70026616e8afe6e1442f8bb4e1092987d81a2f25" + caniuse-lite@^1.0.30000805: version "1.0.30000859" resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000859.tgz#da974adc5348fffe94724877a7ef8cb5d6d3d777" @@ -5016,6 +5038,10 @@ ejs@^2.5.7: version "2.6.1" resolved "https://registry.yarnpkg.com/ejs/-/ejs-2.6.1.tgz#498ec0d495655abc6f23cd61868d926464071aa0" +electron-to-chromium@^1.2.7, electron-to-chromium@^1.3.30: + version "1.3.52" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.52.tgz#d2d9f1270ba4a3b967b831c40ef71fb4d9ab5ce0" + electron-to-chromium@^1.3.47: version "1.3.50" resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.50.tgz#7438b76f92b41b919f3fbdd350fbd0757dacddf7" @@ -11830,7 +11856,7 @@ react-timer-mixin@^0.13.3: version "0.13.3" resolved "https://registry.yarnpkg.com/react-timer-mixin/-/react-timer-mixin-0.13.3.tgz#0da8b9f807ec07dc3e854d082c737c65605b3d22" -react@^16.2.0, react@^16.3.2, react@^16.4.0: +react@^16.2.0, react@^16.3.2: version "16.3.2" resolved "https://registry.yarnpkg.com/react/-/react-16.3.2.tgz#fdc8420398533a1e58872f59091b272ce2f91ea9" dependencies: @@ -11839,6 +11865,15 @@ react@^16.2.0, react@^16.3.2, react@^16.4.0: object-assign "^4.1.1" prop-types "^15.6.0" +react@^16.4.0: + version "16.4.1" + resolved "https://registry.yarnpkg.com/react/-/react-16.4.1.tgz#de51ba5764b5dbcd1f9079037b862bd26b82fe32" + dependencies: + fbjs "^0.8.16" + loose-envify "^1.1.0" + object-assign "^4.1.1" + prop-types "^15.6.0" + read-all-stream@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/read-all-stream/-/read-all-stream-3.1.0.tgz#35c3e177f2078ef789ee4bfafa4373074eaef4fa" @@ -13613,14 +13648,14 @@ stylis-rule-sheet@^0.0.10: version "0.0.10" resolved "https://registry.yarnpkg.com/stylis-rule-sheet/-/stylis-rule-sheet-0.0.10.tgz#44e64a2b076643f4b52e5ff71efc04d8c3c4a430" -stylis@^3.4.0, stylis@^3.5.0: +stylis@3.5.3, stylis@^3.5.0: + version "3.5.3" + resolved "https://registry.yarnpkg.com/stylis/-/stylis-3.5.3.tgz#99fdc46afba6af4deff570825994181a5e6ce546" + +stylis@^3.4.0: version "3.5.0" resolved "https://registry.yarnpkg.com/stylis/-/stylis-3.5.0.tgz#016fa239663d77f868fef5b67cf201c4b7c701e1" -stylis@^3.5.1: - version "3.5.1" - resolved "https://registry.yarnpkg.com/stylis/-/stylis-3.5.1.tgz#fd341d59f57f9aeb412bc14c9d8a8670b438e03b" - sum-up@^1.0.1: version "1.0.3" resolved "https://registry.yarnpkg.com/sum-up/-/sum-up-1.0.3.tgz#1c661f667057f63bcb7875aa1438bc162525156e"