diff --git a/ts2mls/js/src/main/scala/ts2mls/TSCompilerInfo.scala b/ts2mls/js/src/main/scala/ts2mls/TSCompilerInfo.scala index b57f67d16a..83bfe64e4a 100644 --- a/ts2mls/js/src/main/scala/ts2mls/TSCompilerInfo.scala +++ b/ts2mls/js/src/main/scala/ts2mls/TSCompilerInfo.scala @@ -21,6 +21,8 @@ object TypeScript { val syntaxKindPrivate = ts.SyntaxKind.PrivateKeyword val syntaxKindProtected = ts.SyntaxKind.ProtectedKeyword val syntaxKindStatic = ts.SyntaxKind.StaticKeyword + val syntaxKindReadonly = ts.SyntaxKind.ReadonlyKeyword // this flag is only for readonly members + val nodeFlagsConst = ts.NodeFlags.Const // this flag is for const variables val objectFlagsAnonymous = ts.ObjectFlags.Anonymous val symbolFlagsOptional = ts.SymbolFlags.Optional // this flag is only for checking optional members of interfaces @@ -89,6 +91,7 @@ object TSSymbolObject { class TSNodeObject(node: js.Dynamic)(implicit checker: TSTypeChecker) extends TSAny(node) { private lazy val modifiers = TSTokenArray(node.modifiers) + private lazy val flags = node.flags lazy val isToken = TypeScript.isToken(node) lazy val isClassDeclaration = TypeScript.isClassDeclaration(node) @@ -132,6 +135,9 @@ class TSNodeObject(node: js.Dynamic)(implicit checker: TSTypeChecker) extends TS if (modifiers.isUndefined) Public else modifiers.foldLeft[TSAccessModifier](Public)( (m, t) => if (t.isPrivate) Private else if (t.isProtected) Protected else m) + lazy val readonly: Boolean = + if (modifiers.isUndefined) (flags & TypeScript.nodeFlagsConst > 0) + else modifiers.foldLeft[Boolean](false)((m, t) => m || t.isReadonly) lazy val declarationList = TSNodeObject(node.declarationList) lazy val declarations = TSNodeArray(node.declarations) @@ -146,6 +152,7 @@ class TSNodeObject(node: js.Dynamic)(implicit checker: TSTypeChecker) extends TS lazy val symbolType = TSTypeObject(checker.getTypeOfSymbolAtLocation(node.symbol, node)) lazy val literal = TSTokenObject(node.literal) lazy val name = TSIdentifierObject(node.name) + lazy val parent = TSNodeObject(node.parent) } object TSNodeObject { @@ -158,6 +165,7 @@ class TSTokenObject(token: js.Dynamic)(implicit checker: TSTypeChecker) extends lazy val isPrivate = kind == TypeScript.syntaxKindPrivate lazy val isProtected = kind == TypeScript.syntaxKindProtected lazy val isStatic = kind == TypeScript.syntaxKindStatic + lazy val isReadonly = kind == TypeScript.syntaxKindReadonly lazy val typeNode = TSTypeObject(checker.getTypeFromTypeNode(token)) lazy val text = token.text.toString() diff --git a/ts2mls/js/src/main/scala/ts2mls/TSNamespace.scala b/ts2mls/js/src/main/scala/ts2mls/TSNamespace.scala index 4bb94bcf5a..15689472cc 100644 --- a/ts2mls/js/src/main/scala/ts2mls/TSNamespace.scala +++ b/ts2mls/js/src/main/scala/ts2mls/TSNamespace.scala @@ -6,7 +6,7 @@ import mlscript.utils._ class TSNamespace(name: String, parent: Option[TSNamespace]) { private val subSpace = HashMap[String, TSNamespace]() - private val members = HashMap[String, TSType]() + private val members = HashMap[String, (TSType, Boolean)]() // readonly: Boolean // write down the order of members // easier to check the output one by one @@ -21,15 +21,15 @@ class TSNamespace(name: String, parent: Option[TSNamespace]) { sub } - def put(name: String, tp: TSType): Unit = + def put(name: String, tp: TSType, readonly: Boolean): Unit = if (!members.contains(name)) { order += Right(name) - members.put(name, tp) + members.put(name, (tp, readonly)) } - else members.update(name, tp) + else members.update(name, (tp, readonly)) - def get(name: String): TSType = - members.getOrElse(name, + def get(name: String): (TSType, Boolean) = + members.getOrElse[(TSType, Boolean)](name, if (!parent.isEmpty) parent.get.get(name) else throw new Exception(s"member $name not found.")) def containsMember(name: String, searchParent: Boolean = true): Boolean = @@ -44,18 +44,20 @@ class TSNamespace(name: String, parent: Option[TSNamespace]) { } case Right(name) => { val mem = members(name) - mem match { + mem._1 match { case inter: TSIntersectionType => // overloaded functions writer.writeln(Converter.generateFunDeclaration(inter, name)(indent)) case f: TSFunctionType => writer.writeln(Converter.generateFunDeclaration(f, name)(indent)) case overload: TSIgnoredOverload => writer.writeln(Converter.generateFunDeclaration(overload, name)(indent)) - case _: TSClassType => writer.writeln(Converter.convert(mem)(indent)) + case _: TSClassType => writer.writeln(Converter.convert(mem._1)(indent)) case TSInterfaceType(name, _, _, _) if (name =/= "") => - writer.writeln(Converter.convert(mem)(indent)) - case _: TSTypeAlias => writer.writeln(Converter.convert(mem)(indent)) - case _ => writer.writeln(s"${indent}let $name: ${Converter.convert(mem)("")}") + writer.writeln(Converter.convert(mem._1)(indent)) + case _: TSTypeAlias => writer.writeln(Converter.convert(mem._1)(indent)) + case _ => + if (mem._2) writer.writeln(s"${indent}let $name: ${Converter.convert(mem._1)("")}") + else writer.writeln(s"${indent}let $name: {mut contents: ${Converter.convert(mem._1)("")}}") } } }) diff --git a/ts2mls/js/src/main/scala/ts2mls/TSSourceFile.scala b/ts2mls/js/src/main/scala/ts2mls/TSSourceFile.scala index aa0f6e15ad..83c10e4529 100644 --- a/ts2mls/js/src/main/scala/ts2mls/TSSourceFile.scala +++ b/ts2mls/js/src/main/scala/ts2mls/TSSourceFile.scala @@ -110,7 +110,7 @@ object TSSourceFile { mem match { case func: TSFunctionType => { - if (!mp.contains(name)) mp ++ Map(name -> TSMemberType(func, p.modifier)) + if (!mp.contains(name)) mp ++ Map(name -> TSMemberType(func, p.modifier, !p.readonly)) else { // deal with functions overloading val old = mp(name) val res = old.base match { @@ -126,10 +126,10 @@ object TSSourceFile { case _ => old.base } - mp.removed(name) ++ Map(name -> TSMemberType(res, p.modifier)) + mp.removed(name) ++ Map(name -> TSMemberType(res, p.modifier, !p.readonly)) } } - case _ => mp ++ Map(name -> TSMemberType(mem, p.modifier)) + case _ => mp ++ Map(name -> TSMemberType(mem, p.modifier, !p.readonly)) } } else mp @@ -145,11 +145,16 @@ object TSSourceFile { }) private def getInterfacePropertiesType(list: TSNodeArray): Map[String, TSMemberType] = - list.foldLeft(Map[String, TSMemberType]())((mp, p) => mp ++ Map(p.symbol.escapedName -> TSMemberType(getMemberType(p)))) + list.foldLeft(Map[String, TSMemberType]())((mp, p) => + mp ++ Map(p.symbol.escapedName -> TSMemberType(getMemberType(p), Public, !p.readonly))) private def getAnonymousPropertiesType(list: TSSymbolArray): Map[String, TSMemberType] = list.foldLeft(Map[String, TSMemberType]())((mp, p) => - mp ++ Map(p.escapedName -> TSMemberType(if (p.`type`.isUndefined) getMemberType(p.declaration) else getObjectType(p.`type`)))) + mp ++ Map(p.escapedName -> TSMemberType( + (if (p.`type`.isUndefined) getMemberType(p.declaration) else getObjectType(p.`type`)), + Public, !p.declaration.readonly + ) + )) private def parseMembers(name: String, node: TSNodeObject, isClass: Boolean): TSType = if (isClass) @@ -165,9 +170,9 @@ object TSSourceFile { }) private def addFunctionIntoNamespace(fun: TSFunctionType, node: TSNodeObject, name: String)(implicit ns: TSNamespace) = - if (!ns.containsMember(name, false)) ns.put(name, fun) + if (!ns.containsMember(name, false)) ns.put(name, fun, true) else { - val old = ns.get(name) + val old = ns.get(name)._1 val res = old match { case f @ TSFunctionType(_, _, tv) => if (!tv.isEmpty || !fun.typeVars.isEmpty) TSIgnoredOverload(fun, name) @@ -181,7 +186,7 @@ object TSSourceFile { case _ => old } - ns.put(name, res) + ns.put(name, res, true) } // overload functions in a sub-namespace need to provide an overload array @@ -197,15 +202,15 @@ object TSSourceFile { } } else if (node.isClassDeclaration) - ns.put(name, parseMembers(name, node, true)) + ns.put(name, parseMembers(name, node, true), true) else if (node.isInterfaceDeclaration) - ns.put(name, parseMembers(name, node, false)) + ns.put(name, parseMembers(name, node, false), true) else if (node.isTypeAliasDeclaration) - ns.put(name, TSTypeAlias(name, getTypeAlias(node.`type`), getTypeParameters(node))) + ns.put(name, TSTypeAlias(name, getTypeAlias(node.`type`), getTypeParameters(node)), true) else if (node.isObjectLiteral) - ns.put(name, TSInterfaceType("", getObjectLiteralMembers(node.initializer.properties), List(), List())) + ns.put(name, TSInterfaceType("", getObjectLiteralMembers(node.initializer.properties), List(), List()), true) else if (node.isVariableDeclaration) - ns.put(name, getMemberType(node)) + ns.put(name, getMemberType(node), node.parent.readonly) else if (node.isNamespace) parseNamespace(node) diff --git a/ts2mls/js/src/main/scala/ts2mls/types/Converter.scala b/ts2mls/js/src/main/scala/ts2mls/types/Converter.scala index 32760642b2..b32c8c321f 100644 --- a/ts2mls/js/src/main/scala/ts2mls/types/Converter.scala +++ b/ts2mls/js/src/main/scala/ts2mls/types/Converter.scala @@ -42,7 +42,7 @@ object Converter { case TSTupleType(lst) => s"(${lst.foldLeft("")((p, t) => s"$p${convert(t)}, ")})" case TSArrayType(element) => s"MutArray<${convert(element)}>" case TSEnumType => "int" - case TSMemberType(base, _) => convert(base) // TODO: support private/protected members + case TSMemberType(base, _, _) => convert(base) // TODO: support private/protected members case TSInterfaceType(name, members, typeVars, parents) => convertRecord(s"trait $name", members, typeVars, parents, Map(), List())(indent) case TSClassType(name, members, statics, typeVars, parents, cons) => @@ -64,7 +64,9 @@ object Converter { else m._2.base match { case _: TSFunctionType => s"${generateFunDeclaration(m._2.base, m._1)(indent + " ")}\n" case _: TSIgnoredOverload => s"${generateFunDeclaration(m._2.base, m._1)(indent + " ")}\n" - case _ => s"${indent} let ${m._1}: ${convert(m._2)}\n" + case _ => + if (m._2.mutable) s"${indent} mut ${m._1}: ${convert(m._2)}\n" + else s"${indent} ${m._1}: ${convert(m._2)}\n" } case _ => "" // TODO: deal with private/protected members }) ::: diff --git a/ts2mls/js/src/main/scala/ts2mls/types/TSType.scala b/ts2mls/js/src/main/scala/ts2mls/types/TSType.scala index ce0527db8f..4e3c7d3965 100644 --- a/ts2mls/js/src/main/scala/ts2mls/types/TSType.scala +++ b/ts2mls/js/src/main/scala/ts2mls/types/TSType.scala @@ -7,7 +7,7 @@ case object Protected extends TSAccessModifier sealed abstract class TSType case class TSParameterType(name: String, val tp: TSType) extends TSType // record both parameter's name and parameter's type -case class TSMemberType(val base: TSType, val modifier: TSAccessModifier = Public) extends TSType +case class TSMemberType(val base: TSType, val modifier: TSAccessModifier = Public, val mutable: Boolean = false) extends TSType case class TSTypeParameter(val name: String, constraint: Option[TSType] = None) extends TSType case class TSPrimitiveType(typeName: String) extends TSType case class TSReferenceType(name: String) extends TSType diff --git a/ts2mls/js/src/test/diff/Array.d.mls b/ts2mls/js/src/test/diff/Array.d.mls index ec1010a58a..f86ec324ee 100644 --- a/ts2mls/js/src/test/diff/Array.d.mls +++ b/ts2mls/js/src/test/diff/Array.d.mls @@ -6,7 +6,7 @@ fun first2(fs: MutArray<(number) => number>): (number) => number fun doEs(e: MutArray): MutArray class C() {} trait I() { - let i: number + mut i: number } fun doCs(c: MutArray): MutArray fun doIs(i: MutArray): MutArray @@ -15,9 +15,15 @@ fun clean(x: MutArray<(string, number, )>): MutArray<(string, number, )> fun translate(x: MutArray): MutArray fun uu(x: MutArray<((number) | (false)) | (true)>): MutArray<((number) | (false)) | (true)> class Temp() { - let x: T + mut x: T } fun ta(ts: MutArray>): MutArray> fun tat(ts: MutArray>): MutArray> -//│ |#fun| |first|(|x|#:| |MutArray|‹|string|›|)|#:| |string|↵|#fun| |getZero3|(||)|#:| |MutArray|‹|number|›|↵|#fun| |first2|(|fs|#:| |MutArray|‹|(|number|)| |=>| |number|›|)|#:| |(|number|)| |=>| |number|↵|#fun| |doEs|(|e|#:| |MutArray|‹|int|›|)|#:| |MutArray|‹|int|›|↵|#class| |C|(||)| |{||}|↵|#trait| |I|(||)| |{|→|#let| |i|#:| |number|←|↵|}|↵|#fun| |doCs|(|c|#:| |MutArray|‹|C|›|)|#:| |MutArray|‹|C|›|↵|#fun| |doIs|(|i|#:| |MutArray|‹|I|›|)|#:| |MutArray|‹|I|›|↵|#fun| |inter|‹|U|,| |T|›|(|x|#:| |MutArray|‹|(|U|)| |&| |(|T|)|›|)|#:| |MutArray|‹|(|U|)| |&| |(|T|)|›|↵|#fun| |clean|(|x|#:| |MutArray|‹|(|string|,| |number|,| |)|›|)|#:| |MutArray|‹|(|string|,| |number|,| |)|›|↵|#fun| |translate|‹|T|,| |U|›|(|x|#:| |MutArray|‹|T|›|)|#:| |MutArray|‹|U|›|↵|#fun| |uu|(|x|#:| |MutArray|‹|(|(|number|)| ||| |(|false|)|)| ||| |(|true|)|›|)|#:| |MutArray|‹|(|(|number|)| ||| |(|false|)|)| ||| |(|true|)|›|↵|#class| |Temp|‹|T|›|(||)| |{|→|#let| |x|#:| |T|←|↵|}|↵|#fun| |ta|(|ts|#:| |MutArray|‹|Temp|‹|(|false|)| ||| |(|true|)|›|›|)|#:| |MutArray|‹|Temp|‹|(|false|)| ||| |(|true|)|›|›|↵|#fun| |tat|‹|T|›|(|ts|#:| |MutArray|‹|Temp|‹|T|›|›|)|#:| |MutArray|‹|Temp|‹|T|›|›| -//│ Parsed: {fun first: [] -> (x: MutArray[string],) -> string; fun getZero3: [] -> () -> MutArray[number]; fun first2: [] -> (fs: MutArray[number -> number],) -> number -> number; fun doEs: [] -> (e: MutArray[int],) -> MutArray[int]; class C() {}; trait I() {let i: [] -> number}; fun doCs: [] -> (c: MutArray[C],) -> MutArray[C]; fun doIs: [] -> (i: MutArray[I],) -> MutArray[I]; fun inter: [] -> (x: MutArray[(U,) & (T,)],) -> MutArray[(U,) & (T,)]; fun clean: [] -> (x: MutArray[(string, number,)],) -> MutArray[(string, number,)]; fun translate: [] -> (x: MutArray[T],) -> MutArray[U]; fun uu: [] -> (x: MutArray[((number,) | (false,),) | (true,)],) -> MutArray[((number,) | (false,),) | (true,)]; class Temp‹T›() {let x: [] -> T}; fun ta: [] -> (ts: MutArray[Temp[(false,) | (true,)]],) -> MutArray[Temp[(false,) | (true,)]]; fun tat: [] -> (ts: MutArray[Temp[T]],) -> MutArray[Temp[T]]} +//│ |#fun| |first|(|x|#:| |MutArray|‹|string|›|)|#:| |string|↵|#fun| |getZero3|(||)|#:| |MutArray|‹|number|›|↵|#fun| |first2|(|fs|#:| |MutArray|‹|(|number|)| |=>| |number|›|)|#:| |(|number|)| |=>| |number|↵|#fun| |doEs|(|e|#:| |MutArray|‹|int|›|)|#:| |MutArray|‹|int|›|↵|#class| |C|(||)| |{||}|↵|#trait| |I|(||)| |{|→|#mut| |i|#:| |number|←|↵|}|↵|#fun| |doCs|(|c|#:| |MutArray|‹|C|›|)|#:| |MutArray|‹|C|›|↵|#fun| |doIs|(|i|#:| |MutArray|‹|I|›|)|#:| |MutArray|‹|I|›|↵|#fun| |inter|‹|U|,| |T|›|(|x|#:| |MutArray|‹|(|U|)| |&| |(|T|)|›|)|#:| |MutArray|‹|(|U|)| |&| |(|T|)|›|↵|#fun| |clean|(|x|#:| |MutArray|‹|(|string|,| |number|,| |)|›|)|#:| |MutArray|‹|(|string|,| |number|,| |)|›|↵|#fun| |translate|‹|T|,| |U|›|(|x|#:| |MutArray|‹|T|›|)|#:| |MutArray|‹|U|›|↵|#fun| |uu|(|x|#:| |MutArray|‹|(|(|number|)| ||| |(|false|)|)| ||| |(|true|)|›|)|#:| |MutArray|‹|(|(|number|)| ||| |(|false|)|)| ||| |(|true|)|›|↵|#class| |Temp|‹|T|›|(||)| |{|→|#mut| |x|#:| |T|←|↵|}|↵|#fun| |ta|(|ts|#:| |MutArray|‹|Temp|‹|(|false|)| ||| |(|true|)|›|›|)|#:| |MutArray|‹|Temp|‹|(|false|)| ||| |(|true|)|›|›|↵|#fun| |tat|‹|T|›|(|ts|#:| |MutArray|‹|Temp|‹|T|›|›|)|#:| |MutArray|‹|Temp|‹|T|›|›| +//│ ╔══[PARSE ERROR] Unexpected 'mut' keyword in expression position +//│ ║ l.9: mut i: number +//│ ╙── ^^^ +//│ ╔══[PARSE ERROR] Unexpected 'mut' keyword in expression position +//│ ║ l.18: mut x: T +//│ ╙── ^^^ +//│ Parsed: {fun first: [] -> (x: MutArray[string],) -> string; fun getZero3: [] -> () -> MutArray[number]; fun first2: [] -> (fs: MutArray[number -> number],) -> number -> number; fun doEs: [] -> (e: MutArray[int],) -> MutArray[int]; class C() {}; trait I() {i : TypeName(number)}; fun doCs: [] -> (c: MutArray[C],) -> MutArray[C]; fun doIs: [] -> (i: MutArray[I],) -> MutArray[I]; fun inter: [] -> (x: MutArray[(U,) & (T,)],) -> MutArray[(U,) & (T,)]; fun clean: [] -> (x: MutArray[(string, number,)],) -> MutArray[(string, number,)]; fun translate: [] -> (x: MutArray[T],) -> MutArray[U]; fun uu: [] -> (x: MutArray[((number,) | (false,),) | (true,)],) -> MutArray[((number,) | (false,),) | (true,)]; class Temp‹T›() {x : TypeName(T)}; fun ta: [] -> (ts: MutArray[Temp[(false,) | (true,)]],) -> MutArray[Temp[(false,) | (true,)]]; fun tat: [] -> (ts: MutArray[Temp[T]],) -> MutArray[Temp[T]]} diff --git a/ts2mls/js/src/test/diff/BasicFunctions.d.mls b/ts2mls/js/src/test/diff/BasicFunctions.d.mls index fa3404d87d..1d16a89f84 100644 --- a/ts2mls/js/src/test/diff/BasicFunctions.d.mls +++ b/ts2mls/js/src/test/diff/BasicFunctions.d.mls @@ -15,14 +15,20 @@ fun create(): object fun pa(x: number): number fun wtf(x: anything): unit class Foooooo() { - let ooooooo: number + mut ooooooo: number } fun inn(f: Foooooo): unit fun out(): Foooooo trait Barrrrrrrrr() { - let rrrrrrr: number + mut rrrrrrr: number } fun inn2(b: Barrrrrrrrr): unit fun out2(): Barrrrrrrrr -//│ |#fun| |hello|(||)|#:| |unit|↵|#fun| |add|(|x|#:| |number|,| |y|#:| |number|)|#:| |number|↵|#fun| |sub|(|x|#:| |number|,| |y|#:| |number|)|#:| |number|↵|#fun| |foo|(||)|#:| |number|↵|#fun| |id|(|x|#:| |anything|)|#:| |anything|↵|#fun| |odd|(|x|#:| |number|)|#:| |(|false|)| ||| |(|true|)|↵|#fun| |isnull|(|x|#:| |anything|)|#:| |(|false|)| ||| |(|true|)|↵|#fun| |bar|(||)|#:| |anything|↵|#fun| |nu|(|n|#:| |null|)|#:| |null|↵|#fun| |un|(|n|#:| |undefined|)|#:| |undefined|↵|#fun| |fail|(||)|#:| |nothing|↵|#fun| |create|(||)|#:| |object|↵|#fun| |pa|(|x|#:| |number|)|#:| |number|↵|#fun| |wtf|(|x|#:| |anything|)|#:| |unit|↵|#class| |Foooooo|(||)| |{|→|#let| |ooooooo|#:| |number|←|↵|}|↵|#fun| |inn|(|f|#:| |Foooooo|)|#:| |unit|↵|#fun| |out|(||)|#:| |Foooooo|↵|#trait| |Barrrrrrrrr|(||)| |{|→|#let| |rrrrrrr|#:| |number|←|↵|}|↵|#fun| |inn2|(|b|#:| |Barrrrrrrrr|)|#:| |unit|↵|#fun| |out2|(||)|#:| |Barrrrrrrrr| -//│ Parsed: {fun hello: [] -> () -> unit; fun add: [] -> (x: number, y: number,) -> number; fun sub: [] -> (x: number, y: number,) -> number; fun foo: [] -> () -> number; fun id: [] -> (x: anything,) -> anything; fun odd: [] -> (x: number,) -> ((false,) | (true,)); fun isnull: [] -> (x: anything,) -> ((false,) | (true,)); fun bar: [] -> () -> anything; fun nu: [] -> (n: null,) -> null; fun un: [] -> (n: undefined,) -> undefined; fun fail: [] -> () -> nothing; fun create: [] -> () -> object; fun pa: [] -> (x: number,) -> number; fun wtf: [] -> (x: anything,) -> unit; class Foooooo() {let ooooooo: [] -> number}; fun inn: [] -> (f: Foooooo,) -> unit; fun out: [] -> () -> Foooooo; trait Barrrrrrrrr() {let rrrrrrr: [] -> number}; fun inn2: [] -> (b: Barrrrrrrrr,) -> unit; fun out2: [] -> () -> Barrrrrrrrr} +//│ |#fun| |hello|(||)|#:| |unit|↵|#fun| |add|(|x|#:| |number|,| |y|#:| |number|)|#:| |number|↵|#fun| |sub|(|x|#:| |number|,| |y|#:| |number|)|#:| |number|↵|#fun| |foo|(||)|#:| |number|↵|#fun| |id|(|x|#:| |anything|)|#:| |anything|↵|#fun| |odd|(|x|#:| |number|)|#:| |(|false|)| ||| |(|true|)|↵|#fun| |isnull|(|x|#:| |anything|)|#:| |(|false|)| ||| |(|true|)|↵|#fun| |bar|(||)|#:| |anything|↵|#fun| |nu|(|n|#:| |null|)|#:| |null|↵|#fun| |un|(|n|#:| |undefined|)|#:| |undefined|↵|#fun| |fail|(||)|#:| |nothing|↵|#fun| |create|(||)|#:| |object|↵|#fun| |pa|(|x|#:| |number|)|#:| |number|↵|#fun| |wtf|(|x|#:| |anything|)|#:| |unit|↵|#class| |Foooooo|(||)| |{|→|#mut| |ooooooo|#:| |number|←|↵|}|↵|#fun| |inn|(|f|#:| |Foooooo|)|#:| |unit|↵|#fun| |out|(||)|#:| |Foooooo|↵|#trait| |Barrrrrrrrr|(||)| |{|→|#mut| |rrrrrrr|#:| |number|←|↵|}|↵|#fun| |inn2|(|b|#:| |Barrrrrrrrr|)|#:| |unit|↵|#fun| |out2|(||)|#:| |Barrrrrrrrr| +//│ ╔══[PARSE ERROR] Unexpected 'mut' keyword in expression position +//│ ║ l.18: mut ooooooo: number +//│ ╙── ^^^ +//│ ╔══[PARSE ERROR] Unexpected 'mut' keyword in expression position +//│ ║ l.23: mut rrrrrrr: number +//│ ╙── ^^^ +//│ Parsed: {fun hello: [] -> () -> unit; fun add: [] -> (x: number, y: number,) -> number; fun sub: [] -> (x: number, y: number,) -> number; fun foo: [] -> () -> number; fun id: [] -> (x: anything,) -> anything; fun odd: [] -> (x: number,) -> ((false,) | (true,)); fun isnull: [] -> (x: anything,) -> ((false,) | (true,)); fun bar: [] -> () -> anything; fun nu: [] -> (n: null,) -> null; fun un: [] -> (n: undefined,) -> undefined; fun fail: [] -> () -> nothing; fun create: [] -> () -> object; fun pa: [] -> (x: number,) -> number; fun wtf: [] -> (x: anything,) -> unit; class Foooooo() {ooooooo : TypeName(number)}; fun inn: [] -> (f: Foooooo,) -> unit; fun out: [] -> () -> Foooooo; trait Barrrrrrrrr() {rrrrrrr : TypeName(number)}; fun inn2: [] -> (b: Barrrrrrrrr,) -> unit; fun out2: [] -> () -> Barrrrrrrrr} diff --git a/ts2mls/js/src/test/diff/ClassMember.d.mls b/ts2mls/js/src/test/diff/ClassMember.d.mls index a37ab93cc8..ef45518350 100644 --- a/ts2mls/js/src/test/diff/ClassMember.d.mls +++ b/ts2mls/js/src/test/diff/ClassMember.d.mls @@ -1,9 +1,10 @@ :NewParser :ParseOnly class Student(s: string, age: number) { - let name: string + mut name: string fun isFriend(other: Student): (false) | (true) fun addScore(sub: string, score: number): unit + something: string fun getID(): number } class Foo() { @@ -14,12 +15,18 @@ class EZ() { } class Outer() { class Inner() { - let a: number + mut a: number } } class TTT() { fun ttt(x: T): T fun ttt2(x: T): T } -//│ |#class| |Student|(|s|#:| |string|,| |age|#:| |number|)| |{|→|#let| |name|#:| |string|↵|#fun| |isFriend|(|other|#:| |Student|)|#:| |(|false|)| ||| |(|true|)|↵|#fun| |addScore|(|sub|#:| |string|,| |score|#:| |number|)|#:| |unit|↵|#fun| |getID|(||)|#:| |number|←|↵|}|↵|#class| |Foo|‹|T|›|(||)| |{|→|#fun| |bar|(|x|#:| |T|)|#:| |unit|←|↵|}|↵|#class| |EZ|(||)| |{|→|#fun| |inc|(|x|#:| |number|)|#:| |number|←|↵|}|↵|#class| |Outer|(||)| |{|→|#class| |Inner|(||)| |{|→|#let| |a|#:| |number|←|↵|}|←|↵|}|↵|#class| |TTT|‹|T|›|(||)| |{|→|#fun| |ttt|(|x|#:| |T|)|#:| |T|↵|#fun| |ttt2|(|x|#:| |T|)|#:| |T|←|↵|}| -//│ Parsed: {class Student(s: string, age: number,) {let name: [] -> string; fun isFriend: [] -> (other: Student,) -> ((false,) | (true,)); fun addScore: [] -> (sub: string, score: number,) -> unit; fun getID: [] -> () -> number}; class Foo‹T›() {fun bar: [] -> (x: T,) -> unit}; class EZ() {fun inc: [] -> (x: number,) -> number}; class Outer() {class Inner() {let a: [] -> number}}; class TTT‹T›() {fun ttt: [] -> (x: T,) -> T; fun ttt2: [] -> (x: T,) -> T}} +//│ |#class| |Student|(|s|#:| |string|,| |age|#:| |number|)| |{|→|#mut| |name|#:| |string|↵|#fun| |isFriend|(|other|#:| |Student|)|#:| |(|false|)| ||| |(|true|)|↵|#fun| |addScore|(|sub|#:| |string|,| |score|#:| |number|)|#:| |unit|↵|something|#:| |string|↵|#fun| |getID|(||)|#:| |number|←|↵|}|↵|#class| |Foo|‹|T|›|(||)| |{|→|#fun| |bar|(|x|#:| |T|)|#:| |unit|←|↵|}|↵|#class| |EZ|(||)| |{|→|#fun| |inc|(|x|#:| |number|)|#:| |number|←|↵|}|↵|#class| |Outer|(||)| |{|→|#class| |Inner|(||)| |{|→|#mut| |a|#:| |number|←|↵|}|←|↵|}|↵|#class| |TTT|‹|T|›|(||)| |{|→|#fun| |ttt|(|x|#:| |T|)|#:| |T|↵|#fun| |ttt2|(|x|#:| |T|)|#:| |T|←|↵|}| +//│ ╔══[PARSE ERROR] Unexpected 'mut' keyword in expression position +//│ ║ l.4: mut name: string +//│ ╙── ^^^ +//│ ╔══[PARSE ERROR] Unexpected 'mut' keyword in expression position +//│ ║ l.18: mut a: number +//│ ╙── ^^^ +//│ Parsed: {class Student(s: string, age: number,) {name : TypeName(string); fun isFriend: [] -> (other: Student,) -> ((false,) | (true,)); fun addScore: [] -> (sub: string, score: number,) -> unit; something : TypeName(string); fun getID: [] -> () -> number}; class Foo‹T›() {fun bar: [] -> (x: T,) -> unit}; class EZ() {fun inc: [] -> (x: number,) -> number}; class Outer() {class Inner() {a : TypeName(number)}}; class TTT‹T›() {fun ttt: [] -> (x: T,) -> T; fun ttt2: [] -> (x: T,) -> T}} diff --git a/ts2mls/js/src/test/diff/Heritage.d.mls b/ts2mls/js/src/test/diff/Heritage.d.mls index 9d5bfdbca5..a9a60764a9 100644 --- a/ts2mls/js/src/test/diff/Heritage.d.mls +++ b/ts2mls/js/src/test/diff/Heritage.d.mls @@ -10,22 +10,22 @@ class C() { } class D(): C {} trait Wu() { - let x: (false) | (true) + mut x: (false) | (true) } class WuWu(): Wu { - let y: (false) | (true) + mut y: (false) | (true) } trait WuWuWu(): WuWu { - let z: (false) | (true) + mut z: (false) | (true) } trait Never(): WuWuWu { fun w(): nothing } class VG() { - let x: T + mut x: T } class Home(): VG { - let y: T + mut y: T } trait O() { fun xx(x: I): I @@ -35,10 +35,28 @@ class OR(): O { } namespace Five { class ROTK() { - let wu: string + mut wu: string } class Y(): Five.ROTK {} } class Y(): Five.ROTK {} -//│ |#class| |A|(||)| |{|→|#fun| |foo|(||)|#:| |unit|←|↵|}|↵|#class| |B|(||)|#:| |A| |{||}|↵|#class| |C|‹|T|›|(||)| |{|→|#fun| |set|(|x|#:| |T|)|#:| |unit|↵|#fun| |get|(||)|#:| |T|←|↵|}|↵|#class| |D|(||)|#:| |C|‹|number|›| |{||}|↵|#trait| |Wu|(||)| |{|→|#let| |x|#:| |(|false|)| ||| |(|true|)|←|↵|}|↵|#class| |WuWu|(||)|#:| |Wu| |{|→|#let| |y|#:| |(|false|)| ||| |(|true|)|←|↵|}|↵|#trait| |WuWuWu|(||)|#:| |WuWu| |{|→|#let| |z|#:| |(|false|)| ||| |(|true|)|←|↵|}|↵|#trait| |Never|(||)|#:| |WuWuWu| |{|→|#fun| |w|(||)|#:| |nothing|←|↵|}|↵|#class| |VG|‹|T|›|(||)| |{|→|#let| |x|#:| |T|←|↵|}|↵|#class| |Home|‹|T|›|(||)|#:| |VG|‹|string|›| |{|→|#let| |y|#:| |T|←|↵|}|↵|#trait| |O|‹|I|›|(||)| |{|→|#fun| |xx|(|x|#:| |I|)|#:| |I|←|↵|}|↵|#class| |OR|‹|R|›|(||)|#:| |O|‹|R|›| |{|→|#fun| |xx|(|x|#:| |R|)|#:| |R|←|↵|}|↵|#namespace| |Five| |{|→|#class| |ROTK|(||)| |{|→|#let| |wu|#:| |string|←|↵|}|↵|#class| |Y|(||)|#:| |Five|.ROTK| |{||}|←|↵|}|↵|#class| |Y|(||)|#:| |Five|.ROTK| |{||}| -//│ Parsed: {class A() {fun foo: [] -> () -> unit}; class B(): A {}; class C‹T›() {fun set: [] -> (x: T,) -> unit; fun get: [] -> () -> T}; class D(): C‹number› {}; trait Wu() {let x: [] -> (false,) | (true,)}; class WuWu(): Wu {let y: [] -> (false,) | (true,)}; trait WuWuWu(): WuWu {let z: [] -> (false,) | (true,)}; trait Never(): WuWuWu {fun w: [] -> () -> nothing}; class VG‹T›() {let x: [] -> T}; class Home‹T›(): VG‹string› {let y: [] -> T}; trait O‹I›() {fun xx: [] -> (x: I,) -> I}; class OR‹R›(): O‹R› {fun xx: [] -> (x: R,) -> R}; namespace Five() {class ROTK() {let wu: [] -> string}; class Y(): (Five).ROTK {}}; class Y(): (Five).ROTK {}} +//│ |#class| |A|(||)| |{|→|#fun| |foo|(||)|#:| |unit|←|↵|}|↵|#class| |B|(||)|#:| |A| |{||}|↵|#class| |C|‹|T|›|(||)| |{|→|#fun| |set|(|x|#:| |T|)|#:| |unit|↵|#fun| |get|(||)|#:| |T|←|↵|}|↵|#class| |D|(||)|#:| |C|‹|number|›| |{||}|↵|#trait| |Wu|(||)| |{|→|#mut| |x|#:| |(|false|)| ||| |(|true|)|←|↵|}|↵|#class| |WuWu|(||)|#:| |Wu| |{|→|#mut| |y|#:| |(|false|)| ||| |(|true|)|←|↵|}|↵|#trait| |WuWuWu|(||)|#:| |WuWu| |{|→|#mut| |z|#:| |(|false|)| ||| |(|true|)|←|↵|}|↵|#trait| |Never|(||)|#:| |WuWuWu| |{|→|#fun| |w|(||)|#:| |nothing|←|↵|}|↵|#class| |VG|‹|T|›|(||)| |{|→|#mut| |x|#:| |T|←|↵|}|↵|#class| |Home|‹|T|›|(||)|#:| |VG|‹|string|›| |{|→|#mut| |y|#:| |T|←|↵|}|↵|#trait| |O|‹|I|›|(||)| |{|→|#fun| |xx|(|x|#:| |I|)|#:| |I|←|↵|}|↵|#class| |OR|‹|R|›|(||)|#:| |O|‹|R|›| |{|→|#fun| |xx|(|x|#:| |R|)|#:| |R|←|↵|}|↵|#namespace| |Five| |{|→|#class| |ROTK|(||)| |{|→|#mut| |wu|#:| |string|←|↵|}|↵|#class| |Y|(||)|#:| |Five|.ROTK| |{||}|←|↵|}|↵|#class| |Y|(||)|#:| |Five|.ROTK| |{||}| +//│ ╔══[PARSE ERROR] Unexpected 'mut' keyword in expression position +//│ ║ l.13: mut x: (false) | (true) +//│ ╙── ^^^ +//│ ╔══[PARSE ERROR] Unexpected 'mut' keyword in expression position +//│ ║ l.16: mut y: (false) | (true) +//│ ╙── ^^^ +//│ ╔══[PARSE ERROR] Unexpected 'mut' keyword in expression position +//│ ║ l.19: mut z: (false) | (true) +//│ ╙── ^^^ +//│ ╔══[PARSE ERROR] Unexpected 'mut' keyword in expression position +//│ ║ l.25: mut x: T +//│ ╙── ^^^ +//│ ╔══[PARSE ERROR] Unexpected 'mut' keyword in expression position +//│ ║ l.28: mut y: T +//│ ╙── ^^^ +//│ ╔══[PARSE ERROR] Unexpected 'mut' keyword in expression position +//│ ║ l.38: mut wu: string +//│ ╙── ^^^ +//│ Parsed: {class A() {fun foo: [] -> () -> unit}; class B(): A {}; class C‹T›() {fun set: [] -> (x: T,) -> unit; fun get: [] -> () -> T}; class D(): C‹number› {}; trait Wu() {x : Union(Tuple(List((None,Field(None,TypeName(false))))),Tuple(List((None,Field(None,TypeName(true))))))}; class WuWu(): Wu {y : Union(Tuple(List((None,Field(None,TypeName(false))))),Tuple(List((None,Field(None,TypeName(true))))))}; trait WuWuWu(): WuWu {z : Union(Tuple(List((None,Field(None,TypeName(false))))),Tuple(List((None,Field(None,TypeName(true))))))}; trait Never(): WuWuWu {fun w: [] -> () -> nothing}; class VG‹T›() {x : TypeName(T)}; class Home‹T›(): VG‹string› {y : TypeName(T)}; trait O‹I›() {fun xx: [] -> (x: I,) -> I}; class OR‹R›(): O‹R› {fun xx: [] -> (x: R,) -> R}; namespace Five() {class ROTK() {wu : TypeName(string)}; class Y(): (Five).ROTK {}}; class Y(): (Five).ROTK {}} diff --git a/ts2mls/js/src/test/diff/InterfaceMember.d.mls b/ts2mls/js/src/test/diff/InterfaceMember.d.mls index 787ac8c2e4..1a4581bbaa 100644 --- a/ts2mls/js/src/test/diff/InterfaceMember.d.mls +++ b/ts2mls/js/src/test/diff/InterfaceMember.d.mls @@ -1,7 +1,8 @@ :NewParser :ParseOnly trait IFoo() { - let a: string + x: number + mut a: string fun b(x: number): number fun c(): (false) | (true) fun d(x: string): unit @@ -22,19 +23,31 @@ trait StringArray() { } trait Counter() { fun __call(start: number): string - let interval: number + mut interval: number fun reset(): unit } trait Simple() { - let a: number + mut a: number fun b(x: (false) | (true)): string } trait Simple2() { - let abc: T + mut abc: T } trait Next(): Simple {} trait TTT() { fun ttt(x: T): T } -//│ |#trait| |IFoo|(||)| |{|→|#let| |a|#:| |string|↵|#fun| |b|(|x|#:| |number|)|#:| |number|↵|#fun| |c|(||)|#:| |(|false|)| ||| |(|true|)|↵|#fun| |d|(|x|#:| |string|)|#:| |unit|←|↵|}|↵|#trait| |II|‹|T|›|(||)| |{|→|#fun| |test|(|x|#:| |T|)|#:| |number|←|↵|}|↵|#fun| |create|(||)|#:| |{|v|#:| |number|,|}|↵|#fun| |get|(|x|#:| |{|t|#:| |string|,|}|)|#:| |string|↵|#trait| |IEvent|(||)| |{|→|#fun| |callback|(||)|#:| |(|number|)| |=>| |unit|←|↵|}|↵|#trait| |SearchFunc|(||)| |{|→|#fun| |__call|(|source|#:| |string|,| |subString|#:| |string|)|#:| |(|false|)| ||| |(|true|)|←|↵|}|↵|#trait| |StringArray|(||)| |{|→|#fun| |__index|(|index|#:| |number|)|#:| |string|←|↵|}|↵|#trait| |Counter|(||)| |{|→|#fun| |__call|(|start|#:| |number|)|#:| |string|↵|#let| |interval|#:| |number|↵|#fun| |reset|(||)|#:| |unit|←|↵|}|↵|#trait| |Simple|(||)| |{|→|#let| |a|#:| |number|↵|#fun| |b|(|x|#:| |(|false|)| ||| |(|true|)|)|#:| |string|←|↵|}|↵|#trait| |Simple2|‹|T|›|(||)| |{|→|#let| |abc|#:| |T|←|↵|}|↵|#trait| |Next|(||)|#:| |Simple| |{||}|↵|#trait| |TTT|‹|T|›|(||)| |{|→|#fun| |ttt|(|x|#:| |T|)|#:| |T|←|↵|}| -//│ Parsed: {trait IFoo() {let a: [] -> string; fun b: [] -> (x: number,) -> number; fun c: [] -> () -> ((false,) | (true,)); fun d: [] -> (x: string,) -> unit}; trait II‹T›() {fun test: [] -> (x: T,) -> number}; fun create: [] -> () -> {v: number}; fun get: [] -> (x: {t: string},) -> string; trait IEvent() {fun callback: [] -> () -> number -> unit}; trait SearchFunc() {fun __call: [] -> (source: string, subString: string,) -> ((false,) | (true,))}; trait StringArray() {fun __index: [] -> (index: number,) -> string}; trait Counter() {fun __call: [] -> (start: number,) -> string; let interval: [] -> number; fun reset: [] -> () -> unit}; trait Simple() {let a: [] -> number; fun b: [] -> (x: (false,) | (true,),) -> string}; trait Simple2‹T›() {let abc: [] -> T}; trait Next(): Simple {}; trait TTT‹T›() {fun ttt: [] -> (x: T,) -> T}} +//│ |#trait| |IFoo|(||)| |{|→|x|#:| |number|↵|#mut| |a|#:| |string|↵|#fun| |b|(|x|#:| |number|)|#:| |number|↵|#fun| |c|(||)|#:| |(|false|)| ||| |(|true|)|↵|#fun| |d|(|x|#:| |string|)|#:| |unit|←|↵|}|↵|#trait| |II|‹|T|›|(||)| |{|→|#fun| |test|(|x|#:| |T|)|#:| |number|←|↵|}|↵|#fun| |create|(||)|#:| |{|v|#:| |number|,|}|↵|#fun| |get|(|x|#:| |{|t|#:| |string|,|}|)|#:| |string|↵|#trait| |IEvent|(||)| |{|→|#fun| |callback|(||)|#:| |(|number|)| |=>| |unit|←|↵|}|↵|#trait| |SearchFunc|(||)| |{|→|#fun| |__call|(|source|#:| |string|,| |subString|#:| |string|)|#:| |(|false|)| ||| |(|true|)|←|↵|}|↵|#trait| |StringArray|(||)| |{|→|#fun| |__index|(|index|#:| |number|)|#:| |string|←|↵|}|↵|#trait| |Counter|(||)| |{|→|#fun| |__call|(|start|#:| |number|)|#:| |string|↵|#mut| |interval|#:| |number|↵|#fun| |reset|(||)|#:| |unit|←|↵|}|↵|#trait| |Simple|(||)| |{|→|#mut| |a|#:| |number|↵|#fun| |b|(|x|#:| |(|false|)| ||| |(|true|)|)|#:| |string|←|↵|}|↵|#trait| |Simple2|‹|T|›|(||)| |{|→|#mut| |abc|#:| |T|←|↵|}|↵|#trait| |Next|(||)|#:| |Simple| |{||}|↵|#trait| |TTT|‹|T|›|(||)| |{|→|#fun| |ttt|(|x|#:| |T|)|#:| |T|←|↵|}| +//│ ╔══[PARSE ERROR] Unexpected 'mut' keyword in expression position +//│ ║ l.5: mut a: string +//│ ╙── ^^^ +//│ ╔══[PARSE ERROR] Unexpected 'mut' keyword in expression position +//│ ║ l.26: mut interval: number +//│ ╙── ^^^ +//│ ╔══[PARSE ERROR] Unexpected 'mut' keyword in expression position +//│ ║ l.30: mut a: number +//│ ╙── ^^^ +//│ ╔══[PARSE ERROR] Unexpected 'mut' keyword in expression position +//│ ║ l.34: mut abc: T +//│ ╙── ^^^ +//│ Parsed: {trait IFoo() {x : TypeName(number); a : TypeName(string); fun b: [] -> (x: number,) -> number; fun c: [] -> () -> ((false,) | (true,)); fun d: [] -> (x: string,) -> unit}; trait II‹T›() {fun test: [] -> (x: T,) -> number}; fun create: [] -> () -> {v: number}; fun get: [] -> (x: {t: string},) -> string; trait IEvent() {fun callback: [] -> () -> number -> unit}; trait SearchFunc() {fun __call: [] -> (source: string, subString: string,) -> ((false,) | (true,))}; trait StringArray() {fun __index: [] -> (index: number,) -> string}; trait Counter() {fun __call: [] -> (start: number,) -> string; interval : TypeName(number); fun reset: [] -> () -> unit}; trait Simple() {a : TypeName(number); fun b: [] -> (x: (false,) | (true,),) -> string}; trait Simple2‹T›() {abc : TypeName(T)}; trait Next(): Simple {}; trait TTT‹T›() {fun ttt: [] -> (x: T,) -> T}} diff --git a/ts2mls/js/src/test/diff/Intersection.d.mls b/ts2mls/js/src/test/diff/Intersection.d.mls index c51034b18a..4e7fd211eb 100644 --- a/ts2mls/js/src/test/diff/Intersection.d.mls +++ b/ts2mls/js/src/test/diff/Intersection.d.mls @@ -4,10 +4,10 @@ fun extend(first: T, second: U): (T) & (U) fun foo(x: (T) & (U)): unit fun over(f: ((number) => string) & ((object) => string)): string trait IA() { - let x: number + mut x: number } trait IB() { - let y: number + mut y: number } fun iii(x: (IA) & (IB)): (IA) & (IB) fun uu(x: ((((U) & (T)) | ((U) & (P))) | ((V) & (T))) | ((V) & (P))): ((((U) & (T)) | ((U) & (P))) | ((V) & (T))) | ((V) & (P)) @@ -17,5 +17,11 @@ fun tt(x: ((U, T, )) & ((V, V, ))): ((U, T, )) & ((V, V, )) class A() {} class B() {} fun inter(c: (A) & (B)): (A) & (B) -//│ |#fun| |extend|‹|T|,| |U|›|(|first|#:| |T|,| |second|#:| |U|)|#:| |(|T|)| |&| |(|U|)|↵|#fun| |foo|‹|T|,| |U|›|(|x|#:| |(|T|)| |&| |(|U|)|)|#:| |unit|↵|#fun| |over|(|f|#:| |(|(|number|)| |=>| |string|)| |&| |(|(|object|)| |=>| |string|)|)|#:| |string|↵|#trait| |IA|(||)| |{|→|#let| |x|#:| |number|←|↵|}|↵|#trait| |IB|(||)| |{|→|#let| |y|#:| |number|←|↵|}|↵|#fun| |iii|(|x|#:| |(|IA|)| |&| |(|IB|)|)|#:| |(|IA|)| |&| |(|IB|)|↵|#fun| |uu|‹|U|,| |V|,| |T|,| |P|›|(|x|#:| |(|(|(|(|U|)| |&| |(|T|)|)| ||| |(|(|U|)| |&| |(|P|)|)|)| ||| |(|(|V|)| |&| |(|T|)|)|)| ||| |(|(|V|)| |&| |(|P|)|)|)|#:| |(|(|(|(|U|)| |&| |(|T|)|)| ||| |(|(|U|)| |&| |(|P|)|)|)| ||| |(|(|V|)| |&| |(|T|)|)|)| ||| |(|(|V|)| |&| |(|P|)|)|↵|#fun| |iiii|‹|U|,| |T|,| |V|›|(|x|#:| |(|(|U|)| |&| |(|T|)|)| |&| |(|V|)|)|#:| |(|(|U|)| |&| |(|T|)|)| |&| |(|V|)|↵|#fun| |arr|‹|U|,| |T|›|(|a|#:| |(|MutArray|‹|U|›|)| |&| |(|MutArray|‹|T|›|)|)|#:| |(|MutArray|‹|U|›|)| |&| |(|MutArray|‹|T|›|)|↵|#fun| |tt|‹|U|,| |T|,| |V|›|(|x|#:| |(|(|U|,| |T|,| |)|)| |&| |(|(|V|,| |V|,| |)|)|)|#:| |(|(|U|,| |T|,| |)|)| |&| |(|(|V|,| |V|,| |)|)|↵|#class| |A|(||)| |{||}|↵|#class| |B|(||)| |{||}|↵|#fun| |inter|(|c|#:| |(|A|)| |&| |(|B|)|)|#:| |(|A|)| |&| |(|B|)| -//│ Parsed: {fun extend: [] -> (first: T, second: U,) -> ((T,) & (U,)); fun foo: [] -> (x: (T,) & (U,),) -> unit; fun over: [] -> (f: (number -> string,) & (object -> string,),) -> string; trait IA() {let x: [] -> number}; trait IB() {let y: [] -> number}; fun iii: [] -> (x: (IA,) & (IB,),) -> ((IA,) & (IB,)); fun uu: [] -> (x: ((((U,) & (T,),) | ((U,) & (P,),),) | ((V,) & (T,),),) | ((V,) & (P,),),) -> (((((U,) & (T,),) | ((U,) & (P,),),) | ((V,) & (T,),),) | ((V,) & (P,),)); fun iiii: [] -> (x: ((U,) & (T,),) & (V,),) -> (((U,) & (T,),) & (V,)); fun arr: [] -> (a: (MutArray[U],) & (MutArray[T],),) -> ((MutArray[U],) & (MutArray[T],)); fun tt: [] -> (x: ((U, T,),) & ((V, V,),),) -> (((U, T,),) & ((V, V,),)); class A() {}; class B() {}; fun inter: [] -> (c: (A,) & (B,),) -> ((A,) & (B,))} +//│ |#fun| |extend|‹|T|,| |U|›|(|first|#:| |T|,| |second|#:| |U|)|#:| |(|T|)| |&| |(|U|)|↵|#fun| |foo|‹|T|,| |U|›|(|x|#:| |(|T|)| |&| |(|U|)|)|#:| |unit|↵|#fun| |over|(|f|#:| |(|(|number|)| |=>| |string|)| |&| |(|(|object|)| |=>| |string|)|)|#:| |string|↵|#trait| |IA|(||)| |{|→|#mut| |x|#:| |number|←|↵|}|↵|#trait| |IB|(||)| |{|→|#mut| |y|#:| |number|←|↵|}|↵|#fun| |iii|(|x|#:| |(|IA|)| |&| |(|IB|)|)|#:| |(|IA|)| |&| |(|IB|)|↵|#fun| |uu|‹|U|,| |V|,| |T|,| |P|›|(|x|#:| |(|(|(|(|U|)| |&| |(|T|)|)| ||| |(|(|U|)| |&| |(|P|)|)|)| ||| |(|(|V|)| |&| |(|T|)|)|)| ||| |(|(|V|)| |&| |(|P|)|)|)|#:| |(|(|(|(|U|)| |&| |(|T|)|)| ||| |(|(|U|)| |&| |(|P|)|)|)| ||| |(|(|V|)| |&| |(|T|)|)|)| ||| |(|(|V|)| |&| |(|P|)|)|↵|#fun| |iiii|‹|U|,| |T|,| |V|›|(|x|#:| |(|(|U|)| |&| |(|T|)|)| |&| |(|V|)|)|#:| |(|(|U|)| |&| |(|T|)|)| |&| |(|V|)|↵|#fun| |arr|‹|U|,| |T|›|(|a|#:| |(|MutArray|‹|U|›|)| |&| |(|MutArray|‹|T|›|)|)|#:| |(|MutArray|‹|U|›|)| |&| |(|MutArray|‹|T|›|)|↵|#fun| |tt|‹|U|,| |T|,| |V|›|(|x|#:| |(|(|U|,| |T|,| |)|)| |&| |(|(|V|,| |V|,| |)|)|)|#:| |(|(|U|,| |T|,| |)|)| |&| |(|(|V|,| |V|,| |)|)|↵|#class| |A|(||)| |{||}|↵|#class| |B|(||)| |{||}|↵|#fun| |inter|(|c|#:| |(|A|)| |&| |(|B|)|)|#:| |(|A|)| |&| |(|B|)| +//│ ╔══[PARSE ERROR] Unexpected 'mut' keyword in expression position +//│ ║ l.7: mut x: number +//│ ╙── ^^^ +//│ ╔══[PARSE ERROR] Unexpected 'mut' keyword in expression position +//│ ║ l.10: mut y: number +//│ ╙── ^^^ +//│ Parsed: {fun extend: [] -> (first: T, second: U,) -> ((T,) & (U,)); fun foo: [] -> (x: (T,) & (U,),) -> unit; fun over: [] -> (f: (number -> string,) & (object -> string,),) -> string; trait IA() {x : TypeName(number)}; trait IB() {y : TypeName(number)}; fun iii: [] -> (x: (IA,) & (IB,),) -> ((IA,) & (IB,)); fun uu: [] -> (x: ((((U,) & (T,),) | ((U,) & (P,),),) | ((V,) & (T,),),) | ((V,) & (P,),),) -> (((((U,) & (T,),) | ((U,) & (P,),),) | ((V,) & (T,),),) | ((V,) & (P,),)); fun iiii: [] -> (x: ((U,) & (T,),) & (V,),) -> (((U,) & (T,),) & (V,)); fun arr: [] -> (a: (MutArray[U],) & (MutArray[T],),) -> ((MutArray[U],) & (MutArray[T],)); fun tt: [] -> (x: ((U, T,),) & ((V, V,),),) -> (((U, T,),) & ((V, V,),)); class A() {}; class B() {}; fun inter: [] -> (c: (A,) & (B,),) -> ((A,) & (B,))} diff --git a/ts2mls/js/src/test/diff/MultiFiles.d.mls b/ts2mls/js/src/test/diff/MultiFiles.d.mls index 9e6b085056..315fa41eaa 100644 --- a/ts2mls/js/src/test/diff/MultiFiles.d.mls +++ b/ts2mls/js/src/test/diff/MultiFiles.d.mls @@ -4,7 +4,7 @@ fun multi1(x: number): number fun multi3(): unit class Foo(): Base {} trait AnotherBase() { - let y: string + mut y: string } namespace N { fun f(): unit @@ -14,9 +14,15 @@ namespace N { fun multi2(x: string): string fun multi4(): unit trait Base() { - let a: number + mut a: number } class AnotherFoo(): AnotherBase {} fun multi5(): unit -//│ |#fun| |multi1|(|x|#:| |number|)|#:| |number|↵|#fun| |multi3|(||)|#:| |unit|↵|#class| |Foo|(||)|#:| |Base| |{||}|↵|#trait| |AnotherBase|(||)| |{|→|#let| |y|#:| |string|←|↵|}|↵|#namespace| |N| |{|→|#fun| |f|(||)|#:| |unit|↵|#fun| |g|(||)|#:| |unit|↵|#fun| |h|(||)|#:| |unit|←|↵|}|↵|#fun| |multi2|(|x|#:| |string|)|#:| |string|↵|#fun| |multi4|(||)|#:| |unit|↵|#trait| |Base|(||)| |{|→|#let| |a|#:| |number|←|↵|}|↵|#class| |AnotherFoo|(||)|#:| |AnotherBase| |{||}|↵|#fun| |multi5|(||)|#:| |unit| -//│ Parsed: {fun multi1: [] -> (x: number,) -> number; fun multi3: [] -> () -> unit; class Foo(): Base {}; trait AnotherBase() {let y: [] -> string}; namespace N() {fun f: [] -> () -> unit; fun g: [] -> () -> unit; fun h: [] -> () -> unit}; fun multi2: [] -> (x: string,) -> string; fun multi4: [] -> () -> unit; trait Base() {let a: [] -> number}; class AnotherFoo(): AnotherBase {}; fun multi5: [] -> () -> unit} +//│ |#fun| |multi1|(|x|#:| |number|)|#:| |number|↵|#fun| |multi3|(||)|#:| |unit|↵|#class| |Foo|(||)|#:| |Base| |{||}|↵|#trait| |AnotherBase|(||)| |{|→|#mut| |y|#:| |string|←|↵|}|↵|#namespace| |N| |{|→|#fun| |f|(||)|#:| |unit|↵|#fun| |g|(||)|#:| |unit|↵|#fun| |h|(||)|#:| |unit|←|↵|}|↵|#fun| |multi2|(|x|#:| |string|)|#:| |string|↵|#fun| |multi4|(||)|#:| |unit|↵|#trait| |Base|(||)| |{|→|#mut| |a|#:| |number|←|↵|}|↵|#class| |AnotherFoo|(||)|#:| |AnotherBase| |{||}|↵|#fun| |multi5|(||)|#:| |unit| +//│ ╔══[PARSE ERROR] Unexpected 'mut' keyword in expression position +//│ ║ l.7: mut y: string +//│ ╙── ^^^ +//│ ╔══[PARSE ERROR] Unexpected 'mut' keyword in expression position +//│ ║ l.17: mut a: number +//│ ╙── ^^^ +//│ Parsed: {fun multi1: [] -> (x: number,) -> number; fun multi3: [] -> () -> unit; class Foo(): Base {}; trait AnotherBase() {y : TypeName(string)}; namespace N() {fun f: [] -> () -> unit; fun g: [] -> () -> unit; fun h: [] -> () -> unit}; fun multi2: [] -> (x: string,) -> string; fun multi4: [] -> () -> unit; trait Base() {a : TypeName(number)}; class AnotherFoo(): AnotherBase {}; fun multi5: [] -> () -> unit} diff --git a/ts2mls/js/src/test/diff/Optional.d.mls b/ts2mls/js/src/test/diff/Optional.d.mls index 91b5dcb849..7757c7e0e7 100644 --- a/ts2mls/js/src/test/diff/Optional.d.mls +++ b/ts2mls/js/src/test/diff/Optional.d.mls @@ -5,8 +5,8 @@ fun buildName2(firstName: string, lastName: (string) | (undefined)): string fun buildName3(firstName: string, lastName: MutArray): string fun buildName4(firstName: string, lastName: MutArray): string trait SquareConfig() { - let color: (string) | (undefined) - let width: (number) | (undefined) + mut color: (string) | (undefined) + mut width: (number) | (undefined) } fun did(x: number, f: ((number) => number) | (undefined)): number fun getOrElse(arr: (MutArray) | (undefined)): object @@ -17,8 +17,17 @@ fun err(msg: ((number, string, )) | (undefined)): unit fun toStr(x: (((number) | (false)) | (true)) | (undefined)): string fun boo(x: ((T) & (U)) | (undefined)): unit class B() { - let b: T + mut b: T } fun boom(b: (B) | (undefined)): anything -//│ |#fun| |buildName|(|firstName|#:| |string|,| |lastName|#:| |(|string|)| ||| |(|undefined|)|)|#:| |string|↵|#fun| |buildName2|(|firstName|#:| |string|,| |lastName|#:| |(|string|)| ||| |(|undefined|)|)|#:| |string|↵|#fun| |buildName3|(|firstName|#:| |string|,| |lastName|#:| |MutArray|‹|string|›|)|#:| |string|↵|#fun| |buildName4|(|firstName|#:| |string|,| |lastName|#:| |MutArray|‹|anything|›|)|#:| |string|↵|#trait| |SquareConfig|(||)| |{|→|#let| |color|#:| |(|string|)| ||| |(|undefined|)|↵|#let| |width|#:| |(|number|)| ||| |(|undefined|)|←|↵|}|↵|#fun| |did|(|x|#:| |number|,| |f|#:| |(|(|number|)| |=>| |number|)| ||| |(|undefined|)|)|#:| |number|↵|#fun| |getOrElse|(|arr|#:| |(|MutArray|‹|object|›|)| ||| |(|undefined|)|)|#:| |object|↵|#class| |ABC|(||)| |{||}|↵|#fun| |testABC|(|abc|#:| |(|ABC|)| ||| |(|undefined|)|)|#:| |unit|↵|#fun| |testSquareConfig|(|conf|#:| |(|SquareConfig|)| ||| |(|undefined|)|)|#:| |unit|↵|#fun| |err|(|msg|#:| |(|(|number|,| |string|,| |)|)| ||| |(|undefined|)|)|#:| |unit|↵|#fun| |toStr|(|x|#:| |(|(|(|number|)| ||| |(|false|)|)| ||| |(|true|)|)| ||| |(|undefined|)|)|#:| |string|↵|#fun| |boo|‹|T|,| |U|›|(|x|#:| |(|(|T|)| |&| |(|U|)|)| ||| |(|undefined|)|)|#:| |unit|↵|#class| |B|‹|T|›|(||)| |{|→|#let| |b|#:| |T|←|↵|}|↵|#fun| |boom|(|b|#:| |(|B|‹|nothing|›|)| ||| |(|undefined|)|)|#:| |anything| -//│ Parsed: {fun buildName: [] -> (firstName: string, lastName: (string,) | (undefined,),) -> string; fun buildName2: [] -> (firstName: string, lastName: (string,) | (undefined,),) -> string; fun buildName3: [] -> (firstName: string, lastName: MutArray[string],) -> string; fun buildName4: [] -> (firstName: string, lastName: MutArray[anything],) -> string; trait SquareConfig() {let color: [] -> (string,) | (undefined,); let width: [] -> (number,) | (undefined,)}; fun did: [] -> (x: number, f: (number -> number,) | (undefined,),) -> number; fun getOrElse: [] -> (arr: (MutArray[object],) | (undefined,),) -> object; class ABC() {}; fun testABC: [] -> (abc: (ABC,) | (undefined,),) -> unit; fun testSquareConfig: [] -> (conf: (SquareConfig,) | (undefined,),) -> unit; fun err: [] -> (msg: ((number, string,),) | (undefined,),) -> unit; fun toStr: [] -> (x: (((number,) | (false,),) | (true,),) | (undefined,),) -> string; fun boo: [] -> (x: ((T,) & (U,),) | (undefined,),) -> unit; class B‹T›() {let b: [] -> T}; fun boom: [] -> (b: (B[nothing],) | (undefined,),) -> anything} +//│ |#fun| |buildName|(|firstName|#:| |string|,| |lastName|#:| |(|string|)| ||| |(|undefined|)|)|#:| |string|↵|#fun| |buildName2|(|firstName|#:| |string|,| |lastName|#:| |(|string|)| ||| |(|undefined|)|)|#:| |string|↵|#fun| |buildName3|(|firstName|#:| |string|,| |lastName|#:| |MutArray|‹|string|›|)|#:| |string|↵|#fun| |buildName4|(|firstName|#:| |string|,| |lastName|#:| |MutArray|‹|anything|›|)|#:| |string|↵|#trait| |SquareConfig|(||)| |{|→|#mut| |color|#:| |(|string|)| ||| |(|undefined|)|↵|#mut| |width|#:| |(|number|)| ||| |(|undefined|)|←|↵|}|↵|#fun| |did|(|x|#:| |number|,| |f|#:| |(|(|number|)| |=>| |number|)| ||| |(|undefined|)|)|#:| |number|↵|#fun| |getOrElse|(|arr|#:| |(|MutArray|‹|object|›|)| ||| |(|undefined|)|)|#:| |object|↵|#class| |ABC|(||)| |{||}|↵|#fun| |testABC|(|abc|#:| |(|ABC|)| ||| |(|undefined|)|)|#:| |unit|↵|#fun| |testSquareConfig|(|conf|#:| |(|SquareConfig|)| ||| |(|undefined|)|)|#:| |unit|↵|#fun| |err|(|msg|#:| |(|(|number|,| |string|,| |)|)| ||| |(|undefined|)|)|#:| |unit|↵|#fun| |toStr|(|x|#:| |(|(|(|number|)| ||| |(|false|)|)| ||| |(|true|)|)| ||| |(|undefined|)|)|#:| |string|↵|#fun| |boo|‹|T|,| |U|›|(|x|#:| |(|(|T|)| |&| |(|U|)|)| ||| |(|undefined|)|)|#:| |unit|↵|#class| |B|‹|T|›|(||)| |{|→|#mut| |b|#:| |T|←|↵|}|↵|#fun| |boom|(|b|#:| |(|B|‹|nothing|›|)| ||| |(|undefined|)|)|#:| |anything| +//│ ╔══[PARSE ERROR] Unexpected 'mut' keyword in expression position +//│ ║ l.8: mut color: (string) | (undefined) +//│ ╙── ^^^ +//│ ╔══[PARSE ERROR] Unexpected 'mut' keyword in expression position +//│ ║ l.9: mut width: (number) | (undefined) +//│ ╙── ^^^ +//│ ╔══[PARSE ERROR] Unexpected 'mut' keyword in expression position +//│ ║ l.20: mut b: T +//│ ╙── ^^^ +//│ Parsed: {fun buildName: [] -> (firstName: string, lastName: (string,) | (undefined,),) -> string; fun buildName2: [] -> (firstName: string, lastName: (string,) | (undefined,),) -> string; fun buildName3: [] -> (firstName: string, lastName: MutArray[string],) -> string; fun buildName4: [] -> (firstName: string, lastName: MutArray[anything],) -> string; trait SquareConfig() {color : Union(Tuple(List((None,Field(None,TypeName(string))))),Tuple(List((None,Field(None,TypeName(undefined)))))); width : Union(Tuple(List((None,Field(None,TypeName(number))))),Tuple(List((None,Field(None,TypeName(undefined))))))}; fun did: [] -> (x: number, f: (number -> number,) | (undefined,),) -> number; fun getOrElse: [] -> (arr: (MutArray[object],) | (undefined,),) -> object; class ABC() {}; fun testABC: [] -> (abc: (ABC,) | (undefined,),) -> unit; fun testSquareConfig: [] -> (conf: (SquareConfig,) | (undefined,),) -> unit; fun err: [] -> (msg: ((number, string,),) | (undefined,),) -> unit; fun toStr: [] -> (x: (((number,) | (false,),) | (true,),) | (undefined,),) -> string; fun boo: [] -> (x: ((T,) & (U,),) | (undefined,),) -> unit; class B‹T›() {b : TypeName(T)}; fun boom: [] -> (b: (B[nothing],) | (undefined,),) -> anything} diff --git a/ts2mls/js/src/test/diff/Overload.d.mls b/ts2mls/js/src/test/diff/Overload.d.mls index ff3bd9007f..7e73b98a33 100644 --- a/ts2mls/js/src/test/diff/Overload.d.mls +++ b/ts2mls/js/src/test/diff/Overload.d.mls @@ -2,7 +2,7 @@ :ParseOnly fun f: ((number) => string) & ((string) => string) class M() { - let foo: ((number) => string) & ((string) => string) + mut foo: ((number) => string) & ((string) => string) } fun app: (((string) => unit) => (number) => unit) & (((string) => unit) => (string) => unit) fun create: ((number) => unit => (false) | (true)) & (((false) | (true)) => unit => (false) | (true)) @@ -22,5 +22,8 @@ class WWW() { fun F(x: T): anything /* warning: the overload of function F is not supported yet. */ } fun baz(): anything /* warning: the overload of function baz is not supported yet. */ -//│ |#fun| |f|#:| |(|(|number|)| |=>| |string|)| |&| |(|(|string|)| |=>| |string|)|↵|#class| |M|(||)| |{|→|#let| |foo|#:| |(|(|number|)| |=>| |string|)| |&| |(|(|string|)| |=>| |string|)|←|↵|}|↵|#fun| |app|#:| |(|(|(|string|)| |=>| |unit|)| |=>| |(|number|)| |=>| |unit|)| |&| |(|(|(|string|)| |=>| |unit|)| |=>| |(|string|)| |=>| |unit|)|↵|#fun| |create|#:| |(|(|number|)| |=>| |unit| |=>| |(|false|)| ||| |(|true|)|)| |&| |(|(|(|false|)| ||| |(|true|)|)| |=>| |unit| |=>| |(|false|)| ||| |(|true|)|)|↵|#fun| |g0|#:| |(|(|MutArray|‹|string|›|)| |=>| |string|)| |&| |(|(|MutArray|‹|object|›|)| |=>| |string|)|↵|#fun| |db|#:| |(|(|number|)| |=>| |MutArray|‹|number|›|)| |&| |(|(|object|)| |=>| |MutArray|‹|number|›|)|↵|#class| |N|(||)| |{||}|↵|#fun| |id|#:| |(|(|M|)| |=>| |unit|)| |&| |(|(|N|)| |=>| |unit|)|↵|#fun| |tst|#:| |(|(|{|z|#:| |number|,|}|)| |=>| |{|y|#:| |string|,|}|)| |&| |(|(|{|z|#:| |(|false|)| ||| |(|true|)|,|}|)| |=>| |{|y|#:| |string|,|}|)|↵|#fun| |op|#:| |(|(|number|)| |=>| |(|(|number|)| ||| |(|undefined|)|)| |=>| |unit|)| |&| |(|(|number|)| |=>| |(|(|(|false|)| ||| |(|true|)|)| ||| |(|undefined|)|)| |=>| |unit|)|↵|#fun| |swap|#:| |(|(|(|number|,| |string|,| |)|)| |=>| |(|number|,| |string|,| |)|)| |&| |(|(|(|string|,| |number|,| |)|)| |=>| |(|number|,| |string|,| |)|)|↵|#fun| |u|#:| |(|(|(|(|number|)| ||| |(|false|)|)| ||| |(|true|)|)| |=>| |string|)| |&| |(|(|object|)| |=>| |string|)|↵|#fun| |doSome|‹|T|,| |U|›|(|x|#:| |anything|)|#:| |unit| |/* warning: the overload of function doSome is not supported yet. */|↵|#namespace| |XX| |{|→|#fun| |f|‹|T|›|(|x|#:| |T|,| |n|#:| |anything|)|#:| |string| |/* warning: the overload of function f is not supported yet. */|←|↵|}|↵|#class| |WWW|(||)| |{|→|#fun| |F|‹|T|›|(|x|#:| |T|)|#:| |anything| |/* warning: the overload of function F is not supported yet. */|←|↵|}|↵|#fun| |baz|(||)|#:| |anything| |/* warning: the overload of function baz is not supported yet. */| -//│ Parsed: {fun f: [] -> (number -> string,) & (string -> string,); class M() {let foo: [] -> (number -> string,) & (string -> string,)}; fun app: [] -> ((string -> unit) -> number -> unit,) & ((string -> unit) -> string -> unit,); fun create: [] -> (number -> unit -> ((false,) | (true,)),) & (((false,) | (true,)) -> unit -> ((false,) | (true,)),); fun g0: [] -> (MutArray[string] -> string,) & (MutArray[object] -> string,); fun db: [] -> (number -> MutArray[number],) & (object -> MutArray[number],); class N() {}; fun id: [] -> (M -> unit,) & (N -> unit,); fun tst: [] -> ({z: number} -> {y: string},) & ({z: (false,) | (true,)} -> {y: string},); fun op: [] -> (number -> ((number,) | (undefined,)) -> unit,) & (number -> (((false,) | (true,),) | (undefined,)) -> unit,); fun swap: [] -> ((number, string,) -> (number, string,),) & ((string, number,) -> (number, string,),); fun u: [] -> ((((number,) | (false,),) | (true,)) -> string,) & (object -> string,); fun doSome: [] -> (x: anything,) -> unit; namespace XX() {fun f: [] -> (x: T, n: anything,) -> string}; class WWW() {fun F: [] -> (x: T,) -> anything}; fun baz: [] -> () -> anything} +//│ |#fun| |f|#:| |(|(|number|)| |=>| |string|)| |&| |(|(|string|)| |=>| |string|)|↵|#class| |M|(||)| |{|→|#mut| |foo|#:| |(|(|number|)| |=>| |string|)| |&| |(|(|string|)| |=>| |string|)|←|↵|}|↵|#fun| |app|#:| |(|(|(|string|)| |=>| |unit|)| |=>| |(|number|)| |=>| |unit|)| |&| |(|(|(|string|)| |=>| |unit|)| |=>| |(|string|)| |=>| |unit|)|↵|#fun| |create|#:| |(|(|number|)| |=>| |unit| |=>| |(|false|)| ||| |(|true|)|)| |&| |(|(|(|false|)| ||| |(|true|)|)| |=>| |unit| |=>| |(|false|)| ||| |(|true|)|)|↵|#fun| |g0|#:| |(|(|MutArray|‹|string|›|)| |=>| |string|)| |&| |(|(|MutArray|‹|object|›|)| |=>| |string|)|↵|#fun| |db|#:| |(|(|number|)| |=>| |MutArray|‹|number|›|)| |&| |(|(|object|)| |=>| |MutArray|‹|number|›|)|↵|#class| |N|(||)| |{||}|↵|#fun| |id|#:| |(|(|M|)| |=>| |unit|)| |&| |(|(|N|)| |=>| |unit|)|↵|#fun| |tst|#:| |(|(|{|z|#:| |number|,|}|)| |=>| |{|y|#:| |string|,|}|)| |&| |(|(|{|z|#:| |(|false|)| ||| |(|true|)|,|}|)| |=>| |{|y|#:| |string|,|}|)|↵|#fun| |op|#:| |(|(|number|)| |=>| |(|(|number|)| ||| |(|undefined|)|)| |=>| |unit|)| |&| |(|(|number|)| |=>| |(|(|(|false|)| ||| |(|true|)|)| ||| |(|undefined|)|)| |=>| |unit|)|↵|#fun| |swap|#:| |(|(|(|number|,| |string|,| |)|)| |=>| |(|number|,| |string|,| |)|)| |&| |(|(|(|string|,| |number|,| |)|)| |=>| |(|number|,| |string|,| |)|)|↵|#fun| |u|#:| |(|(|(|(|number|)| ||| |(|false|)|)| ||| |(|true|)|)| |=>| |string|)| |&| |(|(|object|)| |=>| |string|)|↵|#fun| |doSome|‹|T|,| |U|›|(|x|#:| |anything|)|#:| |unit| |/* warning: the overload of function doSome is not supported yet. */|↵|#namespace| |XX| |{|→|#fun| |f|‹|T|›|(|x|#:| |T|,| |n|#:| |anything|)|#:| |string| |/* warning: the overload of function f is not supported yet. */|←|↵|}|↵|#class| |WWW|(||)| |{|→|#fun| |F|‹|T|›|(|x|#:| |T|)|#:| |anything| |/* warning: the overload of function F is not supported yet. */|←|↵|}|↵|#fun| |baz|(||)|#:| |anything| |/* warning: the overload of function baz is not supported yet. */| +//│ ╔══[PARSE ERROR] Unexpected 'mut' keyword in expression position +//│ ║ l.5: mut foo: ((number) => string) & ((string) => string) +//│ ╙── ^^^ +//│ Parsed: {fun f: [] -> (number -> string,) & (string -> string,); class M() {foo : Inter(Tuple(List((None,Field(None,Function(Tuple(List((None,Field(None,TypeName(number))))),TypeName(string)))))),Tuple(List((None,Field(None,Function(Tuple(List((None,Field(None,TypeName(string))))),TypeName(string)))))))}; fun app: [] -> ((string -> unit) -> number -> unit,) & ((string -> unit) -> string -> unit,); fun create: [] -> (number -> unit -> ((false,) | (true,)),) & (((false,) | (true,)) -> unit -> ((false,) | (true,)),); fun g0: [] -> (MutArray[string] -> string,) & (MutArray[object] -> string,); fun db: [] -> (number -> MutArray[number],) & (object -> MutArray[number],); class N() {}; fun id: [] -> (M -> unit,) & (N -> unit,); fun tst: [] -> ({z: number} -> {y: string},) & ({z: (false,) | (true,)} -> {y: string},); fun op: [] -> (number -> ((number,) | (undefined,)) -> unit,) & (number -> (((false,) | (true,),) | (undefined,)) -> unit,); fun swap: [] -> ((number, string,) -> (number, string,),) & ((string, number,) -> (number, string,),); fun u: [] -> ((((number,) | (false,),) | (true,)) -> string,) & (object -> string,); fun doSome: [] -> (x: anything,) -> unit; namespace XX() {fun f: [] -> (x: T, n: anything,) -> string}; class WWW() {fun F: [] -> (x: T,) -> anything}; fun baz: [] -> () -> anything} diff --git a/ts2mls/js/src/test/diff/Tuple.d.mls b/ts2mls/js/src/test/diff/Tuple.d.mls index 473cc3b7a1..bcc341c470 100644 --- a/ts2mls/js/src/test/diff/Tuple.d.mls +++ b/ts2mls/js/src/test/diff/Tuple.d.mls @@ -12,9 +12,12 @@ fun ex(x: T, y: U): (T, U, (T) & (U), ) fun foo(x: ((T) & (U), )): unit fun conv(x: {y: number,}): ({y: number,}, {z: string,}, ) class A() { - let x: number + mut x: number } class B() {} fun swap(x: (A, B, )): (B, A, ) -//│ |#fun| |key|(|x|#:| |(|string|,| |(|false|)| ||| |(|true|)|,| |)|)|#:| |string|↵|#fun| |value|(|x|#:| |(|string|,| |(|false|)| ||| |(|true|)|,| |)|)|#:| |(|false|)| ||| |(|true|)|↵|#fun| |third|(|x|#:| |(|number|,| |number|,| |number|,| |)|)|#:| |number|↵|#fun| |vec2|(|x|#:| |number|,| |y|#:| |number|)|#:| |(|number|,| |number|,| |)|↵|#fun| |twoFunctions|(|ff|#:| |(|(|number|)| |=>| |number|,| |(|number|)| |=>| |number|,| |)|,| |x|#:| |number|)|#:| |number|↵|#fun| |tupleIt|(|x|#:| |string|)|#:| |(|unit| |=>| |string|,| |)|↵|#fun| |s|(|flag|#:| |(|false|)| ||| |(|true|)|)|#:| |(|(|string|)| ||| |(|number|)|,| |(|(|number|)| ||| |(|false|)|)| ||| |(|true|)|,| |)|↵|#fun| |s2|(|t|#:| |(|(|false|)| ||| |(|true|)|,| |(|string|)| ||| |(|number|)|,| |)|)|#:| |(|string|)| ||| |(|number|)|↵|#fun| |ex|‹|T|,| |U|›|(|x|#:| |T|,| |y|#:| |U|)|#:| |(|T|,| |U|,| |(|T|)| |&| |(|U|)|,| |)|↵|#fun| |foo|‹|T|,| |U|›|(|x|#:| |(|(|T|)| |&| |(|U|)|,| |)|)|#:| |unit|↵|#fun| |conv|(|x|#:| |{|y|#:| |number|,|}|)|#:| |(|{|y|#:| |number|,|}|,| |{|z|#:| |string|,|}|,| |)|↵|#class| |A|(||)| |{|→|#let| |x|#:| |number|←|↵|}|↵|#class| |B|(||)| |{||}|↵|#fun| |swap|(|x|#:| |(|A|,| |B|,| |)|)|#:| |(|B|,| |A|,| |)| -//│ Parsed: {fun key: [] -> (x: (string, (false,) | (true,),),) -> string; fun value: [] -> (x: (string, (false,) | (true,),),) -> ((false,) | (true,)); fun third: [] -> (x: (number, number, number,),) -> number; fun vec2: [] -> (x: number, y: number,) -> (number, number,); fun twoFunctions: [] -> (ff: (number -> number, number -> number,), x: number,) -> number; fun tupleIt: [] -> (x: string,) -> (unit -> string,); fun s: [] -> (flag: (false,) | (true,),) -> ((string,) | (number,), ((number,) | (false,),) | (true,),); fun s2: [] -> (t: ((false,) | (true,), (string,) | (number,),),) -> ((string,) | (number,)); fun ex: [] -> (x: T, y: U,) -> (T, U, (T,) & (U,),); fun foo: [] -> (x: ((T,) & (U,),),) -> unit; fun conv: [] -> (x: {y: number},) -> ({y: number}, {z: string},); class A() {let x: [] -> number}; class B() {}; fun swap: [] -> (x: (A, B,),) -> (B, A,)} +//│ |#fun| |key|(|x|#:| |(|string|,| |(|false|)| ||| |(|true|)|,| |)|)|#:| |string|↵|#fun| |value|(|x|#:| |(|string|,| |(|false|)| ||| |(|true|)|,| |)|)|#:| |(|false|)| ||| |(|true|)|↵|#fun| |third|(|x|#:| |(|number|,| |number|,| |number|,| |)|)|#:| |number|↵|#fun| |vec2|(|x|#:| |number|,| |y|#:| |number|)|#:| |(|number|,| |number|,| |)|↵|#fun| |twoFunctions|(|ff|#:| |(|(|number|)| |=>| |number|,| |(|number|)| |=>| |number|,| |)|,| |x|#:| |number|)|#:| |number|↵|#fun| |tupleIt|(|x|#:| |string|)|#:| |(|unit| |=>| |string|,| |)|↵|#fun| |s|(|flag|#:| |(|false|)| ||| |(|true|)|)|#:| |(|(|string|)| ||| |(|number|)|,| |(|(|number|)| ||| |(|false|)|)| ||| |(|true|)|,| |)|↵|#fun| |s2|(|t|#:| |(|(|false|)| ||| |(|true|)|,| |(|string|)| ||| |(|number|)|,| |)|)|#:| |(|string|)| ||| |(|number|)|↵|#fun| |ex|‹|T|,| |U|›|(|x|#:| |T|,| |y|#:| |U|)|#:| |(|T|,| |U|,| |(|T|)| |&| |(|U|)|,| |)|↵|#fun| |foo|‹|T|,| |U|›|(|x|#:| |(|(|T|)| |&| |(|U|)|,| |)|)|#:| |unit|↵|#fun| |conv|(|x|#:| |{|y|#:| |number|,|}|)|#:| |(|{|y|#:| |number|,|}|,| |{|z|#:| |string|,|}|,| |)|↵|#class| |A|(||)| |{|→|#mut| |x|#:| |number|←|↵|}|↵|#class| |B|(||)| |{||}|↵|#fun| |swap|(|x|#:| |(|A|,| |B|,| |)|)|#:| |(|B|,| |A|,| |)| +//│ ╔══[PARSE ERROR] Unexpected 'mut' keyword in expression position +//│ ║ l.15: mut x: number +//│ ╙── ^^^ +//│ Parsed: {fun key: [] -> (x: (string, (false,) | (true,),),) -> string; fun value: [] -> (x: (string, (false,) | (true,),),) -> ((false,) | (true,)); fun third: [] -> (x: (number, number, number,),) -> number; fun vec2: [] -> (x: number, y: number,) -> (number, number,); fun twoFunctions: [] -> (ff: (number -> number, number -> number,), x: number,) -> number; fun tupleIt: [] -> (x: string,) -> (unit -> string,); fun s: [] -> (flag: (false,) | (true,),) -> ((string,) | (number,), ((number,) | (false,),) | (true,),); fun s2: [] -> (t: ((false,) | (true,), (string,) | (number,),),) -> ((string,) | (number,)); fun ex: [] -> (x: T, y: U,) -> (T, U, (T,) & (U,),); fun foo: [] -> (x: ((T,) & (U,),),) -> unit; fun conv: [] -> (x: {y: number},) -> ({y: number}, {z: string},); class A() {x : TypeName(number)}; class B() {}; fun swap: [] -> (x: (A, B,),) -> (B, A,)} diff --git a/ts2mls/js/src/test/diff/Type.d.mls b/ts2mls/js/src/test/diff/Type.d.mls index 517963c11a..4089112705 100644 --- a/ts2mls/js/src/test/diff/Type.d.mls +++ b/ts2mls/js/src/test/diff/Type.d.mls @@ -1,11 +1,11 @@ :NewParser :ParseOnly trait None() { - let _tag: "None" + _tag: "None" } trait Some() { - let _tag: "Some" - let value: A + _tag: "Some" + value: A } type Option = (None) | (Some) type Func = (number) => number @@ -23,10 +23,13 @@ namespace NA { type B = string } class NC() { - let b: string + mut b: string } type G = ABC let none: {_tag: "None",} fun some(a: A): (None) | (Some) -//│ |#trait| |None|(||)| |{|→|#let| |_tag|#:| |"None"|←|↵|}|↵|#trait| |Some|‹|A|›|(||)| |{|→|#let| |_tag|#:| |"Some"|↵|#let| |value|#:| |A|←|↵|}|↵|#type| |Option|‹|A|›| |#=| |(|None|)| ||| |(|Some|‹|A|›|)|↵|#type| |Func| |#=| |(|number|)| |=>| |number|↵|#type| |S2| |#=| |(|string|,| |string|,| |)|↵|#trait| |I1|(||)| |{||}|↵|#trait| |I2|(||)| |{||}|↵|#type| |I3| |#=| |(|I1|)| |&| |(|I2|)|↵|#type| |StringArray| |#=| |Array|‹|string|›|↵|#type| |SomeInterface| |#=| |{|x|#:| |number|,|y|#:| |number|,|}|↵|#class| |ABC|(||)| |{||}|↵|#type| |DEF| |#=| |ABC|↵|#type| |TP|‹|A|,| |B|,| |C|›| |#=| |(|A|,| |B|,| |C|,| |)|↵|#namespace| |NA| |{|→|#fun| |fb|(|b|#:| |string|)|#:| |unit|↵|#type| |B| |#=| |string|←|↵|}|↵|#class| |NC|(||)| |{|→|#let| |b|#:| |string|←|↵|}|↵|#type| |G| |#=| |ABC|↵|#let| |none|#:| |{|_tag|#:| |"None"|,|}|↵|#fun| |some|‹|A|›|(|a|#:| |A|)|#:| |(|None|)| ||| |(|Some|‹|A|›|)| -//│ Parsed: {trait None() {let _tag: [] -> "None"}; trait Some‹A›() {let _tag: [] -> "Some"; let value: [] -> A}; type alias Option‹A›() = | (None,) (Some‹A›,) {}; type alias Func() = number, => number {}; type alias S2() = '(' string, string, ')' {}; trait I1() {}; trait I2() {}; type alias I3() = & (I1,) (I2,) {}; type alias StringArray() = Array‹string› {}; type alias SomeInterface() = '{' {x: number, y: number} '}' {}; class ABC() {}; type alias DEF() = ABC {}; type alias TP‹A, B, C›() = '(' A, B, C, ')' {}; namespace NA() {fun fb: [] -> (b: string,) -> unit; type alias B() = string {}}; class NC() {let b: [] -> string}; type alias G() = ABC {}; let none: [] -> {_tag: "None"}; fun some: [] -> (a: A,) -> ((None,) | (Some[A],))} +//│ |#trait| |None|(||)| |{|→|_tag|#:| |"None"|←|↵|}|↵|#trait| |Some|‹|A|›|(||)| |{|→|_tag|#:| |"Some"|↵|value|#:| |A|←|↵|}|↵|#type| |Option|‹|A|›| |#=| |(|None|)| ||| |(|Some|‹|A|›|)|↵|#type| |Func| |#=| |(|number|)| |=>| |number|↵|#type| |S2| |#=| |(|string|,| |string|,| |)|↵|#trait| |I1|(||)| |{||}|↵|#trait| |I2|(||)| |{||}|↵|#type| |I3| |#=| |(|I1|)| |&| |(|I2|)|↵|#type| |StringArray| |#=| |Array|‹|string|›|↵|#type| |SomeInterface| |#=| |{|x|#:| |number|,|y|#:| |number|,|}|↵|#class| |ABC|(||)| |{||}|↵|#type| |DEF| |#=| |ABC|↵|#type| |TP|‹|A|,| |B|,| |C|›| |#=| |(|A|,| |B|,| |C|,| |)|↵|#namespace| |NA| |{|→|#fun| |fb|(|b|#:| |string|)|#:| |unit|↵|#type| |B| |#=| |string|←|↵|}|↵|#class| |NC|(||)| |{|→|#mut| |b|#:| |string|←|↵|}|↵|#type| |G| |#=| |ABC|↵|#let| |none|#:| |{|_tag|#:| |"None"|,|}|↵|#fun| |some|‹|A|›|(|a|#:| |A|)|#:| |(|None|)| ||| |(|Some|‹|A|›|)| +//│ ╔══[PARSE ERROR] Unexpected 'mut' keyword in expression position +//│ ║ l.26: mut b: string +//│ ╙── ^^^ +//│ Parsed: {trait None() {_tag : Literal("None")}; trait Some‹A›() {_tag : Literal("Some"); value : TypeName(A)}; type alias Option‹A›() = | (None,) (Some‹A›,) {}; type alias Func() = number, => number {}; type alias S2() = '(' string, string, ')' {}; trait I1() {}; trait I2() {}; type alias I3() = & (I1,) (I2,) {}; type alias StringArray() = Array‹string› {}; type alias SomeInterface() = '{' {x: number, y: number} '}' {}; class ABC() {}; type alias DEF() = ABC {}; type alias TP‹A, B, C›() = '(' A, B, C, ')' {}; namespace NA() {fun fb: [] -> (b: string,) -> unit; type alias B() = string {}}; class NC() {b : TypeName(string)}; type alias G() = ABC {}; let none: [] -> {_tag: "None"}; fun some: [] -> (a: A,) -> ((None,) | (Some[A],))} diff --git a/ts2mls/js/src/test/diff/TypeParameter.d.mls b/ts2mls/js/src/test/diff/TypeParameter.d.mls index 48a2e0837a..1a0e956c6d 100644 --- a/ts2mls/js/src/test/diff/TypeParameter.d.mls +++ b/ts2mls/js/src/test/diff/TypeParameter.d.mls @@ -13,11 +13,11 @@ fun getStringPrinter(): Printer fun foo(p: Printer, x: T): T fun foo2(p: Printer, x: T): T class F() { - let x: T + mut x: T fun GG(y: U): T } trait I() { - let x: T + mut x: T fun GG(y: U): T } class FFF() { @@ -25,5 +25,11 @@ class FFF() { } fun fff(p: FFF, s: string): unit fun getFFF(): FFF -//│ |#fun| |inc|‹|T|›|(|x|#:| |T|)|#:| |number|↵|#class| |CC|‹|T|›|(||)| |{|→|#fun| |print|(|s|#:| |T|)|#:| |unit|←|↵|}|↵|#fun| |con|‹|U|,| |T|›|(|t|#:| |T|)|#:| |U|↵|#class| |Printer|‹|T|›|(||)| |{|→|#fun| |print|(|t|#:| |T|)|#:| |unit|←|↵|}|↵|#fun| |setStringPrinter|(|p|#:| |Printer|‹|string|›|)|#:| |unit|↵|#fun| |getStringPrinter|(||)|#:| |Printer|‹|string|›|↵|#fun| |foo|‹|T|›|(|p|#:| |Printer|‹|T|›|,| |x|#:| |T|)|#:| |T|↵|#fun| |foo2|‹|T|›|(|p|#:| |Printer|‹|T|›|,| |x|#:| |T|)|#:| |T|↵|#class| |F|‹|T|›|(||)| |{|→|#let| |x|#:| |T|↵|#fun| |GG|‹|U|›|(|y|#:| |U|)|#:| |T|←|↵|}|↵|#trait| |I|‹|T|›|(||)| |{|→|#let| |x|#:| |T|↵|#fun| |GG|‹|U|›|(|y|#:| |U|)|#:| |T|←|↵|}|↵|#class| |FFF|‹|T|›|(||)| |{|→|#fun| |fff|(|x|#:| |T|)|#:| |unit|←|↵|}|↵|#fun| |fff|(|p|#:| |FFF|‹|string|›|,| |s|#:| |string|)|#:| |unit|↵|#fun| |getFFF|(||)|#:| |FFF|‹|number|›| -//│ Parsed: {fun inc: [] -> (x: T,) -> number; class CC‹T›() {fun print: [] -> (s: T,) -> unit}; fun con: [] -> (t: T,) -> U; class Printer‹T›() {fun print: [] -> (t: T,) -> unit}; fun setStringPrinter: [] -> (p: Printer[string],) -> unit; fun getStringPrinter: [] -> () -> Printer[string]; fun foo: [] -> (p: Printer[T], x: T,) -> T; fun foo2: [] -> (p: Printer[T], x: T,) -> T; class F‹T›() {let x: [] -> T; fun GG: [] -> (y: U,) -> T}; trait I‹T›() {let x: [] -> T; fun GG: [] -> (y: U,) -> T}; class FFF‹T›() {fun fff: [] -> (x: T,) -> unit}; fun fff: [] -> (p: FFF[string], s: string,) -> unit; fun getFFF: [] -> () -> FFF[number]} +//│ |#fun| |inc|‹|T|›|(|x|#:| |T|)|#:| |number|↵|#class| |CC|‹|T|›|(||)| |{|→|#fun| |print|(|s|#:| |T|)|#:| |unit|←|↵|}|↵|#fun| |con|‹|U|,| |T|›|(|t|#:| |T|)|#:| |U|↵|#class| |Printer|‹|T|›|(||)| |{|→|#fun| |print|(|t|#:| |T|)|#:| |unit|←|↵|}|↵|#fun| |setStringPrinter|(|p|#:| |Printer|‹|string|›|)|#:| |unit|↵|#fun| |getStringPrinter|(||)|#:| |Printer|‹|string|›|↵|#fun| |foo|‹|T|›|(|p|#:| |Printer|‹|T|›|,| |x|#:| |T|)|#:| |T|↵|#fun| |foo2|‹|T|›|(|p|#:| |Printer|‹|T|›|,| |x|#:| |T|)|#:| |T|↵|#class| |F|‹|T|›|(||)| |{|→|#mut| |x|#:| |T|↵|#fun| |GG|‹|U|›|(|y|#:| |U|)|#:| |T|←|↵|}|↵|#trait| |I|‹|T|›|(||)| |{|→|#mut| |x|#:| |T|↵|#fun| |GG|‹|U|›|(|y|#:| |U|)|#:| |T|←|↵|}|↵|#class| |FFF|‹|T|›|(||)| |{|→|#fun| |fff|(|x|#:| |T|)|#:| |unit|←|↵|}|↵|#fun| |fff|(|p|#:| |FFF|‹|string|›|,| |s|#:| |string|)|#:| |unit|↵|#fun| |getFFF|(||)|#:| |FFF|‹|number|›| +//│ ╔══[PARSE ERROR] Unexpected 'mut' keyword in expression position +//│ ║ l.16: mut x: T +//│ ╙── ^^^ +//│ ╔══[PARSE ERROR] Unexpected 'mut' keyword in expression position +//│ ║ l.20: mut x: T +//│ ╙── ^^^ +//│ Parsed: {fun inc: [] -> (x: T,) -> number; class CC‹T›() {fun print: [] -> (s: T,) -> unit}; fun con: [] -> (t: T,) -> U; class Printer‹T›() {fun print: [] -> (t: T,) -> unit}; fun setStringPrinter: [] -> (p: Printer[string],) -> unit; fun getStringPrinter: [] -> () -> Printer[string]; fun foo: [] -> (p: Printer[T], x: T,) -> T; fun foo2: [] -> (p: Printer[T], x: T,) -> T; class F‹T›() {x : TypeName(T); fun GG: [] -> (y: U,) -> T}; trait I‹T›() {x : TypeName(T); fun GG: [] -> (y: U,) -> T}; class FFF‹T›() {fun fff: [] -> (x: T,) -> unit}; fun fff: [] -> (p: FFF[string], s: string,) -> unit; fun getFFF: [] -> () -> FFF[number]} diff --git a/ts2mls/js/src/test/diff/Variables.d.mls b/ts2mls/js/src/test/diff/Variables.d.mls index 9b3eb52dbf..29bb88b3b9 100644 --- a/ts2mls/js/src/test/diff/Variables.d.mls +++ b/ts2mls/js/src/test/diff/Variables.d.mls @@ -1,18 +1,18 @@ :NewParser :ParseOnly -let URI: string +let URI: {mut contents: string} let URI2: string let foo: number -let bar: false +let bar: {mut contents: false} class FooBar() {} -let fb: FooBar +let fb: {mut contents: FooBar} namespace ABC { class DEF() {} } -let d: ABC.DEF +let d: {mut contents: ABC.DEF} namespace DD { - let foo: number - let bar: number + let foo: {mut contents: number} + let bar: {mut contents: number} } -//│ |#let| |URI|#:| |string|↵|#let| |URI2|#:| |string|↵|#let| |foo|#:| |number|↵|#let| |bar|#:| |false|↵|#class| |FooBar|(||)| |{||}|↵|#let| |fb|#:| |FooBar|↵|#namespace| |ABC| |{|→|#class| |DEF|(||)| |{||}|←|↵|}|↵|#let| |d|#:| |ABC|.DEF|↵|#namespace| |DD| |{|→|#let| |foo|#:| |number|↵|#let| |bar|#:| |number|←|↵|}| -//│ Parsed: {let URI: [] -> string; let URI2: [] -> string; let foo: [] -> number; let bar: [] -> false; class FooBar() {}; let fb: [] -> FooBar; namespace ABC() {class DEF() {}}; let d: [] -> ABC.DEF; namespace DD() {let foo: [] -> number; let bar: [] -> number}} +//│ |#let| |URI|#:| |{|#mut| |contents|#:| |string|}|↵|#let| |URI2|#:| |string|↵|#let| |foo|#:| |number|↵|#let| |bar|#:| |{|#mut| |contents|#:| |false|}|↵|#class| |FooBar|(||)| |{||}|↵|#let| |fb|#:| |{|#mut| |contents|#:| |FooBar|}|↵|#namespace| |ABC| |{|→|#class| |DEF|(||)| |{||}|←|↵|}|↵|#let| |d|#:| |{|#mut| |contents|#:| |ABC|.DEF|}|↵|#namespace| |DD| |{|→|#let| |foo|#:| |{|#mut| |contents|#:| |number|}|↵|#let| |bar|#:| |{|#mut| |contents|#:| |number|}|←|↵|}| +//│ Parsed: {let URI: [] -> {mut contents: string}; let URI2: [] -> string; let foo: [] -> number; let bar: [] -> {mut contents: false}; class FooBar() {}; let fb: [] -> {mut contents: FooBar}; namespace ABC() {class DEF() {}}; let d: [] -> {mut contents: ABC.DEF}; namespace DD() {let foo: [] -> {mut contents: number}; let bar: [] -> {mut contents: number}}} diff --git a/ts2mls/js/src/test/typescript/ClassMember.ts b/ts2mls/js/src/test/typescript/ClassMember.ts index da45f741b0..31d4bdbd4a 100644 --- a/ts2mls/js/src/test/typescript/ClassMember.ts +++ b/ts2mls/js/src/test/typescript/ClassMember.ts @@ -1,7 +1,10 @@ class Student { name: string + readonly something: string - constructor(s: string, age: number) {} + constructor(s: string, age: number) { + this.something = "abc" + } getID() { return 114514; } diff --git a/ts2mls/js/src/test/typescript/InterfaceMember.ts b/ts2mls/js/src/test/typescript/InterfaceMember.ts index b6f057fd5a..0788564466 100644 --- a/ts2mls/js/src/test/typescript/InterfaceMember.ts +++ b/ts2mls/js/src/test/typescript/InterfaceMember.ts @@ -3,6 +3,7 @@ interface IFoo { b: (x: number) => number c: () => boolean d: (x: string) => void + readonly x: number } interface II {