postcss 8.5.2 → 8.5.4

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.
@@ -67,46 +67,6 @@ declare class LazyResult_<RootNode = Document | Root>
67
67
  */
68
68
  then: Promise<Result<RootNode>>['then']
69
69
 
70
- /**
71
- * @param processor Processor used for this transformation.
72
- * @param css CSS to parse and transform.
73
- * @param opts Options from the `Processor#process` or `Root#toResult`.
74
- */
75
- constructor(processor: Processor, css: string, opts: ResultOptions)
76
-
77
- /**
78
- * Run plugin in async way and return `Result`.
79
- *
80
- * @return Result with output content.
81
- */
82
- async(): Promise<Result<RootNode>>
83
-
84
- /**
85
- * Run plugin in sync way and return `Result`.
86
- *
87
- * @return Result with output content.
88
- */
89
- sync(): Result<RootNode>
90
-
91
- /**
92
- * Alias for the `LazyResult#css` property.
93
- *
94
- * ```js
95
- * lazy + '' === lazy.css
96
- * ```
97
- *
98
- * @return Output CSS.
99
- */
100
- toString(): string
101
-
102
- /**
103
- * Processes input CSS through synchronous plugins
104
- * and calls `Result#warnings`.
105
- *
106
- * @return Warnings from plugins.
107
- */
108
- warnings(): Warning[]
109
-
110
70
  /**
111
71
  * An alias for the `css` property. Use it with syntaxes
112
72
  * that generate non-CSS output.
@@ -181,6 +141,46 @@ declare class LazyResult_<RootNode = Document | Root>
181
141
  * Required to implement the Promise interface.
182
142
  */
183
143
  get [Symbol.toStringTag](): string
144
+
145
+ /**
146
+ * @param processor Processor used for this transformation.
147
+ * @param css CSS to parse and transform.
148
+ * @param opts Options from the `Processor#process` or `Root#toResult`.
149
+ */
150
+ constructor(processor: Processor, css: string, opts: ResultOptions)
151
+
152
+ /**
153
+ * Run plugin in async way and return `Result`.
154
+ *
155
+ * @return Result with output content.
156
+ */
157
+ async(): Promise<Result<RootNode>>
158
+
159
+ /**
160
+ * Run plugin in sync way and return `Result`.
161
+ *
162
+ * @return Result with output content.
163
+ */
164
+ sync(): Result<RootNode>
165
+
166
+ /**
167
+ * Alias for the `LazyResult#css` property.
168
+ *
169
+ * ```js
170
+ * lazy + '' === lazy.css
171
+ * ```
172
+ *
173
+ * @return Output CSS.
174
+ */
175
+ toString(): string
176
+
177
+ /**
178
+ * Processes input CSS through synchronous plugins
179
+ * and calls `Result#warnings`.
180
+ *
181
+ * @return Warnings from plugins.
182
+ */
183
+ warnings(): Warning[]
184
184
  }
185
185
 
186
186
  declare class LazyResult<
