版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875
  1. # API Documentation
  2. *Please use only this documented API when working with the parser. Methods
  3. not documented here are subject to change at any point.*
  4. ## `parser` function
  5. This is the module's main entry point.
  6. ```js
  7. const parser = require('postcss-selector-parser');
  8. ```
  9. ### `parser([transform], [options])`
  10. Creates a new `processor` instance
  11. ```js
  12. const processor = parser();
  13. ```
  14. Or, with optional transform function
  15. ```js
  16. const transform = selectors => {
  17. selectors.walkUniversals(selector => {
  18. selector.remove();
  19. });
  20. };
  21. const processor = parser(transform)
  22. // Example
  23. const result = processor.processSync('*.class');
  24. // => .class
  25. ```
  26. [See processor documentation](#processor)
  27. Arguments:
  28. * `transform (function)`: Provide a function to work with the parsed AST.
  29. * `options (object)`: Provide default options for all calls on the returned `Processor`.
  30. ### `parser.attribute([props])`
  31. Creates a new attribute selector.
  32. ```js
  33. parser.attribute({attribute: 'href'});
  34. // => [href]
  35. ```
  36. Arguments:
  37. * `props (object)`: The new node's properties.
  38. ### `parser.className([props])`
  39. Creates a new class selector.
  40. ```js
  41. parser.className({value: 'button'});
  42. // => .button
  43. ```
  44. Arguments:
  45. * `props (object)`: The new node's properties.
  46. ### `parser.combinator([props])`
  47. Creates a new selector combinator.
  48. ```js
  49. parser.combinator({value: '+'});
  50. // => +
  51. ```
  52. Arguments:
  53. * `props (object)`: The new node's properties.
  54. Notes:
  55. * **Descendant Combinators** The value of descendant combinators created by the
  56. parser always just a single space (`" "`). For descendant selectors with no
  57. comments, additional space is now stored in `node.spaces.before`. Depending
  58. on the location of comments, additional spaces may be stored in
  59. `node.raws.spaces.before`, `node.raws.spaces.after`, or `node.raws.value`.
  60. * **Named Combinators** Although, nonstandard and unlikely to ever become a standard,
  61. named combinators like `/deep/` and `/for/` are parsed as combinators. The
  62. `node.value` is name after being unescaped and normalized as lowercase. The
  63. original value for the combinator name is stored in `node.raws.value`.
  64. ### `parser.comment([props])`
  65. Creates a new comment.
  66. ```js
  67. parser.comment({value: '/* Affirmative, Dave. I read you. */'});
  68. // => /* Affirmative, Dave. I read you. */
  69. ```
  70. Arguments:
  71. * `props (object)`: The new node's properties.
  72. ### `parser.id([props])`
  73. Creates a new id selector.
  74. ```js
  75. parser.id({value: 'search'});
  76. // => #search
  77. ```
  78. Arguments:
  79. * `props (object)`: The new node's properties.
  80. ### `parser.nesting([props])`
  81. Creates a new nesting selector.
  82. ```js
  83. parser.nesting();
  84. // => &
  85. ```
  86. Arguments:
  87. * `props (object)`: The new node's properties.
  88. ### `parser.pseudo([props])`
  89. Creates a new pseudo selector.
  90. ```js
  91. parser.pseudo({value: '::before'});
  92. // => ::before
  93. ```
  94. Arguments:
  95. * `props (object)`: The new node's properties.
  96. ### `parser.root([props])`
  97. Creates a new root node.
  98. ```js
  99. parser.root();
  100. // => (empty)
  101. ```
  102. Arguments:
  103. * `props (object)`: The new node's properties.
  104. ### `parser.selector([props])`
  105. Creates a new selector node.
  106. ```js
  107. parser.selector();
  108. // => (empty)
  109. ```
  110. Arguments:
  111. * `props (object)`: The new node's properties.
  112. ### `parser.string([props])`
  113. Creates a new string node.
  114. ```js
  115. parser.string();
  116. // => (empty)
  117. ```
  118. Arguments:
  119. * `props (object)`: The new node's properties.
  120. ### `parser.tag([props])`
  121. Creates a new tag selector.
  122. ```js
  123. parser.tag({value: 'button'});
  124. // => button
  125. ```
  126. Arguments:
  127. * `props (object)`: The new node's properties.
  128. ### `parser.universal([props])`
  129. Creates a new universal selector.
  130. ```js
  131. parser.universal();
  132. // => *
  133. ```
  134. Arguments:
  135. * `props (object)`: The new node's properties.
  136. ## Node types
  137. ### `node.type`
  138. A string representation of the selector type. It can be one of the following;
  139. `attribute`, `class`, `combinator`, `comment`, `id`, `nesting`, `pseudo`,
  140. `root`, `selector`, `string`, `tag`, or `universal`. Note that for convenience,
  141. these constants are exposed on the main `parser` as uppercased keys. So for
  142. example you can get `id` by querying `parser.ID`.
  143. ```js
  144. parser.attribute({attribute: 'href'}).type;
  145. // => 'attribute'
  146. ```
  147. ### `node.parent`
  148. Returns the parent node.
  149. ```js
  150. root.nodes[0].parent === root;
  151. ```
  152. ### `node.toString()`, `String(node)`, or `'' + node`
  153. Returns a string representation of the node.
  154. ```js
  155. const id = parser.id({value: 'search'});
  156. console.log(String(id));
  157. // => #search
  158. ```
  159. ### `node.next()` & `node.prev()`
  160. Returns the next/previous child of the parent node.
  161. ```js
  162. const next = id.next();
  163. if (next && next.type !== 'combinator') {
  164. throw new Error('Qualified IDs are not allowed!');
  165. }
  166. ```
  167. ### `node.replaceWith(node)`
  168. Replace a node with another.
  169. ```js
  170. const attr = selectors.first.first;
  171. const className = parser.className({value: 'test'});
  172. attr.replaceWith(className);
  173. ```
  174. Arguments:
  175. * `node`: The node to substitute the original with.
  176. ### `node.remove()`
  177. Removes the node from its parent node.
  178. ```js
  179. if (node.type === 'id') {
  180. node.remove();
  181. }
  182. ```
  183. ### `node.clone()`
  184. Returns a copy of a node, detached from any parent containers that the
  185. original might have had.
  186. ```js
  187. const cloned = parser.id({value: 'search'});
  188. String(cloned);
  189. // => #search
  190. ```
  191. ### `node.isAtPosition(line, column)`
  192. Return a `boolean` indicating whether this node includes the character at the
  193. position of the given line and column. Returns `undefined` if the nodes lack
  194. sufficient source metadata to determine the position.
  195. Arguments:
  196. * `line`: 1-index based line number relative to the start of the selector.
  197. * `column`: 1-index based column number relative to the start of the selector.
  198. ### `node.spaces`
  199. Extra whitespaces around the node will be moved into `node.spaces.before` and
  200. `node.spaces.after`. So for example, these spaces will be moved as they have
  201. no semantic meaning:
  202. ```css
  203. h1 , h2 {}
  204. ```
  205. For descendent selectors, the value is always a single space.
  206. ```css
  207. h1 h2 {}
  208. ```
  209. Additional whitespace is found in either the `node.spaces.before` and `node.spaces.after` depending on the presence of comments or other whitespace characters. If the actual whitespace does not start or end with a single space, the node's raw value is set to the actual space(s) found in the source.
  210. ### `node.source`
  211. An object describing the node's start/end, line/column source position.
  212. Within the following CSS, the `.bar` class node ...
  213. ```css
  214. .foo,
  215. .bar {}
  216. ```
  217. ... will contain the following `source` object.
  218. ```js
  219. source: {
  220. start: {
  221. line: 2,
  222. column: 3
  223. },
  224. end: {
  225. line: 2,
  226. column: 6
  227. }
  228. }
  229. ```
  230. ### `node.sourceIndex`
  231. The zero-based index of the node within the original source string.
  232. Within the following CSS, the `.baz` class node will have a `sourceIndex` of `12`.
  233. ```css
  234. .foo, .bar, .baz {}
  235. ```
  236. ## Container types
  237. The `root`, `selector`, and `pseudo` nodes have some helper methods for working
  238. with their children.
  239. ### `container.nodes`
  240. An array of the container's children.
  241. ```js
  242. // Input: h1 h2
  243. selectors.at(0).nodes.length // => 3
  244. selectors.at(0).nodes[0].value // => 'h1'
  245. selectors.at(0).nodes[1].value // => ' '
  246. ```
  247. ### `container.first` & `container.last`
  248. The first/last child of the container.
  249. ```js
  250. selector.first === selector.nodes[0];
  251. selector.last === selector.nodes[selector.nodes.length - 1];
  252. ```
  253. ### `container.at(index)`
  254. Returns the node at position `index`.
  255. ```js
  256. selector.at(0) === selector.first;
  257. selector.at(0) === selector.nodes[0];
  258. ```
  259. Arguments:
  260. * `index`: The index of the node to return.
  261. ### `container.atPosition(line, column)`
  262. Returns the node at the source position `line` and `column`.
  263. ```js
  264. // Input: :not(.foo),\n#foo > :matches(ol, ul)
  265. selector.atPosition(1, 1); // => :not(.foo)
  266. selector.atPosition(2, 1); // => \n#foo
  267. ```
  268. Arguments:
  269. * `line`: The line number of the node to return.
  270. * `column`: The column number of the node to return.
  271. ### `container.index(node)`
  272. Return the index of the node within its container.
  273. ```js
  274. selector.index(selector.nodes[2]) // => 2
  275. ```
  276. Arguments:
  277. * `node`: A node within the current container.
  278. ### `container.length`
  279. Proxy to the length of the container's nodes.
  280. ```js
  281. container.length === container.nodes.length
  282. ```
  283. ### `container` Array iterators
  284. The container class provides proxies to certain Array methods; these are:
  285. * `container.map === container.nodes.map`
  286. * `container.reduce === container.nodes.reduce`
  287. * `container.every === container.nodes.every`
  288. * `container.some === container.nodes.some`
  289. * `container.filter === container.nodes.filter`
  290. * `container.sort === container.nodes.sort`
  291. Note that these methods only work on a container's immediate children; recursive
  292. iteration is provided by `container.walk`.
  293. ### `container.each(callback)`
  294. Iterate the container's immediate children, calling `callback` for each child.
  295. You may return `false` within the callback to break the iteration.
  296. ```js
  297. let className;
  298. selectors.each((selector, index) => {
  299. if (selector.type === 'class') {
  300. className = selector.value;
  301. return false;
  302. }
  303. });
  304. ```
  305. Note that unlike `Array#forEach()`, this iterator is safe to use whilst adding
  306. or removing nodes from the container.
  307. Arguments:
  308. * `callback (function)`: A function to call for each node, which receives `node`
  309. and `index` arguments.
  310. ### `container.walk(callback)`
  311. Like `container#each`, but will also iterate child nodes as long as they are
  312. `container` types.
  313. ```js
  314. selectors.walk((selector, index) => {
  315. // all nodes
  316. });
  317. ```
  318. Arguments:
  319. * `callback (function)`: A function to call for each node, which receives `node`
  320. and `index` arguments.
  321. This iterator is safe to use whilst mutating `container.nodes`,
  322. like `container#each`.
  323. ### `container.walk` proxies
  324. The container class provides proxy methods for iterating over types of nodes,
  325. so that it is easier to write modules that target specific selectors. Those
  326. methods are:
  327. * `container.walkAttributes`
  328. * `container.walkClasses`
  329. * `container.walkCombinators`
  330. * `container.walkComments`
  331. * `container.walkIds`
  332. * `container.walkNesting`
  333. * `container.walkPseudos`
  334. * `container.walkTags`
  335. * `container.walkUniversals`
  336. ### `container.split(callback)`
  337. This method allows you to split a group of nodes by returning `true` from
  338. a callback. It returns an array of arrays, where each inner array corresponds
  339. to the groups that you created via the callback.
  340. ```js
  341. // (input) => h1 h2>>h3
  342. const list = selectors.first.split(selector => {
  343. return selector.type === 'combinator';
  344. });
  345. // (node values) => [['h1', ' '], ['h2', '>>'], ['h3']]
  346. ```
  347. Arguments:
  348. * `callback (function)`: A function to call for each node, which receives `node`
  349. as an argument.
  350. ### `container.prepend(node)` & `container.append(node)`
  351. Add a node to the start/end of the container. Note that doing so will set
  352. the parent property of the node to this container.
  353. ```js
  354. const id = parser.id({value: 'search'});
  355. selector.append(id);
  356. ```
  357. Arguments:
  358. * `node`: The node to add.
  359. ### `container.insertBefore(old, new)` & `container.insertAfter(old, new)`
  360. Add a node before or after an existing node in a container:
  361. ```js
  362. selectors.walk(selector => {
  363. if (selector.type !== 'class') {
  364. const className = parser.className({value: 'theme-name'});
  365. selector.parent.insertAfter(selector, className);
  366. }
  367. });
  368. ```
  369. Arguments:
  370. * `old`: The existing node in the container.
  371. * `new`: The new node to add before/after the existing node.
  372. ### `container.removeChild(node)`
  373. Remove the node from the container. Note that you can also use
  374. `node.remove()` if you would like to remove just a single node.
  375. ```js
  376. selector.length // => 2
  377. selector.remove(id)
  378. selector.length // => 1;
  379. id.parent // undefined
  380. ```
  381. Arguments:
  382. * `node`: The node to remove.
  383. ### `container.removeAll()` or `container.empty()`
  384. Remove all children from the container.
  385. ```js
  386. selector.removeAll();
  387. selector.length // => 0
  388. ```
  389. ## Root nodes
  390. A root node represents a comma separated list of selectors. Indeed, all
  391. a root's `toString()` method does is join its selector children with a ','.
  392. Other than this, it has no special functionality and acts like a container.
  393. ### `root.trailingComma`
  394. This will be set to `true` if the input has a trailing comma, in order to
  395. support parsing of legacy CSS hacks.
  396. ## Selector nodes
  397. A selector node represents a single complex selector. For example, this
  398. selector string `h1 h2 h3, [href] > p`, is represented as two selector nodes.
  399. It has no special functionality of its own.
  400. ## Pseudo nodes
  401. A pseudo selector extends a container node; if it has any parameters of its
  402. own (such as `h1:not(h2, h3)`), they will be its children. Note that the pseudo
  403. `value` will always contain the colons preceding the pseudo identifier. This
  404. is so that both `:before` and `::before` are properly represented in the AST.
  405. ## Attribute nodes
  406. ### `attribute.quoted`
  407. Returns `true` if the attribute's value is wrapped in quotation marks, false if it is not.
  408. Remains `undefined` if there is no attribute value.
  409. ```css
  410. [href=foo] /* false */
  411. [href='foo'] /* true */
  412. [href="foo"] /* true */
  413. [href] /* undefined */
  414. ```
  415. ### `attribute.qualifiedAttribute`
  416. Returns the attribute name qualified with the namespace if one is given.
  417. ### `attribute.offsetOf(part)`
  418. Returns the offset of the attribute part specified relative to the
  419. start of the node of the output string. This is useful in raising
  420. error messages about a specific part of the attribute, especially
  421. in combination with `attribute.sourceIndex`.
  422. Returns `-1` if the name is invalid or the value doesn't exist in this
  423. attribute.
  424. The legal values for `part` are:
  425. * `"ns"` - alias for "namespace"
  426. * `"namespace"` - the namespace if it exists.
  427. * `"attribute"` - the attribute name
  428. * `"attributeNS"` - the start of the attribute or its namespace
  429. * `"operator"` - the match operator of the attribute
  430. * `"value"` - The value (string or identifier)
  431. * `"insensitive"` - the case insensitivity flag
  432. ### `attribute.raws.unquoted`
  433. Returns the unquoted content of the attribute's value.
  434. Remains `undefined` if there is no attribute value.
  435. ```css
  436. [href=foo] /* foo */
  437. [href='foo'] /* foo */
  438. [href="foo"] /* foo */
  439. [href] /* undefined */
  440. ```
  441. ### `attribute.spaces`
  442. Like `node.spaces` with the `before` and `after` values containing the spaces
  443. around the element, the parts of the attribute can also have spaces before
  444. and after them. The for each of `attribute`, `operator`, `value` and
  445. `insensitive` there is corresponding property of the same nam in
  446. `node.spaces` that has an optional `before` or `after` string containing only
  447. whitespace.
  448. Note that corresponding values in `attributes.raws.spaces` contain values
  449. including any comments. If set, these values will override the
  450. `attribute.spaces` value. Take care to remove them if changing
  451. `attribute.spaces`.
  452. ### `attribute.raws`
  453. The raws object stores comments and other information necessary to re-render
  454. the node exactly as it was in the source.
  455. If a comment is embedded within the identifiers for the `namespace`, `attribute`
  456. or `value` then a property is placed in the raws for that value containing the full source of the propery including comments.
  457. If a comment is embedded within the space between parts of the attribute
  458. then the raw for that space is set accordingly.
  459. Setting an attribute's property `raws` value to be deleted.
  460. For now, changing the spaces required also updating or removing any of the
  461. raws values that override them.
  462. Example: `[ /*before*/ href /* after-attr */ = /* after-operator */ te/*inside-value*/st/* wow */ /*omg*/i/*bbq*/ /*whodoesthis*/]` would parse as:
  463. ```js
  464. {
  465. attribute: "href",
  466. operator: "=",
  467. value: "test",
  468. spaces: {
  469. before: '',
  470. after: '',
  471. attribute: { before: ' ', after: ' ' },
  472. operator: { after: ' ' },
  473. value: { after: ' ' },
  474. insensitive: { after: ' ' }
  475. },
  476. raws: {
  477. spaces: {
  478. attribute: { before: ' /*before*/ ', after: ' /* after-attr */ ' },
  479. operator: { after: ' /* after-operator */ ' },
  480. value: { after: '/* wow */ /*omg*/' },
  481. insensitive: { after: '/*bbq*/ /*whodoesthis*/' }
  482. },
  483. unquoted: 'test',
  484. value: 'te/*inside-value*/st'
  485. }
  486. }
  487. ```
  488. ## `Processor`
  489. ### `ProcessorOptions`
  490. * `lossless` - When `true`, whitespace is preserved. Defaults to `true`.
  491. * `updateSelector` - When `true`, if any processor methods are passed a postcss
  492. `Rule` node instead of a string, then that Rule's selector is updated
  493. with the results of the processing. Defaults to `true`.
  494. ### `process|processSync(selectors, [options])`
  495. Processes the `selectors`, returning a string from the result of processing.
  496. Note: when the `updateSelector` option is set, the rule's selector
  497. will be updated with the resulting string.
  498. **Example:**
  499. ```js
  500. const parser = require("postcss-selector-parser");
  501. const processor = parser();
  502. let result = processor.processSync(' .class');
  503. console.log(result);
  504. // => .class
  505. // Asynchronous operation
  506. let promise = processor.process(' .class').then(result => {
  507. console.log(result)
  508. // => .class
  509. });
  510. // To have the parser normalize whitespace values, utilize the options
  511. result = processor.processSync(' .class ', {lossless: false});
  512. console.log(result);
  513. // => .class
  514. // For better syntax errors, pass a PostCSS Rule node.
  515. const postcss = require('postcss');
  516. rule = postcss.rule({selector: ' #foo > a, .class '});
  517. processor.process(rule, {lossless: false, updateSelector: true}).then(result => {
  518. console.log(result);
  519. // => #foo>a,.class
  520. console.log("rule:", rule.selector);
  521. // => rule: #foo>a,.class
  522. })
  523. ```
  524. Arguments:
  525. * `selectors (string|postcss.Rule)`: Either a selector string or a PostCSS Rule
  526. node.
  527. * `[options] (object)`: Process options
  528. ### `ast|astSync(selectors, [options])`
  529. Like `process()` and `processSync()` but after
  530. processing the `selectors` these methods return the `Root` node of the result
  531. instead of a string.
  532. Note: when the `updateSelector` option is set, the rule's selector
  533. will be updated with the resulting string.
  534. ### `transform|transformSync(selectors, [options])`
  535. Like `process()` and `processSync()` but after
  536. processing the `selectors` these methods return the value returned by the
  537. processor callback.
  538. Note: when the `updateSelector` option is set, the rule's selector
  539. will be updated with the resulting string.
  540. ### Error Handling Within Selector Processors
  541. The root node passed to the selector processor callback
  542. has a method `error(message, options)` that returns an
  543. error object. This method should always be used to raise
  544. errors relating to the syntax of selectors. The options
  545. to this method are passed to postcss's error constructor
  546. ([documentation](http://api.postcss.org/Container.html#error)).
  547. #### Async Error Example
  548. ```js
  549. let processor = (root) => {
  550. return new Promise((resolve, reject) => {
  551. root.walkClasses((classNode) => {
  552. if (/^(.*)[-_]/.test(classNode.value)) {
  553. let msg = "classes may not have underscores or dashes in them";
  554. reject(root.error(msg, {
  555. index: classNode.sourceIndex + RegExp.$1.length + 1,
  556. word: classNode.value
  557. }));
  558. }
  559. });
  560. resolve();
  561. });
  562. };
  563. const postcss = require("postcss");
  564. const parser = require("postcss-selector-parser");
  565. const selectorProcessor = parser(processor);
  566. const plugin = postcss.plugin('classValidator', (options) => {
  567. return (root) => {
  568. let promises = [];
  569. root.walkRules(rule => {
  570. promises.push(selectorProcessor.process(rule));
  571. });
  572. return Promise.all(promises);
  573. };
  574. });
  575. postcss(plugin()).process(`
  576. .foo-bar {
  577. color: red;
  578. }
  579. `.trim(), {from: 'test.css'}).catch((e) => console.error(e.toString()));
  580. // CssSyntaxError: classValidator: ./test.css:1:5: classes may not have underscores or dashes in them
  581. //
  582. // > 1 | .foo-bar {
  583. // | ^
  584. // 2 | color: red;
  585. // 3 | }
  586. ```
  587. #### Synchronous Error Example
  588. ```js
  589. let processor = (root) => {
  590. root.walkClasses((classNode) => {
  591. if (/.*[-_]/.test(classNode.value)) {
  592. let msg = "classes may not have underscores or dashes in them";
  593. throw root.error(msg, {
  594. index: classNode.sourceIndex,
  595. word: classNode.value
  596. });
  597. }
  598. });
  599. };
  600. const postcss = require("postcss");
  601. const parser = require("postcss-selector-parser");
  602. const selectorProcessor = parser(processor);
  603. const plugin = postcss.plugin('classValidator', (options) => {
  604. return (root) => {
  605. root.walkRules(rule => {
  606. selectorProcessor.processSync(rule);
  607. });
  608. };
  609. });
  610. postcss(plugin()).process(`
  611. .foo-bar {
  612. color: red;
  613. }
  614. `.trim(), {from: 'test.css'}).catch((e) => console.error(e.toString()));
  615. // CssSyntaxError: classValidator: ./test.css:1:5: classes may not have underscores or dashes in them
  616. //
  617. // > 1 | .foo-bar {
  618. // | ^
  619. // 2 | color: red;
  620. // 3 | }
  621. ```