@mirascript/typed 0.1.63 → 0.1.65

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.
@@ -0,0 +1,274 @@
1
+ const DEFAULT_OPTIONS = {
2
+ flattenUnions: true,
3
+ flattenIntersections: true,
4
+ deduplicateUnions: true,
5
+ deduplicateIntersections: true,
6
+ unwrapSingleUnion: true,
7
+ unwrapSingleIntersection: true,
8
+ distributeIntersectionsOverUnions: true,
9
+ mergeRecordIntersections: true,
10
+ expandTupleSpreads: true,
11
+ };
12
+ /** Fills in default simplification options. */
13
+ function normalizeOptions(options) {
14
+ return { ...DEFAULT_OPTIONS, ...options };
15
+ }
16
+ /** Checks whether a type is represented by an object node. */
17
+ function isTypeObject(type) {
18
+ return typeof type === 'object';
19
+ }
20
+ /** Checks whether a record type uses the explicit fields form. */
21
+ function isFieldRecordType(type) {
22
+ return isTypeObject(type) && type.kind === 'record' && 'fields' in type;
23
+ }
24
+ /** Builds a stable key for type-level deduplication within one simplify call. */
25
+ function getTypeDedupKey(type, symbols) {
26
+ if (typeof type === 'string')
27
+ return `string:${type}`;
28
+ if (typeof type === 'symbol') {
29
+ const existing = symbols.get(type);
30
+ if (existing != null)
31
+ return `symbol:${existing}`;
32
+ const next = symbols.size + 1;
33
+ symbols.set(type, next);
34
+ return `symbol:${next}`;
35
+ }
36
+ switch (type.kind) {
37
+ case 'array':
38
+ return `array:${getTypeDedupKey(type.element, symbols)}`;
39
+ case 'union':
40
+ return `union:[${type.types.map((t) => getTypeDedupKey(t, symbols)).join(',')}]`;
41
+ case 'intersection':
42
+ return `intersection:[${type.types.map((t) => getTypeDedupKey(t, symbols)).join(',')}]`;
43
+ case 'record':
44
+ if ('fields' in type) {
45
+ return `recordFields:[${type.fields
46
+ .map((f) => `${f.name}:${String(Boolean(f.optional))}:${getTypeDedupKey(f.type, symbols)}`)
47
+ .join(',')}]`;
48
+ }
49
+ return `recordKV:${type.key == null ? 'none' : getTypeDedupKey(type.key, symbols)}:${getTypeDedupKey(type.value, symbols)}`;
50
+ case 'literal':
51
+ return `literal:${typeof type.value}:${String(type.value)}`;
52
+ case 'template':
53
+ return `template:[${type.parts.map((p) => getTypeDedupKey(p, symbols)).join(',')}]`;
54
+ case 'function':
55
+ return `function:${type.name ?? ''}:<${(type.typeParams ?? []).map((p) => getTypeDedupKey(p, symbols)).join(',')}>(${type.params
56
+ .map((p) => `${p.name}:${String(Boolean(p.spread))}:${getTypeDedupKey(p.type, symbols)}`)
57
+ .join(',')})=>${type.returns == null ? 'void' : getTypeDedupKey(type.returns, symbols)}`;
58
+ case 'tuple':
59
+ return `tuple:[${type.elements
60
+ .map((e) => `${String(Boolean(e.spread))}:${getTypeDedupKey(e.type, symbols)}`)
61
+ .join(',')}]`;
62
+ case 'reflection':
63
+ return `reflection:${type.name}`;
64
+ default:
65
+ return 'unknown';
66
+ }
67
+ }
68
+ /** Removes duplicate members from union/intersection type member lists. */
69
+ function deduplicateTypeMembers(types) {
70
+ const symbols = new Map();
71
+ const seen = new Set();
72
+ const result = [];
73
+ for (const type of types) {
74
+ const key = getTypeDedupKey(type, symbols);
75
+ if (seen.has(key))
76
+ continue;
77
+ seen.add(key);
78
+ result.push(type);
79
+ }
80
+ return result;
81
+ }
82
+ /** Flattens nested union nodes when the corresponding option is enabled. */
83
+ function flattenUnionTypes(types, options) {
84
+ if (!options.flattenUnions)
85
+ return types;
86
+ const result = [];
87
+ for (const type of types) {
88
+ if (isTypeObject(type) && type.kind === 'union') {
89
+ result.push(...flattenUnionTypes(type.types, options));
90
+ }
91
+ else {
92
+ result.push(type);
93
+ }
94
+ }
95
+ return result;
96
+ }
97
+ /** Flattens nested intersection nodes when the corresponding option is enabled. */
98
+ function flattenIntersectionTypes(types, options) {
99
+ if (!options.flattenIntersections)
100
+ return types;
101
+ const result = [];
102
+ for (const type of types) {
103
+ if (isTypeObject(type) && type.kind === 'intersection') {
104
+ result.push(...flattenIntersectionTypes(type.types, options));
105
+ }
106
+ else {
107
+ result.push(type);
108
+ }
109
+ }
110
+ return result;
111
+ }
112
+ /** Simplifies a record field recursively. */
113
+ function simplifyRecordField(field, options) {
114
+ return {
115
+ ...field,
116
+ type: simplifyImpl(field.type, options),
117
+ };
118
+ }
119
+ /** Merges explicit record fields across an intersection. */
120
+ function mergeRecordFieldIntersections(types) {
121
+ const merged = new Map();
122
+ for (const record of types) {
123
+ for (const field of record.fields) {
124
+ const prev = merged.get(field.name);
125
+ if (prev == null) {
126
+ merged.set(field.name, {
127
+ optional: field.optional ?? false,
128
+ type: field.type,
129
+ });
130
+ continue;
131
+ }
132
+ merged.set(field.name, {
133
+ optional: (prev.optional ?? false) && (field.optional ?? false),
134
+ type: {
135
+ kind: 'intersection',
136
+ types: [prev.type, field.type],
137
+ },
138
+ });
139
+ }
140
+ }
141
+ return {
142
+ kind: 'record',
143
+ fields: Array.from(merged.entries()).map(([name, field]) => ({
144
+ name,
145
+ optional: field.optional,
146
+ type: field.type,
147
+ })),
148
+ };
149
+ }
150
+ /** Distributes intersections over unions using a cartesian product. */
151
+ function distributeIntersectionsOverUnions(types, options) {
152
+ let combinations = [[]];
153
+ for (const type of types) {
154
+ const choices = isTypeObject(type) && type.kind === 'union' ? type.types : [type];
155
+ const next = [];
156
+ for (const combo of combinations) {
157
+ for (const choice of choices) {
158
+ next.push([...combo, choice]);
159
+ }
160
+ }
161
+ combinations = next;
162
+ }
163
+ const branches = combinations.map((combo) => simplifyImpl({ kind: 'intersection', types: combo }, {
164
+ ...options,
165
+ distributeIntersectionsOverUnions: false,
166
+ }));
167
+ if (branches.length === 1)
168
+ return branches[0];
169
+ return { kind: 'union', types: branches };
170
+ }
171
+ /** Simplifies a Type AST in place, optionally disabling individual normalization passes. */
172
+ function simplifyImpl(type, config) {
173
+ if (typeof type === 'symbol' || typeof type === 'string') {
174
+ return type;
175
+ }
176
+ if (type.kind === 'array') {
177
+ type.element = simplifyImpl(type.element, config);
178
+ return type;
179
+ }
180
+ if (type.kind === 'function') {
181
+ for (const param of type.params) {
182
+ param.type = simplifyImpl(param.type, config);
183
+ }
184
+ if (type.returns != null)
185
+ type.returns = simplifyImpl(type.returns, config);
186
+ return type;
187
+ }
188
+ if (type.kind === 'literal') {
189
+ return type;
190
+ }
191
+ if (type.kind === 'template') {
192
+ type.parts = type.parts.map((part) => simplifyImpl(part, config));
193
+ return type;
194
+ }
195
+ if (type.kind === 'tuple') {
196
+ type.elements = type.elements.flatMap((element) => {
197
+ const simplifiedType = simplifyImpl(element.type, config);
198
+ if (config.expandTupleSpreads &&
199
+ element.spread &&
200
+ typeof simplifiedType === 'object' &&
201
+ simplifiedType.kind === 'tuple') {
202
+ // Inline tuple spread: ..[A, B] → A, B
203
+ return simplifiedType.elements;
204
+ }
205
+ return [{ ...element, type: simplifiedType }];
206
+ });
207
+ return type;
208
+ }
209
+ if (type.kind === 'reflection') {
210
+ return type;
211
+ }
212
+ if (type.kind === 'record') {
213
+ if ('fields' in type) {
214
+ type.fields = type.fields.map((field) => simplifyRecordField(field, config));
215
+ }
216
+ else {
217
+ if (type.key != null)
218
+ type.key = simplifyImpl(type.key, config);
219
+ type.value = simplifyImpl(type.value, config);
220
+ }
221
+ return type;
222
+ }
223
+ if (type.kind === 'union') {
224
+ let simplifiedTypes = flattenUnionTypes(type.types.map((item) => simplifyImpl(item, config)), config);
225
+ if (config.deduplicateUnions) {
226
+ simplifiedTypes = deduplicateTypeMembers(simplifiedTypes);
227
+ }
228
+ if (config.unwrapSingleUnion && simplifiedTypes.length === 1) {
229
+ return simplifiedTypes[0];
230
+ }
231
+ type.types = simplifiedTypes;
232
+ return type;
233
+ }
234
+ if (type.kind === 'intersection') {
235
+ let simplifiedTypes = flattenIntersectionTypes(type.types.map((item) => simplifyImpl(item, config)), config);
236
+ if (config.deduplicateIntersections) {
237
+ simplifiedTypes = deduplicateTypeMembers(simplifiedTypes);
238
+ }
239
+ if (config.distributeIntersectionsOverUnions &&
240
+ simplifiedTypes.some((item) => isTypeObject(item) && item.kind === 'union')) {
241
+ return distributeIntersectionsOverUnions(simplifiedTypes, config);
242
+ }
243
+ if (config.mergeRecordIntersections) {
244
+ const recordTypes = simplifiedTypes.filter(isFieldRecordType);
245
+ if (recordTypes.length >= 2) {
246
+ const nonRecordTypes = simplifiedTypes.filter((item) => !isFieldRecordType(item));
247
+ const mergedRecord = simplifyImpl(mergeRecordFieldIntersections(recordTypes), config);
248
+ let mergedTypes = [mergedRecord, ...nonRecordTypes];
249
+ if (config.deduplicateIntersections) {
250
+ mergedTypes = deduplicateTypeMembers(mergedTypes);
251
+ }
252
+ if (config.unwrapSingleIntersection && mergedTypes.length === 1) {
253
+ return mergedTypes[0];
254
+ }
255
+ type.types = mergedTypes;
256
+ return type;
257
+ }
258
+ }
259
+ if (config.unwrapSingleIntersection && simplifiedTypes.length === 1) {
260
+ return simplifiedTypes[0];
261
+ }
262
+ type.types = simplifiedTypes;
263
+ return type;
264
+ }
265
+ /* c8 ignore next 3 */
266
+ (type);
267
+ return type;
268
+ }
269
+ /** Simplifies a Type AST in place, optionally disabling individual normalization passes. */
270
+ export function simplify(type, options) {
271
+ const config = normalizeOptions(options);
272
+ return simplifyImpl(type, config);
273
+ }
274
+ //# sourceMappingURL=simplifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simplifier.js","sourceRoot":"","sources":["../src/simplifier.ts"],"names":[],"mappings":"AAwBA,MAAM,eAAe,GAA8B;IAC/C,aAAa,EAAE,IAAI;IACnB,oBAAoB,EAAE,IAAI;IAC1B,iBAAiB,EAAE,IAAI;IACvB,wBAAwB,EAAE,IAAI;IAC9B,iBAAiB,EAAE,IAAI;IACvB,wBAAwB,EAAE,IAAI;IAC9B,iCAAiC,EAAE,IAAI;IACvC,wBAAwB,EAAE,IAAI;IAC9B,kBAAkB,EAAE,IAAI;CAC3B,CAAC;AAEF,+CAA+C;AAC/C,SAAS,gBAAgB,CAAC,OAAyB;IAC/C,OAAO,EAAE,GAAG,eAAe,EAAE,GAAG,OAAO,EAAE,CA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AK,GAAG,WAAW,CAAC;gBACzB,OAAO,IAAI,CAAC;YAChB,CAAC;QACL,CAAC;QACD,IAAI,MAAM,CAAC,wBAAwB,IAAI,eAAe,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAClE,OAAO,eAAe,CAAC,CAAC,CAAE,CAAC;QAC/B,CAAC;QACD,IAAI,CAAC,KAAK,GAAG,eAAe,CAAC;QAC7B,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,sBAAsB;IACtB,CAAC,IAAI,CAAiB,CAAC;IACvB,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,4FAA4F;AAC5F,MAAM,UAAU,QAAQ,CAAC,IAAU,EAAE,OAAyB;IAC1D,MAAM,MAAM,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACzC,OAAO,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACtC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { Type } from './parser.js';
2
+ /**
3
+ * Converts a Type AST back into a MiraScript type string.
4
+ * The output is guaranteed to be parseable by {@link parse}.
5
+ */
6
+ export declare function stringify(type: Type): string;
7
+ //# sourceMappingURL=stringify.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stringify.d.ts","sourceRoot":"","sources":["../src/stringify.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAuLxC;;;GAGG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAE5C"}
@@ -0,0 +1,186 @@
1
+ import { REG_IDENTIFIER_FULL } from '@mirascript/constants';
2
+ /** Precedence levels for parenthesization. */
3
+ const PREC_UNION = 1;
4
+ const PREC_INTERSECTION = 2;
5
+ /** Escape a string literal value for use in double-quoted strings. */
6
+ function escapeString(value) {
7
+ return value
8
+ .replaceAll('\\', '\\\\')
9
+ .replaceAll('"', String.raw `\"`)
10
+ .replaceAll('\n', String.raw `\n`)
11
+ .replaceAll('\r', String.raw `\r`)
12
+ .replaceAll('\t', String.raw `\t`)
13
+ .replaceAll('$', String.raw `\$`);
14
+ }
15
+ /**
16
+ * Returns the precedence level of a type node.
17
+ * Higher number = tighter binding.
18
+ */
19
+ function getPrecedence(type) {
20
+ if (typeof type === 'string' || typeof type === 'symbol')
21
+ return 0;
22
+ if (type.kind === 'union')
23
+ return PREC_UNION;
24
+ if (type.kind === 'intersection')
25
+ return PREC_INTERSECTION;
26
+ return 0;
27
+ }
28
+ /**
29
+ * Stringify a type, adding parentheses if the child's precedence
30
+ * is lower than the parent's required precedence.
31
+ */
32
+ function stringifyImpl(type, parentPrecedence) {
33
+ // ---- primitives ----
34
+ if (typeof type === 'symbol') {
35
+ return type.description ?? '';
36
+ }
37
+ if (typeof type === 'string') {
38
+ return type;
39
+ }
40
+ // ---- compound types ----
41
+ let result;
42
+ switch (type.kind) {
43
+ case 'literal': {
44
+ if (typeof type.value === 'boolean') {
45
+ return String(type.value);
46
+ }
47
+ else {
48
+ return `"${escapeString(type.value)}"`;
49
+ }
50
+ }
51
+ case 'template': {
52
+ let tpl = '`';
53
+ for (const part of type.parts) {
54
+ if (typeof part === 'object' && part.kind === 'literal' && typeof part.value === 'string') {
55
+ tpl += part.value.replaceAll('`', '\\`').replaceAll('$', String.raw `\$`);
56
+ }
57
+ else {
58
+ tpl += `$(${stringifyImpl(part, 0)})`;
59
+ }
60
+ }
61
+ tpl += '`';
62
+ return tpl;
63
+ }
64
+ case 'array': {
65
+ const inner = stringifyImpl(type.element, 0);
66
+ // Use postfix notation for simple types, generic for complex
67
+ if (typeof type.element === 'string' || typeof type.element === 'symbol') {
68
+ result = `${inner}[]`;
69
+ }
70
+ else if (type.element.kind === 'literal' || type.element.kind === 'reflection') {
71
+ result = `${inner}[]`;
72
+ }
73
+ else {
74
+ return `array<${inner}>`;
75
+ }
76
+ break;
77
+ }
78
+ case 'union': {
79
+ const parts = type.types.map((t) => stringifyImpl(t, PREC_UNION));
80
+ result = parts.join(' | ');
81
+ if (parentPrecedence > PREC_UNION)
82
+ return `(${result})`;
83
+ return result;
84
+ }
85
+ case 'intersection': {
86
+ const parts = type.types.map((t) => stringifyImpl(t, PREC_INTERSECTION));
87
+ result = parts.join(' & ');
88
+ if (parentPrecedence > PREC_INTERSECTION)
89
+ return `(${result})`;
90
+ return result;
91
+ }
92
+ case 'record': {
93
+ if ('fields' in type) {
94
+ if (type.fields.length === 0) {
95
+ return '()';
96
+ }
97
+ // Check if all fields are anonymous (name === positional index)
98
+ const allAnonymous = type.fields.every((f, i) => f.name === String(i) && !f.optional);
99
+ if (allAnonymous) {
100
+ const types = type.fields.map((f) => stringifyImpl(f.type, 0));
101
+ // Single anonymous field needs trailing comma to distinguish from grouping
102
+ const trailing = type.fields.length === 1 ? ',' : '';
103
+ return `(${types.join(', ')}${trailing})`;
104
+ }
105
+ else {
106
+ const fields = type.fields.map((f) => {
107
+ const name = REG_IDENTIFIER_FULL.test(f.name) ? f.name : `"${escapeString(f.name)}"`;
108
+ const colon = f.optional ? '?:' : ':';
109
+ const typeStr = stringifyImpl(f.type, 0);
110
+ return `${name}${colon} ${typeStr}`;
111
+ });
112
+ return `(${fields.join(', ')})`;
113
+ }
114
+ }
115
+ // Generic record
116
+ if (type.key == null) {
117
+ return `record<${stringifyImpl(type.value, 0)}>`;
118
+ }
119
+ else {
120
+ return `record<${stringifyImpl(type.key, 0)}, ${stringifyImpl(type.value, 0)}>`;
121
+ }
122
+ }
123
+ case 'function': {
124
+ let fn = 'fn';
125
+ if (type.name != null)
126
+ fn += ` ${type.name}`;
127
+ if (type.typeParams != null && type.typeParams.length > 0) {
128
+ fn += `<${type.typeParams.map((t) => stringifyImpl(t, 0)).join(', ')}>`;
129
+ }
130
+ const params = type.params.map((p) => {
131
+ const spread = p.spread ? '..' : '';
132
+ const name = p.name || (p.spread ? '' : '_');
133
+ const typeStr = p.type === 'any' && !p.spread ? '' : `: ${stringifyImpl(p.type, 0)}`;
134
+ return `${spread}${name}${typeStr}`;
135
+ });
136
+ fn += `(${params.join(', ')})`;
137
+ if (type.returns != null) {
138
+ const ret = stringifyImpl(type.returns, 0);
139
+ const needsParens = typeof type.returns === 'object' &&
140
+ (type.returns.kind === 'union' || type.returns.kind === 'intersection');
141
+ fn += ` -> ${needsParens ? `(${ret})` : ret}`;
142
+ }
143
+ result = fn;
144
+ // Function types need parens inside union / intersection
145
+ if (parentPrecedence > 0)
146
+ return `(${result})`;
147
+ return result;
148
+ }
149
+ case 'tuple': {
150
+ if (type.elements.length === 0) {
151
+ result = '[]';
152
+ }
153
+ else {
154
+ const elements = type.elements.map((e) => {
155
+ const spread = e.spread ? '..' : '';
156
+ return `${spread}${stringifyImpl(e.type, 0)}`;
157
+ });
158
+ result = `[${elements.join(', ')}]`;
159
+ }
160
+ break;
161
+ }
162
+ case 'reflection': {
163
+ result = `type(${type.name})`;
164
+ break;
165
+ }
166
+ /* c8 ignore next 3 */
167
+ default:
168
+ (type);
169
+ return 'unknown';
170
+ }
171
+ // Wrap in parens if needed (for non-union/intersection types that
172
+ // appear inside higher-precedence context, e.g. function in union)
173
+ const childPrec = getPrecedence(type);
174
+ if (parentPrecedence > childPrec) {
175
+ return `(${result})`;
176
+ }
177
+ return result;
178
+ }
179
+ /**
180
+ * Converts a Type AST back into a MiraScript type string.
181
+ * The output is guaranteed to be parseable by {@link parse}.
182
+ */
183
+ export function stringify(type) {
184
+ return stringifyImpl(type, 0);
185
+ }
186
+ //# sourceMappingURL=stringify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stringify.js","sourceRoot":"","sources":["../src/stringify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAG5D,8CAA8C;AAC9C,MAAM,UAAU,GAAG,CAAC,CAAC;AACrB,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAE5B,sEAAsE;AACtE,SAAS,YAAY,CAAC,KAAa;IAC/B,OAAO,KAAK;SACP,UAAU,CAAC,IAAI,EAAE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