@codemirror/language 6.9.2 → 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,9 @@
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
+
1
7
  ## 6.9.2 (2023-10-24)
2
8
 
3
9
  ### 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"],
@@ -2511,7 +2513,11 @@ function createTokenType(extra, tagStr) {
2511
2513
  }
2512
2514
  if (!tags.length)
2513
2515
  return 0;
2514
- 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({
2515
2521
  id: typeArray.length,
2516
2522
  name,
2517
2523
  props: [highlight.styleTags({ [name]: tags })]
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"],
@@ -2509,7 +2511,11 @@ function createTokenType(extra, tagStr) {
2509
2511
  }
2510
2512
  if (!tags$1.length)
2511
2513
  return 0;
2512
- 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({
2513
2519
  id: typeArray.length,
2514
2520
  name,
2515
2521
  props: [styleTags({ [name]: tags$1 })]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codemirror/language",
3
- "version": "6.9.2",
3
+ "version": "6.9.3",
4
4
  "description": "Language support infrastructure for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",