@tbela99/css-parser 2.3.0 → 2.3.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.
- package/CHANGELOG.md +43 -0
- package/README.md +66 -21
- package/architecture.png +0 -0
- package/dist/ast/arena-node.js +32 -3
- package/dist/ast/arena.js +88 -10
- package/dist/ast/cache.js +1 -1
- package/dist/ast/features/calc.js +1 -1
- package/dist/ast/features/if.js +1 -1
- package/dist/ast/features/index.js +1 -1
- package/dist/ast/features/inlinecssvariables.js +1 -1
- package/dist/ast/features/mixin.js +1 -1
- package/dist/ast/features/prefix.js +1 -1
- package/dist/ast/features/shorthand.js +1 -1
- package/dist/ast/features/transform.js +1 -1
- package/dist/ast/features/type.js +1 -1
- package/dist/ast/math/expression.js +1 -1
- package/dist/ast/math/math.js +1 -1
- package/dist/ast/minify.js +131 -36
- package/dist/ast/mixins/custom-function.js +1 -1
- package/dist/ast/mixins/utils.js +1 -1
- package/dist/ast/mixins/variables.js +1 -1
- package/dist/ast/strings.js +26 -1
- package/dist/ast/transform/compute.js +6 -2
- package/dist/ast/transform/matrix.js +1 -1
- package/dist/ast/transform/minify.js +1 -1
- package/dist/ast/transform/perspective.js +1 -1
- package/dist/ast/transform/rotate.js +1 -1
- package/dist/ast/transform/scale.js +1 -1
- package/dist/ast/transform/skew.js +1 -1
- package/dist/ast/transform/translate.js +1 -1
- package/dist/ast/transform/utils.js +1 -1
- package/dist/ast/types.js +22 -2
- package/dist/ast/walk.js +1 -1
- package/dist/data/properties.json.js +1 -1
- package/dist/data/validation.json.js +1 -1
- package/dist/fs/resolve.js +1 -1
- package/dist/index-umd-web.js +1099 -295
- package/dist/index.d.ts +612 -688
- package/dist/node.js +14 -8
- package/dist/parser/declaration/list.js +8 -5
- package/dist/parser/declaration/map.js +1 -1
- package/dist/parser/declaration/set.js +1 -1
- package/dist/parser/input.js +62 -4
- package/dist/parser/linesmap.js +1 -1
- package/dist/parser/parse.js +121 -13
- package/dist/parser/source.js +1 -1
- package/dist/parser/tokenize.js +161 -19
- package/dist/parser/utils/angle.js +1 -1
- package/dist/parser/utils/at-rule-container.js +1 -1
- package/dist/parser/utils/at-rule-font-feature-values.js +1 -1
- package/dist/parser/utils/at-rule-generic.js +1 -1
- package/dist/parser/utils/at-rule-import.js +1 -1
- package/dist/parser/utils/at-rule-media.js +42 -2
- package/dist/parser/utils/at-rule-support.js +1 -1
- package/dist/parser/utils/at-rule-when-else.js +1 -1
- package/dist/parser/utils/at-rule.js +1 -1
- package/dist/parser/utils/base64.js +1 -1
- package/dist/parser/utils/cache.js +1 -1
- package/dist/parser/utils/canonical.js +1 -1
- package/dist/parser/utils/codes.js +1 -1
- package/dist/parser/utils/config.js +1 -1
- package/dist/parser/utils/declaration.js +1 -1
- package/dist/parser/utils/eq.js +1 -1
- package/dist/parser/utils/hash.js +1 -1
- package/dist/parser/utils/selector.js +98 -6
- package/dist/parser/utils/text.js +1 -1
- package/dist/parser/utils/token.js +1 -1
- package/dist/parser/utils/type.js +1 -1
- package/dist/printer/lib/codec.js +1 -1
- package/dist/printer/render.js +5 -7
- package/dist/printer/result.js +18 -3
- package/dist/printer/sourcemap.js +1 -1
- package/dist/printer/writer.js +1 -1
- package/dist/syntax/color/a98rgb.js +1 -1
- package/dist/syntax/color/alpha.js +1 -1
- package/dist/syntax/color/cmyk.js +1 -1
- package/dist/syntax/color/color-mix.js +1 -1
- package/dist/syntax/color/color.js +1 -1
- package/dist/syntax/color/hex.js +1 -1
- package/dist/syntax/color/hsl.js +12 -4
- package/dist/syntax/color/hwb.js +9 -3
- package/dist/syntax/color/lab.js +1 -1
- package/dist/syntax/color/lch.js +1 -1
- package/dist/syntax/color/oklab.js +1 -1
- package/dist/syntax/color/oklch.js +2 -2
- package/dist/syntax/color/p3.js +1 -1
- package/dist/syntax/color/prophotorgb.js +1 -1
- package/dist/syntax/color/rec2020.js +1 -1
- package/dist/syntax/color/relative-color.js +1 -1
- package/dist/syntax/color/rgb.js +1 -1
- package/dist/syntax/color/srgb.js +3 -2
- package/dist/syntax/color/utils/color-type.js +1 -1
- package/dist/syntax/color/utils/colorspace.js +1 -1
- package/dist/syntax/color/utils/components.js +1 -1
- package/dist/syntax/color/utils/distance.js +1 -1
- package/dist/syntax/color/utils/make-color.js +1 -1
- package/dist/syntax/color/utils/matrix.js +1 -1
- package/dist/syntax/color/xyz.js +1 -1
- package/dist/syntax/color/xyzd50.js +1 -1
- package/dist/syntax/constants.js +2 -2
- package/dist/syntax/syntax.js +1 -1
- package/dist/types.js +1 -1
- package/dist/utils/sync.js +1 -1
- package/dist/validation/compiled/builtins.js +1 -1
- package/dist/validation/compiled/runtime.js +1 -1
- package/dist/validation/compiled/syntaxes.js +1 -1
- package/dist/validation/config.js +1 -1
- package/dist/validation/first.js +1 -1
- package/dist/validation/match.js +77 -4
- package/dist/validation/parser/parse.js +1 -1
- package/dist/validation/parser/typedef.js +4 -1
- package/dist/validation/utils/list.js +1 -1
- package/dist/version.js +2 -2
- package/dist/web.js +13 -6
- package/package.json +15 -6
package/dist/node.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.3.
|
|
5
|
+
Version: 2.3.2
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { Readable } from 'node:stream';
|
|
@@ -16,9 +16,9 @@ import { TransformResult, RenderResult } from './printer/result.js';
|
|
|
16
16
|
import { useNativeBuffer } from './printer/writer.js';
|
|
17
17
|
import { Buffer } from 'node:buffer';
|
|
18
18
|
import { ModuleScopeEnumOptions } from './ast/types.js';
|
|
19
|
-
export { ColorType, EnumAstNodeStatus, EnumToken, ModuleCaseTransformEnum, WalkerEvent, WalkerOptionEnum } from './ast/types.js';
|
|
19
|
+
export { ColorType, EnumAstNodeStatus, EnumToken, MergeRulesEnum, ModuleCaseTransformEnum, WalkerEvent, WalkerOptionEnum } from './ast/types.js';
|
|
20
20
|
import { createParseInfo, Tokenizer } from './parser/tokenize.js';
|
|
21
|
-
import { isCssInput } from './parser/input.js';
|
|
21
|
+
import { setStreamSize, responseSize, isCssInput } from './parser/input.js';
|
|
22
22
|
import { resolve, matchUrl, dirname } from './fs/resolve.js';
|
|
23
23
|
import { ResponseType } from './types.js';
|
|
24
24
|
import { resolve as resolve$1 } from 'node:path';
|
|
@@ -31,6 +31,8 @@ export { isOkLabClose, okLabDistance } from './syntax/color/utils/distance.js';
|
|
|
31
31
|
export { Arena, AstArena, TokenField, arenaColumns } from './ast/arena.js';
|
|
32
32
|
export { ARENA, ARENAID, AstArenaNode } from './ast/arena-node.js';
|
|
33
33
|
export { SourceMap } from './printer/sourcemap.js';
|
|
34
|
+
export { ValidationTokenEnum } from './validation/parser/typedef.js';
|
|
35
|
+
export { LOC } from './syntax/constants.js';
|
|
34
36
|
export { FeatureWalkMode } from './ast/features/type.js';
|
|
35
37
|
export { parseSyntax } from './validation/parser/parse.js';
|
|
36
38
|
export { version } from './version.js';
|
|
@@ -66,7 +68,8 @@ async function load(url, currentDirectory = ".", responseType = false) {
|
|
|
66
68
|
return response.json();
|
|
67
69
|
}
|
|
68
70
|
return responseType === ResponseType.ReadableStream
|
|
69
|
-
?
|
|
71
|
+
? // the size of the body: the parser allocates its buffers once
|
|
72
|
+
setStreamSize(response.body, responseSize(response))
|
|
70
73
|
: response.text();
|
|
71
74
|
});
|
|
72
75
|
}
|
|
@@ -82,10 +85,11 @@ async function load(url, currentDirectory = ".", responseType = false) {
|
|
|
82
85
|
? buffer.buffer
|
|
83
86
|
: buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength));
|
|
84
87
|
}
|
|
85
|
-
|
|
88
|
+
// the size of the file: the parser allocates its buffers once
|
|
89
|
+
return setStreamSize(Readable.toWeb(createReadStream(resolved.absolute, {
|
|
86
90
|
encoding: "utf-8",
|
|
87
91
|
highWaterMark: 64 * 1024,
|
|
88
|
-
}));
|
|
92
|
+
})), stats.size);
|
|
89
93
|
}
|
|
90
94
|
}
|
|
91
95
|
catch (error) { }
|
|
@@ -217,7 +221,8 @@ function transformSync(...args) {
|
|
|
217
221
|
}
|
|
218
222
|
// the options of the caller are not modified: they may be reused
|
|
219
223
|
options = { ...options };
|
|
220
|
-
|
|
224
|
+
// the fast mode sets the default value of minify (see fastModeOptions)
|
|
225
|
+
if (options.minify == null && !options.fastMode) {
|
|
221
226
|
options.minify = true;
|
|
222
227
|
}
|
|
223
228
|
if (options.removeEmpty == null) {
|
|
@@ -410,7 +415,8 @@ async function transform(...args) {
|
|
|
410
415
|
}
|
|
411
416
|
// the options of the caller are not modified: they may be reused
|
|
412
417
|
options = { ...options };
|
|
413
|
-
|
|
418
|
+
// the fast mode sets the default value of minify (see fastModeOptions)
|
|
419
|
+
if (options.minify == null && !options.fastMode) {
|
|
414
420
|
options.minify = true;
|
|
415
421
|
}
|
|
416
422
|
if (options.removeEmpty == null) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.3.
|
|
5
|
+
Version: 2.3.2
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { PropertySet } from './set.js';
|
|
@@ -97,7 +97,8 @@ class PropertyList {
|
|
|
97
97
|
*/
|
|
98
98
|
options = { removeDuplicateDeclarations: true, computeShorthand: true };
|
|
99
99
|
/**
|
|
100
|
-
* declarations
|
|
100
|
+
* declarations, by property name
|
|
101
|
+
* @ignore
|
|
101
102
|
*/
|
|
102
103
|
declarations;
|
|
103
104
|
/**
|
|
@@ -114,8 +115,8 @@ class PropertyList {
|
|
|
114
115
|
*/
|
|
115
116
|
descriptors;
|
|
116
117
|
/**
|
|
117
|
-
*
|
|
118
|
-
* @param arena
|
|
118
|
+
* create an empty declaration list
|
|
119
|
+
* @param arena the arena the declarations are stored in
|
|
119
120
|
* @param options
|
|
120
121
|
* @param memo keys shared by the lists that use the same arena
|
|
121
122
|
* @param descriptors syntaxes of the descriptors of the at-rule that contains the declarations
|
|
@@ -294,6 +295,8 @@ class PropertyList {
|
|
|
294
295
|
return this;
|
|
295
296
|
}
|
|
296
297
|
/**
|
|
298
|
+
* Normalize the values of a declaration with the mapping of its property: the values are reordered by the patterns
|
|
299
|
+
* of the mapping, the keywords are replaced by their mapped value
|
|
297
300
|
*
|
|
298
301
|
* @param declaration
|
|
299
302
|
* @param mapping
|
|
@@ -358,7 +361,7 @@ class PropertyList {
|
|
|
358
361
|
}
|
|
359
362
|
}
|
|
360
363
|
/**
|
|
361
|
-
*
|
|
364
|
+
* iterate over the declarations, the shorthands are expanded into their declarations
|
|
362
365
|
* @returns
|
|
363
366
|
*/
|
|
364
367
|
[Symbol.iterator]() {
|
package/dist/parser/input.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.3.
|
|
5
|
+
Version: 2.3.2
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { nativeBufferClass } from '../printer/writer.js';
|
|
@@ -13,7 +13,30 @@ const encoder = new TextEncoder();
|
|
|
13
13
|
*/
|
|
14
14
|
const littleEndian = new Uint8Array(new Uint16Array([1]).buffer)[0] === 1;
|
|
15
15
|
const decoder = new TextDecoder();
|
|
16
|
-
|
|
16
|
+
/**
|
|
17
|
+
* true if the bytes are ascii. the bytes are read 4 at a time when they are aligned: 5 times faster than a regular
|
|
18
|
+
* expression on the decoded text
|
|
19
|
+
* @param bytes
|
|
20
|
+
*/
|
|
21
|
+
function isAscii(bytes) {
|
|
22
|
+
const length = bytes.length;
|
|
23
|
+
let bits = 0;
|
|
24
|
+
let i = 0;
|
|
25
|
+
if ((bytes.byteOffset & 3) === 0) {
|
|
26
|
+
const words = new Uint32Array(bytes.buffer, bytes.byteOffset, length >>> 2);
|
|
27
|
+
for (let k = 0; k < words.length; k++) {
|
|
28
|
+
bits |= words[k];
|
|
29
|
+
}
|
|
30
|
+
if ((bits & 0x80808080) !== 0) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
i = words.length << 2;
|
|
34
|
+
}
|
|
35
|
+
for (; i < length; i++) {
|
|
36
|
+
bits |= bytes[i];
|
|
37
|
+
}
|
|
38
|
+
return (bits & 0x80) === 0;
|
|
39
|
+
}
|
|
17
40
|
const empty = new Uint8Array(0);
|
|
18
41
|
/**
|
|
19
42
|
* true if the input is an ArrayBuffer or a view of an ArrayBuffer
|
|
@@ -76,10 +99,45 @@ function toCodeUnits(input) {
|
|
|
76
99
|
const bytes = bytesOf(input);
|
|
77
100
|
const text = decoder.decode(bytes);
|
|
78
101
|
// the text of an ascii input has a character for each byte. the byte order mark is removed by the decoder
|
|
79
|
-
if (text.length === bytes.length &&
|
|
102
|
+
if (text.length === bytes.length && isAscii(bytes)) {
|
|
80
103
|
return { codes: bytes, text };
|
|
81
104
|
}
|
|
82
105
|
return { codes: codeUnitsOf(text), text };
|
|
83
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* the size of the css of the streams, in bytes, when it is known (a file, a response with a content length)
|
|
109
|
+
*/
|
|
110
|
+
const streamSizes = new WeakMap();
|
|
111
|
+
/**
|
|
112
|
+
* record the size of the css of a stream, in bytes: the parser allocates the code units and the arena once, like for
|
|
113
|
+
* an ArrayBuffer, instead of growing them as the stream is read. 0: the size is not known
|
|
114
|
+
* @param stream
|
|
115
|
+
* @param size
|
|
116
|
+
*/
|
|
117
|
+
function setStreamSize(stream, size) {
|
|
118
|
+
if (size > 0) {
|
|
119
|
+
streamSizes.set(stream, size);
|
|
120
|
+
}
|
|
121
|
+
return stream;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* the size of the css of a stream, in bytes, see {@link setStreamSize}. 0: the size is not known
|
|
125
|
+
* @param stream
|
|
126
|
+
*/
|
|
127
|
+
function getStreamSize(stream) {
|
|
128
|
+
return stream == null ? 0 : (streamSizes.get(stream) ?? 0);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* the size of the body of a response: its content length, 0 when it is not known or when the body is compressed (the
|
|
132
|
+
* content length is the size of the compressed body)
|
|
133
|
+
* @param response
|
|
134
|
+
*/
|
|
135
|
+
function responseSize(response) {
|
|
136
|
+
if (response.headers.get("content-encoding") != null) {
|
|
137
|
+
return 0;
|
|
138
|
+
}
|
|
139
|
+
const length = Number(response.headers.get("content-length"));
|
|
140
|
+
return Number.isFinite(length) && length > 0 ? length : 0;
|
|
141
|
+
}
|
|
84
142
|
|
|
85
|
-
export { isBinaryInput, isCssInput, toCodeUnits };
|
|
143
|
+
export { getStreamSize, isBinaryInput, isCssInput, responseSize, setStreamSize, toCodeUnits };
|
package/dist/parser/linesmap.js
CHANGED
package/dist/parser/parse.js
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.3.
|
|
5
|
+
Version: 2.3.2
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { isIdentColor, parseColor, isColor } from '../syntax/syntax.js';
|
|
9
9
|
import { camelize, equalsIgnoreCase, dasherize } from './utils/text.js';
|
|
10
10
|
import { renderValue } from '../printer/render.js';
|
|
11
|
-
import { EnumToken, EnumAstNodeStatus, ModuleCaseTransformEnum, ModuleScopeEnumOptions, WalkerEvent } from '../ast/types.js';
|
|
12
|
-
import { minify } from '../ast/minify.js';
|
|
11
|
+
import { EnumToken, EnumAstNodeStatus, MergeRulesEnum, ModuleCaseTransformEnum, ModuleScopeEnumOptions, WalkerEvent } from '../ast/types.js';
|
|
12
|
+
import { minify, mergeRules } from '../ast/minify.js';
|
|
13
13
|
import { Tokenizer, createParseInfo } from './tokenize.js';
|
|
14
14
|
import { ResponseType } from '../types.js';
|
|
15
15
|
import { AstArena, TokenField } from '../ast/arena.js';
|
|
@@ -117,7 +117,8 @@ function clearArray(array) {
|
|
|
117
117
|
* @param tokenizer
|
|
118
118
|
*/
|
|
119
119
|
function arenaCapacity(tokenizer) {
|
|
120
|
-
|
|
120
|
+
// a stream: the size of the css when it is known, the arena is allocated as for an ArrayBuffer
|
|
121
|
+
const length = Math.max(tokenizer.streamLength, tokenizer.expectedLength);
|
|
121
122
|
// small inputs (css modules, inline styles, ...) do not allocate a large arena, the arena grows when needed
|
|
122
123
|
return length === 0 ? 4096 : Math.min(1 << 25, Math.ceil(length / 4) + 1024);
|
|
123
124
|
}
|
|
@@ -159,6 +160,29 @@ function allocateToken(arena, tokenizer, sourceIndex) {
|
|
|
159
160
|
}
|
|
160
161
|
return item;
|
|
161
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* allocate a whitespace token
|
|
165
|
+
* @param arena
|
|
166
|
+
* @param sourceIndex index of the source in the arena sources table
|
|
167
|
+
* @param start
|
|
168
|
+
* @param end
|
|
169
|
+
*/
|
|
170
|
+
function allocateWhitespace(arena, sourceIndex, start, end) {
|
|
171
|
+
const item = arena.allocate();
|
|
172
|
+
arena.dataTypes[item] = EnumToken.WhitespaceTokenType;
|
|
173
|
+
arena.setTokenLocation(item, sourceIndex, start, end);
|
|
174
|
+
return item;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* true if the token ends a statement or a block: the whitespace that precedes it is not significant
|
|
178
|
+
* @param type
|
|
179
|
+
*/
|
|
180
|
+
function isStatementEnd(type) {
|
|
181
|
+
return (type === EnumToken.SemiColonTokenType ||
|
|
182
|
+
type === EnumToken.BlockStartTokenType ||
|
|
183
|
+
type === EnumToken.BlockEndTokenType ||
|
|
184
|
+
type === EnumToken.EOFTokenType);
|
|
185
|
+
}
|
|
162
186
|
/**
|
|
163
187
|
* recycle the tokens of a statement that were not attached to the tree: their ids are reused by the next allocations.
|
|
164
188
|
* the tokens referenced by the errors or the invalid nodes of the statement are kept
|
|
@@ -170,6 +194,8 @@ function allocateToken(arena, tokenizer, sourceIndex) {
|
|
|
170
194
|
* @param invalidStart index of the first invalid node of the statement
|
|
171
195
|
*/
|
|
172
196
|
function recycleStatementTokens(arena, tokens, errors, errorStart, invalidNodes, invalidStart) {
|
|
197
|
+
// the statement has errors or invalid nodes: the tokens they reference are kept
|
|
198
|
+
const references = errors.length > errorStart || invalidNodes.length > invalidStart;
|
|
173
199
|
for (let i = 0; i < tokens.length; i++) {
|
|
174
200
|
const token = tokens[i];
|
|
175
201
|
// already recycled (a token can be recorded twice), attached or holding other tokens
|
|
@@ -179,6 +205,10 @@ function recycleStatementTokens(arena, tokens, errors, errorStart, invalidNodes,
|
|
|
179
205
|
arena.firstToken[token] !== 0) {
|
|
180
206
|
continue;
|
|
181
207
|
}
|
|
208
|
+
if (!references) {
|
|
209
|
+
arena.recycle(token);
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
182
212
|
let referenced = invalidNodes.indexOf(token, invalidStart) !== -1;
|
|
183
213
|
for (let j = errorStart; !referenced && j < errors.length; j++) {
|
|
184
214
|
referenced = errors[j].node === token;
|
|
@@ -622,6 +652,14 @@ function parseVisitors(visitorsDef, errors) {
|
|
|
622
652
|
}
|
|
623
653
|
return result;
|
|
624
654
|
}
|
|
655
|
+
/**
|
|
656
|
+
* the settings of the fast mode (see {@link ParserOptions.fastMode}): the default values of these options when
|
|
657
|
+
* `fastMode` is `true`
|
|
658
|
+
*/
|
|
659
|
+
const fastModeOptions = Object.freeze({
|
|
660
|
+
minify: false,
|
|
661
|
+
mergeRules: MergeRulesEnum.None,
|
|
662
|
+
});
|
|
625
663
|
/**
|
|
626
664
|
* Parse css string
|
|
627
665
|
* @param tokenizer
|
|
@@ -632,6 +670,8 @@ function parseVisitors(visitorsDef, errors) {
|
|
|
632
670
|
*/
|
|
633
671
|
function doParseSync(tokenizer, options = {}) {
|
|
634
672
|
if (options.signal != null) {
|
|
673
|
+
// an aborted signal does not dispatch the abort event
|
|
674
|
+
options.signal.throwIfAborted();
|
|
635
675
|
options.signal.addEventListener("abort", reject);
|
|
636
676
|
}
|
|
637
677
|
options = {
|
|
@@ -656,6 +696,7 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
656
696
|
removePrefix: false,
|
|
657
697
|
validation: false,
|
|
658
698
|
lenient: true,
|
|
699
|
+
...(options.fastMode ? fastModeOptions : null),
|
|
659
700
|
...options,
|
|
660
701
|
};
|
|
661
702
|
options.validation = !!options.validation;
|
|
@@ -707,13 +748,34 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
707
748
|
// the strings of the tokens are ranges of the content of the source
|
|
708
749
|
arena.setSourceText(sourceIndex, tokenizer.content, tokenizer.codes);
|
|
709
750
|
let itemType;
|
|
751
|
+
// whitespace outside of parentheses, at the start of a statement or before ';', '{' and '}' is not significant: it
|
|
752
|
+
// is not allocated. the whitespace that follows a token is allocated when the next token is read
|
|
753
|
+
let whitespaceStart = -1;
|
|
754
|
+
let whitespaceEnd = 0;
|
|
710
755
|
// inlined: tokenizer.done()
|
|
711
756
|
while (!(tokenizer.typ === EnumToken.EOF)) {
|
|
712
757
|
tokenizer.next();
|
|
713
|
-
item = allocateToken(arena, tokenizer, sourceIndex);
|
|
714
758
|
itemType = tokenizer.typ;
|
|
715
759
|
stats.bytesIn = tokenizer.bytesIn;
|
|
716
760
|
stats.tokensCount++;
|
|
761
|
+
if (parensMatch === 0) {
|
|
762
|
+
if (itemType === EnumToken.WhitespaceTokenType) {
|
|
763
|
+
if (tokens.length > 0) {
|
|
764
|
+
whitespaceStart = tokenizer.sta;
|
|
765
|
+
whitespaceEnd = tokenizer.end;
|
|
766
|
+
}
|
|
767
|
+
continue;
|
|
768
|
+
}
|
|
769
|
+
if (whitespaceStart !== -1) {
|
|
770
|
+
if (!isStatementEnd(itemType)) {
|
|
771
|
+
item = allocateWhitespace(arena, sourceIndex, whitespaceStart, whitespaceEnd);
|
|
772
|
+
tokens.push(item);
|
|
773
|
+
statement.push(item);
|
|
774
|
+
}
|
|
775
|
+
whitespaceStart = -1;
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
item = allocateToken(arena, tokenizer, sourceIndex);
|
|
717
779
|
if (isBadToken(itemType)) {
|
|
718
780
|
tokens.push(item);
|
|
719
781
|
statement.push(item);
|
|
@@ -1007,6 +1069,13 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
1007
1069
|
}
|
|
1008
1070
|
}
|
|
1009
1071
|
}
|
|
1072
|
+
else if (options.mergeRules != null &&
|
|
1073
|
+
options.mergeRules !== false &&
|
|
1074
|
+
options.mergeRules !== MergeRulesEnum.None &&
|
|
1075
|
+
arena.firstChild[ast] !== 0) {
|
|
1076
|
+
// the ast is not minified: the adjacent rules are merged
|
|
1077
|
+
mergeRules(arena, ast, minifyOptions);
|
|
1078
|
+
}
|
|
1010
1079
|
stats.bytesIn += stats.importedBytesIn;
|
|
1011
1080
|
// the source is no longer tokenized: the code units are not kept
|
|
1012
1081
|
arena.releaseSourceCodes(sourceIndex);
|
|
@@ -1562,6 +1631,8 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
1562
1631
|
*/
|
|
1563
1632
|
async function doParse(iter, options = {}) {
|
|
1564
1633
|
if (options.signal != null) {
|
|
1634
|
+
// an aborted signal does not dispatch the abort event
|
|
1635
|
+
options.signal.throwIfAborted();
|
|
1565
1636
|
options.signal.addEventListener("abort", reject);
|
|
1566
1637
|
}
|
|
1567
1638
|
options = {
|
|
@@ -1587,6 +1658,7 @@ async function doParse(iter, options = {}) {
|
|
|
1587
1658
|
removePrefix: false,
|
|
1588
1659
|
validation: false,
|
|
1589
1660
|
lenient: true,
|
|
1661
|
+
...(options.fastMode ? fastModeOptions : null),
|
|
1590
1662
|
...options,
|
|
1591
1663
|
};
|
|
1592
1664
|
options.minifyAST ??= options.minify;
|
|
@@ -1643,13 +1715,41 @@ async function doParse(iter, options = {}) {
|
|
|
1643
1715
|
// the strings of the tokens are ranges of the content of the source
|
|
1644
1716
|
arena.setSourceText(sourceIndex, tokenizer.content, tokenizer.codes);
|
|
1645
1717
|
let itemType;
|
|
1718
|
+
// whitespace outside of parentheses, at the start of a statement or before ';', '{' and '}' is not significant: it
|
|
1719
|
+
// is not allocated. the whitespace that follows a token is allocated when the next token is read
|
|
1720
|
+
let whitespaceStart = -1;
|
|
1721
|
+
let whitespaceEnd = 0;
|
|
1646
1722
|
// inlined: tokenizer.done()
|
|
1647
1723
|
while (!(tokenizer.typ === EnumToken.EOF)) {
|
|
1648
1724
|
tokenizer.next();
|
|
1649
|
-
|
|
1725
|
+
// a stream: the token may continue in the next chunk, the chunk is read and the token is read again
|
|
1726
|
+
if (tokenizer.waiting) {
|
|
1727
|
+
await tokenizer.read();
|
|
1728
|
+
// the strings of the tokens are ranges of the content read so far
|
|
1729
|
+
arena.setSourceText(sourceIndex, tokenizer.content, tokenizer.codes);
|
|
1730
|
+
continue;
|
|
1731
|
+
}
|
|
1650
1732
|
itemType = tokenizer.typ;
|
|
1651
1733
|
stats.bytesIn = tokenizer.bytesIn;
|
|
1652
1734
|
stats.tokensCount++;
|
|
1735
|
+
if (parensMatch === 0) {
|
|
1736
|
+
if (itemType === EnumToken.WhitespaceTokenType) {
|
|
1737
|
+
if (tokens.length > 0) {
|
|
1738
|
+
whitespaceStart = tokenizer.sta;
|
|
1739
|
+
whitespaceEnd = tokenizer.end;
|
|
1740
|
+
}
|
|
1741
|
+
continue;
|
|
1742
|
+
}
|
|
1743
|
+
if (whitespaceStart !== -1) {
|
|
1744
|
+
if (!isStatementEnd(itemType)) {
|
|
1745
|
+
item = allocateWhitespace(arena, sourceIndex, whitespaceStart, whitespaceEnd);
|
|
1746
|
+
tokens.push(item);
|
|
1747
|
+
statement.push(item);
|
|
1748
|
+
}
|
|
1749
|
+
whitespaceStart = -1;
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
item = allocateToken(arena, tokenizer, sourceIndex);
|
|
1653
1753
|
if (isBadToken(itemType)) {
|
|
1654
1754
|
tokens.push(item);
|
|
1655
1755
|
statement.push(item);
|
|
@@ -1711,6 +1811,11 @@ async function doParse(iter, options = {}) {
|
|
|
1711
1811
|
tokens.push(item);
|
|
1712
1812
|
do {
|
|
1713
1813
|
tokenizer.next();
|
|
1814
|
+
if (tokenizer.waiting) {
|
|
1815
|
+
await tokenizer.read();
|
|
1816
|
+
arena.setSourceText(sourceIndex, tokenizer.content, tokenizer.codes);
|
|
1817
|
+
continue;
|
|
1818
|
+
}
|
|
1714
1819
|
item = allocateToken(arena, tokenizer, sourceIndex);
|
|
1715
1820
|
itemType = tokenizer.typ;
|
|
1716
1821
|
tokens.push(item);
|
|
@@ -2003,6 +2108,13 @@ async function doParse(iter, options = {}) {
|
|
|
2003
2108
|
}
|
|
2004
2109
|
}
|
|
2005
2110
|
}
|
|
2111
|
+
else if (options.mergeRules != null &&
|
|
2112
|
+
options.mergeRules !== false &&
|
|
2113
|
+
options.mergeRules !== MergeRulesEnum.None &&
|
|
2114
|
+
arena.firstChild[ast] !== 0) {
|
|
2115
|
+
// the ast is not minified: the adjacent rules are merged
|
|
2116
|
+
mergeRules(arena, ast, minifyOptions);
|
|
2117
|
+
}
|
|
2006
2118
|
stats.bytesIn += stats.importedBytesIn;
|
|
2007
2119
|
// the source is no longer tokenized: the code units are not kept
|
|
2008
2120
|
arena.releaseSourceCodes(sourceIndex);
|
|
@@ -2966,10 +3078,7 @@ function parseAtRule(arena, stream, context, options, errors, parseAsBlock = nul
|
|
|
2966
3078
|
if (stream.length === 0 ||
|
|
2967
3079
|
arena.dataTypes[stream[0]] !== EnumToken.WhitespaceTokenType ||
|
|
2968
3080
|
arena.getSpanEnd(stream[0]) - arena.getSpanStart(stream[0]) !== 1 ||
|
|
2969
|
-
|
|
2970
|
-
options.sourcesMap
|
|
2971
|
-
?.get(arena.sources[arena.getSourceId(stream[0])] ?? 0)
|
|
2972
|
-
?.content.charCodeAt(arena.getSpanStart(stream[0])) !== 0x20) {
|
|
3081
|
+
arena.sourceCodeAt(arena.getSourceId(stream[0]), arena.getSpanStart(stream[0])) !== 0x20) {
|
|
2973
3082
|
success = false;
|
|
2974
3083
|
errors.push({
|
|
2975
3084
|
action: "drop",
|
|
@@ -3377,8 +3486,7 @@ function parseAtRule(arena, stream, context, options, errors, parseAsBlock = nul
|
|
|
3377
3486
|
}
|
|
3378
3487
|
else {
|
|
3379
3488
|
context = createValidationContext(arena, stream, index);
|
|
3380
|
-
|
|
3381
|
-
range = context.peekRange((t) => arena.dataTypes[t] === EnumToken.EndParensTokenType);
|
|
3489
|
+
range = context.peekRange(EnumToken.EndParensTokenType);
|
|
3382
3490
|
// inlined: arena.typeOf(range.at(-1))
|
|
3383
3491
|
if (arena.dataTypes[range.at(-1)] !== EnumToken.EndParensTokenType) {
|
|
3384
3492
|
errors.push({
|
|
@@ -4014,4 +4122,4 @@ function parseTokens(arena, tokens, options, errors) {
|
|
|
4014
4122
|
return tokens;
|
|
4015
4123
|
}
|
|
4016
4124
|
|
|
4017
|
-
export { doParse, doParseSync, generateScopedName, generateSyncScopedName, getKeyName, getShortNameGenerator, isDefinitionBlock, parseAtRule, parseDeclarations, parseRuleContent, parseString, parseTokens, trimWhiteSpace };
|
|
4125
|
+
export { doParse, doParseSync, fastModeOptions, generateScopedName, generateSyncScopedName, getKeyName, getShortNameGenerator, isDefinitionBlock, parseAtRule, parseDeclarations, parseRuleContent, parseString, parseTokens, trimWhiteSpace };
|