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.
- package/README.md +1 -1
- package/lib/at-rule.d.ts +9 -9
- package/lib/comment.d.ts +7 -7
- package/lib/container.d.ts +45 -48
- package/lib/container.js +10 -10
- package/lib/declaration.d.ts +9 -9
- package/lib/declaration.js +4 -4
- package/lib/input.d.ts +38 -19
- package/lib/input.js +40 -26
- package/lib/lazy-result.d.ts +40 -40
- package/lib/lazy-result.js +32 -32
- package/lib/no-work-result.d.ts +5 -5
- package/lib/no-work-result.js +50 -50
- package/lib/node.d.ts +25 -10
- package/lib/node.js +46 -31
- package/lib/parser.js +1 -1
- package/lib/postcss.d.mts +33 -33
- package/lib/processor.js +1 -1
- package/lib/result.d.ts +10 -10
- package/lib/result.js +5 -5
- package/lib/rule.d.ts +8 -8
- package/lib/rule.js +6 -6
- package/lib/stringifier.d.ts +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
@@ -9,7 +9,7 @@ These plugins can lint your CSS, support variables and mixins,
|
|
9
9
|
transpile future CSS syntax, inline images, and more.
|
10
10
|
|
11
11
|
PostCSS is used by industry leaders including Wikipedia, Twitter, Alibaba,
|
12
|
-
and JetBrains. The [Autoprefixer] and [Stylelint] PostCSS plugins
|
12
|
+
and JetBrains. The [Autoprefixer] and [Stylelint] PostCSS plugins are some of the most popular CSS tools.
|
13
13
|
|
14
14
|
---
|
15
15
|
|
package/lib/at-rule.d.ts
CHANGED
@@ -97,19 +97,11 @@ declare class AtRule_ extends Container {
|
|
97
97
|
* layer.nodes //=> undefined
|
98
98
|
* ```
|
99
99
|
*/
|
100
|
-
nodes: Container['nodes']
|
100
|
+
nodes: Container['nodes'] | undefined
|
101
101
|
parent: ContainerWithChildren | undefined
|
102
102
|
|
103
103
|
raws: AtRule.AtRuleRaws
|
104
104
|
type: 'atrule'
|
105
|
-
constructor(defaults?: AtRule.AtRuleProps)
|
106
|
-
assign(overrides: AtRule.AtRuleProps | object): this
|
107
|
-
|
108
|
-
clone(overrides?: Partial<AtRule.AtRuleProps>): this
|
109
|
-
|
110
|
-
cloneAfter(overrides?: Partial<AtRule.AtRuleProps>): this
|
111
|
-
|
112
|
-
cloneBefore(overrides?: Partial<AtRule.AtRuleProps>): this
|
113
105
|
/**
|
114
106
|
* The at-rule’s name immediately follows the `@`.
|
115
107
|
*
|
@@ -121,6 +113,7 @@ declare class AtRule_ extends Container {
|
|
121
113
|
*/
|
122
114
|
get name(): string
|
123
115
|
set name(value: string)
|
116
|
+
|
124
117
|
/**
|
125
118
|
* The at-rule’s parameters, the values that follow the at-rule’s name
|
126
119
|
* but precede any `{}` block.
|
@@ -132,7 +125,14 @@ declare class AtRule_ extends Container {
|
|
132
125
|
* ```
|
133
126
|
*/
|
134
127
|
get params(): string
|
128
|
+
|
135
129
|
set params(value: string)
|
130
|
+
|
131
|
+
constructor(defaults?: AtRule.AtRuleProps)
|
132
|
+
assign(overrides: AtRule.AtRuleProps | object): this
|
133
|
+
clone(overrides?: Partial<AtRule.AtRuleProps>): this
|
134
|
+
cloneAfter(overrides?: Partial<AtRule.AtRuleProps>): this
|
135
|
+
cloneBefore(overrides?: Partial<AtRule.AtRuleProps>): this
|
136
136
|
}
|
137
137
|
|
138
138
|
declare class AtRule extends AtRule_ {}
|
package/lib/comment.d.ts
CHANGED
@@ -49,18 +49,18 @@ declare class Comment_ extends Node {
|
|
49
49
|
parent: Container | undefined
|
50
50
|
raws: Comment.CommentRaws
|
51
51
|
type: 'comment'
|
52
|
-
constructor(defaults?: Comment.CommentProps)
|
53
|
-
|
54
|
-
assign(overrides: Comment.CommentProps | object): this
|
55
|
-
|
56
|
-
clone(overrides?: Partial<Comment.CommentProps>): this
|
57
|
-
cloneAfter(overrides?: Partial<Comment.CommentProps>): this
|
58
|
-
cloneBefore(overrides?: Partial<Comment.CommentProps>): this
|
59
52
|
/**
|
60
53
|
* The comment's text.
|
61
54
|
*/
|
62
55
|
get text(): string
|
56
|
+
|
63
57
|
set text(value: string)
|
58
|
+
|
59
|
+
constructor(defaults?: Comment.CommentProps)
|
60
|
+
assign(overrides: Comment.CommentProps | object): this
|
61
|
+
clone(overrides?: Partial<Comment.CommentProps>): this
|
62
|
+
cloneAfter(overrides?: Partial<Comment.CommentProps>): this
|
63
|
+
cloneBefore(overrides?: Partial<Comment.CommentProps>): this
|
64
64
|
}
|
65
65
|
|
66
66
|
declare class Comment extends Comment_ {}
|
package/lib/container.d.ts
CHANGED
@@ -65,25 +65,22 @@ declare abstract class Container_<Child extends Node = ChildNode> extends Node {
|
|
65
65
|
nodes: Child[] | undefined
|
66
66
|
|
67
67
|
/**
|
68
|
-
*
|
69
|
-
* child nodes that can then be added to this container.
|
70
|
-
*
|
71
|
-
* This ensures that the nodes' parent is set to this container, that they use
|
72
|
-
* the correct prototype chain, and that they're marked as dirty.
|
68
|
+
* The container’s first child.
|
73
69
|
*
|
74
|
-
*
|
75
|
-
*
|
76
|
-
*
|
77
|
-
* @param type This should be set to `'prepend'` if the new nodes will be
|
78
|
-
* inserted at the beginning of the container.
|
79
|
-
* @hidden
|
70
|
+
* ```js
|
71
|
+
* rule.first === rules.nodes[0]
|
72
|
+
* ```
|
80
73
|
*/
|
81
|
-
|
82
|
-
nodes: Container.NewChild,
|
83
|
-
sample: Node | undefined,
|
84
|
-
type?: 'prepend' | false
|
85
|
-
): Child[]
|
74
|
+
get first(): Child | undefined
|
86
75
|
|
76
|
+
/**
|
77
|
+
* The container’s last child.
|
78
|
+
*
|
79
|
+
* ```js
|
80
|
+
* rule.last === rule.nodes[rule.nodes.length - 1]
|
81
|
+
* ```
|
82
|
+
*/
|
83
|
+
get last(): Child | undefined
|
87
84
|
/**
|
88
85
|
* Inserts new nodes to the end of the container.
|
89
86
|
*
|
@@ -107,10 +104,10 @@ declare abstract class Container_<Child extends Node = ChildNode> extends Node {
|
|
107
104
|
append(...nodes: Container.NewChild[]): this
|
108
105
|
assign(overrides: Container.ContainerProps | object): this
|
109
106
|
clone(overrides?: Partial<Container.ContainerProps>): this
|
107
|
+
|
110
108
|
cloneAfter(overrides?: Partial<Container.ContainerProps>): this
|
111
109
|
|
112
110
|
cloneBefore(overrides?: Partial<Container.ContainerProps>): this
|
113
|
-
|
114
111
|
/**
|
115
112
|
* Iterates through the container’s immediate children,
|
116
113
|
* calling `callback` for each child.
|
@@ -147,6 +144,7 @@ declare abstract class Container_<Child extends Node = ChildNode> extends Node {
|
|
147
144
|
each(
|
148
145
|
callback: (node: Child, index: number) => false | void
|
149
146
|
): false | undefined
|
147
|
+
|
150
148
|
/**
|
151
149
|
* Returns `true` if callback returns `true`
|
152
150
|
* for all of the container’s children.
|
@@ -161,7 +159,6 @@ declare abstract class Container_<Child extends Node = ChildNode> extends Node {
|
|
161
159
|
every(
|
162
160
|
condition: (node: Child, index: number, nodes: Child[]) => boolean
|
163
161
|
): boolean
|
164
|
-
|
165
162
|
/**
|
166
163
|
* Returns a `child`’s index within the `Container#nodes` array.
|
167
164
|
*
|
@@ -173,6 +170,7 @@ declare abstract class Container_<Child extends Node = ChildNode> extends Node {
|
|
173
170
|
* @return Child index.
|
174
171
|
*/
|
175
172
|
index(child: Child | number): number
|
173
|
+
|
176
174
|
/**
|
177
175
|
* Insert new node after old node within the container.
|
178
176
|
*
|
@@ -182,19 +180,6 @@ declare abstract class Container_<Child extends Node = ChildNode> extends Node {
|
|
182
180
|
*/
|
183
181
|
insertAfter(oldNode: Child | number, newNode: Container.NewChild): this
|
184
182
|
|
185
|
-
/**
|
186
|
-
* Insert new node before old node within the container.
|
187
|
-
*
|
188
|
-
* ```js
|
189
|
-
* rule.insertBefore(decl, decl.clone({ prop: '-webkit-' + decl.prop }))
|
190
|
-
* ```
|
191
|
-
*
|
192
|
-
* @param oldNode Child or child’s index.
|
193
|
-
* @param newNode New node.
|
194
|
-
* @return This node for methods chain.
|
195
|
-
*/
|
196
|
-
insertBefore(oldNode: Child | number, newNode: Container.NewChild): this
|
197
|
-
|
198
183
|
/**
|
199
184
|
* Traverses the container’s descendant nodes, calling callback
|
200
185
|
* for each comment node.
|
@@ -212,6 +197,18 @@ declare abstract class Container_<Child extends Node = ChildNode> extends Node {
|
|
212
197
|
* @return Returns `false` if iteration was broke.
|
213
198
|
*/
|
214
199
|
|
200
|
+
/**
|
201
|
+
* Insert new node before old node within the container.
|
202
|
+
*
|
203
|
+
* ```js
|
204
|
+
* rule.insertBefore(decl, decl.clone({ prop: '-webkit-' + decl.prop }))
|
205
|
+
* ```
|
206
|
+
*
|
207
|
+
* @param oldNode Child or child’s index.
|
208
|
+
* @param newNode New node.
|
209
|
+
* @return This node for methods chain.
|
210
|
+
*/
|
211
|
+
insertBefore(oldNode: Child | number, newNode: Container.NewChild): this
|
215
212
|
/**
|
216
213
|
* Inserts new nodes to the start of the container.
|
217
214
|
*
|
@@ -233,6 +230,7 @@ declare abstract class Container_<Child extends Node = ChildNode> extends Node {
|
|
233
230
|
* @return This node for methods chain.
|
234
231
|
*/
|
235
232
|
prepend(...nodes: Container.NewChild[]): this
|
233
|
+
|
236
234
|
/**
|
237
235
|
* Add child to the end of the node.
|
238
236
|
*
|
@@ -278,7 +276,6 @@ declare abstract class Container_<Child extends Node = ChildNode> extends Node {
|
|
278
276
|
pattern: RegExp | string,
|
279
277
|
replaced: { (substring: string, ...args: any[]): string } | string
|
280
278
|
): this
|
281
|
-
|
282
279
|
/**
|
283
280
|
* Passes all declaration values within the container that match pattern
|
284
281
|
* through callback, replacing those values with the returned result
|
@@ -379,14 +376,13 @@ declare abstract class Container_<Child extends Node = ChildNode> extends Node {
|
|
379
376
|
nameFilter: RegExp | string,
|
380
377
|
callback: (atRule: AtRule, index: number) => false | void
|
381
378
|
): false | undefined
|
382
|
-
|
383
379
|
walkAtRules(
|
384
380
|
callback: (atRule: AtRule, index: number) => false | void
|
385
381
|
): false | undefined
|
382
|
+
|
386
383
|
walkComments(
|
387
384
|
callback: (comment: Comment, indexed: number) => false | void
|
388
385
|
): false | undefined
|
389
|
-
|
390
386
|
walkComments(
|
391
387
|
callback: (comment: Comment, indexed: number) => false | void
|
392
388
|
): false | undefined
|
@@ -424,11 +420,9 @@ declare abstract class Container_<Child extends Node = ChildNode> extends Node {
|
|
424
420
|
propFilter: RegExp | string,
|
425
421
|
callback: (decl: Declaration, index: number) => false | void
|
426
422
|
): false | undefined
|
427
|
-
|
428
423
|
walkDecls(
|
429
424
|
callback: (decl: Declaration, index: number) => false | void
|
430
425
|
): false | undefined
|
431
|
-
|
432
426
|
/**
|
433
427
|
* Traverses the container’s descendant nodes, calling callback
|
434
428
|
* for each rule node.
|
@@ -459,21 +453,24 @@ declare abstract class Container_<Child extends Node = ChildNode> extends Node {
|
|
459
453
|
callback: (rule: Rule, index: number) => false | void
|
460
454
|
): false | undefined
|
461
455
|
/**
|
462
|
-
*
|
456
|
+
* An internal method that converts a {@link NewChild} into a list of actual
|
457
|
+
* child nodes that can then be added to this container.
|
463
458
|
*
|
464
|
-
*
|
465
|
-
*
|
466
|
-
* ```
|
467
|
-
*/
|
468
|
-
get first(): Child | undefined
|
469
|
-
/**
|
470
|
-
* The container’s last child.
|
459
|
+
* This ensures that the nodes' parent is set to this container, that they use
|
460
|
+
* the correct prototype chain, and that they're marked as dirty.
|
471
461
|
*
|
472
|
-
*
|
473
|
-
*
|
474
|
-
*
|
462
|
+
* @param mnodes The new node or nodes to add.
|
463
|
+
* @param sample A node from whose raws the new node's `before` raw should be
|
464
|
+
* taken.
|
465
|
+
* @param type This should be set to `'prepend'` if the new nodes will be
|
466
|
+
* inserted at the beginning of the container.
|
467
|
+
* @hidden
|
475
468
|
*/
|
476
|
-
|
469
|
+
protected normalize(
|
470
|
+
nodes: Container.NewChild,
|
471
|
+
sample: Node | undefined,
|
472
|
+
type?: 'prepend' | false
|
473
|
+
): Child[]
|
477
474
|
}
|
478
475
|
|
479
476
|
declare class Container<
|
package/lib/container.js
CHANGED
@@ -25,6 +25,16 @@ function markTreeDirty(node) {
|
|
25
25
|
}
|
26
26
|
|
27
27
|
class Container extends Node {
|
28
|
+
get first() {
|
29
|
+
if (!this.proxyOf.nodes) return undefined
|
30
|
+
return this.proxyOf.nodes[0]
|
31
|
+
}
|
32
|
+
|
33
|
+
get last() {
|
34
|
+
if (!this.proxyOf.nodes) return undefined
|
35
|
+
return this.proxyOf.nodes[this.proxyOf.nodes.length - 1]
|
36
|
+
}
|
37
|
+
|
28
38
|
append(...children) {
|
29
39
|
for (let child of children) {
|
30
40
|
let nodes = this.normalize(child, this.last)
|
@@ -391,16 +401,6 @@ class Container extends Node {
|
|
391
401
|
}
|
392
402
|
})
|
393
403
|
}
|
394
|
-
|
395
|
-
get first() {
|
396
|
-
if (!this.proxyOf.nodes) return undefined
|
397
|
-
return this.proxyOf.nodes[0]
|
398
|
-
}
|
399
|
-
|
400
|
-
get last() {
|
401
|
-
if (!this.proxyOf.nodes) return undefined
|
402
|
-
return this.proxyOf.nodes[this.proxyOf.nodes.length - 1]
|
403
|
-
}
|
404
404
|
}
|
405
405
|
|
406
406
|
Container.registerParse = dependant => {
|
package/lib/declaration.d.ts
CHANGED
@@ -68,14 +68,6 @@ declare class Declaration_ extends Node {
|
|
68
68
|
|
69
69
|
type: 'decl'
|
70
70
|
|
71
|
-
constructor(defaults?: Declaration.DeclarationProps)
|
72
|
-
assign(overrides: Declaration.DeclarationProps | object): this
|
73
|
-
|
74
|
-
clone(overrides?: Partial<Declaration.DeclarationProps>): this
|
75
|
-
|
76
|
-
cloneAfter(overrides?: Partial<Declaration.DeclarationProps>): this
|
77
|
-
|
78
|
-
cloneBefore(overrides?: Partial<Declaration.DeclarationProps>): this
|
79
71
|
/**
|
80
72
|
* It represents a specificity of the declaration.
|
81
73
|
*
|
@@ -91,8 +83,8 @@ declare class Declaration_ extends Node {
|
|
91
83
|
* ```
|
92
84
|
*/
|
93
85
|
get important(): boolean
|
94
|
-
|
95
86
|
set important(value: boolean)
|
87
|
+
|
96
88
|
/**
|
97
89
|
* The property name for a CSS declaration.
|
98
90
|
*
|
@@ -106,6 +98,7 @@ declare class Declaration_ extends Node {
|
|
106
98
|
get prop(): string
|
107
99
|
|
108
100
|
set prop(value: string)
|
101
|
+
|
109
102
|
/**
|
110
103
|
* The property value for a CSS declaration.
|
111
104
|
*
|
@@ -125,6 +118,7 @@ declare class Declaration_ extends Node {
|
|
125
118
|
*/
|
126
119
|
get value(): string
|
127
120
|
set value(value: string)
|
121
|
+
|
128
122
|
/**
|
129
123
|
* It represents a getter that returns `true` if a declaration starts with
|
130
124
|
* `--` or `$`, which are used to declare variables in CSS and SASS/SCSS.
|
@@ -144,6 +138,12 @@ declare class Declaration_ extends Node {
|
|
144
138
|
* ```
|
145
139
|
*/
|
146
140
|
get variable(): boolean
|
141
|
+
constructor(defaults?: Declaration.DeclarationProps)
|
142
|
+
|
143
|
+
assign(overrides: Declaration.DeclarationProps | object): this
|
144
|
+
clone(overrides?: Partial<Declaration.DeclarationProps>): this
|
145
|
+
cloneAfter(overrides?: Partial<Declaration.DeclarationProps>): this
|
146
|
+
cloneBefore(overrides?: Partial<Declaration.DeclarationProps>): this
|
147
147
|
}
|
148
148
|
|
149
149
|
declare class Declaration extends Declaration_ {}
|
package/lib/declaration.js
CHANGED
@@ -3,6 +3,10 @@
|
|
3
3
|
let Node = require('./node')
|
4
4
|
|
5
5
|
class Declaration extends Node {
|
6
|
+
get variable() {
|
7
|
+
return this.prop.startsWith('--') || this.prop[0] === '$'
|
8
|
+
}
|
9
|
+
|
6
10
|
constructor(defaults) {
|
7
11
|
if (
|
8
12
|
defaults &&
|
@@ -14,10 +18,6 @@ class Declaration extends Node {
|
|
14
18
|
super(defaults)
|
15
19
|
this.type = 'decl'
|
16
20
|
}
|
17
|
-
|
18
|
-
get variable() {
|
19
|
-
return this.prop.startsWith('--') || this.prop[0] === '$'
|
20
|
-
}
|
21
21
|
}
|
22
22
|
|
23
23
|
module.exports = Declaration
|
package/lib/input.d.ts
CHANGED
@@ -18,6 +18,11 @@ declare namespace Input {
|
|
18
18
|
*/
|
19
19
|
endLine?: number
|
20
20
|
|
21
|
+
/**
|
22
|
+
* Offset of exclusive end position in source file.
|
23
|
+
*/
|
24
|
+
endOffset?: number
|
25
|
+
|
21
26
|
/**
|
22
27
|
* Absolute path to the source file.
|
23
28
|
*/
|
@@ -28,6 +33,11 @@ declare namespace Input {
|
|
28
33
|
*/
|
29
34
|
line: number
|
30
35
|
|
36
|
+
/**
|
37
|
+
* Offset of inclusive start position in source file.
|
38
|
+
*/
|
39
|
+
offset: number
|
40
|
+
|
31
41
|
/**
|
32
42
|
* Source code.
|
33
43
|
*/
|
@@ -111,12 +121,29 @@ declare class Input_ {
|
|
111
121
|
*/
|
112
122
|
map: PreviousMap
|
113
123
|
|
124
|
+
/**
|
125
|
+
* The CSS source identifier. Contains `Input#file` if the user
|
126
|
+
* set the `from` option, or `Input#id` if they did not.
|
127
|
+
*
|
128
|
+
* ```js
|
129
|
+
* const root = postcss.parse(css, { from: 'a.css' })
|
130
|
+
* root.source.input.from //=> "/home/ai/a.css"
|
131
|
+
*
|
132
|
+
* const root = postcss.parse(css)
|
133
|
+
* root.source.input.from //=> "<input css 1>"
|
134
|
+
* ```
|
135
|
+
*/
|
136
|
+
get from(): string
|
137
|
+
|
114
138
|
/**
|
115
139
|
* @param css Input CSS source.
|
116
140
|
* @param opts Process options.
|
117
141
|
*/
|
118
142
|
constructor(css: string, opts?: ProcessOptions)
|
119
143
|
|
144
|
+
/**
|
145
|
+
* Returns `CssSyntaxError` with information about the error and its position.
|
146
|
+
*/
|
120
147
|
error(
|
121
148
|
message: string,
|
122
149
|
start:
|
@@ -137,29 +164,34 @@ declare class Input_ {
|
|
137
164
|
},
|
138
165
|
opts?: { plugin?: CssSyntaxError['plugin'] }
|
139
166
|
): CssSyntaxError
|
140
|
-
|
141
|
-
/**
|
142
|
-
* Returns `CssSyntaxError` with information about the error and its position.
|
143
|
-
*/
|
144
167
|
error(
|
145
168
|
message: string,
|
146
169
|
line: number,
|
147
170
|
column: number,
|
148
171
|
opts?: { plugin?: CssSyntaxError['plugin'] }
|
149
172
|
): CssSyntaxError
|
150
|
-
|
151
173
|
error(
|
152
174
|
message: string,
|
153
175
|
offset: number,
|
154
176
|
opts?: { plugin?: CssSyntaxError['plugin'] }
|
155
177
|
): CssSyntaxError
|
156
178
|
|
179
|
+
/**
|
180
|
+
* Converts source line and column to offset.
|
181
|
+
*
|
182
|
+
* @param line Source line.
|
183
|
+
* @param column Source column.
|
184
|
+
* @return Source offset.
|
185
|
+
*/
|
186
|
+
fromLineAndColumn(line: number, column: number): number
|
187
|
+
|
157
188
|
/**
|
158
189
|
* Converts source offset to line and column.
|
159
190
|
*
|
160
191
|
* @param offset Source offset.
|
161
192
|
*/
|
162
193
|
fromOffset(offset: number): { col: number; line: number } | null
|
194
|
+
|
163
195
|
/**
|
164
196
|
* Reads the input source map and returns a symbol position
|
165
197
|
* in the input source (e.g., in a Sass file that was compiled
|
@@ -185,22 +217,9 @@ declare class Input_ {
|
|
185
217
|
endLine?: number,
|
186
218
|
endColumn?: number
|
187
219
|
): false | Input.FilePosition
|
220
|
+
|
188
221
|
/** Converts this to a JSON-friendly object representation. */
|
189
222
|
toJSON(): object
|
190
|
-
|
191
|
-
/**
|
192
|
-
* The CSS source identifier. Contains `Input#file` if the user
|
193
|
-
* set the `from` option, or `Input#id` if they did not.
|
194
|
-
*
|
195
|
-
* ```js
|
196
|
-
* const root = postcss.parse(css, { from: 'a.css' })
|
197
|
-
* root.source.input.from //=> "/home/ai/a.css"
|
198
|
-
*
|
199
|
-
* const root = postcss.parse(css)
|
200
|
-
* root.source.input.from //=> "<input css 1>"
|
201
|
-
* ```
|
202
|
-
*/
|
203
|
-
get from(): string
|
204
223
|
}
|
205
224
|
|
206
225
|
declare class Input extends Input_ {}
|
package/lib/input.js
CHANGED
@@ -9,12 +9,31 @@ let CssSyntaxError = require('./css-syntax-error')
|
|
9
9
|
let PreviousMap = require('./previous-map')
|
10
10
|
let terminalHighlight = require('./terminal-highlight')
|
11
11
|
|
12
|
-
let
|
12
|
+
let lineToIndexCache = Symbol('lineToIndexCache')
|
13
13
|
|
14
14
|
let sourceMapAvailable = Boolean(SourceMapConsumer && SourceMapGenerator)
|
15
15
|
let pathAvailable = Boolean(resolve && isAbsolute)
|
16
16
|
|
17
|
+
function getLineToIndex(input) {
|
18
|
+
if (input[lineToIndexCache]) return input[lineToIndexCache]
|
19
|
+
let lines = input.css.split('\n')
|
20
|
+
let lineToIndex = new Array(lines.length)
|
21
|
+
let prevIndex = 0
|
22
|
+
|
23
|
+
for (let i = 0, l = lines.length; i < l; i++) {
|
24
|
+
lineToIndex[i] = prevIndex
|
25
|
+
prevIndex += lines[i].length + 1
|
26
|
+
}
|
27
|
+
|
28
|
+
input[lineToIndexCache] = lineToIndex
|
29
|
+
return lineToIndex
|
30
|
+
}
|
31
|
+
|
17
32
|
class Input {
|
33
|
+
get from() {
|
34
|
+
return this.file || this.id
|
35
|
+
}
|
36
|
+
|
18
37
|
constructor(css, opts = {}) {
|
19
38
|
if (
|
20
39
|
css === null ||
|
@@ -64,31 +83,38 @@ class Input {
|
|
64
83
|
}
|
65
84
|
|
66
85
|
error(message, line, column, opts = {}) {
|
67
|
-
let endColumn, endLine, result
|
86
|
+
let endColumn, endLine, endOffset, offset, result
|
68
87
|
|
69
88
|
if (line && typeof line === 'object') {
|
70
89
|
let start = line
|
71
90
|
let end = column
|
72
91
|
if (typeof start.offset === 'number') {
|
73
|
-
|
92
|
+
offset = start.offset
|
93
|
+
let pos = this.fromOffset(offset)
|
74
94
|
line = pos.line
|
75
95
|
column = pos.col
|
76
96
|
} else {
|
77
97
|
line = start.line
|
78
98
|
column = start.column
|
99
|
+
offset = this.fromLineAndColumn(line, column)
|
79
100
|
}
|
80
101
|
if (typeof end.offset === 'number') {
|
81
|
-
|
102
|
+
endOffset = end.offset
|
103
|
+
let pos = this.fromOffset(endOffset)
|
82
104
|
endLine = pos.line
|
83
105
|
endColumn = pos.col
|
84
106
|
} else {
|
85
107
|
endLine = end.line
|
86
108
|
endColumn = end.column
|
109
|
+
endOffset = this.fromLineAndColumn(end.line, end.column)
|
87
110
|
}
|
88
111
|
} else if (!column) {
|
89
|
-
|
112
|
+
offset = line
|
113
|
+
let pos = this.fromOffset(offset)
|
90
114
|
line = pos.line
|
91
115
|
column = pos.col
|
116
|
+
} else {
|
117
|
+
offset = this.fromLineAndColumn(line, column)
|
92
118
|
}
|
93
119
|
|
94
120
|
let origin = this.origin(line, column, endLine, endColumn)
|
@@ -116,7 +142,7 @@ class Input {
|
|
116
142
|
)
|
117
143
|
}
|
118
144
|
|
119
|
-
result.input = { column, endColumn, endLine, line, source: this.css }
|
145
|
+
result.input = { column, endColumn, endLine, endOffset, line, offset, source: this.css }
|
120
146
|
if (this.file) {
|
121
147
|
if (pathToFileURL) {
|
122
148
|
result.input.url = pathToFileURL(this.file).toString()
|
@@ -127,23 +153,15 @@ class Input {
|
|
127
153
|
return result
|
128
154
|
}
|
129
155
|
|
130
|
-
|
131
|
-
let
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
let prevIndex = 0
|
136
|
-
|
137
|
-
for (let i = 0, l = lines.length; i < l; i++) {
|
138
|
-
lineToIndex[i] = prevIndex
|
139
|
-
prevIndex += lines[i].length + 1
|
140
|
-
}
|
156
|
+
fromLineAndColumn(line, column) {
|
157
|
+
let lineToIndex = getLineToIndex(this)
|
158
|
+
let index = lineToIndex[line - 1]
|
159
|
+
return index + column - 1
|
160
|
+
}
|
141
161
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
}
|
146
|
-
lastLine = lineToIndex[lineToIndex.length - 1]
|
162
|
+
fromOffset(offset) {
|
163
|
+
let lineToIndex = getLineToIndex(this)
|
164
|
+
let lastLine = lineToIndex[lineToIndex.length - 1]
|
147
165
|
|
148
166
|
let min = 0
|
149
167
|
if (offset >= lastLine) {
|
@@ -237,10 +255,6 @@ class Input {
|
|
237
255
|
}
|
238
256
|
return json
|
239
257
|
}
|
240
|
-
|
241
|
-
get from() {
|
242
|
-
return this.file || this.id
|
243
|
-
}
|
244
258
|
}
|
245
259
|
|
246
260
|
module.exports = Input
|