@aljazmc/syntax 0.7.5 → 0.7.7

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 CHANGED
@@ -3,6 +3,9 @@
3
3
  [![CI](https://github.com/aljazmc/aljazmc/actions/workflows/ci.yml/badge.svg)](https://github.com/aljazmc/aljazmc/actions/workflows/ci.yml)
4
4
  [![npm](https://img.shields.io/npm/v/@aljazmc/syntax?logo=npm&color=cb3837)](https://www.npmjs.com/package/@aljazmc/syntax)
5
5
  [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
6
+ [![Install size](https://img.shields.io/npm/unpacked-size/@aljazmc/syntax?label=install%20size)](https://www.npmjs.com/package/@aljazmc/syntax?activeTab=code)
7
+ [![Types: TypeScript](https://img.shields.io/npm/types/@aljazmc/syntax?logo=typescript&logoColor=white&color=3178c6)](https://www.npmjs.com/package/@aljazmc/syntax)
8
+ [![Last commit](https://img.shields.io/github/last-commit/aljazmc/aljazmc?path=shared%2Fsyntax&label=last%20commit)](https://github.com/aljazmc/aljazmc/commits/main/shared/syntax)
6
9
  [![Dependencies: none](https://img.shields.io/badge/dependencies-none-brightgreen)](package.json)
7
10
  [![ESTree](https://img.shields.io/badge/AST-ESTree-f7df1e?logo=javascript&logoColor=black)](https://github.com/estree/estree)
8
11
  [![CommonMark + GFM](https://img.shields.io/badge/Markdown-CommonMark%20%2B%20GFM-000000?logo=markdown&logoColor=white)](https://github.github.com/gfm/)
package/bin/index.js CHANGED
@@ -274,9 +274,19 @@ var Scanner = class _Scanner {
274
274
  // shared/syntax/src/css/tokens.ts
275
275
  var isDigit = /* @__PURE__ */ __name((char) => char !== void 0 && char >= "0" && char <= "9", "isDigit");
276
276
  var isHex = /* @__PURE__ */ __name((char) => char !== void 0 && /^[0-9a-fA-F]$/.test(char), "isHex");
277
- var isNameStart = /* @__PURE__ */ __name((char) => char !== void 0 && (/^[A-Za-z_]$/.test(char) || char.charCodeAt(0) >= 128), "isNameStart");
277
+ var isNonAsciiName = /* @__PURE__ */ __name((code) => code === 183 || code >= 192 && code <= 214 || code >= 216 && code <= 246 || code >= 248 && code <= 893 || code >= 895 && code <= 8191 || code === 8204 || code === 8205 || code === 8255 || code === 8256 || code >= 8304 && code <= 8591 || code >= 11264 && code <= 12271 || code >= 12289 && code <= 57343 || code >= 63744 && code <= 64975 || code >= 65008 && code <= 65533, "isNonAsciiName");
278
+ var isNameStart = /* @__PURE__ */ __name((char) => char !== void 0 && (/^[A-Za-z_]$/.test(char) || char.charCodeAt(0) >= 128 && isNonAsciiName(char.charCodeAt(0))), "isNameStart");
278
279
  var isName = /* @__PURE__ */ __name((char) => char !== void 0 && (isNameStart(char) || isDigit(char) || char === "-"), "isName");
279
280
  var isWhitespace = /* @__PURE__ */ __name((char) => char === " " || char === " " || char === "\n" || char === "\r" || char === "\f", "isWhitespace");
281
+ var rejected = /* @__PURE__ */ __name((char) => {
282
+ if (char === "\f" || char === "\v")
283
+ return "The CSS standard only allows tabs, whitespace, carriage return and line feed whitespace.";
284
+ if (char === void 0) return;
285
+ const code = char.charCodeAt(0);
286
+ if (code < 128 || isNonAsciiName(code)) return;
287
+ const shown = /[\p{Cc}\p{Cf}]/u.test(char) && !/\p{White_Space}/u.test(char) ? "\uFFFD" : char;
288
+ return `unexpected character \`${shown}\``;
289
+ }, "rejected");
280
290
  var Tokenizer = class {
281
291
  static {
282
292
  __name(this, "Tokenizer");
@@ -390,8 +400,14 @@ var Tokenizer = class {
390
400
  value
391
401
  }), "token");
392
402
  if (char === void 0) return token("eof");
393
- if (isWhitespace(char)) {
394
- while (isWhitespace(source[this.#position])) this.#position++;
403
+ if (isWhitespace(char) || rejected(char)) {
404
+ for (; ; ) {
405
+ const next = source[this.#position];
406
+ const message = rejected(next);
407
+ if (message) this.#fail(message, this.#position);
408
+ else if (!isWhitespace(next)) break;
409
+ this.#position++;
410
+ }
395
411
  return token("whitespace");
396
412
  }
397
413
  if (char === '"' || char === "'") return this.#string(char);
@@ -12,6 +12,11 @@ export interface Token {
12
12
  /** Whether a string ends with its quote. */
13
13
  closed?: boolean;
14
14
  }
15
+ /**
16
+ * The non-ASCII code points of names, as CSS Syntax Level 3 lists them and
17
+ * Biome reads them; a surrogate is half of one from U+10000.
18
+ */
19
+ export declare const isNonAsciiName: (code: number) => boolean;
15
20
  export declare const isWhitespace: (char: string | undefined) => char is "\t" | "\n" | "\f" | "\r" | " ";
16
21
  /** Splits CSS into tokens like CSS Syntax Level 3, collecting comments. */
17
22
  export default class Tokenizer {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aljazmc/syntax",
3
- "version": "0.7.5",
3
+ "version": "0.7.7",
4
4
  "description": "Shared, dependency-free parser for CSS, HTML, JavaScript, JSON, JSX, Markdown, TypeScript and YAML, bundled into @aljazmc/formatero and @aljazmc/lintero.",
5
5
  "keywords": [
6
6
  "parser",