@mintplayer/polyglot-target-typescript 0.10.1 → 0.10.2

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/polyglot-plugin.json +436 -178
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mintplayer/polyglot-target-typescript",
3
- "version": "0.10.1",
3
+ "version": "0.10.2",
4
4
  "description": "MintPlayer Polyglot TypeScript / JavaScript target — a pure-JSON language plugin (spec + emission rules + capabilities + std bindings) for the polyglot transpiler.",
5
5
  "keywords": [
6
6
  "polyglot",
@@ -1,5 +1,5 @@
1
1
  {
2
- "schema": 1,
2
+ "schema": 2,
3
3
  "name": "typescript",
4
4
  "crossDirImports": true,
5
5
  "preludePerFile": true,
@@ -84,11 +84,24 @@
84
84
  "void"
85
85
  ],
86
86
  "globals": [
87
- "console"
88
- ]
87
+ "console", "globalThis", "Math", "Number", "String", "BigInt", "Array", "JSON", "Promise"
88
+ ],
89
+ "classNames": {
90
+ "Object": "TS2725: a class named 'Object' is a compile error under --module nodenext (a field, local or enum of that name is fine)"
91
+ }
89
92
  },
90
93
  "rethrow": "throw __e;",
94
+ "preludes": {
95
+ "unionEq": "function __pgUnionEq(a: unknown, b: unknown): boolean {\n // a union value (a tagged object literal) compared as C# compares its generated case records (review r5): the\n // same case with equal payloads, a record payload by its equals(), a nested union recursively, anything else (a\n // class instance, a list) by reference. (Comparing serialized text matched class payloads by content and threw on a bigint.)\n if (a === b) {\n return true;\n }\n if (typeof a === \"number\" && typeof b === \"number\") {\n return a !== a && b !== b;\n }\n if (typeof a !== \"object\" || typeof b !== \"object\" || a === null || b === null) {\n return false;\n }\n const proto = globalThis.Object.getPrototypeOf(a);\n if (proto !== globalThis.Object.getPrototypeOf(b)) {\n return false;\n }\n if (proto === globalThis.Object.prototype) {\n const ra = a as { [k: string]: unknown }, rb = b as { [k: string]: unknown };\n const ka = globalThis.Object.keys(ra);\n if (ka.length !== globalThis.Object.keys(rb).length) {\n return false;\n }\n for (const k of ka) {\n if (!(k in rb) || !__pgUnionEq(ra[k], rb[k])) {\n return false;\n }\n }\n return true;\n }\n const eq = (a as { equals?: unknown }).equals;\n return typeof eq === \"function\" && (eq as (o: unknown) => boolean).call(a, b);\n}\n",
96
+ "nullAssert": "function __pgNullAssert(at: string): never {\n throw new globalThis.TypeError(\"null-assert failed (\" + at + \")\");\n}\n"
97
+ },
91
98
  "tables": {
99
+ "baseRootMembers": {
100
+ "Error.cause": "true",
101
+ "Error.message": "true",
102
+ "Error.name": "true",
103
+ "Error.stack": "true"
104
+ },
92
105
  "opMethod": {
93
106
  "+": "plus",
94
107
  "-": "minus",
@@ -116,6 +129,9 @@
116
129
  "mutable": "let $x: $T",
117
130
  "const": "const $x: $T"
118
131
  },
132
+ "localNullInit": {
133
+ "typed": "$x as $T"
134
+ },
119
135
  "yield": {
120
136
  "value": "yield $x;",
121
137
  "empty": "return;"
@@ -129,11 +145,43 @@
129
145
  "u32": "BigInt.asUintN(32, $x)"
130
146
  }
131
147
  },
