@mintplayer/polyglot-target-typescript 0.9.7 → 0.9.9

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 +606 -27
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mintplayer/polyglot-target-typescript",
3
- "version": "0.9.7",
3
+ "version": "0.9.9",
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",
@@ -2,7 +2,11 @@
2
2
  "schema": 1,
3
3
  "name": "typescript",
4
4
  "crossDirImports": true,
5
- "capabilities": {},
5
+ "capabilities": {
6
+ "interfaces:runtimeIdentity": false,
7
+ "attributes:target.function": false,
8
+ "attributes:target.param": false
9
+ },
6
10
  "spec": {
7
11
  "name": "typescript",
8
12
  "scalarType": {
@@ -89,7 +93,14 @@
89
93
  "<": "lt",
90
94
  "<=": "le",
91
95
  ">": "gt",
92
- ">=": "ge"
96
+ ">=": "ge",
97
+ "&": "band",
98
+ "|": "bor",
99
+ "^": "bxor",
100
+ "<<": "shl",
101
+ ">>": "shr",
102
+ "u-": "neg",
103
+ "u~": "bnot"
93
104
  },
94
105
  "localDecl": {
95
106
  "mutable": "let $x",
@@ -213,7 +224,32 @@
213
224
  }
214
225
  ]
215
226
  },
216
- "This": "this",
227
+ "This": {
228
+ "case": {
229
+ "when": [
230
+ [
231
+ {
232
+ "or": [
233
+ {
234
+ "eq": [
235
+ "node.insideOperator",
236
+ "true"
237
+ ]
238
+ },
239
+ {
240
+ "eq": [
241
+ "node.insideEqOperator",
242
+ "true"
243
+ ]
244
+ }
245
+ ]
246
+ },
247
+ "lhs"
248
+ ]
249
+ ],
250
+ "else": "this"
251
+ }
252
+ },
217
253
  "Extern": {
218
254
  "get": "node.code"
219
255
  },
@@ -567,9 +603,112 @@
567
603
  " }"
568
604
  ]
569
605
  },
