postcss 6.0.18 → 6.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of postcss might be problematic. Click here for more details.
- package/CHANGELOG.md +13 -0
- package/CONTRIBUTING.md +78 -0
- package/{README.cn.md → README-cn.md} +14 -12
- package/README.md +16 -15
- package/docs/architecture.md +156 -0
- package/lib/at-rule.js +1 -1
- package/lib/comment.js +1 -1
- package/lib/container.js +1 -1
- package/lib/css-syntax-error.js +1 -1
- package/lib/declaration.js +1 -1
- package/lib/input.js +7 -1
- package/lib/lazy-result.js +2 -2
- package/lib/map-generator.js +1 -1
- package/lib/node.js +3 -1
- package/lib/parse.js +1 -1
- package/lib/parser.js +1 -1
- package/lib/postcss.d.ts +20 -24
- package/lib/postcss.js +1 -1
- package/lib/previous-map.js +1 -1
- package/lib/processor.js +2 -2
- package/lib/result.js +1 -1
- package/lib/root.js +1 -1
- package/lib/rule.js +1 -1
- package/lib/stringify.js +1 -1
- package/lib/terminal-highlight.js +1 -1
- package/package.json +4 -14
package/CHANGELOG.md
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
# Change Log
|
2
2
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
3
3
|
|
4
|
+
## 6.0.22
|
5
|
+
* Fix `Node#prev` and `Node#next` on missed parent.
|
6
|
+
|
7
|
+
## 6.0.21
|
8
|
+
* Rename Chinese docs to fix `yarnpkg.com` issue.
|
9
|
+
|
10
|
+
## 6.0.20
|
11
|
+
* Better error message on `null` as input CSS.
|
12
|
+
|
13
|
+
## 6.0.19
|
14
|
+
* Fix TypeScript definitions for source maps (by Oleh Kuchuk).
|
15
|
+
* Fix `source` field in TypeScript definitions (by Sylvain Pollet-Villard).
|
16
|
+
|
4
17
|
## 6.0.18
|
5
18
|
* Use primitive object in TypeScript definitions (by Sylvain Pollet-Villard).
|
6
19
|
|
package/CONTRIBUTING.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# Contributing Guide to PostCSS
|
2
|
+
|
3
|
+
If you want contribute to PostCSS, there are few things that you should
|
4
|
+
be familiar with.
|
5
|
+
|
6
|
+
|
7
|
+
## In Case You Have Question About Using PostCSS
|
8
|
+
|
9
|
+
* **Ask for help in [the chat]**
|
10
|
+
|
11
|
+
If you stuck on something there is a big chance
|
12
|
+
that someone had similar problem before.
|
13
|
+
|
14
|
+
[the chat]: https://gitter.im/postcss/postcss
|
15
|
+
|
16
|
+
|
17
|
+
## Adding Your Plugin to the List
|
18
|
+
|
19
|
+
If you created or found a plugin and want to add it to PostCSS plugins list
|
20
|
+
follow this simple steps.
|
21
|
+
|
22
|
+
PR should not change plugins defined in README it contains only favorite plugins
|
23
|
+
and moderated by PostCSS author.
|
24
|
+
|
25
|
+
Plugins submitted by community located in [`docs/plugins`].
|
26
|
+
|
27
|
+
* **Keep plugins order**
|
28
|
+
|
29
|
+
Be sure that plugin not presented yet and find suitable position
|
30
|
+
in alphabetic order for it.
|
31
|
+
But plugins with `postcss-` prefix should come first.
|
32
|
+
|
33
|
+
* **Check spelling**
|
34
|
+
|
35
|
+
Before submitting PR be sure that spelling check pass.
|
36
|
+
For that run command `npm test`.
|
37
|
+
If it fails with unknown word error, add it as word
|
38
|
+
to `.yaspellerrc` dictionary.
|
39
|
+
|
40
|
+
* **Check PostCSS plugin guideline**
|
41
|
+
|
42
|
+
Provided plugin should match plugin [guidelines].
|
43
|
+
|
44
|
+
- **Provide link to suggested plugin**
|
45
|
+
|
46
|
+
Make sure your pull request description contains link to plugin
|
47
|
+
you are willing to add.
|
48
|
+
|
49
|
+
[`docs/plugins`]: https://github.com/postcss/postcss/blob/master/docs/plugins.md
|
50
|
+
[guidelines]: https://github.com/postcss/postcss/blob/master/docs/guidelines/plugin.md
|
51
|
+
|
52
|
+
|
53
|
+
## TypeScript Declaration Improvements
|
54
|
+
|
55
|
+
If you found a bug or want to add certain improvements to types declaration file
|
56
|
+
|
57
|
+
* **Check current TypeScript styling**
|
58
|
+
|
59
|
+
Be sure that your changes match TypeScript styling rules defined in typings file.
|
60
|
+
* We use classes for existing JS classes like `Stringifier`.
|
61
|
+
* Namespaces used for separating functions related to same subject.
|
62
|
+
* Interfaces used for defining custom types.
|
63
|
+
|
64
|
+
Make sure you read through declaration file writing [best practices]
|
65
|
+
by TypeScript team.
|
66
|
+
|
67
|
+
[best practices]: https://www.typescriptlang.org/docs/handbook/declaration-files/do-s-and-don-ts.html
|
68
|
+
|
69
|
+
|
70
|
+
## Core Development
|
71
|
+
|
72
|
+
If you want to add new feature or fix existed issue
|
73
|
+
|
74
|
+
- **Become familiar with PostCSS architecture**
|
75
|
+
|
76
|
+
For gentle intro to PostCSS architecture look through our [guide].
|
77
|
+
|
78
|
+
[guide]: https://github.com/postcss/postcss/blob/master/docs/architecture.md
|
@@ -1,15 +1,11 @@
|
|
1
|
-
# PostCSS [![
|
1
|
+
# PostCSS [![Gitter][chat-img]][chat]
|
2
2
|
|
3
3
|
<img align="right" width="95" height="95"
|
4
4
|
alt="哲学家的石头 - PostCSS 的 logo"
|
5
5
|
src="http://postcss.github.io/postcss/logo.svg">
|
6
6
|
|
7
|
-
[
|
8
|
-
[
|
9
|
-
[chat-img]: https://img.shields.io/badge/Gitter-Join_the_PostCSS_chat-brightgreen.svg
|
10
|
-
[appveyor]: https://ci.appveyor.com/project/ai/postcss
|
11
|
-
[travis]: https://travis-ci.org/postcss/postcss
|
12
|
-
[chat]: https://gitter.im/postcss/postcss
|
7
|
+
[chat-img]: https://img.shields.io/badge/Gitter-Join_the_PostCSS_chat-brightgreen.svg
|
8
|
+
[chat]: https://gitter.im/postcss/postcss
|
13
9
|
|
14
10
|
PostCSS 是一个允许使用 JS 插件转换样式的工具。
|
15
11
|
这些插件可以检查(lint)你的 CSS,支持 CSS Variables 和 Mixins,
|
@@ -18,8 +14,8 @@ PostCSS 是一个允许使用 JS 插件转换样式的工具。
|
|
18
14
|
PostCSS 在工业界被广泛地应用,其中不乏很多有名的行业领导者,如:维基百科,Twitter,阿里巴巴,
|
19
15
|
JetBrains。PostCSS 的 [Autoprefixer] 插件是最流行的 CSS 处理工具之一。
|
20
16
|
|
21
|
-
**Twitter 账号:** [@postcss](https://twitter.com/postcss)
|
22
|
-
**支持 / 讨论:** [Gitter](https://gitter.im/postcss/postcss)
|
17
|
+
**Twitter 账号:** [@postcss](https://twitter.com/postcss)<br>
|
18
|
+
**支持 / 讨论:** [Gitter](https://gitter.im/postcss/postcss)<br>
|
23
19
|
|
24
20
|
如果需要 PostCSS 商业支持(如咨询,提升公司的前端文化,
|
25
21
|
PostCSS 插件),请联系 [Evil Martians](https://evilmartians.com/?utm_source=postcss)
|
@@ -53,7 +49,7 @@ PostCSS 插件),请联系 [Evil Martians](https://evilmartians.com/?utm_sou
|
|
53
49
|
### 提前使用先进的 CSS 特性
|
54
50
|
|
55
51
|
* [`autoprefixer`] 添加了 vendor 浏览器前缀,它使用 Can I Use 上面的数据。
|
56
|
-
* [`postcss-
|
52
|
+
* [`postcss-preset-env`] 允许你使用未来的 CSS 特性。
|
57
53
|
* [`postcss-image-set-polyfill`] 为所有浏览器模拟了 [`image-set`] 函数逻辑。
|
58
54
|
|
59
55
|
### 更佳的 CSS 可读性
|
@@ -87,6 +83,7 @@ PostCSS 插件),请联系 [Evil Martians](https://evilmartians.com/?utm_sou
|
|
87
83
|
|
88
84
|
[`postcss-image-set-polyfill`]: https://github.com/SuperOl3g/postcss-image-set-polyfill
|
89
85
|
[`postcss-inline-svg`]: https://github.com/TrySound/postcss-inline-svg
|
86
|
+
[`postcss-preset-env`]: https://github.com/jonathantneal/postcss-preset-env
|
90
87
|
[`react-css-modules`]: https://github.com/gajus/react-css-modules
|
91
88
|
[`postcss-autoreset`]: https://github.com/maximkoretskiy/postcss-autoreset
|
92
89
|
[`postcss-write-svg`]: https://github.com/jonathantneal/postcss-write-svg
|
@@ -95,7 +92,6 @@ PostCSS 插件),请联系 [Evil Martians](https://evilmartians.com/?utm_sou
|
|
95
92
|
[`postcss-sprites`]: https://github.com/2createStudio/postcss-sprites
|
96
93
|
[`postcss-modules`]: https://github.com/outpunk/postcss-modules
|
97
94
|
[`postcss-sorting`]: https://github.com/hudochenkov/postcss-sorting
|
98
|
-
[`postcss-cssnext`]: http://cssnext.io
|
99
95
|
[`postcss-assets`]: https://github.com/assetsjs/postcss-assets
|
100
96
|
[开发 PostCSS 插件]: https://github.com/postcss/postcss/blob/master/docs/writing-a-plugin.md
|
101
97
|
[`font-magician`]: https://github.com/jonathantneal/postcss-font-magician
|
@@ -121,7 +117,10 @@ PostCSS 可以转化样式到任意语法,不仅仅是 CSS。
|
|
121
117
|
如果还没有支持你最喜欢的语法,你可以编写一个解释器以及(或者)一个 stringifier 来拓展 PostCSS。
|
122
118
|
|
123
119
|
* [`sugarss`] 是一个以缩进为基础的语法,类似于 Sass 和 Stylus。
|
124
|
-
* [`postcss-
|
120
|
+
* [`postcss-syntax`] 通过文件扩展名自动切换语法。
|
121
|
+
* [`postcss-html`] 解析类 HTML 文件里`<style>`标签中的样式。
|
122
|
+
* [`postcss-markdown`] 解析 Markdown 文件里代码块中的样式。
|
123
|
+
* [`postcss-styled`] 解析源文件里模板字面量中的CSS。
|
125
124
|
* [`postcss-scss`] 允许你使用 SCSS *(但并没有将 SCSS 编译到 CSS)*。
|
126
125
|
* [`postcss-sass`] 允许你使用 Sass *(但并没有将 Sass 编译到 CSS)*。
|
127
126
|
* [`postcss-less`] 允许你使用 Less *(但并没有将 LESS 编译到 CSS)*。
|
@@ -132,7 +131,10 @@ PostCSS 可以转化样式到任意语法,不仅仅是 CSS。
|
|
132
131
|
|
133
132
|
[`postcss-less-engine`]: https://github.com/Crunch/postcss-less
|
134
133
|
[`postcss-safe-parser`]: https://github.com/postcss/postcss-safe-parser
|
134
|
+
[`postcss-syntax`]: https://github.com/gucong3000/postcss-syntax
|
135
135
|
[`postcss-html`]: https://github.com/gucong3000/postcss-html
|
136
|
+
[`postcss-markdown`]: https://github.com/gucong3000/postcss-markdown
|
137
|
+
[`postcss-styled`]: https://github.com/gucong3000/postcss-styled
|
136
138
|
[`postcss-scss`]: https://github.com/postcss/postcss-scss
|
137
139
|
[`postcss-sass`]: https://github.com/AleshaOleg/postcss-sass
|
138
140
|
[`postcss-less`]: https://github.com/webschik/postcss-less
|
package/README.md
CHANGED
@@ -1,15 +1,11 @@
|
|
1
|
-
# PostCSS [![
|
1
|
+
# PostCSS [![Gitter][chat-img]][chat]
|
2
2
|
|
3
3
|
<img align="right" width="95" height="95"
|
4
4
|
alt="Philosopher’s stone, logo of PostCSS"
|
5
5
|
src="http://postcss.github.io/postcss/logo.svg">
|
6
6
|
|
7
|
-
[
|
8
|
-
[
|
9
|
-
[chat-img]: https://img.shields.io/badge/Gitter-Join_the_PostCSS_chat-brightgreen.svg
|
10
|
-
[appveyor]: https://ci.appveyor.com/project/ai/postcss
|
11
|
-
[travis]: https://travis-ci.org/postcss/postcss
|
12
|
-
[chat]: https://gitter.im/postcss/postcss
|
7
|
+
[chat-img]: https://img.shields.io/badge/Gitter-Join_the_PostCSS_chat-brightgreen.svg
|
8
|
+
[chat]: https://gitter.im/postcss/postcss
|
13
9
|
|
14
10
|
PostCSS is a tool for transforming styles with JS plugins.
|
15
11
|
These plugins can lint your CSS, support variables and mixins,
|
@@ -19,10 +15,10 @@ PostCSS is used by industry leaders including Wikipedia, Twitter, Alibaba,
|
|
19
15
|
and JetBrains. The [Autoprefixer] PostCSS plugin is one of the most popular
|
20
16
|
CSS processors.
|
21
17
|
|
22
|
-
**
|
23
|
-
**
|
24
|
-
**
|
25
|
-
**中文翻译**: [`README
|
18
|
+
**Support / Discussion:** [Gitter](https://gitter.im/postcss/postcss)<br>
|
19
|
+
**Twitter account:** [@postcss](https://twitter.com/postcss)<br>
|
20
|
+
**VK.com page:** [postcss](https://vk.com/postcss)<br>
|
21
|
+
**中文翻译**: [`README-cn.md`](./README-cn.md)
|
26
22
|
|
27
23
|
For PostCSS commercial support (consulting, improving the front-end culture
|
28
24
|
of your company, PostCSS plugins), contact [Evil Martians](https://evilmartians.com/?utm_source=postcss)
|
@@ -63,8 +59,7 @@ If you have any new ideas, [PostCSS plugin development] is really easy.
|
|
63
59
|
### Use Future CSS, Today
|
64
60
|
|
65
61
|
* [`autoprefixer`] adds vendor prefixes, using data from Can I Use.
|
66
|
-
* [`postcss-
|
67
|
-
(includes `autoprefixer`).
|
62
|
+
* [`postcss-preset-env`] allows you to use future CSS features today.
|
68
63
|
* [`postcss-image-set-polyfill`] emulates [`image-set`] function logic for all browsers
|
69
64
|
|
70
65
|
### Better CSS Readability
|
@@ -101,6 +96,7 @@ If you have any new ideas, [PostCSS plugin development] is really easy.
|
|
101
96
|
[`postcss-image-set-polyfill`]: https://github.com/SuperOl3g/postcss-image-set-polyfill
|
102
97
|
[PostCSS plugin development]: https://github.com/postcss/postcss/blob/master/docs/writing-a-plugin.md
|
103
98
|
[`postcss-inline-svg`]: https://github.com/TrySound/postcss-inline-svg
|
99
|
+
[`postcss-preset-env`]: https://github.com/jonathantneal/postcss-preset-env
|
104
100
|
[`react-css-modules`]: https://github.com/gajus/react-css-modules
|
105
101
|
[`postcss-autoreset`]: https://github.com/maximkoretskiy/postcss-autoreset
|
106
102
|
[`postcss-write-svg`]: https://github.com/jonathantneal/postcss-write-svg
|
@@ -109,7 +105,6 @@ If you have any new ideas, [PostCSS plugin development] is really easy.
|
|
109
105
|
[`postcss-sprites`]: https://github.com/2createStudio/postcss-sprites
|
110
106
|
[`postcss-modules`]: https://github.com/outpunk/postcss-modules
|
111
107
|
[`postcss-sorting`]: https://github.com/hudochenkov/postcss-sorting
|
112
|
-
[`postcss-cssnext`]: http://cssnext.io
|
113
108
|
[`postcss-assets`]: https://github.com/assetsjs/postcss-assets
|
114
109
|
[`font-magician`]: https://github.com/jonathantneal/postcss-font-magician
|
115
110
|
[`autoprefixer`]: https://github.com/postcss/autoprefixer
|
@@ -135,7 +130,10 @@ If there is not yet support for your favorite syntax,
|
|
135
130
|
you can write a parser and/or stringifier to extend PostCSS.
|
136
131
|
|
137
132
|
* [`sugarss`] is a indent-based syntax like Sass or Stylus.
|
138
|
-
* [`postcss-
|
133
|
+
* [`postcss-syntax`] switch syntax automatically by file extensions.
|
134
|
+
* [`postcss-html`] parsing styles in `<style>` tags of HTML-like files.
|
135
|
+
* [`postcss-markdown`] parsing styles in code blocks of Markdown files.
|
136
|
+
* [`postcss-styled`] parsing CSS in template literals of source files.
|
139
137
|
* [`postcss-scss`] allows you to work with SCSS
|
140
138
|
*(but does not compile SCSS to CSS)*.
|
141
139
|
* [`postcss-sass`] allows you to work with Sass
|
@@ -151,7 +149,10 @@ you can write a parser and/or stringifier to extend PostCSS.
|
|
151
149
|
|
152
150
|
[`postcss-less-engine`]: https://github.com/Crunch/postcss-less
|
153
151
|
[`postcss-safe-parser`]: https://github.com/postcss/postcss-safe-parser
|
152
|
+
[`postcss-syntax`]: https://github.com/gucong3000/postcss-syntax
|
154
153
|
[`postcss-html`]: https://github.com/gucong3000/postcss-html
|
154
|
+
[`postcss-markdown`]: https://github.com/gucong3000/postcss-markdown
|
155
|
+
[`postcss-styled`]: https://github.com/gucong3000/postcss-styled
|
155
156
|
[`postcss-scss`]: https://github.com/postcss/postcss-scss
|
156
157
|
[`postcss-sass`]: https://github.com/AleshaOleg/postcss-sass
|
157
158
|
[`postcss-less`]: https://github.com/webschik/postcss-less
|
@@ -0,0 +1,156 @@
|
|
1
|
+
## PostCSS Architecture
|
2
|
+
|
3
|
+
General overview of PostCSS architecture.
|
4
|
+
It can be useful for everyone who wish to contribute to core or develop better understanding of the tool.
|
5
|
+
|
6
|
+
**Table of Contents**
|
7
|
+
|
8
|
+
- [Overview](#overview)
|
9
|
+
- [Workflow](#workflow)
|
10
|
+
- [Core Structures](#core-structures)
|
11
|
+
* [Tokenizer](#tokenizer--libtokenizees6-)
|
12
|
+
* [Parser](#parser--libparsees6-libparseres6-)
|
13
|
+
* [Processor](#processor--libprocessores6-)
|
14
|
+
* [Stringifier](#stringifier--libstringifyes6-libstringifieres6-)
|
15
|
+
- [API](#api-reference)
|
16
|
+
|
17
|
+
### Overview
|
18
|
+
|
19
|
+
> This section describes ideas lying behind PostCSS
|
20
|
+
|
21
|
+
Before diving deeper into development of PostCSS let's briefly describe what is PostCSS and what is not.
|
22
|
+
|
23
|
+
**PostCSS**
|
24
|
+
|
25
|
+
- *is **NOT** a style preprocessor like `Sass` or `Less`.*
|
26
|
+
|
27
|
+
It does not define custom syntax and semantic, it's not actually a language.
|
28
|
+
PostCSS works with CSS and can be easily integrated with tools described above. That being said any valid CSS can be processed by PostCSS.
|
29
|
+
|
30
|
+
- *is a tool for CSS syntax transformations*
|
31
|
+
|
32
|
+
It allows you to define custom CSS like syntax that could be understandable and transformed by plugins. That being said PostCSS is not strictly about CSS spec but about syntax definition manner of CSS. In such way you can define custom syntax constructs like at-rule, that could be very helpful for tools build around PostCSS. PostCSS plays a role of framework for building outstanding tools for CSS manipulations.
|
33
|
+
|
34
|
+
- *is a big player in CSS ecosystem*
|
35
|
+
|
36
|
+
Large amount of lovely tools like `Autoprefixer`, `Stylelint`, `CSSnano` were built on PostCSS ecosystem. There is big chance that you already use it implicitly, just check your `node_modules` :smiley:
|
37
|
+
|
38
|
+
### Workflow
|
39
|
+
|
40
|
+
This is high level overview of whole PostCSS workflow
|
41
|
+
|
42
|
+
<img width="300" src="https://upload.wikimedia.org/wikipedia/commons/thumb/a/aa/PostCSS_scheme.svg/512px-PostCSS_scheme.svg.png" alt="workflow">
|
43
|
+
|
44
|
+
As you can see from diagram above, PostCSS architecture is pretty straightforward but some parts of it could be misunderstood.
|
45
|
+
|
46
|
+
From diagram above you can see part called *Parser*, this construct will be described in details later on, just for now think about it as a structure that can understand your CSS like syntax and create object representation of it.
|
47
|
+
|
48
|
+
That being said, there are few ways to write parser
|
49
|
+
|
50
|
+
- *Write a single file with string to AST transformation*
|
51
|
+
|
52
|
+
This method is quite popular, for example, the [Rework analyzer](https://github.com/reworkcss/css/blob/master/lib/parse/index.js) was written in this style. But with a large code base, the code becomes hard to read and pretty slow.
|
53
|
+
|
54
|
+
- *Split it into lexical analysis/parsing steps (source string → tokens → AST)*
|
55
|
+
|
56
|
+
This is the way of how we do it in PostCSS and also the most popular one.
|
57
|
+
A lot of parsers like [`Babylon` (parser behind Babel)](https://github.com/babel/babel/tree/master/packages/babylon), [`CSSTree`](https://github.com/csstree/csstree) were written in such way.
|
58
|
+
The main reasons to separate tokenization from parsing steps are performance and abstracting complexity.
|
59
|
+
|
60
|
+
Let think about why second way is better for our needs.
|
61
|
+
|
62
|
+
First of all because string to tokens step takes more time than parsing step. We operate on large source string and process it char by char, this is why it is very inefficient operation in terms of performance and we should perform it only once.
|
63
|
+
|
64
|
+
But from other side tokens to AST transformation is logically more complex so with such separation we could write very fast tokenizer (but from this comes sometimes hard to read code) and easy to read (but slow) parser.
|
65
|
+
|
66
|
+
Summing it up splitting in two steps improve performance and code readability.
|
67
|
+
|
68
|
+
So now lets look more closely on structures that play main role in PostCSS workflow.
|
69
|
+
|
70
|
+
### Core Structures
|
71
|
+
|
72
|
+
- #### Tokenizer ( [lib/tokenize.es6](https://github.com/postcss/postcss/blob/master/lib/tokenize.es6) )
|
73
|
+
|
74
|
+
Tokenizer (aka Lexer) plays important role in syntax analysis.
|
75
|
+
|
76
|
+
It accepts CSS string and returns list of tokens.
|
77
|
+
|
78
|
+
Token is a simple structure that describes some part of syntax like `at-rule`, `comment` or `word`. It can also contain positional information for more descriptive errors.
|
79
|
+
|
80
|
+
For example if we consider following css
|
81
|
+
|
82
|
+
```css
|
83
|
+
.className { color: #FFF; }
|
84
|
+
```
|
85
|
+
|
86
|
+
corresponding tokens representation from PostCSS will be
|
87
|
+
```js
|
88
|
+
[
|
89
|
+
["word", ".className", 1, 1, 1, 10]
|
90
|
+
["space", " "]
|
91
|
+
["{", "{", 1, 12]
|
92
|
+
["space", " "]
|
93
|
+
["word", "color", 1, 14, 1, 18]
|
94
|
+
[":", ":", 1, 19]
|
95
|
+
["space", " "]
|
96
|
+
["word", "#FFF" , 1, 21, 1, 23]
|
97
|
+
[";", ";", 1, 24]
|
98
|
+
["space", " "]
|
99
|
+
["}", "}", 1, 26]
|
100
|
+
]
|
101
|
+
```
|
102
|
+
|
103
|
+
As you can see from the example above single token represented as a list and also `space` token doesn't have positional information.
|
104
|
+
|
105
|
+
Lets look more closely on single token like `word`. As it was said each token represented as a list and follow such pattern.
|
106
|
+
|
107
|
+
```typescript
|
108
|
+
const token = [
|
109
|
+
// represents token type
|
110
|
+
'word',
|
111
|
+
|
112
|
+
// represents matched word
|
113
|
+
'.className',
|
114
|
+
|
115
|
+
// This two numbers represent start position of token.
|
116
|
+
// It's optional value as we saw in example above,
|
117
|
+
// tokens like `space` don't have such information.
|
118
|
+
|
119
|
+
// Here the first number is line number and the second one is corresponding column.
|
120
|
+
1, 1,
|
121
|
+
|
122
|
+
// Next two numbers also optional and represent end position for multichar tokens like this one. Numbers follow same rule as was described above
|
123
|
+
1, 10
|
124
|
+
];
|
125
|
+
```
|
126
|
+
There are many patterns how tokenization could be done, PostCSS motto is performance and simplicity. Tokenization is complex computing operation and take large amount of syntax analysis time ( ~90% ), that why PostCSS' Tokenizer looks dirty but it was optimized for speed. Any high-level constructs like classes could dramatically slow down tokenizer.
|
127
|
+
|
128
|
+
PostCSS' Tokenizer use some sort of streaming/chaining API where you exposes [`nextToken()`](https://github.com/postcss/postcss/blob/master/lib/tokenize.es6#L48-L308) method to Parser. In this manner we provide clean interface for Parser and reduce memory usage by storing only few tokens and not whole list of tokens.
|
129
|
+
|
130
|
+
- #### Parser ( [lib/parse.es6](https://github.com/postcss/postcss/blob/master/lib/parse.es6), [lib/parser.es6](https://github.com/postcss/postcss/blob/master/lib/parser.es6) )
|
131
|
+
|
132
|
+
Parser is main structure that responsible for [syntax analysis](https://en.wikipedia.org/wiki/Parsing) of incoming CSS. Parser produces structure called [Abstract Syntax Tree (AST)](https://en.wikipedia.org/wiki/Abstract_syntax_tree) that could then be transformed by plugins later on.
|
133
|
+
|
134
|
+
Parser works in common with Tokenizer and operates over tokens not source string, as it would be very inefficient operation.
|
135
|
+
|
136
|
+
It use mostly `nextToken` and `back` methods provided by Tokenizer for obtaining single or multiple tokens and than construct part of AST called `Node`
|
137
|
+
|
138
|
+
There are multiple Node types that PostCSS could produce but all of them inherit from base Node [class](https://github.com/postcss/postcss/blob/master/lib/node.es6#L34).
|
139
|
+
|
140
|
+
- #### Processor ( [lib/processor.es6](https://github.com/postcss/postcss/blob/master/lib/processor.es6) )
|
141
|
+
|
142
|
+
Processor is a very plain structure that initializes plugins and run syntax transformations. Plugin is just a function registered with [postcss.plugin](https://github.com/postcss/postcss/blob/master/lib/postcss.es6#L109) call.
|
143
|
+
|
144
|
+
It exposes quite few public API methods. Description of them could be found on [api.postcss.org/Processor](http://api.postcss.org/Processor.html)
|
145
|
+
|
146
|
+
- #### Stringifier ( [lib/stringify.es6](https://github.com/postcss/postcss/blob/master/lib/stringify.es6), [lib/stringifier.es6](https://github.com/postcss/postcss/blob/master/lib/stringifier.es6) )
|
147
|
+
|
148
|
+
Stringifier is a base class that translates modified AST to pure CSS string. Stringifier traverse AST starting from provided Node and generate raw string representation of it calling corresponding methods.
|
149
|
+
|
150
|
+
The most essential method is [`Stringifier.stringify`](https://github.com/postcss/postcss/blob/master/lib/stringifier.es6#L25-L27)
|
151
|
+
that accepts initial Node and semicolon indicator.
|
152
|
+
You can learn more by checking [stringifier.es6](https://github.com/postcss/postcss/blob/master/lib/stringifier.es6)
|
153
|
+
|
154
|
+
### API Reference
|
155
|
+
|
156
|
+
More descriptive API documentation could be found [here](http://api.postcss.org/)
|
package/lib/at-rule.js
CHANGED
@@ -128,4 +128,4 @@ var AtRule = function (_Container) {
|
|
128
128
|
|
129
129
|
exports.default = AtRule;
|
130
130
|
module.exports = exports['default'];
|
131
|
-
//# sourceMappingURL=data:application/json;charset=utf8;base64,
|
131
|
+
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImF0LXJ1b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ydGllcy5cbiAgICAgKiBBcyBzdWNoLCBpZiB5b3UgZG9u4oCZdCBjaGFuZ2UgYSBkZWNsYXJhdGlvbuKAmXMgdmFsdWUsXG4gICAgICogUG9zdENTUyB3aWxsIHVzZSB0aGUgcmF3IHZhbHVlIHdpdGggY29tbWVudHMuXG4gICAgICpcbiAgICAgKiBAZXhhbXBsZVxuICAgICAqIGNvbnN0IHJvb3QgPSBwb3N0Y3NzLnBhcnNlKCcgIEBtZWRpYVxcbnByaW50IHtcXG59JylcbiAgICAgKiByb290LmZpcnN0LmZpcnN0LnJhd3MgLy89PiB7IGJlZm9yZTogJyAgJyxcbiAgICAgKiAgICAgICAgICAgICAgICAgICAgICAgLy8gICAgIGJldHdlZW46ICcgJyxcbiAgICAgKiAgICAgICAgICAgICAgICAgICAgICAgLy8gICAgIGFmdGVyTmFtZTogJ1xcbicsXG4gICAgICogICAgICAgICAgICAgICAgICAgICAgIC8vICAgICBhZnRlcjogJ1xcbicgfVxuICAgICAqL1xufVxuXG5leHBvcnQgZGVmYXVsdCBBdFJ1bGU7XG4iXX0=
|
package/lib/comment.js
CHANGED
@@ -58,4 +58,4 @@ var Comment = function (_Node) {
|
|
58
58
|
|
59
59
|
exports.default = Comment;
|
60
60
|
module.exports = exports['default'];
|
61
|
-
//# sourceMappingURL=data:application/json;charset=utf8;base64,
|
61
|
+
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNvbW1lbnQuZXM2Il0sIm5hbWVzIjpbIkNvbW1lbnQiLCJkZWZhdWx0cyIsInR5cGUiLCJOb2RlIl0sIm1hcHBpbmdzIjoiOzs7O0FBQUE7Ozs7Ozs7Ozs7OztBQUVBOzs7Ozs7OztJQVFNQSxPOzs7QUFFRixtQkFBWUMsUUFBWixFQUFzQjtBQUFBOztBQUFBLGlEQUNsQixpQkFBTUEsUUFBTixDQURrQjs7QUFFbEIsVUFBS0MsSUFBTCxHQUFZLFNBQVo7QUFGa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