@prettier/plugin-oxc 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/THIRD-PARTY-NOTICES.md +1 -1
- package/index.browser.mjs +26 -26
- package/index.mjs +27 -21
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -3891,10 +3891,13 @@ function printDocToString(doc, options2) {
|
|
|
3891
3891
|
mode: MODE_BREAK,
|
|
3892
3892
|
doc
|
|
3893
3893
|
}];
|
|
3894
|
-
let
|
|
3894
|
+
let output = "";
|
|
3895
3895
|
let shouldRemeasure = false;
|
|
3896
3896
|
const lineSuffix2 = [];
|
|
3897
3897
|
const cursorPositions = [];
|
|
3898
|
+
const settledOutput = [];
|
|
3899
|
+
const settledCursorPositions = [];
|
|
3900
|
+
let settledTextLength = 0;
|
|
3898
3901
|
propagateBreaks(doc);
|
|
3899
3902
|
while (commands.length > 0) {
|
|
3900
3903
|
const {
|
|
@@ -3912,7 +3915,7 @@ function printDocToString(doc, options2) {
|
|
|
3912
3915
|
newLine
|
|
3913
3916
|
) : doc2;
|
|
3914
3917
|
if (formatted2) {
|
|
3915
|
-
|
|
3918
|
+
output += formatted2;
|
|
3916
3919
|
if (commands.length > 0) {
|
|
3917
3920
|
position += get_string_width_default(formatted2);
|
|
3918
3921
|
}
|
|
@@ -3928,15 +3931,12 @@ function printDocToString(doc, options2) {
|
|
|
3928
3931
|
});
|
|
3929
3932
|
}
|
|
3930
3933
|
break;
|
|
3931
|
-
case DOC_TYPE_CURSOR:
|
|
3934
|
+
case DOC_TYPE_CURSOR:
|
|
3932
3935
|
if (cursorPositions.length >= 2) {
|
|
3933
3936
|
throw new Error("There are too many 'cursor' in doc.");
|
|
3934
3937
|
}
|
|
3935
|
-
|
|
3936
|
-
out = [text];
|
|
3937
|
-
cursorPositions.push(text.length - 1);
|
|
3938
|
+
cursorPositions.push(settledTextLength + output.length);
|
|
3938
3939
|
break;
|
|
3939
|
-
}
|
|
3940
3940
|
case DOC_TYPE_INDENT:
|
|
3941
3941
|
commands.push({
|
|
3942
3942
|
indent: makeIndent(indent2, options2),
|
|
@@ -4175,7 +4175,7 @@ function printDocToString(doc, options2) {
|
|
|
4175
4175
|
case MODE_FLAT:
|
|
4176
4176
|
if (!doc2.hard) {
|
|
4177
4177
|
if (!doc2.soft) {
|
|
4178
|
-
|
|
4178
|
+
output += " ";
|
|
4179
4179
|
position += 1;
|
|
4180
4180
|
}
|
|
4181
4181
|
break;
|
|
@@ -4194,17 +4194,17 @@ function printDocToString(doc, options2) {
|
|
|
4194
4194
|
break;
|
|
4195
4195
|
}
|
|
4196
4196
|
if (doc2.literal) {
|
|
4197
|
-
|
|
4197
|
+
output += newLine;
|
|
4198
4198
|
position = 0;
|
|
4199
4199
|
if (indent2.root) {
|
|
4200
4200
|
if (indent2.root.value) {
|
|
4201
|
-
|
|
4201
|
+
output += indent2.root.value;
|
|
4202
4202
|
}
|
|
4203
4203
|
position = indent2.root.length;
|
|
4204
4204
|
}
|
|
4205
4205
|
} else {
|
|
4206
4206
|
trim();
|
|
4207
|
-
|
|
4207
|
+
output += newLine + indent2.value;
|
|
4208
4208
|
position = indent2.length;
|
|
4209
4209
|
}
|
|
4210
4210
|
break;
|
|
@@ -4227,32 +4227,38 @@ function printDocToString(doc, options2) {
|
|
|
4227
4227
|
lineSuffix2.length = 0;
|
|
4228
4228
|
}
|
|
4229
4229
|
}
|
|
4230
|
-
const formatted =
|
|
4231
|
-
|
|
4230
|
+
const formatted = settledOutput.join("") + output;
|
|
4231
|
+
const finalCursorPositions = [...settledCursorPositions, ...cursorPositions];
|
|
4232
|
+
if (finalCursorPositions.length !== 2) {
|
|
4232
4233
|
return {
|
|
4233
4234
|
formatted
|
|
4234
4235
|
};
|
|
4235
4236
|
}
|
|
4236
|
-
const cursorNodeStart =
|
|
4237
|
+
const cursorNodeStart = finalCursorPositions[0];
|
|
4237
4238
|
return {
|
|
4238
4239
|
formatted,
|
|
4239
4240
|
cursorNodeStart,
|
|
4240
4241
|
cursorNodeText: formatted.slice(cursorNodeStart, method_at_default(
|
|
4241
4242
|
/* OPTIONAL_OBJECT: false */
|
|
4242
4243
|
0,
|
|
4243
|
-
|
|
4244
|
+
finalCursorPositions,
|
|
4244
4245
|
-1
|
|
4245
|
-
)
|
|
4246
|
+
))
|
|
4246
4247
|
};
|
|
4247
4248
|
function trim() {
|
|
4248
4249
|
const {
|
|
4249
|
-
text,
|
|
4250
|
+
text: trimmed,
|
|
4250
4251
|
count
|
|
4251
|
-
} = trimIndentation(
|
|
4252
|
-
|
|
4252
|
+
} = trimIndentation(output);
|
|
4253
|
+
if (trimmed) {
|
|
4254
|
+
settledOutput.push(trimmed);
|
|
4255
|
+
settledTextLength += trimmed.length;
|
|
4256
|
+
}
|
|
4257
|
+
output = "";
|
|
4253
4258
|
position -= count;
|
|
4254
|
-
|
|
4255
|
-
cursorPositions
|
|
4259
|
+
if (cursorPositions.length > 0) {
|
|
4260
|
+
settledCursorPositions.push(...cursorPositions.map((position2) => Math.min(position2, settledTextLength)));
|
|
4261
|
+
cursorPositions.length = 0;
|
|
4256
4262
|
}
|
|
4257
4263
|
}
|
|
4258
4264
|
}
|