@openrewrite/rewrite 8.111.0 → 8.112.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.
Files changed (42) hide show
  1. package/dist/javascript/add-import.d.ts +7 -2
  2. package/dist/javascript/add-import.d.ts.map +1 -1
  3. package/dist/javascript/add-import.js +47 -4
  4. package/dist/javascript/add-import.js.map +1 -1
  5. package/dist/javascript/binding.d.ts.map +1 -1
  6. package/dist/javascript/binding.js +15 -9
  7. package/dist/javascript/binding.js.map +1 -1
  8. package/dist/javascript/member-spellings.d.ts +1 -4
  9. package/dist/javascript/member-spellings.d.ts.map +1 -1
  10. package/dist/javascript/member-spellings.js +16 -26
  11. package/dist/javascript/member-spellings.js.map +1 -1
  12. package/dist/javascript/type-mapping.d.ts +1 -1
  13. package/dist/javascript/type-mapping.d.ts.map +1 -1
  14. package/dist/javascript/type-mapping.js +18 -34
  15. package/dist/javascript/type-mapping.js.map +1 -1
  16. package/dist/rewrite-javascript-version.txt +1 -1
  17. package/dist/rpc/index.d.ts +1 -0
  18. package/dist/rpc/index.d.ts.map +1 -1
  19. package/dist/rpc/index.js +2 -0
  20. package/dist/rpc/index.js.map +1 -1
  21. package/dist/rpc/msbuild-project.d.ts +96 -0
  22. package/dist/rpc/msbuild-project.d.ts.map +1 -0
  23. package/dist/rpc/msbuild-project.js +219 -0
  24. package/dist/rpc/msbuild-project.js.map +1 -0
  25. package/dist/yaml/markers.d.ts +9 -0
  26. package/dist/yaml/markers.d.ts.map +1 -1
  27. package/dist/yaml/markers.js +10 -1
  28. package/dist/yaml/markers.js.map +1 -1
  29. package/dist/yaml/parser.js +26 -19
  30. package/dist/yaml/parser.js.map +1 -1
  31. package/dist/yaml/print.js +15 -18
  32. package/dist/yaml/print.js.map +1 -1
  33. package/package.json +2 -2
  34. package/src/javascript/add-import.ts +46 -4
  35. package/src/javascript/binding.ts +20 -10
  36. package/src/javascript/member-spellings.ts +7 -15
  37. package/src/javascript/type-mapping.ts +18 -35
  38. package/src/rpc/index.ts +2 -0
  39. package/src/rpc/msbuild-project.ts +329 -0
  40. package/src/yaml/markers.ts +19 -1
  41. package/src/yaml/parser.ts +27 -19
  42. package/src/yaml/print.ts +16 -18
@@ -23,13 +23,15 @@ declare module "./tree" {
23
23
  namespace Yaml {
24
24
  export const Markers: {
25
25
  readonly OmitColon: "org.openrewrite.yaml.marker.OmitColon";
26
+ readonly TagBeforeAnchor: "org.openrewrite.yaml.marker.TagBeforeAnchor";
26
27
  };
27
28
  }
28
29
  }
29
30
 
30
31
  // At runtime actually attach it to Yaml
31
32
  (Yaml as any).Markers = {
32
- OmitColon: "org.openrewrite.yaml.marker.OmitColon"
33
+ OmitColon: "org.openrewrite.yaml.marker.OmitColon",
34
+ TagBeforeAnchor: "org.openrewrite.yaml.marker.TagBeforeAnchor"
33
35
  } as const;
34
36
 
35
37
  /**
@@ -50,6 +52,21 @@ export function omitColon(): OmitColon {
50
52
  };
51
53
  }
52
54
 
55
+ /**
56
+ * Marker on a scalar, mapping or sequence whose tag was written before its anchor, as in `!!str &a value`,
57
+ * so that it prints back in that order.
58
+ */
59
+ export interface TagBeforeAnchor extends Marker {
60
+ readonly kind: typeof Yaml.Markers.TagBeforeAnchor;
61
+ }
62
+
63
+ export function tagBeforeAnchor(): TagBeforeAnchor {
64
+ return {
65
+ kind: Yaml.Markers.TagBeforeAnchor,
66
+ id: randomId()
67
+ };
68
+ }
69
+
53
70
  /**
54
71
  * Registers an RPC codec for any marker without additional properties.
55
72
  */
@@ -68,3 +85,4 @@ function registerMarkerCodec<M extends Marker>(kind: M["kind"]) {
68
85
  }
69
86
 
70
87
  registerMarkerCodec(Yaml.Markers.OmitColon);
