prettier-plugin-razor2 0.1.1 → 0.1.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/dist/index.js +45 -1
- package/package.json +26 -15
package/dist/index.js
CHANGED
|
@@ -59,6 +59,24 @@ function readTagName(src, i) {
|
|
|
59
59
|
while (j < src.length && /[A-Za-z0-9]/.test(src[j])) j++;
|
|
60
60
|
return src.slice(i, j);
|
|
61
61
|
}
|
|
62
|
+
function readCSharpIdent(src, i) {
|
|
63
|
+
if (!/[A-Za-z_]/.test(src[i] ?? "")) return "";
|
|
64
|
+
let j = i + 1;
|
|
65
|
+
while (j < src.length && /[A-Za-z0-9_]/.test(src[j])) j++;
|
|
66
|
+
return src.slice(i, j);
|
|
67
|
+
}
|
|
68
|
+
function readImplicitExpression(src, at) {
|
|
69
|
+
let i = at + 1 + readCSharpIdent(src, at + 1).length;
|
|
70
|
+
for (;;) {
|
|
71
|
+
const c = src[i];
|
|
72
|
+
if (c === "(") i = matchParen(src, i);
|
|
73
|
+
else if (c === "[") i = matchDelimited(src, i, "[", "]");
|
|
74
|
+
else if (c === "." && readCSharpIdent(src, i + 1) !== "") i += 1 + readCSharpIdent(src, i + 1).length;
|
|
75
|
+
else if (c === "?" && src[i + 1] === "." && readCSharpIdent(src, i + 2) !== "") i += 2 + readCSharpIdent(src, i + 2).length;
|
|
76
|
+
else break;
|
|
77
|
+
}
|
|
78
|
+
return i;
|
|
79
|
+
}
|
|
62
80
|
function atLineStart(src, i) {
|
|
63
81
|
let j = i - 1;
|
|
64
82
|
while (j >= 0 && (src[j] === " " || src[j] === " ")) j--;
|
|
@@ -412,6 +430,17 @@ function mask(src) {
|
|
|
412
430
|
i = end;
|
|
413
431
|
continue;
|
|
414
432
|
}
|
|
433
|
+
if (/[A-Za-z_]/.test(src[i + 1] ?? "")) {
|
|
434
|
+
const end = readImplicitExpression(src, i);
|
|
435
|
+
const text = src.slice(i, end);
|
|
436
|
+
if (text.includes("\"") || text.includes("'")) out += inlinePlaceholder({
|
|
437
|
+
kind: "inline",
|
|
438
|
+
text
|
|
439
|
+
});
|
|
440
|
+
else out += text;
|
|
441
|
+
i = end;
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
415
444
|
out += c;
|
|
416
445
|
i++;
|
|
417
446
|
}
|
|
@@ -701,13 +730,28 @@ const options = {
|
|
|
701
730
|
description: "Command used to invoke the CSharpier CLI."
|
|
702
731
|
}
|
|
703
732
|
};
|
|
733
|
+
function warnUnformatted(filepath, error) {
|
|
734
|
+
const where = filepath ? ` (${filepath})` : "";
|
|
735
|
+
const why = error instanceof Error ? `: ${error.message.split("\n")[0]}` : "";
|
|
736
|
+
console.warn(`[prettier-plugin-razor2] Could not format this file${where}; leaving it unchanged${why}`);
|
|
737
|
+
}
|
|
704
738
|
const printers = { "razor-ast": {
|
|
705
739
|
print: () => "",
|
|
706
740
|
embed(path) {
|
|
707
741
|
const node = path.node;
|
|
708
742
|
if (node.type !== "razor-root") return null;
|
|
709
743
|
return async (textToDoc, _print, _embedPath, options) => {
|
|
710
|
-
|
|
744
|
+
try {
|
|
745
|
+
const formatted = await formatDocument(node.source, textToDoc, options);
|
|
746
|
+
if (formatted.trim() === "" && node.source.trim() !== "") {
|
|
747
|
+
warnUnformatted(options.filepath);
|
|
748
|
+
return node.source;
|
|
749
|
+
}
|
|
750
|
+
return formatted.replace(/\s+$/, "") + "\n";
|
|
751
|
+
} catch (error) {
|
|
752
|
+
warnUnformatted(options.filepath, error);
|
|
753
|
+
return node.source;
|
|
754
|
+
}
|
|
711
755
|
};
|
|
712
756
|
}
|
|
713
757
|
} };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prettier-plugin-razor2",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Prettier plugin for Razor (Blazor) files — a fork of prettier-plugin-razor",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"prettier",
|
|
@@ -33,30 +33,41 @@
|
|
|
33
33
|
"files": [
|
|
34
34
|
"dist"
|
|
35
35
|
],
|
|
36
|
-
"scripts": {
|
|
37
|
-
"bench": "node bench/bench.ts",
|
|
38
|
-
"build": "tsdown",
|
|
39
|
-
"clean": "rm -rf dist",
|
|
40
|
-
"csharpier": "dotnet csharpier",
|
|
41
|
-
"format": "prettier --write .",
|
|
42
|
-
"node": "node",
|
|
43
|
-
"prepublishOnly": "rm -rf dist && tsdown",
|
|
44
|
-
"test": "node --test \"tests/**/*.test.ts\"",
|
|
45
|
-
"typecheck": "tsc"
|
|
46
|
-
},
|
|
47
36
|
"devDependencies": {
|
|
48
37
|
"@types/node": "26.1.0",
|
|
49
38
|
"prettier": "3.9.4",
|
|
50
39
|
"prettier-plugin-jsdoc": "1.8.1",
|
|
51
40
|
"prettier-plugin-packagejson": "3.0.2",
|
|
52
41
|
"tsdown": "^0.22.3",
|
|
53
|
-
"typescript": "6.0.3"
|
|
42
|
+
"typescript": "6.0.3",
|
|
43
|
+
"node": "runtime:26.4.0"
|
|
54
44
|
},
|
|
55
45
|
"peerDependencies": {
|
|
56
46
|
"prettier": "^3.0.0"
|
|
57
47
|
},
|
|
58
|
-
"packageManager": "pnpm@11.9.0",
|
|
59
48
|
"engines": {
|
|
60
49
|
"node": ">=20"
|
|
50
|
+
},
|
|
51
|
+
"devEngines": {
|
|
52
|
+
"runtime": {
|
|
53
|
+
"name": "node",
|
|
54
|
+
"version": "26.4.0",
|
|
55
|
+
"onFail": "download"
|
|
56
|
+
},
|
|
57
|
+
"packageManager": {
|
|
58
|
+
"name": "pnpm",
|
|
59
|
+
"version": "11.10.0",
|
|
60
|
+
"onFail": "download"
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"scripts": {
|
|
64
|
+
"bench": "node bench/bench.ts",
|
|
65
|
+
"build": "tsdown",
|
|
66
|
+
"clean": "rm -rf dist",
|
|
67
|
+
"csharpier": "dotnet csharpier",
|
|
68
|
+
"format": "prettier --write .",
|
|
69
|
+
"node": "node",
|
|
70
|
+
"test": "node --test \"tests/**/*.test.ts\"",
|
|
71
|
+
"typecheck": "tsc"
|
|
61
72
|
}
|
|
62
|
-
}
|
|
73
|
+
}
|