@puruslang/prettier-plugin-purus 0.3.1 → 0.4.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 +25 -4
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -10,7 +10,7 @@ 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
16
|
"true", "false", "null", "nil", "undefined",
|
|
@@ -101,16 +101,37 @@ function tokenize(source) {
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
// Punctuation
|
|
104
|
-
if ("[]
|
|
104
|
+
if ("[],;".includes(source[i])) {
|
|
105
|
+
tokens.push({ type: "punct", value: source[i] });
|
|
106
|
+
i++;
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Optional chaining \.
|
|
111
|
+
if (source[i] === "\\" && source[i + 1] === ".") {
|
|
112
|
+
tokens.push({ type: "punct", value: "\\." });
|
|
113
|
+
i += 2;
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Backslash (computed access prefix)
|
|
118
|
+
if (source[i] === "\\") {
|
|
119
|
+
tokens.push({ type: "punct", value: "\\" });
|
|
120
|
+
i++;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Dot
|
|
125
|
+
if (source[i] === ".") {
|
|
105
126
|
tokens.push({ type: "punct", value: source[i] });
|
|
106
127
|
i++;
|
|
107
128
|
continue;
|
|
108
129
|
}
|
|
109
130
|
|
|
110
131
|
// Word (identifier or keyword)
|
|
111
|
-
if (/[a-zA-
|
|
132
|
+
if (/[a-zA-Z_]/.test(source[i])) {
|
|
112
133
|
let start = i;
|
|
113
|
-
while (i < len && /[a-zA-Z0-
|
|
134
|
+
while (i < len && /[a-zA-Z0-9_-]/.test(source[i])) i++;
|
|
114
135
|
const word = source.slice(start, i);
|
|
115
136
|
tokens.push({ type: KEYWORDS.has(word) ? "keyword" : "ident", value: word });
|
|
116
137
|
continue;
|