@openrewrite/rewrite 8.92.17 → 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 +116 -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/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.map +1 -1
- package/dist/javascript/markers.js +64 -0
- 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/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/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/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 +200 -112
- 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 +34 -16
- package/dist/javascript/type-mapping.d.ts.map +1 -1
- package/dist/javascript/type-mapping.js +253 -249
- 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/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/queue.d.ts +16 -0
- package/dist/rpc/queue.d.ts.map +1 -1
- package/dist/rpc/queue.js +27 -9
- package/dist/rpc/queue.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/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/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 +119 -43
- package/src/javascript/format/format.ts +9 -0
- package/src/javascript/index.ts +6 -3
- package/src/javascript/markers.ts +43 -1
- package/src/javascript/method-matcher.ts +34 -22
- package/src/javascript/package-name.ts +45 -0
- package/src/javascript/preconditions.ts +7 -4
- 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 +229 -127
- 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 +258 -252
- 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/recipe.ts +6 -0
- package/src/rpc/queue.ts +44 -5
- package/src/rpc/request/prepare-recipe.ts +16 -6
- package/src/search/is-source-file.ts +8 -3
- package/src/test/rewrite-test.ts +14 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"method-matcher.js","sourceRoot":"","sources":["../../src/javascript/method-matcher.ts"],"names":[],"mappings":";;;AAAA,kCAA6B;AAC7B,IAAO,cAAc,GAAG,WAAI,CAAC,cAAc,CAAC;AAE5C,MAAa,aAAa;IAMtB,YAAY,OAAe;
|
|
1
|
+
{"version":3,"file":"method-matcher.js","sourceRoot":"","sources":["../../src/javascript/method-matcher.ts"],"names":[],"mappings":";;;AAAA,kCAA6B;AAC7B,IAAO,cAAc,GAAG,WAAI,CAAC,cAAc,CAAC;AA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,CAAC;YACf,KAAK,SAAS,CAAC;YACf,KAAK,aAAa;gBACd,OAAO,SAAS,CAAC;YACrB;gBACI,OAAO,IAAI,CAAC;QACpB,CAAC;IACL,CAAC;CACJ;AA3PD,sCA2PC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The package a bare module specifier, or a path below `node_modules`, names. Attribution names a
|
|
3
|
+
* type declared in an installed package after it, so `@scope/pkg/sub` gives `@scope/pkg`.
|
|
4
|
+
*/
|
|
5
|
+
export declare function packageNameOf(specifier: string): string;
|
|
6
|
+
//# sourceMappingURL=package-name.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-name.d.ts","sourceRoot":"","sources":["../../src/javascript/package-name.ts"],"names":[],"mappings":"AAgBA;;;GAGG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAKvD"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2026 the original author or authors.
|
|
4
|
+
* <p>
|
|
5
|
+
* Licensed under the Moderne Source Available License (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
* <p>
|
|
9
|
+
* https://docs.moderne.io/licensing/moderne-source-available-license
|
|
10
|
+
* <p>
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.packageNameOf = packageNameOf;
|
|
19
|
+
/**
|
|
20
|
+
* The package a bare module specifier, or a path below `node_modules`, names. Attribution names a
|
|
21
|
+
* type declared in an installed package after it, so `@scope/pkg/sub` gives `@scope/pkg`.
|
|
22
|
+
*/
|
|
23
|
+
function packageNameOf(specifier) {
|
|
24
|
+
const segments = specifier.split('/');
|
|
25
|
+
return normalizePackageName(segments[0].startsWith('@') && segments.length > 1
|
|
26
|
+
? `${segments[0]}/${segments[1]}`
|
|
27
|
+
: segments[0]);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The specifier consumers import a node_modules package under. A DefinitelyTyped package
|
|
31
|
+
* `@types/<pkg>` names `<pkg>`, and `@types/testing-library__react` names `@testing-library/react`.
|
|
32
|
+
* Types reached directly and through a declaration file's path then share one name.
|
|
33
|
+
*/
|
|
34
|
+
function normalizePackageName(packageName) {
|
|
35
|
+
if (packageName.startsWith('@types/')) {
|
|
36
|
+
packageName = packageName.substring('@types/'.length);
|
|
37
|
+
// Decode __ encoding for scoped packages: testing-library__react -> @testing-library/react
|
|
38
|
+
if (packageName.includes('__')) {
|
|
39
|
+
const parts = packageName.split('__');
|
|
40
|
+
if (parts.length === 2) {
|
|
41
|
+
packageName = `@${parts[0]}/${parts[1]}`;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return packageName;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=package-name.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-name.js","sourceRoot":"","sources":["../../src/javascript/package-name.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AAMH,sCAKC;AATD;;;GAGG;AACH,SAAgB,aAAa,CAAC,SAAiB;IAC3C,MAAM,QAAQ,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACtC,OAAO,oBAAoB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC;QAC1E,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,EAAE;QACjC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AACvB,CAAC;AAED;;;;GAIG;AACH,SAAS,oBAAoB,CAAC,WAAmB;IAC7C,IAAI,WAAW,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QACpC,WAAW,GAAG,WAAW,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACtD,2FAA2F;QAC3F,IAAI,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YAC7B,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACtC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACrB,WAAW,GAAG,IAAI,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;YAC7C,CAAC;QACL,CAAC;IACL,CAAC;IACD,OAAO,WAAW,CAAC;AACvB,CAAC"}
|
|
@@ -36,6 +36,8 @@ export declare function isVendoredOrBundled(): RecipeRef;
|
|
|
36
36
|
* ``methodPattern`` follows the OpenRewrite method-pattern syntax:
|
|
37
37
|
* ``<receiver-type> <method-name>(<args>)`` — e.g.
|
|
38
38
|
* ``"*..* tostring(..)"`` or ``"java.util.Collections emptyList()"``.
|
|
39
|
+
* For a pattern that does not fire, ``REWRITE_JAVASCRIPT_DUMP_TYPES=1`` prints the
|
|
40
|
+
* declaring type each call got during the test run.
|
|
39
41
|
*
|
|
40
42
|
* Delegates to {@code org.openrewrite.java.search.HasMethod}.
|
|
41
43
|
*/
|
|
@@ -47,7 +49,8 @@ export declare function usesMethod(methodPattern: string, matchOverrides?: boole
|
|
|
47
49
|
* {@link UsesType} visitor for in-process evaluation; see
|
|
48
50
|
* {@link hasSourcePath} for the introspection / lazy-evaluation pattern.
|
|
49
51
|
*
|
|
50
|
-
* Delegates to {@code org.openrewrite.java.search.HasType}
|
|
52
|
+
* Delegates to {@code org.openrewrite.java.search.HasType}, which matches a type through any class
|
|
53
|
+
* or interface it extends and reads `checkAssignability` as `UsesType`'s `includeImplicit`.
|
|
51
54
|
*/
|
|
52
55
|
export declare function usesType(fullyQualifiedTypeName: string, checkAssignability?: boolean): RecipeRef;
|
|
53
56
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preconditions.d.ts","sourceRoot":"","sources":["../../src/javascript/preconditions.ts"],"names":[],"mappings":"AAeA,OAAO,EAAC,SAAS,EAAC,MAAM,kBAAkB,CAAC;AAI3C;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,CAM5D;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,IAAI,SAAS,CAM/C;AAED
|
|
1
|
+
{"version":3,"file":"preconditions.d.ts","sourceRoot":"","sources":["../../src/javascript/preconditions.ts"],"names":[],"mappings":"AAeA,OAAO,EAAC,SAAS,EAAC,MAAM,kBAAkB,CAAC;AAI3C;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,CAM5D;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,IAAI,SAAS,CAM/C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,UAAU,CAAC,aAAa,EAAE,MAAM,EAAE,cAAc,GAAE,OAAe,GAAG,SAAS,CAM5F;AAED;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,sBAAsB,EAAE,MAAM,EAAE,kBAAkB,GAAE,OAAe,GAAG,SAAS,CAMvG;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,aAAa,EAAE,MAAM,EAAE,cAAc,GAAE,OAAe,GAAG,SAAS,CAM7F;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,sBAAsB,EAAE,MAAM,GAAG,SAAS,CAMnE"}
|
|
@@ -65,11 +65,13 @@ function isVendoredOrBundled() {
|
|
|
65
65
|
* ``methodPattern`` follows the OpenRewrite method-pattern syntax:
|
|
66
66
|
* ``<receiver-type> <method-name>(<args>)`` — e.g.
|
|
67
67
|
* ``"*..* tostring(..)"`` or ``"java.util.Collections emptyList()"``.
|
|
68
|
+
* For a pattern that does not fire, ``REWRITE_JAVASCRIPT_DUMP_TYPES=1`` prints the
|
|
69
|
+
* declaring type each call got during the test run.
|
|
68
70
|
*
|
|
69
71
|
* Delegates to {@code org.openrewrite.java.search.HasMethod}.
|
|
70
72
|
*/
|
|
71
73
|
function usesMethod(methodPattern, matchOverrides = false) {
|
|
72
|
-
return new preconditions_1.RecipeRef("org.openrewrite.java.search.HasMethod", { methodPattern, matchOverrides }, new search_2.UsesMethod(methodPattern));
|
|
74
|
+
return new preconditions_1.RecipeRef("org.openrewrite.java.search.HasMethod", { methodPattern, matchOverrides }, new search_2.UsesMethod(methodPattern, matchOverrides));
|
|
73
75
|
}
|
|
74
76
|
/**
|
|
75
77
|
* Match files using a specific type.
|
|
@@ -78,10 +80,11 @@ function usesMethod(methodPattern, matchOverrides = false) {
|
|
|
78
80
|
* {@link UsesType} visitor for in-process evaluation; see
|
|
79
81
|
* {@link hasSourcePath} for the introspection / lazy-evaluation pattern.
|
|
80
82
|
*
|
|
81
|
-
* Delegates to {@code org.openrewrite.java.search.HasType}
|
|
83
|
+
* Delegates to {@code org.openrewrite.java.search.HasType}, which matches a type through any class
|
|
84
|
+
* or interface it extends and reads `checkAssignability` as `UsesType`'s `includeImplicit`.
|
|
82
85
|
*/
|
|
83
86
|
function usesType(fullyQualifiedTypeName, checkAssignability = false) {
|
|
84
|
-
return new preconditions_1.RecipeRef("org.openrewrite.java.search.HasType", { fullyQualifiedTypeName, checkAssignability }, new search_2.UsesType(fullyQualifiedTypeName));
|
|
87
|
+
return new preconditions_1.RecipeRef("org.openrewrite.java.search.HasType", { fullyQualifiedTypeName, checkAssignability }, new search_2.UsesType(fullyQualifiedTypeName, { assignable: true, includeImplicit: checkAssignability }));
|
|
85
88
|
}
|
|
86
89
|
/**
|
|
87
90
|
* Find and mark methods matching a pattern.
|
|
@@ -93,7 +96,7 @@ function usesType(fullyQualifiedTypeName, checkAssignability = false) {
|
|
|
93
96
|
* Delegates to {@code org.openrewrite.java.search.FindMethods}.
|
|
94
97
|
*/
|
|
95
98
|
function findMethods(methodPattern, matchOverrides = false) {
|
|
96
|
-
return new preconditions_1.RecipeRef("org.openrewrite.java.search.FindMethods", { methodPattern, matchOverrides }, new search_2.UsesMethod(methodPattern));
|
|
99
|
+
return new preconditions_1.RecipeRef("org.openrewrite.java.search.FindMethods", { methodPattern, matchOverrides }, new search_2.UsesMethod(methodPattern, matchOverrides));
|
|
97
100
|
}
|
|
98
101
|
/**
|
|
99
102
|
* Find and mark usages of a type.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preconditions.js","sourceRoot":"","sources":["../../src/javascript/preconditions.ts"],"names":[],"mappings":";;AAkCA,sCAMC;AAYD,kDAMC;
|
|
1
|
+
{"version":3,"file":"preconditions.js","sourceRoot":"","sources":["../../src/javascript/preconditions.ts"],"names":[],"mappings":";;AAkCA,sCAMC;AAYD,kDAMC;AAiBD,gCAMC;AAYD,4BAMC;AAWD,kCAMC;AAWD,8BAMC;AArID;;;;;;;;;;;;;;GAcG;AACH,oDAA2C;AAC3C,sCAAuC;AACvC,qCAAmE;AAEnE;;;;;;;;;;;;;;GAcG;AACH,SAAgB,aAAa,CAAC,WAAmB;IAC7C,OAAO,IAAI,yBAAS,CAChB,iCAAiC,EACjC,EAAC,WAAW,EAAC,EACb,IAAI,qBAAY,CAAC,WAAW,CAAC,CAChC,CAAC;AACN,CAAC;AAED;;;;;;;;;GASG;AACH,SAAgB,mBAAmB;IAC/B,OAAO,IAAI,yBAAS,CAChB,yDAAyD,EACzD,EAAE,EACF,IAAI,4BAAmB,EAAE,CAC5B,CAAC;AACN,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,SAAgB,UAAU,CAAC,aAAqB,EAAE,iBAA0B,KAAK;IAC7E,OAAO,IAAI,yBAAS,CAChB,uCAAuC,EACvC,EAAC,aAAa,EAAE,cAAc,EAAC,EAC/B,IAAI,mBAAU,CAAC,aAAa,EAAE,cAAc,CAAC,CAChD,CAAC;AACN,CAAC;AAED;;;;;;;;;GASG;AACH,SAAgB,QAAQ,CAAC,sBAA8B,EAAE,qBAA8B,KAAK;IACxF,OAAO,IAAI,yBAAS,CAChB,qCAAqC,EACrC,EAAC,sBAAsB,EAAE,kBAAkB,EAAC,EAC5C,IAAI,iBAAQ,CAAC,sBAAsB,EAAE,EAAC,UAAU,EAAE,IAAI,EAAE,eAAe,EAAE,kBAAkB,EAAC,CAAC,CAChG,CAAC;AACN,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,WAAW,CAAC,aAAqB,EAAE,iBAA0B,KAAK;IAC9E,OAAO,IAAI,yBAAS,CAChB,yCAAyC,EACzC,EAAC,aAAa,EAAE,cAAc,EAAC,EAC/B,IAAI,mBAAU,CAAC,aAAa,EAAE,cAAc,CAAC,CAChD,CAAC;AACN,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,SAAS,CAAC,sBAA8B;IACpD,OAAO,IAAI,yBAAS,CAChB,uCAAuC,EACvC,EAAC,sBAAsB,EAAC,EACxB,IAAI,iBAAQ,CAAC,sBAAsB,CAAC,CACvC,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Recipe } from "../../recipe";
|
|
2
|
+
import { TreeVisitor } from "../../visitor";
|
|
3
|
+
import { ExecutionContext } from "../../execution";
|
|
4
|
+
/**
|
|
5
|
+
* Moves calls matching a method pattern onto a member imported from a module, such as `jest.fn()`
|
|
6
|
+
* to `vi.fn()` with `import {vi} from "vitest"`.
|
|
7
|
+
*
|
|
8
|
+
* A call through an import of the old target, whether a namespace, default or named import, moves
|
|
9
|
+
* too, and the import goes once nothing else uses it.
|
|
10
|
+
*/
|
|
11
|
+
export declare class ChangeMethodTargetToImport extends Recipe {
|
|
12
|
+
readonly name = "org.openrewrite.javascript.change-method-target-to-import";
|
|
13
|
+
readonly displayName = "Change method target to an import";
|
|
14
|
+
readonly description: string;
|
|
15
|
+
methodPattern: string;
|
|
16
|
+
targetModule: string;
|
|
17
|
+
targetMember: string;
|
|
18
|
+
targetType?: string;
|
|
19
|
+
matchOverrides?: boolean;
|
|
20
|
+
constructor(options?: {
|
|
21
|
+
methodPattern?: string;
|
|
22
|
+
targetModule?: string;
|
|
23
|
+
targetMember?: string;
|
|
24
|
+
targetType?: string;
|
|
25
|
+
matchOverrides?: boolean;
|
|
26
|
+
});
|
|
27
|
+
editor(): Promise<TreeVisitor<any, ExecutionContext>>;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=change-method-target-to-import.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"change-method-target-to-import.d.ts","sourceRoot":"","sources":["../../../src/javascript/recipes/change-method-target-to-import.ts"],"names":[],"mappings":"AAeA,OAAO,EAAS,MAAM,EAAC,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAC,gBAAgB,EAAC,MAAM,iBAAiB,CAAC;AAYjD;;;;;;GAMG;AACH,qBAAa,0BAA2B,SAAQ,MAAM;IAClD,QAAQ,CAAC,IAAI,+DAA+D;IAC5E,QAAQ,CAAC,WAAW,uCAAuC;IAC3D,QAAQ,CAAC,WAAW,SACsG;IAO1H,aAAa,EAAG,MAAM,CAAC;IAOvB,YAAY,EAAG,MAAM,CAAC;IAOtB,YAAY,EAAG,MAAM,CAAC;IAStB,UAAU,CAAC,EAAE,MAAM,CAAC;IAOpB,cAAc,CAAC,EAAE,OAAO,CAAC;gBAEb,OAAO,CAAC,EAAE;QAClB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,cAAc,CAAC,EAAE,OAAO,CAAC;KAC5B;IAIK,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;CA0E9D"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ChangeMethodTargetToImport = void 0;
|
|
10
|
+
/*
|
|
11
|
+
* Copyright 2026 the original author or authors.
|
|
12
|
+
* <p>
|
|
13
|
+
* Licensed under the Moderne Source Available License (the "License");
|
|
14
|
+
* you may not use this file except in compliance with the License.
|
|
15
|
+
* You may obtain a copy of the License at
|
|
16
|
+
* <p>
|
|
17
|
+
* https://docs.moderne.io/licensing/moderne-source-available-license
|
|
18
|
+
* <p>
|
|
19
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
20
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
21
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
22
|
+
* See the License for the specific language governing permissions and
|
|
23
|
+
* limitations under the License.
|
|
24
|
+
*/
|
|
25
|
+
const recipe_1 = require("../../recipe");
|
|
26
|
+
const preconditions_1 = require("../../preconditions");
|
|
27
|
+
const markers_1 = require("../../markers");
|
|
28
|
+
const uuid_1 = require("../../uuid");
|
|
29
|
+
const java_1 = require("../../java");
|
|
30
|
+
const visitor_1 = require("../visitor");
|
|
31
|
+
const method_matcher_1 = require("../method-matcher");
|
|
32
|
+
const preconditions_2 = require("../preconditions");
|
|
33
|
+
const binding_1 = require("../binding");
|
|
34
|
+
const add_import_1 = require("../add-import");
|
|
35
|
+
const scope_1 = require("../scope");
|
|
36
|
+
/**
|
|
37
|
+
* Moves calls matching a method pattern onto a member imported from a module, such as `jest.fn()`
|
|
38
|
+
* to `vi.fn()` with `import {vi} from "vitest"`.
|
|
39
|
+
*
|
|
40
|
+
* A call through an import of the old target, whether a namespace, default or named import, moves
|
|
41
|
+
* too, and the import goes once nothing else uses it.
|
|
42
|
+
*/
|
|
43
|
+
class ChangeMethodTargetToImport extends recipe_1.Recipe {
|
|
44
|
+
constructor(options) {
|
|
45
|
+
super(options);
|
|
46
|
+
this.name = "org.openrewrite.javascript.change-method-target-to-import";
|
|
47
|
+
this.displayName = "Change method target to an import";
|
|
48
|
+
this.description = "Changes the target of calls matching a method pattern to a member imported from a module, " +
|
|
49
|
+
"adding the import. A CommonJS file changes only where it already requires the target, and an AMD module not at all.";
|
|
50
|
+
}
|
|
51
|
+
async editor() {
|
|
52
|
+
const matcher = new method_matcher_1.MethodMatcher(this.methodPattern, this.matchOverrides);
|
|
53
|
+
const module = this.targetModule;
|
|
54
|
+
const member = this.targetMember;
|
|
55
|
+
// Named after the specifier, as the parser names a module object.
|
|
56
|
+
const moduleObject = classNamed(module);
|
|
57
|
+
const memberType = this.targetType ? classNamed(this.targetType) : java_1.Type.unknownType;
|
|
58
|
+
return (0, preconditions_1.check)((0, preconditions_2.usesMethod)(this.methodPattern, this.matchOverrides), new class extends visitor_1.JavaScriptVisitor {
|
|
59
|
+
async visitMethodInvocation(method, ctx) {
|
|
60
|
+
var _a, _b, _c, _d;
|
|
61
|
+
const m = await super.visitMethodInvocation(method, ctx);
|
|
62
|
+
if (!matcher.matches(m.methodType)) {
|
|
63
|
+
return m;
|
|
64
|
+
}
|
|
65
|
+
const select = (_a = m.select) === null || _a === void 0 ? void 0 : _a.element;
|
|
66
|
+
if (select !== undefined && !(0, java_1.isIdentifier)(select)) {
|
|
67
|
+
return m;
|
|
68
|
+
}
|
|
69
|
+
const oldName = (_b = select === null || select === void 0 ? void 0 : select.simpleName) !== null && _b !== void 0 ? _b : m.name.simpleName;
|
|
70
|
+
const cu = (0, scope_1.compilationUnitOf)(this);
|
|
71
|
+
const owner = (0, scope_1.scopeOf)(this.cursor).declaringScope(oldName);
|
|
72
|
+
const imported = owner === cu ?
|
|
73
|
+
(0, add_import_1.moduleScopeBindings)(cu).find(b => b.name === oldName && b.module !== undefined) : undefined;
|
|
74
|
+
if (owner !== undefined && !imported) {
|
|
75
|
+
return m;
|
|
76
|
+
}
|
|
77
|
+
// A call without a receiver names the member it was imported as, which a default import lacks.
|
|
78
|
+
const methodName = select || !imported ? m.name.simpleName : imported.member;
|
|
79
|
+
if (methodName === undefined) {
|
|
80
|
+
return m;
|
|
81
|
+
}
|
|
82
|
+
const name = (0, binding_1.maybeBind)(this, { module, member, onlyIfReferenced: false });
|
|
83
|
+
if (name === undefined) {
|
|
84
|
+
return m;
|
|
85
|
+
}
|
|
86
|
+
if (imported) {
|
|
87
|
+
(0, binding_1.maybeUnbind)(this, { module: imported.module, member: (_c = imported.member) !== null && _c !== void 0 ? _c : 'default' });
|
|
88
|
+
}
|
|
89
|
+
const methodType = m.methodType && Object.assign(Object.assign({}, m.methodType), { declaringType: memberType });
|
|
90
|
+
const target = {
|
|
91
|
+
kind: java_1.J.Kind.Identifier,
|
|
92
|
+
id: (0, uuid_1.randomId)(),
|
|
93
|
+
prefix: (_d = select === null || select === void 0 ? void 0 : select.prefix) !== null && _d !== void 0 ? _d : m.name.prefix,
|
|
94
|
+
markers: markers_1.emptyMarkers,
|
|
95
|
+
annotations: [],
|
|
96
|
+
simpleName: name,
|
|
97
|
+
type: memberType,
|
|
98
|
+
fieldType: {
|
|
99
|
+
kind: java_1.Type.Kind.Variable,
|
|
100
|
+
name: member,
|
|
101
|
+
flags: 0,
|
|
102
|
+
owner: moduleObject,
|
|
103
|
+
type: memberType,
|
|
104
|
+
annotations: []
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const moved = Object.assign(Object.assign({}, m), { select: m.select ? Object.assign(Object.assign({}, m.select), { element: target }) : (0, java_1.rightPadded)(target, java_1.emptySpace), name: Object.assign(Object.assign({}, m.name), { prefix: m.select ? m.name.prefix : java_1.emptySpace, simpleName: methodName, type: java_1.Type.isMethod(m.name.type) ? methodType : m.name.type, fieldType: m.name.fieldType && Object.assign(Object.assign({}, m.name.fieldType), { name: methodName, owner: memberType }) }), methodType });
|
|
108
|
+
return moved;
|
|
109
|
+
}
|
|
110
|
+
}());
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.ChangeMethodTargetToImport = ChangeMethodTargetToImport;
|
|
114
|
+
__decorate([
|
|
115
|
+
(0, recipe_1.Option)({
|
|
116
|
+
displayName: "Method pattern",
|
|
117
|
+
description: "A method pattern matching the calls to move, as `<declaring type> <name>(<args>)`.",
|
|
118
|
+
example: "jest *(..)"
|
|
119
|
+
})
|
|
120
|
+
], ChangeMethodTargetToImport.prototype, "methodPattern", void 0);
|
|
121
|
+
__decorate([
|
|
122
|
+
(0, recipe_1.Option)({
|
|
123
|
+
displayName: "Target module",
|
|
124
|
+
description: "The module the new target is imported from.",
|
|
125
|
+
example: "vitest"
|
|
126
|
+
})
|
|
127
|
+
], ChangeMethodTargetToImport.prototype, "targetModule", void 0);
|
|
128
|
+
__decorate([
|
|
129
|
+
(0, recipe_1.Option)({
|
|
130
|
+
displayName: "Target member",
|
|
131
|
+
description: "The member of the target module the calls move onto.",
|
|
132
|
+
example: "vi"
|
|
133
|
+
})
|
|
134
|
+
], ChangeMethodTargetToImport.prototype, "targetMember", void 0);
|
|
135
|
+
__decorate([
|
|
136
|
+
(0, recipe_1.Option)({
|
|
137
|
+
displayName: "Target type",
|
|
138
|
+
description: "The fully-qualified type of the target member, which declares the methods the calls move to. " +
|
|
139
|
+
"Without it, the moved calls are attributed to an unknown declaring type.",
|
|
140
|
+
example: "vitest.VitestUtils",
|
|
141
|
+
required: false
|
|
142
|
+
})
|
|
143
|
+
], ChangeMethodTargetToImport.prototype, "targetType", void 0);
|
|
144
|
+
__decorate([
|
|
145
|
+
(0, recipe_1.Option)({
|
|
146
|
+
displayName: "Match on overrides",
|
|
147
|
+
description: "When enabled, find methods that are overrides of the method pattern.",
|
|
148
|
+
required: false
|
|
149
|
+
})
|
|
150
|
+
], ChangeMethodTargetToImport.prototype, "matchOverrides", void 0);
|
|
151
|
+
function classNamed(fullyQualifiedName) {
|
|
152
|
+
return {
|
|
153
|
+
kind: java_1.Type.Kind.Class,
|
|
154
|
+
flags: 0,
|
|
155
|
+
classKind: java_1.Type.Class.Kind.Interface,
|
|
156
|
+
fullyQualifiedName,
|
|
157
|
+
typeParameters: [],
|
|
158
|
+
annotations: [],
|
|
159
|
+
interfaces: [],
|
|
160
|
+
members: [],
|
|
161
|
+
methods: []
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=change-method-target-to-import.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"change-method-target-to-import.js","sourceRoot":"","sources":["../../../src/javascript/recipes/change-method-target-to-import.ts"],"names":[],"mappings":";;;;;;;;;AAAA;;;;;;;;;;;;;;GAcG;AACH,yCAA4C;AAG5C,uDAA0C;AAC1C,2CAA2C;AAC3C,qCAAoC;AACpC,qCAA0E;AAC1E,wCAA6C;AAC7C,sDAAgD;AAChD,oDAA4C;AAC5C,wCAAkD;AAClD,8CAAkD;AAClD,oCAAoD;AAEpD;;;;;;GAMG;AACH,MAAa,0BAA2B,SAAQ,eAAM;IA2ClD,YAAY,OAMX;QACG,KAAK,CAAC,OAAO,CAAC,CAAC;QAjDV,SAAI,GAAG,2DAA2D,CAAC;QACnE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O,KAAK,CAAC;YACjB,CAAC;SACJ,EAAE,CAAC,CAAC;IACT,CAAC;CACJ;AA/HD,gEA+HC;AApHG;IALC,IAAA,eAAM,EAAC;QACJ,WAAW,EAAE,gBAAgB;QAC7B,WAAW,EAAE,oFAAoF;QACjG,OAAO,EAAE,YAAY;KACxB,CAAC;iEACqB;AAOvB;IALC,IAAA,eAAM,EAAC;QACJ,WAAW,EAAE,eAAe;QAC5B,WAAW,EAAE,6CAA6C;QAC1D,OAAO,EAAE,QAAQ;KACpB,CAAC;gEACoB;AAOtB;IALC,IAAA,eAAM,EAAC;QACJ,WAAW,EAAE,eAAe;QAC5B,WAAW,EAAE,sDAAsD;QACnE,OAAO,EAAE,IAAI;KAChB,CAAC;gEACoB;AAStB;IAPC,IAAA,eAAM,EAAC;QACJ,WAAW,EAAE,aAAa;QAC1B,WAAW,EAAE,+FAA+F;YACxG,0EAA0E;QAC9E,OAAO,EAAE,oBAAoB;QAC7B,QAAQ,EAAE,KAAK;KAClB,CAAC;8DACkB;AAOpB;IALC,IAAA,eAAM,EAAC;QACJ,WAAW,EAAE,oBAAoB;QACjC,WAAW,EAAE,sEAAsE;QACnF,QAAQ,EAAE,KAAK;KAClB,CAAC;kEACuB;AAwF7B,SAAS,UAAU,CAAC,kBAA0B;IAC1C,OAAO;QACH,IAAI,EAAE,WAAI,CAAC,IAAI,CAAC,KAAK;QACrB,KAAK,EAAE,CAAC;QACR,SAAS,EAAE,WAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS;QACpC,kBAAkB;QAClB,cAAc,EAAE,EAAE;QAClB,WAAW,EAAE,EAAE;QACf,UAAU,EAAE,EAAE;QACd,OAAO,EAAE,EAAE;QACX,OAAO,EAAE,EAAE;KACA,CAAC;AACpB,CAAC"}
|
|
@@ -2,5 +2,6 @@ export * from "./async-callback-in-sync-array-method";
|
|
|
2
2
|
export * from "./auto-format";
|
|
3
3
|
export * from "./order-imports";
|
|
4
4
|
export * from "./change-import";
|
|
5
|
+
export * from "./change-method-target-to-import";
|
|
5
6
|
export * from "./dependencies";
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/javascript/recipes/index.ts"],"names":[],"mappings":"AAgBA,cAAc,uCAAuC,CAAC;AACtD,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/javascript/recipes/index.ts"],"names":[],"mappings":"AAgBA,cAAc,uCAAuC,CAAC;AACtD,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kCAAkC,CAAC;AACjD,cAAc,gBAAgB,CAAC"}
|
|
@@ -33,5 +33,6 @@ __exportStar(require("./async-callback-in-sync-array-method"), exports);
|
|
|
33
33
|
__exportStar(require("./auto-format"), exports);
|
|
34
34
|
__exportStar(require("./order-imports"), exports);
|
|
35
35
|
__exportStar(require("./change-import"), exports);
|
|
36
|
+
__exportStar(require("./change-method-target-to-import"), exports);
|
|
36
37
|
__exportStar(require("./dependencies"), exports);
|
|
37
38
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/javascript/recipes/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;AAEH,wEAAsD;AACtD,gDAA8B;AAC9B,kDAAgC;AAChC,kDAAgC;AAChC,iDAA+B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/javascript/recipes/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;AAEH,wEAAsD;AACtD,gDAA8B;AAC9B,kDAAgC;AAChC,kDAAgC;AAChC,mEAAiD;AACjD,iDAA+B"}
|
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import { Cursor } from "../tree";
|
|
1
|
+
import { Cursor, Tree } from "../tree";
|
|
2
2
|
import { J } from "../java";
|
|
3
3
|
import { JS } from "./tree";
|
|
4
4
|
import type { JavaScriptVisitor } from "./visitor";
|
|
5
|
+
/**
|
|
6
|
+
* What a name means where it is bound, a value, a type or a namespace, which is what TypeScript
|
|
7
|
+
* resolves a name against. A `const` binds a value, an interface a type, a class both, and the
|
|
8
|
+
* qualifier before a dot in a type reads a namespace, which an interface does not declare. A read
|
|
9
|
+
* with one meaning is hidden only by a binding with that meaning.
|
|
10
|
+
*/
|
|
11
|
+
export type Meaning = 'value' | 'type' | 'namespace';
|
|
5
12
|
/** One scope: the names it binds itself, the scopes around it, and what they answer together. */
|
|
6
13
|
export interface Scope {
|
|
7
14
|
/** The names this scope binds itself, which is not what it reaches: for that, ask `declares`. */
|
|
@@ -12,15 +19,16 @@ export interface Scope {
|
|
|
12
19
|
* name already in hand.
|
|
13
20
|
*/
|
|
14
21
|
walk(visit: (scope: Scope) => boolean): void;
|
|
15
|
-
/** Whether this scope or one enclosing it binds `name`. */
|
|
16
|
-
declares(name: string): boolean;
|
|
17
22
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
* Whether this scope or one enclosing it binds `name`. Any meaning counts unless one is asked
|
|
24
|
+
* for, since a new binding collides with a type of its name as much as with a value.
|
|
25
|
+
*/
|
|
26
|
+
declares(name: string, meaning?: Meaning): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The node owning the innermost scope that binds `name`, or undefined. A caller holding a
|
|
29
|
+
* declaration compares this to the node it came from, since anything nearer shadows it.
|
|
22
30
|
*/
|
|
23
|
-
declaringScope(name: string): J | undefined;
|
|
31
|
+
declaringScope(name: string, meaning?: Meaning): J | undefined;
|
|
24
32
|
}
|
|
25
33
|
/**
|
|
26
34
|
* The innermost scope holding `cursor`, which a visitor's own cursor rarely is: it stands on
|
|
@@ -46,7 +54,8 @@ export declare function namesDeclaredWithin(node: unknown, cacheKey?: object): R
|
|
|
46
54
|
/**
|
|
47
55
|
* The names `node` reads and nothing within it binds, so each one reaches a binding further out.
|
|
48
56
|
* A name its parent introduces rather than reads is not one, nor is a name an inner scope rebinds:
|
|
49
|
-
* that reference reads the rebinding.
|
|
57
|
+
* that reference reads the rebinding. A value position is hidden only by a value binding, a type
|
|
58
|
+
* position only by a type.
|
|
50
59
|
*/
|
|
51
60
|
export declare function namesReferencedWithin(node: unknown, cacheKey?: object): ReadonlySet<string>;
|
|
52
61
|
/**
|
|
@@ -64,7 +73,7 @@ export declare function bindingNames(pattern: J | undefined): {
|
|
|
64
73
|
* into, which a `JavaType` is not, so the walk stays in the tree the source spells rather than
|
|
65
74
|
* entering the type graph — cyclic and shared, where it would not terminate.
|
|
66
75
|
*/
|
|
67
|
-
export declare function walk(node: unknown, visit: (node:
|
|
76
|
+
export declare function walk(node: unknown, visit: (node: Tree) => boolean): void;
|
|
68
77
|
/** `cursor` is protected on `TreeVisitor` and these APIs are free functions, so reaching it takes a cast. */
|
|
69
78
|
export declare function cursorOf(visitor: JavaScriptVisitor<any>): Cursor | undefined;
|
|
70
79
|
/** The compilation unit a cursor sits in, or the one a visitor is currently positioned in. */
|
|
@@ -78,11 +87,46 @@ export declare function deconflict(preferred: string, isTaken: (name: string) =>
|
|
|
78
87
|
*/
|
|
79
88
|
export declare function declarationsOf(statement: J | undefined): J.VariableDeclarations[];
|
|
80
89
|
/**
|
|
81
|
-
* Whether the identifier
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
|
|
90
|
+
* Whether the identifier may be renamed in place, which is so where its slot reads rather than
|
|
91
|
+
* names. A shorthand property `{x}` answers false though it reads `x`, since a rename has to
|
|
92
|
+
* expand it to `{x: y}`. Position is all this reads, so a type position reads alike to a value,
|
|
93
|
+
* and what `x` reads is {@link resolve}'s question.
|
|
94
|
+
*/
|
|
95
|
+
export declare function isReference(cursor: Cursor, identifier: J.Identifier): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* @deprecated Use {@link isReference}. Unlike this function once did, it answers false for an
|
|
98
|
+
* import's own name, an alias and a re-export's specifier, which name rather than read.
|
|
99
|
+
*/
|
|
100
|
+
export declare const isValueReference: typeof isReference;
|
|
101
|
+
/**
|
|
102
|
+
* The node owning the scope that binds what `identifier` reads, or undefined where it reads a
|
|
103
|
+
* global or reads nothing. Position is what resolves it, so the cursor stands on the identifier
|
|
104
|
+
* or on the node holding it, and a node the cursor does not hold is refused.
|
|
105
|
+
*/
|
|
106
|
+
export declare function resolve(cursor: Cursor, identifier: J.Identifier): J | undefined;
|
|
107
|
+
/**
|
|
108
|
+
* Whether the identifier is assigned to where it stands. An assignment's target, plain or compound,
|
|
109
|
+
* is, and so are the operand of `++` or `--`, the head of a for-in or for-of declaring nothing, and
|
|
110
|
+
* a name in such a target's destructuring pattern. A write resolves as a value read, since
|
|
111
|
+
* `x = 2` assigns to the `x` it reads. The cursor is as {@link resolve} takes it.
|
|
112
|
+
*/
|
|
113
|
+
export declare function isWrite(cursor: Cursor, identifier: J.Identifier): boolean;
|
|
114
|
+
/** One identifier referring to a binding, from {@link referencesOf}. */
|
|
115
|
+
export interface Reference {
|
|
116
|
+
/** The identifier's position, holding the tree nodes above it with no padding between them. */
|
|
117
|
+
cursor: Cursor;
|
|
118
|
+
identifier: J.Identifier;
|
|
119
|
+
/** Whether the identifier is one declaring the binding. */
|
|
120
|
+
declares: boolean;
|
|
121
|
+
/** Whether the identifier is assigned to, as {@link isWrite} answers. */
|
|
122
|
+
writes: boolean;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Every identifier referring to the binding `name` has at `cursor`, the ones declaring it and the
|
|
126
|
+
* ones resolving to it, in the order the tree holds them, which a type annotation can depart from.
|
|
127
|
+
* The binding is the innermost one of the name with `meaning`, or with any meaning where none is
|
|
128
|
+
* asked for. A read with any meaning, as an export clause reads, refers to every meaning it finds.
|
|
129
|
+
* A name bound nowhere has no references. Each reference's cursor continues the caller's chain.
|
|
86
130
|
*/
|
|
87
|
-
export declare function
|
|
131
|
+
export declare function referencesOf(cursor: Cursor, name: string, meaning?: Meaning): Reference[];
|
|
88
132
|
//# sourceMappingURL=scope.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../../src/javascript/scope.ts"],"names":[],"mappings":"AAeA,OAAO,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../../src/javascript/scope.ts"],"names":[],"mappings":"AAeA,OAAO,EAAC,MAAM,EAAU,IAAI,EAAC,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAC,CAAC,EAAC,MAAM,SAAS,CAAC;AAE1B,OAAO,EAAC,EAAE,EAAC,MAAM,QAAQ,CAAC;AAE1B,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,WAAW,CAAC;AAIjD;;;;;GAKG;AACH,MAAM,MAAM,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,WAAW,CAAC;AA0CrD,iGAAiG;AACjG,MAAM,WAAW,KAAK;IAClB,iGAAiG;IACjG,KAAK,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC;IAE7B;;;;OAIG;IACH,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,GAAG,IAAI,CAAC;IAE7C;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;IAEnD;;;OAGG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,CAAC,GAAG,SAAS,CAAC;CAClE;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,CAE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