88
+ registerMarkerCodec(Yaml.Markers.TagBeforeAnchor);
@@ -592,7 +592,24 @@ class YamlCstReader {
592
592
  for (let i = 0; i < cst.items.length; i++) {
593
593
  const item = cst.items[i];
594
594
  const isLast = i === cst.items.length - 1;
595
- const result = this.convertFlowSequenceEntry(item, isLast, pendingPrefix);
595
+ let start = item.start || [];
596
+ const comma = start.findIndex(token => token.type === 'comma');
597
+ if (comma >= 0) {
598
+ if (comma > 0 && entries.length > 0) {
599
+ const previous = entries[entries.length - 1];
600
+ entries[entries.length - 1] = {
601
+ ...previous,
602
+ trailingCommaPrefix: (previous.trailingCommaPrefix ?? "") + this.concatenateSources(start.slice(0, comma))
603
+ };
604
+ }
605
+ start = start.slice(comma + 1);
606
+ }
607
+ if (isLast && item.key === undefined && !item.value &&
608
+ start.every(token => token.type === 'space' || token.type === 'newline' || token.type === 'comment')) {
609
+ pendingPrefix += this.concatenateSources(start);
610
+ break;
611
+ }
612
+ const result = this.convertFlowSequenceEntry({...item, start}, isLast, pendingPrefix);
596
613
  entries.push(result.entry);
597
614
  pendingPrefix = result.trailingContent;
598
615
  }
@@ -693,28 +710,13 @@ class YamlCstReader {
693
710
  }
694
711
 
695
712
  private convertFlowSequenceEntry(item: CstCollectionItem, isLast: boolean, pendingPrefix: string): {entry: Yaml.SequenceEntry, trailingContent: string} {
696
- // Start tokens may include comma from previous item
713
+ const startTokens = item.start || [];
697
714
  let prefix = pendingPrefix;
698
- let hasComma = false;
699
-
700
- for (const token of item.start || []) {
701
- if (token.type === 'comma') {
702
- hasComma = true;
703
- } else {
704
- prefix += token.source;
705
- }
706
- }
707
-
708
715
  let block: Yaml.Block;
709
716
  let trailing = "";
710
717
 
711
- if (item.value) {
712
- const valueResult = this.convertTokenWithTrailing(item.value);
713
- block = valueResult.node as Yaml.Block;
714
- trailing = valueResult.trailing;
715
- } else if (item.key !== undefined) {
716
- // Flow sequence can contain mapping entries: [a: 1, b: 2]
717
- const entryResult = this.convertFlowMappingEntry(item, "");
718
+ if (item.key !== undefined) {
719
+ const entryResult = this.convertFlowMappingEntry({...item, start: startTokens}, "");
718
720
  block = {
719
721
  kind: Yaml.Kind.Mapping,
720
722
  id: randomId(),
@@ -727,7 +729,13 @@ class YamlCstReader {
727
729
  tag: undefined
728
730
  };
729
731
  trailing = entryResult.trailingContent;
732
+ } else if (item.value) {
733
+ prefix += this.concatenateSources(startTokens);
734
+ const valueResult = this.convertTokenWithTrailing(item.value);
735
+ block = valueResult.node as Yaml.Block;
736
+ trailing = valueResult.trailing;
730
737
  } else {
738
+ prefix += this.concatenateSources(startTokens);
731
739
  block = this.createEmptyScalar();
732
740
  }
733
741
 
package/src/yaml/print.ts CHANGED
@@ -67,12 +67,7 @@ class YamlPrinter extends YamlVisitor<PrintOutputCapture> {
67
67
 
68
68
  protected async visitMapping(mapping: Yaml.Mapping, p: PrintOutputCapture): Promise<Yaml | undefined> {
69
69
  await this.beforeSyntax(mapping, p);
70
- if (mapping.anchor) {
71
- await this.visit(mapping.anchor, p);
72
- }
73
- if (mapping.tag) {
74
- await this.visit(mapping.tag, p);
75
- }
70
+ await this.visitProperties(mapping, mapping.anchor, mapping.tag, p);
76
71
  if (mapping.openingBracePrefix !== undefined) {
77
72
  p.append(mapping.openingBracePrefix);
78
73
  p.append('{');
@@ -102,12 +97,7 @@ class YamlPrinter extends YamlVisitor<PrintOutputCapture> {
102
97
 
103
98
  protected async visitScalar(scalar: Yaml.Scalar, p: PrintOutputCapture): Promise<Yaml | undefined> {
104
99
  await this.beforeSyntax(scalar, p);
105
- if (scalar.anchor) {
106
- await this.visit(scalar.anchor, p);
107
- }
108
- if (scalar.tag) {
109
- await this.visit(scalar.tag, p);
110
- }
100
+ await this.visitProperties(scalar, scalar.anchor, scalar.tag, p);
111
101
  switch (scalar.style) {
112
102
  case Yaml.ScalarStyle.DOUBLE_QUOTED:
113
103
  p.append('"');
@@ -138,12 +128,7 @@ class YamlPrinter extends YamlVisitor<PrintOutputCapture> {
138
128
 
139
129
  protected async visitSequence(sequence: Yaml.Sequence, p: PrintOutputCapture): Promise<Yaml | undefined> {
140
130
  await this.beforeSyntax(sequence, p);
141
- if (sequence.anchor) {
142
- await this.visit(sequence.anchor, p);
143
- }
144
- if (sequence.tag) {
145
- await this.visit(sequence.tag, p);
146
- }
131
+ await this.visitProperties(sequence, sequence.anchor, sequence.tag, p);
147
132
  if (sequence.openingBracketPrefix !== undefined) {
148
133
  p.append(sequence.openingBracketPrefix);
149
134
  p.append('[');
@@ -173,6 +158,19 @@ class YamlPrinter extends YamlVisitor<PrintOutputCapture> {
173
158
  return entry;
174
159
  }
175
160
 
161
+ private async visitProperties(yaml: Yaml, anchor: Yaml.Anchor | undefined, tag: Yaml.Tag | undefined, p: PrintOutputCapture): Promise<void> {
162
+ const tagBeforeAnchor = findMarker(yaml, Yaml.Markers.TagBeforeAnchor) !== undefined;
163
+ if (tagBeforeAnchor && tag) {
164
+ await this.visit(tag, p);
165
+ }
166
+ if (anchor) {
167
+ await this.visit(anchor, p);
168
+ }
169
+ if (!tagBeforeAnchor && tag) {
170
+ await this.visit(tag, p);
171
+ }
172
+ }
173
+
176
174
  protected async visitAnchor(anchor: Yaml.Anchor, p: PrintOutputCapture): Promise<Yaml | undefined> {
177
175
  await this.visitMarkers(anchor.markers, p);
178
176
  p.append(anchor.prefix);