@@ -105,6 +105,38 @@ function cleanMarks(node) {
105
105
  let postcss = {}
106
106
 
107
107
  class LazyResult {
108
+ get content() {
109
+ return this.stringify().content
110
+ }
111
+
112
+ get css() {
113
+ return this.stringify().css
114
+ }
115
+
116
+ get map() {
117
+ return this.stringify().map
118
+ }
119
+
120
+ get messages() {
121
+ return this.sync().messages
122
+ }
123
+
124
+ get opts() {
125
+ return this.result.opts
126
+ }
127
+
128
+ get processor() {
129
+ return this.result.processor
130
+ }
131
+
132
+ get root() {
133
+ return this.sync().root
134
+ }
135
+
136
+ get [Symbol.toStringTag]() {
137
+ return 'LazyResult'
138
+ }
139
+
108
140
  constructor(processor, css, opts) {
109
141
  this.stringified = false
110
142
  this.processed = false
@@ -505,38 +537,6 @@ class LazyResult {
505
537
  warnings() {
506
538
  return this.sync().warnings()
507
539
  }
508
-
509
- get content() {
510
- return this.stringify().content
511
- }
512
-
513
- get css() {
514
- return this.stringify().css
515
- }
516
-
517
- get map() {
518
- return this.stringify().map
519
- }
520
-
521
- get messages() {
522
- return this.sync().messages
523
- }
524
-
525
- get opts() {
526
- return this.result.opts
527
- }
528
-
529
- get processor() {
530
- return this.result.processor
531
- }
532
-
533
- get root() {
534
- return this.sync().root
535
- }
536
-
537
- get [Symbol.toStringTag]() {
538
- return 'LazyResult'
539
- }
540
540
  }
541
541
 
542
542
  LazyResult.registerPostcss = dependant => {
@@ -26,11 +26,6 @@ declare class NoWorkResult_ implements LazyResult<Root> {
26
26
  catch: Promise<Result<Root>>['catch']
27
27
  finally: Promise<Result<Root>>['finally']
28
28
  then: Promise<Result<Root>>['then']
29
- constructor(processor: Processor, css: string, opts: ResultOptions)
30
- async(): Promise<Result<Root>>
31
- sync(): Result<Root>
32
- toString(): string
33
- warnings(): Warning[]
34
29
  get content(): string
35
30
  get css(): string
36
31
  get map(): SourceMap
@@ -39,6 +34,11 @@ declare class NoWorkResult_ implements LazyResult<Root> {
39
34
  get processor(): Processor
40
35
  get root(): Root
41
36
  get [Symbol.toStringTag](): string
37
+ constructor(processor: Processor, css: string, opts: ResultOptions)
38
+ async(): Promise<Result<Root>>
39
+ sync(): Result<Root>
40
+ toString(): string
41
+ warnings(): Warning[]
42
42
  }
43
43
 
44
44
  declare class NoWorkResult extends NoWorkResult_ {}
@@ -7,6 +7,56 @@ let stringify = require('./stringify')
7
7
  let warnOnce = require('./warn-once')
8
8
 
9
9
  class NoWorkResult {
10
+ get content() {
11
+ return this.result.css
12
+ }
13
+
14
+ get css() {
15
+ return this.result.css
16
+ }
17
+
18
+ get map() {
19
+ return this.result.map
20
+ }
21
+
22
+ get messages() {
23
+ return []
24
+ }
25
+
26
+ get opts() {
27
+ return this.result.opts
28
+ }
29
+
30
+ get processor() {
31
+ return this.result.processor
32
+ }
33
+
34
+ get root() {
35
+ if (this._root) {
36
+ return this._root
37
+ }
38
+
39
+ let root
40
+ let parser = parse
41
+
42
+ try {
43
+ root = parser(this._css, this._opts)
44
+ } catch (error) {
45
+ this.error = error
46
+ }
47
+
48
+ if (this.error) {
49
+ throw this.error
50
+ } else {
51
+ this._root = root
52
+ return root
53
+ }
54
+ }
55
+
56
+ get [Symbol.toStringTag]() {
57
+ return 'NoWorkResult'
58
+ }
59
+
10
60
  constructor(processor, css, opts) {
11
61
  css = css.toString()
12
62
  this.stringified = false
@@ -82,56 +132,6 @@ class NoWorkResult {
82
132
  warnings() {
83
133
  return []
84
134
  }
85
-
86
- get content() {
87
- return this.result.css
88
- }
89
-
90
- get css() {
91
- return this.result.css
92
- }
93
-
94
- get map() {
95
- return this.result.map
96
- }
97
-
98
- get messages() {
99
- return []
100
- }
101
-
102
- get opts() {
103
- return this.result.opts
104
- }
105
-
106
- get processor() {
107
- return this.result.processor
108
- }
109
-
110
- get root() {
111
- if (this._root) {
112
- return this._root
113
- }
114
-
115
- let root
116
- let parser = parse
117
-
118
- try {
119
- root = parser(this._css, this._opts)
120
- } catch (error) {
121
- this.error = error
122
- }
123
-
124
- if (this.error) {
125
- throw this.error
126
- } else {
127
- this._root = root
128
- return root
129
- }
130
- }
131
-
132
- get [Symbol.toStringTag]() {
133
- return 'NoWorkResult'
134
- }
135
135
  }
136
136
 
137
137
  module.exports = NoWorkResult
package/lib/node.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import AtRule = require('./at-rule.js')
2
-
3
2
  import { AtRuleProps } from './at-rule.js'
4
3
  import Comment, { CommentProps } from './comment.js'
5
4
  import Container, { NewChild } from './container.js'
@@ -66,6 +65,22 @@ declare namespace Node {
66
65
  /**
67
66
  * The inclusive ending position for the source
68
67
  * code of a node.
68
+ *
69
+ * However, `end.offset` of a non `Root` node is the exclusive position.
70
+ * See https://github.com/postcss/postcss/pull/1879 for details.
71
+ *
72
+ * ```js
73
+ * const root = postcss.parse('a { color: black }')
74
+ * const a = root.first
75
+ * const color = a.first
76
+ *
77
+ * // The offset of `Root` node is the inclusive position
78
+ * css.source.end // { line: 1, column: 19, offset: 18 }
79
+ *
80
+ * // The offset of non `Root` node is the exclusive position
81
+ * a.source.end // { line: 1, column: 18, offset: 18 }
82
+ * color.source.end // { line: 1, column: 16, offset: 16 }
83
+ * ```
69
84
  */
70
85
  end?: Position
71
86
 
@@ -234,14 +249,6 @@ declare abstract class Node_ {
234
249
 
235
250
  constructor(defaults?: object)
236
251
 
237
- /**
238
- * If this node isn't already dirty, marks it and its ancestors as such. This
239
- * indicates to the LazyResult processor that the {@link Root} has been
240
- * modified by the current plugin and may need to be processed again by other
241
- * plugins.
242
- */
243
- protected markDirty(): void
244
-
245
252
  /**
246
253
  * Insert new node after current node to current node’s parent.
247
254
  *
@@ -432,7 +439,7 @@ declare abstract class Node_ {
432
439
  * @return Range.
433
440
  */
434
441
  rangeBy(
435
- opts?: Pick<WarningOptions, 'endIndex' | 'index' | 'word'>
442
+ opts?: Pick<WarningOptions, 'end' | 'endIndex' | 'index' | 'start' | 'word'>
436
443
  ): Node.Range
437
444
 
438
445
  /**
@@ -534,6 +541,14 @@ declare abstract class Node_ {
534
541
  * @return `Warning` instance is returned
535
542
  */
536
543
  warn(result: Result, message: string, options?: WarningOptions): Warning
544
+
545
+ /**
546
+ * If this node isn't already dirty, marks it and its ancestors as such. This
547
+ * indicates to the LazyResult processor that the {@link Root} has been
548
+ * modified by the current plugin and may need to be processed again by other
549
+ * plugins.
550
+ */
551
+ protected markDirty(): void
537
552
  }
538
553
 
539
554
  declare class Node extends Node_ {}
package/lib/node.js CHANGED
@@ -34,11 +34,8 @@ function cloneNode(obj, parent) {
34
34
 
35
35
  function sourceOffset(inputCSS, position) {
36
36
  // Not all custom syntaxes support `offset` in `source.start` and `source.end`
37
- if (
38
- position &&
39
- typeof position.offset !== 'undefined'
40
- ) {
41
- return position.offset;
37
+ if (position && typeof position.offset !== 'undefined') {
38
+ return position.offset
42
39
  }
43
40
 
44
41
  let column = 1
@@ -63,6 +60,10 @@ function sourceOffset(inputCSS, position) {
63
60
  }
64
61
 
65
62
  class Node {
63
+ get proxyOf() {
64
+ return this
65
+ }
66
+
66
67
  constructor(defaults = {}) {
67
68
  this.raws = {}
68
69
  this[isClean] = false
@@ -204,14 +205,15 @@ class Node {
204
205
  return this.parent.nodes[index + 1]
205
206
  }
206
207
 
207
- positionBy(opts) {
208
+ positionBy(opts = {}) {
208
209
  let pos = this.source.start
209
210
  if (opts.index) {
210
211
  pos = this.positionInside(opts.index)
211
212
  } else if (opts.word) {
212
- let inputString = ('document' in this.source.input)
213
- ? this.source.input.document
214
- : this.source.input.css
213
+ let inputString =
214
+ 'document' in this.source.input
215
+ ? this.source.input.document
216
+ : this.source.input.css
215
217
  let stringRepresentation = inputString.slice(
216
218
  sourceOffset(inputString, this.source.start),
217
219
  sourceOffset(inputString, this.source.end)
@@ -225,9 +227,10 @@ class Node {
225
227
  positionInside(index) {
226
228
  let column = this.source.start.column
227
229
  let line = this.source.start.line
228
- let inputString = ('document' in this.source.input)
229
- ? this.source.input.document
230
- : this.source.input.css
230
+ let inputString =
231
+ 'document' in this.source.input
232
+ ? this.source.input.document
233
+ : this.source.input.css
231
234
  let offset = sourceOffset(inputString, this.source.start)
232
235
  let end = offset + index
233
236
 
@@ -240,7 +243,7 @@ class Node {
240
243
  }
241
244
  }
242
245
 
243
- return { column, line }
246
+ return { column, line, offset: end }
244
247
  }
245
248
 
246
249
  prev() {
@@ -249,25 +252,36 @@ class Node {
249
252
  return this.parent.nodes[index - 1]
250
253
  }
251
254
 
252
- rangeBy(opts) {
255
+ rangeBy(opts = {}) {
256
+ let inputString =
257
+ 'document' in this.source.input
258
+ ? this.source.input.document
259
+ : this.source.input.css
253
260
  let start = {
254
261
  column: this.source.start.column,
255
- line: this.source.start.line
262
+ line: this.source.start.line,
263
+ offset: sourceOffset(inputString, this.source.start)
256
264
  }
257
265
  let end = this.source.end
258
266
  ? {
259
267
  column: this.source.end.column + 1,
260
- line: this.source.end.line
268
+ line: this.source.end.line,
269
+ offset:
270
+ typeof this.source.end.offset === 'number'
271
+ ? // `source.end.offset` is exclusive, so we don't need to add 1
272
+ this.source.end.offset
273
+ : // Since line/column in this.source.end is inclusive,
274
+ // the `sourceOffset(... , this.source.end)` returns an inclusive offset.
275
+ // So, we add 1 to convert it to exclusive.
276
+ sourceOffset(inputString, this.source.end) + 1
261
277
  }
262
278
  : {
263
279
  column: start.column + 1,
264
- line: start.line
280
+ line: start.line,
281
+ offset: start.offset + 1
265
282
  }
266
283
 
267
284
  if (opts.word) {
268
- let inputString = ('document' in this.source.input)
269
- ? this.source.input.document
270
- : this.source.input.css
271
285
  let stringRepresentation = inputString.slice(
272
286
  sourceOffset(inputString, this.source.start),
273
287
  sourceOffset(inputString, this.source.end)
@@ -275,15 +289,14 @@ class Node {
275
289
  let index = stringRepresentation.indexOf(opts.word)
276
290
  if (index !== -1) {
277
291
  start = this.positionInside(index)
278
- end = this.positionInside(
279
- index + opts.word.length,
280
- )
292
+ end = this.positionInside(index + opts.word.length)
281
293
  }
282
294
  } else {
283
295
  if (opts.start) {
284
296
  start = {
285
297
  column: opts.start.column,
286
- line: opts.start.line
298
+ line: opts.start.line,
299
+ offset: sourceOffset(inputString, opts.start)
287
300
  }
288
301
  } else if (opts.index) {
289
302
  start = this.positionInside(opts.index)
@@ -292,7 +305,8 @@ class Node {
292
305
  if (opts.end) {
293
306
  end = {
294
307
  column: opts.end.column,
295
- line: opts.end.line
308
+ line: opts.end.line,
309
+ offset: sourceOffset(inputString, opts.end)
296
310
  }
297
311
  } else if (typeof opts.endIndex === 'number') {
298
312
  end = this.positionInside(opts.endIndex)
@@ -305,7 +319,11 @@ class Node {
305
319
  end.line < start.line ||
306
320
  (end.line === start.line && end.column <= start.column)
307
321
  ) {
308
- end = { column: start.column + 1, line: start.line }
322
+ end = {
323
+ column: start.column + 1,
324
+ line: start.line,
325
+ offset: start.offset + 1
326
+ }
309
327
  }
310
328
 
311
329
  return { end, start }
@@ -380,6 +398,7 @@ class Node {
380
398
  } else if (typeof value === 'object' && value.toJSON) {
381
399
  fixed[name] = value.toJSON(null, inputs)
382
400
  } else if (name === 'source') {
401
+ if (value == null) continue
383
402
  let inputId = inputs.get(value.input)
384
403
  if (inputId == null) {
385
404
  inputId = inputsNextIndex
@@ -419,15 +438,11 @@ class Node {
419
438
  return result
420
439
  }
421
440
 
422
- warn(result, text, opts) {
441
+ warn(result, text, opts = {}) {
423
442
  let data = { node: this }
424
443
  for (let i in opts) data[i] = opts[i]
425
444
  return result.warn(text, data)
426
445
  }
427
-
428
- get proxyOf() {
429
- return this
430
- }
431
446
  }
432
447
 
433
448
  module.exports = Node
package/lib/parser.js CHANGED
@@ -593,7 +593,7 @@ class Parser {
593
593
 
594
594
  unknownWord(tokens) {
595
595
  throw this.input.error(
596
- 'Unknown word',
596
+ 'Unknown word ' + tokens[0][1],
597
597
  { offset: tokens[0][2] },
598
598
  { offset: tokens[0][2] + tokens[0][1].length }
599
599
  )
package/lib/postcss.d.mts CHANGED
@@ -1,69 +1,69 @@
1
1
  export {
2
- // postcss function / namespace
3
- default,
4
-
5
- // Value exports from postcss.mjs
6
- stringify,
7
- fromJSON,
8
- // @ts-expect-error This value exists, but it’s untyped.
9
- plugin,
10
- parse,
11
- list,
12
- document,
13
- comment,
14
- atRule,
15
- rule,
16
- decl,
17
- root,
18
- CssSyntaxError,
19
- Declaration,
20
- Container,
21
- Processor,
22
- Document,
23
- Comment,
24
- Warning,
25
- AtRule,
26
- Result,
27
- Input,
28
- Rule,
29
- Root,
30
- Node,
31
-
32
2
  // Type-only exports
33
3
  AcceptedPlugin,
4
+
34
5
  AnyNode,
6
+ atRule,
7
+ AtRule,
35
8
  AtRuleProps,
36
9
  Builder,
37
10
  ChildNode,
38
11
  ChildProps,
12
+ comment,
13
+ Comment,
39
14
  CommentProps,
15
+ Container,
40
16
  ContainerProps,
17
+ CssSyntaxError,
18
+ decl,
19
+ Declaration,
41
20
  DeclarationProps,
21
+ // postcss function / namespace
22
+ default,
23
+ document,
24
+ Document,
42
25
  DocumentProps,
43
26
  FilePosition,
27
+ fromJSON,
44
28
  Helpers,
29
+ Input,
30
+
45
31
  JSONHydrator,
32
+ // This is a class, but it’s not re-exported. That’s why it’s exported as type-only here.
33
+ type LazyResult,
34
+ list,
46
35
  Message,
36
+ Node,
47
37
  NodeErrorOptions,
48
38
  NodeProps,
49
39
  OldPlugin,
40
+ parse,
50
41
  Parser,
42
+ // @ts-expect-error This value exists, but it’s untyped.
43
+ plugin,
51
44
  Plugin,
52
45
  PluginCreator,
53
46
  Position,
54
47
  Postcss,
55
48
  ProcessOptions,
49
+ Processor,
50
+ Result,
51
+ root,
52
+ Root,
56
53
  RootProps,
54
+ rule,
55
+ Rule,
57
56
  RuleProps,
58
57
  Source,
59
58
  SourceMap,
60
59
  SourceMapOptions,
61
60
  Stringifier,
61
+ // Value exports from postcss.mjs
62
+ stringify,
62
63
  Syntax,
63
64
  TransformCallback,
64
65
  Transformer,
65
- WarningOptions,
66
+ Warning,
66
67
 
67
- // This is a class, but it’s not re-exported. That’s why it’s exported as type-only here.
68
- type LazyResult
68
+ WarningOptions
69
69
  } from './postcss.js'
package/lib/processor.js CHANGED
@@ -7,7 +7,7 @@ let Root = require('./root')
7
7
 
8
8
  class Processor {
9
9
  constructor(plugins = []) {
10
- this.version = '8.5.2'
10
+ this.version = '8.5.4'
11
11
  this.plugins = this.normalize(plugins)
12
12
  }
13
13
 
package/lib/result.d.ts CHANGED
@@ -142,6 +142,16 @@ declare class Result_<RootNode = Document | Root> {
142
142
  */
143
143
  root: RootNode
144
144
 
145
+ /**
146
+ * An alias for the `Result#css` property.
147
+ * Use it with syntaxes that generate non-CSS output.
148
+ *
149
+ * ```js
150
+ * result.css === result.content
151
+ * ```
152
+ */
153
+ get content(): string
154
+
145
155
  /**
146
156
  * @param processor Processor used for this transformation.
147
157
  * @param root Root node after all transformations.
@@ -188,16 +198,6 @@ declare class Result_<RootNode = Document | Root> {
188
198
  * @return Warnings from plugins.
189
199
  */
190
200
  warnings(): Warning[]
191
-
192
- /**
193
- * An alias for the `Result#css` property.
194
- * Use it with syntaxes that generate non-CSS output.
195
- *
196
- * ```js
197
- * result.css === result.content
198
- * ```
199
- */
200
- get content(): string
201
201
  }
202
202
 
203
203
  declare class Result<RootNode = Document | Root> extends Result_<RootNode> {}