@spyglassmc/core 0.1.2 → 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/README.md +7 -0
- package/lib/browser.d.ts +2 -0
- package/lib/browser.js +2 -0
- package/lib/common/Dev.d.ts +11 -0
- package/lib/common/Dev.js +90 -0
- package/lib/{service → common}/Logger.d.ts +0 -0
- package/lib/{service → common}/Logger.js +2 -5
- package/lib/common/Operations.d.ts +12 -0
- package/lib/common/Operations.js +33 -0
- package/lib/common/ReadonlyProxy.d.ts +9 -0
- package/lib/common/ReadonlyProxy.js +23 -0
- package/lib/common/StateProxy.d.ts +35 -0
- package/lib/common/StateProxy.js +69 -0
- package/lib/common/TwoWayMap.js +4 -10
- package/lib/common/externals/BrowserExternals.d.ts +3 -0
- package/lib/common/externals/BrowserExternals.js +191 -0
- package/lib/common/externals/NodeJsExternals.d.ts +3 -0
- package/lib/common/externals/NodeJsExternals.js +152 -0
- package/lib/common/externals/downloader.d.ts +31 -0
- package/lib/common/externals/downloader.js +32 -0
- package/lib/common/externals/index.d.ts +96 -0
- package/lib/common/externals/index.js +2 -0
- package/lib/common/index.d.ts +8 -1
- package/lib/common/index.js +8 -17
- package/lib/common/util.d.ts +48 -20
- package/lib/common/util.js +71 -86
- package/lib/index.d.ts +7 -7
- package/lib/index.js +7 -23
- package/lib/node/AstNode.d.ts +12 -11
- package/lib/node/AstNode.js +10 -16
- package/lib/node/BooleanNode.d.ts +2 -2
- package/lib/node/BooleanNode.js +4 -7
- package/lib/node/CommentNode.d.ts +6 -5
- package/lib/node/CommentNode.js +4 -9
- package/lib/node/ErrorNode.d.ts +1 -1
- package/lib/node/ErrorNode.js +2 -5
- package/lib/node/FileNode.d.ts +8 -4
- package/lib/node/FileNode.js +3 -6
- package/lib/node/FloatNode.d.ts +3 -3
- package/lib/node/FloatNode.js +4 -7
- package/lib/node/IntegerNode.d.ts +3 -3
- package/lib/node/IntegerNode.js +4 -7
- package/lib/node/ListNode.d.ts +2 -2
- package/lib/node/ListNode.js +2 -5
- package/lib/node/LiteralNode.d.ts +4 -4
- package/lib/node/LiteralNode.js +4 -7
- package/lib/node/LongNode.d.ts +3 -3
- package/lib/node/LongNode.js +4 -7
- package/lib/node/RecordNode.d.ts +2 -2
- package/lib/node/RecordNode.js +2 -5
- package/lib/node/ResourceLocationNode.d.ts +7 -7
- package/lib/node/ResourceLocationNode.js +9 -12
- package/lib/node/Sequence.d.ts +2 -2
- package/lib/node/Sequence.js +4 -7
- package/lib/node/StringNode.d.ts +5 -5
- package/lib/node/StringNode.js +9 -12
- package/lib/node/SymbolNode.d.ts +4 -4
- package/lib/node/SymbolNode.js +4 -7
- package/lib/node/index.d.ts +15 -15
- package/lib/node/index.js +15 -31
- package/lib/nodejs.d.ts +2 -0
- package/lib/nodejs.js +2 -0
- package/lib/parser/Parser.d.ts +3 -3
- package/lib/parser/Parser.js +1 -4
- package/lib/parser/boolean.d.ts +2 -2
- package/lib/parser/boolean.js +3 -6
- package/lib/parser/comment.d.ts +2 -2
- package/lib/parser/comment.js +5 -9
- package/lib/parser/empty.d.ts +1 -1
- package/lib/parser/empty.js +1 -5
- package/lib/parser/error.d.ts +2 -2
- package/lib/parser/error.js +5 -9
- package/lib/parser/file.d.ts +3 -3
- package/lib/parser/file.js +9 -13
- package/lib/parser/float.d.ts +4 -4
- package/lib/parser/float.js +12 -16
- package/lib/parser/index.d.ts +16 -16
- package/lib/parser/index.js +16 -38
- package/lib/parser/integer.d.ts +4 -4
- package/lib/parser/integer.js +10 -14
- package/lib/parser/list.d.ts +2 -2
- package/lib/parser/list.js +15 -19
- package/lib/parser/literal.d.ts +2 -2
- package/lib/parser/literal.js +5 -9
- package/lib/parser/long.d.ts +4 -4
- package/lib/parser/long.js +10 -14
- package/lib/parser/record.d.ts +3 -3
- package/lib/parser/record.js +20 -24
- package/lib/parser/resourceLocation.d.ts +2 -2
- package/lib/parser/resourceLocation.js +12 -24
- package/lib/parser/string.d.ts +7 -7
- package/lib/parser/string.js +36 -42
- package/lib/parser/symbol.d.ts +3 -3
- package/lib/parser/symbol.js +4 -14
- package/lib/parser/util.d.ts +6 -5
- package/lib/parser/util.js +40 -60
- package/lib/processor/ColorInfoProvider.d.ts +1 -1
- package/lib/processor/ColorInfoProvider.js +6 -9
- package/lib/processor/InlayHintProvider.d.ts +4 -3
- package/lib/processor/InlayHintProvider.js +1 -2
- package/lib/processor/SignatureHelpProvider.d.ts +4 -3
- package/lib/processor/SignatureHelpProvider.js +1 -2
- package/lib/processor/binder/Binder.d.ts +26 -0
- package/lib/processor/binder/Binder.js +18 -0
- package/lib/processor/binder/builtin.d.ts +27 -0
- package/lib/processor/binder/builtin.js +116 -0
- package/lib/processor/binder/index.d.ts +3 -0
- package/lib/processor/binder/index.js +3 -0
- package/lib/processor/checker/Checker.d.ts +2 -2
- package/lib/processor/checker/Checker.js +1 -5
- package/lib/processor/checker/builtin.d.ts +4 -4
- package/lib/processor/checker/builtin.js +22 -33
- package/lib/processor/checker/index.d.ts +2 -2
- package/lib/processor/checker/index.js +2 -31
- package/lib/processor/colorizer/Colorizer.d.ts +6 -5
- package/lib/processor/colorizer/Colorizer.js +8 -11
- package/lib/processor/colorizer/builtin.d.ts +3 -3
- package/lib/processor/colorizer/builtin.js +34 -46
- package/lib/processor/colorizer/index.d.ts +2 -2
- package/lib/processor/colorizer/index.js +2 -31
- package/lib/processor/completer/Completer.d.ts +6 -5
- package/lib/processor/completer/Completer.js +14 -33
- package/lib/processor/completer/builtin.d.ts +10 -9
- package/lib/processor/completer/builtin.js +47 -63
- package/lib/processor/completer/index.d.ts +2 -2
- package/lib/processor/completer/index.js +2 -31
- package/lib/processor/formatter/Formatter.d.ts +4 -3
- package/lib/processor/formatter/Formatter.js +2 -7
- package/lib/processor/formatter/builtin.d.ts +3 -3
- package/lib/processor/formatter/builtin.js +22 -36
- package/lib/processor/formatter/index.d.ts +2 -2
- package/lib/processor/formatter/index.js +2 -31
- package/lib/processor/index.d.ts +10 -9
- package/lib/processor/index.js +10 -25
- package/lib/processor/linter/Linter.d.ts +4 -3
- package/lib/processor/linter/Linter.js +1 -2
- package/lib/processor/linter/builtin/undeclaredSymbol.d.ts +2 -2
- package/lib/processor/linter/builtin/undeclaredSymbol.js +20 -24
- package/lib/processor/linter/builtin.d.ts +4 -3
- package/lib/processor/linter/builtin.js +19 -26
- package/lib/processor/linter/index.d.ts +2 -2
- package/lib/processor/linter/index.js +2 -31
- package/lib/processor/util.d.ts +4 -14
- package/lib/processor/util.js +1 -16
- package/lib/service/CacheService.d.ts +13 -8
- package/lib/service/CacheService.js +45 -57
- package/lib/service/Config.d.ts +11 -12
- package/lib/service/Config.js +50 -45
- package/lib/service/Context.d.ts +23 -20
- package/lib/service/Context.js +39 -36
- package/lib/service/Dependency.js +2 -5
- package/lib/service/Downloader.d.ts +9 -40
- package/lib/service/Downloader.js +37 -110
- package/lib/service/ErrorReporter.d.ts +2 -2
- package/lib/service/ErrorReporter.js +10 -14
- package/lib/service/FileService.d.ts +15 -14
- package/lib/service/FileService.js +55 -92
- package/lib/service/Hover.d.ts +2 -2
- package/lib/service/Hover.js +4 -7
- package/lib/service/MetaRegistry.d.ts +22 -12
- package/lib/service/MetaRegistry.js +81 -73
- package/lib/service/Profiler.d.ts +3 -2
- package/lib/service/Profiler.js +81 -45
- package/lib/service/Project.d.ts +105 -76
- package/lib/service/Project.js +449 -370
- package/lib/service/Service.d.ts +17 -27
- package/lib/service/Service.js +37 -43
- package/lib/service/SymbolLocations.d.ts +3 -3
- package/lib/service/SymbolLocations.js +4 -7
- package/lib/service/SymbolRegistrar.d.ts +1 -1
- package/lib/service/SymbolRegistrar.js +1 -2
- package/lib/service/UriProcessor.d.ts +5 -0
- package/lib/service/UriProcessor.js +2 -0
- package/lib/service/fileUtil.d.ts +15 -45
- package/lib/service/fileUtil.js +38 -143
- package/lib/service/index.d.ts +16 -17
- package/lib/service/index.js +16 -35
- package/lib/source/IndexMap.d.ts +1 -1
- package/lib/source/IndexMap.js +7 -10
- package/lib/source/LanguageError.d.ts +20 -6
- package/lib/source/LanguageError.js +16 -9
- package/lib/source/Location.d.ts +3 -3
- package/lib/source/Location.js +6 -9
- package/lib/source/Offset.d.ts +1 -1
- package/lib/source/Offset.js +4 -7
- package/lib/source/Position.js +2 -5
- package/lib/source/PositionRange.d.ts +3 -3
- package/lib/source/PositionRange.js +17 -20
- package/lib/source/Range.d.ts +1 -1
- package/lib/source/Range.js +7 -10
- package/lib/source/Source.d.ts +5 -3
- package/lib/source/Source.js +34 -29
- package/lib/source/index.d.ts +8 -8
- package/lib/source/index.js +8 -24
- package/lib/symbol/Symbol.d.ts +5 -4
- package/lib/symbol/Symbol.js +49 -65
- package/lib/symbol/SymbolUtil.d.ts +29 -31
- package/lib/symbol/SymbolUtil.js +178 -157
- package/lib/symbol/index.d.ts +2 -3
- package/lib/symbol/index.js +2 -19
- package/package.json +7 -4
- package/lib/service/Operations.d.ts +0 -8
- package/lib/service/Operations.js +0 -26
- package/lib/symbol/UriBinder.d.ts +0 -3
- package/lib/symbol/UriBinder.js +0 -3
package/lib/common/util.js
CHANGED
|
@@ -1,56 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.isIterable = exports.binarySearch = exports.getStates = exports.Lazy = exports.merge = exports.isObject = exports.parseGzippedJson = exports.zip = exports.unzip = exports.promisifyAsyncIterable = exports.TypePredicates = exports.Arrayable = exports.isEnoent = exports.isErrorCode = exports.getSha1 = exports.base64ToString = exports.stringToBase64 = exports.bufferToString = exports.ResourceLocation = exports.Delay = exports.Singleton = exports.CachePromise = exports.Uri = void 0;
|
|
7
|
-
const binary_search_1 = __importDefault(require("binary-search"));
|
|
8
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
9
|
-
const rfdc_1 = __importDefault(require("rfdc"));
|
|
10
|
-
const util_1 = require("util");
|
|
11
|
-
const zlib_1 = __importDefault(require("zlib"));
|
|
12
|
-
var url_1 = require("url");
|
|
13
|
-
Object.defineProperty(exports, "Uri", { enumerable: true, get: function () { return url_1.URL; } });
|
|
1
|
+
import externalBinarySearch from 'binary-search';
|
|
2
|
+
import rfdc from 'rfdc';
|
|
3
|
+
export const Uri = URL;
|
|
14
4
|
/**
|
|
15
|
-
* @param
|
|
16
|
-
* The result of this function will be used as the key to
|
|
5
|
+
* @param getKey A function that takes the actual arguments being passed into the decorated method, and returns anything.
|
|
6
|
+
* The result of this function will be used as the key to identify the `Promise`. By default the first element in the argument
|
|
17
7
|
* list will be used.
|
|
18
8
|
*
|
|
19
9
|
* This is a decorator for async methods. Decorated methods will return the same `Promise` for
|
|
20
|
-
* the same
|
|
10
|
+
* the same key, provided that the previously returned `Promise` is still pending.
|
|
21
11
|
*/
|
|
22
|
-
function
|
|
12
|
+
export function SingletonPromise(getKey = args => args[0]) {
|
|
23
13
|
return (_target, _key, descripter) => {
|
|
24
14
|
const promises = new Map();
|
|
25
15
|
const decoratedMethod = descripter.value;
|
|
26
16
|
// The `function` syntax is used to preserve `this` context from the decorated method.
|
|
27
17
|
descripter.value = function (...args) {
|
|
28
|
-
const
|
|
29
|
-
if (promises.has(
|
|
30
|
-
return promises.get(
|
|
18
|
+
const key = getKey(args);
|
|
19
|
+
if (promises.has(key)) {
|
|
20
|
+
return promises.get(key);
|
|
31
21
|
}
|
|
32
22
|
const ans = decoratedMethod.apply(this, args)
|
|
33
|
-
.then(ans => (promises.delete(
|
|
34
|
-
promises.set(
|
|
23
|
+
.then(ans => (promises.delete(key), ans), e => (promises.delete(key), Promise.reject(e)));
|
|
24
|
+
promises.set(key, ans);
|
|
35
25
|
return ans;
|
|
36
26
|
};
|
|
37
27
|
return descripter;
|
|
38
28
|
};
|
|
39
29
|
}
|
|
40
|
-
exports.CachePromise = CachePromise;
|
|
41
30
|
/**
|
|
42
31
|
* This is a decorator for methods. Decorated methods will return the same non-`undefined` value no matter what.
|
|
43
32
|
*/
|
|
44
|
-
const Singleton = (_target, _key, descripter) => {
|
|
33
|
+
export const Singleton = (_target, _key, descripter) => {
|
|
45
34
|
let value;
|
|
46
35
|
const decoratedMethod = descripter.value;
|
|
47
36
|
// The `function` syntax is used to preserve `this` context from the decorated method.
|
|
48
37
|
descripter.value = function (...args) {
|
|
49
|
-
return value
|
|
38
|
+
return value ??= decoratedMethod.apply(this, args);
|
|
50
39
|
};
|
|
51
40
|
return descripter;
|
|
52
41
|
};
|
|
53
|
-
exports.Singleton = Singleton;
|
|
54
42
|
/**
|
|
55
43
|
* @param getKey A function that takes the actual arguments being passed into the decorated method, and returns anything.
|
|
56
44
|
* The result of this function will be used as the key to cache the `Timeout`. By default the first element in the argument
|
|
@@ -58,7 +46,7 @@ exports.Singleton = Singleton;
|
|
|
58
46
|
*
|
|
59
47
|
* Decorated methods will be scheduled to run after `ms` milliseconds. The timer will reset when the method is called again.
|
|
60
48
|
*/
|
|
61
|
-
function Delay(ms, getKey = args => args[0]) {
|
|
49
|
+
export function Delay(ms, getKey = args => args[0]) {
|
|
62
50
|
return (_target, _key, descripter) => {
|
|
63
51
|
const timeouts = new Map();
|
|
64
52
|
const decoratedMethod = descripter.value;
|
|
@@ -76,8 +64,7 @@ function Delay(ms, getKey = args => args[0]) {
|
|
|
76
64
|
return descripter;
|
|
77
65
|
};
|
|
78
66
|
}
|
|
79
|
-
|
|
80
|
-
var ResourceLocation;
|
|
67
|
+
export var ResourceLocation;
|
|
81
68
|
(function (ResourceLocation) {
|
|
82
69
|
/**
|
|
83
70
|
* The prefix for tags.
|
|
@@ -107,45 +94,19 @@ var ResourceLocation;
|
|
|
107
94
|
return value.replace(/^(?:minecraft)?:/, '');
|
|
108
95
|
}
|
|
109
96
|
ResourceLocation.shorten = shorten;
|
|
110
|
-
})(ResourceLocation
|
|
97
|
+
})(ResourceLocation || (ResourceLocation = {}));
|
|
111
98
|
/**
|
|
112
99
|
* @returns The string value decoded from the buffer according to UTF-8.
|
|
113
100
|
* Byte order mark is correctly removed.
|
|
114
101
|
*/
|
|
115
|
-
function bufferToString(buffer) {
|
|
116
|
-
const ans =
|
|
117
|
-
if (ans.charCodeAt(0) === 0xFEFF) {
|
|
118
|
-
|
|
119
|
-
}
|
|
102
|
+
export function bufferToString(buffer) {
|
|
103
|
+
const ans = new TextDecoder().decode(buffer);
|
|
104
|
+
// if (ans.charCodeAt(0) === 0xFEFF) {
|
|
105
|
+
// return ans.slice(1)
|
|
106
|
+
// }
|
|
120
107
|
return ans;
|
|
121
108
|
}
|
|
122
|
-
|
|
123
|
-
function stringToBase64(str) {
|
|
124
|
-
return Buffer.from(str).toString('base64');
|
|
125
|
-
}
|
|
126
|
-
exports.stringToBase64 = stringToBase64;
|
|
127
|
-
function base64ToString(base64) {
|
|
128
|
-
return Buffer.from(base64, 'base64').toString('utf-8');
|
|
129
|
-
}
|
|
130
|
-
exports.base64ToString = base64ToString;
|
|
131
|
-
/**
|
|
132
|
-
* @throws
|
|
133
|
-
*/
|
|
134
|
-
function getSha1(data) {
|
|
135
|
-
const hash = crypto_1.default.createHash('sha1');
|
|
136
|
-
hash.update(data);
|
|
137
|
-
return hash.digest('hex');
|
|
138
|
-
}
|
|
139
|
-
exports.getSha1 = getSha1;
|
|
140
|
-
function isErrorCode(e, code) {
|
|
141
|
-
return e instanceof Error && e.code === code;
|
|
142
|
-
}
|
|
143
|
-
exports.isErrorCode = isErrorCode;
|
|
144
|
-
function isEnoent(e) {
|
|
145
|
-
return isErrorCode(e, 'ENOENT');
|
|
146
|
-
}
|
|
147
|
-
exports.isEnoent = isEnoent;
|
|
148
|
-
var Arrayable;
|
|
109
|
+
export var Arrayable;
|
|
149
110
|
(function (Arrayable) {
|
|
150
111
|
function is(value, isT) {
|
|
151
112
|
return Array.isArray(value)
|
|
@@ -157,15 +118,15 @@ var Arrayable;
|
|
|
157
118
|
return Array.isArray(value) ? value : [value];
|
|
158
119
|
}
|
|
159
120
|
Arrayable.toArray = toArray;
|
|
160
|
-
})(Arrayable
|
|
161
|
-
var TypePredicates;
|
|
121
|
+
})(Arrayable || (Arrayable = {}));
|
|
122
|
+
export var TypePredicates;
|
|
162
123
|
(function (TypePredicates) {
|
|
163
124
|
function isString(value) {
|
|
164
125
|
return typeof value === 'string';
|
|
165
126
|
}
|
|
166
127
|
TypePredicates.isString = isString;
|
|
167
|
-
})(TypePredicates
|
|
168
|
-
function promisifyAsyncIterable(iterable, joiner) {
|
|
128
|
+
})(TypePredicates || (TypePredicates = {}));
|
|
129
|
+
export function promisifyAsyncIterable(iterable, joiner) {
|
|
169
130
|
return (async () => {
|
|
170
131
|
const chunks = [];
|
|
171
132
|
for await (const chunk of iterable) {
|
|
@@ -174,21 +135,19 @@ function promisifyAsyncIterable(iterable, joiner) {
|
|
|
174
135
|
return joiner(chunks);
|
|
175
136
|
})();
|
|
176
137
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
exports.zip = (0, util_1.promisify)(zlib_1.default.gzip);
|
|
180
|
-
async function parseGzippedJson(buffer) {
|
|
181
|
-
return JSON.parse(bufferToString(await (0, exports.unzip)(buffer)));
|
|
138
|
+
export async function parseGzippedJson(externals, buffer) {
|
|
139
|
+
return JSON.parse(bufferToString(await externals.archive.gunzip(buffer)));
|
|
182
140
|
}
|
|
183
|
-
|
|
184
|
-
|
|
141
|
+
/**
|
|
142
|
+
* @returns Is Plain Old JavaScript Object (POJO).
|
|
143
|
+
*/
|
|
144
|
+
export function isPojo(value) {
|
|
185
145
|
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
186
146
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
const ans = (0, rfdc_1.default)()(a);
|
|
147
|
+
export function merge(a, b) {
|
|
148
|
+
const ans = rfdc()(a);
|
|
190
149
|
for (const [key, value] of Object.entries(b)) {
|
|
191
|
-
if (
|
|
150
|
+
if (isPojo(ans[key]) && isPojo(value)) {
|
|
192
151
|
ans[key] = merge(ans[key], value);
|
|
193
152
|
}
|
|
194
153
|
else if (value === undefined) {
|
|
@@ -200,8 +159,7 @@ function merge(a, b) {
|
|
|
200
159
|
}
|
|
201
160
|
return ans;
|
|
202
161
|
}
|
|
203
|
-
|
|
204
|
-
var Lazy;
|
|
162
|
+
export var Lazy;
|
|
205
163
|
(function (Lazy) {
|
|
206
164
|
const LazyDiscriminator = Symbol('LazyDiscriminator');
|
|
207
165
|
function create(getter) {
|
|
@@ -223,13 +181,13 @@ var Lazy;
|
|
|
223
181
|
return isUnresolved(lazy) ? lazy.value = lazy.getter() : lazy;
|
|
224
182
|
}
|
|
225
183
|
Lazy.resolve = resolve;
|
|
226
|
-
})(Lazy
|
|
184
|
+
})(Lazy || (Lazy = {}));
|
|
227
185
|
/**
|
|
228
186
|
* @param ids An array of block/fluid IDs, with or without the namespace.
|
|
229
187
|
* @returns A map from state names to the corresponding sets of values. The first element in the value array is the default
|
|
230
188
|
* value for that state.
|
|
231
189
|
*/
|
|
232
|
-
function getStates(category, ids, ctx) {
|
|
190
|
+
export function getStates(category, ids, ctx) {
|
|
233
191
|
const ans = {};
|
|
234
192
|
ids = ids.map(ResourceLocation.lengthen);
|
|
235
193
|
for (const id of ids) {
|
|
@@ -237,7 +195,7 @@ function getStates(category, ids, ctx) {
|
|
|
237
195
|
.query(ctx.doc, category, id)
|
|
238
196
|
.forEachMember((state, stateQuery) => {
|
|
239
197
|
const values = Object.keys(stateQuery.visibleMembers);
|
|
240
|
-
const set = ans[state]
|
|
198
|
+
const set = ans[state] ??= new Set();
|
|
241
199
|
const defaultValue = stateQuery.symbol?.relations?.default;
|
|
242
200
|
if (defaultValue) {
|
|
243
201
|
set.add(defaultValue.path[defaultValue.path.length - 1]);
|
|
@@ -249,10 +207,37 @@ function getStates(category, ids, ctx) {
|
|
|
249
207
|
}
|
|
250
208
|
return Object.fromEntries(Object.entries(ans).map(([k, v]) => [k, [...v]]));
|
|
251
209
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
function isIterable(value) {
|
|
210
|
+
export const binarySearch = externalBinarySearch;
|
|
211
|
+
export function isIterable(value) {
|
|
255
212
|
return !!value[Symbol.iterator];
|
|
256
213
|
}
|
|
257
|
-
|
|
214
|
+
//#region ESNext functions polyfill
|
|
215
|
+
export function atArray(array, index) {
|
|
216
|
+
return index >= 0 ? array?.[index] : array?.[array.length + index];
|
|
217
|
+
}
|
|
218
|
+
export function emplaceMap(map, key, handler) {
|
|
219
|
+
if (map.has(key)) {
|
|
220
|
+
let value = map.get(key);
|
|
221
|
+
if (handler.update) {
|
|
222
|
+
value = handler.update(value, key, map);
|
|
223
|
+
map.set(key, value);
|
|
224
|
+
}
|
|
225
|
+
return value;
|
|
226
|
+
}
|
|
227
|
+
else if (handler.insert) {
|
|
228
|
+
const value = handler.insert(key, map);
|
|
229
|
+
map.set(key, value);
|
|
230
|
+
return value;
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
throw new Error(`No key ${key} in map and no insert handler provided`);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
//#endregion
|
|
237
|
+
/**
|
|
238
|
+
* @returns If `val` is an non-null object or a callable object (i.e. function).
|
|
239
|
+
*/
|
|
240
|
+
export function isObject(val) {
|
|
241
|
+
return typeof val === 'function' || (!!val && typeof val === 'object');
|
|
242
|
+
}
|
|
258
243
|
//# sourceMappingURL=util.js.map
|
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from './common';
|
|
2
|
-
export * from './node';
|
|
3
|
-
export * from './parser';
|
|
4
|
-
export * from './processor';
|
|
5
|
-
export * from './service';
|
|
6
|
-
export * from './source';
|
|
7
|
-
export * from './symbol';
|
|
1
|
+
export * from './common/index.js';
|
|
2
|
+
export * from './node/index.js';
|
|
3
|
+
export * from './parser/index.js';
|
|
4
|
+
export * from './processor/index.js';
|
|
5
|
+
export * from './service/index.js';
|
|
6
|
+
export * from './source/index.js';
|
|
7
|
+
export * from './symbol/index.js';
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.js
CHANGED
|
@@ -1,24 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./common"), exports);
|
|
18
|
-
__exportStar(require("./node"), exports);
|
|
19
|
-
__exportStar(require("./parser"), exports);
|
|
20
|
-
__exportStar(require("./processor"), exports);
|
|
21
|
-
__exportStar(require("./service"), exports);
|
|
22
|
-
__exportStar(require("./source"), exports);
|
|
23
|
-
__exportStar(require("./symbol"), exports);
|
|
1
|
+
export * from './common/index.js';
|
|
2
|
+
export * from './node/index.js';
|
|
3
|
+
export * from './parser/index.js';
|
|
4
|
+
export * from './processor/index.js';
|
|
5
|
+
export * from './service/index.js';
|
|
6
|
+
export * from './source/index.js';
|
|
7
|
+
export * from './symbol/index.js';
|
|
24
8
|
//# sourceMappingURL=index.js.map
|
package/lib/node/AstNode.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import type { DeepReadonly } from '../common/index.js';
|
|
2
|
+
import type { Color, FormattableColor } from '../processor/index.js';
|
|
3
|
+
import { Range } from '../source/index.js';
|
|
4
|
+
import type { Symbol, SymbolTable } from '../symbol/index.js';
|
|
4
5
|
export interface AstNode {
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
type: string;
|
|
7
|
+
range: Range;
|
|
7
8
|
/**
|
|
8
9
|
* All child nodes of this AST node.
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
children?: AstNode[];
|
|
12
|
+
parent?: AstNode;
|
|
12
13
|
locals?: SymbolTable;
|
|
13
14
|
symbol?: Symbol;
|
|
14
15
|
hover?: string;
|
|
@@ -23,21 +24,21 @@ export declare namespace AstNode {
|
|
|
23
24
|
/**
|
|
24
25
|
* @param endInclusive Defaults to `false`.
|
|
25
26
|
*/
|
|
26
|
-
export function findChildIndex(node: AstNode
|
|
27
|
+
export function findChildIndex(node: DeepReadonly<AstNode>, needle: number | Range, endInclusive?: boolean): number;
|
|
27
28
|
/**
|
|
28
29
|
* @param endInclusive Defaults to `false`.
|
|
29
30
|
*/
|
|
30
|
-
export function findChild<N extends AstNode
|
|
31
|
+
export function findChild<N extends DeepReadonly<AstNode>>(node: N, needle: number | Range, endInclusive?: boolean): Exclude<N['children'], undefined>[number] | undefined;
|
|
31
32
|
/**
|
|
32
33
|
* Returns the index of the last child node that ends before the `needle`.
|
|
33
34
|
*
|
|
34
35
|
* @param endInclusive Defaults to `false`.
|
|
35
36
|
*/
|
|
36
|
-
export function findLastChildIndex(node: AstNode
|
|
37
|
+
export function findLastChildIndex(node: DeepReadonly<AstNode>, needle: number | Range, endInclusive?: boolean): number;
|
|
37
38
|
/**
|
|
38
39
|
* @param endInclusive Defaults to `false`.
|
|
39
40
|
*/
|
|
40
|
-
export function findLastChild<N extends AstNode
|
|
41
|
+
export function findLastChild<N extends DeepReadonly<AstNode>>(node: N, needle: number | Range, endInclusive?: boolean): (N['children'] extends readonly unknown[] ? N['children'][number] : undefined) | undefined;
|
|
41
42
|
interface FindRecursivelyOptions<P = (node: AstNode) => boolean> {
|
|
42
43
|
node: AstNode;
|
|
43
44
|
needle: number;
|
package/lib/node/AstNode.js
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.AstNode = void 0;
|
|
7
|
-
const binary_search_1 = __importDefault(require("binary-search"));
|
|
8
|
-
const source_1 = require("../source");
|
|
9
|
-
var AstNode;
|
|
1
|
+
import binarySearch from 'binary-search';
|
|
2
|
+
import { Range } from '../source/index.js';
|
|
3
|
+
export var AstNode;
|
|
10
4
|
(function (AstNode) {
|
|
11
5
|
/* istanbul ignore next */
|
|
12
6
|
function is(obj) {
|
|
13
7
|
return !!obj && typeof obj === 'object' && typeof obj.type === 'string' &&
|
|
14
|
-
|
|
8
|
+
Range.is(obj.range);
|
|
15
9
|
}
|
|
16
10
|
AstNode.is = is;
|
|
17
11
|
function setParents(node) {
|
|
@@ -28,8 +22,8 @@ var AstNode;
|
|
|
28
22
|
if (!node.children) {
|
|
29
23
|
return -1;
|
|
30
24
|
}
|
|
31
|
-
const comparator = typeof needle === 'number' ?
|
|
32
|
-
return (
|
|
25
|
+
const comparator = typeof needle === 'number' ? Range.compareOffset : Range.compare;
|
|
26
|
+
return binarySearch(node.children, needle, (a, b) => comparator(a.range, b, endInclusive));
|
|
33
27
|
}
|
|
34
28
|
AstNode.findChildIndex = findChildIndex;
|
|
35
29
|
/**
|
|
@@ -50,7 +44,7 @@ var AstNode;
|
|
|
50
44
|
}
|
|
51
45
|
let ans = -1;
|
|
52
46
|
for (const [i, childNode] of node.children.entries()) {
|
|
53
|
-
if (
|
|
47
|
+
if (Range.endsBefore(childNode.range, needle, endInclusive)) {
|
|
54
48
|
ans = i;
|
|
55
49
|
}
|
|
56
50
|
else {
|
|
@@ -69,7 +63,7 @@ var AstNode;
|
|
|
69
63
|
AstNode.findLastChild = findLastChild;
|
|
70
64
|
function findDeepestChild({ node, needle, endInclusive = false, predicate = () => true }) {
|
|
71
65
|
let last;
|
|
72
|
-
let head =
|
|
66
|
+
let head = Range.contains(node, needle, endInclusive) ? node : undefined;
|
|
73
67
|
while (head && predicate(head)) {
|
|
74
68
|
last = head;
|
|
75
69
|
head = findChild(head, needle, endInclusive);
|
|
@@ -78,7 +72,7 @@ var AstNode;
|
|
|
78
72
|
}
|
|
79
73
|
AstNode.findDeepestChild = findDeepestChild;
|
|
80
74
|
function findShallowestChild({ node, needle, endInclusive = false, predicate = () => true }) {
|
|
81
|
-
let head =
|
|
75
|
+
let head = Range.contains(node, needle, endInclusive) ? node : undefined;
|
|
82
76
|
while (head && !predicate(head)) {
|
|
83
77
|
head = findChild(head, needle, endInclusive);
|
|
84
78
|
}
|
|
@@ -104,5 +98,5 @@ var AstNode;
|
|
|
104
98
|
}
|
|
105
99
|
}
|
|
106
100
|
AstNode.getLocalsToLeaves = getLocalsToLeaves;
|
|
107
|
-
})(AstNode
|
|
101
|
+
})(AstNode || (AstNode = {}));
|
|
108
102
|
//# sourceMappingURL=AstNode.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { RangeLike } from '../source';
|
|
2
|
-
import type { AstNode } from './AstNode';
|
|
1
|
+
import type { RangeLike } from '../source/index.js';
|
|
2
|
+
import type { AstNode } from './AstNode.js';
|
|
3
3
|
export interface BooleanBaseNode extends AstNode {
|
|
4
4
|
readonly value?: boolean;
|
|
5
5
|
}
|
package/lib/node/BooleanNode.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.BooleanNode = void 0;
|
|
4
|
-
const source_1 = require("../source");
|
|
5
|
-
var BooleanNode;
|
|
1
|
+
import { Range } from '../source/index.js';
|
|
2
|
+
export var BooleanNode;
|
|
6
3
|
(function (BooleanNode) {
|
|
7
4
|
/* istanbul ignore next */
|
|
8
5
|
function is(obj) {
|
|
@@ -12,9 +9,9 @@ var BooleanNode;
|
|
|
12
9
|
function mock(range) {
|
|
13
10
|
return {
|
|
14
11
|
type: 'boolean',
|
|
15
|
-
range:
|
|
12
|
+
range: Range.get(range),
|
|
16
13
|
};
|
|
17
14
|
}
|
|
18
15
|
BooleanNode.mock = mock;
|
|
19
|
-
})(BooleanNode
|
|
16
|
+
})(BooleanNode || (BooleanNode = {}));
|
|
20
17
|
//# sourceMappingURL=BooleanNode.js.map
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DeepReadonly } from '../common/index.js';
|
|
2
|
+
import type { AstNode } from './AstNode.js';
|
|
2
3
|
export interface CommentNode extends AstNode {
|
|
3
4
|
readonly type: 'comment';
|
|
4
5
|
/**
|
|
5
6
|
* The actual comment with prefixes and suffixes removed.
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
export declare namespace CommentNode {
|
|
10
|
-
function is(obj: AstNode | undefined): obj is CommentNode;
|
|
8
|
+
comment: string;
|
|
11
9
|
}
|
|
10
|
+
export declare const CommentNode: Readonly<{
|
|
11
|
+
is<T extends DeepReadonly<AstNode> | undefined>(obj: T): obj is import("../common/util.js").IsHelper<AstNode, CommentNode, T>;
|
|
12
|
+
}>;
|
|
12
13
|
//# sourceMappingURL=CommentNode.d.ts.map
|
package/lib/node/CommentNode.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.CommentNode = void 0;
|
|
4
|
-
var CommentNode;
|
|
5
|
-
(function (CommentNode) {
|
|
6
|
-
function is(obj) {
|
|
1
|
+
export const CommentNode = Object.freeze({
|
|
2
|
+
is(obj) {
|
|
7
3
|
return obj?.type === 'comment';
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
})(CommentNode = exports.CommentNode || (exports.CommentNode = {}));
|
|
4
|
+
},
|
|
5
|
+
});
|
|
11
6
|
//# sourceMappingURL=CommentNode.js.map
|
package/lib/node/ErrorNode.d.ts
CHANGED
package/lib/node/ErrorNode.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ErrorNode = void 0;
|
|
4
|
-
var ErrorNode;
|
|
1
|
+
export var ErrorNode;
|
|
5
2
|
(function (ErrorNode) {
|
|
6
3
|
/* istanbul ignore next */
|
|
7
4
|
function is(obj) {
|
|
8
5
|
return obj.type === 'error';
|
|
9
6
|
}
|
|
10
7
|
ErrorNode.is = is;
|
|
11
|
-
})(ErrorNode
|
|
8
|
+
})(ErrorNode || (ErrorNode = {}));
|
|
12
9
|
//# sourceMappingURL=ErrorNode.js.map
|
package/lib/node/FileNode.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import type { AstNode } from '../node';
|
|
2
|
-
import type { LanguageError } from '../source';
|
|
3
|
-
import type { SymbolTable } from '../symbol';
|
|
1
|
+
import type { AstNode } from '../node/index.js';
|
|
2
|
+
import type { LanguageError } from '../source/index.js';
|
|
3
|
+
import type { SymbolTable } from '../symbol/index.js';
|
|
4
4
|
export interface FileNode<CN extends AstNode> extends AstNode {
|
|
5
5
|
readonly type: 'file';
|
|
6
6
|
readonly children: CN[];
|
|
7
7
|
locals: SymbolTable;
|
|
8
|
-
|
|
8
|
+
parserErrors: readonly LanguageError[];
|
|
9
|
+
/**
|
|
10
|
+
* Only exists when the file has been bound.
|
|
11
|
+
*/
|
|
12
|
+
binderErrors?: readonly LanguageError[];
|
|
9
13
|
/**
|
|
10
14
|
* Only exists when the file has been checked.
|
|
11
15
|
*/
|
package/lib/node/FileNode.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FileNode = void 0;
|
|
4
|
-
var FileNode;
|
|
1
|
+
export var FileNode;
|
|
5
2
|
(function (FileNode) {
|
|
6
3
|
function getErrors(node) {
|
|
7
|
-
return [...node.parserErrors, ...node.checkerErrors ?? [], ...node.linterErrors ?? []];
|
|
4
|
+
return [...node.parserErrors, ...node.binderErrors ?? [], ...node.checkerErrors ?? [], ...node.linterErrors ?? []];
|
|
8
5
|
}
|
|
9
6
|
FileNode.getErrors = getErrors;
|
|
10
|
-
})(FileNode
|
|
7
|
+
})(FileNode || (FileNode = {}));
|
|
11
8
|
//# sourceMappingURL=FileNode.js.map
|
package/lib/node/FloatNode.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { RangeLike } from '../source';
|
|
2
|
-
import type { AstNode } from './AstNode';
|
|
1
|
+
import type { RangeLike } from '../source/index.js';
|
|
2
|
+
import type { AstNode } from './AstNode.js';
|
|
3
3
|
export interface FloatBaseNode extends AstNode {
|
|
4
|
-
|
|
4
|
+
value: number;
|
|
5
5
|
}
|
|
6
6
|
export interface FloatNode extends FloatBaseNode {
|
|
7
7
|
readonly type: 'float';
|
package/lib/node/FloatNode.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.FloatNode = void 0;
|
|
4
|
-
const source_1 = require("../source");
|
|
5
|
-
var FloatNode;
|
|
1
|
+
import { Range } from '../source/index.js';
|
|
2
|
+
export var FloatNode;
|
|
6
3
|
(function (FloatNode) {
|
|
7
4
|
/* istanbul ignore next */
|
|
8
5
|
function is(obj) {
|
|
@@ -12,10 +9,10 @@ var FloatNode;
|
|
|
12
9
|
function mock(range) {
|
|
13
10
|
return {
|
|
14
11
|
type: 'float',
|
|
15
|
-
range:
|
|
12
|
+
range: Range.get(range),
|
|
16
13
|
value: 0,
|
|
17
14
|
};
|
|
18
15
|
}
|
|
19
16
|
FloatNode.mock = mock;
|
|
20
|
-
})(FloatNode
|
|
17
|
+
})(FloatNode || (FloatNode = {}));
|
|
21
18
|
//# sourceMappingURL=FloatNode.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { RangeLike } from '../source';
|
|
2
|
-
import type { AstNode } from './AstNode';
|
|
1
|
+
import type { RangeLike } from '../source/index.js';
|
|
2
|
+
import type { AstNode } from './AstNode.js';
|
|
3
3
|
export interface IntegerBaseNode extends AstNode {
|
|
4
|
-
|
|
4
|
+
value: number;
|
|
5
5
|
}
|
|
6
6
|
export interface IntegerNode extends IntegerBaseNode {
|
|
7
7
|
readonly type: 'integer';
|
package/lib/node/IntegerNode.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.IntegerNode = void 0;
|
|
4
|
-
const source_1 = require("../source");
|
|
5
|
-
var IntegerNode;
|
|
1
|
+
import { Range } from '../source/index.js';
|
|
2
|
+
export var IntegerNode;
|
|
6
3
|
(function (IntegerNode) {
|
|
7
4
|
function is(obj) {
|
|
8
5
|
return obj.type === 'integer';
|
|
@@ -11,10 +8,10 @@ var IntegerNode;
|
|
|
11
8
|
function mock(range) {
|
|
12
9
|
return {
|
|
13
10
|
type: 'integer',
|
|
14
|
-
range:
|
|
11
|
+
range: Range.get(range),
|
|
15
12
|
value: 0,
|
|
16
13
|
};
|
|
17
14
|
}
|
|
18
15
|
IntegerNode.mock = mock;
|
|
19
|
-
})(IntegerNode
|
|
16
|
+
})(IntegerNode || (IntegerNode = {}));
|
|
20
17
|
//# sourceMappingURL=IntegerNode.js.map
|
package/lib/node/ListNode.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Range } from '../source';
|
|
2
|
-
import type { AstNode } from './AstNode';
|
|
1
|
+
import type { Range } from '../source/index.js';
|
|
2
|
+
import type { AstNode } from './AstNode.js';
|
|
3
3
|
export interface ListNode<V extends AstNode> extends AstNode {
|
|
4
4
|
readonly children: ItemNode<V>[];
|
|
5
5
|
}
|