added all files to project

This commit is contained in:
2022-03-10 10:36:59 +01:00
parent 09dd957b33
commit 46a936d7de
25351 changed files with 3883356 additions and 0 deletions
+459
View File
@@ -0,0 +1,459 @@
# Changelog
#### Legend:
:japanese_ogre: — be afraid of this change because it breaks the way things
worked before.
:star: — some new thing has been added.
:green_apple: — some bad thing has been fixed.
## 30.03.2020, version 4.3.0
:star: Added support for interpolation of custom properties in Sass.
:green_apple: Updated minimist version to 1.2.5.
:green_apple: Updated playground link to https.
## 22.03.2019, version 4.2.4
:star: Renamed `prepublish` script to `prepublishOnly`.
:star: Updated link to playground.
:green_apple: Fixed badges.
:green_apple: Fixed `content` guard in `node.contains()`.
## 28.09.2017, version 4.2.3
:green_apple: Fixed parsing of empty `url()` in Sass and SCSS.
## 30.08.2017, version 4.2.2
:green_apple: Fixed parsing of `/deep/` in CSS, LESS, Sass and SCSS.
## 29.08.2017, version 4.2.1
:green_apple: Fixed parsing of `pseudo-element` in CSS, LESS, Sass and SCSS.
## 29.08.2017, version 4.2.0
:star: Add support for custom property syntax in CSS, Sass and SCSS.
:star: Add support for deep combinator syntax in CSS, LESS, Sass and SCSS.
:star: Add support for alternative descendant `>>` syntax in CSS, LESS, Sass and SCSS.
:star: Add support for `::slotted()` syntax in CSS, LESS, Sass and SCSS.
:green_apple: Fixed parsing of non-lowercase keyframes at-rule in CSS, LESS, Sass and SCSS.
:green_apple: Fixed parsing of multiline selectors within keyframes in Sass.
:green_apple: Fixed parsing of `!important` within maps in Sass and SCSS.
:green_apple: Fixed parsing of `...` following a function in Sass and SCSS.
## 23.08.2017, version 4.1.1
:star: Unified codebase style across syntaxes.
:green_apple: Fixed parsing of URLs in Sass and SCSS.
:green_apple: Fixed parsing of placeholders in Sass and SCSS.
:green_apple: Fixed parsing of interpolated values within type selectors in Sass and SCSS.
:green_apple: Fixed parsing of spacing within pseudo class arguments in all syntaxes.
:green_apple: Fixed parsing of parent selectors within parentheses in Sass and SCSS.
:star: Abstracted attribute tests for CSS, LESS, Sass and SCSS.
:green_apple: Fixed parsing of pseudo classes within keyframes in Sass and SCSS.
:green_apple: Fixed parsing of dimensions in LESS.
## 20.11.2016, version 4.0.3
:green_apple: Fixed parsing of interpolations inside URI nodes in SCSS and Sass.
## 18.11.2016, version 4.0.2
:green_apple: Fixed parsing of trailing newlines.
## 18.11.2016, version 4.0.1
:japanese_ogre: Removed `postinstall` script.
## 17.11.2016, version 4.0.0
:japanese_ogre: Dropped support for Node < 4.
:japanese_ogre: Brought back `postinstall` script that should allow installing
from GitHub.
:japanese_ogre: Made multiline comments in Sass consistent with other syntaxes
by removing closing `*/` from node's content.
:japanese_ogre: Implemented new node type, `universalSelector`, which represents
`*`. See [docs](https://github.com/tonyganch/gonzales-pe/blob/dev/docs/node-types.md#universalselector)
for more details.
:green_apple: Fixed parsing of comments in Sass.
:green_apple: Fixed parsing of keyframes inside includes in Sass.
:green_apple: Fixed parsing of flags in arguments in Sass and SCSS.
:green_apple: Fixed parsing of multiple declarations within arguments in SCSS
and Sass.
:green_apple: Improved parsing of interpolations in SCSS and Sass.
:green_apple: Adjust parsing priority of declarations & atrule in Less.
## 22.10.2016, version 3.4.7
:green_apple: Included forgotten test for #226.
:green_apple: Fixed issue when `!important` was not parsed as function argument.
## 22.10.2016, version 3.4.6
:green_apple: Changed parsing of `ident` nodes which fixed issue with asterisks
being parsed as idents instead of operators.
:green_apple: Fixed capitalisation in Changelog.
## 20.10.2016, version 3.4.5
:green_apple: Change parser to strip DOS newlines from comments.
:star: Add links to README.md.
## 12.08.2016, version 3.4.4
:green_apple: Fixed parsing of numbers following interpolation in class
selectors in Sass and SCSS.
## 08.08.2016, version 3.4.3
:green_apple: Fixed parsing of unicode ranges.
## 04.08.2016, version 3.4.2
:green_apple: Disable Google Closure Compiler due to some errors in parsing.
## 27.07.2016, version 3.4.1
:star: Added publich script.
:green_apple: Fixed post-refactor error in Node#last method.
## 27.07.2016, version 3.4.0
:star: Added `unicode-range` and `urange` node types in CSS, Less, Sass and SCSS.
:green_apple: Fixed parsing of trailing interpolation in compound selector in Sass and SCSS.
:green_apple: Fix parsing of hyphens after interpolation with parentSelectors in Sass and SCSS.
:green_apple: Added ESLint and moved linters to a separate script.
:green_apple: Fixed incorrect dimension wrap of unicode-ranges in CSS, Sass and SCSS.
:green_apple: Fixed parsing of hyphens in interpolated idents in Sass and SCSS.
:green_apple: Added compilation of JS using Google Closure.
## 01.07.2016, version 3.3.6
:green_apple: Fixed parsing of nth selector without numbers before `n`.
## 21.06.2016, version 3.3.5
:green_apple: Fixed issue with content at-rule and keyframes in Sass and SCSS.
:green_apple: Fixed namespace attribute selector in CSS, Sass and SCSS.
:green_apple: Fixed issue with modulo operator in values in Sass.
:green_apple: Fixed usage of @content with keyframes in Sass and SCSS.
:green_apple: Fixed namespace attribute selector issue in CSS, Sass and SCSS.
:green_apple: Fixed parsing of interpolations in pseudo-classes in Sass and SCSS.
:green_apple: Fixed interpolated percentage keyframe selector issue in Sass and SCSS.
:green_apple: Updated Travis config to not include environment variables.
## 18.05.2016, version 3.3.4
:green_apple: Fixed mistake from `@3.3.2` version when parent selector was
"correctly" parsed as property instead of value.
## 18.05.2016, version 3.3.3
:green_apple: Fixed prepublish script to build lib.
## 18.05.2016, version 3.3.2
:star: Added AppVeyor badge.
:green_apple: Fixed build file to glue multiple syntaxes into one file.
:green_apple: Fixed parsing of functions inside urls in Sass.
:green_apple: Fixed parsing of mulitple keyframe selectors in CSS, Sass and SCSS.
:green_apple: Fixed parsing of parent selector as property in Sass and SCSS.
:green_apple: Fixed parsing of parent selector inside interpolations in Sass and SCSS.
## 29.04.2016, version 3.3.1
:star: Added config for AppVeyor to run automated tests on Windows.
:green_apple: Fix installation for Windows.
## 28.04.2016, version 3.3.0
:star: Added browser support. `build.sh` now build a script that can be used in
browsers.
## 28.04.2016, version 3.2.7
:green_apple: Fixed typos and example in documentation.
:green_apple: Fixed parsing of functions inside urls in SCSS.
:green_apple: Fixed parsing of selectors starting with combinators in Sass, SCSS
and Less.
:green_apple: Fixed incorrect CRLF line numbers.
:green_apple: Fixed parsing of extends that sometimes were incorrectly parsed
as atrules.
## 07.02.2016, version 3.2.6
:green_apple: Fixed the issue with installation of the package with npm@3.
## 07.02.2016, version 3.2.5
:green_apple: Fixed parsing of nested multiline selectors group.
## 07.02.2016, version 3.2.4
:star: Added support for `!global` in Sass.
## 07.02.2016, version 3.2.3
:star: Modified `npm test` to remove `.DS_Store` files before running tests.
:star: Updated Travis config to use Node@5.0.
:star: Updated Travis config to include compiler info.
:star: Made it possible to build files if module is installed from github.
:green_apple: Fixed parsing of interpolation content in Sass and SCSS.
:green_apple: Fixed parsing of interpolation as part of parent selector
extension in Sass and SCSS.
:green_apple: Fixed issue with keyframeSelector in includes in SCSS.
## 17.01.2016, version 3.2.2
:green_apple: Made `ParsingError#message` property writeable.
## 19.10.2015, version 3.2.1
#### Parsing rules
:green_apple: Fixed the issue when selectors inside extends were not wrapped in
`selector` nodes in Sass and SCSS.
:green_apple: Fixed parsing of multiple selectors in extends in Sass and SCSS.
## 19.10.2015, version 3.2.0
#### Node types
:star: Added new node type: `parentSelectorExtension`.
#### Parsing rules
:green_apple: Fixed parsing of parent selectors with extensions, like
`&__element` or `&--modifier`.
## 19.10.2015, version 3.1.1
#### Parsing rules
:green_apple: Fixed parsing of selectors starting or ending with a combinator
in Less, Sass and SCSS.
## 18.10.2015, version 3.1.0
#### CLI
:green_apple: Fixed passing a `--context` argument.
:green_apple: Fixed printing of a simplified tree.
#### Node types
:star: Added new node type: `keyframesSelector`.
#### Parsing rules
:green_apple: Fixed parsing of keyframes in all syntaxes.
## 18.10.2015, version 3.0.3
#### Parsing rules
:green_apple: Fixed parsing of spaces inside interpolations in Sass and SCSS.
## 18.10.2015, version 3.0.2
#### Parsing rules
:green_apple: Fixed the issue when operators were parsed as idents inside
parentheses in Sass and SCSS.
## 18.10.2015, version 3.0.1
#### Parsing rules
:green_apple: Fixed parsing of parent selectors in SCSS and Less.
:green_apple: Fixed parsing of placeholders inside selectors in SCSS.
## 18.10.2015, version 3.0.0
#### CLI
:japanese_ogre: Made cli process stdin only if `-` argument is passed.
:star: Added help message.
#### API
:japanese_ogre: Renamed `parseTree.remove` to `parseTree.removeChild()`.
:japanese_ogre: Unwraped callback parameters for `traverse...` methods.
:japanese_ogre: Made `first()`, `last()` and `get()` methods return `null` if no child nodes were found.
:japanese_ogre: Made `node.length` return a number of child nodes.
:japanese_ogre: Renamed `rule` to `context`.
:star: Made `parseTree.removeChild()` return a removed node.
:star: Added `traverseBy...` methods to all nodes, not only root ones.
:star: Added support for specifying a tab size in spaces.
#### Parsing rules
:green_apple: Fixed parsing of single-line comments after `url` token.
:green_apple: Fixed parsing of interpolations inside id selectors in Less.
:green_apple: Fixed parsing of selectors according to spec.
:green_apple: Fixed parsing of placeholders as selectors in SCSS.
#### Misc
:star: Added Travis badge to Readme page.
:star: Added init script to build sources.
:star: Added commit message template.
## 05.10.2015, version 3.0.0-beta
#### CLI
:star: Added `--simple` flag for printing a simplified tree structure.
:green_apple: CLI now prints parse tree to stdout.
#### API
:japanese_ogre: Parse tree is now represented as objects, not arrays.
:japanese_ogre: Renamed `gonzales.srcToAST()` to `gonzales.parse()`.
See [Readme](README.md#gonzalesparsecss-options).
:japanese_ogre: Renamed `gonzales.astToSrc()` to `parseTree.toString()`.
See [Readme](README.md#parsetreetostring).
:japanese_ogre: Renamed `gonzales.astToString()` to `parseTree.toJson()`.
See [Readme](README.md#parsetreetojson).
:star: Added information about column number to nodes.
:star: Added information about end position to nodes.
:green_apple: Made empty strings to be parsed as empty nodes.
#### Node types
:japanese_ogre: In Sass renamed `interpolatedVariable` to `interpolation`.
:japanese_ogre: Separated `include` and `extend` nodes.
:japanese_ogre: Replaced `filter` with `declaration`.
:japanese_ogre: Replaced `braces` with `brackets` and `parentheses`.
:japanese_ogre: Replaced `atrulers` with `block`.
:japanese_ogre: Renamed `nthSelector` to `pseudoClass`.
:japanese_ogre: Renamed `atrules`, `atruler` and `atruleb` to `atrule`.
:japanese_ogre: Renamed `functionBody` to `arguments`.
:japanese_ogre: Renamed `functionExpression` to `expression`.
:japanese_ogre: Renamed `attrib` to `attributeSelector`.
:japanese_ogre: Renamed `attrselector` to `attributeMatch`.
:japanese_ogre: Renamed `commentSL` to `singlelineComment`.
:japanese_ogre: Renamed `commentML` to `multilineComment`.
:japanese_ogre: Renamed `declDelim` to `declarationDelimiter`.
:japanese_ogre: Renamed `delim` to `delimiter`.
:japanese_ogre: Renamed `propertyDelim` to `propertyDelimiter`.
:japanese_ogre: Renamed `pseudoc` to `pseudoClass`.
:japanese_ogre: Renamed `pseudoe` to `pseudoElement`.
:japanese_ogre: Renamed `s` to `space`.
:japanese_ogre: Renamed `shash` to `color`.
:japanese_ogre: Renamed `vhash` to `id`.
:japanese_ogre: Removed `atrulerq`, `unary` and `unknown`.
:star: Added `attributeFlags`.
:star: Added `attributeName`.
:star: Added `attributeValue`.
:star: Added `conditionalStatement`.
:star: Added `namePrefix`.
:star: Added `namespacePrefix`.
:star: Added `namespaceSeparator`.
:star: Added `typeSelector`.
#### Parsing rules
:japanese_ogre: Spaces that separate two nodes are now put between those
nodes in parse tree.
:star: Added support for `extend` nodes in Less.
:star: Added support for equality and inequality signs in Sass and SCSS.
:star: Added support for `/deep/` combinator.
:star: Added support for `!optional` and `!global` in Sass and SCSS.
:green_apple: Fixed parsing of interpolations in Sass and SCSS.
:green_apple: Fixed parsing of arguments in Sass, SCSS and Less.
:green_apple: Fixed parsing of declaration delimiters in Sass.
:green_apple: Fixed the issue when pseudo-classes were parsed like declarations.
:green_apple: Fixed parsing of selectors on multiple lines in Sass.
:green_apple: Fixed parsing of percent sign as operator in SCSS.
:green_apple: Fixed parsing of pseudo-elements as selectors in Sass.
#### Misc
:star: Added Babel to build source files.
:star: Used mocha for tests.
:star: Added helper scripts.
:star: Added Travis config.
:rocket: Improved tests structure.
:rocket: Separated log and test scripts.
:rocket: Improved error messages.
:rocket: Removed benchmark tests.
:rocket: Moved source files from `lib` to `src` directory.
:rocket: Made package availbale for install from GitHub.
## 29.12.2013, version 2.0.2
- Sass includes can have both arguments list and content block,
i.e. `@include nani() { color: tomato }` is valid syntax.
## 18.11.2013, version 2.0.1
- Bring back lost whitespaces and comments
## 11.11.2013, version 2.0.0
- Support preprocessors: Sass (both SCSS and indented syntax), LESS.
- New node types:
- `arguments` (less and sass only)
- `commentML`
- `commentSL` (less and sass only)
- `condition` (sass only)
- `default` (sass only)
- `escapedString` (less only)
- `include` (less and sass only)
- `loop` (sass only)
- `mixin` (less and sass only)
- `parentselector` (less and sass only)
- `placeholder` (sass only)
- `propertyDelim`
- `variable` (less and sass only)
- `varialeList` (less and sass only)
- Rename methods:
- `srcToCSSP` -> `cssToAST`
- `csspToSrc` -> `astToCSS`
- `csspToTree` -> `astToTree`
- Pass all arguments as one object:
- `gonzales.cssToAST({css: a, syntax: b, rule: c, needInfo: d})`
- `gonzales.astToCSS({ast: ast, syntax: syntax})`
- Remove built files from VCS
- Move test command from `make` to `npm`
- Build files before running tests
- Divide tests into groups according to syntax
- Add script to test one specific css string
- Add token's index number to info object
## 11.02.2013, version 1.0.7
- Identifiers like `_0` are identifiers now.
- Throw error instead of console.error: https://github.com/css/csso/issues/109
## 25.11.2012, version 1.0.6
- Typo fix (global variable leak): https://github.com/css/csso/pull/110
- Attribute selectors extended by `|`.
- `not(..)` pseudo-class special support: https://github.com/css/csso/issues/111
## 28.10.2012, version 1.0.5
- Better error line numbering: https://github.com/css/gonzales/issues/2
## 11.10.2012, version 1.0.4
- CSSO issue (@page inside @media error): https://github.com/css/csso/issues/90
## 10.10.2012, version 1.0.3
- Both .t-1 and .t-01 should be idents: https://github.com/css/gonzales/issues/1
## 08.10.2012, version 1.0.2
- CSSO issue (filter + important breaks csso v1.3.1): https://github.com/css/csso/issues/87
## 08.10.2012, version 1.0.1
- CSSO issue ("filter" IE property breaks CSSO v1.3.0): https://github.com/css/csso/issues/86
## 03.10.2012, version 1.0.0
- First revision.
+19
View File
@@ -0,0 +1,19 @@
Copyright (C) 2012 by Sergey Kryzhanovsky
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
+808
View File
@@ -0,0 +1,808 @@
# Gonzales PE @dev
[![NPM version][npm-img]][npm]
[![Build Status][travis-img]][travis]
[![AppVeyor Build Status][appveyor-img]][appveyor]
[npm-img]: https://img.shields.io/npm/v/gonzales-pe.svg
[npm]: https://www.npmjs.com/package/gonzales-pe
[travis-img]: https://travis-ci.org/tonyganch/gonzales-pe.svg
[travis]: https://travis-ci.org/tonyganch/gonzales-pe
[appveyor-img]: https://ci.appveyor.com/api/projects/status/m29jphtrqt398v2o/branch/dev?svg=true
[appveyor]: https://ci.appveyor.com/project/tonyganch/gonzales-pe/branch/dev
Gonzales PE is a CSS parser which plays nicely with preprocessors.
Currently those are supported: SCSS, Sass, LESS.
Try out Gonzales PE online: [Gonzales PE Playground](https://tonyganch.io/gonzales-pe/).
## Install
(1) To install command-line tool globally:
```bash
npm install -g git://github.com/tonyganch/gonzales-pe.git#dev
```
(2) To install parser as a project dependency:
```bash
npm install --save git://github.com/tonyganch/gonzales-pe.git#dev
```
(3) If for some reason you want to build files yourself:
```bash
# Clone the repo.
git clone git@github.com:tonyganch/gonzales-pe.git
# Go to dev branch.
git checkout dev
# Install project dependencies.
npm install
# Install git hooks and build files.
npm run init
```
## API
Basically there are a few things you can do:
1. parse css string and get a parse tree in return;
2. modify tree nodes;
3. remove tree nodes;
4. add new nodes to the tree;
5. convert modified tree back to a string.
The different type of tree nodes can be found in [docs/node-types.md](https://github.com/tonyganch/gonzales-pe/blob/dev/docs/node-types.md).
In examples below I assume that `gonzales` is a parser module and `parseTree`
is some parsed css:
```js
let gonzales = require('gonzales-pe');
let parseTree = gonzales.parse(css);
```
### gonzales.createNode(options)
##### Description
Creates a new node. Useful when you need to add something to a tree.
##### Parameters
<table>
<tr>
<td><i>{Object}</i></td>
<td>options</td>
<td>Options to pass to a `Node` constructor.</td>
</tr>
<tr>
</table>
##### Returns
<table>
<tr>
<td><i>{Object}</i></td>
<td>A new node.</td>
</tr>
</table>
##### Examples
```js
let css = 'a {color: tomato}';
let parseTree = gonzales.parse(css);
let node = gonzales.createNode({ type: 'animal', content: 'panda' });
parseTree.content.push(node);
```
### gonzales.parse(css[, options])
##### Description
Parses a css string.
##### Parameters
<table>
<tr>
<td><i>{string}</i></td>
<td>css</td>
<td>A string to parse.</td>
</tr>
<tr>
<td><i>{Object=}</i></td>
<td>options</td>
<td>Optional. Additional options:
<ul>
<li>
<code>{string} syntax</code> — any of the following: <code>css</code>,
<code>less</code>, <code>sass</code>, <code>scss</code>.
Default one is <code>css</code>.
</li>
<li>
<code>{string} context</code> — root node's type. For a list of available
values see <a href="docs/node-types.md">"Node types"</a>. Default
one is <code>stylesheet</code>.
</li>
<li>
<code>{number} tabSize</code> — size of a tab character in spaces.
Default one is 1.
</li>
</ul>
</td>
</tr>
</table>
##### Returns
<table>
<tr>
<td><i>{Object}</i></td>
<td>Parse tree.</td>
</tr>
</table>
##### Examples
```js
let css = 'a {color: tomato}';
let parseTree = gonzales.parse(css);
```
```js
let less = 'a {$color: tomato}';
let parseTree = gonzales.parse(less, {syntax: 'less'});
```
```js
let less = '$color: tomato';
let parseTree = gonzales.parse(less, {syntax: 'less', rule: 'declaration'});
```
### parseTree.contains(type)
##### Description
Checks whether there is a child node of given type.
##### Parameters
<table>
<tr>
<td><i>{string}</i></td>
<td>type</td>
<td>
Node type we're looking for. For a list of available values see
<a href="docs/node-types.md">"Node types"</a>.
</td>
</tr>
</table>
##### Returns
<table>
<tr>
<td><i>{boolean}</i></td>
<td>
<code>true</code> if a tree contains a child node of a given type,
<code>false</code> otherwise.
</td>
</tr>
</table>
##### Examples
```js
if (parseTree.contains('space')) {
doSomething();
}
```
### parseTree.content
##### Returns
<table>
<tr>
<td><i>{string|Array}</i></td>
<td>Node's content (child nodes or a string).</td>
</tr>
</table>
### parseTree.eachFor([type, ]callback)
##### Description
Calls a function for every child node in tree. If `type` parameter is passed,
calls a function only for child nodes of a given type. The main difference from
`parseTree.forEach()` is that this method loops through node list from the end
to beginning.
##### Parameters
<table>
<tr>
<td><i>{string=}</i></td>
<td>type</td>
<td>
Optional. A node type by which to filter child nodes before applying
a callback function. For a list of available values see
<a href="docs/node-types.md">"Node types"</a>.
</td>
</tr>
<tr>
<td><i>{Function}</i></td>
<td>callback</td>
<td>
Function to call for every child node. Accepts following parameters:
<ul>
<li><code>{Object}</code> — a child node;</li>
<li><code>{number}</code> — index of the child node in node list;</li>
<li>
<code>{Object}</code> — parent node (equals to <code>parseTree</code>).
</li>
</ul>
</td>
</tr>
</table>
##### Examples
```js
parseTree.eachFor(function(childNode) {
doSomething(childNode);
});
```
```js
// Remove all child spaces.
parseTree.eachFor('space', function(spaceNode, i) {
parseTree.removeChild(i);
});
```
### parseTree.end
##### Returns
<table>
<tr>
<td><i>{Object}</i></td>
<td>
End position of the node. Contains following info:
<ul>
<li>
<code>{number} line</code> — last symbol's line number
(1-based index);
</li>
<li>
<code>{number} column</code> — last symbol's column number
(1-based index).
</li>
</ul>
</td>
</tr>
</table>
### parseTree.first([type])
##### Description
Gets the first child node. If `type` parameter is passed, gets the first child
node of a given type. If no node has been found, returns `null`.
##### Parameters
<table>
<tr>
<td><i>{string=}</i></td>
<td>type</td>
<td>
Optional. Node type to look for. For a list of available values see
<a href="docs/node-types.md">"Node types"</a>.
</td>
</tr>
</table>
##### Returns
<table>
<tr>
<td><i>{?Object}</i></td>
<td>A node.</td>
</tr>
</table>
##### Examples
```js
let node = parseTree.first();
node.content = 'panda';
```
```js
let node = parseTree.first('multilineComment');
node.content = 'panda';
```
### parseTree.forEach([type, ]callback)
##### Description
Calls a function for every child node in tree. If `type` parameter is passed,
calls a function only for child nodes of a given type. The main difference from
`parseTree.eachFor()` is that this method loops through node list from the
beginnig to end.
##### Parameters
<table>
<tr>
<td><i>{string=}</i></td>
<td>type</td>
<td>
Optional. A node type by which to filter child nodes before applying
a callback function. For a list of available values see
<a href="docs/node-types.md">"Node types"</a>.
</td>
</tr>
<tr>
<td><i>{Function}</i></td>
<td>callback</td>
<td>
Function to call for every child node. Accepts following parameters:
<ul>
<li><code>{Object}</code> — a child node;</li>
<li><code>{number}</code> — index of the child node in node list;</li>
<li>
<code>{Object}</code> — parent node (equals to <code>parseTree</code>).
</li>
</ul>
</td>
</tr>
</table>
##### Examples
```js
parseTree.forEach(function(childNode) {
doSomething();
});
```
```js
parseTree.forEach('space', function(spaceNode) {
doSomething();
});
```
### parseTree.get(index)
##### Description
Gets *nth* child of the `parseTree`. If no node has been found, returns `null`.
##### Parameters
<table>
<tr>
<td><i>{number}</i></td>
<td>index</td>
<td>Index number of node which we're looking for.</td>
</tr>
</table>
##### Returns
<table>
<tr>
<td><i>{?Object}</i></td>
<td>A node.</td>
</tr>
</table>
##### Examples
```js
var node = parseTree.get(2);
doSomething(node);
```
### parseTree.insert(index, node)
##### Description
Inserts a node to a given position in `parseTree`.
##### Parameters
<table>
<tr>
<td><i>{number}</i></td>
<td>index</td>
<td>Index of position where to insert the node.</td>
</tr>
<tr>
<td><i>{Object}</i></td>
<td>node</td>
<td>A node to insert.</td>
</tr>
</table>
##### Examples
```js
let node = gonzales.createNode({type: 'animal', content: 'panda'});
parseTree.insert(2, node);
```
### parseTree.is(type)
##### Description
Checks whether the node is of given type.
##### Parameters
<table>
<tr>
<td><i>{string}</i></td>
<td>type</td>
<td>
A node type against which to check type of <code>parseTree</code>.
For a list of available values see
<a href="docs/node-types.md">"Node types"</a>.
</td>
</tr>
</table>
##### Returns
<table>
<tr>
<td><i>{boolean}</i></td>
<td>
<code>true</code> if types are equal, <code>false</code> otherwise.
</td>
</tr>
</table>
##### Examples
```js
if (node.is('space')) {
node.content = '';
}
```
### parseTree.last(type)
Gets the last child node. If `type` parameter is passed, gets the last child
node of a given type. If no node has been found, returns `null`.
##### Parameters
<table>
<tr>
<td><i>{string=}</i></td>
<td>type</td>
<td>
Optional. Node type to look for. For a list of available values see
<a href="docs/node-types.md">"Node types"</a>.
</td>
</tr>
</table>
##### Returns
<table>
<tr>
<td><i>{?Object}</i></td>
<td>A node.</td>
</tr>
</table>
##### Examples
```js
let node = parseTree.last();
node.content = 'panda';
```
```js
let node = parseTree.last('multilineComment');
node.content = 'panda';
```
### parseTree.length
##### Returns
<table>
<tr>
<td><i>{number}</i></td>
<td>Number of child nodes.</td>
</tr>
</table>
### parseTree.removeChild(index)
##### Description
Removes a child node at a given position.
##### Parameters
<table>
<tr>
<td><i>{number}</i></td>
<td>index</td>
<td>Index of a child node we need to remove.</td>
</tr>
</table>
##### Returns
<table>
<tr>
<td><i>{Object}</i></td>
<td>Removed node.</td>
</tr>
</table>
##### Examples
```js
// Swap nodes.
var node = parseTree.removeChild(1);
parseTree.insert(0, node);
```
### parseTree.start
##### Returns
<table>
<tr>
<td><i>{Object}</i></td>
<td>
Start position of the node. Contains following info:
<ul>
<li>
<code>{number} line</code> — first symbol's line number
(1-based index);
</li>
<li>
<code>{number} column</code> — first symbol's column number
(1-based index).
</li>
</ul>
</td>
</tr>
</table>
### parseTree.syntax
##### Returns
<table>
<tr>
<td><i>{string}</i></td>
<td>Syntax of original parsed string.</td>
</tr>
</table>
### parseTree.toJson()
##### Description
Converts parse tree to JSON. Useful for printing.
##### Returns
<table>
<tr>
<td><i>{Object}</i></td>
<td>Parse tree in JSON</td>
</tr>
</table>
### parseTree.toString()
##### Description
Converts parse tree back to string according to original syntax.
##### Returns
<table>
<tr>
<td><i>{string}</i></td>
<td>A compiled string.</td>
</tr>
</table>
##### Examples
```js
let css = parseTree.toString();
```
### parseTree.traverse(callback)
##### Description
Calls the function for every node in a tree including `parseTree` itself.
##### Parameters
<table>
<tr>
<td><i>{Function}</i></td>
<td>callback</td>
<td>
Function to apply to every node. Accepts following parameters:
<ul>
<li><code>{Object}</code> — a node to which we apply callback;</li>
<li><code>{number}</code> — node's index number inside its parent;</li>
<li><code>{Object}</code> — a node's parent;</li>
<li>
<code>{number}</code> — node's nesting level relative to its parent.
</li>
</ul>
</td>
</tr>
</table>
##### Examples
```js
parseTree.traverse(function(node, index, parent) {
if (node.is('multilineComment')) {
parent.removeChild(index);
} else if (node.is('space')) {
node.content = ' ';
}
});
```
### parseTree.traverseByType(type, callback)
##### Description
This method should be called for a root node, because calling it for a child
will be more time consuming.
Calls the function for every node of a given type. This means not just child
nodes, but grandchilds and so on.
##### Parameters
<table>
<tr>
<td><i>{string}</i></td>
<td>type</td>
<td>
Node type. For a list of available values please see
<a href="docs/node-types.md">"Node types"</a>.
</td>
</tr>
<tr>
<td><i>{Function}</i></td>
<td>callback</td>
<td>
Function to apply to every node of a given type.
Accepts following parameters:
<ul>
<li><code>{Object}</code> — a node to which we apply callback;</li>
<li><code>{number}</code> — node's index number inside its parent;</li>
<li><code>{Object}</code> — a node's parent.</li>
</ul>
</td>
</tr>
</table>
##### Examples
```js
// Remove all comments.
parseTree.traverseByType('multilineComment', function(node, index, parent) {
parent.removeChild(index);
});
```
### parseTree.traverseByTypes(types, callback)
##### Description
This method should be called for a root node, because calling it for a child
will be more time consuming.
Calls the function for every node of given types. This means not just child
nodes, but grandchilds and so on.
##### Parameters
<table>
<tr>
<td><i>{Array.string}</i></td>
<td>types</td>
<td>
List of node types. For a list of available values please see
<a href="docs/node-types.md">"Node types"</a>.
</td>
</tr>
<tr>
<td><i>{Function}</i></td>
<td>callback</td>
<td>
Function to apply to every node of given types.
Accepts following parameters:
<ul>
<li><code>{Object}</code> — a node to which we apply callback;</li>
<li><code>{number}</code> — node's index number inside its parent;</li>
<li><code>{Object}</code> — a node's parent.</li>
</ul>
</td>
</tr>
</table>
##### Examples
```js
// Remove all comments and spaces.
let types = ['multilineComment', 'space'];
parseTree.traverseByTypes(types, function(node, index, parent) {
parent.removeChild(index);
});
```
### parseTree.type
##### Returns
<table>
<tr>
<td><i>{string}</i></td>
<td>
Node type. For a list of available values see
<a href="docs/node-types.md">"Node types"</a>.
</td>
</tr>
</table>
## Test
To run tests:
npm test
This command will build library files from sources and run tests on all files
in syntax directories.
Every test has 3 files: source stylesheet, expected parse tree and expected
string compiled back from parse tree to css.
If some tests fail, you can find information in test logs:
- `log/test.log` contains all information from stdout;
- `log/expected.txt` contains only expected text;
- `log/result.txt` contains only result text.
The last two are made for your convenience: you can use any diff app to see
the defference between them.
If you want to test one specific string or get a general idea of how Gonzales
works, you can use `test/ast.js` file.
Simply change the first two strings (`css` and `syntax` vars) and run:
node test/single-test.js
## Report
If you find a bug or want to add a feature, welcome to [Issues](https://github.com/tonyganch/gonzales-pe/issues).
If you are shy but have a question, feel free to [drop me a
line](mailto:tonyganch+gonzales@gmail.com).
+116
View File
@@ -0,0 +1,116 @@
#!/usr/bin/env node
'use strict';
var parseArgs = require('minimist');
var gonzales = require('..');
var fs = require('fs');
var path = require('path');
var options = getOptions();
if (options.help) {
displayHelp();
process.exit(0);
}
if (isSTDIN()) {
processSTDIN();
} else {
processFile(options._[0]);
}
function getOptions() {
var parserOptions = {
boolean: ['silent', 'simple'],
alias: {
help: 'h',
syntax: 's',
context: 'c'
}
};
return parseArgs(process.argv.slice(2), parserOptions);
}
function isSTDIN() {
return options._.indexOf('-') !== -1;
}
function processSTDIN() {
var input = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', data => {
input += data;
});
process.stdin.on('end', () => {
processInputData(input);
});
}
function processFile(file) {
if (!file) process.exit(0);
if (!options.syntax) options.syntax = path.extname(file).substring(1);
var css = fs.readFileSync(file, 'utf-8').trim();
processInputData(css);
}
function processInputData(input) {
try {
var ast = gonzales.parse(input, {
syntax: options.syntax,
context: options.context
});
printTree(ast);
process.exit(0);
} catch (e) {
if (!options.silent) process.stderr.write(e.toString());
process.exit(1);
}
}
function printTree(ast) {
if (!options.simple) {
var tree = ast.toJson();
process.stdout.write(tree);
} else {
var lastLevel;
ast.traverse(function(node, i, parent, lastLevel) {
var type = node.type;
var spaces = new Array(lastLevel).join(' |');
if (typeof node.content === 'string') {
var content = JSON.stringify(node.content);
console.log(spaces, '->', type);
console.log(spaces, ' ', content);
} else {
console.log(spaces, '->', type);
}
});
var spaces = new Array(lastLevel).join(' -');
console.log(spaces);
}
}
function displayHelp() {
var help = [
'NAME',
' gonzlaes-pe — Parse a css file and print its parse tree in JSON',
'',
'SYNOPSIS',
' gonzales-pe [options] file.js',
' cat file.js | gonzales-pe [options] -',
'',
'OPTIONS',
' -s, --syntax',
' Syntax name: css, less, sass or scss.',
' -c, --context',
' Context of code part. See docs on node types for more info.',
' --simple',
' Print a simplified parse tree structure instead of JSON.',
' --silent',
' Don\'t print any error messages.'
];
console.log(help.join('\n'));
}
+22435
View File
File diff suppressed because it is too large Load Diff
+87
View File
@@ -0,0 +1,87 @@
{
"_args": [
[
"gonzales-pe@4.3.0",
"/home/pi/Desktop/smartMirrorTestEnvironment/MagicMirror"
]
],
"_development": true,
"_from": "gonzales-pe@4.3.0",
"_id": "gonzales-pe@4.3.0",
"_inBundle": false,
"_integrity": "sha512-otgSPpUmdWJ43VXyiNgEYE4luzHCL2pz4wQ0OnDluC6Eg4Ko3Vexy/SrSynglw/eR+OhkzmqFCZa/OFa/RgAOQ==",
"_location": "/gonzales-pe",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "gonzales-pe@4.3.0",
"name": "gonzales-pe",
"escapedName": "gonzales-pe",
"rawSpec": "4.3.0",
"saveSpec": null,
"fetchSpec": "4.3.0"
},
"_requiredBy": [
"/postcss-sass"
],
"_resolved": "https://registry.npmjs.org/gonzales-pe/-/gonzales-pe-4.3.0.tgz",
"_spec": "4.3.0",
"_where": "/home/pi/Desktop/smartMirrorTestEnvironment/MagicMirror",
"author": {
"name": "Tony Ganch",
"email": "tonyganch+github@gmail.com",
"url": "http://tonyganch.com"
},
"bin": {
"gonzales": "./bin/gonzales.js"
},
"bugs": {
"url": "http://github.com/tonyganch/gonzales-pe/issues"
},
"dependencies": {
"minimist": "^1.2.5"
},
"description": "Gonzales Preprocessor Edition (fast CSS parser)",
"devDependencies": {
"babel-core": "^6.18.2",
"babel-loader": "^6.2.7",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-preset-es2015": "^6.18.0",
"coffee-script": "~1.7.1",
"eslint": "^3.0.0",
"jscs": "2.1.0",
"jshint": "2.10.2",
"json-loader": "^0.5.3",
"mocha": "2.2.x",
"webpack": "^1.12.2",
"webpack-closure-compiler": "^2.0.2"
},
"engines": {
"node": ">=0.6.0"
},
"files": [
"MIT-LICENSE.txt",
"bin/gonzales.js",
"lib/gonzales.js"
],
"homepage": "http://github.com/tonyganch/gonzales-pe",
"license": "MIT",
"main": "./lib/gonzales",
"name": "gonzales-pe",
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/tonyganch/gonzales-pe.git"
},
"scripts": {
"autofix-tests": "bash ./scripts/build.sh && bash ./scripts/autofix-tests.sh",
"build": "bash ./scripts/build.sh",
"init": "bash ./scripts/init.sh",
"lint": "bash ./scripts/lint.sh",
"log": "bash ./scripts/log.sh",
"prepublishOnly": "bash ./scripts/build.sh",
"test": "bash ./scripts/test.sh",
"watch": "bash ./scripts/watch.sh"
},
"version": "4.3.0"
}