@projectwallace/css-parser 0.12.0 → 0.12.1

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.
@@ -2,7 +2,7 @@ import { Lexer } from './tokenize.js';
2
2
  import { CSSDataArena, SELECTOR_LIST, SELECTOR, COMBINATOR, NESTING_SELECTOR, ID_SELECTOR, TYPE_SELECTOR, UNIVERSAL_SELECTOR, CLASS_SELECTOR, ATTRIBUTE_SELECTOR, ATTR_OPERATOR_NONE, ATTR_FLAG_NONE, ATTR_OPERATOR_EQUAL, ATTR_OPERATOR_TILDE_EQUAL, ATTR_OPERATOR_PIPE_EQUAL, ATTR_OPERATOR_CARET_EQUAL, ATTR_OPERATOR_DOLLAR_EQUAL, ATTR_OPERATOR_STAR_EQUAL, ATTR_FLAG_CASE_INSENSITIVE, ATTR_FLAG_CASE_SENSITIVE, PSEUDO_ELEMENT_SELECTOR, PSEUDO_CLASS_SELECTOR, FLAG_HAS_PARENS, LANG_SELECTOR, NTH_OF_SELECTOR } from './arena.js';
3
3
  import { TOKEN_COMMA, TOKEN_DELIM, TOKEN_EOF, TOKEN_WHITESPACE, TOKEN_FUNCTION, TOKEN_COLON, TOKEN_LEFT_BRACKET, TOKEN_HASH, TOKEN_IDENT, TOKEN_RIGHT_BRACKET, TOKEN_LEFT_PAREN, TOKEN_RIGHT_PAREN, TOKEN_STRING } from './token-types.js';
4
4
  import { skip_whitespace_and_comments_forward, skip_whitespace_and_comments_backward, skip_whitespace_forward } from './parse-utils.js';
5
- import { CHAR_GREATER_THAN, CHAR_PLUS, CHAR_TILDE, CHAR_PERIOD, CHAR_ASTERISK, CHAR_AMPERSAND, CHAR_PIPE, CHAR_SPACE, CHAR_TAB, CHAR_NEWLINE, CHAR_CARRIAGE_RETURN, CHAR_FORM_FEED, is_combinator, is_whitespace, CHAR_EQUALS, CHAR_CARET, CHAR_DOLLAR, CHAR_SINGLE_QUOTE, CHAR_DOUBLE_QUOTE, CHAR_COLON, str_equals, CHAR_FORWARD_SLASH } from './string-utils.js';
5
+ import { CHAR_GREATER_THAN, CHAR_PLUS, CHAR_TILDE, CHAR_PERIOD, CHAR_ASTERISK, CHAR_AMPERSAND, CHAR_PIPE, is_combinator, is_whitespace, CHAR_EQUALS, CHAR_CARET, CHAR_DOLLAR, CHAR_SINGLE_QUOTE, CHAR_DOUBLE_QUOTE, CHAR_COLON, str_equals, CHAR_FORWARD_SLASH } from './string-utils.js';
6
6
  import { ANplusBParser } from './parse-anplusb.js';
7
7
  import { CSSNode } from './css-node.js';
8
8
 
@@ -38,7 +38,13 @@ class SelectorParser {
38
38
  let selector_column = this.lexer.column;
39
39
  let complex_selector = this.parse_complex_selector(allow_relative);
40
40
  if (complex_selector !== null) {
41
- let selector_wrapper = this.arena.create_node(SELECTOR, selector_start, this.lexer.pos - selector_start, selector_line, selector_column);
41
+ let selector_wrapper = this.arena.create_node(
42
+ SELECTOR,
43
+ selector_start,
44
+ this.lexer.pos - selector_start,
45
+ selector_line,
46
+ selector_column
47
+ );
42
48
  this.arena.set_content_start_delta(selector_wrapper, 0);
43
49
  this.arena.set_content_length(selector_wrapper, this.lexer.pos - selector_start);
44
50
  let last_component = complex_selector;
@@ -81,7 +87,13 @@ class SelectorParser {
81
87
  if (token_type === TOKEN_DELIM) {
82
88
  let ch = this.source.charCodeAt(this.lexer.token_start);
83
89
  if (ch === CHAR_GREATER_THAN || ch === CHAR_PLUS || ch === CHAR_TILDE) {
84
- let combinator = this.create_node_at(COMBINATOR, this.lexer.token_start, this.lexer.token_end, this.lexer.token_line, this.lexer.token_column);
90
+ let combinator = this.create_node_at(
91
+ COMBINATOR,
92
+ this.lexer.token_start,
93
+ this.lexer.token_end,
94
+ this.lexer.token_line,
95
+ this.lexer.token_column
96
+ );
85
97
  components.push(combinator);
86
98
  this.skip_whitespace();
87
99
  } else {
@@ -239,16 +251,9 @@ class SelectorParser {
239
251
  let whitespace_start = this.lexer.pos;
240
252
  let whitespace_start_line = this.lexer.line;
241
253
  let whitespace_start_column = this.lexer.column;
242
- let has_whitespace = false;
243
- while (this.lexer.pos < this.selector_end) {
244
- let ch = this.source.charCodeAt(this.lexer.pos);
245
- if (ch === CHAR_SPACE || ch === CHAR_TAB || ch === CHAR_NEWLINE || ch === CHAR_CARRIAGE_RETURN || ch === CHAR_FORM_FEED) {
246
- has_whitespace = true;
247
- this.lexer.advance();
248
- } else {
249
- break;
250
- }
251
- }
254
+ let has_whitespace = this.lexer.pos < this.selector_end;
255
+ this.skip_whitespace();
256
+ has_whitespace = has_whitespace && this.lexer.pos > whitespace_start;
252
257
  if (this.lexer.pos >= this.selector_end) {
253
258
  this.lexer.pos = whitespace_start;
254
259
  this.lexer.line = whitespace_start_line;
@@ -266,14 +271,7 @@ class SelectorParser {
266
271
  this.lexer.pos = whitespace_start;
267
272
  this.lexer.line = whitespace_start_line;
268
273
  this.lexer.column = whitespace_start_column;
269
- while (this.lexer.pos < this.selector_end) {
270
- let ch = this.source.charCodeAt(this.lexer.pos);
271
- if (ch === CHAR_SPACE || ch === CHAR_TAB || ch === CHAR_NEWLINE || ch === CHAR_CARRIAGE_RETURN || ch === CHAR_FORM_FEED) {
272
- this.lexer.advance();
273
- } else {
274
- break;
275
- }
276
- }
274
+ this.skip_whitespace();
277
275
  return this.create_node_at(COMBINATOR, whitespace_start, this.lexer.pos, whitespace_start_line, whitespace_start_column);
278
276
  }
279
277
  this.lexer.pos = whitespace_start;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@projectwallace/css-parser",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "description": "High-performance CSS lexer and parser, optimized for CSS inspection and analysis",
5
5
  "author": "Bart Veneman <bart@projectwallace.com>",
6
6
  "license": "MIT",