@openrewrite/rewrite 8.92.16 → 8.92.18
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/README.md +48 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/java/formatting-utils.d.ts +2 -1
- package/dist/java/formatting-utils.d.ts.map +1 -1
- package/dist/java/formatting-utils.js +4 -3
- package/dist/java/formatting-utils.js.map +1 -1
- package/dist/java/rpc.d.ts.map +1 -1
- package/dist/java/rpc.js +2 -0
- package/dist/java/rpc.js.map +1 -1
- package/dist/java/tree.d.ts +8 -0
- package/dist/java/tree.d.ts.map +1 -1
- package/dist/java/tree.js +11 -1
- package/dist/java/tree.js.map +1 -1
- package/dist/java/type.d.ts +7 -1
- package/dist/java/type.d.ts.map +1 -1
- package/dist/java/type.js +16 -1
- package/dist/java/type.js.map +1 -1
- package/dist/javascript/add-import.d.ts +27 -21
- package/dist/javascript/add-import.d.ts.map +1 -1
- package/dist/javascript/add-import.js +303 -143
- package/dist/javascript/add-import.js.map +1 -1
- package/dist/javascript/amd.d.ts.map +1 -1
- package/dist/javascript/amd.js +25 -10
- package/dist/javascript/amd.js.map +1 -1
- package/dist/javascript/autodetect.js +36 -45
- package/dist/javascript/autodetect.js.map +1 -1
- package/dist/javascript/binding.d.ts +6 -4
- package/dist/javascript/binding.d.ts.map +1 -1
- package/dist/javascript/binding.js +54 -18
- package/dist/javascript/binding.js.map +1 -1
- package/dist/javascript/comparator.d.ts +22 -5
- package/dist/javascript/comparator.d.ts.map +1 -1
- package/dist/javascript/comparator.js +120 -38
- package/dist/javascript/comparator.js.map +1 -1
- package/dist/javascript/format/format.d.ts +2 -0
- package/dist/javascript/format/format.d.ts.map +1 -1
- package/dist/javascript/format/format.js +11 -1
- package/dist/javascript/format/format.js.map +1 -1
- package/dist/javascript/format/tabs-and-indents-visitor.d.ts.map +1 -1
- package/dist/javascript/format/tabs-and-indents-visitor.js +31 -4
- package/dist/javascript/format/tabs-and-indents-visitor.js.map +1 -1
- package/dist/javascript/index.d.ts +4 -2
- package/dist/javascript/index.d.ts.map +1 -1
- package/dist/javascript/index.js +10 -1
- package/dist/javascript/index.js.map +1 -1
- package/dist/javascript/markers.d.ts +12 -0
- package/dist/javascript/markers.d.ts.map +1 -1
- package/dist/javascript/markers.js +81 -2
- package/dist/javascript/markers.js.map +1 -1
- package/dist/javascript/method-matcher.d.ts +13 -2
- package/dist/javascript/method-matcher.d.ts.map +1 -1
- package/dist/javascript/method-matcher.js +32 -19
- package/dist/javascript/method-matcher.js.map +1 -1
- package/dist/javascript/node-resolution-result.js +3 -2
- package/dist/javascript/node-resolution-result.js.map +1 -1
- package/dist/javascript/package-name.d.ts +6 -0
- package/dist/javascript/package-name.d.ts.map +1 -0
- package/dist/javascript/package-name.js +47 -0
- package/dist/javascript/package-name.js.map +1 -0
- package/dist/javascript/parser.d.ts +9 -0
- package/dist/javascript/parser.d.ts.map +1 -1
- package/dist/javascript/parser.js +185 -88
- package/dist/javascript/parser.js.map +1 -1
- package/dist/javascript/preconditions.d.ts +4 -1
- package/dist/javascript/preconditions.d.ts.map +1 -1
- package/dist/javascript/preconditions.js +7 -4
- package/dist/javascript/preconditions.js.map +1 -1
- package/dist/javascript/print.d.ts +10 -1
- package/dist/javascript/print.d.ts.map +1 -1
- package/dist/javascript/print.js +120 -77
- package/dist/javascript/print.js.map +1 -1
- package/dist/javascript/recipes/change-method-target-to-import.d.ts +29 -0
- package/dist/javascript/recipes/change-method-target-to-import.d.ts.map +1 -0
- package/dist/javascript/recipes/change-method-target-to-import.js +164 -0
- package/dist/javascript/recipes/change-method-target-to-import.js.map +1 -0
- package/dist/javascript/recipes/index.d.ts +1 -0
- package/dist/javascript/recipes/index.d.ts.map +1 -1
- package/dist/javascript/recipes/index.js +1 -0
- package/dist/javascript/recipes/index.js.map +1 -1
- package/dist/javascript/scope.d.ts +60 -16
- package/dist/javascript/scope.d.ts.map +1 -1
- package/dist/javascript/scope.js +596 -131
- package/dist/javascript/scope.js.map +1 -1
- package/dist/javascript/search/uses-method.d.ts +1 -1
- package/dist/javascript/search/uses-method.d.ts.map +1 -1
- package/dist/javascript/search/uses-method.js +2 -2
- package/dist/javascript/search/uses-method.js.map +1 -1
- package/dist/javascript/search/uses-type.d.ts +14 -1
- package/dist/javascript/search/uses-type.d.ts.map +1 -1
- package/dist/javascript/search/uses-type.js +24 -9
- package/dist/javascript/search/uses-type.js.map +1 -1
- package/dist/javascript/templating/bindings.d.ts +1 -1
- package/dist/javascript/templating/bindings.d.ts.map +1 -1
- package/dist/javascript/templating/bindings.js +10 -50
- package/dist/javascript/templating/bindings.js.map +1 -1
- package/dist/javascript/templating/comparator.d.ts +8 -11
- package/dist/javascript/templating/comparator.d.ts.map +1 -1
- package/dist/javascript/templating/comparator.js +12 -110
- package/dist/javascript/templating/comparator.js.map +1 -1
- package/dist/javascript/templating/engine.d.ts +34 -24
- package/dist/javascript/templating/engine.d.ts.map +1 -1
- package/dist/javascript/templating/engine.js +208 -115
- package/dist/javascript/templating/engine.js.map +1 -1
- package/dist/javascript/templating/pattern.d.ts +11 -5
- package/dist/javascript/templating/pattern.d.ts.map +1 -1
- package/dist/javascript/templating/pattern.js +86 -20
- package/dist/javascript/templating/pattern.js.map +1 -1
- package/dist/javascript/templating/placeholder-replacement.d.ts +34 -3
- package/dist/javascript/templating/placeholder-replacement.d.ts.map +1 -1
- package/dist/javascript/templating/placeholder-replacement.js +126 -60
- package/dist/javascript/templating/placeholder-replacement.js.map +1 -1
- package/dist/javascript/templating/precedence.d.ts +3 -1
- package/dist/javascript/templating/precedence.d.ts.map +1 -1
- package/dist/javascript/templating/precedence.js +28 -8
- package/dist/javascript/templating/precedence.js.map +1 -1
- package/dist/javascript/templating/template.d.ts +7 -6
- package/dist/javascript/templating/template.d.ts.map +1 -1
- package/dist/javascript/templating/template.js +31 -28
- package/dist/javascript/templating/template.js.map +1 -1
- package/dist/javascript/templating/types.d.ts +6 -3
- package/dist/javascript/templating/types.d.ts.map +1 -1
- package/dist/javascript/templating/utils.d.ts +10 -1
- package/dist/javascript/templating/utils.d.ts.map +1 -1
- package/dist/javascript/templating/utils.js +22 -3
- package/dist/javascript/templating/utils.js.map +1 -1
- package/dist/javascript/tree-debug.d.ts +2 -0
- package/dist/javascript/tree-debug.d.ts.map +1 -1
- package/dist/javascript/tree-debug.js +6 -0
- package/dist/javascript/tree-debug.js.map +1 -1
- package/dist/javascript/tsconfig.d.ts.map +1 -1
- package/dist/javascript/tsconfig.js +7 -17
- package/dist/javascript/tsconfig.js.map +1 -1
- package/dist/javascript/type-mapping.d.ts +35 -16
- package/dist/javascript/type-mapping.d.ts.map +1 -1
- package/dist/javascript/type-mapping.js +271 -252
- package/dist/javascript/type-mapping.js.map +1 -1
- package/dist/javascript/type-report-cli.d.ts +7 -0
- package/dist/javascript/type-report-cli.d.ts.map +1 -0
- package/dist/javascript/type-report-cli.js +129 -0
- package/dist/javascript/type-report-cli.js.map +1 -0
- package/dist/javascript/type-report.d.ts +61 -0
- package/dist/javascript/type-report.d.ts.map +1 -0
- package/dist/javascript/type-report.js +488 -0
- package/dist/javascript/type-report.js.map +1 -0
- package/dist/markers.d.ts +4 -0
- package/dist/markers.d.ts.map +1 -1
- package/dist/markers.js +8 -0
- package/dist/markers.js.map +1 -1
- package/dist/print.d.ts +6 -1
- package/dist/print.d.ts.map +1 -1
- package/dist/print.js +21 -7
- package/dist/print.js.map +1 -1
- package/dist/recipe.d.ts +5 -0
- package/dist/recipe.d.ts.map +1 -1
- package/dist/recipe.js +5 -0
- package/dist/recipe.js.map +1 -1
- package/dist/rewrite-javascript-version.txt +1 -1
- package/dist/rpc/java-rpc-client.d.ts +2 -0
- package/dist/rpc/java-rpc-client.d.ts.map +1 -1
- package/dist/rpc/java-rpc-client.js +1 -0
- package/dist/rpc/java-rpc-client.js.map +1 -1
- package/dist/rpc/queue.d.ts +24 -0
- package/dist/rpc/queue.d.ts.map +1 -1
- package/dist/rpc/queue.js +71 -11
- package/dist/rpc/queue.js.map +1 -1
- package/dist/rpc/request/get-object.d.ts +4 -0
- package/dist/rpc/request/get-object.d.ts.map +1 -1
- package/dist/rpc/request/get-object.js +23 -1
- package/dist/rpc/request/get-object.js.map +1 -1
- package/dist/rpc/request/parse.d.ts.map +1 -1
- package/dist/rpc/request/parse.js +3 -1
- package/dist/rpc/request/parse.js.map +1 -1
- package/dist/rpc/request/prepare-recipe.d.ts +3 -1
- package/dist/rpc/request/prepare-recipe.d.ts.map +1 -1
- package/dist/rpc/request/prepare-recipe.js +13 -6
- package/dist/rpc/request/prepare-recipe.js.map +1 -1
- package/dist/rpc/request/print.d.ts +8 -2
- package/dist/rpc/request/print.d.ts.map +1 -1
- package/dist/rpc/request/print.js +12 -9
- package/dist/rpc/request/print.js.map +1 -1
- package/dist/rpc/rewrite-rpc.d.ts +3 -2
- package/dist/rpc/rewrite-rpc.d.ts.map +1 -1
- package/dist/rpc/rewrite-rpc.js +9 -3
- package/dist/rpc/rewrite-rpc.js.map +1 -1
- package/dist/rpc/server.d.ts.map +1 -1
- package/dist/rpc/server.js +19 -5
- package/dist/rpc/server.js.map +1 -1
- package/dist/search/is-source-file.d.ts +1 -0
- package/dist/search/is-source-file.d.ts.map +1 -1
- package/dist/search/is-source-file.js +7 -2
- package/dist/search/is-source-file.js.map +1 -1
- package/dist/test/java-rpc.d.ts.map +1 -1
- package/dist/test/java-rpc.js +3 -0
- package/dist/test/java-rpc.js.map +1 -1
- package/dist/test/rewrite-test.d.ts +5 -0
- package/dist/test/rewrite-test.d.ts.map +1 -1
- package/dist/test/rewrite-test.js +14 -3
- package/dist/test/rewrite-test.js.map +1 -1
- package/package.json +4 -3
- package/src/index.ts +3 -1
- package/src/java/formatting-utils.ts +5 -4
- package/src/java/rpc.ts +2 -0
- package/src/java/tree.ts +15 -0
- package/src/java/type.ts +19 -2
- package/src/javascript/add-import.ts +338 -152
- package/src/javascript/amd.ts +28 -12
- package/src/javascript/autodetect.ts +32 -41
- package/src/javascript/binding.ts +64 -22
- package/src/javascript/comparator.ts +129 -43
- package/src/javascript/format/format.ts +9 -0
- package/src/javascript/format/tabs-and-indents-visitor.ts +30 -3
- package/src/javascript/index.ts +6 -3
- package/src/javascript/markers.ts +77 -5
- package/src/javascript/method-matcher.ts +34 -22
- package/src/javascript/node-resolution-result.ts +3 -2
- package/src/javascript/package-name.ts +45 -0
- package/src/javascript/parser.ts +200 -91
- package/src/javascript/preconditions.ts +7 -4
- package/src/javascript/print.ts +123 -76
- package/src/javascript/recipes/change-method-target-to-import.ts +178 -0
- package/src/javascript/recipes/index.ts +1 -0
- package/src/javascript/scope.ts +705 -169
- package/src/javascript/search/uses-method.ts +2 -2
- package/src/javascript/search/uses-type.ts +30 -9
- package/src/javascript/templating/bindings.ts +13 -38
- package/src/javascript/templating/comparator.ts +16 -127
- package/src/javascript/templating/engine.ts +236 -129
- package/src/javascript/templating/pattern.ts +107 -28
- package/src/javascript/templating/placeholder-replacement.ts +154 -62
- package/src/javascript/templating/precedence.ts +33 -11
- package/src/javascript/templating/template.ts +35 -30
- package/src/javascript/templating/types.ts +6 -3
- package/src/javascript/templating/utils.ts +24 -2
- package/src/javascript/tree-debug.ts +9 -0
- package/src/javascript/tsconfig.ts +7 -17
- package/src/javascript/type-mapping.ts +277 -255
- package/src/javascript/type-report-cli.ts +96 -0
- package/src/javascript/type-report.ts +575 -0
- package/src/markers.ts +8 -0
- package/src/print.ts +23 -8
- package/src/recipe.ts +6 -0
- package/src/rpc/java-rpc-client.ts +3 -0
- package/src/rpc/queue.ts +80 -7
- package/src/rpc/request/get-object.ts +24 -0
- package/src/rpc/request/parse.ts +4 -1
- package/src/rpc/request/prepare-recipe.ts +16 -6
- package/src/rpc/request/print.ts +12 -8
- package/src/rpc/rewrite-rpc.ts +16 -5
- package/src/rpc/server.ts +18 -6
- package/src/search/is-source-file.ts +8 -3
- package/src/test/java-rpc.ts +3 -0
- package/src/test/rewrite-test.ts +14 -3
package/src/javascript/index.ts
CHANGED
|
@@ -29,14 +29,17 @@ export * from "./method-matcher";
|
|
|
29
29
|
export * from "./format";
|
|
30
30
|
export * from "./autodetect";
|
|
31
31
|
export * from "./tree-debug";
|
|
32
|
+
// The comparator visitors stay internal so what they compare is free to change.
|
|
33
|
+
export {isEqual} from "./comparator";
|
|
34
|
+
export * from "./type-report";
|
|
32
35
|
export * from "./project-parser";
|
|
33
36
|
|
|
34
|
-
export type {Scope} from "./scope";
|
|
37
|
+
export type {Scope, Meaning, Reference} from "./scope";
|
|
35
38
|
// `cursorOf` is deliberately absent: a visitor of one's own reaches `this.cursor` directly, and
|
|
36
39
|
// the free functions that have no visitor to reach it through are already in this list.
|
|
37
40
|
export {
|
|
38
|
-
scopeOf, namesDeclaredIn, namesDeclaredWithin, namesUsedIn, namesReferencedWithin, bindingNames,
|
|
39
|
-
isValueReference, declarationsOf, compilationUnitOf, walk
|
|
41
|
+
scopeOf, namesDeclaredIn, namesDeclaredWithin, namesUsedIn, namesUsedWithin, namesReferencedWithin, bindingNames,
|
|
42
|
+
deconflict, isReference, isValueReference, isWrite, resolve, referencesOf, declarationsOf, compilationUnitOf, walk
|
|
40
43
|
} from "./scope";
|
|
41
44
|
export type {QuoteChar, AddImportOptions} from "./add-import";
|
|
42
45
|
export {ImportStyle, moduleNameOf, AddImport} from "./add-import";
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import {Marker} from "../markers";
|
|
16
|
+
import {Marker, MarkersKind} from "../markers";
|
|
17
17
|
import {J} from "../java";
|
|
18
18
|
import {JS} from "./tree";
|
|
19
19
|
import {RpcCodecs, RpcReceiveQueue, RpcSendQueue} from "../rpc";
|
|
@@ -24,10 +24,12 @@ import {
|
|
|
24
24
|
StyleKind,
|
|
25
25
|
TabsAndIndentsStyle,
|
|
26
26
|
WrappingAndBracesStyle,
|
|
27
|
-
WrappingAndBracesStyleDetailKind
|
|
27
|
+
WrappingAndBracesStyleDetailKind,
|
|
28
|
+
prettierStyle
|
|
28
29
|
} from "./style";
|
|
29
|
-
import {Autodetect} from "./autodetect";
|
|
30
|
+
import {Autodetect, autodetect} from "./autodetect";
|
|
30
31
|
import {updateIfChanged} from "../util";
|
|
32
|
+
import {NamedStyles, Style} from "../style";
|
|
31
33
|
|
|
32
34
|
declare module "./tree" {
|
|
33
35
|
namespace JS {
|
|
@@ -37,6 +39,7 @@ declare module "./tree" {
|
|
|
37
39
|
readonly NonNullAssertion: "org.openrewrite.javascript.marker.NonNullAssertion";
|
|
38
40
|
readonly DelegatedYield: "org.openrewrite.javascript.marker.DelegatedYield";
|
|
39
41
|
readonly FunctionDeclaration: "org.openrewrite.javascript.marker.FunctionDeclaration";
|
|
42
|
+
readonly Computed: "org.openrewrite.javascript.marker.Computed";
|
|
40
43
|
};
|
|
41
44
|
}
|
|
42
45
|
}
|
|
@@ -48,6 +51,7 @@ declare module "./tree" {
|
|
|
48
51
|
Optional: "org.openrewrite.javascript.marker.Optional",
|
|
49
52
|
NonNullAssertion: "org.openrewrite.javascript.marker.NonNullAssertion",
|
|
50
53
|
FunctionDeclaration: "org.openrewrite.javascript.marker.FunctionDeclaration",
|
|
54
|
+
Computed: "org.openrewrite.javascript.marker.Computed",
|
|
51
55
|
} as const;
|
|
52
56
|
|
|
53
57
|
/**
|
|
@@ -80,6 +84,18 @@ export interface FunctionDeclaration extends Marker {
|
|
|
80
84
|
readonly prefix: J.Space;
|
|
81
85
|
}
|
|
82
86
|
|
|
87
|
+
/**
|
|
88
|
+
* A name written in brackets where the model has room for an identifier only, as the
|
|
89
|
+
* member of `enum A { ['b'] }` is. The identifier holds the bracketed literal.
|
|
90
|
+
*/
|
|
91
|
+
export interface Computed extends Marker {
|
|
92
|
+
readonly kind: typeof JS.Markers.Computed;
|
|
93
|
+
/**
|
|
94
|
+
* The space before the closing bracket.
|
|
95
|
+
*/
|
|
96
|
+
readonly suffix: J.Space;
|
|
97
|
+
}
|
|
98
|
+
|
|
83
99
|
/**
|
|
84
100
|
* Registers an RPC codec for any marker that has a `prefix: J.Space` field.
|
|
85
101
|
*/
|
|
@@ -107,11 +123,26 @@ registerPrefixedMarkerCodec<Generator>(JS.Markers.Generator);
|
|
|
107
123
|
registerPrefixedMarkerCodec<NonNullAssertion>(JS.Markers.NonNullAssertion);
|
|
108
124
|
registerPrefixedMarkerCodec<FunctionDeclaration>(JS.Markers.FunctionDeclaration);
|
|
109
125
|
|
|
126
|
+
RpcCodecs.registerCodec(JS.Markers.Computed, {
|
|
127
|
+
async rpcReceive(before: Computed, q: RpcReceiveQueue): Promise<Computed> {
|
|
128
|
+
return updateIfChanged(before, {
|
|
129
|
+
id: await q.receive(before.id),
|
|
130
|
+
suffix: await q.receive(before.suffix),
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
|
|
134
|
+
async rpcSend(after: Computed, q: RpcSendQueue): Promise<void> {
|
|
135
|
+
await q.getAndSend(after, a => a.id);
|
|
136
|
+
await q.getAndSend(after, a => a.suffix);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
|
|
110
140
|
// Register codec for PrettierStyle (a NamedStyles that contains Prettier configuration)
|
|
111
141
|
// Only serialize the variable fields; constant fields are defined in the interface
|
|
112
142
|
RpcCodecs.registerCodec(StyleKind.PrettierStyle, {
|
|
113
143
|
async rpcReceive(before: PrettierStyle, q: RpcReceiveQueue): Promise<PrettierStyle> {
|
|
114
|
-
|
|
144
|
+
// the fields that never vary are not sent, so a marker first met here does not have them yet
|
|
145
|
+
return updateIfChanged(before.name ? before : {...prettierStyle(before.id, {}), ...before}, {
|
|
115
146
|
id: await q.receive(before.id),
|
|
116
147
|
config: await q.receive(before.config),
|
|
117
148
|
prettierVersion: await q.receive(before.prettierVersion),
|
|
@@ -131,7 +162,7 @@ RpcCodecs.registerCodec(StyleKind.PrettierStyle, {
|
|
|
131
162
|
// Only serialize the variable fields (id, styles); constant fields are defined in the interface
|
|
132
163
|
RpcCodecs.registerCodec(StyleKind.Autodetect, {
|
|
133
164
|
async rpcReceive(before: Autodetect, q: RpcReceiveQueue): Promise<Autodetect> {
|
|
134
|
-
return updateIfChanged(before, {
|
|
165
|
+
return updateIfChanged(before.name ? before : {...autodetect(before.id, []), ...before}, {
|
|
135
166
|
id: await q.receive(before.id),
|
|
136
167
|
styles: (await q.receiveList(before.styles))!,
|
|
137
168
|
});
|
|
@@ -266,3 +297,44 @@ RpcCodecs.registerCodec(StyleKind.WrappingAndBracesStyle, {
|
|
|
266
297
|
await q.getAndSend(after, a => a.keepWhenReformatting);
|
|
267
298
|
}
|
|
268
299
|
});
|
|
300
|
+
|
|
301
|
+
const styleDetailKinds = new Set<string>([
|
|
302
|
+
...Object.values(SpacesStyleDetailKind),
|
|
303
|
+
...Object.values(WrappingAndBracesStyleDetailKind)
|
|
304
|
+
]);
|
|
305
|
+
|
|
306
|
+
function detailKind(styleKind: string, field: string): string | undefined {
|
|
307
|
+
const kind = `${styleKind}$${field.charAt(0).toUpperCase()}${field.slice(1)}`;
|
|
308
|
+
return styleDetailKinds.has(kind) ? kind : undefined;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function styleFromValue(value: any): Style {
|
|
312
|
+
if (value === null || typeof value !== "object") {
|
|
313
|
+
return value;
|
|
314
|
+
}
|
|
315
|
+
const {"@c": kind, "@ref": _ref, ...fields} = value;
|
|
316
|
+
for (const [field, detail] of Object.entries(fields)) {
|
|
317
|
+
const kindOfDetail = detailKind(kind, field);
|
|
318
|
+
if (kindOfDetail && detail !== null && typeof detail === "object") {
|
|
319
|
+
fields[field] = {kind: kindOfDetail, ...detail};
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return {kind, ...fields};
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function styleToValue({kind, ...fields}: Style & Record<string, any>, ref: number): any {
|
|
326
|
+
for (const [field, detail] of Object.entries(fields)) {
|
|
327
|
+
if (detailKind(kind, field) && detail !== null && typeof detail === "object") {
|
|
328
|
+
const {kind: _kind, ...detailFields} = detail;
|
|
329
|
+
fields[field] = detailFields;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return {"@c": kind, "@ref": ref, ...fields};
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// A plain NamedStyles has no codec on either side, so it travels in the shape Java's serializer gives it
|
|
336
|
+
RpcCodecs.registerValueCodec(MarkersKind.NamedStyles, {
|
|
337
|
+
fromValue: (value: NamedStyles): NamedStyles => ({...value, styles: (value.styles ?? []).map(styleFromValue)}),
|
|
338
|
+
// Java's deserializer wants an object id on each style, and gives the first to the set itself
|
|
339
|
+
toValue: (after: NamedStyles) => ({...after, styles: after.styles.map((style, i) => styleToValue(style, i + 2))})
|
|
340
|
+
});
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import {Type} from "../java";
|
|
2
2
|
import FullyQualified = Type.FullyQualified;
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Matches a method type against a `<declaring type> <name>(<args>)` pattern.
|
|
6
|
+
* `REWRITE_JAVASCRIPT_DUMP_TYPES=1` in a test run prints the pattern each call would match.
|
|
7
|
+
*
|
|
8
|
+
* With `matchOverrides`, the pattern's type may also be a supertype or interface of the declaring
|
|
9
|
+
* type, as in Java. A pattern naming a subtype of the declaring type never matches.
|
|
10
|
+
*/
|
|
4
11
|
export class MethodMatcher {
|
|
5
12
|
private readonly packagePattern: string;
|
|
6
13
|
private readonly typePattern: string;
|
|
7
14
|
private readonly methodPattern: string;
|
|
8
15
|
private readonly argumentPatterns: string[];
|
|
9
16
|
|
|
10
|
-
constructor(pattern: string) {
|
|
17
|
+
constructor(pattern: string, private readonly matchOverrides: boolean = false) {
|
|
11
18
|
// Find the last space before the method spec (which contains parentheses)
|
|
12
19
|
const firstParenIndex = pattern.indexOf('(');
|
|
13
20
|
if (firstParenIndex === -1) {
|
|
@@ -31,7 +38,9 @@ export class MethodMatcher {
|
|
|
31
38
|
} else {
|
|
32
39
|
const lastDotIndex = typeSpec.lastIndexOf('.');
|
|
33
40
|
if (lastDotIndex === -1) {
|
|
34
|
-
|
|
41
|
+
// As in Java, a type without a package matches only the type in no package, such as
|
|
42
|
+
// the global `Array` or the module `fs-extra`. `*.Array` matches any package.
|
|
43
|
+
this.packagePattern = '';
|
|
35
44
|
this.typePattern = typeSpec;
|
|
36
45
|
} else {
|
|
37
46
|
// Check if we're splitting a *.. pattern incorrectly
|
|
@@ -71,23 +80,7 @@ export class MethodMatcher {
|
|
|
71
80
|
return false;
|
|
72
81
|
}
|
|
73
82
|
|
|
74
|
-
|
|
75
|
-
const fullyQualifiedName = FullyQualified.getFullyQualifiedName(method.declaringType);
|
|
76
|
-
|
|
77
|
-
// Split fully qualified name into package and type
|
|
78
|
-
const lastDotIndex = fullyQualifiedName.lastIndexOf('.');
|
|
79
|
-
const packageName = lastDotIndex === -1 ? '' : fullyQualifiedName.substring(0, lastDotIndex);
|
|
80
|
-
const typeName = lastDotIndex === -1 ? fullyQualifiedName : fullyQualifiedName.substring(lastDotIndex + 1);
|
|
81
|
-
|
|
82
|
-
// Match package
|
|
83
|
-
if (!this.matchesPackage(packageName)) {
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Match type (normalize primitives for matching)
|
|
88
|
-
const normalizedTypePattern = this.normalizePrimitiveType(this.typePattern);
|
|
89
|
-
const normalizedTypeName = this.normalizePrimitiveType(typeName);
|
|
90
|
-
if (!this.matchesPattern(normalizedTypePattern, normalizedTypeName)) {
|
|
83
|
+
if (!this.matchesTargetType(method.declaringType)) {
|
|
91
84
|
return false;
|
|
92
85
|
}
|
|
93
86
|
|
|
@@ -97,11 +90,30 @@ export class MethodMatcher {
|
|
|
97
90
|
}
|
|
98
91
|
|
|
99
92
|
// Match arguments - convert Type[] to string representations
|
|
100
|
-
const argStrings = method.parameterTypes.map(type =>
|
|
93
|
+
const argStrings = method.parameterTypes.map(type => MethodMatcher.typeName(type));
|
|
101
94
|
return this.matchesArguments(argStrings);
|
|
102
95
|
}
|
|
103
96
|
|
|
104
|
-
private
|
|
97
|
+
private matchesTargetType(type: Type | undefined): boolean {
|
|
98
|
+
const matches = (name: string) => this.matchesTypeName(name);
|
|
99
|
+
// A call on an untyped receiver declares on the unknown type, which a wildcard pattern
|
|
100
|
+
// matches by name. Java's matcher has no such case because Java calls are always typed.
|
|
101
|
+
return type?.kind === Type.Kind.Unknown
|
|
102
|
+
? matches(FullyQualified.getFullyQualifiedName(type))
|
|
103
|
+
: Type.isOfTypeWithName(type, this.matchOverrides, matches);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private matchesTypeName(fullyQualifiedName: string): boolean {
|
|
107
|
+
const lastDotIndex = fullyQualifiedName.lastIndexOf('.');
|
|
108
|
+
const packageName = lastDotIndex === -1 ? '' : fullyQualifiedName.substring(0, lastDotIndex);
|
|
109
|
+
const typeName = lastDotIndex === -1 ? fullyQualifiedName : fullyQualifiedName.substring(lastDotIndex + 1);
|
|
110
|
+
|
|
111
|
+
return this.matchesPackage(packageName) &&
|
|
112
|
+
this.matchesPattern(this.normalizePrimitiveType(this.typePattern), this.normalizePrimitiveType(typeName));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** The name an argument pattern compares against a parameter of this type. */
|
|
116
|
+
static typeName(type: Type): string {
|
|
105
117
|
switch (type.kind) {
|
|
106
118
|
case Type.Kind.Primitive:
|
|
107
119
|
return (type as Type.Primitive).keyword;
|
|
@@ -111,7 +123,7 @@ export class MethodMatcher {
|
|
|
111
123
|
return FullyQualified.getFullyQualifiedName((type as Type.Parameterized).type);
|
|
112
124
|
case Type.Kind.Array:
|
|
113
125
|
const arrayType = type as Type.Array;
|
|
114
|
-
return
|
|
126
|
+
return MethodMatcher.typeName(arrayType.elemType) + '[]';
|
|
115
127
|
case Type.Kind.GenericTypeVariable:
|
|
116
128
|
return (type as Type.GenericTypeVariable).name;
|
|
117
129
|
default:
|
|
@@ -659,7 +659,7 @@ export function createNodeResolutionResultMarker(
|
|
|
659
659
|
resolvedDependencies,
|
|
660
660
|
packageManager,
|
|
661
661
|
engines: normalizeEngines(packageJsonContent.engines),
|
|
662
|
-
npmrcConfigs,
|
|
662
|
+
npmrcConfigs: npmrcConfigs?.length ? npmrcConfigs : undefined,
|
|
663
663
|
} as NodeResolutionResult;
|
|
664
664
|
}
|
|
665
665
|
|
|
@@ -1022,7 +1022,8 @@ RpcCodecs.registerCodec(NodeResolutionResultKind, {
|
|
|
1022
1022
|
resolvedDependencies: (await q.receiveList(before.resolvedDependencies)) || [],
|
|
1023
1023
|
packageManager: await q.receive(before.packageManager),
|
|
1024
1024
|
engines: await q.receive(before.engines),
|
|
1025
|
-
|
|
1025
|
+
// an empty list is how having none is sent
|
|
1026
|
+
npmrcConfigs: await q.receiveList(before.npmrcConfigs).then(configs => configs?.length ? configs : undefined),
|
|
1026
1027
|
});
|
|
1027
1028
|
},
|
|
1028
1029
|
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 the original author or authors.
|
|
3
|
+
* <p>
|
|
4
|
+
* Licensed under the Moderne Source Available License (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
* <p>
|
|
8
|
+
* https://docs.moderne.io/licensing/moderne-source-available-license
|
|
9
|
+
* <p>
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The package a bare module specifier, or a path below `node_modules`, names. Attribution names a
|
|
19
|
+
* type declared in an installed package after it, so `@scope/pkg/sub` gives `@scope/pkg`.
|
|
20
|
+
*/
|
|
21
|
+
export function packageNameOf(specifier: string): string {
|
|
22
|
+
const segments = specifier.split('/');
|
|
23
|
+
return normalizePackageName(segments[0].startsWith('@') && segments.length > 1
|
|
24
|
+
? `${segments[0]}/${segments[1]}`
|
|
25
|
+
: segments[0]);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The specifier consumers import a node_modules package under. A DefinitelyTyped package
|
|
30
|
+
* `@types/<pkg>` names `<pkg>`, and `@types/testing-library__react` names `@testing-library/react`.
|
|
31
|
+
* Types reached directly and through a declaration file's path then share one name.
|
|
32
|
+
*/
|
|
33
|
+
function normalizePackageName(packageName: string): string {
|
|
34
|
+
if (packageName.startsWith('@types/')) {
|
|
35
|
+
packageName = packageName.substring('@types/'.length);
|
|
36
|
+
// Decode __ encoding for scoped packages: testing-library__react -> @testing-library/react
|
|
37
|
+
if (packageName.includes('__')) {
|
|
38
|
+
const parts = packageName.split('__');
|
|
39
|
+
if (parts.length === 2) {
|
|
40
|
+
packageName = `@${parts[0]}/${parts[1]}`;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return packageName;
|
|
45
|
+
}
|