@tsrx/language-server 0.7.12 → 0.7.14

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.
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- const require_server = require('./server-9-3sh49Z.js');
2
+ const require_server = require('./server-BkaXY_b_.js');
3
3
 
4
4
  //#region src/language-server.js
5
5
  require_server.createTsrxLanguageServer();
@@ -22692,6 +22692,32 @@ function typescript_notice(found, workspace_dirs) {
22692
22692
  * file, so that closing tag can belong to a later element (see `isUnclosed`).
22693
22693
  */
22694
22694
  const RAW_TEXT_OPENING_TAGS = /* @__PURE__ */ new Map([["style", /<style[\s/>]/], ["script", /<script[\s/>]/]]);
22695
+ const regex_name_escape = /\\u(?:\{([\da-fA-F]+)\}|([\da-fA-F]{4}))/g;
22696
+ /**
22697
+ * The name the Unicode escapes in `name` spell: `Inn\u0065r` is `Inner`. The
22698
+ * parser reads a JSX name so, and matches opening and closing tags by it.
22699
+ * @param {string} name
22700
+ * @returns {string}
22701
+ */
22702
+ function decodeNameEscapes(name) {
22703
+ return name.replace(regex_name_escape, (escape, braced, short) => {
22704
+ const code = Number.parseInt(braced ?? short, 16);
22705
+ return code <= 1114111 ? String.fromCodePoint(code) : escape;
22706
+ });
22707
+ }
22708
+ /**
22709
+ * A tag's name as the parser matches tags by it: a static name (`div`,
22710
+ * `ui.Item`, `svg:rect`) as its escapes spell it, a dynamic one (`{Tag}`) as
22711
+ * its expression is written.
22712
+ * @param {AST.Node} name The opening or closing element's `name`.
22713
+ * @param {string} sourceCode
22714
+ * @returns {string}
22715
+ */
22716
+ function tagNameText(name, sourceCode) {
22717
+ const { start, end } = name;
22718
+ const text = sourceCode.slice(start, end);
22719
+ return name.type === "JSXExpressionContainer" ? text : decodeNameEscapes(text);
22720
+ }
22695
22721
  /**
22696
22722
  * An element of the parsed source and, when the element is one of its children,
22697
22723
  * the element that holds it.
@@ -22743,10 +22769,7 @@ function findElement(node, end, parent = null) {
22743
22769
  */
22744
22770
  function isUnclosed(path, sourceCode) {
22745
22771
  /** @param {AST.TSRXJSXElement} element */
22746
- const name = (element) => {
22747
- const { start, end } = element.openingElement.name;
22748
- return sourceCode.slice(start, end);
22749
- };
22772
+ const name = (element) => tagNameText(element.openingElement.name, sourceCode);
22750
22773
  const { element } = path;
22751
22774
  const rawTextOpeningTag = RAW_TEXT_OPENING_TAGS.get(name(element));
22752
22775
  if (rawTextOpeningTag) {
@@ -22859,6 +22882,7 @@ async provideAutoInsertSnippet(document, position, lastChange, _token) {
22859
22882
  return null;
22860
22883
  }
22861
22884
  log$8("Tag matched:", tagName);
22885
+ tagName = decodeNameEscapes(tagName);
22862
22886
  if (VOID_ELEMENTS.has(tagName.toLowerCase())) {
22863
22887
  log$8("Void element, skipping auto-close:", tagName);
22864
22888
  return null;
@@ -22893,6 +22917,8 @@ function escapeSnippetText(text) {
22893
22917
  function unescapeSnippetText(snippet) {
22894
22918
  return snippet.replace(/\\([\\$}])/g, "$1");
22895
22919
  }
22920
+ const name_escape = String.raw`\\u(?:[\da-fA-F]{4}|\{[\da-fA-F]+\})`;
22921
+ const regex_opening_tag_name = new RegExp(String.raw`^<((?:[@$_\p{ID_Start}]|${name_escape})(?:[$\p{ID_Continue}\u200C\u200D.-]|${name_escape})*)`, "u");
22896
22922
  /**
22897
22923
  * Match an opening tag `<name …>` that ends exactly at the end of `text` and return its name.
22898
22924
  *
@@ -22904,13 +22930,14 @@ function unescapeSnippetText(snippet) {
22904
22930
  * self-closing (`<style apply={theme} />`).
22905
22931
  *
22906
22932
  * A name is made of JavaScript identifier characters, `.` and `-`, so `$` and non-ASCII
22907
- * letters can appear anywhere in it (`<ui.$Item>`, `<Café>`).
22933
+ * letters can appear anywhere in it (`<ui.$Item>`, `<Café>`), and Unicode escapes
22934
+ * (`<Inn\u0065r>`), which the name is returned with, as written.
22908
22935
  *
22909
22936
  * @param {string} text - Source text from the tag's `<` up to and including the typed `>`
22910
22937
  * @returns {string | null}
22911
22938
  */
22912
22939
  function matchOpeningTag(text) {
22913
- const nameMatch = text.match(/^<([@$_\p{ID_Start}][$\p{ID_Continue}\u200C\u200D.-]*)/u);
22940
+ const nameMatch = text.match(regex_opening_tag_name);
22914
22941
  if (!nameMatch) return null;
22915
22942
  let depth = 0;
22916
22943
  /** @type {string | null} */
@@ -26331,4 +26358,4 @@ Object.defineProperty(exports, 'createTsrxLanguageServer', {
26331
26358
  return createTsrxLanguageServer;
26332
26359
  }
26333
26360
  });
26334
- //# sourceMappingURL=server-9-3sh49Z.js.map
26361
+ //# sourceMappingURL=server-BkaXY_b_.js.map