nav tabs on admin dashboard

This commit is contained in:
2019-03-07 00:20:34 -06:00
parent f73d6ae228
commit e4f473f376
11661 changed files with 216240 additions and 1544253 deletions

View File

@@ -8,27 +8,30 @@ not documented here are subject to change at any point.*
This is the module's main entry point.
```js
var parser = require('postcss-selector-parser');
const parser = require('postcss-selector-parser');
```
### `parser([transform])`
### `parser([transform], [options])`
Creates a new `processor` instance
```js
var processor = parser();
const processor = parser();
```
// or, with optional transform function
var transform = function (selectors) {
selectors.eachUniversal(function (selector) {
Or, with optional transform function
```js
const transform = selectors => {
selectors.walkUniversals(selector => {
selector.remove();
});
};
var processor = parser(transform)
const processor = parser(transform)
// Example
var result = processor.process('*.class').result;
const result = processor.processSync('*.class');
// => .class
```
@@ -37,6 +40,7 @@ var result = processor.process('*.class').result;
Arguments:
* `transform (function)`: Provide a function to work with the parsed AST.
* `options (object)`: Provide default options for all calls on the returned `Processor`.
### `parser.attribute([props])`
@@ -77,6 +81,18 @@ Arguments:
* `props (object)`: The new node's properties.
Notes:
* **Descendant Combinators** The value of descendant combinators created by the
parser always just a single space (`" "`). For descendant selectors with no
comments, additional space is now stored in `node.spaces.before`. Depending
on the location of comments, additional spaces may be stored in
`node.raws.spaces.before`, `node.raws.spaces.after`, or `node.raws.value`.
* **Named Combinators** Although, nonstandard and unlikely to ever become a standard,
named combinators like `/deep/` and `/for/` are parsed as combinators. The
`node.value` is name after being unescaped and normalized as lowercase. The
original value for the combinator name is stored in `node.raws.value`.
### `parser.comment([props])`
Creates a new comment.
@@ -222,7 +238,7 @@ root.nodes[0].parent === root;
Returns a string representation of the node.
```js
var id = parser.id({value: 'search'});
const id = parser.id({value: 'search'});
console.log(String(id));
// => #search
```
@@ -232,7 +248,7 @@ console.log(String(id));
Returns the next/previous child of the parent node.
```js
var next = id.next();
const next = id.next();
if (next && next.type !== 'combinator') {
throw new Error('Qualified IDs are not allowed!');
}
@@ -243,8 +259,8 @@ if (next && next.type !== 'combinator') {
Replace a node with another.
```js
var attr = selectors.first.first;
var className = parser.className({value: 'test'});
const attr = selectors.first.first;
const className = parser.className({value: 'test'});
attr.replaceWith(className);
```
@@ -268,12 +284,23 @@ Returns a copy of a node, detached from any parent containers that the
original might have had.
```js
var cloned = parser.id({value: 'search'});
const cloned = parser.id({value: 'search'});
String(cloned);
// => #search
```
### `node.isAtPosition(line, column)`
Return a `boolean` indicating whether this node includes the character at the
position of the given line and column. Returns `undefined` if the nodes lack
sufficient source metadata to determine the position.
Arguments:
* `line`: 1-index based line number relative to the start of the selector.
* `column`: 1-index based column number relative to the start of the selector.
### `node.spaces`
Extra whitespaces around the node will be moved into `node.spaces.before` and
@@ -284,15 +311,13 @@ no semantic meaning:
h1 , h2 {}
```
However, *combinating* spaces will form a `combinator` node:
For descendent selectors, the value is always a single space.
```css
h1 h2 {}
```
A `combinator` node may only have the `spaces` property set if the combinator
value is a non-whitespace character, such as `+`, `~` or `>`. Otherwise, the
combinator value will contain all of the spaces between selectors.
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.
### `node.source`
@@ -368,6 +393,19 @@ Arguments:
* `index`: The index of the node to return.
### `container.atPosition(line, column)`
Returns the node at the source position `index`.
```js
selector.at(0) === selector.first;
selector.at(0) === selector.nodes[0];
```
Arguments:
* `index`: The index of the node to return.
### `container.index(node)`
Return the index of the node within its container.
@@ -408,8 +446,8 @@ Iterate the container's immediate children, calling `callback` for each child.
You may return `false` within the callback to break the iteration.
```js
var className;
selectors.each(function (selector, index) {
let className;
selectors.each((selector, index) => {
if (selector.type === 'class') {
className = selector.value;
return false;
@@ -431,7 +469,7 @@ Like `container#each`, but will also iterate child nodes as long as they are
`container` types.
```js
selectors.walk(function (selector, index) {
selectors.walk((selector, index) => {
// all nodes
});
```
@@ -468,7 +506,7 @@ to the groups that you created via the callback.
```js
// (input) => h1 h2>>h3
var list = selectors.first.split((selector) => {
const list = selectors.first.split(selector => {
return selector.type === 'combinator';
});
@@ -486,7 +524,7 @@ Add a node to the start/end of the container. Note that doing so will set
the parent property of the node to this container.
```js
var id = parser.id({value: 'search'});
const id = parser.id({value: 'search'});
selector.append(id);
```
@@ -499,9 +537,9 @@ Arguments:
Add a node before or after an existing node in a container:
```js
selectors.walk(function (selector) {
selectors.walk(selector => {
if (selector.type !== 'class') {
var className = parser.className({value: 'theme-name'});
const className = parser.className({value: 'theme-name'});
selector.parent.insertAfter(selector, className);
}
});
@@ -550,7 +588,7 @@ support parsing of legacy CSS hacks.
## Selector nodes
A selector node represents a single compound selector. For example, this
A selector node represents a single complex selector. For example, this
selector string `h1 h2 h3, [href] > p`, is represented as two selector nodes.
It has no special functionality of its own.
@@ -575,6 +613,30 @@ Remains `undefined` if there is no attribute value.
[href] /* undefined */
```
### `attribute.qualifiedAttribute`
Returns the attribute name qualified with the namespace if one is given.
### `attribute.offsetOf(part)`
Returns the offset of the attribute part specified relative to the
start of the node of the output string. This is useful in raising
error messages about a specific part of the attribute, especially
in combination with `attribute.sourceIndex`.
Returns `-1` if the name is invalid or the value doesn't exist in this
attribute.
The legal values for `part` are:
* `"ns"` - alias for "namespace"
* `"namespace"` - the namespace if it exists.
* `"attribute"` - the attribute name
* `"attributeNS"` - the start of the attribute or its namespace
* `"operator"` - the match operator of the attribute
* `"value"` - The value (string or identifier)
* `"insensitive"` - the case insensitivity flag
### `attribute.raws.unquoted`
Returns the unquoted content of the attribute's value.
@@ -587,38 +649,225 @@ Remains `undefined` if there is no attribute value.
[href] /* undefined */
```
### `attribute.raws.insensitive`
### `attribute.spaces`
If there is an `i` specifying case insensitivity, returns that `i` along with the whitespace
around it.
Like `node.spaces` with the `before` and `after` values containing the spaces
around the element, the parts of the attribute can also have spaces before
and after them. The for each of `attribute`, `operator`, `value` and
`insensitive` there is corresponding property of the same nam in
`node.spaces` that has an optional `before` or `after` string containing only
whitespace.
```css
[id=Bar i ] /* " i " */
[id=Bar i ] /* " i " */
```
Note that corresponding values in `attributes.raws.spaces` contain values
including any comments. If set, these values will override the
`attribute.spaces` value. Take care to remove them if changing
`attribute.spaces`.
## `processor`
### `attribute.raws`
### `process(cssText, [options])`
The raws object stores comments and other information necessary to re-render
the node exactly as it was in the source.
Processes the `cssText`, returning the parsed output
If a comment is embedded within the identifiers for the `namespace`, `attribute`
or `value` then a property is placed in the raws for that value containing the full source of the propery including comments.
If a comment is embedded within the space between parts of the attribute
then the raw for that space is set accordingly.
Setting an attribute's property `raws` value to be deleted.
For now, changing the spaces required also updating or removing any of the
raws values that override them.
Example: `[ /*before*/ href /* after-attr */ = /* after-operator */ te/*inside-value*/st/* wow */ /*omg*/i/*bbq*/ /*whodoesthis*/]` would parse as:
```js
var processor = parser();
{
attribute: "href",
operatator: "=",
value: "test",
spaces: {
before: '',
after: '',
attribute: { before: ' ', after: ' ' },
operator: { after: ' ' },
value: { after: ' ' },
insensitive: { after: ' ' }
},
raws: {
spaces: {
attribute: { before: ' /*before*/ ', after: ' /* after-attr */ ' },
operator: { after: ' /* after-operator */ ' },
value: { after: '/* wow */ /*omg*/' },
insensitive: { after: '/*bbq*/ /*whodoesthis*/' }
},
unquoted: 'test',
value: 'te/*inside-value*/st'
}
}
```
var result = processor.process(' .class').result;
## `Processor`
### `ProcessorOptions`
* `lossless` - When `true`, whitespace is preserved. Defaults to `true`.
* `updateSelector` - When `true`, if any processor methods are passed a postcss
`Rule` node instead of a string, then that Rule's selector is updated
with the results of the processing. Defaults to `true`.
### `process|processSync(selectors, [options])`
Processes the `selectors`, returning a string from the result of processing.
Note: when the `updateSelector` option is set, the rule's selector
will be updated with the resulting string.
**Example:**
```js
const parser = require("postcss-selector-parser");
const processor = parser();
let result = processor.processSync(' .class');
console.log(result);
// => .class
// Asynchronous operation
let promise = processor.process(' .class').then(result => {
console.log(result)
// => .class
});
// To have the parser normalize whitespace values, utilize the options
var result = processor.process(' .class ', {lossless: false}).result;
result = processor.processSync(' .class ', {lossless: false});
console.log(result);
// => .class
// For better syntax errors, pass a PostCSS Rule node.
const postcss = require('postcss');
rule = postcss.rule({selector: ' #foo > a, .class '});
processor.process(rule, {lossless: false, updateSelector: true}).then(result => {
console.log(result);
// => #foo>a,.class
console.log("rule:", rule.selector);
// => rule: #foo>a,.class
})
```
Arguments:
* `cssText (string)`: The css to be parsed.
* `selectors (string|postcss.Rule)`: Either a selector string or a PostCSS Rule
node.
* `[options] (object)`: Process options
Options:
* `lossless (boolean)`: false to normalize the selector whitespace, defaults to true
### `ast|astSync(selectors, [options])`
Like `process()` and `processSync()` but after
processing the `selectors` these methods return the `Root` node of the result
instead of a string.
Note: when the `updateSelector` option is set, the rule's selector
will be updated with the resulting string.
### `transform|transformSync(selectors, [options])`
Like `process()` and `processSync()` but after
processing the `selectors` these methods return the value returned by the
processor callback.
Note: when the `updateSelector` option is set, the rule's selector
will be updated with the resulting string.
### Error Handling Within Selector Processors
The root node passed to the selector processor callback
has a method `error(message, options)` that returns an
error object. This method should always be used to raise
errors relating to the syntax of selectors. The options
to this method are passed to postcss's error constructor
([documentation](http://api.postcss.org/Container.html#error)).
#### Async Error Example
```js
let processor = (root) => {
return new Promise((resolve, reject) => {
root.walkClasses((classNode) => {
if (/^(.*)[-_]/.test(classNode.value)) {
let msg = "classes may not have underscores or dashes in them";
reject(root.error(msg, {
index: classNode.sourceIndex + RegExp.$1.length + 1,
word: classNode.value
}));
}
});
resolve();
});
};
const postcss = require("postcss");
const parser = require("postcss-selector-parser");
const selectorProcessor = parser(processor);
const plugin = postcss.plugin('classValidator', (options) => {
return (root) => {
let promises = [];
root.walkRules(rule => {
promises.push(selectorProcessor.process(rule));
});
return Promise.all(promises);
};
});
postcss(plugin()).process(`
.foo-bar {
color: red;
}
`.trim(), {from: 'test.css'}).catch((e) => console.error(e.toString()));
// CssSyntaxError: classValidator: ./test.css:1:5: classes may not have underscores or dashes in them
//
// > 1 | .foo-bar {
// | ^
// 2 | color: red;
// 3 | }
```
#### Synchronous Error Example
```js
let processor = (root) => {
root.walkClasses((classNode) => {
if (/.*[-_]/.test(classNode.value)) {
let msg = "classes may not have underscores or dashes in them";
throw root.error(msg, {
index: classNode.sourceIndex,
word: classNode.value
});
}
});
};
const postcss = require("postcss");
const parser = require("postcss-selector-parser");
const selectorProcessor = parser(processor);
const plugin = postcss.plugin('classValidator', (options) => {
return (root) => {
root.walkRules(rule => {
selectorProcessor.processSync(rule);
});
};
});
postcss(plugin()).process(`
.foo-bar {
color: red;
}
`.trim(), {from: 'test.css'}).catch((e) => console.error(e.toString()));
// CssSyntaxError: classValidator: ./test.css:1:5: classes may not have underscores or dashes in them
//
// > 1 | .foo-bar {
// | ^
// 2 | color: red;
// 3 | }
```

View File

@@ -1,3 +1,312 @@
# 5.0.0
- Allow escaped dot within class name.
- Update PostCSS to 7.0.7 (patch)
# 5.0.0-rc.4
- Fixed and issue where comments immediately after an insensitive
(in attribute) were not parsed correctly.
- Updated `cssesc` to 2.0.0 (major).
- Removed outdated integration tests.
- Added tests for custom selectors, tags with attributes, the universal
selector with pseudos, and tokens after combinators.
# 5.0.0-rc.1
To ease adoption of the v5.0 release, we have relaxed the node version
check performed by npm at installation time to allow for node 4, which
remains officially unsupported, but likely to continue working for the
time being.
# 5.0.0-rc.0
This release has **BREAKING CHANGES** that were required to fix regressions
in 4.0.0 and to make the Combinator Node API consistent for all combinator
types. Please read carefully.
## Summary of Changes
* The way a descendent combinator that isn't a single space character (E.g. `.a .b`) is stored in the AST has changed.
* Named Combinators (E.g. `.a /for/ .b`) are now properly parsed as a combinator.
* 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.
* Several bug fixes that caused the parser to hang and run out of memory when a `/` was encountered have been fixed.
* The minimum supported version of Node is now `v6.0.0`.
### Changes to the Descendent Combinator
In prior releases, the value of a descendant combinator with multiple spaces included all the spaces.
* `.a .b`: Extra spaces are now stored as space before.
- Old & Busted:
- `combinator.value === " "`
- New hotness:
- `combinator.value === " " && combinator.spaces.before === " "`
* `.a /*comment*/.b`: A comment at the end of the combinator causes extra space to become after space.
- Old & Busted:
- `combinator.value === " "`
- `combinator.raws.value === " /*comment/"`
- New hotness:
- `combinator.value === " "`
- `combinator.spaces.after === " "`
- `combinator.raws.spaces.after === " /*comment*/"`
* `.a<newline>.b`: whitespace that doesn't start or end with a single space character is stored as a raw value.
- Old & Busted:
- `combinator.value === "\n"`
- `combinator.raws.value === undefined`
- New hotness:
- `combinator.value === " "`
- `combinator.raws.value === "\n"`
### Support for "Named Combinators"
Although, nonstandard and unlikely to ever become a standard, combinators like `/deep/` and `/for/` are now properly supported.
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.
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 `"/"`.
* `.a /for/ .b` is parsed as a combinator.
- Old & Busted:
- `root.nodes[0].nodes[1].type === "tag"`
- `root.nodes[0].nodes[1].value === "/"`
- New hotness:
- `root.nodes[0].nodes[1].type === "combinator"`
- `root.nodes[0].nodes[1].value === "/for/"`
* `.a /F\6fR/ .b` escapes are handled and uppercase is normalized.
- Old & Busted:
- `root.nodes[0].nodes[2].type === "tag"`
- `root.nodes[0].nodes[2].value === "F\\6fR"`
- New hotness:
- `root.nodes[0].nodes[1].type === "combinator"`
- `root.nodes[0].nodes[1].value === "/for/"`
- `root.nodes[0].nodes[1].raws.value === "/F\\6fR/"`
### Source position checks and lookups
A new API was added to look up a node based on the source location.
```js
const selectorParser = require("postcss-selector-parser");
// You can find the most specific node for any given character
let combinator = selectorParser.astSync(".a > .b").atPosition(1,4);
combinator.toString() === " > ";
// You can check if a node includes a specific character
// Whitespace surrounding the node that is owned by that node
// is included in the check.
[2,3,4,5,6].map(column => combinator.isAtPosition(1, column));
// => [false, true, true, true, false]
```
# 4.0.0
This release has **BREAKING CHANGES** that were required to fix bugs regarding values with escape sequences. Please read carefully.
* **Identifiers with escapes** - CSS escape sequences are now hidden from the public API by default.
The normal value of a node like a class name or ID, or an aspect of a node such as attribute
selector's value, is unescaped. Escapes representing Non-ascii characters are unescaped into
unicode characters. For example: `bu\tton, .\31 00, #i\2764\FE0Fu, [attr="value is \"quoted\""]`
will parse respectively to the values `button`, `100`, `i❤u`, `value is "quoted"`.
The original escape sequences for these values can be found in the corresponding property name
in `node.raws`. Where possible, deprecation warnings were added, but the nature
of escape handling makes it impossible to detect what is escaped or not. Our expectation is
that most users are neither expecting nor handling escape sequences in their use of this library,
and so for them, this is a bug fix. Users who are taking care to handle escapes correctly can
now update their code to remove the escape handling and let us do it for them.
* **Mutating values with escapes** - When you make an update to a node property that has escape handling
The value is assumed to be unescaped, and any special characters are escaped automatically and
the corresponding `raws` value is immediately updated. This can result in changes to the original
escape format. Where the exact value of the escape sequence is important there are methods that
allow both values to be set in conjunction. There are a number of new convenience methods for
manipulating values that involve escapes, especially for attributes values where the quote mark
is involved. See https://github.com/postcss/postcss-selector-parser/pull/133 for an extensive
write-up on these changes.
**Upgrade/API Example**
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
to create a CSS file that did not parse correctly when some types of values
were in use.
```js
const selectorParser = require("postcss-selector-parser");
let attr = selectorParser.attribute({attribute: "id", operator: "=", value: "a-value"});
attr.value; // => "a-value"
attr.toString(); // => [id=a-value]
// Add quotes to an attribute's value.
// All these values have to be set by the caller to be consistent:
// no internal consistency is maintained.
attr.raws.unquoted = attr.value
attr.value = "'" + attr.value + "'";
attr.value; // => "'a-value'"
attr.quoted = true;
attr.toString(); // => "[id='a-value']"
```
In `4.0` there is a convenient API for setting and mutating values
that may need escaping. Especially for attributes.
```js
const selectorParser = require("postcss-selector-parser");
// The constructor requires you specify the exact escape sequence
let className = selectorParser.className({value: "illegal class name", raws: {value: "illegal\\ class\\ name"}});
className.toString(); // => '.illegal\\ class\\ name'
// So it's better to set the value as a property
className = selectorParser.className();
// Most properties that deal with identifiers work like this
className.value = "escape for me";
className.value; // => 'escape for me'
className.toString(); // => '.escape\\ for\\ me'
// emoji and all non-ascii are escaped to ensure it works in every css file.
className.value = "😱🦄😍";
className.value; // => '😱🦄😍'
className.toString(); // => '.\\1F631\\1F984\\1F60D'
// you can control the escape sequence if you want, or do bad bad things
className.setPropertyAndEscape('value', 'xxxx', 'yyyy');
className.value; // => "xxxx"
className.toString(); // => ".yyyy"
// Pass a value directly through to the css output without escaping it.
className.setPropertyWithoutEscape('value', '$REPLACE_ME$');
className.value; // => "$REPLACE_ME$"
className.toString(); // => ".$REPLACE_ME$"
// The biggest changes are to the Attribute class
// passing quoteMark explicitly is required to avoid a deprecation warning.
let attr = selectorParser.attribute({attribute: "id", operator: "=", value: "a-value", quoteMark: null});
attr.toString(); // => "[id=a-value]"
// Get the value with quotes on it and any necessary escapes.
// This is the same as reading attr.value in 3.x.
attr.getQuotedValue(); // => "a-value";
attr.quoteMark; // => null
// Add quotes to an attribute's value.
attr.quoteMark = "'"; // This is all that's required.
attr.toString(); // => "[id='a-value']"
attr.quoted; // => true
// The value is still the same, only the quotes have changed.
attr.value; // => a-value
attr.getQuotedValue(); // => "'a-value'";
// deprecated assignment, no warning because there's no escapes
attr.value = "new-value";
// no quote mark is needed so it is removed
attr.getQuotedValue(); // => "new-value";
// deprecated assignment,
attr.value = "\"a 'single quoted' value\"";
// > (node:27859) DeprecationWarning: Assigning an attribute a value containing characters that might need to be escaped is deprecated. Call attribute.setValue() instead.
attr.getQuotedValue(); // => '"a \'single quoted\' value"';
// quote mark inferred from first and last characters.
attr.quoteMark; // => '"'
// setValue takes options to make manipulating the value simple.
attr.setValue('foo', {smart: true});
// foo doesn't require any escapes or quotes.
attr.toString(); // => '[id=foo]'
attr.quoteMark; // => null
// An explicit quote mark can be specified
attr.setValue('foo', {quoteMark: '"'});
attr.toString(); // => '[id="foo"]'
// preserves quote mark by default
attr.setValue('bar');
attr.toString(); // => '[id="bar"]'
attr.quoteMark = null;
attr.toString(); // => '[id=bar]'
// with no arguments, it preserves quote mark even when it's not a great idea
attr.setValue('a value \n that should be quoted');
attr.toString(); // => '[id=a\\ value\\ \\A\\ that\\ should\\ be\\ quoted]'
// smart preservation with a specified default
attr.setValue('a value \n that should be quoted', {smart: true, preferCurrentQuoteMark: true, quoteMark: "'"});
// => "[id='a value \\A that should be quoted']"
attr.quoteMark = '"';
// => '[id="a value \\A that should be quoted"]'
// this keeps double quotes because it wants to quote the value and the existing value has double quotes.
attr.setValue('this should be quoted', {smart: true, preferCurrentQuoteMark: true, quoteMark: "'"});
// => '[id="this should be quoted"]'
// picks single quotes because the value has double quotes
attr.setValue('a "double quoted" value', {smart: true, preferCurrentQuoteMark: true, quoteMark: "'"});
// => "[id='a "double quoted" value']"
// setPropertyAndEscape lets you do anything you want. Even things that are a bad idea and illegal.
attr.setPropertyAndEscape('value', 'xxxx', 'the password is 42');
attr.value; // => "xxxx"
attr.toString(); // => "[id=the password is 42]"
// Pass a value directly through to the css output without escaping it.
attr.setPropertyWithoutEscape('value', '$REPLACEMENT$');
attr.value; // => "$REPLACEMENT$"
attr.toString(); // => "[id=$REPLACEMENT$]"
```
# 3.1.2
* Fix: Removed dot-prop dependency since it's no longer written in es5.
# 3.1.1
* Fix: typescript definitions weren't in the published package.
# 3.1.0
* Fixed numerous bugs in attribute nodes relating to the handling of comments
and whitespace. There's significant changes to `attrNode.spaces` and `attrNode.raws` since the `3.0.0` release.
* Added `Attribute#offsetOf(part)` to get the offset location of
attribute parts like `"operator"` and `"value"`. This is most
often added to `Attribute#sourceIndex` for error reporting.
# 3.0.0
## Breaking changes
* Some tweaks to the tokenizer/attribute selector parsing mean that whitespace
locations might be slightly different to the 2.x code.
* Better attribute selector parsing with more validation; postcss-selector-parser
no longer uses regular expressions to parse attribute selectors.
* Added an async API (thanks to @jacobp100); the default `process` API is now
async, and the sync API is now accessed through `processSync` instead.
* `process()` and `processSync()` now return a string instead of the Processor
instance.
* Tweaks handling of Less interpolation (thanks to @jwilsson).
* Removes support for Node 0.12.
## Other changes
* `ast()` and `astSync()` methods have been added to the `Processor`. These
return the `Root` node of the selectors after processing them.
* `transform()` and `transformSync()` methods have been added to the
`Processor`. These return the value returned by the processor callback
after processing the selectors.
* Set the parent when inserting a node (thanks to @chriseppstein).
* Correctly adjust indices when using insertBefore/insertAfter (thanks to @tivac).
* Fixes handling of namespaces with qualified tag selectors.
* `process`, `ast` and `transform` (and their sync variants) now accept a
`postcss` rule node. When provided, better errors are generated and selector
processing is automatically set back to the rule selector (unless the `updateSelector` option is set to `false`.)
* Now more memory efficient when tokenizing selectors.
### Upgrade hints
The pattern of:
`rule.selector = processor.process(rule.selector).result.toString();`
is now:
`processor.processSync(rule)`
# 2.2.3
* Resolves an issue where the parser would not reduce multiple spaces between an

View File

@@ -13,25 +13,28 @@ npm install postcss-selector-parser
## Quick Start
```js
var parser = require('postcss-selector-parser');
var transform = function (selectors) {
selectors.eachInside(function (selector) {
const parser = require('postcss-selector-parser');
const transform = selectors => {
selectors.walk(selector => {
// do something with the selector
console.log(String(selector))
});
};
var transformed = parser(transform).process('h1, h2, h3').result;
const transformed = parser(transform).processSync('h1, h2, h3');
```
To normalize selector whitespace:
```js
var parser = require('postcss-selector-parser');
var normalized = parser().process('h1, h2, h3', {lossless:false}).result;
const parser = require('postcss-selector-parser');
const normalized = parser().processSync('h1, h2, h3', {lossless: false});
// -> h1,h2,h3
```
Async support is provided through `parser.process` and will resolve a Promise
with the resulting selector string.
## API
Please see [API.md](API.md).

View File

@@ -6,109 +6,21 @@ var _processor = require('./processor');
var _processor2 = _interopRequireDefault(_processor);
var _attribute = require('./selectors/attribute');
var _selectors = require('./selectors');
var _attribute2 = _interopRequireDefault(_attribute);
var _className = require('./selectors/className');
var _className2 = _interopRequireDefault(_className);
var _combinator = require('./selectors/combinator');
var _combinator2 = _interopRequireDefault(_combinator);
var _comment = require('./selectors/comment');
var _comment2 = _interopRequireDefault(_comment);
var _id = require('./selectors/id');
var _id2 = _interopRequireDefault(_id);
var _nesting = require('./selectors/nesting');
var _nesting2 = _interopRequireDefault(_nesting);
var _pseudo = require('./selectors/pseudo');
var _pseudo2 = _interopRequireDefault(_pseudo);
var _root = require('./selectors/root');
var _root2 = _interopRequireDefault(_root);
var _selector = require('./selectors/selector');
var _selector2 = _interopRequireDefault(_selector);
var _string = require('./selectors/string');
var _string2 = _interopRequireDefault(_string);
var _tag = require('./selectors/tag');
var _tag2 = _interopRequireDefault(_tag);
var _universal = require('./selectors/universal');
var _universal2 = _interopRequireDefault(_universal);
var _types = require('./selectors/types');
var types = _interopRequireWildcard(_types);
var selectors = _interopRequireWildcard(_selectors);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var parser = function parser(processor) {
return new _processor2.default(processor);
return new _processor2.default(processor);
};
parser.attribute = function (opts) {
return new _attribute2.default(opts);
};
parser.className = function (opts) {
return new _className2.default(opts);
};
parser.combinator = function (opts) {
return new _combinator2.default(opts);
};
parser.comment = function (opts) {
return new _comment2.default(opts);
};
parser.id = function (opts) {
return new _id2.default(opts);
};
parser.nesting = function (opts) {
return new _nesting2.default(opts);
};
parser.pseudo = function (opts) {
return new _pseudo2.default(opts);
};
parser.root = function (opts) {
return new _root2.default(opts);
};
parser.selector = function (opts) {
return new _selector2.default(opts);
};
parser.string = function (opts) {
return new _string2.default(opts);
};
parser.tag = function (opts) {
return new _tag2.default(opts);
};
parser.universal = function (opts) {
return new _universal2.default(opts);
};
Object.assign(parser, selectors);
Object.keys(types).forEach(function (type) {
if (type === '__esModule') {
return;
}
parser[type] = types[type]; // eslint-disable-line
});
delete parser.__esModule;
exports.default = parser;
module.exports = exports['default'];

File diff suppressed because it is too large Load Diff

View File

@@ -1,10 +1,8 @@
'use strict';
"use strict";
exports.__esModule = true;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _parser = require('./parser');
var _parser = require("./parser");
var _parser2 = _interopRequireDefault(_parser);
@@ -13,37 +11,175 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Processor = function () {
function Processor(func) {
function Processor(func, options) {
_classCallCheck(this, Processor);
this.func = func || function noop() {};
return this;
this.funcRes = null;
this.options = options;
}
Processor.prototype.process = function process(selectors) {
Processor.prototype._shouldUpdateSelector = function _shouldUpdateSelector(rule) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var input = new _parser2.default({
css: selectors,
error: function error(e) {
throw new Error(e);
},
options: options
});
this.res = input;
this.func(input);
return this;
var merged = Object.assign({}, this.options, options);
if (merged.updateSelector === false) {
return false;
} else {
return typeof rule !== "string";
}
};
_createClass(Processor, [{
key: 'result',
get: function get() {
return String(this.res);
Processor.prototype._isLossy = function _isLossy() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var merged = Object.assign({}, this.options, options);
if (merged.lossless === false) {
return true;
} else {
return false;
}
}]);
};
Processor.prototype._root = function _root(rule) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var parser = new _parser2.default(rule, this._parseOptions(options));
return parser.root;
};
Processor.prototype._parseOptions = function _parseOptions(options) {
return {
lossy: this._isLossy(options)
};
};
Processor.prototype._run = function _run(rule) {
var _this = this;
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return new Promise(function (resolve, reject) {
try {
var root = _this._root(rule, options);
Promise.resolve(_this.func(root)).then(function (transform) {
var string = undefined;
if (_this._shouldUpdateSelector(rule, options)) {
string = root.toString();
rule.selector = string;
}
return { transform: transform, root: root, string: string };
}).then(resolve, reject);
} catch (e) {
reject(e);
return;
}
});
};
Processor.prototype._runSync = function _runSync(rule) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var root = this._root(rule, options);
var transform = this.func(root);
if (transform && typeof transform.then === "function") {
throw new Error("Selector processor returned a promise to a synchronous call.");
}
var string = undefined;
if (options.updateSelector && typeof rule !== "string") {
string = root.toString();
rule.selector = string;
}
return { transform: transform, root: root, string: string };
};
/**
* Process rule into a selector AST.
*
* @param rule {postcss.Rule | string} The css selector to be processed
* @param options The options for processing
* @returns {Promise<parser.Root>} The AST of the selector after processing it.
*/
Processor.prototype.ast = function ast(rule, options) {
return this._run(rule, options).then(function (result) {
return result.root;
});
};
/**
* Process rule into a selector AST synchronously.
*
* @param rule {postcss.Rule | string} The css selector to be processed
* @param options The options for processing
* @returns {parser.Root} The AST of the selector after processing it.
*/
Processor.prototype.astSync = function astSync(rule, options) {
return this._runSync(rule, options).root;
};
/**
* Process a selector into a transformed value asynchronously
*
* @param rule {postcss.Rule | string} The css selector to be processed
* @param options The options for processing
* @returns {Promise<any>} The value returned by the processor.
*/
Processor.prototype.transform = function transform(rule, options) {
return this._run(rule, options).then(function (result) {
return result.transform;
});
};
/**
* Process a selector into a transformed value synchronously.
*
* @param rule {postcss.Rule | string} The css selector to be processed
* @param options The options for processing
* @returns {any} The value returned by the processor.
*/
Processor.prototype.transformSync = function transformSync(rule, options) {
return this._runSync(rule, options).transform;
};
/**
* Process a selector into a new selector string asynchronously.
*
* @param rule {postcss.Rule | string} The css selector to be processed
* @param options The options for processing
* @returns {string} the selector after processing.
*/
Processor.prototype.process = function process(rule, options) {
return this._run(rule, options).then(function (result) {
return result.string || result.root.toString();
});
};
/**
* Process a selector into a new selector string synchronously.
*
* @param rule {postcss.Rule | string} The css selector to be processed
* @param options The options for processing
* @returns {string} the selector after processing.
*/
Processor.prototype.processSync = function processSync(rule, options) {
var result = this._runSync(rule, options);
return result.string || result.root.toString();
};
return Processor;
}();
exports.default = Processor;
module.exports = exports['default'];
module.exports = exports["default"];

View File

@@ -1,12 +1,26 @@
'use strict';
"use strict";
exports.__esModule = true;
var _namespace = require('./namespace');
var _CSSESC_QUOTE_OPTIONS;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
exports.unescapeValue = unescapeValue;
var _cssesc = require("cssesc");
var _cssesc2 = _interopRequireDefault(_cssesc);
var _unesc = require("../util/unesc");
var _unesc2 = _interopRequireDefault(_unesc);
var _namespace = require("./namespace");
var _namespace2 = _interopRequireDefault(_namespace);
var _types = require('./types');
var _types = require("./types");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -16,39 +30,439 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var _require = require("util"),
deprecate = _require.deprecate;
var WRAPPED_IN_QUOTES = /^('|")(.*)\1$/;
var warnOfDeprecatedValueAssignment = deprecate(function () {}, "Assigning an attribute a value containing characters that might need to be escaped is deprecated. " + "Call attribute.setValue() instead.");
var warnOfDeprecatedQuotedAssignment = deprecate(function () {}, "Assigning attr.quoted is deprecated and has no effect. Assign to attr.quoteMark instead.");
var warnOfDeprecatedConstructor = deprecate(function () {}, "Constructing an Attribute selector with a value without specifying quoteMark is deprecated. Note: The value should be unescaped now.");
function unescapeValue(value) {
var deprecatedUsage = false;
var quoteMark = null;
var unescaped = value;
var m = unescaped.match(WRAPPED_IN_QUOTES);
if (m) {
quoteMark = m[1];
unescaped = m[2];
}
unescaped = (0, _unesc2.default)(unescaped);
if (unescaped !== value) {
deprecatedUsage = true;
}
return {
deprecatedUsage: deprecatedUsage,
unescaped: unescaped,
quoteMark: quoteMark
};
}
function handleDeprecatedContructorOpts(opts) {
if (opts.quoteMark !== undefined) {
return opts;
}
if (opts.value === undefined) {
return opts;
}
warnOfDeprecatedConstructor();
var _unescapeValue = unescapeValue(opts.value),
quoteMark = _unescapeValue.quoteMark,
unescaped = _unescapeValue.unescaped;
if (!opts.raws) {
opts.raws = {};
}
if (opts.raws.value === undefined) {
opts.raws.value = opts.value;
}
opts.value = unescaped;
opts.quoteMark = quoteMark;
return opts;
}
var Attribute = function (_Namespace) {
_inherits(Attribute, _Namespace);
function Attribute(opts) {
function Attribute() {
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, Attribute);
var _this = _possibleConstructorReturn(this, _Namespace.call(this, opts));
var _this = _possibleConstructorReturn(this, _Namespace.call(this, handleDeprecatedContructorOpts(opts)));
_this.type = _types.ATTRIBUTE;
_this.raws = {};
_this.raws = _this.raws || {};
Object.defineProperty(_this.raws, 'unquoted', {
get: deprecate(function () {
return _this.value;
}, "attr.raws.unquoted is deprecated. Call attr.value instead."),
set: deprecate(function () {
return _this.value;
}, "Setting attr.raws.unquoted is deprecated and has no effect. attr.value is unescaped by default now.")
});
_this._constructed = true;
return _this;
}
Attribute.prototype.toString = function toString() {
var selector = [this.spaces.before, '[', this.ns, this.attribute];
/**
* Returns the Attribute's value quoted such that it would be legal to use
* in the value of a css file. The original value's quotation setting
* used for stringification is left unchanged. See `setValue(value, options)`
* if you want to control the quote settings of a new value for the attribute.
*
* You can also change the quotation used for the current value by setting quoteMark.
*
* Options:
* * quoteMark {'"' | "'" | null} - Use this value to quote the value. If this
* option is not set, the original value for quoteMark will be used. If
* indeterminate, a double quote is used. The legal values are:
* * `null` - the value will be unquoted and characters will be escaped as necessary.
* * `'` - the value will be quoted with a single quote and single quotes are escaped.
* * `"` - the value will be quoted with a double quote and double quotes are escaped.
* * preferCurrentQuoteMark {boolean} - if true, prefer the source quote mark
* over the quoteMark option value.
* * smart {boolean} - if true, will select a quote mark based on the value
* and the other options specified here. See the `smartQuoteMark()`
* method.
**/
if (this.operator) {
selector.push(this.operator);
}
if (this.value) {
selector.push(this.value);
}
if (this.raws.insensitive) {
selector.push(this.raws.insensitive);
} else if (this.insensitive) {
selector.push(' i');
}
selector.push(']');
return selector.concat(this.spaces.after).join('');
Attribute.prototype.getQuotedValue = function getQuotedValue() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var quoteMark = this._determineQuoteMark(options);
var cssescopts = CSSESC_QUOTE_OPTIONS[quoteMark];
var escaped = (0, _cssesc2.default)(this._value, cssescopts);
return escaped;
};
Attribute.prototype._determineQuoteMark = function _determineQuoteMark(options) {
return options.smart ? this.smartQuoteMark(options) : this.preferredQuoteMark(options);
};
/**
* Set the unescaped value with the specified quotation options. The value
* provided must not include any wrapping quote marks -- those quotes will
* be interpreted as part of the value and escaped accordingly.
*/
Attribute.prototype.setValue = function setValue(value) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
this._value = value;
this._quoteMark = this._determineQuoteMark(options);
this._syncRawValue();
};
/**
* Intelligently select a quoteMark value based on the value's contents. If
* the value is a legal CSS ident, it will not be quoted. Otherwise a quote
* mark will be picked that minimizes the number of escapes.
*
* If there's no clear winner, the quote mark from these options is used,
* then the source quote mark (this is inverted if `preferCurrentQuoteMark` is
* true). If the quoteMark is unspecified, a double quote is used.
*
* @param options This takes the quoteMark and preferCurrentQuoteMark options
* from the quoteValue method.
*/
Attribute.prototype.smartQuoteMark = function smartQuoteMark(options) {
var v = this.value;
var numSingleQuotes = v.replace(/[^']/g, '').length;
var numDoubleQuotes = v.replace(/[^"]/g, '').length;
if (numSingleQuotes + numDoubleQuotes === 0) {
var escaped = (0, _cssesc2.default)(v, { isIdentifier: true });
if (escaped === v) {
return Attribute.NO_QUOTE;
} else {
var pref = this.preferredQuoteMark(options);
if (pref === Attribute.NO_QUOTE) {
// pick a quote mark that isn't none and see if it's smaller
var quote = this.quoteMark || options.quoteMark || Attribute.DOUBLE_QUOTE;
var opts = CSSESC_QUOTE_OPTIONS[quote];
var quoteValue = (0, _cssesc2.default)(v, opts);
if (quoteValue.length < escaped.length) {
return quote;
}
}
return pref;
}
} else if (numDoubleQuotes === numSingleQuotes) {
return this.preferredQuoteMark(options);
} else if (numDoubleQuotes < numSingleQuotes) {
return Attribute.DOUBLE_QUOTE;
} else {
return Attribute.SINGLE_QUOTE;
}
};
/**
* Selects the preferred quote mark based on the options and the current quote mark value.
* If you want the quote mark to depend on the attribute value, call `smartQuoteMark(opts)`
* instead.
*/
Attribute.prototype.preferredQuoteMark = function preferredQuoteMark(options) {
var quoteMark = options.preferCurrentQuoteMark ? this.quoteMark : options.quoteMark;
if (quoteMark === undefined) {
quoteMark = options.preferCurrentQuoteMark ? options.quoteMark : this.quoteMark;
}
if (quoteMark === undefined) {
quoteMark = Attribute.DOUBLE_QUOTE;
}
return quoteMark;
};
Attribute.prototype._syncRawValue = function _syncRawValue() {
var rawValue = (0, _cssesc2.default)(this._value, CSSESC_QUOTE_OPTIONS[this.quoteMark]);
if (rawValue === this._value) {
if (this.raws) {
delete this.raws.value;
}
} else {
this.raws.value = rawValue;
}
};
Attribute.prototype._handleEscapes = function _handleEscapes(prop, value) {
if (this._constructed) {
var escaped = (0, _cssesc2.default)(value, { isIdentifier: true });
if (escaped !== value) {
this.raws[prop] = escaped;
} else {
delete this.raws[prop];
}
}
};
Attribute.prototype._spacesFor = function _spacesFor(name) {
var attrSpaces = { before: '', after: '' };
var spaces = this.spaces[name] || {};
var rawSpaces = this.raws.spaces && this.raws.spaces[name] || {};
return Object.assign(attrSpaces, spaces, rawSpaces);
};
Attribute.prototype._stringFor = function _stringFor(name) {
var spaceName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : name;
var concat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultAttrConcat;
var attrSpaces = this._spacesFor(spaceName);
return concat(this.stringifyProperty(name), attrSpaces);
};
/**
* returns the offset of the attribute part specified relative to the
* start of the node of the output string.
*
* * "ns" - alias for "namespace"
* * "namespace" - the namespace if it exists.
* * "attribute" - the attribute name
* * "attributeNS" - the start of the attribute or its namespace
* * "operator" - the match operator of the attribute
* * "value" - The value (string or identifier)
* * "insensitive" - the case insensitivity flag;
* @param part One of the possible values inside an attribute.
* @returns -1 if the name is invalid or the value doesn't exist in this attribute.
*/
Attribute.prototype.offsetOf = function offsetOf(name) {
var count = 1;
var attributeSpaces = this._spacesFor("attribute");
count += attributeSpaces.before.length;
if (name === "namespace" || name === "ns") {
return this.namespace ? count : -1;
}
if (name === "attributeNS") {
return count;
}
count += this.namespaceString.length;
if (this.namespace) {
count += 1;
}
if (name === "attribute") {
return count;
}
count += this.stringifyProperty("attribute").length;
count += attributeSpaces.after.length;
var operatorSpaces = this._spacesFor("operator");
count += operatorSpaces.before.length;
var operator = this.stringifyProperty("operator");
if (name === "operator") {
return operator ? count : -1;
}
count += operator.length;
count += operatorSpaces.after.length;
var valueSpaces = this._spacesFor("value");
count += valueSpaces.before.length;
var value = this.stringifyProperty("value");
if (name === "value") {
return value ? count : -1;
}
count += value.length;
count += valueSpaces.after.length;
var insensitiveSpaces = this._spacesFor("insensitive");
count += insensitiveSpaces.before.length;
if (name === "insensitive") {
return this.insensitive ? count : -1;
}
return -1;
};
Attribute.prototype.toString = function toString() {
var _this2 = this;
var selector = [this.rawSpaceBefore, '['];
selector.push(this._stringFor('qualifiedAttribute', 'attribute'));
if (this.operator && this.value) {
selector.push(this._stringFor('operator'));
selector.push(this._stringFor('value'));
selector.push(this._stringFor('insensitiveFlag', 'insensitive', function (attrValue, attrSpaces) {
if (attrValue.length > 0 && !_this2.quoted && attrSpaces.before.length === 0 && !(_this2.spaces.value && _this2.spaces.value.after)) {
attrSpaces.before = " ";
}
return defaultAttrConcat(attrValue, attrSpaces);
}));
}
selector.push(']');
selector.push(this.rawSpaceAfter);
return selector.join('');
};
_createClass(Attribute, [{
key: "quoted",
get: function get() {
var qm = this.quoteMark;
return qm === "'" || qm === '"';
},
set: function set(value) {
warnOfDeprecatedQuotedAssignment();
}
/**
* returns a single (`'`) or double (`"`) quote character if the value is quoted.
* returns `null` if the value is not quoted.
* returns `undefined` if the quotation state is unknown (this can happen when
* the attribute is constructed without specifying a quote mark.)
*/
}, {
key: "quoteMark",
get: function get() {
return this._quoteMark;
}
/**
* Set the quote mark to be used by this attribute's value.
* If the quote mark changes, the raw (escaped) value at `attr.raws.value` of the attribute
* value is updated accordingly.
*
* @param {"'" | '"' | null} quoteMark The quote mark or `null` if the value should be unquoted.
*/
,
set: function set(quoteMark) {
if (!this._constructed) {
this._quoteMark = quoteMark;
return;
}
if (this._quoteMark !== quoteMark) {
this._quoteMark = quoteMark;
this._syncRawValue();
}
}
}, {
key: "qualifiedAttribute",
get: function get() {
return this.qualifiedName(this.raws.attribute || this.attribute);
}
}, {
key: "insensitiveFlag",
get: function get() {
return this.insensitive ? 'i' : '';
}
}, {
key: "value",
get: function get() {
return this._value;
}
/**
* Before 3.0, the value had to be set to an escaped value including any wrapped
* quote marks. In 3.0, the semantics of `Attribute.value` changed so that the value
* is unescaped during parsing and any quote marks are removed.
*
* Because the ambiguity of this semantic change, if you set `attr.value = newValue`,
* a deprecation warning is raised when the new value contains any characters that would
* require escaping (including if it contains wrapped quotes).
*
* Instead, you should call `attr.setValue(newValue, opts)` and pass options that describe
* how the new value is quoted.
*/
,
set: function set(v) {
if (this._constructed) {
var _unescapeValue2 = unescapeValue(v),
deprecatedUsage = _unescapeValue2.deprecatedUsage,
unescaped = _unescapeValue2.unescaped,
quoteMark = _unescapeValue2.quoteMark;
if (deprecatedUsage) {
warnOfDeprecatedValueAssignment();
}
if (unescaped === this._value && quoteMark === this._quoteMark) {
return;
}
this._value = unescaped;
this._quoteMark = quoteMark;
this._syncRawValue();
} else {
this._value = v;
}
}
}, {
key: "attribute",
get: function get() {
return this._attribute;
},
set: function set(name) {
this._handleEscapes("attribute", name);
this._attribute = name;
}
}]);
return Attribute;
}(_namespace2.default);
Attribute.NO_QUOTE = null;
Attribute.SINGLE_QUOTE = "'";
Attribute.DOUBLE_QUOTE = '"';
exports.default = Attribute;
module.exports = exports['default'];
var CSSESC_QUOTE_OPTIONS = (_CSSESC_QUOTE_OPTIONS = {
"'": { quotes: 'single', wrap: true },
'"': { quotes: 'double', wrap: true }
}, _CSSESC_QUOTE_OPTIONS[null] = { isIdentifier: true }, _CSSESC_QUOTE_OPTIONS);
function defaultAttrConcat(attrValue, attrSpaces) {
return "" + attrSpaces.before + attrValue + attrSpaces.after;
}

View File

@@ -2,9 +2,17 @@
exports.__esModule = true;
var _namespace = require('./namespace');
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _namespace2 = _interopRequireDefault(_namespace);
var _cssesc = require('cssesc');
var _cssesc2 = _interopRequireDefault(_cssesc);
var _util = require('../util');
var _node = require('./node');
var _node2 = _interopRequireDefault(_node);
var _types = require('./types');
@@ -16,24 +24,44 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var ClassName = function (_Namespace) {
_inherits(ClassName, _Namespace);
var ClassName = function (_Node) {
_inherits(ClassName, _Node);
function ClassName(opts) {
_classCallCheck(this, ClassName);
var _this = _possibleConstructorReturn(this, _Namespace.call(this, opts));
var _this = _possibleConstructorReturn(this, _Node.call(this, opts));
_this.type = _types.CLASS;
_this._constructed = true;
return _this;
}
ClassName.prototype.toString = function toString() {
return [this.spaces.before, this.ns, String('.' + this.value), this.spaces.after].join('');
return [this.rawSpaceBefore, String('.' + this.stringifyProperty("value")), this.rawSpaceAfter].join('');
};
_createClass(ClassName, [{
key: 'value',
set: function set(v) {
if (this._constructed) {
var escaped = (0, _cssesc2.default)(v, { isIdentifier: true });
if (escaped !== v) {
(0, _util.ensureObject)(this, "raws");
this.raws.value = escaped;
} else if (this.raws) {
delete this.raws.value;
}
}
this._value = v;
},
get: function get() {
return this._value;
}
}]);
return ClassName;
}(_namespace2.default);
}(_node2.default);
exports.default = ClassName;
module.exports = exports['default'];

View File

@@ -101,14 +101,17 @@ var Container = function (_Node) {
};
Container.prototype.insertAfter = function insertAfter(oldNode, newNode) {
newNode.parent = this;
var oldIndex = this.index(oldNode);
this.nodes.splice(oldIndex + 1, 0, newNode);
newNode.parent = this;
var index = void 0;
for (var id in this.indexes) {
index = this.indexes[id];
if (oldIndex <= index) {
this.indexes[id] = index + this.nodes.length;
this.indexes[id] = index + 1;
}
}
@@ -116,20 +119,71 @@ var Container = function (_Node) {
};
Container.prototype.insertBefore = function insertBefore(oldNode, newNode) {
newNode.parent = this;
var oldIndex = this.index(oldNode);
this.nodes.splice(oldIndex, 0, newNode);
newNode.parent = this;
var index = void 0;
for (var id in this.indexes) {
index = this.indexes[id];
if (oldIndex <= index) {
this.indexes[id] = index + this.nodes.length;
if (index <= oldIndex) {
this.indexes[id] = index + 1;
}
}
return this;
};
Container.prototype._findChildAtPosition = function _findChildAtPosition(line, col) {
var found = undefined;
this.each(function (node) {
if (node.atPosition) {
var foundChild = node.atPosition(line, col);
if (foundChild) {
found = foundChild;
return false;
}
} else if (node.isAtPosition(line, col)) {
found = node;
return false;
}
});
return found;
};
/**
* Return the most specific node at the line and column number given.
* The source location is based on the original parsed location, locations aren't
* updated as selector nodes are mutated.
*
* Note that this location is relative to the location of the first character
* of the selector, and not the location of the selector in the overall document
* when used in conjunction with postcss.
*
* If not found, returns undefined.
* @param {number} line The line number of the node to find. (1-based index)
* @param {number} col The column number of the node to find. (1-based index)
*/
Container.prototype.atPosition = function atPosition(line, col) {
if (this.isAtPosition(line, col)) {
return this._findChildAtPosition(line, col) || this;
} else {
return undefined;
}
};
Container.prototype._inferEndPosition = function _inferEndPosition() {
if (this.last && this.last.source && this.last.source.end) {
this.source = this.source || {};
this.source.end = this.source.end || {};
Object.assign(this.source.end, this.last.source.end);
}
};
Container.prototype.each = function each(callback) {
if (!this.lastEach) {
this.lastEach = 0;

View File

@@ -2,9 +2,9 @@
exports.__esModule = true;
var _namespace = require('./namespace');
var _node = require('./node');
var _namespace2 = _interopRequireDefault(_namespace);
var _node2 = _interopRequireDefault(_node);
var _types = require('./types');
@@ -16,24 +16,24 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var ID = function (_Namespace) {
_inherits(ID, _Namespace);
var ID = function (_Node) {
_inherits(ID, _Node);
function ID(opts) {
_classCallCheck(this, ID);
var _this = _possibleConstructorReturn(this, _Namespace.call(this, opts));
var _this = _possibleConstructorReturn(this, _Node.call(this, opts));
_this.type = _types.ID;
return _this;
}
ID.prototype.toString = function toString() {
return [this.spaces.before, this.ns, String('#' + this.value), this.spaces.after].join('');
return [this.rawSpaceBefore, String('#' + this.stringifyProperty("value")), this.rawSpaceAfter].join('');
};
return ID;
}(_namespace2.default);
}(_node2.default);
exports.default = ID;
module.exports = exports['default'];

View File

@@ -4,6 +4,12 @@ exports.__esModule = true;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _cssesc = require('cssesc');
var _cssesc2 = _interopRequireDefault(_cssesc);
var _util = require('../util');
var _node = require('./node');
var _node2 = _interopRequireDefault(_node);
@@ -25,15 +31,62 @@ var Namespace = function (_Node) {
return _possibleConstructorReturn(this, _Node.apply(this, arguments));
}
Namespace.prototype.qualifiedName = function qualifiedName(value) {
if (this.namespace) {
return this.namespaceString + '|' + value;
} else {
return value;
}
};
Namespace.prototype.toString = function toString() {
return [this.spaces.before, this.ns, String(this.value), this.spaces.after].join('');
return [this.rawSpaceBefore, this.qualifiedName(this.stringifyProperty("value")), this.rawSpaceAfter].join('');
};
_createClass(Namespace, [{
key: 'namespace',
get: function get() {
return this._namespace;
},
set: function set(namespace) {
if (namespace === true || namespace === "*" || namespace === "&") {
this._namespace = namespace;
if (this.raws) {
delete this.raws.namespace;
}
return;
}
var escaped = (0, _cssesc2.default)(namespace, { isIdentifier: true });
this._namespace = namespace;
if (escaped !== namespace) {
(0, _util.ensureObject)(this, "raws");
this.raws.namespace = escaped;
} else if (this.raws) {
delete this.raws.namespace;
}
}
}, {
key: 'ns',
get: function get() {
var n = this.namespace;
return n ? (typeof n === 'string' ? n : '') + '|' : '';
return this._namespace;
},
set: function set(namespace) {
this.namespace = namespace;
}
}, {
key: 'namespaceString',
get: function get() {
if (this.namespace) {
var ns = this.stringifyProperty("namespace");
if (ns === true) {
return '';
} else {
return ns;
}
} else {
return '';
}
}
}]);

View File

@@ -2,12 +2,16 @@
exports.__esModule = true;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _util = require('../util');
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var cloneNode = function cloneNode(obj, parent) {
if ((typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) !== 'object') {
if ((typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) !== 'object' || obj === null) {
return obj;
}
@@ -36,26 +40,19 @@ var cloneNode = function cloneNode(obj, parent) {
return cloned;
};
var _class = function () {
function _class() {
var Node = function () {
function Node() {
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, _class);
_classCallCheck(this, Node);
for (var key in opts) {
this[key] = opts[key];
}
var _opts$spaces = opts.spaces;
_opts$spaces = _opts$spaces === undefined ? {} : _opts$spaces;
var _opts$spaces$before = _opts$spaces.before,
before = _opts$spaces$before === undefined ? '' : _opts$spaces$before,
_opts$spaces$after = _opts$spaces.after,
after = _opts$spaces$after === undefined ? '' : _opts$spaces$after;
this.spaces = { before: before, after: after };
Object.assign(this, opts);
this.spaces = this.spaces || {};
this.spaces.before = this.spaces.before || '';
this.spaces.after = this.spaces.after || '';
}
_class.prototype.remove = function remove() {
Node.prototype.remove = function remove() {
if (this.parent) {
this.parent.removeChild(this);
}
@@ -63,7 +60,7 @@ var _class = function () {
return this;
};
_class.prototype.replaceWith = function replaceWith() {
Node.prototype.replaceWith = function replaceWith() {
if (this.parent) {
for (var index in arguments) {
this.parent.insertBefore(this, arguments[index]);
@@ -73,15 +70,15 @@ var _class = function () {
return this;
};
_class.prototype.next = function next() {
Node.prototype.next = function next() {
return this.parent.at(this.parent.index(this) + 1);
};
_class.prototype.prev = function prev() {
Node.prototype.prev = function prev() {
return this.parent.at(this.parent.index(this) - 1);
};
_class.prototype.clone = function clone() {
Node.prototype.clone = function clone() {
var overrides = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var cloned = cloneNode(this);
@@ -91,12 +88,129 @@ var _class = function () {
return cloned;
};
_class.prototype.toString = function toString() {
return [this.spaces.before, String(this.value), this.spaces.after].join('');
/**
* Some non-standard syntax doesn't follow normal escaping rules for css.
* This allows non standard syntax to be appended to an existing property
* by specifying the escaped value. By specifying the escaped value,
* illegal characters are allowed to be directly inserted into css output.
* @param {string} name the property to set
* @param {any} value the unescaped value of the property
* @param {string} valueEscaped optional. the escaped value of the property.
*/
Node.prototype.appendToPropertyAndEscape = function appendToPropertyAndEscape(name, value, valueEscaped) {
if (!this.raws) {
this.raws = {};
}
var originalValue = this[name];
var originalEscaped = this.raws[name];
this[name] = originalValue + value; // this may trigger a setter that updates raws, so it has to be set first.
if (originalEscaped || valueEscaped !== value) {
this.raws[name] = (originalEscaped || originalValue) + valueEscaped;
} else {
delete this.raws[name]; // delete any escaped value that was created by the setter.
}
};
return _class;
/**
* Some non-standard syntax doesn't follow normal escaping rules for css.
* This allows the escaped value to be specified directly, allowing illegal
* characters to be directly inserted into css output.
* @param {string} name the property to set
* @param {any} value the unescaped value of the property
* @param {string} valueEscaped the escaped value of the property.
*/
Node.prototype.setPropertyAndEscape = function setPropertyAndEscape(name, value, valueEscaped) {
if (!this.raws) {
this.raws = {};
}
this[name] = value; // this may trigger a setter that updates raws, so it has to be set first.
this.raws[name] = valueEscaped;
};
/**
* When you want a value to passed through to CSS directly. This method
* deletes the corresponding raw value causing the stringifier to fallback
* to the unescaped value.
* @param {string} name the property to set.
* @param {any} value The value that is both escaped and unescaped.
*/
Node.prototype.setPropertyWithoutEscape = function setPropertyWithoutEscape(name, value) {
this[name] = value; // this may trigger a setter that updates raws, so it has to be set first.
if (this.raws) {
delete this.raws[name];
}
};
/**
*
* @param {number} line The number (starting with 1)
* @param {number} column The column number (starting with 1)
*/
Node.prototype.isAtPosition = function isAtPosition(line, column) {
if (this.source && this.source.start && this.source.end) {
if (this.source.start.line > line) {
return false;
}
if (this.source.end.line < line) {
return false;
}
if (this.source.start.line === line && this.source.start.column > column) {
return false;
}
if (this.source.end.line === line && this.source.end.column < column) {
return false;
}
return true;
}
return undefined;
};
Node.prototype.stringifyProperty = function stringifyProperty(name) {
return this.raws && this.raws[name] || this[name];
};
Node.prototype.toString = function toString() {
return [this.rawSpaceBefore, String(this.stringifyProperty("value")), this.rawSpaceAfter].join('');
};
_createClass(Node, [{
key: 'rawSpaceBefore',
get: function get() {
var rawSpace = this.raws && this.raws.spaces && this.raws.spaces.before;
if (rawSpace === undefined) {
rawSpace = this.spaces && this.spaces.before;
}
return rawSpace || "";
},
set: function set(raw) {
(0, _util.ensureObject)(this, "raws", "spaces");
this.raws.spaces.before = raw;
}
}, {
key: 'rawSpaceAfter',
get: function get() {
var rawSpace = this.raws && this.raws.spaces && this.raws.spaces.after;
if (rawSpace === undefined) {
rawSpace = this.spaces.after;
}
return rawSpace || "";
},
set: function set(raw) {
(0, _util.ensureObject)(this, "raws", "spaces");
this.raws.spaces.after = raw;
}
}]);
return Node;
}();
exports.default = _class;
exports.default = Node;
module.exports = exports['default'];

View File

@@ -30,7 +30,7 @@ var Pseudo = function (_Container) {
Pseudo.prototype.toString = function toString() {
var params = this.length ? '(' + this.map(String).join(',') + ')' : '';
return [this.spaces.before, String(this.value), params, this.spaces.after].join('');
return [this.rawSpaceBefore, this.stringifyProperty("value"), params, this.rawSpaceAfter].join('');
};
return Pseudo;

View File

@@ -2,6 +2,8 @@
exports.__esModule = true;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _container = require('./container');
var _container2 = _interopRequireDefault(_container);
@@ -30,12 +32,27 @@ var Root = function (_Container) {
Root.prototype.toString = function toString() {
var str = this.reduce(function (memo, selector) {
var sel = String(selector);
return sel ? memo + sel + ',' : '';
}, '').slice(0, -1);
memo.push(String(selector));
return memo;
}, []).join(',');
return this.trailingComma ? str + ',' : str;
};
Root.prototype.error = function error(message, options) {
if (this._error) {
return this._error(message, options);
} else {
return new Error(message);
}
};
_createClass(Root, [{
key: 'errorGenerator',
set: function set(handler) {
this._error = handler;
}
}]);
return Root;
}(_container2.default);

View File

@@ -1,144 +1,194 @@
'use strict';
exports.__esModule = true;
exports.FIELDS = undefined;
var _unescapable, _wordDelimiters;
exports.default = tokenize;
var singleQuote = 39,
doubleQuote = 34,
backslash = 92,
slash = 47,
newline = 10,
space = 32,
feed = 12,
tab = 9,
cr = 13,
plus = 43,
gt = 62,
tilde = 126,
pipe = 124,
comma = 44,
openBracket = 40,
closeBracket = 41,
openSq = 91,
closeSq = 93,
semicolon = 59,
asterisk = 42,
colon = 58,
ampersand = 38,
at = 64,
atEnd = /[ \n\t\r\{\(\)'"\\;/]/g,
wordEnd = /[ \n\t\r\(\)\*:;@!&'"\+\|~>,\[\]\\]|\/(?=\*)/g;
var _tokenTypes = require('./tokenTypes');
var t = _interopRequireWildcard(_tokenTypes);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
var unescapable = (_unescapable = {}, _unescapable[t.tab] = true, _unescapable[t.newline] = true, _unescapable[t.cr] = true, _unescapable[t.feed] = true, _unescapable);
var wordDelimiters = (_wordDelimiters = {}, _wordDelimiters[t.space] = true, _wordDelimiters[t.tab] = true, _wordDelimiters[t.newline] = true, _wordDelimiters[t.cr] = true, _wordDelimiters[t.feed] = true, _wordDelimiters[t.ampersand] = true, _wordDelimiters[t.asterisk] = true, _wordDelimiters[t.bang] = true, _wordDelimiters[t.comma] = true, _wordDelimiters[t.colon] = true, _wordDelimiters[t.semicolon] = true, _wordDelimiters[t.openParenthesis] = true, _wordDelimiters[t.closeParenthesis] = true, _wordDelimiters[t.openSquare] = true, _wordDelimiters[t.closeSquare] = true, _wordDelimiters[t.singleQuote] = true, _wordDelimiters[t.doubleQuote] = true, _wordDelimiters[t.plus] = true, _wordDelimiters[t.pipe] = true, _wordDelimiters[t.tilde] = true, _wordDelimiters[t.greaterThan] = true, _wordDelimiters[t.equals] = true, _wordDelimiters[t.dollar] = true, _wordDelimiters[t.caret] = true, _wordDelimiters[t.slash] = true, _wordDelimiters);
var hex = {};
var hexChars = "0123456789abcdefABCDEF";
for (var i = 0; i < hexChars.length; i++) {
hex[hexChars.charCodeAt(i)] = true;
}
/**
* Returns the last index of the bar css word
* @param {string} css The string in which the word begins
* @param {number} start The index into the string where word's first letter occurs
*/
function consumeWord(css, start) {
var next = start;
var code = void 0;
do {
code = css.charCodeAt(next);
if (wordDelimiters[code]) {
return next - 1;
} else if (code === t.backslash) {
next = consumeEscape(css, next) + 1;
} else {
// All other characters are part of the word
next++;
}
} while (next < css.length);
return next - 1;
}
/**
* Returns the last index of the escape sequence
* @param {string} css The string in which the sequence begins
* @param {number} start The index into the string where escape character (`\`) occurs.
*/
function consumeEscape(css, start) {
var next = start;
var code = css.charCodeAt(next + 1);
if (unescapable[code]) {
// just consume the escape char
} else if (hex[code]) {
var hexDigits = 0;
// consume up to 6 hex chars
do {
next++;
hexDigits++;
code = css.charCodeAt(next + 1);
} while (hex[code] && hexDigits < 6);
// if fewer than 6 hex chars, a trailing space ends the escape
if (hexDigits < 6 && code === t.space) {
next++;
}
} else {
// the next char is part of the current word
next++;
}
return next;
}
var FIELDS = exports.FIELDS = {
TYPE: 0,
START_LINE: 1,
START_COL: 2,
END_LINE: 3,
END_COL: 4,
START_POS: 5,
END_POS: 6
};
function tokenize(input) {
var tokens = [];
var css = input.css.valueOf();
var _css = css,
length = _css.length;
var code = void 0,
next = void 0,
quote = void 0,
lines = void 0,
last = void 0,
content = void 0,
escape = void 0,
nextLine = void 0,
nextOffset = void 0,
escaped = void 0,
escapePos = void 0;
var length = css.length;
var offset = -1;
var line = 1;
var pos = 0;
var start = 0;
var end = 0;
var unclosed = function unclosed(what, end) {
var code = void 0,
content = void 0,
endColumn = void 0,
endLine = void 0,
escaped = void 0,
escapePos = void 0,
last = void 0,
lines = void 0,
next = void 0,
nextLine = void 0,
nextOffset = void 0,
quote = void 0,
tokenType = void 0;
function unclosed(what, fix) {
if (input.safe) {
css += end;
// fyi: this is never set to true.
css += fix;
next = css.length - 1;
} else {
throw input.error('Unclosed ' + what, line, pos - offset, pos);
throw input.error('Unclosed ' + what, line, start - offset, start);
}
};
}
while (pos < length) {
code = css.charCodeAt(pos);
while (start < length) {
code = css.charCodeAt(start);
if (code === newline) {
offset = pos;
if (code === t.newline) {
offset = start;
line += 1;
}
switch (code) {
case newline:
case space:
case tab:
case cr:
case feed:
next = pos;
case t.space:
case t.tab:
case t.newline:
case t.cr:
case t.feed:
next = start;
do {
next += 1;
code = css.charCodeAt(next);
if (code === newline) {
if (code === t.newline) {
offset = next;
line += 1;
}
} while (code === space || code === newline || code === tab || code === cr || code === feed);
} while (code === t.space || code === t.newline || code === t.tab || code === t.cr || code === t.feed);
tokens.push(['space', css.slice(pos, next), line, pos - offset, pos]);
pos = next - 1;
tokenType = t.space;
endLine = line;
endColumn = next - offset - 1;
end = next;
break;
case plus:
case gt:
case tilde:
case pipe:
next = pos;
case t.plus:
case t.greaterThan:
case t.tilde:
case t.pipe:
next = start;
do {
next += 1;
code = css.charCodeAt(next);
} while (code === plus || code === gt || code === tilde || code === pipe);
tokens.push(['combinator', css.slice(pos, next), line, pos - offset, pos]);
pos = next - 1;
} while (code === t.plus || code === t.greaterThan || code === t.tilde || code === t.pipe);
tokenType = t.combinator;
endLine = line;
endColumn = start - offset;
end = next;
break;
case asterisk:
tokens.push(['*', '*', line, pos - offset, pos]);
// Consume these characters as single tokens.
case t.asterisk:
case t.ampersand:
case t.bang:
case t.comma:
case t.equals:
case t.dollar:
case t.caret:
case t.openSquare:
case t.closeSquare:
case t.colon:
case t.semicolon:
case t.openParenthesis:
case t.closeParenthesis:
next = start;
tokenType = code;
endLine = line;
endColumn = start - offset;
end = next + 1;
break;
case ampersand:
tokens.push(['&', '&', line, pos - offset, pos]);
break;
case comma:
tokens.push([',', ',', line, pos - offset, pos]);
break;
case openSq:
tokens.push(['[', '[', line, pos - offset, pos]);
break;
case closeSq:
tokens.push([']', ']', line, pos - offset, pos]);
break;
case colon:
tokens.push([':', ':', line, pos - offset, pos]);
break;
case semicolon:
tokens.push([';', ';', line, pos - offset, pos]);
break;
case openBracket:
tokens.push(['(', '(', line, pos - offset, pos]);
break;
case closeBracket:
tokens.push([')', ')', line, pos - offset, pos]);
break;
case singleQuote:
case doubleQuote:
quote = code === singleQuote ? "'" : '"';
next = pos;
case t.singleQuote:
case t.doubleQuote:
quote = code === t.singleQuote ? "'" : '"';
next = start;
do {
escaped = false;
next = css.indexOf(quote, next + 1);
@@ -146,51 +196,26 @@ function tokenize(input) {
unclosed('quote', quote);
}
escapePos = next;
while (css.charCodeAt(escapePos - 1) === backslash) {
while (css.charCodeAt(escapePos - 1) === t.backslash) {
escapePos -= 1;
escaped = !escaped;
}
} while (escaped);
tokens.push(['string', css.slice(pos, next + 1), line, pos - offset, line, next - offset, pos]);
pos = next;
break;
case at:
atEnd.lastIndex = pos + 1;
atEnd.test(css);
if (atEnd.lastIndex === 0) {
next = css.length - 1;
} else {
next = atEnd.lastIndex - 2;
}
tokens.push(['at-word', css.slice(pos, next + 1), line, pos - offset, line, next - offset, pos]);
pos = next;
break;
case backslash:
next = pos;
escape = true;
while (css.charCodeAt(next + 1) === backslash) {
next += 1;
escape = !escape;
}
code = css.charCodeAt(next + 1);
if (escape && code !== slash && code !== space && code !== newline && code !== tab && code !== cr && code !== feed) {
next += 1;
}
tokens.push(['word', css.slice(pos, next + 1), line, pos - offset, line, next - offset, pos]);
pos = next;
tokenType = t.str;
endLine = line;
endColumn = start - offset;
end = next + 1;
break;
default:
if (code === slash && css.charCodeAt(pos + 1) === asterisk) {
next = css.indexOf('*/', pos + 2) + 1;
if (code === t.slash && css.charCodeAt(start + 1) === t.asterisk) {
next = css.indexOf('*/', start + 2) + 1;
if (next === 0) {
unclosed('comment', '*/');
}
content = css.slice(pos, next + 1);
content = css.slice(start, next + 1);
lines = content.split('\n');
last = lines.length - 1;
@@ -202,30 +227,45 @@ function tokenize(input) {
nextOffset = offset;
}
tokens.push(['comment', content, line, pos - offset, nextLine, next - nextOffset, pos]);
offset = nextOffset;
tokenType = t.comment;
line = nextLine;
pos = next;
endLine = nextLine;
endColumn = next - nextOffset;
} else if (code === t.slash) {
next = start;
tokenType = code;
endLine = line;
endColumn = start - offset;
end = next + 1;
} else {
wordEnd.lastIndex = pos + 1;
wordEnd.test(css);
if (wordEnd.lastIndex === 0) {
next = css.length - 1;
} else {
next = wordEnd.lastIndex - 2;
}
tokens.push(['word', css.slice(pos, next + 1), line, pos - offset, line, next - offset, pos]);
pos = next;
next = consumeWord(css, start);
tokenType = t.word;
endLine = line;
endColumn = next - offset;
}
end = next + 1;
break;
}
pos++;
// Ensure that the token structure remains consistent
tokens.push([tokenType, // [0] Token type
line, // [1] Starting line
start - offset, // [2] Starting column
endLine, // [3] Ending line
endColumn, // [4] Ending column
start, // [5] Start position / Source index
end] // [6] End position
);
// Reset offset for the next token
if (nextOffset) {
offset = nextOffset;
nextOffset = null;
}
start = end;
}
return tokens;
}
module.exports = exports['default'];
}

View File

@@ -1,34 +1,28 @@
{
"_from": "postcss-selector-parser@^2.2.2",
"_id": "postcss-selector-parser@2.2.3",
"_from": "postcss-selector-parser@^5.0.0-rc.4",
"_id": "postcss-selector-parser@5.0.0",
"_inBundle": false,
"_integrity": "sha1-+UN3iGBsPJrO4W/+jYsWKX8nu5A=",
"_integrity": "sha512-w+zLE5Jhg6Liz8+rQOWEAwtwkyqpfnmsinXjXg6cY7YIONZZtgvE0v2O0uhQBs0peNomOJwWRKt6JBfTdTd3OQ==",
"_location": "/postcss-selector-parser",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "postcss-selector-parser@^2.2.2",
"raw": "postcss-selector-parser@^5.0.0-rc.4",
"name": "postcss-selector-parser",
"escapedName": "postcss-selector-parser",
"rawSpec": "^2.2.2",
"rawSpec": "^5.0.0-rc.4",
"saveSpec": null,
"fetchSpec": "^2.2.2"
"fetchSpec": "^5.0.0-rc.4"
},
"_requiredBy": [
"/postcss-merge-rules",
"/postcss-minify-selectors",
"/vue-loader"
"/@vue/component-compiler-utils",
"/postcss-calc"
],
"_resolved": "https://registry.npmjs.org/postcss-selector-parser/-/postcss-selector-parser-2.2.3.tgz",
"_shasum": "f9437788606c3c9acee16ffe8d8b16297f27bb90",
"_spec": "postcss-selector-parser@^2.2.2",
"_where": "C:\\xampp\\htdocs\\w4rpservices\\node_modules\\postcss-merge-rules",
"author": {
"name": "Ben Briggs",
"email": "beneb.info@gmail.com",
"url": "http://beneb.info"
},
"_resolved": "https://registry.npmjs.org/postcss-selector-parser/-/postcss-selector-parser-5.0.0.tgz",
"_shasum": "249044356697b33b64f1a8f7c80922dddee7195c",
"_spec": "postcss-selector-parser@^5.0.0-rc.4",
"_where": "C:\\xampp\\htdocs\\w4rpservices\\node_modules\\postcss-calc",
"ava": {
"require": "babel-register",
"concurrency": 5
@@ -37,41 +31,56 @@
"url": "https://github.com/postcss/postcss-selector-parser/issues"
},
"bundleDependencies": false,
"contributors": [
{
"name": "Ben Briggs",
"email": "beneb.info@gmail.com",
"url": "http://beneb.info"
},
{
"name": "Chris Eppstein",
"email": "chris@eppsteins.net",
"url": "http://twitter.com/chriseppstein"
}
],
"dependencies": {
"flatten": "^1.0.2",
"cssesc": "^2.0.0",
"indexes-of": "^1.0.1",
"uniq": "^1.0.1"
},
"deprecated": false,
"description": "> Selector parser with built in methods for working with selector strings.",
"devDependencies": {
"ava": "^0.17.0",
"babel-cli": "^6.4.0",
"babel-core": "^6.4.0",
"ava": "^0.25.0",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-eslint": "^8.2.3",
"babel-plugin-add-module-exports": "^0.2.0",
"babel-plugin-precompile-charcodes": "^1.0.0",
"babel-preset-es2015": "^6.3.13",
"babel-plugin-precompile-charcodes": "^1.1.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-es2015-loose": "^7.0.0",
"babel-preset-stage-0": "^6.3.13",
"babel-register": "^6.9.0",
"coveralls": "^2.11.6",
"del-cli": "^0.2.0",
"eslint": "^3.0.0",
"eslint-config-cssnano": "^3.0.0",
"babel-preset-stage-0": "^6.24.1",
"babel-register": "^6.26.0",
"coveralls": "^3.0.2",
"del-cli": "^1.1.0",
"eslint": "^4.19.1",
"eslint-plugin-babel": "^3.3.0",
"eslint-plugin-import": "^1.10.2",
"glob": "^7.0.3",
"eslint-plugin-import": "^2.14.0",
"glob": "^7.1.3",
"minimist": "^1.2.0",
"nyc": "^10.0.0"
"nyc": "^11.7.3",
"postcss": "^7.0.7",
"semver": "^5.6.0"
},
"eslintConfig": {
"extends": "cssnano"
"engines": {
"node": ">=4"
},
"files": [
"API.md",
"CHANGELOG.md",
"LICENSE-MIT",
"dist"
"dist",
"postcss-selector-parser.d.ts"
],
"homepage": "https://github.com/postcss/postcss-selector-parser",
"license": "MIT",
@@ -88,11 +97,13 @@
"url": "git+https://github.com/postcss/postcss-selector-parser.git"
},
"scripts": {
"prepublish": "del-cli dist && BABEL_ENV=publish babel src --out-dir dist --ignore /__tests__/",
"lintfix": "eslint --fix src",
"prepare": "del-cli dist && BABEL_ENV=publish babel src --out-dir dist --ignore /__tests__/",
"pretest": "eslint src",
"report": "nyc report --reporter=html",
"test": "nyc ava src/__tests__/*.js",
"test-012": "nyc ava src/__tests__/*.js"
"testone": "ava"
},
"version": "2.2.3"
"types": "postcss-selector-parser.d.ts",
"version": "5.0.0"
}