@prettier/plugin-oxc 0.1.0 → 0.1.2
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 +42 -42
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -2246,15 +2246,22 @@ function getPreferredQuote(text, preferredQuoteOrPreferSingleQuote) {
|
|
|
2246
2246
|
var get_preferred_quote_default = getPreferredQuote;
|
|
2247
2247
|
|
|
2248
2248
|
// src/utils/make-string.js
|
|
2249
|
-
var REGEX =
|
|
2249
|
+
var REGEX = /\\(["'\\])|(["'])/gu;
|
|
2250
2250
|
function makeString(rawText, enclosingQuote) {
|
|
2251
|
-
|
|
2251
|
+
const otherQuote = enclosingQuote === '"' ? "'" : '"';
|
|
2252
|
+
const raw = method_replace_all_default(
|
|
2252
2253
|
/* OPTIONAL_OBJECT: false */
|
|
2253
2254
|
0,
|
|
2254
2255
|
rawText,
|
|
2255
2256
|
REGEX,
|
|
2256
|
-
(
|
|
2257
|
-
|
|
2257
|
+
(match, escaped, unescaped) => {
|
|
2258
|
+
if (escaped) {
|
|
2259
|
+
return escaped === otherQuote ? otherQuote : match;
|
|
2260
|
+
}
|
|
2261
|
+
return unescaped === enclosingQuote ? "\\" + unescaped : unescaped;
|
|
2262
|
+
}
|
|
2263
|
+
);
|
|
2264
|
+
return enclosingQuote + raw + enclosingQuote;
|
|
2258
2265
|
}
|
|
2259
2266
|
var make_string_default = makeString;
|
|
2260
2267
|
|
|
@@ -3891,10 +3898,13 @@ function printDocToString(doc, options2) {
|
|
|
3891
3898
|
mode: MODE_BREAK,
|
|
3892
3899
|
doc
|
|
3893
3900
|
}];
|
|
3894
|
-
let
|
|
3901
|
+
let output = "";
|
|
3895
3902
|
let shouldRemeasure = false;
|
|
3896
3903
|
const lineSuffix2 = [];
|
|
3897
3904
|
const cursorPositions = [];
|
|
3905
|
+
const settledOutput = [];
|
|
3906
|
+
const settledCursorPositions = [];
|
|
3907
|
+
let settledTextLength = 0;
|
|
3898
3908
|
propagateBreaks(doc);
|
|
3899
3909
|
while (commands.length > 0) {
|
|
3900
3910
|
const {
|
|
@@ -3912,7 +3922,7 @@ function printDocToString(doc, options2) {
|
|
|
3912
3922
|
newLine
|
|
3913
3923
|
) : doc2;
|
|
3914
3924
|
if (formatted2) {
|
|
3915
|
-
|
|
3925
|
+
output += formatted2;
|
|
3916
3926
|
if (commands.length > 0) {
|
|
3917
3927
|
position += get_string_width_default(formatted2);
|
|
3918
3928
|
}
|
|
@@ -3928,15 +3938,12 @@ function printDocToString(doc, options2) {
|
|
|
3928
3938
|
});
|
|
3929
3939
|
}
|
|
3930
3940
|
break;
|
|
3931
|
-
case DOC_TYPE_CURSOR:
|
|
3941
|
+
case DOC_TYPE_CURSOR:
|
|
3932
3942
|
if (cursorPositions.length >= 2) {
|
|
3933
3943
|
throw new Error("There are too many 'cursor' in doc.");
|
|
3934
3944
|
}
|
|
3935
|
-
|
|
3936
|
-
out = [text];
|
|
3937
|
-
cursorPositions.push(text.length - 1);
|
|
3945
|
+
cursorPositions.push(settledTextLength + output.length);
|
|
3938
3946
|
break;
|
|
3939
|
-
}
|
|
3940
3947
|
case DOC_TYPE_INDENT:
|
|
3941
3948
|
commands.push({
|
|
3942
3949
|
indent: makeIndent(indent2, options2),
|
|
@@ -4175,7 +4182,7 @@ function printDocToString(doc, options2) {
|
|
|
4175
4182
|
case MODE_FLAT:
|
|
4176
4183
|
if (!doc2.hard) {
|
|
4177
4184
|
if (!doc2.soft) {
|
|
4178
|
-
|
|
4185
|
+
output += " ";
|
|
4179
4186
|
position += 1;
|
|
4180
4187
|
}
|
|
4181
4188
|
break;
|
|
@@ -4194,17 +4201,17 @@ function printDocToString(doc, options2) {
|
|
|
4194
4201
|
break;
|
|
4195
4202
|
}
|
|
4196
4203
|
if (doc2.literal) {
|
|
4197
|
-
|
|
4204
|
+
output += newLine;
|
|
4198
4205
|
position = 0;
|
|
4199
4206
|
if (indent2.root) {
|
|
4200
4207
|
if (indent2.root.value) {
|
|
4201
|
-
|
|
4208
|
+
output += indent2.root.value;
|
|
4202
4209
|
}
|
|
4203
4210
|
position = indent2.root.length;
|
|
4204
4211
|
}
|
|
4205
4212
|
} else {
|
|
4206
4213
|
trim();
|
|
4207
|
-
|
|
4214
|
+
output += newLine + indent2.value;
|
|
4208
4215
|
position = indent2.length;
|
|
4209
4216
|
}
|
|
4210
4217
|
break;
|
|
@@ -4227,32 +4234,38 @@ function printDocToString(doc, options2) {
|
|
|
4227
4234
|
lineSuffix2.length = 0;
|
|
4228
4235
|
}
|
|
4229
4236
|
}
|
|
4230
|
-
const formatted =
|
|
4231
|
-
|
|
4237
|
+
const formatted = settledOutput.join("") + output;
|
|
4238
|
+
const finalCursorPositions = [...settledCursorPositions, ...cursorPositions];
|
|
4239
|
+
if (finalCursorPositions.length !== 2) {
|
|
4232
4240
|
return {
|
|
4233
4241
|
formatted
|
|
4234
4242
|
};
|
|
4235
4243
|
}
|
|
4236
|
-
const cursorNodeStart =
|
|
4244
|
+
const cursorNodeStart = finalCursorPositions[0];
|
|
4237
4245
|
return {
|
|
4238
4246
|
formatted,
|
|
4239
4247
|
cursorNodeStart,
|
|
4240
4248
|
cursorNodeText: formatted.slice(cursorNodeStart, method_at_default(
|
|
4241
4249
|
/* OPTIONAL_OBJECT: false */
|
|
4242
4250
|
0,
|
|
4243
|
-
|
|
4251
|
+
finalCursorPositions,
|
|
4244
4252
|
-1
|
|
4245
|
-
)
|
|
4253
|
+
))
|
|
4246
4254
|
};
|
|
4247
4255
|
function trim() {
|
|
4248
4256
|
const {
|
|
4249
|
-
text,
|
|
4257
|
+
text: trimmed,
|
|
4250
4258
|
count
|
|
4251
|
-
} = trimIndentation(
|
|
4252
|
-
|
|
4259
|
+
} = trimIndentation(output);
|
|
4260
|
+
if (trimmed) {
|
|
4261
|
+
settledOutput.push(trimmed);
|
|
4262
|
+
settledTextLength += trimmed.length;
|
|
4263
|
+
}
|
|
4264
|
+
output = "";
|
|
4253
4265
|
position -= count;
|
|
4254
|
-
|
|
4255
|
-
cursorPositions
|
|
4266
|
+
if (cursorPositions.length > 0) {
|
|
4267
|
+
settledCursorPositions.push(...cursorPositions.map((position2) => Math.min(position2, settledTextLength)));
|
|
4268
|
+
cursorPositions.length = 0;
|
|
4256
4269
|
}
|
|
4257
4270
|
}
|
|
4258
4271
|
}
|
|
@@ -8761,6 +8774,7 @@ function printClassBody(path, options2, print3) {
|
|
|
8761
8774
|
const isFlowTypeAnnotation = node.type === "ObjectTypeAnnotation";
|
|
8762
8775
|
const isObjectType2 = !isClassBody(path);
|
|
8763
8776
|
const separator = isObjectType2 ? line : hardline;
|
|
8777
|
+
const hasDanglingComments = hasComment(node, CommentCheckFlags.Dangling);
|
|
8764
8778
|
const [openingBrace, closingBrace] = isFlowTypeAnnotation && node.exact ? ["{|", "|}"] : "{}";
|
|
8765
8779
|
let firstMember;
|
|
8766
8780
|
iterateClassMembers(path, ({
|
|
@@ -8796,7 +8810,7 @@ function printClassBody(path, options2, print3) {
|
|
|
8796
8810
|
}
|
|
8797
8811
|
}
|
|
8798
8812
|
});
|
|
8799
|
-
if (
|
|
8813
|
+
if (hasDanglingComments) {
|
|
8800
8814
|
parts.push(printDanglingComments(path, options2));
|
|
8801
8815
|
}
|
|
8802
8816
|
if (node.type === "ObjectTypeAnnotation" && node.inexact) {
|
|
@@ -8815,7 +8829,7 @@ function printClassBody(path, options2, print3) {
|
|
|
8815
8829
|
parts.push(printed);
|
|
8816
8830
|
}
|
|
8817
8831
|
if (isObjectType2) {
|
|
8818
|
-
const shouldBreak = options2.objectWrap === "preserve" && firstMember && has_newline_in_range_default(options2.originalText, locStart(node), locStart(firstMember));
|
|
8832
|
+
const shouldBreak = hasDanglingComments || options2.objectWrap === "preserve" && firstMember && has_newline_in_range_default(options2.originalText, locStart(node), locStart(firstMember));
|
|
8819
8833
|
let content;
|
|
8820
8834
|
if (parts.length === 0) {
|
|
8821
8835
|
content = openingBrace + closingBrace;
|
|
@@ -10664,21 +10678,7 @@ function printTernaryOld(path, options2, print3) {
|
|
|
10664
10678
|
parent.type !== node.type || parent[alternateNodePropertyName] === node || isParentTest ? part : options2.useTabs ? dedent(indent(part)) : align(Math.max(0, options2.tabWidth - 2), part)
|
|
10665
10679
|
);
|
|
10666
10680
|
}
|
|
10667
|
-
const
|
|
10668
|
-
consequentNodePropertyName,
|
|
10669
|
-
alternateNodePropertyName,
|
|
10670
|
-
...testNodePropertyNames
|
|
10671
|
-
].some(
|
|
10672
|
-
(property) => hasComment(
|
|
10673
|
-
node[property],
|
|
10674
|
-
(comment) => is_block_comment_default(comment) && has_newline_in_range_default(
|
|
10675
|
-
options2.originalText,
|
|
10676
|
-
locStart(comment),
|
|
10677
|
-
locEnd(comment)
|
|
10678
|
-
)
|
|
10679
|
-
)
|
|
10680
|
-
);
|
|
10681
|
-
const maybeGroup = (doc) => parent === firstNonConditionalParent ? group(doc, { shouldBreak }) : shouldBreak ? [doc, breakParent] : doc;
|
|
10681
|
+
const maybeGroup = (doc) => parent === firstNonConditionalParent ? group(doc) : doc;
|
|
10682
10682
|
const breakClosingParen = !jsxMode && (isMemberExpression(parent) || parent.type === "NGPipeExpression" && parent.left === node) && !parent.computed;
|
|
10683
10683
|
const shouldExtraIndent = shouldExtraIndentForConditionalExpression(path);
|
|
10684
10684
|
const result = maybeGroup([
|