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.

513 lines
19 KiB

2 years ago
  1. # 6.0.10
  2. - Fixed: `isPseudoElement()` supports `:first-letter` and `:first-line`
  3. # 6.0.9
  4. - Fixed: `Combinator.raws` property type
  5. # 6.0.8
  6. - Fixed: reduced size
  7. # 6.0.7
  8. - Fixed: parse animation percents
  9. # 6.0.6
  10. - Fixed: parse quoted attributes containing a newline correctly
  11. # 6.0.5
  12. - Perf: rework unesc for a 63+% performance boost
  13. # 6.0.4
  14. - Fixed: ts errors
  15. # 6.0.3
  16. - Fixed: replace node built-in "util" module with "util-deprecate"
  17. - Fixed: handle uppercase pseudo elements
  18. - Fixed: do not create invalid combinator before comment
  19. # 6.0.2
  20. - Fixed an issue with parsing and stringifying an empty attribute value
  21. # 6.0.1
  22. - Fixed an issue with unicode surrogate pair parsing
  23. # 6.0.0
  24. - Updated: `cssesc` to 3.0.0 (major)
  25. - Fixed: Issues with escaped `id` and `class` selectors
  26. # 5.0.0
  27. - Allow escaped dot within class name.
  28. - Update PostCSS to 7.0.7 (patch)
  29. # 5.0.0-rc.4
  30. - Fixed an issue where comments immediately after an insensitive (in attribute)
  31. were not parsed correctly.
  32. - Updated `cssesc` to 2.0.0 (major).
  33. - Removed outdated integration tests.
  34. - Added tests for custom selectors, tags with attributes, the universal
  35. selector with pseudos, and tokens after combinators.
  36. # 5.0.0-rc.1
  37. To ease adoption of the v5.0 release, we have relaxed the node version
  38. check performed by npm at installation time to allow for node 4, which
  39. remains officially unsupported, but likely to continue working for the
  40. time being.
  41. # 5.0.0-rc.0
  42. This release has **BREAKING CHANGES** that were required to fix regressions
  43. in 4.0.0 and to make the Combinator Node API consistent for all combinator
  44. types. Please read carefully.
  45. ## Summary of Changes
  46. * The way a descendent combinator that isn't a single space character (E.g. `.a .b`) is stored in the AST has changed.
  47. * Named Combinators (E.g. `.a /for/ .b`) are now properly parsed as a combinator.
  48. * It is now possible to look up a node based on the source location of a character in that node and to query nodes if they contain some character.
  49. * Several bug fixes that caused the parser to hang and run out of memory when a `/` was encountered have been fixed.
  50. * The minimum supported version of Node is now `v6.0.0`.
  51. ### Changes to the Descendent Combinator
  52. In prior releases, the value of a descendant combinator with multiple spaces included all the spaces.
  53. * `.a .b`: Extra spaces are now stored as space before.
  54. - Old & Busted:
  55. - `combinator.value === " "`
  56. - New hotness:
  57. - `combinator.value === " " && combinator.spaces.before === " "`
  58. * `.a /*comment*/.b`: A comment at the end of the combinator causes extra space to become after space.
  59. - Old & Busted:
  60. - `combinator.value === " "`
  61. - `combinator.raws.value === " /*comment/"`
  62. - New hotness:
  63. - `combinator.value === " "`
  64. - `combinator.spaces.after === " "`
  65. - `combinator.raws.spaces.after === " /*comment*/"`
  66. * `.a<newline>.b`: whitespace that doesn't start or end with a single space character is stored as a raw value.
  67. - Old & Busted:
  68. - `combinator.value === "\n"`
  69. - `combinator.raws.value === undefined`
  70. - New hotness:
  71. - `combinator.value === " "`
  72. - `combinator.raws.value === "\n"`
  73. ### Support for "Named Combinators"
  74. Although, nonstandard and unlikely to ever become a standard, combinators like `/deep/` and `/for/` are now properly supported.
  75. Because they've been taken off the standardization track, there is no spec-official name for combinators of the form `/<ident>/`. However, I talked to [Tab Atkins](https://twitter.com/tabatkins) and we agreed to call them "named combinators" so now they are called that.
  76. Before this release such named combinators were parsed without intention and generated three nodes of type `"tag"` where the first and last nodes had a value of `"/"`.
  77. * `.a /for/ .b` is parsed as a combinator.
  78. - Old & Busted:
  79. - `root.nodes[0].nodes[1].type === "tag"`
  80. - `root.nodes[0].nodes[1].value === "/"`
  81. - New hotness:
  82. - `root.nodes[0].nodes[1].type === "combinator"`
  83. - `root.nodes[0].nodes[1].value === "/for/"`
  84. * `.a /F\6fR/ .b` escapes are handled and uppercase is normalized.
  85. - Old & Busted:
  86. - `root.nodes[0].nodes[2].type === "tag"`
  87. - `root.nodes[0].nodes[2].value === "F\\6fR"`
  88. - New hotness:
  89. - `root.nodes[0].nodes[1].type === "combinator"`
  90. - `root.nodes[0].nodes[1].value === "/for/"`
  91. - `root.nodes[0].nodes[1].raws.value === "/F\\6fR/"`
  92. ### Source position checks and lookups
  93. A new API was added to look up a node based on the source location.
  94. ```js
  95. const selectorParser = require("postcss-selector-parser");
  96. // You can find the most specific node for any given character
  97. let combinator = selectorParser.astSync(".a > .b").atPosition(1,4);
  98. combinator.toString() === " > ";
  99. // You can check if a node includes a specific character
  100. // Whitespace surrounding the node that is owned by that node
  101. // is included in the check.
  102. [2,3,4,5,6].map(column => combinator.isAtPosition(1, column));
  103. // => [false, true, true, true, false]
  104. ```
  105. # 4.0.0
  106. This release has **BREAKING CHANGES** that were required to fix bugs regarding values with escape sequences. Please read carefully.
  107. * **Identifiers with escapes** - CSS escape sequences are now hidden from the public API by default.
  108. The normal value of a node like a class name or ID, or an aspect of a node such as attribute
  109. selector's value, is unescaped. Escapes representing Non-ascii characters are unescaped into
  110. unicode characters. For example: `bu\tton, .\31 00, #i\2764\FE0Fu, [attr="value is \"quoted\""]`
  111. will parse respectively to the values `button`, `100`, `i❤️u`, `value is "quoted"`.
  112. The original escape sequences for these values can be found in the corresponding property name
  113. in `node.raws`. Where possible, deprecation warnings were added, but the nature
  114. of escape handling makes it impossible to detect what is escaped or not. Our expectation is
  115. that most users are neither expecting nor handling escape sequences in their use of this library,
  116. and so for them, this is a bug fix. Users who are taking care to handle escapes correctly can
  117. now update their code to remove the escape handling and let us do it for them.
  118. * **Mutating values with escapes** - When you make an update to a node property that has escape handling
  119. The value is assumed to be unescaped, and any special characters are escaped automatically and
  120. the corresponding `raws` value is immediately updated. This can result in changes to the original
  121. escape format. Where the exact value of the escape sequence is important there are methods that
  122. allow both values to be set in conjunction. There are a number of new convenience methods for
  123. manipulating values that involve escapes, especially for attributes values where the quote mark
  124. is involved. See https://github.com/postcss/postcss-selector-parser/pull/133 for an extensive
  125. write-up on these changes.
  126. **Upgrade/API Example**
  127. In `3.x` there was no unescape handling and internal consistency of several properties was the caller's job to maintain. It was very easy for the developer
  128. to create a CSS file that did not parse correctly when some types of values
  129. were in use.
  130. ```js
  131. const selectorParser = require("postcss-selector-parser");
  132. let attr = selectorParser.attribute({attribute: "id", operator: "=", value: "a-value"});
  133. attr.value; // => "a-value"
  134. attr.toString(); // => [id=a-value]
  135. // Add quotes to an attribute's value.
  136. // All these values have to be set by the caller to be consistent:
  137. // no internal consistency is maintained.
  138. attr.raws.unquoted = attr.value
  139. attr.value = "'" + attr.value + "'";
  140. attr.value; // => "'a-value'"
  141. attr.quoted = true;
  142. attr.toString(); // => "[id='a-value']"
  143. ```
  144. In `4.0` there is a convenient API for setting and mutating values
  145. that may need escaping. Especially for attributes.
  146. ```js
  147. const selectorParser = require("postcss-selector-parser");
  148. // The constructor requires you specify the exact escape sequence
  149. let className = selectorParser.className({value: "illegal class name", raws: {value: "illegal\\ class\\ name"}});
  150. className.toString(); // => '.illegal\\ class\\ name'
  151. // So it's better to set the value as a property
  152. className = selectorParser.className();
  153. // Most properties that deal with identifiers work like this
  154. className.value = "escape for me";
  155. className.value; // => 'escape for me'
  156. className.toString(); // => '.escape\\ for\\ me'
  157. // emoji and all non-ascii are escaped to ensure it works in every css file.
  158. className.value = "😱🦄😍";
  159. className.value; // => '😱🦄😍'
  160. className.toString(); // => '.\\1F631\\1F984\\1F60D'
  161. // you can control the escape sequence if you want, or do bad bad things
  162. className.setPropertyAndEscape('value', 'xxxx', 'yyyy');
  163. className.value; // => "xxxx"
  164. className.toString(); // => ".yyyy"
  165. // Pass a value directly through to the css output without escaping it.
  166. className.setPropertyWithoutEscape('value', '$REPLACE_ME$');
  167. className.value; // => "$REPLACE_ME$"
  168. className.toString(); // => ".$REPLACE_ME$"
  169. // The biggest changes are to the Attribute class
  170. // passing quoteMark explicitly is required to avoid a deprecation warning.
  171. let attr = selectorParser.attribute({attribute: "id", operator: "=", value: "a-value", quoteMark: null});
  172. attr.toString(); // => "[id=a-value]"
  173. // Get the value with quotes on it and any necessary escapes.
  174. // This is the same as reading attr.value in 3.x.
  175. attr.getQuotedValue(); // => "a-value";
  176. attr.quoteMark; // => null
  177. // Add quotes to an attribute's value.
  178. attr.quoteMark = "'"; // This is all that's required.
  179. attr.toString(); // => "[id='a-value']"
  180. attr.quoted; // => true
  181. // The value is still the same, only the quotes have changed.
  182. attr.value; // => a-value
  183. attr.getQuotedValue(); // => "'a-value'";
  184. // deprecated assignment, no warning because there's no escapes
  185. attr.value = "new-value";
  186. // no quote mark is needed so it is removed
  187. attr.getQuotedValue(); // => "new-value";
  188. // deprecated assignment,
  189. attr.value = "\"a 'single quoted' value\"";
  190. // > (node:27859) DeprecationWarning: Assigning an attribute a value containing characters that might need to be escaped is deprecated. Call attribute.setValue() instead.
  191. attr.getQuotedValue(); // => '"a \'single quoted\' value"';
  192. // quote mark inferred from first and last characters.
  193. attr.quoteMark; // => '"'
  194. // setValue takes options to make manipulating the value simple.
  195. attr.setValue('foo', {smart: true});
  196. // foo doesn't require any escapes or quotes.
  197. attr.toString(); // => '[id=foo]'
  198. attr.quoteMark; // => null
  199. // An explicit quote mark can be specified
  200. attr.setValue('foo', {quoteMark: '"'});
  201. attr.toString(); // => '[id="foo"]'
  202. // preserves quote mark by default
  203. attr.setValue('bar');
  204. attr.toString(); // => '[id="bar"]'
  205. attr.quoteMark = null;
  206. attr.toString(); // => '[id=bar]'
  207. // with no arguments, it preserves quote mark even when it's not a great idea
  208. attr.setValue('a value \n that should be quoted');
  209. attr.toString(); // => '[id=a\\ value\\ \\A\\ that\\ should\\ be\\ quoted]'
  210. // smart preservation with a specified default
  211. attr.setValue('a value \n that should be quoted', {smart: true, preferCurrentQuoteMark: true, quoteMark: "'"});
  212. // => "[id='a value \\A that should be quoted']"
  213. attr.quoteMark = '"';
  214. // => '[id="a value \\A that should be quoted"]'
  215. // this keeps double quotes because it wants to quote the value and the existing value has double quotes.
  216. attr.setValue('this should be quoted', {smart: true, preferCurrentQuoteMark: true, quoteMark: "'"});
  217. // => '[id="this should be quoted"]'
  218. // picks single quotes because the value has double quotes
  219. attr.setValue('a "double quoted" value', {smart: true, preferCurrentQuoteMark: true, quoteMark: "'"});
  220. // => "[id='a "double quoted" value']"
  221. // setPropertyAndEscape lets you do anything you want. Even things that are a bad idea and illegal.
  222. attr.setPropertyAndEscape('value', 'xxxx', 'the password is 42');
  223. attr.value; // => "xxxx"
  224. attr.toString(); // => "[id=the password is 42]"
  225. // Pass a value directly through to the css output without escaping it.
  226. attr.setPropertyWithoutEscape('value', '$REPLACEMENT$');
  227. attr.value; // => "$REPLACEMENT$"
  228. attr.toString(); // => "[id=$REPLACEMENT$]"
  229. ```
  230. # 3.1.2
  231. * Fix: Removed dot-prop dependency since it's no longer written in es5.
  232. # 3.1.1
  233. * Fix: typescript definitions weren't in the published package.
  234. # 3.1.0
  235. * Fixed numerous bugs in attribute nodes relating to the handling of comments
  236. and whitespace. There's significant changes to `attrNode.spaces` and `attrNode.raws` since the `3.0.0` release.
  237. * Added `Attribute#offsetOf(part)` to get the offset location of
  238. attribute parts like `"operator"` and `"value"`. This is most
  239. often added to `Attribute#sourceIndex` for error reporting.
  240. # 3.0.0
  241. ## Breaking changes
  242. * Some tweaks to the tokenizer/attribute selector parsing mean that whitespace
  243. locations might be slightly different to the 2.x code.
  244. * Better attribute selector parsing with more validation; postcss-selector-parser
  245. no longer uses regular expressions to parse attribute selectors.
  246. * Added an async API (thanks to @jacobp100); the default `process` API is now
  247. async, and the sync API is now accessed through `processSync` instead.
  248. * `process()` and `processSync()` now return a string instead of the Processor
  249. instance.
  250. * Tweaks handling of Less interpolation (thanks to @jwilsson).
  251. * Removes support for Node 0.12.
  252. ## Other changes
  253. * `ast()` and `astSync()` methods have been added to the `Processor`. These
  254. return the `Root` node of the selectors after processing them.
  255. * `transform()` and `transformSync()` methods have been added to the
  256. `Processor`. These return the value returned by the processor callback
  257. after processing the selectors.
  258. * Set the parent when inserting a node (thanks to @chriseppstein).
  259. * Correctly adjust indices when using insertBefore/insertAfter (thanks to @tivac).
  260. * Fixes handling of namespaces with qualified tag selectors.
  261. * `process`, `ast` and `transform` (and their sync variants) now accept a
  262. `postcss` rule node. When provided, better errors are generated and selector
  263. processing is automatically set back to the rule selector (unless the `updateSelector` option is set to `false`.)
  264. * Now more memory efficient when tokenizing selectors.
  265. ### Upgrade hints
  266. The pattern of:
  267. `rule.selector = processor.process(rule.selector).result.toString();`
  268. is now:
  269. `processor.processSync(rule)`
  270. # 2.2.3
  271. * Resolves an issue where the parser would not reduce multiple spaces between an
  272. ampersand and another simple selector in lossy mode (thanks to @adam-26).
  273. # 2.2.2
  274. * No longer hangs on an unescaped semicolon; instead the parser will throw
  275. an exception for these cases.
  276. # 2.2.1
  277. * Allows a consumer to specify whitespace tokens when creating a new Node
  278. (thanks to @Semigradsky).
  279. # 2.2.0
  280. * Added a new option to normalize whitespace when parsing the selector string
  281. (thanks to @adam-26).
  282. # 2.1.1
  283. * Better unquoted value handling within attribute selectors
  284. (thanks to @evilebottnawi).
  285. # 2.1.0
  286. * Added: Use string constants for all node types & expose them on the main
  287. parser instance (thanks to @Aweary).
  288. # 2.0.0
  289. This release contains the following breaking changes:
  290. * Renamed all `eachInside` iterators to `walk`. For example, `eachTag` is now
  291. `walkTags`, and `eachInside` is now `walk`.
  292. * Renamed `Node#removeSelf()` to `Node#remove()`.
  293. * Renamed `Container#remove()` to `Container#removeChild()`.
  294. * Renamed `Node#raw` to `Node#raws` (thanks to @davidtheclark).
  295. * Now parses `&` as the *nesting* selector, rather than a *tag* selector.
  296. * Fixes misinterpretation of Sass interpolation (e.g. `#{foo}`) as an
  297. id selector (thanks to @davidtheclark).
  298. and;
  299. * Fixes parsing of attribute selectors with equals signs in them
  300. (e.g. `[data-attr="foo=bar"]`) (thanks to @montmanu).
  301. * Adds `quoted` and `raw.unquoted` properties to attribute nodes
  302. (thanks to @davidtheclark).
  303. # 1.3.3
  304. * Fixes an infinite loop on `)` and `]` tokens when they had no opening pairs.
  305. Now postcss-selector-parser will throw when it encounters these lone tokens.
  306. # 1.3.2
  307. * Now uses plain integers rather than `str.charCodeAt(0)` for compiled builds.
  308. # 1.3.1
  309. * Update flatten to v1.x (thanks to @shinnn).
  310. # 1.3.0
  311. * Adds a new node type, `String`, to fix a crash on selectors such as
  312. `foo:bar("test")`.
  313. # 1.2.1
  314. * Fixes a crash when the parser encountered a trailing combinator.
  315. # 1.2.0
  316. * A more descriptive error is thrown when the parser expects to find a
  317. pseudo-class/pseudo-element (thanks to @ashelley).
  318. * Adds support for line/column locations for selector nodes, as well as a
  319. `Node#sourceIndex` method (thanks to @davidtheclark).
  320. # 1.1.4
  321. * Fixes a crash when a selector started with a `>` combinator. The module will
  322. now no longer throw if a selector has a leading/trailing combinator node.
  323. # 1.1.3
  324. * Fixes a crash on `@` tokens.
  325. # 1.1.2
  326. * Fixes an infinite loop caused by using parentheses in a non-pseudo element
  327. context.
  328. # 1.1.1
  329. * Fixes a crash when a backslash ended a selector string.
  330. # 1.1.0
  331. * Adds support for replacing multiple nodes at once with `replaceWith`
  332. (thanks to @jonathantneal).
  333. * Parser no longer throws on sequential IDs and trailing commas, to support
  334. parsing of selector hacks.
  335. # 1.0.1
  336. * Fixes using `insertAfter` and `insertBefore` during iteration.
  337. # 1.0.0
  338. * Adds `clone` and `replaceWith` methods to nodes.
  339. * Adds `insertBefore` and `insertAfter` to containers.
  340. * Stabilises API.
  341. # 0.0.5
  342. * Fixes crash on extra whitespace inside a pseudo selector's parentheses.
  343. * Adds sort function to the container class.
  344. * Enables the parser to pass its input through without transforming.
  345. * Iteration-safe `each` and `eachInside`.
  346. # 0.0.4
  347. * Tidy up redundant duplication.
  348. * Fixes a bug where the parser would loop infinitely on universal selectors
  349. inside pseudo selectors.
  350. * Adds `length` getter and `eachInside`, `map`, `reduce` to the container class.
  351. * When a selector has been removed from the tree, the root node will no longer
  352. cast it to a string.
  353. * Adds node type iterators to the container class (e.g. `eachComment`).
  354. * Adds filter function to the container class.
  355. * Adds split function to the container class.
  356. * Create new node types by doing `parser.id(opts)` etc.
  357. * Adds support for pseudo classes anywhere in the selector.
  358. # 0.0.3
  359. * Adds `next` and `prev` to the node class.
  360. * Adds `first` and `last` getters to the container class.
  361. * Adds `every` and `some` iterators to the container class.
  362. * Add `empty` alias for `removeAll`.
  363. * Combinators are now types of node.
  364. * Fixes the at method so that it is not an alias for `index`.
  365. * Tidy up creation of new nodes in the parser.
  366. * Refactors how namespaces are handled for consistency & less redundant code.
  367. * Refactors AST to use `nodes` exclusively, and eliminates excessive nesting.
  368. * Fixes nested pseudo parsing.
  369. * Fixes whitespace parsing.
  370. # 0.0.2
  371. * Adds support for namespace selectors.
  372. * Adds support for selectors joined by escaped spaces - such as `.\31\ 0`.
  373. # 0.0.1
  374. * Initial release.