Skip to content

Commit

Permalink
support styled-components v6
Browse files Browse the repository at this point in the history
  • Loading branch information
quantizor committed Apr 18, 2021
1 parent 5448282 commit ba3140c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- 'lts/*'
- "lts/*"
branches:
only:
- master
- main
15 changes: 8 additions & 7 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ if (!__PRIVATE__) {
throw new Error('Could neither find styled-components secret internals');
}

const { masterSheet } = __PRIVATE__;
const { mainSheet, masterSheet } = __PRIVATE__;

const sheet = mainSheet || masterSheet;
const isServer = () => typeof document === 'undefined';

const resetStyleSheet = () => {
masterSheet.names = new Map();
masterSheet.clearTag();
sheet.names = new Map();
sheet.clearTag();
};

const getHTML = () => (isServer() ? new ServerStyleSheet().getStyleTags() : masterSheet.toString());
const getHTML = () => (isServer() ? new ServerStyleSheet().getStyleTags() : sheet.toString());

const extract = regex => {
const extract = (regex) => {
let style = '';
let matches;

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

for (const [masterHash, childHashSet] of masterSheet.names) {
hashes.add(masterHash);
for (const [mainHash, childHashSet] of sheet.names) {
hashes.add(mainHash);

for (const childHash of childHashSet) hashes.add(childHash);
}
Expand Down
12 changes: 9 additions & 3 deletions test/utils.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
const {
__PRIVATE__: { masterSheet },
__PRIVATE__: { mainSheet, masterSheet },
} = require('styled-components');

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

const sheet = mainSheet || masterSheet;

it('extracts hashes', () => {
masterSheet.names = new Map([['sc-1', new Set(['a'])], ['sc-2', new Set(['b', 'c'])], ['sc-3', new Set(['d', 'e'])]]);
masterSheet.toString = function() {
sheet.names = new Map([
['sc-1', new Set(['a'])],
['sc-2', new Set(['b', 'c'])],
['sc-3', new Set(['d', 'e'])],
]);
sheet.toString = function() {
return `
<style data-styled="active">
.sc-1 {}
Expand Down

0 comments on commit ba3140c

Please sign in to comment.