typia 13.1.0 → 13.1.1

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.
@@ -407,13 +407,86 @@ func metadata_js_doc_comment_text(list *nativeast.NodeList) string {
407
407
  }
408
408
  parts := []string{}
409
409
  for _, node := range list.Nodes {
410
- if node != nil {
410
+ if node == nil {
411
+ continue
412
+ }
413
+ switch node.Kind {
414
+ case nativeast.KindJSDocText:
411
415
  parts = append(parts, node.Text())
416
+ case nativeast.KindJSDocLink,
417
+ nativeast.KindJSDocLinkCode,
418
+ nativeast.KindJSDocLinkPlain:
419
+ parts = append(parts, metadata_js_doc_link_text(node))
412
420
  }
413
421
  }
414
422
  return metadata_clean_js_doc_text(strings.Join(parts, ""))
415
423
  }
416
424
 
425
+ func metadata_js_doc_link_text(node *nativeast.Node) string {
426
+ if node == nil {
427
+ return ""
428
+ }
429
+ name := node.Name()
430
+ text := strings.Trim(node.Text(), " ")
431
+ if name == nil {
432
+ return text
433
+ }
434
+ nameText := metadata_js_doc_entity_name_text(name)
435
+ if (nameText == "http" || nameText == "https") && strings.HasPrefix(text, "://") {
436
+ target := nameText + text
437
+ index := strings.IndexAny(target, " |")
438
+ if index == -1 {
439
+ return target
440
+ }
441
+ label := metadata_js_doc_link_label(target[index:])
442
+ if label != "" {
443
+ return label
444
+ }
445
+ return target[:index]
446
+ }
447
+
448
+ suffix := ""
449
+ if strings.HasPrefix(text, "()") {
450
+ suffix = "()"
451
+ text = text[2:]
452
+ }
453
+ if label := metadata_js_doc_link_label(text); label != "" {
454
+ return label
455
+ }
456
+ return nameText + suffix
457
+ }
458
+
459
+ func metadata_js_doc_link_label(text string) string {
460
+ text = strings.TrimLeft(text, " ")
461
+ text = strings.TrimPrefix(text, "|")
462
+ return strings.TrimSpace(text)
463
+ }
464
+
465
+ func metadata_js_doc_entity_name_text(node *nativeast.Node) string {
466
+ if node == nil {
467
+ return ""
468
+ }
469
+ switch node.Kind {
470
+ case nativeast.KindIdentifier:
471
+ return node.Text()
472
+ case nativeast.KindQualifiedName:
473
+ name := node.AsQualifiedName()
474
+ if name == nil {
475
+ return ""
476
+ }
477
+ return metadata_js_doc_entity_name_text(name.Left) + "." + metadata_js_doc_entity_name_text(name.Right)
478
+ case nativeast.KindPropertyAccessExpression:
479
+ return metadata_js_doc_entity_name_text(node.Expression()) + "." + metadata_js_doc_entity_name_text(node.Name())
480
+ case nativeast.KindParenthesizedExpression,
481
+ nativeast.KindExpressionWithTypeArguments:
482
+ return metadata_js_doc_entity_name_text(node.Expression())
483
+ case nativeast.KindJSDocNameReference:
484
+ return metadata_js_doc_entity_name_text(node.Name())
485
+ default:
486
+ return ""
487
+ }
488
+ }
489
+
417
490
  func metadata_clean_js_doc_text(text string) string {
418
491
  text = strings.ReplaceAll(text, "\r\n", "\n")
419
492
  text = strings.ReplaceAll(text, "\r", "\n")
@@ -0,0 +1,69 @@
1
+ //go:build typia_native_internal
2
+ // +build typia_native_internal
3
+
4
+ package metadata
5
+
6
+ import (
7
+ "path/filepath"
8
+ "testing"
9
+
10
+ nativeast "github.com/microsoft/typescript-go/shim/ast"
11
+ nativecore "github.com/microsoft/typescript-go/shim/core"
12
+ nativeparser "github.com/microsoft/typescript-go/shim/parser"
13
+ )
14
+
15
+ // TestJsDocLinkText verifies the metadata helper renders visible inline links.
16
+ //
17
+ // JSDoc link nodes split their entity target into Name() and their optional
18
+ // display label into Text(). This test pins the shared renderer directly so all
19
+ // metadata consumers keep qualified targets, normalized labels, call suffixes,
20
+ // URLs, and tag comments without depending only on an application-programmer
21
+ // integration.
22
+ //
23
+ // 1. Parse a property comment containing plain, qualified, labeled, URL, and
24
+ // unresolved and malformed links, empty labels, call suffixes, plus a link
25
+ // inside a JSDoc tag.
26
+ // 2. Reflect the property's description and tags through the metadata helpers.
27
+ // 3. Assert the visible text and punctuation are preserved deterministically.
28
+ func TestJsDocLinkText(t *testing.T) {
29
+ file := nativeparser.ParseSourceFile(
30
+ nativeast.SourceFileParseOptions{FileName: filepath.ToSlash(filepath.Join(t.TempDir(), "links.ts"))},
31
+ `interface ITarget {
32
+ value: string;
33
+ }
34
+ interface IBox {
35
+ /**
36
+ * Plain; {@link ITarget}; {@link ITarget.value};
37
+ * {@link ITarget | label}; {@linkcode ITarget};
38
+ * {@linkplain ITarget.value}; {@link MissingTarget};
39
+ * {@link https://example.com/docs}; {@link https://example.com/docs | docs}.
40
+ * {@link ITarget | }; {@link makeTarget()}; {@link makeTarget() | maker}.
41
+ * {@link Missing.};
42
+ * @title {@link ITarget titled target}
43
+ */
44
+ field: string;
45
+ }
46
+ `,
47
+ nativecore.ScriptKindTS,
48
+ )
49
+ member := file.Statements.Nodes[1].AsInterfaceDeclaration().Members.Nodes[0]
50
+ symbol := &nativeast.Symbol{
51
+ Name: "field",
52
+ ValueDeclaration: member,
53
+ Declarations: []*nativeast.Node{member},
54
+ }
55
+ description := metadata_node_description(symbol)
56
+ if description == nil {
57
+ t.Fatal("description was not reflected")
58
+ }
59
+ if *description != "Plain; ITarget; ITarget.value;\nlabel; ITarget;\nITarget.value; MissingTarget;\nhttps://example.com/docs; docs.\nITarget; makeTarget(); maker.\nMissing.;" {
60
+ t.Fatalf("unexpected description: %q", *description)
61
+ }
62
+ tags := metadata_node_js_doc_tags(symbol)
63
+ if len(tags) != 1 || tags[0].Name != "title" || len(tags[0].Text) != 1 || tags[0].Text[0].Text != "titled target" {
64
+ t.Fatalf("unexpected tags: %#v", tags)
65
+ }
66
+ if metadata_js_doc_link_text(nil) != "" {
67
+ t.Fatal("nil JSDoc link should render empty text")
68
+ }
69
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typia",
3
- "version": "13.1.0",
3
+ "version": "13.1.1",
4
4
  "description": "Superfast runtime validators with only one line",
5
5
  "main": "lib/index.js",
6
6
  "exports": {
@@ -50,8 +50,8 @@
50
50
  "inquirer": "^8.2.5",
51
51
  "randexp": "^0.5.3",
52
52
  "tinyglobby": "^0.2.12",
53
- "@typia/interface": "^13.1.0",
54
- "@typia/utils": "^13.1.0"
53
+ "@typia/interface": "^13.1.1",
54
+ "@typia/utils": "^13.1.1"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@types/inquirer": "^8.2.5",