132
- "escapes": {
148
+ "literals": {
149
+ "string": {
150
+ "quote": "\"",
151
+ "map": {
152
+ "\\": "\\\\",
153
+ "\"": "\\\"",
154
+ "\n": "\\n",
155
+ "\t": "\\t",
156
+ "\r": "\\r"
157
+ },
158
+ "codepoint": "\\u{$H}",
159
+ "astral": "\\u{$H}"
160
+ },
133
161
  "interp": {
134
- "`": "\\`",
135
- "\\": "\\\\",
136
- "${": "\\${"
162
+ "quote": "`",
163
+ "map": {
164
+ "\\": "\\\\",
165
+ "`": "\\`",
166
+ "\n": "\\n",
167
+ "\t": "\\t",
168
+ "\r": "\\r",
169
+ "${": "\\${"
170
+ },
171
+ "codepoint": "\\u{$H}",
172
+ "astral": "\\u{$H}"
173
+ },
174
+ "char": {
175
+ "quote": "\"",
176
+ "map": {
177
+ "\\": "\\\\",
178
+ "\"": "\\\"",
179
+ "\n": "\\n",
180
+ "\t": "\\t",
181
+ "\r": "\\r"
182
+ },
183
+ "codepoint": "\\u{$H}",
184
+ "astral": "\\u{$H}"
137
185
  }
138
186
  },
139
187
  "wrapInt": {
@@ -146,13 +194,31 @@
146
194
  "i64": "BigInt.asIntN(64, $x)",
147
195
  "u64": "BigInt.asUintN(64, $x)"
148
196
  },
197
+ "absentNormalize": { "prefix": "(", "suffix": " ?? null)", "foldedBy": ["coalesce", "nullAssert", "nullSafe"] },
198
+ "nativeCoalesceAssign": true,
199
+ "typeOnlyImports": ["union", "interface"],
200
+ "unboundImports": ["unionCase"],
201
+ "assignmentOrder": "targetFirst",
202
+ "exprStmt": { "parenIfStarts": ["{"] },
149
203
  "wrapAtom": {
150
- "recv": [
151
- "unary",
152
- "binaryScalar"
153
- ],
154
- "unary": [
155
- "binary"
204
+ "recvPrimary": [
205
+ "var",
206
+ "this",
207
+ "call",
208
+ "methodCall",
209
+ "member",
210
+ "index",
211
+ "str",
212
+ "char",
213
+ "bool",
214
+ "null",
215
+ "extern",
216
+ "nullAssert",
217
+ "listLit",
218
+ "tuple",
219
+ "interp",
220
+ "new",
221
+ "makeCase"
156
222
  ]
157
223
  },
158
224
  "generics": {
@@ -160,7 +226,8 @@
160
226
  "boundsIntro": " extends ",
161
227
  "boundsSep": " & ",
162
228
  "erase": [
163
- "INumber"
229
+ "INumber",
230
+ "IMapKey"
164
231
  ]
165
232
  }
166
233
  },
@@ -181,7 +248,7 @@
181
248
  ]
182
249
  },
183
250
  "Float": {
184
- "get": "node.text"
251
+ "get": "node.widenedText"
185
252
  },
