import {CompilationTargetId} from "../../types/CompilationTargetId"; import {ChunkType} from "../chunks/types/ChunkType"; import {ScriptChunk} from "../chunks/types/ScriptChunk"; import {scriptChunkToScriptDef} from "./scriptChunkToScriptDef"; describe("scriptChunkToScriptDef()", () => { it("should convert script chunk to script definition", () => { const scriptChunk: ScriptChunk = { "offset": { "line": 0, "column": 0 }, "type": ChunkType.Script, "children": [ { "offset": { "line": 7, "column": 0 }, "type": ChunkType.Node, "children": [ { "offset": { "line": 8, "column": 2 }, "type": ChunkType.About, "children": [], "content": "Prints \"Hello, World!\" on the console.", "captures": [ "about" ] }, { "offset": { "line": 10, "column": 2 }, "type": ChunkType.NodeImpl, "children": [ { "offset": { "line": 11, "column": 4 }, "type": ChunkType.ChildNodes, "children": [ { "offset": { "line": 12, "column": 6 }, "type": ChunkType.ChildNodesItem, "captures": [ "(start program):(core).(Start)", { "type": ChunkType.NodeDecl, "captures": [ "(start program):(core).(Start)", { "type": ChunkType.Identifier, "captures": [ "(start program)" ], "offset": { "line": 12, "column": 6 } }, { "type": ChunkType.Identifier, "captures": [ "(Start)" ], "offset": { "line": 12, "column": 6 } } ], "offset": { "line": 12, "column": 6 } } ] }, { "offset": { "line": 13, "column": 6 }, "type": ChunkType.ChildNodesItem, "children": [ { "offset": { "line": 14, "column": 8 }, "type": ChunkType.NodeParam, "captures": [ "param (value) = \"Hello, World!\"", { "type": ChunkType.VarAssignment, "captures": [ "(value) = \"Hello, World!\"", { "type": ChunkType.Identifier, "captures": [ "(value)" ], "offset": { "line": 14, "column": 8 } }, { "type": ChunkType.Any, "captures": [ "\"Hello, World!\"" ], "offset": { "line": 14, "column": 8 } } ], "offset": { "line": 14, "column": 8 } } ] } ], "content": "param (value) = \"Hello, World!\"", "captures": [ "(send \"Hello, World!\"):(core).(Value)", { "type": ChunkType.NodeDecl, "captures": [ "(send \"Hello, World!\"):(core).(Value)", { "type": ChunkType.Identifier, "captures": [ "(send \"Hello, World!\")" ], "offset": { "line": 13, "column": 6 } }, { "type": ChunkType.Identifier, "captures": [ "(Value)" ], "offset": { "line": 13, "column": 6 } } ], "offset": { "line": 13, "column": 6 } } ] }, { "offset": { "line": 15, "column": 6 }, "type": ChunkType.ChildNodesItem, "captures": [ "(log to console):(console).(Console Log)", { "type": ChunkType.NodeDecl, "captures": [ "(log to console):(console).(Console Log)", { "type": ChunkType.Identifier, "captures": [ "(log to console)" ], "offset": { "line": 15, "column": 6 } }, { "type": ChunkType.Identifier, "captures": [ "(Console Log)" ], "offset": { "line": 15, "column": 6 } } ], "offset": { "line": 15, "column": 6 } } ] } ], "content": "(start program):(core).(Start)\n(send \"Hello, World!\"):(core).(Value)\n param (value) = \"Hello, World!\"\n(log to console):(console).(Console Log)", "captures": [ "children" ] }, { "offset": { "line": 16, "column": 4 }, "type": ChunkType.Connections, "children": [ { "offset": { "line": 17, "column": 6 }, "type": ChunkType.ConnectionsItem, "captures": [ "(start program).out.(start) and (send \"Hello, World!\").in.(start)", { "type": ChunkType.ConnectionBody, "captures": [ "(start program).out.(start) and (send \"Hello, World!\").in.(start)", { "type": ChunkType.ChildPort, "captures": [ "(start program).out.(start)", { "type": ChunkType.Identifier, "captures": [ "(start program)" ], "offset": { "line": 17, "column": 6 } }, { "type": ChunkType.ChildPortDirection, "captures": [ "out" ], "offset": { "line": 17, "column": 6 } }, { "type": ChunkType.Identifier, "captures": [ "(start)" ], "offset": { "line": 17, "column": 6 } } ], "offset": { "line": 17, "column": 6 } }, { "type": ChunkType.ChildPort, "captures": [ "(send \"Hello, World!\").in.(start)", { "type": ChunkType.Identifier, "captures": [ "(send \"Hello, World!\")" ], "offset": { "line": 17, "column": 6 } }, { "type": ChunkType.ChildPortDirection, "captures": [ "in" ], "offset": { "line": 17, "column": 6 } }, { "type": ChunkType.Identifier, "captures": [ "(start)" ], "offset": { "line": 17, "column": 6 } } ], "offset": { "line": 17, "column": 6 } } ], "offset": { "line": 17, "column": 6 } } ] }, { "offset": { "line": 18, "column": 6 }, "type": ChunkType.ConnectionsItem, "captures": [ "(send \"Hello, World!\").out.(value) and (log to console).in.(value)", { "type": ChunkType.ConnectionBody, "captures": [ "(send \"Hello, World!\").out.(value) and (log to console).in.(value)", { "type": ChunkType.ChildPort, "captures": [ "(send \"Hello, World!\").out.(value)", { "type": ChunkType.Identifier, "captures": [ "(send \"Hello, World!\")" ], "offset": { "line": 18, "column": 6 } }, { "type": ChunkType.ChildPortDirection, "captures": [ "out" ], "offset": { "line": 18, "column": 6 } }, { "type": ChunkType.Identifier, "captures": [ "(value)" ], "offset": { "line": 18, "column": 6 } } ], "offset": { "line": 18, "column": 6 } }, { "type": ChunkType.ChildPort, "captures": [ "(log to console).in.(value)", { "type": ChunkType.Identifier, "captures": [ "(log to console)" ], "offset": { "line": 18, "column": 6 } }, { "type": ChunkType.ChildPortDirection, "captures": [ "in" ], "offset": { "line": 18, "column": 6 } }, { "type": ChunkType.Identifier, "captures": [ "(value)" ], "offset": { "line": 18, "column": 6 } } ], "offset": { "line": 18, "column": 6 } } ], "offset": { "line": 18, "column": 6 } } ] } ], "content": "(start program).out.(start) and (send \"Hello, World!\").in.(start)\n(send \"Hello, World!\").out.(value) and (log to console).in.(value)", "captures": [ "connect" ] } ], "content": "children\n (start program):(core).(Start)\n (send \"Hello, World!\"):(core).(Value)\n param (value) = \"Hello, World!\"\n (log to console):(console).(Console Log)\nconnect\n (start program).out.(start) and (send \"Hello, World!\").in.(start)\n (send \"Hello, World!\").out.(value) and (log to console).in.(value)", "captures": [ "in all", { "type": ChunkType.BuiltinTarget, "captures": [ "all" ], "offset": { "line": 10, "column": 2 } }, null ] } ], "content": "about\n Prints \"Hello, World!\" on the console.\nin all\n children\n (start program):(core).(Start)\n (send \"Hello, World!\"):(core).(Value)\n param (value) = \"Hello, World!\"\n (log to console):(console).(Console Log)\n connect\n (start program).out.(start) and (send \"Hello, World!\").in.(start)\n (send \"Hello, World!\").out.(value) and (log to console).in.(value)", "captures": [ "main", null, null ] } ], "captures": [""] }; const result = scriptChunkToScriptDef( scriptChunk, CompilationTargetId.es6); expect(result).toMatchSnapshot(); }); });