Skip to content

Commit 10f0adb

Browse files
committed
Update docs and metadata for 3.1.
1 parent e35949f commit 10f0adb

File tree

3 files changed

+87
-7
lines changed

3 files changed

+87
-7
lines changed

API.md

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,30 @@ Remains `undefined` if there is no attribute value.
576576
[href] /* undefined */
577577
```
578578

579+
### `attribute.qualifiedAttribute`
580+
581+
Returns the attribute name qualified with the namespace if one is given.
582+
583+
### `attribute.offsetOf(part)`
584+
585+
Returns the offset of the attribute part specified relative to the
586+
start of the node of the output string. This is useful in raising
587+
error messages about a specific part of the attribute, especially
588+
in combination with `attribute.sourceIndex`.
589+
590+
Returns `-1` if the name is invalid or the value doesn't exist in this
591+
attribute.
592+
593+
The legal values for `part` are:
594+
595+
* `"ns"` - alias for "namespace"
596+
* `"namespace"` - the namespace if it exists.
597+
* `"attribute"` - the attribute name
598+
* `"attributeNS"` - the start of the attribute or its namespace
599+
* `"operator"` - the match operator of the attribute
600+
* `"value"` - The value (string or identifier)
601+
* `"insensitive"` - the case insensitivity flag
602+
579603
### `attribute.raws.unquoted`
580604

581605
Returns the unquoted content of the attribute's value.
@@ -588,14 +612,62 @@ Remains `undefined` if there is no attribute value.
588612
[href] /* undefined */
589613
```
590614

591-
### `attribute.raws.insensitive`
615+
### `attribute.spaces`
592616

593-
If there is an `i` specifying case insensitivity, returns that `i` along with the whitespace
594-
around it.
617+
Like `node.spaces` with the `before` and `after` values containing the spaces
618+
around the element, the parts of the attribute can also have spaces before
619+
and after them. The for each of `attribute`, `operator`, `value` and
620+
`insensitive` there is corresponding property of the same nam in
621+
`node.spaces` that has an optional `before` or `after` string containing only
622+
whitespace.
595623

596-
```css
597-
[id=Bar i ] /* " i " */
598-
[id=Bar i ] /* " i " */
624+
Note that corresponding values in `attributes.raws.spaces` contain values
625+
including any comments. If set, these values will override the
626+
`attribute.spaces` value. Take care to remove them if changing
627+
`attribute.spaces`.
628+
629+
### `attribute.raws`
630+
631+
The raws object stores comments and other information necessary to re-render
632+
the node exactly as it was in the source.
633+
634+
If a comment is embedded within the identifiers for the `namespace`, `attribute`
635+
or `value` then a property is placed in the raws for that value containing the full source of the propery including comments.
636+
637+
If a comment is embedded within the space between parts of the attribute
638+
then the raw for that space is set accordingly.
639+
640+
Setting an attribute's property `raws` value to be deleted.
641+
642+
For now, changing the spaces required also updating or removing any of the
643+
raws values that override them.
644+
645+
Example: `[ /*before*/ href /* after-attr */ = /* after-operator */ te/*inside-value*/st/* wow */ /*omg*/i/*bbq*/ /*whodoesthis*/]` would parse as:
646+
647+
```js
648+
{
649+
attribute: "href",
650+
operatator: "=",
651+
value: "test",
652+
spaces: {
653+
before: '',
654+
after: '',
655+
attribute: { before: ' ', after: ' ' },
656+
operator: { after: ' ' },
657+
value: { after: ' ' },
658+
insensitive: { after: ' ' }
659+
},
660+
raws: {
661+
spaces: {
662+
attribute: { before: ' /*before*/ ', after: ' /* after-attr */ ' },
663+
operator: { after: ' /* after-operator */ ' },
664+
value: { after: '/* wow */ /*omg*/' },
665+
insensitive: { after: '/*bbq*/ /*whodoesthis*/' }
666+
},
667+
unquoted: 'test',
668+
value: 'te/*inside-value*/st'
669+
}
670+
}
599671
```
600672

601673
## `Processor`

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# 3.1.0
2+
3+
* Fixed numerous bugs in attribute nodes relating to the handling of comments
4+
and whitespace. There's significant changes to `attrNode.spaces` and `attrNode.raws` since the `3.0.0` release.
5+
* Added `Attribute#offsetOf(part)` to get the offset location of
6+
attribute parts like `"operator"` and `"value"`. This is most
7+
often added to `Attribute#sourceIndex` for error reporting.
8+
19
# 3.0.0
210

311
## Breaking changes

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "postcss-selector-parser",
3-
"version": "3.0.0",
3+
"version": "3.1.0",
44
"devDependencies": {
55
"ava": "^0.20.0",
66
"babel-cli": "^6.4.0",

0 commit comments

Comments
 (0)