@codemirror/language 6.9.1 → 6.9.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 6.9.2 (2023-10-24)
2
+
3
+ ### Bug fixes
4
+
5
+ Allow `StreamParser` tokens get multiple highlighting tags.
6
+
1
7
  ## 6.9.1 (2023-09-20)
2
8
 
3
9
  ### Bug fixes
package/dist/index.cjs CHANGED
@@ -2485,31 +2485,36 @@ function warnForPart(part, msg) {
2485
2485
  console.warn(msg);
2486
2486
  }
2487
2487
  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;
2488
+ let tags = [];
2489
+ for (let name of tagStr.split(" ")) {
2490
+ let found = [];
2491
+ for (let part of name.split(".")) {
2492
+ let value = (extra[part] || highlight.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
+ }
2505
2508
  }
2509
+ for (let tag of found)
2510
+ tags.push(tag);
2506
2511
  }
2507
- if (!tag)
2512
+ if (!tags.length)
2508
2513
  return 0;
2509
2514
  let name = tagStr.replace(/ /g, "_"), type = common.NodeType.define({
2510
2515
  id: typeArray.length,
2511
2516
  name,
2512
- props: [highlight.styleTags({ [name]: tag })]
2517
+ props: [highlight.styleTags({ [name]: tags })]
2513
2518
  });
2514
2519
  typeArray.push(type);
2515
2520
  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
@@ -2483,31 +2483,36 @@ function warnForPart(part, msg) {
2483
2483
  console.warn(msg);
2484
2484
  }
2485
2485
  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;
2486
+ let tags$1 = [];
2487
+ for (let name of tagStr.split(" ")) {
2488
+ let found = [];
2489
+ for (let part of name.split(".")) {
2490
+ let value = (extra[part] || tags[part]);
2491
+ if (!value) {
2492
+ warnForPart(part, `Unknown highlighting tag ${part}`);
2493
+ }
2494
+ else if (typeof value == "function") {
2495
+ if (!found.length)
2496
+ warnForPart(part, `Modifier ${part} used at start of tag`);
2497
+ else
2498
+ found = found.map(value);
2499
+ }
2500
+ else {
2501
+ if (found.length)
2502
+ warnForPart(part, `Tag ${part} used as modifier`);
2503
+ else
2504
+ found = Array.isArray(value) ? value : [value];
2505
+ }
2503
2506
  }
2507
+ for (let tag of found)
2508
+ tags$1.push(tag);
2504
2509
  }
2505
- if (!tag)
2510
+ if (!tags$1.length)
2506
2511
  return 0;
2507
2512
  let name = tagStr.replace(/ /g, "_"), type = NodeType.define({
2508
2513
  id: typeArray.length,
2509
2514
  name,
2510
- props: [styleTags({ [name]: tag })]
2515
+ props: [styleTags({ [name]: tags$1 })]
2511
2516
  });
2512
2517
  typeArray.push(type);
2513
2518
  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.2",
4
4
  "description": "Language support infrastructure for the CodeMirror code editor",
5
5
  "scripts": {
6
6
  "test": "cm-runtests",