@prettier/plugin-oxc 0.0.1 → 0.0.3
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 +5 -0
- package/THIRD-PARTY-NOTICES.md +1 -1
- package/index.mjs +42 -23
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# @prettier/plugin-oxc
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@prettier/plugin-oxc)
|
|
4
|
+
[](https://github.com/prettier/prettier/blob/main/license)
|
|
5
|
+
|
|
3
6
|
> Prettier [Oxc](https://oxc.rs/) plugin.
|
|
4
7
|
|
|
5
8
|
## Install
|
|
@@ -17,6 +20,8 @@ plugins:
|
|
|
17
20
|
- "@prettier/plugin-oxc"
|
|
18
21
|
```
|
|
19
22
|
|
|
23
|
+
**Requires prettier >= 3.6**
|
|
24
|
+
|
|
20
25
|
Or config explicitly
|
|
21
26
|
|
|
22
27
|
```yaml
|
package/THIRD-PARTY-NOTICES.md
CHANGED
package/index.mjs
CHANGED
|
@@ -1921,30 +1921,26 @@ async function parseJs(text, options2) {
|
|
|
1921
1921
|
return postprocess_default(ast, { text, parser: "oxc" });
|
|
1922
1922
|
}
|
|
1923
1923
|
async function parseTs(text, options2) {
|
|
1924
|
-
|
|
1924
|
+
const filepath = options2 == null ? void 0 : options2.filepath;
|
|
1925
1925
|
const sourceType = getSourceType(filepath);
|
|
1926
1926
|
const parseOptions = { sourceType, astType: "ts" };
|
|
1927
1927
|
const isKnownJsx = typeof filepath === "string" && /\.(?:jsx|tsx)$/iu.test(filepath);
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
} else {
|
|
1928
|
+
const isDtsFile = typeof filepath === "string" && filepath.toLowerCase().endsWith(".d.ts");
|
|
1929
|
+
let filenameCombinations = [isDtsFile ? "prettier.d.ts" : "prettier.tsx"];
|
|
1930
|
+
if (!isDtsFile && !isKnownJsx) {
|
|
1932
1931
|
const shouldEnableJsx = jsx_regexp_evaluate_default.test(text);
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
}
|
|
1940
|
-
if (typeof filepath !== "string") {
|
|
1941
|
-
filepath = "prettier.tsx";
|
|
1932
|
+
filenameCombinations = [
|
|
1933
|
+
...[shouldEnableJsx, !shouldEnableJsx].map(
|
|
1934
|
+
(shouldEnableJsx2) => shouldEnableJsx2 ? "prettier.tsx" : "prettier.ts"
|
|
1935
|
+
),
|
|
1936
|
+
"prettier.d.ts"
|
|
1937
|
+
];
|
|
1942
1938
|
}
|
|
1943
1939
|
let result;
|
|
1944
1940
|
try {
|
|
1945
1941
|
result = await tryCombinationsAsync(
|
|
1946
|
-
|
|
1947
|
-
(
|
|
1942
|
+
filenameCombinations.map(
|
|
1943
|
+
(filename) => () => parseWithOptions(filename, text, parseOptions)
|
|
1948
1944
|
)
|
|
1949
1945
|
);
|
|
1950
1946
|
} catch ({
|
|
@@ -6803,12 +6799,7 @@ function maybeWrapJsxElementInParens(path, elem, options2) {
|
|
|
6803
6799
|
if (NO_WRAP_PARENTS.has(parent.type)) {
|
|
6804
6800
|
return elem;
|
|
6805
6801
|
}
|
|
6806
|
-
const shouldBreak = path
|
|
6807
|
-
void 0,
|
|
6808
|
-
(node) => node.type === "ArrowFunctionExpression",
|
|
6809
|
-
isCallExpression,
|
|
6810
|
-
(node) => node.type === "JSXExpressionContainer"
|
|
6811
|
-
);
|
|
6802
|
+
const shouldBreak = shouldBreakJsxElement(path);
|
|
6812
6803
|
const needsParens2 = needs_parens_default(path, options2);
|
|
6813
6804
|
return group(
|
|
6814
6805
|
[
|
|
@@ -6820,6 +6811,26 @@ function maybeWrapJsxElementInParens(path, elem, options2) {
|
|
|
6820
6811
|
{ shouldBreak }
|
|
6821
6812
|
);
|
|
6822
6813
|
}
|
|
6814
|
+
function shouldBreakJsxElement(path) {
|
|
6815
|
+
return path.match(
|
|
6816
|
+
void 0,
|
|
6817
|
+
(node) => node.type === "ArrowFunctionExpression",
|
|
6818
|
+
isCallExpression
|
|
6819
|
+
) && // Babel
|
|
6820
|
+
(path.match(
|
|
6821
|
+
void 0,
|
|
6822
|
+
void 0,
|
|
6823
|
+
void 0,
|
|
6824
|
+
(node) => node.type === "JSXExpressionContainer"
|
|
6825
|
+
) || // Estree
|
|
6826
|
+
path.match(
|
|
6827
|
+
void 0,
|
|
6828
|
+
void 0,
|
|
6829
|
+
void 0,
|
|
6830
|
+
(node) => node.type === "ChainExpression",
|
|
6831
|
+
(node) => node.type === "JSXExpressionContainer"
|
|
6832
|
+
));
|
|
6833
|
+
}
|
|
6823
6834
|
function printJsxAttribute(path, options2, print3) {
|
|
6824
6835
|
const { node } = path;
|
|
6825
6836
|
const parts = [];
|
|
@@ -7473,6 +7484,10 @@ function printCallArguments(path, options2, print3) {
|
|
|
7473
7484
|
!options2.parser.startsWith("__ng_") && // Dynamic imports cannot have trailing commas
|
|
7474
7485
|
node.type !== "ImportExpression" && node.type !== "TSImportType" && shouldPrintComma(options2, "all") ? "," : ""
|
|
7475
7486
|
);
|
|
7487
|
+
if (node.type === "TSImportType" && args.length === 1 && (args[0].type === "TSLiteralType" && isStringLiteral(args[0].literal) || // TODO: Remove this when update Babel to v8
|
|
7488
|
+
isStringLiteral(args[0])) && !hasComment(args[0])) {
|
|
7489
|
+
return group(["(", ...printedArguments, ifBreak(maybeTrailingComma), ")"]);
|
|
7490
|
+
}
|
|
7476
7491
|
function allArgsBrokenOut() {
|
|
7477
7492
|
return group(
|
|
7478
7493
|
["(", indent([line, ...printedArguments]), maybeTrailingComma, line, ")"],
|
|
@@ -10363,7 +10378,11 @@ function printObject(path, options2, print3) {
|
|
|
10363
10378
|
propsAndLoc,
|
|
10364
10379
|
-1
|
|
10365
10380
|
)) == null ? void 0 : _a.node;
|
|
10366
|
-
const canHaveTrailingSeparator = !(node.inexact || node.hasUnknownMembers || lastElem && (lastElem.type === "RestElement" || (lastElem.type === "TSPropertySignature" || lastElem.type === "TSCallSignatureDeclaration" || lastElem.type === "TSMethodSignature" || lastElem.type === "TSConstructSignatureDeclaration" || lastElem.type === "TSIndexSignature") && hasComment(lastElem, CommentCheckFlags.PrettierIgnore))
|
|
10381
|
+
const canHaveTrailingSeparator = !(node.inexact || node.hasUnknownMembers || lastElem && (lastElem.type === "RestElement" || (lastElem.type === "TSPropertySignature" || lastElem.type === "TSCallSignatureDeclaration" || lastElem.type === "TSMethodSignature" || lastElem.type === "TSConstructSignatureDeclaration" || lastElem.type === "TSIndexSignature") && hasComment(lastElem, CommentCheckFlags.PrettierIgnore)) || // https://github.com/microsoft/TypeScript/issues/61916
|
|
10382
|
+
path.match(
|
|
10383
|
+
void 0,
|
|
10384
|
+
(node2, key2) => node2.type === "TSImportType" && key2 === "options"
|
|
10385
|
+
));
|
|
10367
10386
|
let content;
|
|
10368
10387
|
if (props.length === 0) {
|
|
10369
10388
|
if (!hasComment(node, CommentCheckFlags.Dangling)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prettier/plugin-oxc",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Prettier Oxc plugin.",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"package.json"
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"oxc-parser": "0.
|
|
34
|
+
"oxc-parser": "0.74.0"
|
|
35
35
|
},
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public",
|