@projectwallace/css-parser 0.13.0 → 0.13.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.
@@ -2,7 +2,7 @@ import { Lexer } from './tokenize.js';
2
2
  import { CSSDataArena, DECLARATION, FLAG_IMPORTANT, FLAG_BROWSERHACK } from './arena.js';
3
3
  import { ValueParser } from './parse-value.js';
4
4
  import { is_vendor_prefixed } from './string-utils.js';
5
- import { TOKEN_AT_KEYWORD, TOKEN_HASH, TOKEN_IDENT, TOKEN_DELIM, TOKEN_LEFT_PAREN, TOKEN_RIGHT_PAREN, TOKEN_LEFT_BRACKET, TOKEN_RIGHT_BRACKET, TOKEN_COMMA, TOKEN_COLON, TOKEN_EOF, TOKEN_SEMICOLON, TOKEN_RIGHT_BRACE, TOKEN_LEFT_BRACE } from './token-types.js';
5
+ import { TOKEN_AT_KEYWORD, TOKEN_HASH, TOKEN_IDENT, TOKEN_DELIM, TOKEN_LEFT_PAREN, TOKEN_RIGHT_PAREN, TOKEN_LEFT_BRACKET, TOKEN_RIGHT_BRACKET, TOKEN_COMMA, TOKEN_COLON, TOKEN_EOF, TOKEN_SEMICOLON, TOKEN_RIGHT_BRACE, TOKEN_LEFT_BRACE, TOKEN_FUNCTION } from './token-types.js';
6
6
  import { trim_boundaries } from './parse-utils.js';
7
7
  import { CSSNode } from './css-node.js';
8
8
 
@@ -97,10 +97,16 @@ class DeclarationParser {
97
97
  let value_end = value_start;
98
98
  let has_important = false;
99
99
  let last_end = lexer.token_end;
100
+ let paren_depth = 0;
100
101
  while (lexer.token_type !== TOKEN_EOF && lexer.token_start < end) {
101
102
  let token_type = lexer.token_type;
102
- if (token_type === TOKEN_SEMICOLON) break;
103
- if (token_type === TOKEN_RIGHT_BRACE) break;
103
+ if (token_type === TOKEN_LEFT_PAREN || token_type === TOKEN_FUNCTION) {
104
+ paren_depth++;
105
+ } else if (token_type === TOKEN_RIGHT_PAREN) {
106
+ paren_depth--;
107
+ }
108
+ if (token_type === TOKEN_SEMICOLON && paren_depth === 0) break;
109
+ if (token_type === TOKEN_RIGHT_BRACE && paren_depth === 0) break;
104
110
  if (token_type === TOKEN_LEFT_BRACE) {
105
111
  lexer.restore_position(saved);
106
112
  return null;
package/dist/parse.js CHANGED
@@ -4,7 +4,7 @@ import { CSSNode } from './css-node.js';
4
4
  import { SelectorParser } from './parse-selector.js';
5
5
  import { AtRulePreludeParser } from './parse-atrule-prelude.js';
6
6
  import { DeclarationParser } from './parse-declaration.js';
7
- import { TOKEN_EOF, TOKEN_AT_KEYWORD, TOKEN_LEFT_BRACE, TOKEN_RIGHT_BRACE, TOKEN_IDENT, TOKEN_HASH, TOKEN_DELIM, TOKEN_LEFT_PAREN, TOKEN_RIGHT_PAREN, TOKEN_LEFT_BRACKET, TOKEN_RIGHT_BRACKET, TOKEN_COMMA, TOKEN_COLON, TOKEN_SEMICOLON } from './token-types.js';
7
+ import { TOKEN_EOF, TOKEN_AT_KEYWORD, TOKEN_LEFT_BRACE, TOKEN_RIGHT_BRACE, TOKEN_IDENT, TOKEN_HASH, TOKEN_DELIM, TOKEN_LEFT_PAREN, TOKEN_RIGHT_PAREN, TOKEN_LEFT_BRACKET, TOKEN_RIGHT_BRACKET, TOKEN_COMMA, TOKEN_COLON, TOKEN_SEMICOLON, TOKEN_FUNCTION } from './token-types.js';
8
8
  import { trim_boundaries } from './parse-utils.js';
9
9
  import { CHAR_PERIOD, CHAR_GREATER_THAN, CHAR_PLUS, CHAR_TILDE, CHAR_AMPERSAND } from './string-utils.js';
10
10
 
@@ -213,9 +213,16 @@ class Parser {
213
213
  this.arena.set_content_length(at_rule, name_length);
214
214
  let prelude_start = this.lexer.token_start;
215
215
  let prelude_end = prelude_start;
216
+ let paren_depth = 0;
216
217
  while (!this.is_eof()) {
217
218
  let token_type = this.peek_type();
218
- if (token_type === TOKEN_LEFT_BRACE || token_type === TOKEN_SEMICOLON) break;
219
+ if (token_type === TOKEN_LEFT_PAREN || token_type === TOKEN_FUNCTION) {
220
+ paren_depth++;
221
+ } else if (token_type === TOKEN_RIGHT_PAREN) {
222
+ paren_depth--;
223
+ }
224
+ if (token_type === TOKEN_LEFT_BRACE && paren_depth === 0) break;
225
+ if (token_type === TOKEN_SEMICOLON && paren_depth === 0) break;
219
226
  prelude_end = this.lexer.token_end;
220
227
  this.next_token();
221
228
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@projectwallace/css-parser",
3
- "version": "0.13.0",
3
+ "version": "0.13.2",
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",