prettier-plugin-insert-comma 1.0.0 → 1.0.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/index.js +8 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ function fixMissingCommas(code) {
|
|
|
6
6
|
let quote = null;
|
|
7
7
|
let isEscaped = false;
|
|
8
8
|
let out = '';
|
|
9
|
+
let lastWasComment = false;
|
|
9
10
|
for (let i = 0; i < code.length; i++) {
|
|
10
11
|
const ch = code[i];
|
|
11
12
|
if (inString) {
|
|
@@ -26,6 +27,7 @@ function fixMissingCommas(code) {
|
|
|
26
27
|
const comment = code.slice(i, lineEnd === -1 ? code.length : lineEnd);
|
|
27
28
|
out += comment;
|
|
28
29
|
i += comment.length - 1;
|
|
30
|
+
lastWasComment = true;
|
|
29
31
|
continue;
|
|
30
32
|
}
|
|
31
33
|
if (ch === '/' && code[i + 1] === '*') {
|
|
@@ -34,6 +36,7 @@ function fixMissingCommas(code) {
|
|
|
34
36
|
const comment = code.slice(i, endIdx + 2);
|
|
35
37
|
out += comment;
|
|
36
38
|
i += comment.length - 1;
|
|
39
|
+
lastWasComment = true;
|
|
37
40
|
continue;
|
|
38
41
|
}
|
|
39
42
|
}
|
|
@@ -69,7 +72,7 @@ function fixMissingCommas(code) {
|
|
|
69
72
|
prev === ':' ||
|
|
70
73
|
prev === ';' ||
|
|
71
74
|
prev === undefined;
|
|
72
|
-
if (isNextKeyOrClosing && !isPrevSeparator) {
|
|
75
|
+
if (isNextKeyOrClosing && !isPrevSeparator && !lastWasComment) {
|
|
73
76
|
out += ',';
|
|
74
77
|
}
|
|
75
78
|
}
|
|
@@ -87,13 +90,16 @@ function fixMissingCommas(code) {
|
|
|
87
90
|
prev === ':' ||
|
|
88
91
|
prev === ';' ||
|
|
89
92
|
prev === undefined;
|
|
90
|
-
if (!isPrevSeparator) {
|
|
93
|
+
if (!isPrevSeparator && !lastWasComment) {
|
|
91
94
|
out += ',';
|
|
92
95
|
}
|
|
93
96
|
}
|
|
94
97
|
}
|
|
95
98
|
}
|
|
96
99
|
out += ch;
|
|
100
|
+
if (!/\s/.test(ch)) {
|
|
101
|
+
lastWasComment = false;
|
|
102
|
+
}
|
|
97
103
|
}
|
|
98
104
|
return out;
|
|
99
105
|
}
|
package/package.json
CHANGED