Skip to content

Commit

Permalink
Remove deasync due to abbr/deasync#21
Browse files Browse the repository at this point in the history
  • Loading branch information
iwilson-r7 committed May 12, 2020
1 parent 4c2d892 commit d4cb365
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 266 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "babel-plugin-namespace-styled-components",
"name": "@iainwilson/babel-plugin-namespace-styled-components",
"version": "0.4.0",
"main": "lib/index.js",
"files": [
Expand All @@ -22,7 +22,6 @@
"dependencies": {
"babel-plugin-styled-components": "1.10.0",
"babel-types": "6.26.0",
"deasync": "0.1.14",
"postcss": "7.0.7",
"postcss-nested": "4.1.1",
"postcss-selector-parser": "5.0.0"
Expand Down
14 changes: 1 addition & 13 deletions src/detectInvalidSelector.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { loopWhile } from 'deasync';
import postcssInvalidSelector from './postcssInvalidSelector';
import postcssSafeParser from './placeholderSafeParser';

Expand All @@ -14,22 +13,11 @@ const detectInvalidSelector = path => {
)
.join('');

let postcssInvalidSelectorResult;
postcssInvalidSelector
.process(`& { ${originalStyleString} }`, {
from: undefined,
parser: postcssSafeParser,
})
.then(() => {
postcssInvalidSelectorResult = 0;
})
.catch(err => {
postcssInvalidSelectorResult = err;
});

loopWhile(() => postcssInvalidSelectorResult == null);
if (postcssInvalidSelectorResult instanceof Error)
throw postcssInvalidSelectorResult;
}).sync();
};

export default detectInvalidSelector;
27 changes: 4 additions & 23 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import postcssNested from 'postcss-nested';
import { loopWhile } from 'deasync';
import * as t from 'babel-types';
import {
isCSSHelper,
Expand Down Expand Up @@ -47,37 +46,19 @@ const taggedTemplateVisitor = (path, state) => {
.join('');

// Run the string through postcss-nested to "unwrap" any nested style rules
let postcssNestedResult;
postcssNested
let postcssNestedResult = postcssNested
.process(`& { ${originalStyleString} }`, {
from: undefined,
parser: postcssSafeParser,
})
.then(asyncResult => {
postcssNestedResult = asyncResult;
})
.catch(err => {
postcssNestedResult = err;
});
loopWhile(() => postcssNestedResult == null);
if (postcssNestedResult instanceof Error) throw postcssNestedResult;
}).stringify();

// Run the string through our namespace plugin to prefix each selector with the given namespace
let postcssNamespaceResult;
postcssNamespace
let postcssNamespaceResult = postcssNamespace
.process(
postcssNestedResult.css,
{ from: undefined, parser: postcssSafeParser },
{ namespace }
)
.then(asyncResult => {
postcssNamespaceResult = asyncResult;
})
.catch(err => {
postcssNamespaceResult = err;
});
loopWhile(() => postcssNamespaceResult == null);
if (postcssNamespaceResult instanceof Error) throw postcssNamespaceResult;
).stringify();

// Replace the expression placeholders to form a new, properly namespaced tagged template
const processedString = postcssNamespaceResult.css;
Expand Down
Loading

0 comments on commit d4cb365

Please sign in to comment.