@openrewrite/rewrite 8.100.0 → 8.100.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.
- package/dist/java/rpc.d.ts.map +1 -1
- package/dist/java/rpc.js +6 -1
- package/dist/java/rpc.js.map +1 -1
- package/dist/javascript/add-import.d.ts.map +1 -1
- package/dist/javascript/add-import.js +3 -0
- package/dist/javascript/add-import.js.map +1 -1
- package/dist/javascript/binding.d.ts.map +1 -1
- package/dist/javascript/binding.js +8 -1
- package/dist/javascript/binding.js.map +1 -1
- package/dist/javascript/comparator.js +2 -1
- package/dist/javascript/comparator.js.map +1 -1
- package/dist/javascript/format/format.d.ts.map +1 -1
- package/dist/javascript/format/format.js +3 -2
- package/dist/javascript/format/format.js.map +1 -1
- package/dist/javascript/format/minimum-viable-spacing-visitor.js +3 -3
- package/dist/javascript/format/minimum-viable-spacing-visitor.js.map +1 -1
- package/dist/javascript/parser.d.ts.map +1 -1
- package/dist/javascript/parser.js +11 -17
- package/dist/javascript/parser.js.map +1 -1
- package/dist/javascript/print.d.ts +4 -0
- package/dist/javascript/print.d.ts.map +1 -1
- package/dist/javascript/print.js +82 -20
- package/dist/javascript/print.js.map +1 -1
- package/dist/javascript/rpc.js +2 -0
- package/dist/javascript/rpc.js.map +1 -1
- package/dist/javascript/scope.d.ts.map +1 -1
- package/dist/javascript/scope.js +4 -1
- package/dist/javascript/scope.js.map +1 -1
- package/dist/javascript/templating/comparator.d.ts +9 -0
- package/dist/javascript/templating/comparator.d.ts.map +1 -1
- package/dist/javascript/templating/comparator.js +21 -0
- package/dist/javascript/templating/comparator.js.map +1 -1
- package/dist/javascript/templating/debug.d.ts.map +1 -1
- package/dist/javascript/templating/debug.js +2 -0
- package/dist/javascript/templating/debug.js.map +1 -1
- package/dist/javascript/templating/precedence.d.ts.map +1 -1
- package/dist/javascript/templating/precedence.js +36 -39
- package/dist/javascript/templating/precedence.js.map +1 -1
- package/dist/javascript/templating/types.d.ts +4 -4
- package/dist/javascript/tree-debug.d.ts.map +1 -1
- package/dist/javascript/tree-debug.js +6 -3
- package/dist/javascript/tree-debug.js.map +1 -1
- package/dist/javascript/tree.d.ts +4 -1
- package/dist/javascript/tree.d.ts.map +1 -1
- package/dist/javascript/tree.js +2 -0
- package/dist/javascript/tree.js.map +1 -1
- package/dist/javascript/type-mapping.d.ts +1 -0
- package/dist/javascript/type-mapping.d.ts.map +1 -1
- package/dist/javascript/type-mapping.js +12 -1
- package/dist/javascript/type-mapping.js.map +1 -1
- package/dist/json/edit.d.ts +150 -0
- package/dist/json/edit.d.ts.map +1 -0
- package/dist/json/edit.js +667 -0
- package/dist/json/edit.js.map +1 -0
- package/dist/json/index.d.ts +1 -0
- package/dist/json/index.d.ts.map +1 -1
- package/dist/json/index.js +1 -0
- package/dist/json/index.js.map +1 -1
- package/dist/parser.d.ts +1 -1
- package/dist/parser.d.ts.map +1 -1
- package/dist/print.d.ts +16 -0
- package/dist/print.d.ts.map +1 -1
- package/dist/print.js +33 -0
- package/dist/print.js.map +1 -1
- package/dist/rewrite-javascript-version.txt +1 -1
- package/dist/rpc/request/get-languages.d.ts.map +1 -1
- package/dist/rpc/request/get-languages.js +1 -0
- package/dist/rpc/request/get-languages.js.map +1 -1
- package/dist/rpc/request/parse.d.ts.map +1 -1
- package/dist/rpc/request/parse.js +4 -0
- package/dist/rpc/request/parse.js.map +1 -1
- package/dist/rpc/server.d.ts +1 -0
- package/dist/rpc/server.d.ts.map +1 -1
- package/dist/rpc/server.js +1 -0
- package/dist/rpc/server.js.map +1 -1
- package/dist/xml/assertions.d.ts +4 -0
- package/dist/xml/assertions.d.ts.map +1 -0
- package/dist/xml/assertions.js +31 -0
- package/dist/xml/assertions.js.map +1 -0
- package/dist/xml/index.d.ts +8 -0
- package/dist/xml/index.d.ts.map +1 -0
- package/dist/xml/index.js +39 -0
- package/dist/xml/index.js.map +1 -0
- package/dist/xml/namespaces.d.ts +36 -0
- package/dist/xml/namespaces.d.ts.map +1 -0
- package/dist/xml/namespaces.js +98 -0
- package/dist/xml/namespaces.js.map +1 -0
- package/dist/xml/parser.d.ts +15 -0
- package/dist/xml/parser.d.ts.map +1 -0
- package/dist/xml/parser.js +677 -0
- package/dist/xml/parser.js.map +1 -0
- package/dist/xml/print.d.ts +2 -0
- package/dist/xml/print.d.ts.map +1 -0
- package/dist/xml/print.js +209 -0
- package/dist/xml/print.js.map +1 -0
- package/dist/xml/rpc.d.ts +2 -0
- package/dist/xml/rpc.d.ts.map +1 -0
- package/dist/xml/rpc.js +313 -0
- package/dist/xml/rpc.js.map +1 -0
- package/dist/xml/tree.d.ts +244 -0
- package/dist/xml/tree.d.ts.map +1 -0
- package/dist/xml/tree.js +265 -0
- package/dist/xml/tree.js.map +1 -0
- package/dist/xml/visitor.d.ts +35 -0
- package/dist/xml/visitor.d.ts.map +1 -0
- package/dist/xml/visitor.js +203 -0
- package/dist/xml/visitor.js.map +1 -0
- package/package.json +5 -1
- package/src/java/rpc.ts +6 -1
- package/src/javascript/add-import.ts +3 -0
- package/src/javascript/binding.ts +10 -1
- package/src/javascript/comparator.ts +2 -1
- package/src/javascript/format/format.ts +3 -2
- package/src/javascript/format/minimum-viable-spacing-visitor.ts +3 -3
- package/src/javascript/parser.ts +12 -17
- package/src/javascript/print.ts +85 -23
- package/src/javascript/rpc.ts +2 -0
- package/src/javascript/scope.ts +4 -1
- package/src/javascript/templating/comparator.ts +23 -0
- package/src/javascript/templating/debug.ts +1 -0
- package/src/javascript/templating/precedence.ts +17 -20
- package/src/javascript/templating/types.ts +4 -4
- package/src/javascript/tree-debug.ts +7 -3
- package/src/javascript/tree.ts +4 -1
- package/src/javascript/type-mapping.ts +15 -1
- package/src/json/edit.ts +750 -0
- package/src/json/index.ts +1 -0
- package/src/parser.ts +1 -1
- package/src/print.ts +42 -0
- package/src/rpc/request/get-languages.ts +1 -0
- package/src/rpc/request/parse.ts +3 -0
- package/src/rpc/server.ts +1 -0
- package/src/xml/assertions.ts +28 -0
- package/src/xml/index.ts +23 -0
- package/src/xml/namespaces.ts +109 -0
- package/src/xml/parser.ts +692 -0
- package/src/xml/print.ts +225 -0
- package/src/xml/rpc.ts +370 -0
- package/src/xml/tree.ts +455 -0
- package/src/xml/visitor.ts +227 -0
package/src/json/index.ts
CHANGED
package/src/parser.ts
CHANGED
|
@@ -189,7 +189,7 @@ export function readSourceSync(sourcePath: ParserInput) {
|
|
|
189
189
|
|
|
190
190
|
type ParserConstructor<T extends Parser> = new (options?: ParserOptions) => T;
|
|
191
191
|
|
|
192
|
-
export type ParserType = "javascript" | "packageJson" | "json" | "yaml" | "plainText";
|
|
192
|
+
export type ParserType = "javascript" | "packageJson" | "json" | "yaml" | "xml" | "plainText";
|
|
193
193
|
|
|
194
194
|
export class Parsers {
|
|
195
195
|
private static registry = new Map<ParserType, ParserConstructor<Parser>>();
|
package/src/print.ts
CHANGED
|
@@ -112,8 +112,16 @@ export namespace MarkerPrinter {
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
/** Where printing continued when {@link PrintOutputCapture.mark} was called, and the character printed first from there. */
|
|
116
|
+
export interface PrintMark {
|
|
117
|
+
readonly offset: number;
|
|
118
|
+
readonly firstChar: string;
|
|
119
|
+
}
|
|
120
|
+
|
|
115
121
|
export class PrintOutputCapture {
|
|
116
122
|
private _out: string = "";
|
|
123
|
+
private _lastChar: string = "";
|
|
124
|
+
private _unresolvedMarks: { offset: number, firstChar: string }[] = [];
|
|
117
125
|
|
|
118
126
|
constructor(public readonly markerPrinter: MarkerPrinter = MarkerPrinter.DEFAULT) {
|
|
119
127
|
}
|
|
@@ -122,10 +130,44 @@ export class PrintOutputCapture {
|
|
|
122
130
|
return this._out;
|
|
123
131
|
}
|
|
124
132
|
|
|
133
|
+
/**
|
|
134
|
+
* The last character printed so far, a whole surrogate pair where it is one. Reading it back from
|
|
135
|
+
* {@link out} instead would flatten the whole output each time.
|
|
136
|
+
*/
|
|
137
|
+
get lastChar(): string {
|
|
138
|
+
return this._lastChar;
|
|
139
|
+
}
|
|
140
|
+
|
|
125
141
|
append(text: string | undefined): PrintOutputCapture {
|
|
126
142
|
if (text && text.length > 0) {
|
|
143
|
+
if (this._unresolvedMarks.length > 0) {
|
|
144
|
+
const firstChar = String.fromCodePoint(text.codePointAt(0)!);
|
|
145
|
+
for (const mark of this._unresolvedMarks) {
|
|
146
|
+
mark.firstChar = firstChar;
|
|
147
|
+
}
|
|
148
|
+
this._unresolvedMarks.length = 0;
|
|
149
|
+
}
|
|
127
150
|
this._out += text;
|
|
151
|
+
const last = text.charCodeAt(text.length - 1);
|
|
152
|
+
this._lastChar = last >= 0xDC00 && last <= 0xDFFF && text.length > 1 ?
|
|
153
|
+
text.substring(text.length - 2) : text.charAt(text.length - 1);
|
|
154
|
+
}
|
|
155
|
+
return this;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** Marks where printing continues, so that what is printed there first can be told without reading {@link out} back. */
|
|
159
|
+
mark(): PrintMark {
|
|
160
|
+
const mark = {offset: this._out.length, firstChar: ""};
|
|
161
|
+
this._unresolvedMarks.push(mark);
|
|
162
|
+
return mark;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Inserts `text` at `offset` of what has been printed so far. */
|
|
166
|
+
insert(offset: number, text: string): PrintOutputCapture {
|
|
167
|
+
if (offset >= this._out.length) {
|
|
168
|
+
return this.append(text);
|
|
128
169
|
}
|
|
170
|
+
this._out = this._out.substring(0, offset) + text + this._out.substring(offset);
|
|
129
171
|
return this;
|
|
130
172
|
}
|
|
131
173
|
}
|
|
@@ -14,6 +14,7 @@ export class GetLanguages {
|
|
|
14
14
|
"org.openrewrite.text.PlainText",
|
|
15
15
|
"org.openrewrite.json.tree.Json$Document",
|
|
16
16
|
"org.openrewrite.yaml.tree.Yaml$Documents",
|
|
17
|
+
"org.openrewrite.xml.tree.Xml$Document",
|
|
17
18
|
// TODO Support for Javadoc comments is not yet implemented
|
|
18
19
|
// "org.openrewrite.java.tree.J$CompilationUnit",
|
|
19
20
|
"org.openrewrite.javascript.tree.JS$CompilationUnit",
|
package/src/rpc/request/parse.ts
CHANGED
|
@@ -20,6 +20,7 @@ import {randomId, UUID} from "../../uuid";
|
|
|
20
20
|
import {SourceFile} from "../../tree";
|
|
21
21
|
import {withMetrics} from "./metrics";
|
|
22
22
|
import * as path from "path";
|
|
23
|
+
import {XmlParser} from "../../xml/parser";
|
|
23
24
|
|
|
24
25
|
export class Parse {
|
|
25
26
|
constructor(private readonly inputs: ParserInput[],
|
|
@@ -39,6 +40,8 @@ export class Parse {
|
|
|
39
40
|
const fileName = path.basename(filePath);
|
|
40
41
|
if (fileName === 'package.json') {
|
|
41
42
|
return "packageJson";
|
|
43
|
+
} else if (XmlParser.accept(filePath)) {
|
|
44
|
+
return "xml";
|
|
42
45
|
}
|
|
43
46
|
return "javascript";
|
|
44
47
|
}
|
package/src/rpc/server.ts
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
import {AfterRecipeText, dedentAfter, SourceSpec} from "../test";
|
|
17
|
+
import {XmlParser} from "./parser";
|
|
18
|
+
import {Xml} from "./tree";
|
|
19
|
+
|
|
20
|
+
export function xml(before: string | null, after?: AfterRecipeText): SourceSpec<Xml.Document> {
|
|
21
|
+
return {
|
|
22
|
+
kind: Xml.Kind.Document,
|
|
23
|
+
before: before,
|
|
24
|
+
after: dedentAfter(after),
|
|
25
|
+
ext: 'xml',
|
|
26
|
+
parser: () => new XmlParser()
|
|
27
|
+
};
|
|
28
|
+
}
|
package/src/xml/index.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
export * from "./tree";
|
|
17
|
+
export * from "./namespaces";
|
|
18
|
+
export * from "./visitor";
|
|
19
|
+
export * from "./assertions";
|
|
20
|
+
export * from "./parser";
|
|
21
|
+
|
|
22
|
+
import "./print";
|
|
23
|
+
import "./rpc";
|
|
@@ -0,0 +1,109 @@
|
|
|
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
|
+
import {Cursor} from "../tree";
|
|
17
|
+
import {isAttribute, isTag, isXml, Xml} from "./tree";
|
|
18
|
+
|
|
19
|
+
export const XML_NS_URI = "http://www.w3.org/XML/1998/namespace";
|
|
20
|
+
export const XMLNS_ATTRIBUTE_NS_URI = "http://www.w3.org/2000/xmlns/";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The part of a tag or attribute name after its namespace prefix, as `Namespaced.extractLocalName` returns it:
|
|
24
|
+
* `Button` for both `Button` and `m:Button`.
|
|
25
|
+
*/
|
|
26
|
+
export function localName(name: string): string {
|
|
27
|
+
const colon = name.indexOf(":");
|
|
28
|
+
return colon === -1 ? name : name.substring(colon + 1);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The namespace prefix of a tag or attribute name, as `Namespaced.extractNamespacePrefix` returns it:
|
|
33
|
+
* `m` for `m:Button`, and the empty string for an unprefixed name.
|
|
34
|
+
*/
|
|
35
|
+
export function namespacePrefix(name: string): string {
|
|
36
|
+
const colon = name.indexOf(":");
|
|
37
|
+
return colon === -1 ? "" : name.substring(0, colon);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function isNamespaceDeclaration(attributeName: string): boolean {
|
|
41
|
+
return attributeName === "xmlns" || attributeName.startsWith("xmlns:");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The namespaces a tag declares itself, keyed by prefix, with the empty string for the default namespace.
|
|
46
|
+
* They map to the URIs as written, so `xmlns=""` maps the empty prefix to the empty string.
|
|
47
|
+
*/
|
|
48
|
+
export function namespaces(tag: Xml.Tag): Map<string, string> {
|
|
49
|
+
const declared = new Map<string, string>();
|
|
50
|
+
for (const attribute of tag.attributes) {
|
|
51
|
+
const name = attribute.key.name;
|
|
52
|
+
if (isNamespaceDeclaration(name)) {
|
|
53
|
+
declared.set(name === "xmlns" ? "" : localName(name), attribute.value.value);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return declared;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The namespaces in scope at the cursor: those of every tag from the root down to the cursor's own tag,
|
|
61
|
+
* where a declaration replaces one of the same prefix on an enclosing tag.
|
|
62
|
+
*/
|
|
63
|
+
export function allNamespaces(cursor: Cursor): Map<string, string> {
|
|
64
|
+
const tags = cursor.asArray().filter((v): v is Xml.Tag => isXml(v) && isTag(v));
|
|
65
|
+
const inScope = new Map<string, string>();
|
|
66
|
+
for (let i = tags.length - 1; i >= 0; i--) {
|
|
67
|
+
for (const [prefix, uri] of namespaces(tags[i])) {
|
|
68
|
+
inScope.set(prefix, uri);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return inScope;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Resolves a namespace URI at the cursor, as `Namespaced.getNamespaceUri()` does.
|
|
76
|
+
*
|
|
77
|
+
* Given a `prefix`, this is the URI bound to it where the cursor is, with the empty string standing for the
|
|
78
|
+
* default namespace. Without one, it is the namespace of the tag or attribute at the cursor: an unprefixed tag
|
|
79
|
+
* is in the default namespace, an unprefixed attribute in none, and an `xmlns` declaration in the xmlns
|
|
80
|
+
* namespace. The `xml` prefix is bound without a declaration, and `xmlns=""` leaves the default namespace
|
|
81
|
+
* unbound. An unbound prefix resolves to `undefined`.
|
|
82
|
+
*/
|
|
83
|
+
export function namespaceUri(cursor: Cursor, prefix?: string): string | undefined {
|
|
84
|
+
if (prefix === undefined) {
|
|
85
|
+
const value = cursor.value;
|
|
86
|
+
if (!isXml(value)) {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
if (isTag(value)) {
|
|
90
|
+
prefix = namespacePrefix(value.name);
|
|
91
|
+
} else if (isAttribute(value)) {
|
|
92
|
+
const name = value.key.name;
|
|
93
|
+
if (isNamespaceDeclaration(name)) {
|
|
94
|
+
return XMLNS_ATTRIBUTE_NS_URI;
|
|
95
|
+
}
|
|
96
|
+
prefix = namespacePrefix(name);
|
|
97
|
+
if (prefix === "") {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
} else {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const uri = allNamespaces(cursor).get(prefix);
|
|
105
|
+
if (uri === undefined && prefix === "xml") {
|
|
106
|
+
return XML_NS_URI;
|
|
107
|
+
}
|
|
108
|
+
return uri === "" ? undefined : uri;
|
|
109
|
+
}
|