@puruslang/prettier-plugin-purus 0.3.1 → 0.5.0
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/package.json +1 -1
- package/src/index.js +27 -5
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -10,9 +10,10 @@ const KEYWORDS = new Set([
|
|
|
10
10
|
"import", "from", "export", "default", "require", "use", "namespace", "pub", "all",
|
|
11
11
|
"add", "sub", "mul", "div", "mod", "neg", "pow",
|
|
12
12
|
"eq", "neq", "lt", "gt", "le", "ge",
|
|
13
|
-
"and", "or", "not", "pipe",
|
|
13
|
+
"and", "or", "not", "pipe", "coal",
|
|
14
14
|
"is", "as", "of", "typeof", "instanceof", "type",
|
|
15
15
|
"new", "delete", "this", "await",
|
|
16
|
+
"class", "extends", "super", "static", "private", "get", "set",
|
|
16
17
|
"true", "false", "null", "nil", "undefined",
|
|
17
18
|
"break", "continue",
|
|
18
19
|
"list", "object",
|
|
@@ -23,7 +24,7 @@ const BLOCK_STARTERS = new Set([
|
|
|
23
24
|
"while", "until", "for",
|
|
24
25
|
"match", "when",
|
|
25
26
|
"try", "catch", "finally",
|
|
26
|
-
"namespace",
|
|
27
|
+
"namespace", "class",
|
|
27
28
|
]);
|
|
28
29
|
|
|
29
30
|
function tokenize(source) {
|
|
@@ -101,16 +102,37 @@ function tokenize(source) {
|
|
|
101
102
|
}
|
|
102
103
|
|
|
103
104
|
// Punctuation
|
|
104
|
-
if ("[]
|
|
105
|
+
if ("[],;".includes(source[i])) {
|
|
106
|
+
tokens.push({ type: "punct", value: source[i] });
|
|
107
|
+
i++;
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Optional chaining \.
|
|
112
|
+
if (source[i] === "\\" && source[i + 1] === ".") {
|
|
113
|
+
tokens.push({ type: "punct", value: "\\." });
|
|
114
|
+
i += 2;
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Backslash (computed access prefix)
|
|
119
|
+
if (source[i] === "\\") {
|
|
120
|
+
tokens.push({ type: "punct", value: "\\" });
|
|
121
|
+
i++;
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Dot
|
|
126
|
+
if (source[i] === ".") {
|
|
105
127
|
tokens.push({ type: "punct", value: source[i] });
|
|
106
128
|
i++;
|
|
107
129
|
continue;
|
|
108
130
|
}
|
|
109
131
|
|
|
110
132
|
// Word (identifier or keyword)
|
|
111
|
-
if (/[a-zA-
|
|
133
|
+
if (/[a-zA-Z_]/.test(source[i])) {
|
|
112
134
|
let start = i;
|
|
113
|
-
while (i < len && /[a-zA-Z0-
|
|
135
|
+
while (i < len && /[a-zA-Z0-9_-]/.test(source[i])) i++;
|
|
114
136
|
const word = source.slice(start, i);
|
|
115
137
|
tokens.push({ type: KEYWORDS.has(word) ? "keyword" : "ident", value: word });
|
|
116
138
|
continue;
|