Skip to content

Commit 1e35d2a

Browse files
committed
Use style-to-js
`style-to-js` is a small wrapper around `style-to-object`. It’s maintained by the same person. It performs the same logic we had in here, meaning that dependency can replaces it.
1 parent 09c32dc commit 1e35d2a

File tree

2 files changed

+3
-45
lines changed

2 files changed

+3
-45
lines changed

lib/index.js

+2-44
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {name as isIdentifierName} from 'estree-util-is-identifier-name'
1515
import {whitespace} from 'hast-util-whitespace'
1616
import {find, hastToReact, html, svg} from 'property-information'
1717
import {stringify as spaces} from 'space-separated-tokens'
18-
import styleToObject from 'style-to-object'
18+
import styleToJs from 'style-to-js'
1919
import {pointStart} from 'unist-util-position'
2020
import {VFileMessage} from 'vfile-message'
2121

@@ -26,7 +26,6 @@ const own = {}.hasOwnProperty
2626
const emptyMap = new Map()
2727

2828
const cap = /[A-Z]/g
29-
const dashSomething = /-([a-z])/g
3029

3130
// `react-dom` triggers a warning for *any* white space in tables.
3231
// To follow GFM, `mdast-util-to-hast` injects line endings between elements.
@@ -635,11 +634,8 @@ function createProperty(state, prop, value) {
635634
* Throws `VFileMessage` when CSS cannot be parsed.
636635
*/
637636
function parseStyle(state, value) {
638-
/** @type {Style} */
639-
const result = {}
640-
641637
try {
642-
styleToObject(value, replacer)
638+
return styleToJs(value, {reactCompat: true})
643639
} catch (error) {
644640
if (!state.ignoreInvalidStyle) {
645641
const cause = /** @type {Error} */ (error)
@@ -655,30 +651,6 @@ function parseStyle(state, value) {
655651
throw message
656652
}
657653
}
658-
659-
return result
660-
661-
/**
662-
* Add a CSS property (normal, so with dashes) to `result` as a DOM CSS
663-
* property.
664-
*
665-
* @param {string} name
666-
* Key.
667-
* @param {string} value
668-
* Value
669-
* @returns {undefined}
670-
* Nothing.
671-
*/
672-
function replacer(name, value) {
673-
let key = name
674-
675-
if (key.slice(0, 2) !== '--') {
676-
if (key.slice(0, 4) === '-ms-') key = 'ms-' + key.slice(4)
677-
key = key.replace(dashSomething, toCamel)
678-
}
679-
680-
result[key] = value
681-
}
682654
}
683655

684656
/**
@@ -800,20 +772,6 @@ function transformStyleToCssCasing(from) {
800772
return to
801773
}
802774

803-
/**
804-
* Make `$1` capitalized.
805-
*
806-
* @param {string} _
807-
* Whatever.
808-
* @param {string} $1
809-
* Single ASCII alphabetical.
810-
* @returns {string}
811-
* Capitalized `$1`.
812-
*/
813-
function toCamel(_, $1) {
814-
return $1.toUpperCase()
815-
}
816-
817775
/**
818776
* Make `$0` dash cased.
819777
*

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"mdast-util-mdxjs-esm": "^2.0.0",
1818
"property-information": "^7.0.0",
1919
"space-separated-tokens": "^2.0.0",
20-
"style-to-object": "^1.0.0",
20+
"style-to-js": "^1.0.0",
2121
"unist-util-position": "^5.0.0",
2222
"vfile-message": "^4.0.0"
2323
},

0 commit comments

Comments
 (0)