@spyglassmc/mcdoc 0.1.1 → 0.2.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/lib/binder/index.d.ts +2 -2
- package/lib/binder/index.js +2 -18
- package/lib/binder/uriBinder.js +5 -9
- package/lib/binder/util.js +2 -7
- package/lib/checker/CheckerContext.d.ts +1 -1
- package/lib/checker/CheckerContext.js +1 -2
- package/lib/checker/entry.d.ts +1 -1
- package/lib/checker/entry.js +4 -8
- package/lib/checker/index.d.ts +1 -1
- package/lib/checker/index.js +1 -17
- package/lib/colorizer/index.d.ts +1 -1
- package/lib/colorizer/index.js +8 -14
- package/lib/index.d.ts +5 -5
- package/lib/index.js +10 -40
- package/lib/node/index.d.ts +5 -2
- package/lib/node/index.js +84 -82
- package/lib/parser/index.d.ts +1 -1
- package/lib/parser/index.js +184 -214
- package/lib/type/index.d.ts +1 -1
- package/lib/type/index.js +24 -35
- package/package.json +4 -3
package/lib/type/index.d.ts
CHANGED
package/lib/type/index.js
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const locales_1 = require("@spyglassmc/locales");
|
|
6
|
-
exports.EmptyUnion = Object.freeze({ kind: 'union', members: [] });
|
|
7
|
-
function createEmptyUnion(attributes) {
|
|
1
|
+
import { Arrayable } from '@spyglassmc/core';
|
|
2
|
+
import { localeQuote, localize } from '@spyglassmc/locales';
|
|
3
|
+
export const EmptyUnion = Object.freeze({ kind: 'union', members: [] });
|
|
4
|
+
export function createEmptyUnion(attributes) {
|
|
8
5
|
return {
|
|
9
|
-
...
|
|
6
|
+
...EmptyUnion,
|
|
10
7
|
attributes,
|
|
11
8
|
};
|
|
12
9
|
}
|
|
13
|
-
|
|
14
|
-
var McdocType;
|
|
10
|
+
export var McdocType;
|
|
15
11
|
(function (McdocType) {
|
|
16
12
|
function toString(type) {
|
|
17
13
|
const rangeToString = (range) => {
|
|
@@ -23,7 +19,7 @@ var McdocType;
|
|
|
23
19
|
};
|
|
24
20
|
const indicesToString = (indices) => {
|
|
25
21
|
const strings = [];
|
|
26
|
-
for (const index of
|
|
22
|
+
for (const index of Arrayable.toArray(indices)) {
|
|
27
23
|
if (index === undefined) {
|
|
28
24
|
strings.push('()');
|
|
29
25
|
}
|
|
@@ -81,7 +77,7 @@ var McdocType;
|
|
|
81
77
|
}
|
|
82
78
|
}
|
|
83
79
|
McdocType.toString = toString;
|
|
84
|
-
})(McdocType
|
|
80
|
+
})(McdocType || (McdocType = {}));
|
|
85
81
|
var CheckResult;
|
|
86
82
|
(function (CheckResult) {
|
|
87
83
|
CheckResult[CheckResult["Nah"] = 0] = "Nah";
|
|
@@ -100,7 +96,7 @@ const areRangesMatch = (s, t) => {
|
|
|
100
96
|
return (tMin === undefined || (sMin !== undefined && sMin >= tMin)) &&
|
|
101
97
|
(tMax === undefined || (sMax !== undefined && sMax <= tMax));
|
|
102
98
|
};
|
|
103
|
-
const flattenUnionType = (union) => {
|
|
99
|
+
export const flattenUnionType = (union) => {
|
|
104
100
|
const set = new Set();
|
|
105
101
|
const add = (data) => {
|
|
106
102
|
for (const existingMember of set) {
|
|
@@ -115,7 +111,7 @@ const flattenUnionType = (union) => {
|
|
|
115
111
|
};
|
|
116
112
|
for (const member of union.members) {
|
|
117
113
|
if (member.kind === 'union') {
|
|
118
|
-
|
|
114
|
+
flattenUnionType(member).members.forEach(add);
|
|
119
115
|
}
|
|
120
116
|
else {
|
|
121
117
|
add(member);
|
|
@@ -126,8 +122,7 @@ const flattenUnionType = (union) => {
|
|
|
126
122
|
members: [...set],
|
|
127
123
|
};
|
|
128
124
|
};
|
|
129
|
-
|
|
130
|
-
const unionTypes = (a, b) => {
|
|
125
|
+
export const unionTypes = (a, b) => {
|
|
131
126
|
if ((check(a, b) & CheckResult.StrictlyAssignable) === CheckResult.StrictlyAssignable) {
|
|
132
127
|
return b;
|
|
133
128
|
}
|
|
@@ -143,37 +138,33 @@ const unionTypes = (a, b) => {
|
|
|
143
138
|
};
|
|
144
139
|
return ans;
|
|
145
140
|
};
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
union = (0, exports.flattenUnionType)(union);
|
|
141
|
+
export const simplifyUnionType = (union) => {
|
|
142
|
+
union = flattenUnionType(union);
|
|
149
143
|
if (union.members.length === 1) {
|
|
150
144
|
return union.members[0];
|
|
151
145
|
}
|
|
152
146
|
return union;
|
|
153
147
|
};
|
|
154
|
-
|
|
155
|
-
const simplifyListType = (list) => ({
|
|
148
|
+
export const simplifyListType = (list) => ({
|
|
156
149
|
kind: 'list',
|
|
157
|
-
item:
|
|
150
|
+
item: simplifyType(list.item),
|
|
158
151
|
...list.lengthRange ? { lengthRange: [...list.lengthRange] } : {},
|
|
159
152
|
});
|
|
160
|
-
|
|
161
|
-
const simplifyType = (data) => {
|
|
153
|
+
export const simplifyType = (data) => {
|
|
162
154
|
if (data.kind === 'union') {
|
|
163
|
-
data =
|
|
155
|
+
data = simplifyUnionType(data);
|
|
164
156
|
}
|
|
165
157
|
else if (data.kind === 'list') {
|
|
166
|
-
data =
|
|
158
|
+
data = simplifyListType(data);
|
|
167
159
|
}
|
|
168
160
|
return data;
|
|
169
161
|
};
|
|
170
|
-
exports.simplifyType = simplifyType;
|
|
171
162
|
const check = (s, t, errors = []) => {
|
|
172
163
|
const strictlyAssignableIfTrue = (value) => value ? CheckResult.StrictlyAssignable : CheckResult.Nah;
|
|
173
164
|
const assignableIfTrue = (value) => value ? CheckResult.Assignable : CheckResult.Nah;
|
|
174
165
|
let ans;
|
|
175
|
-
s =
|
|
176
|
-
t =
|
|
166
|
+
s = simplifyType(s);
|
|
167
|
+
t = simplifyType(t);
|
|
177
168
|
if (s.kind === 'any' || s.kind === 'reference' || t.kind === 'reference') {
|
|
178
169
|
// Reference types are treated as any for now.
|
|
179
170
|
ans = CheckResult.Assignable;
|
|
@@ -244,11 +235,11 @@ const check = (s, t, errors = []) => {
|
|
|
244
235
|
ans = CheckResult.Nah;
|
|
245
236
|
}
|
|
246
237
|
if (!ans) {
|
|
247
|
-
errors.push(
|
|
238
|
+
errors.push(localize('mcdoc.checker.type-not-assignable', localeQuote(McdocType.toString(s)), localeQuote(McdocType.toString(t))));
|
|
248
239
|
}
|
|
249
240
|
return ans;
|
|
250
241
|
};
|
|
251
|
-
const checkAssignability = ({ source, target }) => {
|
|
242
|
+
export const checkAssignability = ({ source, target }) => {
|
|
252
243
|
if (source === undefined || target === undefined) {
|
|
253
244
|
return { isAssignable: true };
|
|
254
245
|
}
|
|
@@ -259,8 +250,7 @@ const checkAssignability = ({ source, target }) => {
|
|
|
259
250
|
...errors.length ? { errorMessage: errors.reverse().map((m, i) => `${' '.repeat(i)}${m}`).join('\n') } : {},
|
|
260
251
|
};
|
|
261
252
|
};
|
|
262
|
-
|
|
263
|
-
function resolveType(inputType, ctx, value) {
|
|
253
|
+
export function resolveType(inputType, ctx, value) {
|
|
264
254
|
const type = getTangibleType(inputType, ctx, value);
|
|
265
255
|
let ans = (() => {
|
|
266
256
|
if (type.kind === 'union') {
|
|
@@ -282,7 +272,6 @@ function resolveType(inputType, ctx, value) {
|
|
|
282
272
|
}
|
|
283
273
|
return ans;
|
|
284
274
|
}
|
|
285
|
-
exports.resolveType = resolveType;
|
|
286
275
|
function dispatchType(type, ctx) {
|
|
287
276
|
throw '// TODO';
|
|
288
277
|
}
|
|
@@ -389,7 +378,7 @@ function flattenStruct(type, ctx, value) {
|
|
|
389
378
|
}
|
|
390
379
|
function addAttributes(type, ...attributes) {
|
|
391
380
|
for (const attr of attributes) {
|
|
392
|
-
type.attributes
|
|
381
|
+
type.attributes ??= [];
|
|
393
382
|
if (!type.attributes.some(a => a.name === attr.name)) {
|
|
394
383
|
type.attributes.push(attr);
|
|
395
384
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spyglassmc/mcdoc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"main": "lib/index.js",
|
|
5
6
|
"types": "lib/index.d.ts",
|
|
6
7
|
"author": "SPGoding",
|
|
@@ -24,7 +25,7 @@
|
|
|
24
25
|
"url": "https://github.com/SpyglassMC/Spyglass/issues"
|
|
25
26
|
},
|
|
26
27
|
"dependencies": {
|
|
27
|
-
"@spyglassmc/core": "0.
|
|
28
|
-
"@spyglassmc/locales": "0.
|
|
28
|
+
"@spyglassmc/core": "0.2.0",
|
|
29
|
+
"@spyglassmc/locales": "0.2.0"
|
|
29
30
|
}
|
|
30
31
|
}
|