Skip to content

Commit accbe5a

Browse files
committed
refactor: remove cssToJss, use convertCssToJssString in demo
1 parent 58c514f commit accbe5a

File tree

3 files changed

+23
-39
lines changed

3 files changed

+23
-39
lines changed

demo/Root.tsx

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { makeStyles, Theme } from '@material-ui/core/styles'
77
import debounce from 'lodash/debounce'
88
import noop from 'lodash/noop'
99
import j from 'jscodeshift'
10-
import cssToJss from '../src/cssToJss'
10+
import { convertCssToJssString } from '../src/convertCssToJss'
1111
import classNames from 'classnames'
1212

1313
const useStyles = makeStyles((theme: Theme) => ({
@@ -111,21 +111,7 @@ export default function Root(): React.ReactNode {
111111
debounce((input: string): void => {
112112
let converted: string | Error
113113
try {
114-
converted =
115-
cssToJss(
116-
{
117-
path: '',
118-
source: input,
119-
},
120-
{
121-
j,
122-
jscodeshift: j,
123-
report: noop,
124-
stats: noop,
125-
},
126-
{}
127-
) || ''
128-
converted = converted.replace(/^ {2,}/gm, match =>
114+
converted = convertCssToJssString(input).replace(/^ {2,}/gm, match =>
129115
match.substring(match.length / 2)
130116
)
131117
} catch (error) {

src/css-to-jss.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,21 @@
1-
import cssToJss from './cssToJss'
2-
module.exports = cssToJss
1+
import { FileInfo, API, Options } from 'jscodeshift'
2+
import { convertCssToJssString } from './convertCssToJss'
3+
4+
module.exports = function cssToJss(
5+
fileInfo: FileInfo,
6+
api: API,
7+
options: Options
8+
): string | null | undefined | void {
9+
const selectionStart = options.selectionStart
10+
? parseInt(options.selectionStart)
11+
: 0
12+
const selectionEnd = options.selectionEnd
13+
? parseInt(options.selectionEnd)
14+
: fileInfo.source.length
15+
16+
const before = fileInfo.source.substring(0, selectionStart)
17+
const rawCss = fileInfo.source.substring(selectionStart, selectionEnd)
18+
const after = fileInfo.source.substring(selectionEnd)
19+
20+
return `${before}${convertCssToJssString(rawCss)}${after}`
21+
}

src/cssToJss.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)