postcss 8.3.10 → 8.4.2
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/lib/container.d.ts +2 -2
- package/lib/container.js +3 -2
- package/lib/css-syntax-error.d.ts +55 -8
- package/lib/css-syntax-error.js +9 -2
- package/lib/input.d.ts +26 -6
- package/lib/input.js +43 -11
- package/lib/lazy-result.d.ts +11 -10
- package/lib/lazy-result.js +4 -2
- package/lib/map-generator.js +71 -42
- package/lib/no-work-result.d.ts +37 -0
- package/lib/no-work-result.js +131 -0
- package/lib/node.d.ts +36 -2
- package/lib/node.js +63 -4
- package/lib/parser.js +25 -5
- package/lib/postcss.d.ts +31 -30
- package/lib/postcss.js +5 -1
- package/lib/postcss.mjs +1 -0
- package/lib/previous-map.js +1 -2
- package/lib/processor.d.ts +5 -4
- package/lib/processor.js +6 -13
- package/lib/result.d.ts +3 -2
- package/lib/stringifier.d.ts +37 -0
- package/lib/stringifier.js +3 -1
- package/lib/warn-once.js +1 -0
- package/lib/warning.d.ts +37 -3
- package/lib/warning.js +5 -3
- package/package.json +3 -2
@@ -0,0 +1,131 @@
|
|
1
|
+
'use strict'
|
2
|
+
|
3
|
+
let MapGenerator = require('./map-generator')
|
4
|
+
let stringify = require('./stringify')
|
5
|
+
let warnOnce = require('./warn-once')
|
6
|
+
let parse = require('./parse')
|
7
|
+
const Result = require('./result')
|
8
|
+
|
9
|
+
class NoWorkResult {
|
10
|
+
constructor(processor, css, opts) {
|
11
|
+
this.stringified = false
|
12
|
+
|
13
|
+
this._processor = processor
|
14
|
+
this._css = css
|
15
|
+
this._opts = opts
|
16
|
+
this._map = undefined
|
17
|
+
let root
|
18
|
+
|
19
|
+
let str = stringify
|
20
|
+
this.result = new Result(this._processor, root, this._opts)
|
21
|
+
this.result.css = css
|
22
|
+
|
23
|
+
let self = this
|
24
|
+
Object.defineProperty(this.result, 'root', {
|
25
|
+
get() {
|
26
|
+
return self.root
|
27
|
+
}
|
28
|
+
})
|
29
|
+
|
30
|
+
let map = new MapGenerator(str, root, this._opts, css)
|
31
|
+
if (map.isMap()) {
|
32
|
+
let [generatedCSS, generatedMap] = map.generate()
|
33
|
+
if (generatedCSS) {
|
34
|
+
this.result.css = generatedCSS
|
35
|
+
}
|
36
|
+
if (generatedMap) {
|
37
|
+
this.result.map = generatedMap
|
38
|
+
}
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
get [Symbol.toStringTag]() {
|
43
|
+
return 'NoWorkResult'
|
44
|
+
}
|
45
|
+
|
46
|
+
get processor() {
|
47
|
+
return this.result.processor
|
48
|
+
}
|
49
|
+
|
50
|
+
get opts() {
|
51
|
+
return this.result.opts
|
52
|
+
}
|
53
|
+
|
54
|
+
get css() {
|
55
|
+
return this.result.css
|
56
|
+
}
|
57
|
+
|
58
|
+
get content() {
|
59
|
+
return this.result.css
|
60
|
+
}
|
61
|
+
|
62
|
+
get map() {
|
63
|
+
return this.result.map
|
64
|
+
}
|
65
|
+
|
66
|
+
get root() {
|
67
|
+
if (this._root) {
|
68
|
+
return this._root
|
69
|
+
}
|
70
|
+
|
71
|
+
let root
|
72
|
+
let parser = parse
|
73
|
+
|
74
|
+
try {
|
75
|
+
root = parser(this._css, this._opts)
|
76
|
+
} catch (error) {
|
77
|
+
this.error = error
|
78
|
+
}
|
79
|
+
|
80
|
+
this._root = root
|
81
|
+
|
82
|
+
return root
|
83
|
+
}
|
84
|
+
|
85
|
+
get messages() {
|
86
|
+
return []
|
87
|
+
}
|
88
|
+
|
89
|
+
warnings() {
|
90
|
+
return []
|
91
|
+
}
|
92
|
+
|
93
|
+
toString() {
|
94
|
+
return this._css
|
95
|
+
}
|
96
|
+
|
97
|
+
then(onFulfilled, onRejected) {
|
98
|
+
if (process.env.NODE_ENV !== 'production') {
|
99
|
+
if (!('from' in this._opts)) {
|
100
|
+
warnOnce(
|
101
|
+
'Without `from` option PostCSS could generate wrong source map ' +
|
102
|
+
'and will not find Browserslist config. Set it to CSS file path ' +
|
103
|
+
'or to `undefined` to prevent this warning.'
|
104
|
+
)
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
return this.async().then(onFulfilled, onRejected)
|
109
|
+
}
|
110
|
+
|
111
|
+
catch(onRejected) {
|
112
|
+
return this.async().catch(onRejected)
|
113
|
+
}
|
114
|
+
|
115
|
+
finally(onFinally) {
|
116
|
+
return this.async().then(onFinally, onFinally)
|
117
|
+
}
|
118
|
+
|
119
|
+
async() {
|
120
|
+
if (this.error) return Promise.reject(this.error)
|
121
|
+
return Promise.resolve(this.result)
|
122
|
+
}
|
123
|
+
|
124
|
+
sync() {
|
125
|
+
if (this.error) throw this.error
|
126
|
+
return this.result
|
127
|
+
}
|
128
|
+
}
|
129
|
+
|
130
|
+
module.exports = NoWorkResult
|
131
|
+
NoWorkResult.default = NoWorkResult
|
package/lib/node.d.ts
CHANGED
@@ -38,17 +38,29 @@ export interface Position {
|
|
38
38
|
line: number
|
39
39
|
}
|
40
40
|
|
41
|
+
export interface Range {
|
42
|
+
/**
|
43
|
+
* Start position, inclusive.
|
44
|
+
*/
|
45
|
+
start: Position
|
46
|
+
|
47
|
+
/**
|
48
|
+
* End position, exclusive.
|
49
|
+
*/
|
50
|
+
end: Position
|
51
|
+
}
|
52
|
+
|
41
53
|
export interface Source {
|
42
54
|
/**
|
43
55
|
* The file source of the node.
|
44
56
|
*/
|
45
57
|
input: Input
|
46
58
|
/**
|
47
|
-
* The starting position of the node’s source.
|
59
|
+
* The inclusive starting position of the node’s source.
|
48
60
|
*/
|
49
61
|
start?: Position
|
50
62
|
/**
|
51
|
-
* The ending position of the node's source.
|
63
|
+
* The inclusive ending position of the node's source.
|
52
64
|
*/
|
53
65
|
end?: Position
|
54
66
|
}
|
@@ -72,6 +84,11 @@ interface NodeErrorOptions {
|
|
72
84
|
* of error.
|
73
85
|
*/
|
74
86
|
index?: number
|
87
|
+
/**
|
88
|
+
* An ending index inside a node's string that should be highlighted as
|
89
|
+
* source of error.
|
90
|
+
*/
|
91
|
+
endIndex?: number
|
75
92
|
}
|
76
93
|
|
77
94
|
/**
|
@@ -441,4 +458,21 @@ export default abstract class Node {
|
|
441
458
|
* @return Symbol position in file.
|
442
459
|
*/
|
443
460
|
positionInside(index: number): Position
|
461
|
+
|
462
|
+
/**
|
463
|
+
* Get the position for a word or an index inside the node.
|
464
|
+
*
|
465
|
+
* @param opts Options.
|
466
|
+
* @return Position.
|
467
|
+
*/
|
468
|
+
positionBy(opts?: Pick<WarningOptions, 'word' | 'index'>): Position
|
469
|
+
|
470
|
+
/**
|
471
|
+
* Get the range for a word or start and end index inside the node.
|
472
|
+
* The start index is inclusive; the end index is exclusive.
|
473
|
+
*
|
474
|
+
* @param opts Options.
|
475
|
+
* @return Range.
|
476
|
+
*/
|
477
|
+
rangeBy(opts?: Pick<WarningOptions, 'word' | 'index' | 'endIndex'>): Range
|
444
478
|
}
|
package/lib/node.js
CHANGED
@@ -10,7 +10,7 @@ function cloneNode(obj, parent) {
|
|
10
10
|
|
11
11
|
for (let i in obj) {
|
12
12
|
if (!Object.prototype.hasOwnProperty.call(obj, i)) {
|
13
|
-
|
13
|
+
/* c8 ignore next 2 */
|
14
14
|
continue
|
15
15
|
}
|
16
16
|
if (i === 'proxyCache') continue
|
@@ -56,8 +56,13 @@ class Node {
|
|
56
56
|
|
57
57
|
error(message, opts = {}) {
|
58
58
|
if (this.source) {
|
59
|
-
let
|
60
|
-
return this.source.input.error(
|
59
|
+
let { start, end } = this.rangeBy(opts)
|
60
|
+
return this.source.input.error(
|
61
|
+
message,
|
62
|
+
{ line: start.line, column: start.column },
|
63
|
+
{ line: end.line, column: end.column },
|
64
|
+
opts
|
65
|
+
)
|
61
66
|
}
|
62
67
|
return new CssSyntaxError(message)
|
63
68
|
}
|
@@ -184,7 +189,7 @@ class Node {
|
|
184
189
|
|
185
190
|
for (let name in this) {
|
186
191
|
if (!Object.prototype.hasOwnProperty.call(this, name)) {
|
187
|
-
|
192
|
+
/* c8 ignore next 2 */
|
188
193
|
continue
|
189
194
|
}
|
190
195
|
if (name === 'parent' || name === 'proxyCache') continue
|
@@ -252,6 +257,59 @@ class Node {
|
|
252
257
|
return pos
|
253
258
|
}
|
254
259
|
|
260
|
+
rangeBy(opts) {
|
261
|
+
let start = {
|
262
|
+
line: this.source.start.line,
|
263
|
+
column: this.source.start.column
|
264
|
+
}
|
265
|
+
let end = this.source.end
|
266
|
+
? {
|
267
|
+
line: this.source.end.line,
|
268
|
+
column: this.source.end.column + 1
|
269
|
+
}
|
270
|
+
: {
|
271
|
+
line: start.line,
|
272
|
+
column: start.column + 1
|
273
|
+
}
|
274
|
+
|
275
|
+
if (opts.word) {
|
276
|
+
let index = this.toString().indexOf(opts.word)
|
277
|
+
if (index !== -1) {
|
278
|
+
start = this.positionInside(index)
|
279
|
+
end = this.positionInside(index + opts.word.length)
|
280
|
+
}
|
281
|
+
} else {
|
282
|
+
if (opts.start) {
|
283
|
+
start = {
|
284
|
+
line: opts.start.line,
|
285
|
+
column: opts.start.column
|
286
|
+
}
|
287
|
+
} else if (opts.index) {
|
288
|
+
start = this.positionInside(opts.index)
|
289
|
+
}
|
290
|
+
|
291
|
+
if (opts.end) {
|
292
|
+
end = {
|
293
|
+
line: opts.end.line,
|
294
|
+
column: opts.end.column
|
295
|
+
}
|
296
|
+
} else if (opts.endIndex) {
|
297
|
+
end = this.positionInside(opts.endIndex)
|
298
|
+
} else if (opts.index) {
|
299
|
+
end = this.positionInside(opts.index + 1)
|
300
|
+
}
|
301
|
+
}
|
302
|
+
|
303
|
+
if (
|
304
|
+
end.line < start.line ||
|
305
|
+
(end.line === start.line && end.column <= start.column)
|
306
|
+
) {
|
307
|
+
end = { line: start.line, column: start.column + 1 }
|
308
|
+
}
|
309
|
+
|
310
|
+
return { start, end }
|
311
|
+
}
|
312
|
+
|
255
313
|
getProxyProcessor() {
|
256
314
|
return {
|
257
315
|
set(node, prop, value) {
|
@@ -263,6 +321,7 @@ class Node {
|
|
263
321
|
prop === 'name' ||
|
264
322
|
prop === 'params' ||
|
265
323
|
prop === 'important' ||
|
324
|
+
/* c8 ignore next */
|
266
325
|
prop === 'text'
|
267
326
|
) {
|
268
327
|
node.markDirty()
|
package/lib/parser.js
CHANGED
@@ -511,15 +511,27 @@ class Parser {
|
|
511
511
|
// Errors
|
512
512
|
|
513
513
|
unclosedBracket(bracket) {
|
514
|
-
throw this.input.error(
|
514
|
+
throw this.input.error(
|
515
|
+
'Unclosed bracket',
|
516
|
+
{ offset: bracket[2] },
|
517
|
+
{ offset: bracket[2] + 1 }
|
518
|
+
)
|
515
519
|
}
|
516
520
|
|
517
521
|
unknownWord(tokens) {
|
518
|
-
throw this.input.error(
|
522
|
+
throw this.input.error(
|
523
|
+
'Unknown word',
|
524
|
+
{ offset: tokens[0][2] },
|
525
|
+
{ offset: tokens[0][2] + tokens[0][1].length }
|
526
|
+
)
|
519
527
|
}
|
520
528
|
|
521
529
|
unexpectedClose(token) {
|
522
|
-
throw this.input.error(
|
530
|
+
throw this.input.error(
|
531
|
+
'Unexpected }',
|
532
|
+
{ offset: token[2] },
|
533
|
+
{ offset: token[2] + 1 }
|
534
|
+
)
|
523
535
|
}
|
524
536
|
|
525
537
|
unclosedBlock() {
|
@@ -528,11 +540,19 @@ class Parser {
|
|
528
540
|
}
|
529
541
|
|
530
542
|
doubleColon(token) {
|
531
|
-
throw this.input.error(
|
543
|
+
throw this.input.error(
|
544
|
+
'Double colon',
|
545
|
+
{ offset: token[2] },
|
546
|
+
{ offset: token[2] + token[1].length }
|
547
|
+
)
|
532
548
|
}
|
533
549
|
|
534
550
|
unnamedAtrule(node, token) {
|
535
|
-
throw this.input.error(
|
551
|
+
throw this.input.error(
|
552
|
+
'At-rule without name',
|
553
|
+
{ offset: token[2] },
|
554
|
+
{ offset: token[2] + token[1].length }
|
555
|
+
)
|
536
556
|
}
|
537
557
|
|
538
558
|
precheckMissedSemicolon(/* tokens */) {
|
package/lib/postcss.d.ts
CHANGED
@@ -10,52 +10,53 @@ import Node, {
|
|
10
10
|
AnyNode
|
11
11
|
} from './node.js'
|
12
12
|
import Declaration, { DeclarationProps } from './declaration.js'
|
13
|
-
import
|
13
|
+
import Container, { ContainerProps } from './container.js'
|
14
14
|
import Document, { DocumentProps } from './document.js'
|
15
|
+
import Warning, { WarningOptions } from './warning.js'
|
15
16
|
import Comment, { CommentProps } from './comment.js'
|
16
17
|
import AtRule, { AtRuleProps } from './at-rule.js'
|
18
|
+
import Input, { FilePosition } from './input.js'
|
17
19
|
import Result, { Message } from './result.js'
|
18
|
-
import
|
20
|
+
import Root, { RootProps } from './root.js'
|
19
21
|
import Rule, { RuleProps } from './rule.js'
|
20
|
-
import Container, { ContainerProps } from './container.js'
|
21
|
-
import Warning, { WarningOptions } from './warning.js'
|
22
|
-
import Input, { FilePosition } from './input.js'
|
23
22
|
import CssSyntaxError from './css-syntax-error.js'
|
24
23
|
import list, { List } from './list.js'
|
24
|
+
import LazyResult from './lazy-result.js'
|
25
25
|
import Processor from './processor.js'
|
26
26
|
|
27
27
|
export {
|
28
|
-
WarningOptions,
|
29
|
-
FilePosition,
|
30
|
-
Position,
|
31
|
-
Source,
|
32
|
-
ChildNode,
|
33
|
-
AnyNode,
|
34
|
-
Message,
|
35
28
|
NodeErrorOptions,
|
36
|
-
NodeProps,
|
37
29
|
DeclarationProps,
|
30
|
+
CssSyntaxError,
|
38
31
|
ContainerProps,
|
32
|
+
WarningOptions,
|
33
|
+
DocumentProps,
|
34
|
+
FilePosition,
|
39
35
|
CommentProps,
|
40
|
-
RuleProps,
|
41
|
-
ChildProps,
|
42
36
|
AtRuleProps,
|
37
|
+
Declaration,
|
38
|
+
ChildProps,
|
39
|
+
LazyResult,
|
40
|
+
ChildNode,
|
41
|
+
NodeProps,
|
42
|
+
Processor,
|
43
|
+
RuleProps,
|
43
44
|
RootProps,
|
44
|
-
DocumentProps,
|
45
|
-
Warning,
|
46
|
-
CssSyntaxError,
|
47
|
-
Node,
|
48
45
|
Container,
|
49
|
-
|
50
|
-
|
46
|
+
Position,
|
47
|
+
Document,
|
48
|
+
AnyNode,
|
49
|
+
Warning,
|
50
|
+
Message,
|
51
51
|
Comment,
|
52
|
+
Source,
|
52
53
|
AtRule,
|
53
|
-
Rule,
|
54
|
-
Root,
|
55
|
-
Document,
|
56
54
|
Result,
|
57
|
-
|
58
|
-
|
55
|
+
Input,
|
56
|
+
Node,
|
57
|
+
list,
|
58
|
+
Rule,
|
59
|
+
Root
|
59
60
|
}
|
60
61
|
|
61
62
|
export type SourceMap = SourceMapGenerator & {
|
@@ -221,7 +222,7 @@ export type AcceptedPlugin =
|
|
221
222
|
}
|
222
223
|
| Processor
|
223
224
|
|
224
|
-
export interface Parser<RootNode = Root> {
|
225
|
+
export interface Parser<RootNode = Root | Document> {
|
225
226
|
(
|
226
227
|
css: string | { toString(): string },
|
227
228
|
opts?: Pick<ProcessOptions, 'map' | 'from'>
|
@@ -245,7 +246,7 @@ export interface Syntax {
|
|
245
246
|
/**
|
246
247
|
* Function to generate AST by string.
|
247
248
|
*/
|
248
|
-
parse?: Parser
|
249
|
+
parse?: Parser
|
249
250
|
|
250
251
|
/**
|
251
252
|
* Class to generate string by AST.
|
@@ -378,7 +379,7 @@ export interface Postcss {
|
|
378
379
|
* root1.append(root2).toResult().css
|
379
380
|
* ```
|
380
381
|
*/
|
381
|
-
parse: Parser
|
382
|
+
parse: Parser<Root>
|
382
383
|
|
383
384
|
/**
|
384
385
|
* Rehydrate a JSON AST (from `Node#toJSON`) back into the AST classes.
|
@@ -458,7 +459,7 @@ export interface Postcss {
|
|
458
459
|
}
|
459
460
|
|
460
461
|
export const stringify: Stringifier
|
461
|
-
export const parse: Parser
|
462
|
+
export const parse: Parser<Root>
|
462
463
|
export const fromJSON: JSONHydrator
|
463
464
|
|
464
465
|
export const comment: Postcss['comment']
|
package/lib/postcss.js
CHANGED
@@ -27,14 +27,17 @@ function postcss(...plugins) {
|
|
27
27
|
}
|
28
28
|
|
29
29
|
postcss.plugin = function plugin(name, initializer) {
|
30
|
+
// eslint-disable-next-line no-console
|
30
31
|
if (console && console.warn) {
|
32
|
+
// eslint-disable-next-line no-console
|
31
33
|
console.warn(
|
32
34
|
name +
|
33
35
|
': postcss.plugin was deprecated. Migration guide:\n' +
|
34
36
|
'https://evilmartians.com/chronicles/postcss-8-plugin-migration'
|
35
37
|
)
|
36
38
|
if (process.env.LANG && process.env.LANG.startsWith('cn')) {
|
37
|
-
|
39
|
+
/* c8 ignore next 7 */
|
40
|
+
// eslint-disable-next-line no-console
|
38
41
|
console.warn(
|
39
42
|
name +
|
40
43
|
': 里面 postcss.plugin 被弃用. 迁移指南:\n' +
|
@@ -79,6 +82,7 @@ postcss.document = defaults => new Document(defaults)
|
|
79
82
|
postcss.CssSyntaxError = CssSyntaxError
|
80
83
|
postcss.Declaration = Declaration
|
81
84
|
postcss.Container = Container
|
85
|
+
postcss.Processor = Processor
|
82
86
|
postcss.Document = Document
|
83
87
|
postcss.Comment = Comment
|
84
88
|
postcss.Warning = Warning
|
package/lib/postcss.mjs
CHANGED
@@ -18,6 +18,7 @@ export const root = postcss.root
|
|
18
18
|
export const CssSyntaxError = postcss.CssSyntaxError
|
19
19
|
export const Declaration = postcss.Declaration
|
20
20
|
export const Container = postcss.Container
|
21
|
+
export const Processor = postcss.Processor
|
21
22
|
export const Document = postcss.Document
|
22
23
|
export const Comment = postcss.Comment
|
23
24
|
export const Warning = postcss.Warning
|
package/lib/previous-map.js
CHANGED
@@ -8,7 +8,7 @@ function fromBase64(str) {
|
|
8
8
|
if (Buffer) {
|
9
9
|
return Buffer.from(str, 'base64').toString()
|
10
10
|
} else {
|
11
|
-
|
11
|
+
/* c8 ignore next 2 */
|
12
12
|
return window.atob(str)
|
13
13
|
}
|
14
14
|
}
|
@@ -48,7 +48,6 @@ class PreviousMap {
|
|
48
48
|
}
|
49
49
|
|
50
50
|
getAnnotationURL(sourceMapString) {
|
51
|
-
console.log(sourceMapString)
|
52
51
|
return sourceMapString.replace(/^\/\*\s*# sourceMappingURL=/, '').trim()
|
53
52
|
}
|
54
53
|
|
package/lib/processor.d.ts
CHANGED
@@ -8,13 +8,14 @@ import {
|
|
8
8
|
import LazyResult from './lazy-result.js'
|
9
9
|
import Result from './result.js'
|
10
10
|
import Root from './root.js'
|
11
|
+
import NoWorkResult from './no-work-result.js'
|
11
12
|
|
12
13
|
/**
|
13
14
|
* Contains plugins to process CSS. Create one `Processor` instance,
|
14
15
|
* initialize its plugins, and then use that instance on numerous CSS files.
|
15
16
|
*
|
16
17
|
* ```js
|
17
|
-
* const processor = postcss([autoprefixer,
|
18
|
+
* const processor = postcss([autoprefixer, postcssNested])
|
18
19
|
* processor.process(css1).then(result => console.log(result.css))
|
19
20
|
* processor.process(css2).then(result => console.log(result.css))
|
20
21
|
* ```
|
@@ -35,7 +36,7 @@ export default class Processor {
|
|
35
36
|
* Plugins added to this processor.
|
36
37
|
*
|
37
38
|
* ```js
|
38
|
-
* const processor = postcss([autoprefixer,
|
39
|
+
* const processor = postcss([autoprefixer, postcssNested])
|
39
40
|
* processor.plugins.length //=> 2
|
40
41
|
* ```
|
41
42
|
*/
|
@@ -67,7 +68,7 @@ export default class Processor {
|
|
67
68
|
* ```js
|
68
69
|
* const processor = postcss()
|
69
70
|
* .use(autoprefixer)
|
70
|
-
* .use(
|
71
|
+
* .use(postcssNested)
|
71
72
|
* ```
|
72
73
|
*
|
73
74
|
* @param plugin PostCSS plugin or `Processor` with plugins.
|
@@ -97,5 +98,5 @@ export default class Processor {
|
|
97
98
|
process(
|
98
99
|
css: string | { toString(): string } | Result | LazyResult | Root,
|
99
100
|
options?: ProcessOptions
|
100
|
-
): LazyResult
|
101
|
+
): LazyResult | NoWorkResult
|
101
102
|
}
|
package/lib/processor.js
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
'use strict'
|
2
2
|
|
3
|
+
let NoWorkResult = require('./no-work-result')
|
3
4
|
let LazyResult = require('./lazy-result')
|
4
5
|
let Document = require('./document')
|
5
6
|
let Root = require('./root')
|
6
7
|
|
7
8
|
class Processor {
|
8
9
|
constructor(plugins = []) {
|
9
|
-
this.version = '8.
|
10
|
+
this.version = '8.4.2'
|
10
11
|
this.plugins = this.normalize(plugins)
|
11
12
|
}
|
12
13
|
|
@@ -20,20 +21,12 @@ class Processor {
|
|
20
21
|
this.plugins.length === 0 &&
|
21
22
|
typeof opts.parser === 'undefined' &&
|
22
23
|
typeof opts.stringifier === 'undefined' &&
|
23
|
-
typeof opts.syntax === 'undefined'
|
24
|
-
!opts.hideNothingWarning
|
24
|
+
typeof opts.syntax === 'undefined'
|
25
25
|
) {
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
'You did not set any plugins, parser, or stringifier. ' +
|
30
|
-
'Right now, PostCSS does nothing. Pick plugins for your case ' +
|
31
|
-
'on https://www.postcss.parts/ and use them in postcss.config.js.'
|
32
|
-
)
|
33
|
-
}
|
34
|
-
}
|
26
|
+
return new NoWorkResult(this, css, opts)
|
27
|
+
} else {
|
28
|
+
return new LazyResult(this, css, opts)
|
35
29
|
}
|
36
|
-
return new LazyResult(this, css, opts)
|
37
30
|
}
|
38
31
|
|
39
32
|
normalize(plugins) {
|
package/lib/result.d.ts
CHANGED
@@ -4,6 +4,7 @@ import {
|
|
4
4
|
SourceMap,
|
5
5
|
TransformCallback,
|
6
6
|
Root,
|
7
|
+
Document,
|
7
8
|
Node,
|
8
9
|
Warning,
|
9
10
|
WarningOptions
|
@@ -94,7 +95,7 @@ export default class Result {
|
|
94
95
|
* root.toResult().root === root
|
95
96
|
* ```
|
96
97
|
*/
|
97
|
-
root: Root
|
98
|
+
root: Root | Document
|
98
99
|
|
99
100
|
/**
|
100
101
|
* Options from the `Processor#process` or `Root#toResult` call
|
@@ -141,7 +142,7 @@ export default class Result {
|
|
141
142
|
* @param root Root node after all transformations.
|
142
143
|
* @param opts Options from the `Processor#process` or `Root#toResult`.
|
143
144
|
*/
|
144
|
-
constructor(processor: Processor, root: Root, opts: ResultOptions)
|
145
|
+
constructor(processor: Processor, root: Root | Document, opts: ResultOptions)
|
145
146
|
|
146
147
|
/**
|
147
148
|
* An alias for the `Result#css` property.
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import {
|
2
|
+
Document,
|
3
|
+
Root,
|
4
|
+
Comment,
|
5
|
+
Declaration,
|
6
|
+
Builder,
|
7
|
+
AnyNode,
|
8
|
+
Rule,
|
9
|
+
AtRule,
|
10
|
+
Container
|
11
|
+
} from './postcss.js'
|
12
|
+
|
13
|
+
export default class Stringifier {
|
14
|
+
builder: Builder
|
15
|
+
constructor(builder: Builder)
|
16
|
+
stringify(node: AnyNode, semicolon?: boolean): void
|
17
|
+
document(node: Document): void
|
18
|
+
root(node: Root): void
|
19
|
+
comment(node: Comment): void
|
20
|
+
decl(node: Declaration, semicolon?: boolean): void
|
21
|
+
rule(node: Rule): void
|
22
|
+
atrule(node: AtRule, semicolon?: boolean): void
|
23
|
+
body(node: Container): void
|
24
|
+
block(node: AnyNode, start: string): void
|
25
|
+
raw(node: AnyNode, own: string | null, detect?: string): string
|
26
|
+
rawSemicolon(root: Root): boolean | undefined
|
27
|
+
rawEmptyBody(root: Root): string | undefined
|
28
|
+
rawIndent(root: Root): string | undefined
|
29
|
+
rawBeforeComment(root: Root, node: Comment): string | undefined
|
30
|
+
rawBeforeDecl(root: Root, node: Declaration): string | undefined
|
31
|
+
rawBeforeRule(root: Root): string | undefined
|
32
|
+
rawBeforeClose(root: Root): string | undefined
|
33
|
+
rawBeforeOpen(root: Root): string | undefined
|
34
|
+
rawColon(root: Root): string | undefined
|
35
|
+
beforeAfter(node: AnyNode, detect: 'before' | 'after'): string
|
36
|
+
rawValue(node: AnyNode, prop: string): string
|
37
|
+
}
|
package/lib/stringifier.js
CHANGED
@@ -25,7 +25,7 @@ class Stringifier {
|
|
25
25
|
}
|
26
26
|
|
27
27
|
stringify(node, semicolon) {
|
28
|
-
/*
|
28
|
+
/* c8 ignore start */
|
29
29
|
if (!this[node.type]) {
|
30
30
|
throw new Error(
|
31
31
|
'Unknown AST node type ' +
|
@@ -34,6 +34,7 @@ class Stringifier {
|
|
34
34
|
'Maybe you need to change PostCSS stringifier.'
|
35
35
|
)
|
36
36
|
}
|
37
|
+
/* c8 ignore stop */
|
37
38
|
this[node.type](node, semicolon)
|
38
39
|
}
|
39
40
|
|
@@ -349,3 +350,4 @@ class Stringifier {
|
|
349
350
|
}
|
350
351
|
|
351
352
|
module.exports = Stringifier
|
353
|
+
Stringifier.default = Stringifier
|
package/lib/warn-once.js
CHANGED