606
+ "IsTest": {
607
+ "tmpl": [
608
+ { "emitChild": "node.operand", "side": "recv" },
609
+ " instanceof ",
610
+ { "type": "node.testType" }
611
+ ]
612
+ },
613
+ "AsCast": {
614
+ "case": {
615
+ "when": [
616
+ [
617
+ {
618
+ "eq": [
619
+ "node.operandIsSimple",
620
+ "true"
621
+ ]
622
+ },
623
+ {
624
+ "tmpl": [
625
+ "(",
626
+ {
627
+ "emit": "node.operand"
628
+ },
629
+ " instanceof ",
630
+ {
631
+ "type": "node.castType"
632
+ },
633
+ " ? ",
634
+ {
635
+ "emit": "node.operand"
636
+ },
637
+ " : null)"
638
+ ]
639
+ }
640
+ ]
641
+ ],
642
+ "else": {
643
+ "tmpl": [
644
+ "((",
645
+ {
646
+ "get": "node.tempName"
647
+ },
648
+ ": any) => ",
649
+ {
650
+ "get": "node.tempName"
651
+ },
652
+ " instanceof ",
653
+ {
654
+ "type": "node.castType"
655
+ },
656
+ " ? ",
657
+ {
658
+ "get": "node.tempName"
659
+ },
660
+ " : null)(",
661
+ {
662
+ "emit": "node.operand"
663
+ },
664
+ ")"
665
+ ]
666
+ }
667
+ }
668
+ },
570
669
  "Unary": {
571
670
  "case": {
572
671
  "when": [
672
+ [
673
+ {
674
+ "eq": [
675
+ "node.hasUnaryOpMethod",
676
+ "true"
677
+ ]
678
+ },
679
+ {
680
+ "tmpl": [
681
+ {
682
+ "fn": "ident",
683
+ "args": [
684
+ {
685
+ "get": "node.operandTypeName"
686
+ }
687
+ ]
688
+ },
689
+ ".",
690
+ {
691
+ "fn": "table",
692
+ "args": [
693
+ "opMethod",
694
+ {
695
+ "tmpl": [
696
+ "u",
697
+ {
698
+ "get": "node.op"
699
+ }
700
+ ]
701
+ }
702
+ ]
703
+ },
704
+ "(",
705
+ {
706
+ "emit": "node.operand"
707
+ },
708
+ ")"
709
+ ]
710
+ }
711
+ ],
573
712
  [
574
713
  {
575
714
  "and": [
@@ -622,6 +761,32 @@
622
761
  "Cast": {
623
762
  "case": {
624
763
  "when": [
764
+ [
765
+ {
766
+ "has": "node.convMethod"
767
+ },
768
+ {
769
+ "tmpl": [
770
+ {
771
+ "fn": "ident",
772
+ "args": [
773
+ {
774
+ "get": "node.operandTypeName"
775
+ }
776
+ ]
777
+ },
778
+ ".",
779
+ {
780
+ "get": "node.convMethod"
781
+ },
782
+ "(",
783
+ {
784
+ "emit": "node.operand"
785
+ },
786
+ ")"
787
+ ]
788
+ }
789
+ ],
625
790
  [
626
791
  {
627
792
  "eq": [
@@ -1607,6 +1772,85 @@
1607
1772
  }
1608
1773
  ]
1609
1774
  },
1775
+ "tsOperatorSig": {
1776
+ "tmpl": [
1777
+ "static ",
1778
+ {
1779
+ "fn": "ident",
1780
+ "args": [
1781
+ {
1782
+ "get": "decl.name"
1783
+ }
1784
+ ]
1785
+ },
1786
+ "(lhs: ",
1787
+ {
1788
+ "fn": "ident",
1789
+ "args": [
1790
+ {
1791
+ "get": "decl.owner"
1792
+ }
1793
+ ]
1794
+ },
1795
+ {
1796
+ "case": {
1797
+ "when": [
1798
+ [
1799
+ {
1800
+ "eq": [
1801
+ "decl.opSymbol",
1802
+ "=="
1803
+ ]
1804
+ },
1805
+ " | null"
1806
+ ]
1807
+ ],
1808
+ "else": ""
1809
+ }
1810
+ },
1811
+ {
1812
+ "map": "decl.params",
1813
+ "sep": "",
1814
+ "item": {
1815
+ "tmpl": [
1816
+ ", ",
1817
+ {
1818
+ "fn": "ident",
1819
+ "args": [
1820
+ {
1821
+ "get": "item.name"
1822
+ }
1823
+ ]
1824
+ },
1825
+ ": ",
1826
+ {
1827
+ "type": "item.type"
1828
+ },
1829
+ {
1830
+ "case": {
1831
+ "when": [
1832
+ [
1833
+ {
1834
+ "eq": [
1835
+ "decl.opSymbol",
1836
+ "=="
1837
+ ]
1838
+ },
1839
+ " | null"
1840
+ ]
1841
+ ],
1842
+ "else": ""
1843
+ }
1844
+ }
1845
+ ]
1846
+ }
1847
+ },
1848
+ "): ",
1849
+ {
1850
+ "type": "decl.returnType"
1851
+ }
1852
+ ]
1853
+ },
1610
1854
  "MethodDecl": {
1611
1855
  "case": {
1612
1856
  "when": [
@@ -1624,9 +1868,18 @@
1624
1868
  "head": {
1625
1869
  "tmpl": [
1626
1870
  "get ",
1627
- { "fn": "ident", "args": [ { "get": "decl.name" } ] },
1871
+ {
1872
+ "fn": "ident",
1873
+ "args": [
1874
+ {
1875
+ "get": "decl.name"
1876
+ }
1877
+ ]
1878
+ },
1628
1879
  "(): ",
1629
- { "type": "decl.returnType" }
1880
+ {
1881
+ "type": "decl.returnType"
1882
+ }
1630
1883
  ]
1631
1884
  },
1632
1885
  "body": [
@@ -1634,11 +1887,28 @@
1634
1887
  "case": {
1635
1888
  "when": [
1636
1889
  [
1637
- { "eq": [ "decl.exprBodied", "true" ] },
1638
- { "line": { "tmpl": [ "return ", { "emit": "decl.exprBody" }, ";" ] } }
1890
+ {
1891
+ "eq": [
1892
+ "decl.exprBodied",
1893
+ "true"
1894
+ ]
1895
+ },
1896
+ {
1897
+ "line": {
1898
+ "tmpl": [
1899
+ "return ",
1900
+ {
1901
+ "emit": "decl.exprBody"
1902
+ },
1903
+ ";"
1904
+ ]
1905
+ }
1906
+ }
1639
1907
  ]
1640
1908
  ],
1641
- "else": { "stmts": "decl.body" }
1909
+ "else": {
1910
+ "stmts": "decl.body"
1911
+ }
1642
1912
  }
1643
1913
  }
1644
1914
  ]
@@ -1648,21 +1918,46 @@
1648
1918
  "case": {
1649
1919
  "when": [
1650
1920
  [
1651
- { "eq": [ "decl.propHasSetter", "true" ] },
1921
+ {
1922
+ "eq": [
1923
+ "decl.propHasSetter",
1924
+ "true"
1925
+ ]
1926
+ },
1652
1927
  {
1653
1928
  "block": {
1654
1929
  "head": {
1655
1930
  "tmpl": [
1656
1931
  "set ",
1657
- { "fn": "ident", "args": [ { "get": "decl.name" } ] },
1932
+ {
1933
+ "fn": "ident",
1934
+ "args": [
1935
+ {
1936
+ "get": "decl.name"
1937
+ }
1938
+ ]
1939
+ },
1658
1940
  "(",
1659
- { "fn": "ident", "args": [ { "get": "decl.propSetterParam" } ] },
1941
+ {
1942
+ "fn": "ident",
1943
+ "args": [
1944
+ {
1945
+ "get": "decl.propSetterParam"
1946
+ }
1947
+ ]
1948
+ },
1660
1949
  ": ",
1661
- { "type": "decl.returnType" },
1950
+ {
1951
+ "type": "decl.returnType"
1952
+ },
1662
1953
  ")"
1663
1954
  ]
1664
1955
  },
1665
- "body": [ { "stmts": "decl.propSetterBody" } ]
1956
+ "body": [
1957
+ {
1958
+ "stmts": "decl.propSetterBody"
1959
+ }
1960
+ ]
1666
1961
  }
1667
1962
  }
1668
1963
  ]
@@ -1672,6 +1967,201 @@
1672
1967
  }
1673
1968
  ]
1674
1969
  }
1970
+ ],
1971
+ [
1972
+ {
1973
+ "and": [
1974
+ {
1975
+ "eq": [
1976
+ "decl.kind",
1977
+ "operator"
1978
+ ]
1979
+ },
1980
+ {
1981
+ "or": [
1982
+ {
1983
+ "eq": [
1984
+ "decl.opSymbol",
1985
+ "+"
1986
+ ]
1987
+ },
1988
+ {
1989
+ "eq": [
1990
+ "decl.opSymbol",
1991
+ "-"
1992
+ ]
1993
+ },
1994
+ {
1995
+ "eq": [
1996
+ "decl.opSymbol",
1997
+ "*"
1998
+ ]
1999
+ },
2000
+ {
2001
+ "eq": [
2002
+ "decl.opSymbol",
2003
+ "/"
2004
+ ]
2005
+ },
2006
+ {
2007
+ "eq": [
2008
+ "decl.opSymbol",
2009
+ "%"
2010
+ ]
2011
+ },
2012
+ {
2013
+ "eq": [
2014
+ "decl.opSymbol",
2015
+ "<"
2016
+ ]
2017
+ },
2018
+ {
2019
+ "eq": [
2020
+ "decl.opSymbol",
2021
+ "<="
2022
+ ]
2023
+ },
2024
+ {
2025
+ "eq": [
2026
+ "decl.opSymbol",
2027
+ ">"
2028
+ ]
2029
+ },
2030
+ {
2031
+ "eq": [
2032
+ "decl.opSymbol",
2033
+ ">="
2034
+ ]
2035
+ },
2036
+ {
2037
+ "eq": [
2038
+ "decl.opSymbol",
2039
+ "&"
2040
+ ]
2041
+ },
2042
+ {
2043
+ "eq": [
2044
+ "decl.opSymbol",
2045
+ "|"
2046
+ ]
2047
+ },
2048
+ {
2049
+ "eq": [
2050
+ "decl.opSymbol",
2051
+ "^"
2052
+ ]
2053
+ },
2054
+ {
2055
+ "eq": [
2056
+ "decl.opSymbol",
2057
+ "<<"
2058
+ ]
2059
+ },
2060
+ {
2061
+ "eq": [
2062
+ "decl.opSymbol",
2063
+ ">>"
2064
+ ]
2065
+ },
2066
+ {
2067
+ "eq": [
2068
+ "decl.opSymbol",
2069
+ "~"
2070
+ ]
2071
+ },
2072
+ {
2073
+ "eq": [
2074
+ "decl.opSymbol",
2075
+ "=="
2076
+ ]
2077
+ },
2078
+ {
2079
+ "eq": [
2080
+ "decl.opSymbol",
2081
+ "explicit"
2082
+ ]
2083
+ }
2084
+ ]
2085
+ }
2086
+ ]
2087
+ },
2088
+ {
2089
+ "block": {
2090
+ "head": {
2091
+ "call": "tsOperatorSig"
2092
+ },
2093
+ "body": [
2094
+ {
2095
+ "case": {
2096
+ "when": [
2097
+ [
2098
+ {
2099
+ "eq": [
2100
+ "decl.opSymbol",
2101
+ "=="
2102
+ ]
2103
+ },
2104
+ {
2105
+ "line": {
2106
+ "tmpl": [
2107
+ "if (lhs === null || ",
2108
+ {
2109
+ "fn": "ident",
2110
+ "args": [
2111
+ {
2112
+ "get": "decl.params.0.name"
2113
+ }
2114
+ ]
2115
+ },
2116
+ " === null) { return lhs === ",
2117
+ {
2118
+ "fn": "ident",
2119
+ "args": [
2120
+ {
2121
+ "get": "decl.params.0.name"
2122
+ }
2123
+ ]
2124
+ },
2125
+ "; }"
2126
+ ]
2127
+ }
2128
+ }
2129
+ ]
2130
+ ],
2131
+ "else": ""
2132
+ }
2133
+ },
2134
+ {
2135
+ "case": {
2136
+ "when": [
2137
+ [
2138
+ {
2139
+ "eq": [
2140
+ "decl.exprBodied",
2141
+ "true"
2142
+ ]
2143
+ },
2144
+ {
2145
+ "line": {
2146
+ "tmpl": [
2147
+ "return ",
2148
+ {
2149
+ "emit": "decl.exprBody"
2150
+ },
2151
+ ";"
2152
+ ]
2153
+ }
2154
+ }
2155
+ ]
2156
+ ],
2157
+ "else": {
2158
+ "stmts": "decl.body"
2159
+ }
2160
+ }
2161
+ }
2162
+ ]
2163
+ }
2164
+ }
1675
2165
  ]
1676
2166
  ],
1677
2167
  "else": {
@@ -2517,6 +3007,27 @@
2517
3007
  },
2518
3008
  "Program": {
2519
3009
  "seq": [
3010
+ {
3011
+ "case": {
3012
+ "when": [
3013
+ [
3014
+ {
3015
+ "not": {
3016
+ "eq": [
3017
+ "module.attrImportsBlock",
3018
+ ""
3019
+ ]
3020
+ }
3021
+ },
3022
+ {
3023
+ "line": {
3024
+ "get": "module.attrImportsBlock"
3025
+ }
3026
+ }
3027
+ ]
3028
+ ]
3029
+ }
3030
+ },
2520
3031
  {
2521
3032
  "mapDecl": "module.imports",
2522
3033
  "each": {
@@ -2524,15 +3035,59 @@
2524
3035
  "case": {
2525
3036
  "when": [
2526
3037
  [
2527
- { "eq": [ "item.isNamespace", "true" ] },
2528
- { "tmpl": [ "import * as ", { "get": "item.ns" }, " from \"", { "get": "item.path" }, "\";" ] }
3038
+ {
3039
+ "eq": [
3040
+ "item.isNamespace",
3041
+ "true"
3042
+ ]
3043
+ },
3044
+ {
3045
+ "tmpl": [
3046
+ "import * as ",
3047
+ {
3048
+ "get": "item.ns"
3049
+ },
3050
+ " from \"",
3051
+ {
3052
+ "get": "item.path"
3053
+ },
3054
+ "\";"
3055
+ ]
3056
+ }
2529
3057
  ],
2530
3058
  [
2531
- { "not": { "eq": [ "item.names", "" ] } },
2532
- { "tmpl": [ "import { ", { "get": "item.names" }, " } from \"", { "get": "item.path" }, "\";" ] }
3059
+ {
3060
+ "not": {
3061
+ "eq": [
3062
+ "item.names",
3063
+ ""
3064
+ ]
3065
+ }
3066
+ },
3067
+ {
3068
+ "tmpl": [
3069
+ "import { ",
3070
+ {
3071
+ "get": "item.names"
3072
+ },
3073
+ " } from \"",
3074
+ {
3075
+ "get": "item.path"
3076
+ },
3077
+ "\";"
3078
+ ]
3079
+ }
2533
3080
  ]
2534
3081
  ],
2535
- "else": { "tmpl": [ "import \"", { "get": "item.path" }, "\";" ] }
3082
+ "else": {
3083
+ "tmpl": [
3084
+ "import \"",
3085
+ {
3086
+ "get": "item.path"
3087
+ },
3088
+ "\";"
3089
+ ]
3090
+ }
2536
3091
  }
2537
3092
  }
2538
3093
  }
@@ -3404,10 +3959,18 @@
3404
3959
  {
3405
3960
  "tmpl": [
3406
3961
  {
3407
- "emitChild": "node.lhs",
3408
- "side": "recv"
3962
+ "fn": "ident",
3963
+ "args": [
3964
+ {
3965
+ "get": "node.lhsTypeName"
3966
+ }
3967
+ ]
3409
3968
  },
3410
3969
  ".eq(",
3970
+ {
3971
+ "emit": "node.lhs"
3972
+ },
3973
+ ", ",
3411
3974
  {
3412
3975
  "emit": "node.rhs"
3413
3976
  },
@@ -3420,10 +3983,18 @@
3420
3983
  "tmpl": [
3421
3984
  "!",
3422
3985
  {
3423
- "emitChild": "node.lhs",
3424
- "side": "recv"
3986
+ "fn": "ident",
3987
+ "args": [
3988
+ {
3989
+ "get": "node.lhsTypeName"
3990
+ }
3991
+ ]
3425
3992
  },
3426
3993
  ".eq(",
3994
+ {
3995
+ "emit": "node.lhs"
3996
+ },
3997
+ ", ",
3427
3998
  {
3428
3999
  "emit": "node.rhs"
3429
4000
  },
@@ -3620,8 +4191,12 @@
3620
4191
  {
3621
4192
  "tmpl": [
3622
4193
  {
3623
- "emitChild": "node.lhs",
3624
- "side": "recv"
4194
+ "fn": "ident",
4195
+ "args": [
4196
+ {
4197
+ "get": "node.lhsTypeName"
4198
+ }
4199
+ ]
3625
4200
  },
3626
4201
  ".",
3627
4202
  {
@@ -3634,6 +4209,10 @@
3634
4209
  ]
3635
4210
  },
3636
4211
  "(",
4212
+ {
4213
+ "emit": "node.lhs"
4214
+ },
4215
+ ", ",
3637
4216
  {
3638
4217
  "emit": "node.rhs"
3639
4218
  },
@@ -3968,7 +4547,7 @@
3968
4547
  "std": {
3969
4548
  "std.collections": {
3970
4549
  "List.type": "$0[]",
3971
- "List.init": "[]",
4550
+ "List.constructor": "[]",
3972
4551
  "List.count": "$this.length",
3973
4552
  "List.add": "$this.push($0)",
3974
4553
  "List.clear": "$this.length = 0",
@@ -4028,11 +4607,11 @@
4028
4607
  },
4029
4608
  "std.core": {
4030
4609
  "Error.type": "Error",
4031
- "Error.init": "new $T($0)",
4610
+ "Error.constructor": "new $T($0)",
4032
4611
  "Error.message": "$this.message",
4033
4612
  "Iterable.type": "Iterable<$0>",
4034
4613
  "Array.type": "$0[]",
4035
- "Array.init": "[]",
4614
+ "Array.constructor": "[]",
4036
4615
  "Array.count": "$this.length",
4037
4616
  "i8.parse": "(Number.parseInt($0, 10) << 24 >> 24)",
4038
4617
  "i16.parse": "(Number.parseInt($0, 10) << 16 >> 16)",