Skip to content

Commit 9446fa2

Browse files
fix: improve the key sanitization, closes #19 (#20)
* fix: improve the key sanitization, needed for v TW 1.6 animation keyframes. * chore: update deps * chore: reduce test noise
1 parent 540ef21 commit 9446fa2

19 files changed

+6882
-17454
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"chalk": "^2.4.2",
4444
"fs-extra": "^8.1.0",
4545
"lodash.reduce": "^4.6.0",
46-
"tailwindcss": "^1.1.2",
46+
"tailwindcss": "^1.6.0",
4747
"yargs": "^14.0.0"
4848
},
4949
"devDependencies": {

src/converters/Converter.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { indentWith } from './utils.js'
2-
import { isObject } from './utils'
2+
import { isObject, sanitizeKey } from './utils'
33

44
const INDENT_BY = 2
55

@@ -220,7 +220,7 @@ class Converter {
220220
* @private
221221
*/
222222
_propertyNameSanitizer (property) {
223-
property = property.replace('/', '\\/')
223+
property = sanitizeKey(property.replace(/\//g, '\\/'))
224224
return [this.prefix, property].filter(v => v).join('-')
225225
}
226226

@@ -231,6 +231,7 @@ class Converter {
231231
* @private
232232
*/
233233
_objectEntryKeySanitizer (key) {
234+
key = sanitizeKey(key)
234235
return this.quotedKeys ? `"${key}"` : key
235236
}
236237
}

src/converters/Stylus.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class StylusConverter extends Converter {
1111
}
1212

1313
_objectEntryKeySanitizer (prop) {
14-
if (/\d/.test(prop) || this.quotedKeys) return `"${prop}"`
14+
prop = super._objectEntryKeySanitizer(prop)
15+
if (/\d/.test(prop) && !prop.startsWith("\"")) return `"${prop}"`
1516
return prop
1617
}
1718
}

src/converters/utils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ export function resolveConfig (config) {
2020
export function isObject (value) {
2121
return !Array.isArray(value) && typeof value === 'object'
2222
}
23+
24+
export function sanitizeKey (text) {
25+
return text.replace(/%/g, '').replace(/, /g, '-')
26+
}

0 commit comments

Comments
 (0)