186
253
  "Bool": {
187
254
  "case": {
@@ -207,16 +274,18 @@
207
274
  "get": "spec.nullLit"
208
275
  },
209
276
  "Str": {
210
- "fn": "escapeString",
277
+ "fn": "quoted",
211
278
  "args": [
279
+ "string",
212
280
  {
213
281
  "get": "node.value"
214
282
  }
215
283
  ]
216
284
  },
217
285
  "Char": {
218
- "fn": "escapeString",
286
+ "fn": "quoted",
219
287
  "args": [
288
+ "char",
220
289
  {
221
290
  "get": "node.value"
222
291
  }
@@ -269,22 +338,32 @@
269
338
  ]
270
339
  },
271
340
  "Call": {
272
- "tmpl": [
273
- {
274
- "fn": "ident",
275
- "args": [
341
+ "case": {
342
+ "when": [
343
+ [
344
+ { "has": "node.hasCalleeExpr" },
345
+ { "tmpl": [ { "emitChild": "node.calleeExpr", "side": "recv" }, "(", { "map": "node.args", "sep": ", " }, ")" ] }
346
+ ]
347
+ ],
348
+ "else": {
349
+ "tmpl": [
276
350
  {
277
- "get": "node.mangledCallee"
351
+ "fn": "ident",
352
+ "args": [
353
+ {
354
+ "get": "node.mangledCallee"
355
+ }
356
+ ]
357
+ },
358
+ {
359
+ "case": {
360
+ "when": [[ { "eq": ["node.isRef", "true"] }, "" ]],
361
+ "else": { "tmpl": [ { "call": "typeArgsSuffix" }, "(", { "map": "node.args", "sep": ", " }, ")" ] }
362
+ }
278
363
  }
279
364
  ]
280
- },
281
- "(",
282
- {
283
- "map": "node.args",
284
- "sep": ", "
285
- },
286
- ")"
287
- ]
365
+ }
366
+ }
288
367
  },
289
368
  "Member": {
290
369
  "tmpl": [
@@ -578,13 +657,15 @@
578
657
  "tmpl": [
579
658
  "{ tag: ",
580
659
  {
581
- "fn": "escapeString",
660
+ "fn": "quoted",
582
661
  "args": [
662
+ "string",
583
663
  {
584
664
  "get": "node.caseName"
585
665
  }
586
666
  ]
587
667
  },
668
+ " as const",
588
669
  {
589
670
  "map": "node.fields",
590
671
  "sep": "",
@@ -616,6 +697,26 @@
616
697
  { "type": "node.testType" }
617
698
  ]
618
699
  },
700
+ "NullAssert": {
701
+ "case": {
702
+ "when": [
703
+ [
704
+ { "eq": ["node.isFail", "true"] },
705
+ { "tmpl": [{ "fn": "require", "args": ["nullAssert"] }, "__pgNullAssert(", { "fn": "quoted", "args": ["string", { "get": "node.where" }] }, ")"] }
706
+ ]
707
+ ],
708
+ "else": {
709
+ "tmpl": [
710
+ { "fn": "require", "args": ["nullAssert"] },
711
+ "(",
712
+ { "emitChild": "node.operand", "side": "recv" },
713
+ " ?? __pgNullAssert(",
714
+ { "fn": "quoted", "args": ["string", { "get": "node.where" }] },
715
+ "))"
716
+ ]
717
+ }
718
+ }
719
+ },
619
720
  "AsCast": {
620
721
  "case": {
621
722
  "when": [
@@ -1030,7 +1131,7 @@
1030
1131
  "lits": "node.chunks",
1031
1132
  "holes": "node.holes",
1032
1133
  "lit": {
1033
- "fn": "escape",
1134
+ "fn": "literal",
1034
1135
  "args": [
1035
1136
  "interp",
1036
1137
  {
@@ -1064,14 +1165,7 @@
1064
1165
  },
1065
1166
  {
1066
1167
  "tmpl": [
1067
- {
1068
- "fn": "ident",
1069
- "args": [
1070
- {
1071
- "get": "node.method"
1072
- }
1073
- ]
1074
- },
1168
+ { "fn": "mangleName", "args": [ { "fn": "ident", "args": [ { "get": "node.freeName" } ] } ] },
1075
1169
  "(",
1076
1170
  {
1077
1171
  "emit": "node.object"
@@ -1146,7 +1240,14 @@
1146
1240
  },
1147
1241
  "Match": {
1148
1242
  "tmpl": [
1149
- "(() => { const _m = ",
1243
+ "(() => { const _m",
1244
+ {
1245
+ "case": {
1246
+ "when": [[ { "has": "node.scrutineeScalar" }, { "tmpl": [": ", { "get": "node.scrutineeScalar" }] } ]],
1247
+ "else": ""
1248
+ }
1249
+ },
1250
+ " = ",
1150
1251
  {
1151
1252
  "emit": "node.scrutinee"
1152
1253
  },
@@ -1196,8 +1297,9 @@
1196
1297
  "tmpl": [
1197
1298
  "if (_m.tag === ",
1198
1299
  {
1199
- "fn": "escapeString",
1300
+ "fn": "quoted",
1200
1301
  "args": [
1302
+ "string",
1201
1303
  {
1202
1304
  "get": "item.pattern.ctorCase"
1203
1305
  }
@@ -1499,7 +1601,7 @@
1499
1601
  }
1500
1602
  }
1501
1603
  },
1502
- "throw new Error(\"non-exhaustive match\"); })()"
1604
+ "throw new globalThis.Error(\"non-exhaustive match\"); })()"
1503
1605
  ]
1504
1606
  },
1505
1607
  "Lambda": {
@@ -1556,7 +1658,8 @@
1556
1658
  ]
1557
1659
  },
1558
1660
  {
1559
- "emit": "node.body"
1661
+ "fn": "parenIfStarts",
1662
+ "args": ["{", { "emit": "node.body" }]
1560
1663
  }
1561
1664
  ]
1562
1665
  ],
@@ -1578,7 +1681,10 @@
1578
1681
  {
1579
1682
  "line": {
1580
1683
  "tmpl": [
1581
- "export type ",
1684
+ {
1685
+ "call": "tsExport"
1686
+ },
1687
+ "type ",
1582
1688
  {
1583
1689
  "fn": "ident",
1584
1690
  "args": [
@@ -1594,7 +1700,10 @@
1594
1700
  {
1595
1701
  "line": {
1596
1702
  "tmpl": [
1597
- "export const ",
1703
+ {
1704
+ "call": "tsExport"
1705
+ },
1706
+ "const ",
1598
1707
  {
1599
1708
  "fn": "ident",
1600
1709
  "args": [
@@ -1696,7 +1805,8 @@
1696
1805
  ]
1697
1806
  },
1698
1807
  "override "
1699
- ]
1808
+ ],
1809
+ [ { "eq": [ "decl.isAbstract", "true" ] }, "abstract " ]
1700
1810
  ]
1701
1811
  }
1702
1812
  },
@@ -1873,6 +1983,7 @@
1873
1983
  "block": {
1874
1984
  "head": {
1875
1985
  "tmpl": [
1986
+ { "case": { "when": [ [ { "eq": [ "decl.isStatic", "true" ] }, "static " ] ] } },
1876
1987
  "get ",
1877
1988
  {
1878
1989
  "fn": "ident",
@@ -1934,6 +2045,7 @@
1934
2045
  "block": {
1935
2046
  "head": {
1936
2047
  "tmpl": [
2048
+ { "case": { "when": [ [ { "eq": [ "decl.isStatic", "true" ] }, "static " ] ] } },
1937
2049
  "set ",
1938
2050
  {
1939
2051
  "fn": "ident",
@@ -2170,7 +2282,9 @@
2170
2282
  }
2171
2283
  ]
2172
2284
  ],
2173
- "else": {
2285
+ "else": { "case": { "when": [
2286
+ [ { "eq": [ "decl.isAbstract", "true" ] }, { "line": { "tmpl": [ { "call": "tsMethodSig" }, ";" ] } } ]
2287
+ ], "else": {
2174
2288
  "block": {
2175
2289
  "head": {
2176
2290
  "call": "tsMethodSig"
@@ -2206,12 +2320,15 @@
2206
2320
  }
2207
2321
  ]
2208
2322
  }
2209
- }
2323
+ } } }
2210
2324
  }
2211
2325
  },
2212
2326
  "tsRecordHead": {
2213
2327
  "tmpl": [
2214
- "export class ",
2328
+ {
2329
+ "call": "tsExport"
2330
+ },
2331
+ "class ",
2215
2332
  {
2216
2333
  "fn": "ident",
2217
2334
  "args": [
@@ -2633,6 +2750,17 @@
2633
2750
  {
2634
2751
  "case": {
2635
2752
  "when": [
2753
+ [
2754
+ {
2755
+ "eq": [
2756
+ "stmt.catchesDiverge",
2757
+ "true"
2758
+ ]
2759
+ },
2760
+ {
2761
+ "line": "throw __e;"
2762
+ }
2763
+ ],
2636
2764
  [
2637
2765
  {
2638
2766
  "eq": [
@@ -2803,6 +2931,19 @@
2803
2931
  }
2804
2932
  ]
2805
2933
  },
2934
+ "rangeEndDecl": {
2935
+ "case": {
2936
+ "when": [ [ { "eq": [ "stmt.rangeEndSimple", "false" ] },
2937
+ { "tmpl": [ ", ", { "fn": "ident", "args": [ { "get": "stmt.rangeEndTemp" } ] }, " = ", { "emit": "stmt.rangeEnd" } ] } ] ],
2938
+ "else": ""
2939
+ }
2940
+ },
2941
+ "rangeEndRead": {
2942
+ "case": {
2943
+ "when": [ [ { "eq": [ "stmt.rangeEndSimple", "true" ] }, { "emit": "stmt.rangeEnd" } ] ],
2944
+ "else": { "fn": "ident", "args": [ { "get": "stmt.rangeEndTemp" } ] }
2945
+ }
2946
+ },
2806
2947
  "ForStmt": {
2807
2948
  "case": {
2808
2949
  "when": [
@@ -2830,6 +2971,7 @@
2830
2971
  {
2831
2972
  "emit": "stmt.rangeStart"
2832
2973
  },
2974
+ { "call": "rangeEndDecl" },
2833
2975
  "; ",
2834
2976
  {
2835
2977
  "fn": "ident",
@@ -2855,9 +2997,7 @@
2855
2997
  "else": " < "
2856
2998
  }
2857
2999
  },
2858
- {
2859
- "emit": "stmt.rangeEnd"
2860
- },
3000
+ { "call": "rangeEndRead" },
2861
3001
  "; ",
2862
3002
  {
2863
3003
  "fn": "ident",
@@ -2946,6 +3086,15 @@
2946
3086
  },
2947
3087
  "Program": {
2948
3088
  "seq": [
3089
+ {
3090
+ "line": "// <auto-generated/>"
3091
+ },
3092
+ {
3093
+ "line": "// Generated by Polyglot. Do not edit: regenerate with `polyglot build`."
3094
+ },
3095
+ {
3096
+ "fn": "preludeSlot"
3097
+ },
2949
3098
  {
2950
3099
  "case": {
2951
3100
  "when": [
@@ -2969,8 +3118,26 @@
2969
3118
  },
2970
3119
  {
2971
3120
  "mapDecl": "module.imports",
2972
- "each": {
2973
- "line": {
3121
+ "each": { "seq": [
3122
+ {
3123
+ "case": {
3124
+ "when": [
3125
+ [
3126
+ { "not": { "eq": ["item.typeNames", ""] } },
3127
+ { "line": { "tmpl": ["import type { ", { "get": "item.typeNames" }, " } from \"", { "get": "item.path" }, "\";"] } }
3128
+ ]
3129
+ ]
3130
+ }
3131
+ },
3132
+ { "case": {
3133
+ "when": [
3134
+ [
3135
+ { "and": [ { "eq": ["item.names", ""] }, { "eq": ["item.allNames", ""] }, { "not": { "eq": ["item.typeNames", ""] } } ] },
3136
+ { "seq": [] }
3137
+ ]
3138
+ ],
3139
+ "else": {
3140
+ "line": {
2974
3141
  "case": {
2975
3142
  "when": [
2976
3143
  [
@@ -3016,6 +3183,10 @@
3016
3183
  "\";"
3017
3184
  ]
3018
3185
  }
3186
+ ],
3187
+ [
3188
+ { "not": { "eq": ["item.allNames", ""] } },
3189
+ { "tmpl": ["import { ", { "get": "item.allNames" }, " } from \"", { "get": "item.path" }, "\";"] }
3019
3190
  ]
3020
3191
  ],
3021
3192
  "else": {
@@ -3029,97 +3200,96 @@
3029
3200
  }
3030
3201
  }
3031
3202
  }
3032
- }
3203
+ } } }
3204
+ ] }
3033
3205
  },
3034
3206
  {
3035
- "mapMembers": "module.enums",
3036
- "rule": "EnumDecl"
3037
- },
3038
- {
3039
- "mapMembers": "module.interfaces",
3040
- "rule": "InterfaceDecl"
3041
- },
3042
- {
3043
- "mapMembers": "module.unions",
3044
- "rule": "UnionDecl"
3045
- },
3046
- {
3047
- "mapMembers": "module.records",
3048
- "rule": "RecordDecl"
3049
- },
3050
- {
3051
- "mapMembers": "module.classes",
3052
- "rule": "ClassDecl"
3053
- },
3054
- {
3055
- "mapDecl": "module.globals",
3056
- "each": {
3057
- "line": {
3058
- "tmpl": [
3059
- "export ",
3060
- {
3061
- "case": {
3062
- "when": [
3063
- [
3064
- {
3065
- "eq": [
3066
- "item.isConst",
3067
- "true"
3207
+ "mapOrder": "module.order",
3208
+ "kinds": {
3209
+ "enum": { "rule": "EnumDecl" },
3210
+ "interface": { "rule": "InterfaceDecl" },
3211
+ "union": { "rule": "UnionDecl" },
3212
+ "record": { "rule": "RecordDecl" },
3213
+ "function": { "rule": "FunctionDecl" },
3214
+ "extension": { "rule": "ExtensionDecl" },
3215
+ "class": { "rule": "ClassDecl" },
3216
+ "global": {
3217
+ "each": {
3218
+ "line": {
3219
+ "tmpl": [
3220
+ {
3221
+ "case": {
3222
+ "when": [
3223
+ [
3224
+ {
3225
+ "eq": [
3226
+ "item.isPrelude",
3227
+ "true"
3228
+ ]
3229
+ },
3230
+ ""
3068
3231
  ]
3069
- },
3070
- "const "
3071
- ]
3072
- ],
3073
- "else": "let "
3074
- }
3075
- },
3076
- {
3077
- "fn": "ident",
3078
- "args": [
3232
+ ],
3233
+ "else": "export "
3234
+ }
3235
+ },
3079
3236
  {
3080
- "get": "item.name"
3081
- }
3082
- ]
3083
- },
3084
- ": ",
3085
- {
3086
- "type": "item.type"
3087
- },
3088
- {
3089
- "case": {
3090
- "when": [
3091
- [
3092
- {
3093
- "eq": [
3094
- "item.hasInit",
3095
- "true"
3237
+ "case": {
3238
+ "when": [
3239
+ [
3240
+ {
3241
+ "eq": [
3242
+ "item.isConst",
3243
+ "true"
3244
+ ]
3245
+ },
3246
+ "const "
3096
3247
  ]
3097
- },
3248
+ ],
3249
+ "else": "let "
3250
+ }
3251
+ },
3252
+ {
3253
+ "fn": "ident",
3254
+ "args": [
3098
3255
  {
3099
- "tmpl": [
3100
- " = ",
3256
+ "get": "item.name"
3257
+ }
3258
+ ]
3259
+ },
3260
+ ": ",
3261
+ {
3262
+ "type": "item.type"
3263
+ },
3264
+ {
3265
+ "case": {
3266
+ "when": [
3267
+ [
3101
3268
  {
3102
- "emit": "item.init"
3269
+ "eq": [
3270
+ "item.hasInit",
3271
+ "true"
3272
+ ]
3273
+ },
3274
+ {
3275
+ "tmpl": [
3276
+ " = ",
3277
+ {
3278
+ "emit": "item.init"
3279
+ }
3280
+ ]
3103
3281
  }
3104
3282
  ]
3105
- }
3106
- ]
3107
- ]
3108
- }
3109
- },
3110
- ";"
3111
- ]
3283
+ ]
3284
+ }
3285
+ },
3286
+ ";"
3287
+ ]
3288
+ }
3289
+ }
3112
3290
  }
3113
3291
  }
3114
3292
  },
3115
- {
3116
- "mapMembers": "module.extensions",
3117
- "rule": "ExtensionDecl"
3118
- },
3119
- {
3120
- "mapMembers": "module.functions",
3121
- "rule": "FunctionDecl"
3122
- },
3123
3293
  {
3124
3294
  "case": {
3125
3295
  "when": [
@@ -3143,12 +3313,35 @@
3143
3313
  ]
3144
3314
  ]
3145
3315
  }
3316
+ },
3317
+ {
3318
+ "case": {
3319
+ "when": [[{ "eq": ["module.userDecls.count", "0"] }, { "line": "export {};" }]]
3320
+ }
3146
3321
  }
3147
3322
  ]
3148
3323
  },
3324
+ "tsExport": {
3325
+ "case": {
3326
+ "when": [
3327
+ [
3328
+ {
3329
+ "eq": [
3330
+ "decl.isPrelude",
3331
+ "true"
3332
+ ]
3333
+ },
3334
+ ""
3335
+ ]
3336
+ ],
3337
+ "else": "export "
3338
+ }
3339
+ },
3149
3340
  "tsFnSig": {
3150
3341
  "tmpl": [
3151
- "export ",
3342
+ {
3343
+ "call": "tsExport"
3344
+ },
3152
3345
  {
3153
3346
  "case": {
3154
3347
  "when": [
@@ -3231,12 +3424,15 @@
3231
3424
  },
3232
3425
  "tsExtSig": {
3233
3426
  "tmpl": [
3234
- "export function ",
3427
+ {
3428
+ "call": "tsExport"
3429
+ },
3430
+ "function ",
3235
3431
  {
3236
3432
  "fn": "ident",
3237
3433
  "args": [
3238
3434
  {
3239
- "get": "decl.name"
3435
+ "get": "decl.emitName"
3240
3436
  }
3241
3437
  ]
3242
3438
  },
@@ -3296,7 +3492,11 @@
3296
3492
  },
3297
3493
  "tsClassHead": {
3298
3494
  "tmpl": [
3299
- "export class ",
3495
+ {
3496
+ "call": "tsExport"
3497
+ },
3498
+ { "case": { "when": [ [ { "eq": [ "decl.isAbstract", "true" ] }, "abstract " ] ] } },
3499
+ "class ",
3300
3500
  {
3301
3501
  "fn": "ident",
3302
3502
  "args": [
@@ -3405,6 +3605,21 @@
3405
3605
  "else": ""
3406
3606
  }
3407
3607
  },
3608
+ {
3609
+ "case": {
3610
+ "when": [
3611
+ [
3612
+ {
3613
+ "eq": [
3614
+ "item.shadowsBaseRoot",
3615
+ "true"
3616
+ ]
3617
+ },
3618
+ "override "
3619
+ ]
3620
+ ]
3621
+ }
3622
+ },
3408
3623
  {
3409
3624
  "fn": "ident",
3410
3625
  "args": [
@@ -3520,7 +3735,10 @@
3520
3735
  "block": {
3521
3736
  "head": {
3522
3737
  "tmpl": [
3523
- "export interface ",
3738
+ {
3739
+ "call": "tsExport"
3740
+ },
3741
+ "interface ",
3524
3742
  {
3525
3743
  "fn": "ident",
3526
3744
  "args": [
@@ -3641,7 +3859,10 @@
3641
3859
  "UnionDecl": {
3642
3860
  "line": {
3643
3861
  "tmpl": [
3644
- "export type ",
3862
+ {
3863
+ "call": "tsExport"
3864
+ },
3865
+ "type ",
3645
3866
  {
3646
3867
  "fn": "ident",
3647
3868
  "args": [
@@ -3701,6 +3922,33 @@
3701
3922
  "Type": {
3702
3923
  "case": {
3703
3924
  "when": [
3925
+ [
3926
+ {
3927
+ "and": [
3928
+ {
3929
+ "eq": [
3930
+ "type.kind",
3931
+ "function"
3932
+ ]
3933
+ },
3934
+ {
3935
+ "eq": [
3936
+ "type.nullable",
3937
+ "true"
3938
+ ]
3939
+ }
3940
+ ]
3941
+ },
3942
+ {
3943
+ "tmpl": [
3944
+ "((",
3945
+ {
3946
+ "type": "type.base"
3947
+ },
3948
+ ") | null)"
3949
+ ]
3950
+ }
3951
+ ],
3704
3952
  [
3705
3953
  {
3706
3954
  "eq": [
@@ -3982,30 +4230,16 @@
3982
4230
  },
3983
4231
  {
3984
4232
  "tmpl": [
3985
- "JSON.stringify(",
3986
- {
3987
- "emit": "node.lhs"
3988
- },
3989
- ") === JSON.stringify(",
3990
- {
3991
- "emit": "node.rhs"
3992
- },
3993
- ")"
4233
+ { "fn": "require", "args": ["unionEq"] },
4234
+ "__pgUnionEq(", { "emit": "node.lhs" }, ", ", { "emit": "node.rhs" }, ")"
3994
4235
  ]
3995
4236
  }
3996
4237
  ]
3997
4238
  ],
3998
4239
  "else": {
3999
4240
  "tmpl": [
4000
- "JSON.stringify(",
4001
- {
4002
- "emit": "node.lhs"
4003
- },
4004
- ") !== JSON.stringify(",
4005
- {
4006
- "emit": "node.rhs"
4007
- },
4008
- ")"
4241
+ { "fn": "require", "args": ["unionEq"] },
4242
+ "!__pgUnionEq(", { "emit": "node.lhs" }, ", ", { "emit": "node.rhs" }, ")"
4009
4243
  ]
4010
4244
  }
4011
4245
  }
@@ -4491,20 +4725,30 @@
4491
4725
  "List.add": "$this.push($0)",
4492
4726
  "List.clear": "$this.length = 0",
4493
4727
  "List.removeAll": "$this.splice(0, $this.length, ...$this.filter(__e => !(($0)(__e))))",
4494
- "List.removeAt": "$this.splice($0, 1)"
4728
+ "List.removeAt": "$this.splice($0, 1)",
4729
+ "Map.type": "Map<$0, $1>",
4730
+ "Map.constructor": "new $T()",
4731
+ "Map.count": "$this.size",
4732
+ "Map.get": "($this.get($0) ?? null)",
4733
+ "Map.set": "$this.set($0, $1)",
4734
+ "Map.has": "$this.has($0)",
4735
+ "Map.remove": "$this.delete($0)",
4736
+ "Map.keys": "[...$this.keys()]",
4737
+ "Map.values": "[...$this.values()]"
4495
4738
  },
4496
4739
  "std.io": {
4497
4740
  "print": "console.log(String(x))",
4498
- "readText": "process.getBuiltinModule('fs').readFileSync(path, 'utf8')",
4499
- "writeText": "process.getBuiltinModule('fs').writeFileSync(path, content)",
4500
- "appendText": "process.getBuiltinModule('fs').appendFileSync(path, content)",
4501
- "fileExists": "process.getBuiltinModule('fs').existsSync(path)",
4502
- "deleteFile": "process.getBuiltinModule('fs').unlinkSync(path)"
4741
+ "readText": "globalThis.process.getBuiltinModule('fs').readFileSync(path, 'utf8')",
4742
+ "writeText": "globalThis.process.getBuiltinModule('fs').writeFileSync(path, content)",
4743
+ "appendText": "globalThis.process.getBuiltinModule('fs').appendFileSync(path, content)",
4744
+ "fileExists": "globalThis.process.getBuiltinModule('fs').existsSync(path)",
4745
+ "deleteFile": "globalThis.process.getBuiltinModule('fs').unlinkSync(path)"
4503
4746
  },
4504
4747
  "std.math": {
4505
4748
  "Math.PI": "Math.PI",
4506
4749
  "Math.E": "Math.E",
4507
4750
  "Math.sqrt": "Math.sqrt($0)",
4751
+ "Math.isNaN": "Number.isNaN($0)",
4508
4752
  "Math.ln": "Math.log($0)",
4509
4753
  "Math.log": "Math.log($0)",
4510
4754
  "Math.log2": "Math.log2($0)",
@@ -4539,10 +4783,21 @@
4539
4783
  "string.len": "$this.length",
4540
4784
  "string.toUpper": "$this.toUpperCase()",
4541
4785
  "string.toLower": "$this.toLowerCase()",
4542
- "string.charAt": "$this.charAt($0)",
4543
- "string.codePointAt": "$this.codePointAt($0)!",
4786
+ "string.toUpperAscii": "$this.replace(/[a-z]+/g, (__m) => __m.toUpperCase())",
4787
+ "string.toLowerAscii": "$this.replace(/[A-Z]+/g, (__m) => __m.toLowerCase())",
4544
4788
  "string.codePoints": "Array.from($this)",
4545
- "string.toI32": "parseInt($this, 10)"
4789
+ "string.startsWith": "$this.startsWith($0)",
4790
+ "string.endsWith": "$this.endsWith($0)",
4791
+ "string.contains": "$this.includes($0)",
4792
+ "string.trimAscii": "$this.replace(/^[\\t\\n\\v\\f\\r ]+|[\\t\\n\\v\\f\\r ]+$/g, \"\")",
4793
+ "compareOrdinal": "(a < b ? -1 : (a > b ? 1 : 0))",
4794
+ "string.__pgCharAt": "$this.charAt($0)",
4795
+ "string.__pgCodePointAt": "$this.codePointAt($0)!",
4796
+ "string.__pgSubstring": "$this.substring($0, $1)",
4797
+ "string.__pgIndexOf": "$this.indexOf($0, $1)",
4798
+ "string.__pgReplaceAll": "$this.split($0).join($1)",
4799
+ "string.__pgSplit": "$this.split($0)",
4800
+ "string.__pgFromCodePoint": "String.fromCodePoint($0)"
4546
4801
  },
4547
4802
  "std.core": {
4548
4803
  "Error.type": "Error",
@@ -4552,17 +4807,20 @@
4552
4807
  "Array.type": "$0[]",
4553
4808
  "Array.constructor": "[]",
4554
4809
  "Array.count": "$this.length",
4555
- "i8.parse": "(Number.parseInt($0, 10) << 24 >> 24)",
4556
- "i16.parse": "(Number.parseInt($0, 10) << 16 >> 16)",
4557
- "i32.parse": "(Number.parseInt($0, 10) | 0)",
4558
- "i64.parse": "BigInt($0)",
4559
- "u8.parse": "(Number.parseInt($0, 10) & 0xff)",
4560
- "u16.parse": "(Number.parseInt($0, 10) & 0xffff)",
4561
- "u32.parse": "(Number.parseInt($0, 10) >>> 0)",
4562
- "u64.parse": "BigInt($0)",
4563
- "f32.parse": "Number($0)",
4564
- "f64.parse": "Number($0)"
4810
+ "__pgText.rawLen": "$0.length",
4811
+ "__pgText.rawCode": "$0.charCodeAt($1)",
4812
+ "i8.__pgParse": "(Number.parseInt($0, 10) << 24 >> 24)",
4813
+ "i16.__pgParse": "(Number.parseInt($0, 10) << 16 >> 16)",
4814
+ "i32.__pgParse": "(Number.parseInt($0, 10) | 0)",
4815
+ "i64.__pgParse": "BigInt($0)",
4816
+ "u8.__pgParse": "(Number.parseInt($0, 10) & 0xff)",
4817
+ "u16.__pgParse": "(Number.parseInt($0, 10) & 0xffff)",
4818
+ "u32.__pgParse": "(Number.parseInt($0, 10) >>> 0)",
4819
+ "u64.__pgParse": "BigInt($0)",
4820
+ "f32.__pgParse": "Math.fround(Number($0))",
4821
+ "f64.__pgParse": "Number($0)"
4565
4822
  }
4566
4823
  },
4567
- "fileExtension": ".ts"
4824
+ "fileExtension": ".ts",
4825
+ "lineComment": "//"
4568
4826
  }