@lezer/common 1.1.1 → 1.2.0

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/dist/index.cjs CHANGED
@@ -67,6 +67,22 @@ types that represent an expression could be tagged with an
67
67
  */
68
68
  NodeProp.group = new NodeProp({ deserialize: str => str.split(" ") });
69
69
  /**
70
+ Attached to nodes to indicate these should be
71
+ [displayed](https://codemirror.net/docs/ref/#language.syntaxTree)
72
+ in a bidirectional text isolate, so that direction-neutral
73
+ characters on their sides don't incorrectly get associated with
74
+ surrounding text. You'll generally want to set this for nodes
75
+ that contain arbitrary text, like strings and comments, and for
76
+ nodes that appear _inside_ arbitrary text, like HTML tags. When
77
+ not given a value, in a grammar declaration, defaults to
78
+ `"auto"`.
79
+ */
80
+ NodeProp.isolate = new NodeProp({ deserialize: value => {
81
+ if (value && value != "rtl" && value != "ltr" && value != "auto")
82
+ throw new RangeError("Invalid value for isolate: " + value);
83
+ return value || "auto";
84
+ } });
85
+ /**
70
86
  The hash of the [context](#lr.ContextTracker.constructor)
71
87
  that the node was parsed in, if any. Used to limit reuse of
72
88
  contextual nodes.
@@ -1938,18 +1954,14 @@ function sliceBuf(buf, startI, endI, nodes, positions, off) {
1938
1954
  // any other code, making violations of the immutability safe.
1939
1955
  function materialize(cursor) {
1940
1956
  let { node } = cursor, stack = [];
1957
+ let buffer = node.context.buffer;
1941
1958
  // Scan up to the nearest tree
1942
1959
  do {
1943
1960
  stack.push(cursor.index);
1944
1961
  cursor.parent();
1945
1962
  } while (!cursor.tree);
1946
1963
  // Find the index of the buffer in that tree
1947
- let i = 0, base = cursor.tree, off = 0;
1948
- for (;; i++) {
1949
- off = base.positions[i] + cursor.from;
1950
- if (off <= node.from && off + base.children[i].length >= node.to)
1951
- break;
1952
- }
1964
+ let base = cursor.tree, i = base.children.indexOf(buffer);
1953
1965
  let buf = base.children[i], b = buf.buffer, newStack = [i];
1954
1966
  // Split a level in the buffer, putting the nodes before and after
1955
1967
  // the child that contains `node` into new buffers.
package/dist/index.d.cts CHANGED
@@ -284,6 +284,18 @@ declare class NodeProp<T> {
284
284
  */
285
285
  static group: NodeProp<readonly string[]>;
286
286
  /**
287
+ Attached to nodes to indicate these should be
288
+ [displayed](https://codemirror.net/docs/ref/#language.syntaxTree)
289
+ in a bidirectional text isolate, so that direction-neutral
290
+ characters on their sides don't incorrectly get associated with
291
+ surrounding text. You'll generally want to set this for nodes
292
+ that contain arbitrary text, like strings and comments, and for
293
+ nodes that appear _inside_ arbitrary text, like HTML tags. When
294
+ not given a value, in a grammar declaration, defaults to
295
+ `"auto"`.
296
+ */
297
+ static isolate: NodeProp<"rtl" | "ltr" | "auto">;
298
+ /**
287
299
  The hash of the [context](#lr.ContextTracker.constructor)
288
300
  that the node was parsed in, if any. Used to limit reuse of
289
301
  contextual nodes.
package/dist/index.d.ts CHANGED
@@ -284,6 +284,18 @@ declare class NodeProp<T> {
284
284
  */
285
285
  static group: NodeProp<readonly string[]>;
286
286
  /**
287
+ Attached to nodes to indicate these should be
288
+ [displayed](https://codemirror.net/docs/ref/#language.syntaxTree)
289
+ in a bidirectional text isolate, so that direction-neutral
290
+ characters on their sides don't incorrectly get associated with
291
+ surrounding text. You'll generally want to set this for nodes
292
+ that contain arbitrary text, like strings and comments, and for
293
+ nodes that appear _inside_ arbitrary text, like HTML tags. When
294
+ not given a value, in a grammar declaration, defaults to
295
+ `"auto"`.
296
+ */
297
+ static isolate: NodeProp<"rtl" | "ltr" | "auto">;
298
+ /**
287
299
  The hash of the [context](#lr.ContextTracker.constructor)
288
300
  that the node was parsed in, if any. Used to limit reuse of
289
301
  contextual nodes.
package/dist/index.js CHANGED
@@ -65,6 +65,22 @@ types that represent an expression could be tagged with an
65
65
  */
66
66
  NodeProp.group = new NodeProp({ deserialize: str => str.split(" ") });
67
67
  /**
68
+ Attached to nodes to indicate these should be
69
+ [displayed](https://codemirror.net/docs/ref/#language.syntaxTree)
70
+ in a bidirectional text isolate, so that direction-neutral
71
+ characters on their sides don't incorrectly get associated with
72
+ surrounding text. You'll generally want to set this for nodes
73
+ that contain arbitrary text, like strings and comments, and for
74
+ nodes that appear _inside_ arbitrary text, like HTML tags. When
75
+ not given a value, in a grammar declaration, defaults to
76
+ `"auto"`.
77
+ */
78
+ NodeProp.isolate = new NodeProp({ deserialize: value => {
79
+ if (value && value != "rtl" && value != "ltr" && value != "auto")
80
+ throw new RangeError("Invalid value for isolate: " + value);
81
+ return value || "auto";
82
+ } });
83
+ /**
68
84
  The hash of the [context](#lr.ContextTracker.constructor)
69
85
  that the node was parsed in, if any. Used to limit reuse of
70
86
  contextual nodes.
@@ -1936,18 +1952,14 @@ function sliceBuf(buf, startI, endI, nodes, positions, off) {
1936
1952
  // any other code, making violations of the immutability safe.
1937
1953
  function materialize(cursor) {
1938
1954
  let { node } = cursor, stack = [];
1955
+ let buffer = node.context.buffer;
1939
1956
  // Scan up to the nearest tree
1940
1957
  do {
1941
1958
  stack.push(cursor.index);
1942
1959
  cursor.parent();
1943
1960
  } while (!cursor.tree);
1944
1961
  // Find the index of the buffer in that tree
1945
- let i = 0, base = cursor.tree, off = 0;
1946
- for (;; i++) {
1947
- off = base.positions[i] + cursor.from;
1948
- if (off <= node.from && off + base.children[i].length >= node.to)
1949
- break;
1950
- }
1962
+ let base = cursor.tree, i = base.children.indexOf(buffer);
1951
1963
  let buf = base.children[i], b = buf.buffer, newStack = [i];
1952
1964
  // Split a level in the buffer, putting the nodes before and after
1953
1965
  // the child that contains `node` into new buffers.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lezer/common",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "Syntax tree data structure and parser interfaces for the lezer parser",
5
5
  "main": "dist/index.cjs",
6
6
  "type": "module",