@codemirror/language 6.9.1 → 6.9.3

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 CHANGED
@@ -1,3 +1,15 @@
1
+ ## 6.9.3 (2023-11-27)
2
+
3
+ ### Bug fixes
4
+
5
+ Fix an issue in `StreamLanguage` where it ran out of node type ids if you repeatedly redefined a language with the same token table.
6
+
7
+ ## 6.9.2 (2023-10-24)
8
+
9
+ ### Bug fixes
10
+
11
+ Allow `StreamParser` tokens get multiple highlighting tags.
12
+
1
13
  ## 6.9.1 (2023-09-20)
2
14
 
3
15
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -2452,6 +2452,8 @@ const noTokens = Object.create(null);
2452
2452
  const typeArray = [common.NodeType.none];
2453
2453
  const nodeSet = new common.NodeSet(typeArray);
2454
2454
  const warned = [];
2455
+ // Cache of node types by name and tags
2456
+ const byTag = Object.create(null);
2455
2457
  const defaultTable = Object.create(null);
2456
2458
  for (let [legacyName, name] of [
2457
2459
  ["variable", "variableName"],
@@ -2485,31 +2487,40 @@ function warnForPart(part, msg) {
2485
2487
  console.warn(msg);
2486
2488
  }
2487
2489
  function createTokenType(extra, tagStr) {
2488
- let tag = null;
2489
- for (let part of tagStr.split(".")) {
2490
- let value = (extra[part] || highlight.tags[part]);
2491
- if (!value) {
2492
- warnForPart(part, `Unknown highlighting tag ${part}`);
2493
- }
2494
- else if (typeof value == "function") {
2495
- if (!tag)
2496
- warnForPart(part, `Modifier ${part} used at start of tag`);
2497
- else
2498
- tag = value(tag);
2499
- }
2500
- else {
2501
- if (tag)
2502
- warnForPart(part, `Tag ${part} used as modifier`);
2503
- else
2504
- tag = value;
2490
+ let tags = [];
2491
+ for (let name of tagStr.split(" ")) {
2492
+ let found = [];
2493
+ for (let part of name.split(".")) {
2494
+ let value = (extra[part] || highlight.tags[part]);
2495
+ if (!value) {
2496
+ warnForPart(part, `Unknown highlighting tag ${part}`);
2497
+ }
2498
+ else if (typeof value == "function") {
2499
+ if (!found.length)
2500
+ warnForPart(part, `Modifier ${part} used at start of tag`);
2501
+ else
2502
+ found = found.map(value);
2503
+ }
2504
+ else {
2505
+ if (found.length)
2506
+ warnForPart(part, `Tag ${part} used as modifier`);
2507
+ else
2508
+ found = Array.isArray(value) ? value : [value];
2509
+ }
2505
2510
  }
2511
+ for (let tag of found)
2512
+ tags.push(tag);
2506
2513
  }
2507
- if (!tag)
2514
+ if (!tags.length)
2508
2515
  return 0;
2509
- let name = tagStr.replace(/ /g, "_"), type = common.NodeType.define({
2516
+ let name = tagStr.replace(/ /g, "_"), key = name + " " + tags.map(t => t.id);
2517
+ let known = byTag[key];
2518
+ if (known)
2519
+ return known.id;
2520
+ let type = byTag[key] = common.NodeType.define({
2510
2521
  id: typeArray.length,
2511
2522
  name,
2512
- props: [highlight.styleTags({ [name]: tag })]
2523
+ props: [highlight.styleTags({ [name]: tags })]
2513
2524
  });
2514
2525
  typeArray.push(type);
2515
2526
  return type.id;
package/dist/index.d.cts CHANGED
@@ -1139,11 +1139,13 @@ interface StreamParser<State> {
1139
1139
  Read one token, advancing the stream past it, and returning a
1140
1140
  string indicating the token's style tag—either the name of one
1141
1141
  of the tags in
1142
- [`tags`](https://lezer.codemirror.net/docs/ref#highlight.tags),
1143
- or such a name suffixed by one or more tag
1142
+ [`tags`](https://lezer.codemirror.net/docs/ref#highlight.tags)
1143
+ or [`tokenTable`](https://codemirror.net/6/docs/ref/#language.StreamParser.tokenTable), or such a
1144
+ name suffixed by one or more tag
1144
1145
  [modifier](https://lezer.codemirror.net/docs/ref#highlight.Tag^defineModifier)
1145
1146
  names, separated by periods. For example `"keyword"` or
1146
- "`variableName.constant"`.
1147
+ "`variableName.constant"`, or a space-separated set of such
1148
+ token types.
1147
1149
 
1148
1150
  It is okay to return a zero-length token, but only if that
1149
1151
  updates the state so that the next call will return a non-empty
@@ -1175,10 +1177,10 @@ interface StreamParser<State> {
1175
1177
  /**
1176
1178
  Extra tokens to use in this parser. When the tokenizer returns a
1177
1179
  token name that exists as a property in this object, the
1178
- corresponding tag will be assigned to the token.
1180
+ corresponding tags will be assigned to the token.
1179
1181
  */
1180
1182
  tokenTable?: {
1181
- [name: string]: Tag;
1183
+ [name: string]: Tag | readonly Tag[];
1182
1184
  };
1183
1185
  }
1184
1186
  /**
package/dist/index.d.ts CHANGED
@@ -1139,11 +1139,13 @@ interface StreamParser<State> {
1139
1139
  Read one token, advancing the stream past it, and returning a
1140
1140
  string indicating the token's style tag—either the name of one
1141
1141
  of the tags in
1142
- [`tags`](https://lezer.codemirror.net/docs/ref#highlight.tags),
1143
- or such a name suffixed by one or more tag
1142
+ [`tags`](https://lezer.codemirror.net/docs/ref#highlight.tags)
1143
+ or [`tokenTable`](https://codemirror.net/6/docs/ref/#language.StreamParser.tokenTable), or such a
1144
+ name suffixed by one or more tag
1144
1145
  [modifier](https://lezer.codemirror.net/docs/ref#highlight.Tag^defineModifier)
1145
1146
  names, separated by periods. For example `"keyword"` or
1146
- "`variableName.constant"`.
1147
+ "`variableName.constant"`, or a space-separated set of such
1148
+ token types.
1147
1149
 
1148
1150
  It is okay to return a zero-length token, but only if that
1149
1151
  updates the state so that the next call will return a non-empty
@@ -1175,10 +1177,10 @@ interface StreamParser<State> {
1175
1177
  /**
1176
1178
  Extra tokens to use in this parser. When the tokenizer returns a
1177
1179
  token name that exists as a property in this object, the
1178
- corresponding tag will be assigned to the token.
1180
+ corresponding tags will be assigned to the token.
1179
1181
  */
1180
1182
  tokenTable?: {
1181
- [name: string]: Tag;
1183
+ [name: string]: Tag | readonly Tag[];
1182
1184
  };
1183
1185
  }
1184
1186
  /**
package/dist/index.js CHANGED
@@ -2450,6 +2450,8 @@ const noTokens = /*@__PURE__*/Object.create(null);
2450
2450
  const typeArray = [NodeType.none];
2451
2451
  const nodeSet = /*@__PURE__*/new NodeSet(typeArray);
2452
2452
  const warned = [];
2453
+ // Cache of node types by name and tags
2454
+ const byTag = /*@__PURE__*/Object.create(null);
2453
2455
  const defaultTable = /*@__PURE__*/Object.create(null);
2454
2456
  for (let [legacyName, name] of [
2455
2457
  ["variable", "variableName"],
@@ -2483,31 +2485,40 @@ function warnForPart(part, msg) {
2483
2485
  console.warn(msg);
2484
2486
  }
2485
2487
  function createTokenType(extra, tagStr) {
2486
- let tag = null;
2487
- for (let part of tagStr.split(".")) {
2488
- let value = (extra[part] || tags[part]);
2489
- if (!value) {
2490
- warnForPart(part, `Unknown highlighting tag ${part}`);
2491
- }
2492
- else if (typeof value == "function") {
2493
- if (!tag)
2494
- warnForPart(part, `Modifier ${part} used at start of tag`);
2495
- else
2496
- tag = value(tag);
2497
- }
2498
- else {
2499
- if (tag)
2500
- warnForPart(part, `Tag ${part} used as modifier`);
2501
- else
2502
- tag = value;
2488
+ let tags$1 = [];
2489
+ for (let name of tagStr.split(" ")) {
2490
+ let found = [];
2491
+ for (let part of name.split(".")) {
2492
+ let value = (extra[part] || tags[part]);
2493
+ if (!value) {
2494
+ warnForPart(part, `Unknown highlighting tag ${part}`);
2495
+ }
2496
+ else if (typeof value == "function") {
2497
+ if (!found.length)
2498
+ warnForPart(part, `Modifier ${part} used at start of tag`);
2499
+ else
2500
+ found = found.map(value);
2501
+ }
2502
+ else {
2503
+ if (found.length)
2504
+ warnForPart(part, `Tag ${part} used as modifier`);
2505
+ else
2506
+ found = Array.isArray(value) ? value : [value];
2507
+ }
2503
2508
  }
2509
+ for (let tag of found)
2510
+ tags$1.push(tag);
2504
2511
  }
2505
- if (!tag)
2512
+ if (!tags$1.length)
2506
2513
  return 0;
2507
- let name = tagStr.replace(/ /g, "_"), type = NodeType.define({
2514
+ let name = tagStr.replace(/ /g, "_"), key = name + " " + tags$1.map(t => t.id);
2515
+ let known = byTag[key];
2516
+ if (known)
2517
+ return known.id;
2518
+ let type = byTag[key] = NodeType.define({
2508
2519
  id: typeArray.length,
2509
2520
  name,
2510
- props: [styleTags({ [name]: tag })]
2521
+ props: [styleTags({ [name]: tags$1 })]
2511
2522
  });
2512
2523
  typeArray.push(type);
2513
2524
  return type.id;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/language",
3
- "version": "6.9.1",
3
+ "version": "6.9.3",
4
4
  "description": "Language support infrastructure for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",