Skip to content

Commit ba3140c

Browse files
committed
support styled-components v6
1 parent 5448282 commit ba3140c

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: node_js
22
node_js:
3-
- 'lts/*'
3+
- "lts/*"
44
branches:
55
only:
6-
- master
6+
- main

src/utils.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@ if (!__PRIVATE__) {
55
throw new Error('Could neither find styled-components secret internals');
66
}
77

8-
const { masterSheet } = __PRIVATE__;
8+
const { mainSheet, masterSheet } = __PRIVATE__;
99

10+
const sheet = mainSheet || masterSheet;
1011
const isServer = () => typeof document === 'undefined';
1112

1213
const resetStyleSheet = () => {
13-
masterSheet.names = new Map();
14-
masterSheet.clearTag();
14+
sheet.names = new Map();
15+
sheet.clearTag();
1516
};
1617

17-
const getHTML = () => (isServer() ? new ServerStyleSheet().getStyleTags() : masterSheet.toString());
18+
const getHTML = () => (isServer() ? new ServerStyleSheet().getStyleTags() : sheet.toString());
1819

19-
const extract = regex => {
20+
const extract = (regex) => {
2021
let style = '';
2122
let matches;
2223

@@ -33,8 +34,8 @@ const getCSS = () => css.parse(getStyle());
3334
const getHashes = () => {
3435
const hashes = new Set();
3536

36-
for (const [masterHash, childHashSet] of masterSheet.names) {
37-
hashes.add(masterHash);
37+
for (const [mainHash, childHashSet] of sheet.names) {
38+
hashes.add(mainHash);
3839

3940
for (const childHash of childHashSet) hashes.add(childHash);
4041
}

test/utils.spec.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
const {
2-
__PRIVATE__: { masterSheet },
2+
__PRIVATE__: { mainSheet, masterSheet },
33
} = require('styled-components');
44

55
const { getHashes } = require('../src/utils');
66

7+
const sheet = mainSheet || masterSheet;
8+
79
it('extracts hashes', () => {
8-
masterSheet.names = new Map([['sc-1', new Set(['a'])], ['sc-2', new Set(['b', 'c'])], ['sc-3', new Set(['d', 'e'])]]);
9-
masterSheet.toString = function() {
10+
sheet.names = new Map([
11+
['sc-1', new Set(['a'])],
12+
['sc-2', new Set(['b', 'c'])],
13+
['sc-3', new Set(['d', 'e'])],
14+
]);
15+
sheet.toString = function() {
1016
return `
1117
<style data-styled="active">
1218
.sc-1 {}

0 commit comments

Comments
 (0)