This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const csstree = require('css-tree'); | |
const ast1 = csstree.parse('.a { color: red }', { | |
filename: './a.css', | |
positions: true | |
}); | |
const ast2 = csstree.parse('.b { color: red }', { | |
filename: './b.css', | |
positions: true | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// UPDATE: you can use ready to use package prop-types-definition | |
// https://github.com/avito-tech/prop-types-definition | |
module.exports = function(content) { | |
return content + ` | |
(function(ReactPropTypes) { | |
function unwrapValueItem(value) { | |
if (value) { | |
if (typeof value.getTypeDefinition === 'function') { | |
return value.getTypeDefinition(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cssTree = require("[email protected]"); | |
function getSelectorParent(selector) { | |
const selectorAst = cssTree.parse(selector, { context: 'selector' }); | |
// solution #1 | |
// selectorAst.children.prevUntil(selectorAst.children.tail, (node, item, list) => { | |
// list.remove(item); | |
// return node.type === 'Combinator' || node.type === 'WhiteSpace'; | |
// }); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cssTree = require("[email protected]"); | |
function getSelectorParent(selector) { | |
const selectorAst = cssTree.parse(selector, { context: 'selector' }); | |
// solution #1 | |
// selectorAst.children.prevUntil(selectorAst.children.tail, (node, item, list) => { | |
// list.remove(item); | |
// return node.type === 'Combinator' || node.type === 'WhiteSpace'; | |
// }); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cssTree = require("[email protected]"); | |
function getSelectorParent(selector) { | |
const selectorAst = cssTree.parse(selector, { context: 'selector' }); | |
// solution #1 | |
selectorAst.children.prevUntil(selectorAst.children.tail, (node, item, list) => { | |
list.remove(item); | |
return node.type === 'Combinator' || node.type === 'WhiteSpace'; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const csstree = require("css-tree"); | |
const cssDefinitions = ["color"]; | |
const ast = csstree.parse(` | |
.some-selector { | |
color: black; | |
border: 1px solid #fff; | |
} | |
`, { parseValue: false }); | |
csstree.walk(ast, { |
OlderNewer