brighterscript 1.0.0-alpha.3 → 1.0.0-alpha.30

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 (605) hide show
  1. package/CHANGELOG.md +1230 -285
  2. package/README.md +61 -131
  3. package/bsconfig.schema.json +68 -2
  4. package/dist/ActionPipeline.d.ts +10 -0
  5. package/dist/ActionPipeline.js +40 -0
  6. package/dist/ActionPipeline.js.map +1 -0
  7. package/dist/AstValidationSegmenter.d.ts +35 -0
  8. package/dist/AstValidationSegmenter.js +209 -0
  9. package/dist/AstValidationSegmenter.js.map +1 -0
  10. package/dist/BsConfig.d.ts +51 -6
  11. package/dist/BusyStatusTracker.d.ts +31 -0
  12. package/dist/BusyStatusTracker.js +83 -0
  13. package/dist/BusyStatusTracker.js.map +1 -0
  14. package/dist/Cache.d.ts +5 -6
  15. package/dist/Cache.js +12 -11
  16. package/dist/Cache.js.map +1 -1
  17. package/dist/CacheVerifier.d.ts +7 -0
  18. package/dist/CacheVerifier.js +20 -0
  19. package/dist/CacheVerifier.js.map +1 -0
  20. package/dist/CodeActionUtil.d.ts +11 -2
  21. package/dist/CodeActionUtil.js +17 -3
  22. package/dist/CodeActionUtil.js.map +1 -1
  23. package/dist/CommentFlagProcessor.d.ts +7 -6
  24. package/dist/CommentFlagProcessor.js +10 -7
  25. package/dist/CommentFlagProcessor.js.map +1 -1
  26. package/dist/DependencyGraph.d.ts +8 -3
  27. package/dist/DependencyGraph.js +49 -16
  28. package/dist/DependencyGraph.js.map +1 -1
  29. package/dist/DiagnosticCollection.d.ts +5 -3
  30. package/dist/DiagnosticCollection.js +18 -16
  31. package/dist/DiagnosticCollection.js.map +1 -1
  32. package/dist/DiagnosticFilterer.d.ts +8 -4
  33. package/dist/DiagnosticFilterer.js +77 -44
  34. package/dist/DiagnosticFilterer.js.map +1 -1
  35. package/dist/DiagnosticManager.d.ts +55 -0
  36. package/dist/DiagnosticManager.js +214 -0
  37. package/dist/DiagnosticManager.js.map +1 -0
  38. package/dist/DiagnosticMessages.d.ts +184 -17
  39. package/dist/DiagnosticMessages.js +242 -24
  40. package/dist/DiagnosticMessages.js.map +1 -1
  41. package/dist/DiagnosticSeverityAdjuster.d.ts +7 -0
  42. package/dist/DiagnosticSeverityAdjuster.js +41 -0
  43. package/dist/DiagnosticSeverityAdjuster.js.map +1 -0
  44. package/dist/FunctionScope.d.ts +28 -0
  45. package/dist/FunctionScope.js +52 -0
  46. package/dist/FunctionScope.js.map +1 -0
  47. package/dist/KeyedThrottler.d.ts +3 -3
  48. package/dist/KeyedThrottler.js +3 -3
  49. package/dist/KeyedThrottler.js.map +1 -1
  50. package/dist/LanguageServer.d.ts +72 -47
  51. package/dist/LanguageServer.js +544 -312
  52. package/dist/LanguageServer.js.map +1 -1
  53. package/dist/Logger.d.ts +9 -10
  54. package/dist/Logger.js +36 -30
  55. package/dist/Logger.js.map +1 -1
  56. package/dist/PluginInterface.d.ts +29 -7
  57. package/dist/PluginInterface.js +90 -7
  58. package/dist/PluginInterface.js.map +1 -1
  59. package/dist/Program.d.ts +204 -99
  60. package/dist/Program.js +1060 -699
  61. package/dist/Program.js.map +1 -1
  62. package/dist/ProgramBuilder.d.ts +29 -18
  63. package/dist/ProgramBuilder.js +170 -132
  64. package/dist/ProgramBuilder.js.map +1 -1
  65. package/dist/Scope.d.ts +144 -109
  66. package/dist/Scope.js +538 -551
  67. package/dist/Scope.js.map +1 -1
  68. package/dist/SemanticTokenUtils.d.ts +14 -0
  69. package/dist/SemanticTokenUtils.js +81 -0
  70. package/dist/SemanticTokenUtils.js.map +1 -0
  71. package/dist/Stopwatch.d.ts +4 -0
  72. package/dist/Stopwatch.js +8 -1
  73. package/dist/Stopwatch.js.map +1 -1
  74. package/dist/SymbolTable.d.ts +91 -24
  75. package/dist/SymbolTable.js +286 -63
  76. package/dist/SymbolTable.js.map +1 -1
  77. package/dist/SymbolTypeFlag.d.ts +8 -0
  78. package/dist/SymbolTypeFlag.js +13 -0
  79. package/dist/SymbolTypeFlag.js.map +1 -0
  80. package/dist/Throttler.d.ts +12 -0
  81. package/dist/Throttler.js +39 -0
  82. package/dist/Throttler.js.map +1 -1
  83. package/dist/Watcher.d.ts +0 -3
  84. package/dist/Watcher.js +0 -3
  85. package/dist/Watcher.js.map +1 -1
  86. package/dist/XmlScope.d.ts +5 -15
  87. package/dist/XmlScope.js +35 -87
  88. package/dist/XmlScope.js.map +1 -1
  89. package/dist/astUtils/CachedLookups.d.ts +49 -0
  90. package/dist/astUtils/CachedLookups.js +324 -0
  91. package/dist/astUtils/CachedLookups.js.map +1 -0
  92. package/dist/astUtils/Editor.d.ts +69 -0
  93. package/dist/astUtils/Editor.js +245 -0
  94. package/dist/astUtils/Editor.js.map +1 -0
  95. package/dist/astUtils/Editor.spec.js +258 -0
  96. package/dist/astUtils/Editor.spec.js.map +1 -0
  97. package/dist/astUtils/creators.d.ts +33 -10
  98. package/dist/astUtils/creators.js +224 -30
  99. package/dist/astUtils/creators.js.map +1 -1
  100. package/dist/astUtils/creators.spec.js +5 -5
  101. package/dist/astUtils/creators.spec.js.map +1 -1
  102. package/dist/astUtils/reflection.d.ts +145 -82
  103. package/dist/astUtils/reflection.js +304 -132
  104. package/dist/astUtils/reflection.js.map +1 -1
  105. package/dist/astUtils/reflection.spec.js +267 -162
  106. package/dist/astUtils/reflection.spec.js.map +1 -1
  107. package/dist/astUtils/stackedVisitor.js.map +1 -1
  108. package/dist/astUtils/stackedVisitor.spec.js +14 -14
  109. package/dist/astUtils/stackedVisitor.spec.js.map +1 -1
  110. package/dist/astUtils/visitors.d.ts +114 -53
  111. package/dist/astUtils/visitors.js +70 -13
  112. package/dist/astUtils/visitors.js.map +1 -1
  113. package/dist/astUtils/visitors.spec.js +465 -51
  114. package/dist/astUtils/visitors.spec.js.map +1 -1
  115. package/dist/astUtils/xml.d.ts +9 -8
  116. package/dist/astUtils/xml.js +10 -5
  117. package/dist/astUtils/xml.js.map +1 -1
  118. package/dist/bscPlugin/BscPlugin.d.ts +22 -1
  119. package/dist/bscPlugin/BscPlugin.js +88 -0
  120. package/dist/bscPlugin/BscPlugin.js.map +1 -1
  121. package/dist/bscPlugin/CallExpressionInfo.d.ts +36 -0
  122. package/dist/bscPlugin/CallExpressionInfo.js +131 -0
  123. package/dist/bscPlugin/CallExpressionInfo.js.map +1 -0
  124. package/dist/bscPlugin/FileWriter.d.ts +6 -0
  125. package/dist/bscPlugin/FileWriter.js +24 -0
  126. package/dist/bscPlugin/FileWriter.js.map +1 -0
  127. package/dist/bscPlugin/SignatureHelpUtil.d.ts +10 -0
  128. package/dist/bscPlugin/SignatureHelpUtil.js +137 -0
  129. package/dist/bscPlugin/SignatureHelpUtil.js.map +1 -0
  130. package/dist/bscPlugin/codeActions/CodeActionsProcessor.d.ts +1 -1
  131. package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +26 -17
  132. package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
  133. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +94 -20
  134. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
  135. package/dist/bscPlugin/completions/CompletionsProcessor.d.ts +60 -0
  136. package/dist/bscPlugin/completions/CompletionsProcessor.js +601 -0
  137. package/dist/bscPlugin/completions/CompletionsProcessor.js.map +1 -0
  138. package/dist/bscPlugin/completions/CompletionsProcessor.spec.js +2139 -0
  139. package/dist/bscPlugin/completions/CompletionsProcessor.spec.js.map +1 -0
  140. package/dist/bscPlugin/definition/DefinitionProvider.d.ts +13 -0
  141. package/dist/bscPlugin/definition/DefinitionProvider.js +210 -0
  142. package/dist/bscPlugin/definition/DefinitionProvider.js.map +1 -0
  143. package/dist/bscPlugin/definition/DefinitionProvider.spec.js +88 -0
  144. package/dist/bscPlugin/definition/DefinitionProvider.spec.js.map +1 -0
  145. package/dist/bscPlugin/fileProviders/FileProvider.d.ts +9 -0
  146. package/dist/bscPlugin/fileProviders/FileProvider.js +51 -0
  147. package/dist/bscPlugin/fileProviders/FileProvider.js.map +1 -0
  148. package/dist/bscPlugin/hover/HoverProcessor.d.ts +18 -0
  149. package/dist/bscPlugin/hover/HoverProcessor.js +218 -0
  150. package/dist/bscPlugin/hover/HoverProcessor.js.map +1 -0
  151. package/dist/bscPlugin/hover/HoverProcessor.spec.d.ts +1 -0
  152. package/dist/bscPlugin/hover/HoverProcessor.spec.js +737 -0
  153. package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +1 -0
  154. package/dist/bscPlugin/references/ReferencesProvider.d.ts +12 -0
  155. package/dist/bscPlugin/references/ReferencesProvider.js +56 -0
  156. package/dist/bscPlugin/references/ReferencesProvider.js.map +1 -0
  157. package/dist/bscPlugin/references/ReferencesProvider.spec.d.ts +1 -0
  158. package/dist/bscPlugin/references/ReferencesProvider.spec.js +51 -0
  159. package/dist/bscPlugin/references/ReferencesProvider.spec.js.map +1 -0
  160. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.d.ts +14 -0
  161. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +138 -0
  162. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -0
  163. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.d.ts +1 -0
  164. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js +491 -0
  165. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +1 -0
  166. package/dist/bscPlugin/serialize/BslibInjector.spec.d.ts +1 -0
  167. package/dist/bscPlugin/serialize/BslibInjector.spec.js +19 -0
  168. package/dist/bscPlugin/serialize/BslibInjector.spec.js.map +1 -0
  169. package/dist/bscPlugin/serialize/BslibManager.d.ts +9 -0
  170. package/dist/bscPlugin/serialize/BslibManager.js +40 -0
  171. package/dist/bscPlugin/serialize/BslibManager.js.map +1 -0
  172. package/dist/bscPlugin/serialize/FileSerializer.d.ts +9 -0
  173. package/dist/bscPlugin/serialize/FileSerializer.js +72 -0
  174. package/dist/bscPlugin/serialize/FileSerializer.js.map +1 -0
  175. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.d.ts +7 -0
  176. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.js +22 -0
  177. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.js.map +1 -0
  178. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.d.ts +1 -0
  179. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.js +291 -0
  180. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.js.map +1 -0
  181. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.d.ts +7 -0
  182. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.js +26 -0
  183. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.js.map +1 -0
  184. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.d.ts +1 -0
  185. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.js +245 -0
  186. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.js.map +1 -0
  187. package/dist/bscPlugin/symbols/symbolUtils.d.ts +5 -0
  188. package/dist/bscPlugin/symbols/symbolUtils.js +140 -0
  189. package/dist/bscPlugin/symbols/symbolUtils.js.map +1 -0
  190. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.d.ts +21 -0
  191. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js +202 -0
  192. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js.map +1 -0
  193. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.d.ts +1 -0
  194. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.js +41 -0
  195. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.js.map +1 -0
  196. package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.d.ts +12 -0
  197. package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.js +99 -0
  198. package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.js.map +1 -0
  199. package/dist/bscPlugin/validation/BrsFileAfterValidatior.d.ts +7 -0
  200. package/dist/bscPlugin/validation/BrsFileAfterValidatior.js +18 -0
  201. package/dist/bscPlugin/validation/BrsFileAfterValidatior.js.map +1 -0
  202. package/dist/bscPlugin/validation/BrsFileValidator.d.ts +34 -0
  203. package/dist/bscPlugin/validation/BrsFileValidator.js +462 -0
  204. package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -0
  205. package/dist/bscPlugin/validation/BrsFileValidator.spec.d.ts +1 -0
  206. package/dist/bscPlugin/validation/BrsFileValidator.spec.js +758 -0
  207. package/dist/bscPlugin/validation/BrsFileValidator.spec.js.map +1 -0
  208. package/dist/bscPlugin/validation/ProgramValidator.d.ts +11 -0
  209. package/dist/bscPlugin/validation/ProgramValidator.js +33 -0
  210. package/dist/bscPlugin/validation/ProgramValidator.js.map +1 -0
  211. package/dist/bscPlugin/validation/ScopeValidator.d.ts +131 -0
  212. package/dist/bscPlugin/validation/ScopeValidator.js +1097 -0
  213. package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -0
  214. package/dist/bscPlugin/validation/ScopeValidator.spec.d.ts +1 -0
  215. package/dist/bscPlugin/validation/ScopeValidator.spec.js +2796 -0
  216. package/dist/bscPlugin/validation/ScopeValidator.spec.js.map +1 -0
  217. package/dist/bscPlugin/validation/XmlFileValidator.d.ts +8 -0
  218. package/dist/bscPlugin/validation/XmlFileValidator.js +44 -0
  219. package/dist/bscPlugin/validation/XmlFileValidator.js.map +1 -0
  220. package/dist/cli.js +117 -11
  221. package/dist/cli.js.map +1 -1
  222. package/dist/deferred.d.ts +3 -3
  223. package/dist/deferred.js.map +1 -1
  224. package/dist/diagnosticUtils.d.ts +10 -3
  225. package/dist/diagnosticUtils.js +58 -21
  226. package/dist/diagnosticUtils.js.map +1 -1
  227. package/dist/examples/plugins/removePrint.js +8 -12
  228. package/dist/examples/plugins/removePrint.js.map +1 -1
  229. package/dist/files/AssetFile.d.ts +24 -0
  230. package/dist/files/AssetFile.js +25 -0
  231. package/dist/files/AssetFile.js.map +1 -0
  232. package/dist/files/BrsFile.Class.spec.js +858 -153
  233. package/dist/files/BrsFile.Class.spec.js.map +1 -1
  234. package/dist/files/BrsFile.d.ts +144 -82
  235. package/dist/files/BrsFile.js +847 -911
  236. package/dist/files/BrsFile.js.map +1 -1
  237. package/dist/files/BrsFile.spec.js +2928 -834
  238. package/dist/files/BrsFile.spec.js.map +1 -1
  239. package/dist/files/BscFile.d.ts +101 -0
  240. package/dist/files/BscFile.js +15 -0
  241. package/dist/files/BscFile.js.map +1 -0
  242. package/dist/files/Factory.d.ts +25 -0
  243. package/dist/files/Factory.js +22 -0
  244. package/dist/files/Factory.js.map +1 -0
  245. package/dist/files/LazyFileData.d.ts +20 -0
  246. package/dist/files/LazyFileData.js +54 -0
  247. package/dist/files/LazyFileData.js.map +1 -0
  248. package/dist/files/LazyFileData.spec.d.ts +1 -0
  249. package/dist/files/LazyFileData.spec.js +27 -0
  250. package/dist/files/LazyFileData.spec.js.map +1 -0
  251. package/dist/files/XmlFile.d.ts +73 -41
  252. package/dist/files/XmlFile.js +126 -138
  253. package/dist/files/XmlFile.js.map +1 -1
  254. package/dist/files/XmlFile.spec.js +450 -318
  255. package/dist/files/XmlFile.spec.js.map +1 -1
  256. package/dist/files/tests/imports.spec.js +62 -52
  257. package/dist/files/tests/imports.spec.js.map +1 -1
  258. package/dist/files/tests/optionalChaning.spec.d.ts +1 -0
  259. package/dist/files/tests/optionalChaning.spec.js +152 -0
  260. package/dist/files/tests/optionalChaning.spec.js.map +1 -0
  261. package/dist/globalCallables.d.ts +3 -1
  262. package/dist/globalCallables.js +416 -162
  263. package/dist/globalCallables.js.map +1 -1
  264. package/dist/index.d.ts +25 -3
  265. package/dist/index.js +42 -5
  266. package/dist/index.js.map +1 -1
  267. package/dist/interfaces.d.ts +722 -119
  268. package/dist/interfaces.js +31 -0
  269. package/dist/interfaces.js.map +1 -1
  270. package/dist/lexer/Character.spec.js +5 -5
  271. package/dist/lexer/Character.spec.js.map +1 -1
  272. package/dist/lexer/Lexer.d.ts +40 -9
  273. package/dist/lexer/Lexer.js +191 -49
  274. package/dist/lexer/Lexer.js.map +1 -1
  275. package/dist/lexer/Lexer.spec.js +775 -563
  276. package/dist/lexer/Lexer.spec.js.map +1 -1
  277. package/dist/lexer/Token.d.ts +11 -3
  278. package/dist/lexer/Token.js +10 -2
  279. package/dist/lexer/Token.js.map +1 -1
  280. package/dist/lexer/TokenKind.d.ts +27 -1
  281. package/dist/lexer/TokenKind.js +112 -5
  282. package/dist/lexer/TokenKind.js.map +1 -1
  283. package/dist/logging.d.ts +9 -0
  284. package/dist/logging.js +16 -0
  285. package/dist/logging.js.map +1 -0
  286. package/dist/parser/AstNode.d.ts +180 -0
  287. package/dist/parser/AstNode.js +245 -0
  288. package/dist/parser/AstNode.js.map +1 -0
  289. package/dist/parser/AstNode.spec.d.ts +1 -0
  290. package/dist/parser/AstNode.spec.js +165 -0
  291. package/dist/parser/AstNode.spec.js.map +1 -0
  292. package/dist/parser/BrsTranspileState.d.ts +12 -2
  293. package/dist/parser/BrsTranspileState.js +6 -0
  294. package/dist/parser/BrsTranspileState.js.map +1 -1
  295. package/dist/parser/Expression.d.ts +454 -210
  296. package/dist/parser/Expression.js +953 -498
  297. package/dist/parser/Expression.js.map +1 -1
  298. package/dist/parser/Parser.Class.spec.js +200 -95
  299. package/dist/parser/Parser.Class.spec.js.map +1 -1
  300. package/dist/parser/Parser.d.ts +105 -120
  301. package/dist/parser/Parser.js +1406 -912
  302. package/dist/parser/Parser.js.map +1 -1
  303. package/dist/parser/Parser.spec.d.ts +3 -1
  304. package/dist/parser/Parser.spec.js +1383 -456
  305. package/dist/parser/Parser.spec.js.map +1 -1
  306. package/dist/parser/SGParser.d.ts +44 -6
  307. package/dist/parser/SGParser.js +212 -185
  308. package/dist/parser/SGParser.js.map +1 -1
  309. package/dist/parser/SGParser.spec.js +30 -28
  310. package/dist/parser/SGParser.spec.js.map +1 -1
  311. package/dist/parser/SGTypes.d.ts +293 -50
  312. package/dist/parser/SGTypes.js +540 -187
  313. package/dist/parser/SGTypes.js.map +1 -1
  314. package/dist/parser/Statement.d.ts +734 -244
  315. package/dist/parser/Statement.js +1758 -611
  316. package/dist/parser/Statement.js.map +1 -1
  317. package/dist/parser/Statement.spec.js +45 -34
  318. package/dist/parser/Statement.spec.js.map +1 -1
  319. package/dist/parser/TranspileState.d.ts +17 -8
  320. package/dist/parser/TranspileState.js +73 -11
  321. package/dist/parser/TranspileState.js.map +1 -1
  322. package/dist/parser/tests/Parser.spec.d.ts +10 -9
  323. package/dist/parser/tests/Parser.spec.js +18 -14
  324. package/dist/parser/tests/Parser.spec.js.map +1 -1
  325. package/dist/parser/tests/controlFlow/For.spec.js +79 -69
  326. package/dist/parser/tests/controlFlow/For.spec.js.map +1 -1
  327. package/dist/parser/tests/controlFlow/ForEach.spec.js +53 -47
  328. package/dist/parser/tests/controlFlow/ForEach.spec.js.map +1 -1
  329. package/dist/parser/tests/controlFlow/If.spec.js +217 -196
  330. package/dist/parser/tests/controlFlow/If.spec.js.map +1 -1
  331. package/dist/parser/tests/controlFlow/While.spec.js +48 -42
  332. package/dist/parser/tests/controlFlow/While.spec.js.map +1 -1
  333. package/dist/parser/tests/expression/Additive.spec.js +31 -31
  334. package/dist/parser/tests/expression/Additive.spec.js.map +1 -1
  335. package/dist/parser/tests/expression/ArrayLiterals.spec.js +157 -120
  336. package/dist/parser/tests/expression/ArrayLiterals.spec.js.map +1 -1
  337. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +202 -139
  338. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
  339. package/dist/parser/tests/expression/Boolean.spec.js +25 -25
  340. package/dist/parser/tests/expression/Boolean.spec.js.map +1 -1
  341. package/dist/parser/tests/expression/Call.spec.js +150 -41
  342. package/dist/parser/tests/expression/Call.spec.js.map +1 -1
  343. package/dist/parser/tests/expression/Exponential.spec.js +18 -18
  344. package/dist/parser/tests/expression/Exponential.spec.js.map +1 -1
  345. package/dist/parser/tests/expression/Function.spec.js +257 -257
  346. package/dist/parser/tests/expression/Function.spec.js.map +1 -1
  347. package/dist/parser/tests/expression/Indexing.spec.js +160 -90
  348. package/dist/parser/tests/expression/Indexing.spec.js.map +1 -1
  349. package/dist/parser/tests/expression/Multiplicative.spec.js +38 -38
  350. package/dist/parser/tests/expression/Multiplicative.spec.js.map +1 -1
  351. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +196 -98
  352. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
  353. package/dist/parser/tests/expression/PrefixUnary.spec.js +42 -42
  354. package/dist/parser/tests/expression/PrefixUnary.spec.js.map +1 -1
  355. package/dist/parser/tests/expression/Primary.spec.js +42 -42
  356. package/dist/parser/tests/expression/Primary.spec.js.map +1 -1
  357. package/dist/parser/tests/expression/RegexLiteralExpression.spec.d.ts +1 -0
  358. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +171 -0
  359. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js.map +1 -0
  360. package/dist/parser/tests/expression/Relational.spec.js +44 -44
  361. package/dist/parser/tests/expression/Relational.spec.js.map +1 -1
  362. package/dist/parser/tests/expression/SourceLiteralExpression.spec.js +31 -31
  363. package/dist/parser/tests/expression/SourceLiteralExpression.spec.js.map +1 -1
  364. package/dist/parser/tests/expression/TemplateStringExpression.spec.js +230 -90
  365. package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +1 -1
  366. package/dist/parser/tests/expression/TernaryExpression.spec.js +377 -148
  367. package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
  368. package/dist/parser/tests/expression/TypeExpression.spec.d.ts +1 -0
  369. package/dist/parser/tests/expression/TypeExpression.spec.js +126 -0
  370. package/dist/parser/tests/expression/TypeExpression.spec.js.map +1 -0
  371. package/dist/parser/tests/expression/UnaryExpression.spec.d.ts +1 -0
  372. package/dist/parser/tests/expression/UnaryExpression.spec.js +52 -0
  373. package/dist/parser/tests/expression/UnaryExpression.spec.js.map +1 -0
  374. package/dist/parser/tests/statement/AssignmentOperators.spec.js +37 -37
  375. package/dist/parser/tests/statement/AssignmentOperators.spec.js.map +1 -1
  376. package/dist/parser/tests/statement/ConstStatement.spec.d.ts +1 -0
  377. package/dist/parser/tests/statement/ConstStatement.spec.js +262 -0
  378. package/dist/parser/tests/statement/ConstStatement.spec.js.map +1 -0
  379. package/dist/parser/tests/statement/Continue.spec.d.ts +1 -0
  380. package/dist/parser/tests/statement/Continue.spec.js +119 -0
  381. package/dist/parser/tests/statement/Continue.spec.js.map +1 -0
  382. package/dist/parser/tests/statement/Declaration.spec.js +45 -45
  383. package/dist/parser/tests/statement/Declaration.spec.js.map +1 -1
  384. package/dist/parser/tests/statement/Dim.spec.js +22 -22
  385. package/dist/parser/tests/statement/Dim.spec.js.map +1 -1
  386. package/dist/parser/tests/statement/Enum.spec.d.ts +1 -0
  387. package/dist/parser/tests/statement/Enum.spec.js +684 -0
  388. package/dist/parser/tests/statement/Enum.spec.js.map +1 -0
  389. package/dist/parser/tests/statement/For.spec.d.ts +1 -0
  390. package/dist/parser/tests/statement/For.spec.js +45 -0
  391. package/dist/parser/tests/statement/For.spec.js.map +1 -0
  392. package/dist/parser/tests/statement/ForEach.spec.d.ts +1 -0
  393. package/dist/parser/tests/statement/ForEach.spec.js +36 -0
  394. package/dist/parser/tests/statement/ForEach.spec.js.map +1 -0
  395. package/dist/parser/tests/statement/Function.spec.js +208 -198
  396. package/dist/parser/tests/statement/Function.spec.js.map +1 -1
  397. package/dist/parser/tests/statement/Goto.spec.js +16 -15
  398. package/dist/parser/tests/statement/Goto.spec.js.map +1 -1
  399. package/dist/parser/tests/statement/Increment.spec.js +51 -51
  400. package/dist/parser/tests/statement/Increment.spec.js.map +1 -1
  401. package/dist/parser/tests/statement/InterfaceStatement.spec.d.ts +1 -0
  402. package/dist/parser/tests/statement/InterfaceStatement.spec.js +109 -0
  403. package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +1 -0
  404. package/dist/parser/tests/statement/LibraryStatement.spec.js +18 -18
  405. package/dist/parser/tests/statement/LibraryStatement.spec.js.map +1 -1
  406. package/dist/parser/tests/statement/Misc.spec.js +123 -163
  407. package/dist/parser/tests/statement/Misc.spec.js.map +1 -1
  408. package/dist/parser/tests/statement/PrintStatement.spec.js +125 -108
  409. package/dist/parser/tests/statement/PrintStatement.spec.js.map +1 -1
  410. package/dist/parser/tests/statement/ReturnStatement.spec.js +51 -49
  411. package/dist/parser/tests/statement/ReturnStatement.spec.js.map +1 -1
  412. package/dist/parser/tests/statement/Set.spec.js +110 -97
  413. package/dist/parser/tests/statement/Set.spec.js.map +1 -1
  414. package/dist/parser/tests/statement/Stop.spec.js +13 -12
  415. package/dist/parser/tests/statement/Stop.spec.js.map +1 -1
  416. package/dist/parser/tests/statement/Throw.spec.js +6 -6
  417. package/dist/parser/tests/statement/Throw.spec.js.map +1 -1
  418. package/dist/parser/tests/statement/TryCatch.spec.js +26 -15
  419. package/dist/parser/tests/statement/TryCatch.spec.js.map +1 -1
  420. package/dist/preprocessor/Manifest.d.ts +6 -6
  421. package/dist/preprocessor/Manifest.js +17 -38
  422. package/dist/preprocessor/Manifest.js.map +1 -1
  423. package/dist/preprocessor/Manifest.spec.d.ts +1 -0
  424. package/dist/preprocessor/Manifest.spec.js +78 -103
  425. package/dist/preprocessor/Manifest.spec.js.map +1 -1
  426. package/dist/roku-types/data.json +19351 -0
  427. package/dist/roku-types/index.d.ts +5483 -0
  428. package/dist/roku-types/index.js +11 -0
  429. package/dist/roku-types/index.js.map +1 -0
  430. package/dist/types/ArrayType.d.ts +9 -5
  431. package/dist/types/ArrayType.js +68 -24
  432. package/dist/types/ArrayType.js.map +1 -1
  433. package/dist/types/ArrayType.spec.js +39 -11
  434. package/dist/types/ArrayType.spec.js.map +1 -1
  435. package/dist/types/AssociativeArrayType.d.ts +14 -0
  436. package/dist/types/AssociativeArrayType.js +60 -0
  437. package/dist/types/AssociativeArrayType.js.map +1 -0
  438. package/dist/types/BaseFunctionType.d.ts +9 -0
  439. package/dist/types/BaseFunctionType.js +25 -0
  440. package/dist/types/BaseFunctionType.js.map +1 -0
  441. package/dist/types/BooleanType.d.ts +10 -5
  442. package/dist/types/BooleanType.js +21 -9
  443. package/dist/types/BooleanType.js.map +1 -1
  444. package/dist/types/BooleanType.spec.js +10 -4
  445. package/dist/types/BooleanType.spec.js.map +1 -1
  446. package/dist/types/BscType.d.ts +29 -3
  447. package/dist/types/BscType.js +121 -0
  448. package/dist/types/BscType.js.map +1 -1
  449. package/dist/types/BscTypeKind.d.ts +25 -0
  450. package/dist/types/BscTypeKind.js +30 -0
  451. package/dist/types/BscTypeKind.js.map +1 -0
  452. package/dist/types/BuiltInInterfaceAdder.d.ts +23 -0
  453. package/dist/types/BuiltInInterfaceAdder.js +174 -0
  454. package/dist/types/BuiltInInterfaceAdder.js.map +1 -0
  455. package/dist/types/BuiltInInterfaceAdder.spec.d.ts +1 -0
  456. package/dist/types/BuiltInInterfaceAdder.spec.js +115 -0
  457. package/dist/types/BuiltInInterfaceAdder.spec.js.map +1 -0
  458. package/dist/types/ClassType.d.ts +17 -0
  459. package/dist/types/ClassType.js +58 -0
  460. package/dist/types/ClassType.js.map +1 -0
  461. package/dist/types/ClassType.spec.d.ts +1 -0
  462. package/dist/types/ClassType.spec.js +76 -0
  463. package/dist/types/ClassType.spec.js.map +1 -0
  464. package/dist/types/ComponentType.d.ts +27 -0
  465. package/dist/types/ComponentType.js +83 -0
  466. package/dist/types/ComponentType.js.map +1 -0
  467. package/dist/types/DoubleType.d.ts +10 -5
  468. package/dist/types/DoubleType.js +25 -18
  469. package/dist/types/DoubleType.js.map +1 -1
  470. package/dist/types/DoubleType.spec.js +12 -4
  471. package/dist/types/DoubleType.spec.js.map +1 -1
  472. package/dist/types/DynamicType.d.ts +12 -5
  473. package/dist/types/DynamicType.js +22 -6
  474. package/dist/types/DynamicType.js.map +1 -1
  475. package/dist/types/DynamicType.spec.js +16 -5
  476. package/dist/types/DynamicType.spec.js.map +1 -1
  477. package/dist/types/EnumType.d.ts +40 -0
  478. package/dist/types/EnumType.js +80 -0
  479. package/dist/types/EnumType.js.map +1 -0
  480. package/dist/types/EnumType.spec.d.ts +1 -0
  481. package/dist/types/EnumType.spec.js +33 -0
  482. package/dist/types/EnumType.spec.js.map +1 -0
  483. package/dist/types/FloatType.d.ts +10 -5
  484. package/dist/types/FloatType.js +25 -18
  485. package/dist/types/FloatType.js.map +1 -1
  486. package/dist/types/FloatType.spec.js +4 -4
  487. package/dist/types/FloatType.spec.js.map +1 -1
  488. package/dist/types/FunctionType.d.ts +10 -22
  489. package/dist/types/FunctionType.js +26 -63
  490. package/dist/types/FunctionType.js.map +1 -1
  491. package/dist/types/InheritableType.d.ts +28 -0
  492. package/dist/types/InheritableType.js +157 -0
  493. package/dist/types/InheritableType.js.map +1 -0
  494. package/dist/types/IntegerType.d.ts +10 -5
  495. package/dist/types/IntegerType.js +25 -18
  496. package/dist/types/IntegerType.js.map +1 -1
  497. package/dist/types/IntegerType.spec.js +8 -4
  498. package/dist/types/IntegerType.spec.js.map +1 -1
  499. package/dist/types/InterfaceType.d.ts +14 -6
  500. package/dist/types/InterfaceType.js +26 -15
  501. package/dist/types/InterfaceType.js.map +1 -1
  502. package/dist/types/InterfaceType.spec.d.ts +1 -0
  503. package/dist/types/InterfaceType.spec.js +227 -0
  504. package/dist/types/InterfaceType.spec.js.map +1 -0
  505. package/dist/types/InvalidType.d.ts +9 -5
  506. package/dist/types/InvalidType.js +20 -9
  507. package/dist/types/InvalidType.js.map +1 -1
  508. package/dist/types/InvalidType.spec.js +8 -4
  509. package/dist/types/InvalidType.spec.js.map +1 -1
  510. package/dist/types/LongIntegerType.d.ts +10 -5
  511. package/dist/types/LongIntegerType.js +25 -18
  512. package/dist/types/LongIntegerType.js.map +1 -1
  513. package/dist/types/LongIntegerType.spec.js +10 -4
  514. package/dist/types/LongIntegerType.spec.js.map +1 -1
  515. package/dist/types/NamespaceType.d.ts +12 -0
  516. package/dist/types/NamespaceType.js +28 -0
  517. package/dist/types/NamespaceType.js.map +1 -0
  518. package/dist/types/ObjectType.d.ts +10 -5
  519. package/dist/types/ObjectType.js +23 -9
  520. package/dist/types/ObjectType.js.map +1 -1
  521. package/dist/types/ObjectType.spec.js +3 -3
  522. package/dist/types/ObjectType.spec.js.map +1 -1
  523. package/dist/types/ReferenceType.d.ts +71 -0
  524. package/dist/types/ReferenceType.js +467 -0
  525. package/dist/types/ReferenceType.js.map +1 -0
  526. package/dist/types/ReferenceType.spec.d.ts +1 -0
  527. package/dist/types/ReferenceType.spec.js +151 -0
  528. package/dist/types/ReferenceType.spec.js.map +1 -0
  529. package/dist/types/StringType.d.ts +13 -5
  530. package/dist/types/StringType.js +25 -9
  531. package/dist/types/StringType.js.map +1 -1
  532. package/dist/types/StringType.spec.js +3 -3
  533. package/dist/types/StringType.spec.js.map +1 -1
  534. package/dist/types/TypedFunctionType.d.ts +33 -0
  535. package/dist/types/TypedFunctionType.js +106 -0
  536. package/dist/types/TypedFunctionType.js.map +1 -0
  537. package/dist/types/TypedFunctionType.spec.d.ts +1 -0
  538. package/dist/types/TypedFunctionType.spec.js +122 -0
  539. package/dist/types/TypedFunctionType.spec.js.map +1 -0
  540. package/dist/types/UninitializedType.d.ts +8 -6
  541. package/dist/types/UninitializedType.js +15 -9
  542. package/dist/types/UninitializedType.js.map +1 -1
  543. package/dist/types/UnionType.d.ts +20 -0
  544. package/dist/types/UnionType.js +127 -0
  545. package/dist/types/UnionType.js.map +1 -0
  546. package/dist/types/UnionType.spec.d.ts +1 -0
  547. package/dist/types/UnionType.spec.js +129 -0
  548. package/dist/types/UnionType.spec.js.map +1 -0
  549. package/dist/types/VoidType.d.ts +10 -5
  550. package/dist/types/VoidType.js +20 -9
  551. package/dist/types/VoidType.js.map +1 -1
  552. package/dist/types/VoidType.spec.js +3 -3
  553. package/dist/types/VoidType.spec.js.map +1 -1
  554. package/dist/types/helper.spec.d.ts +1 -0
  555. package/dist/types/helper.spec.js +144 -0
  556. package/dist/types/helper.spec.js.map +1 -0
  557. package/dist/types/helpers.d.ts +24 -0
  558. package/dist/types/helpers.js +178 -0
  559. package/dist/types/helpers.js.map +1 -0
  560. package/dist/types/index.d.ts +22 -0
  561. package/dist/types/index.js +39 -0
  562. package/dist/types/index.js.map +1 -0
  563. package/dist/util.d.ts +216 -106
  564. package/dist/util.js +1289 -319
  565. package/dist/util.js.map +1 -1
  566. package/dist/validators/ClassValidator.d.ts +9 -15
  567. package/dist/validators/ClassValidator.js +81 -134
  568. package/dist/validators/ClassValidator.js.map +1 -1
  569. package/package.json +169 -138
  570. package/dist/astUtils/index.d.ts +0 -7
  571. package/dist/astUtils/index.js +0 -26
  572. package/dist/astUtils/index.js.map +0 -1
  573. package/dist/lexer/index.d.ts +0 -3
  574. package/dist/lexer/index.js +0 -17
  575. package/dist/lexer/index.js.map +0 -1
  576. package/dist/parser/index.d.ts +0 -3
  577. package/dist/parser/index.js +0 -16
  578. package/dist/parser/index.js.map +0 -1
  579. package/dist/preprocessor/Chunk.d.ts +0 -82
  580. package/dist/preprocessor/Chunk.js +0 -77
  581. package/dist/preprocessor/Chunk.js.map +0 -1
  582. package/dist/preprocessor/Preprocessor.d.ts +0 -60
  583. package/dist/preprocessor/Preprocessor.js +0 -156
  584. package/dist/preprocessor/Preprocessor.js.map +0 -1
  585. package/dist/preprocessor/Preprocessor.spec.js +0 -152
  586. package/dist/preprocessor/Preprocessor.spec.js.map +0 -1
  587. package/dist/preprocessor/PreprocessorParser.d.ts +0 -61
  588. package/dist/preprocessor/PreprocessorParser.js +0 -194
  589. package/dist/preprocessor/PreprocessorParser.js.map +0 -1
  590. package/dist/preprocessor/PreprocessorParser.spec.js +0 -116
  591. package/dist/preprocessor/PreprocessorParser.spec.js.map +0 -1
  592. package/dist/preprocessor/index.d.ts +0 -3
  593. package/dist/preprocessor/index.js +0 -16
  594. package/dist/preprocessor/index.js.map +0 -1
  595. package/dist/types/CustomType.d.ts +0 -10
  596. package/dist/types/CustomType.js +0 -35
  597. package/dist/types/CustomType.js.map +0 -1
  598. package/dist/types/FunctionType.spec.js +0 -29
  599. package/dist/types/FunctionType.spec.js.map +0 -1
  600. package/dist/types/LazyType.d.ts +0 -15
  601. package/dist/types/LazyType.js +0 -32
  602. package/dist/types/LazyType.js.map +0 -1
  603. /package/dist/{preprocessor/Preprocessor.spec.d.ts → astUtils/Editor.spec.d.ts} +0 -0
  604. /package/dist/{preprocessor/PreprocessorParser.spec.d.ts → bscPlugin/completions/CompletionsProcessor.spec.d.ts} +0 -0
  605. /package/dist/{types/FunctionType.spec.d.ts → bscPlugin/definition/DefinitionProvider.spec.d.ts} +0 -0
@@ -1,151 +1,304 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SGAst = exports.SGComponent = exports.SGInterface = exports.SGFunction = exports.SGFieldTypes = exports.SGField = exports.SGScript = exports.SGChildren = exports.SGNode = exports.SGProlog = exports.SGTag = void 0;
3
+ exports.SGAst = exports.SGComponent = exports.SGInterface = exports.SGInterfaceFunction = exports.SGFieldTypes = exports.SGFieldType = exports.SGInterfaceField = exports.SGScript = exports.SGCustomization = exports.SGChildren = exports.SGNode = exports.SGProlog = exports.SGElement = exports.SGAttribute = void 0;
4
4
  const source_map_1 = require("source-map");
5
5
  const creators_1 = require("../astUtils/creators");
6
- const xml_1 = require("../astUtils/xml");
7
6
  const util_1 = require("../util");
8
- class SGTag {
9
- constructor(tag, attributes = [], range) {
10
- this.tag = tag;
11
- this.attributes = attributes;
12
- this.range = range;
7
+ class SGAttribute {
8
+ constructor(options) {
9
+ this._range = null;
10
+ this.tokens = {
11
+ key: options.key,
12
+ equals: options.equals,
13
+ openingQuote: options.openingQuote,
14
+ value: options.value,
15
+ closingQuote: options.closingQuote
16
+ };
17
+ }
18
+ get key() {
19
+ return this.tokens.key.text;
20
+ }
21
+ /**
22
+ * The value of this attribute. This does not including the opening or closing quote
23
+ */
24
+ get value() {
25
+ var _a;
26
+ return (_a = this.tokens.value) === null || _a === void 0 ? void 0 : _a.text;
27
+ }
28
+ set value(val) {
29
+ if (val === null || val === undefined) {
30
+ val = '';
31
+ }
32
+ if (!this.tokens.equals) {
33
+ this.tokens.equals = { text: '=' };
34
+ }
35
+ if (this.tokens.value) {
36
+ this.tokens.value.text = val;
37
+ }
38
+ else {
39
+ this.tokens.value = { text: val };
40
+ }
41
+ }
42
+ get range() {
43
+ if (!this._range) {
44
+ this._range = util_1.default.createBoundingRange(this.tokens.key, this.tokens.equals, this.tokens.openingQuote, this.tokens.value, this.tokens.closingQuote);
45
+ }
46
+ return this._range;
47
+ }
48
+ transpile(state) {
49
+ const result = [
50
+ state.transpileToken(this.tokens.key)
51
+ ];
52
+ if (this.tokens.value) {
53
+ result.push(state.transpileToken(this.tokens.equals, '='), state.transpileToken(this.tokens.openingQuote, '"'), state.transpileToken(this.tokens.value), state.transpileToken(this.tokens.closingQuote, '"'));
54
+ }
55
+ return util_1.default.sourceNodeFromTranspileResult(null, null, null, result);
56
+ }
57
+ clone() {
58
+ return new SGAttribute(this.tokens);
59
+ }
60
+ }
61
+ exports.SGAttribute = SGAttribute;
62
+ class SGElement {
63
+ constructor(options) {
64
+ var _a, _b;
65
+ /**
66
+ * Array of attributes found on this tag
67
+ */
68
+ this.attributes = [];
69
+ /**
70
+ * The array of direct children AST elements of this AST node
71
+ */
72
+ this.elements = [];
73
+ this._range = null;
74
+ this.tokens = {
75
+ startTagOpen: options.startTagOpen,
76
+ startTagName: options.startTagName,
77
+ startTagClose: options.startTagClose,
78
+ endTagOpen: options.endTagOpen,
79
+ endTagName: options.endTagName,
80
+ endTagClose: options.endTagClose
81
+ };
82
+ this.attributes = (_a = options.attributes) !== null && _a !== void 0 ? _a : [];
83
+ this.elements = (_b = options.elements) !== null && _b !== void 0 ? _b : [];
84
+ }
85
+ get range() {
86
+ var _a, _b, _c, _d;
87
+ if (!this._range) {
88
+ this._range = util_1.default.createBoundingRange(this.tokens.startTagOpen, this.tokens.startTagName, (_a = this.attributes) === null || _a === void 0 ? void 0 : _a[((_b = this.attributes) === null || _b === void 0 ? void 0 : _b.length) - 1], this.tokens.startTagClose, (_c = this.elements) === null || _c === void 0 ? void 0 : _c[((_d = this.elements) === null || _d === void 0 ? void 0 : _d.length) - 1], this.tokens.endTagOpen, this.tokens.endTagName, this.tokens.endTagClose);
89
+ }
90
+ return this._range;
91
+ }
92
+ /**
93
+ * Is this a self-closing tag?
94
+ */
95
+ get isSelfClosing() {
96
+ var _a;
97
+ return this.tokens.startTagClose && ((_a = this.tokens.startTagClose) === null || _a === void 0 ? void 0 : _a.text) !== '>';
13
98
  }
14
99
  get id() {
15
100
  return this.getAttributeValue('id');
16
101
  }
17
102
  set id(value) {
18
- this.setAttribute('id', value);
103
+ this.setAttributeValue('id', value);
104
+ }
105
+ /**
106
+ * Get the name of this tag.
107
+ */
108
+ get tagName() {
109
+ var _a;
110
+ return (_a = this.tokens.startTagName) === null || _a === void 0 ? void 0 : _a.text;
111
+ }
112
+ /**
113
+ * Find all direct children by their tag name (case insensitive).
114
+ * This does not step into children's children.
115
+ *
116
+ */
117
+ getElementsByTagName(tagName) {
118
+ const result = [];
119
+ const lowerTagName = tagName.toLowerCase();
120
+ for (const el of this.elements) {
121
+ if (el.tokens.startTagName.text.toLowerCase() === lowerTagName) {
122
+ result.push(el);
123
+ }
124
+ }
125
+ return result;
126
+ }
127
+ /**
128
+ * Add a child to the end of the children array
129
+ */
130
+ addChild(tag) {
131
+ this.elements.push(tag);
132
+ return tag;
133
+ }
134
+ /**
135
+ * Remove a child from the children array.
136
+ * @returns true if node was found and removed, false if the node wasn't there and thus nothing was done
137
+ */
138
+ removeChild(tag) {
139
+ const idx = this.elements.indexOf(tag);
140
+ if (idx > -1) {
141
+ this.elements.splice(idx, 1);
142
+ return true;
143
+ }
144
+ return false;
145
+ }
146
+ /**
147
+ * Does this node have the specified attribute?
148
+ */
149
+ hasAttribute(name) {
150
+ return !!this.getAttribute(name);
19
151
  }
152
+ /**
153
+ * Get an SGAttribute by its name (case INsensitive)
154
+ */
20
155
  getAttribute(name) {
21
- return this.attributes.find(att => att.key.text.toLowerCase() === name);
156
+ var _a;
157
+ const nameLower = name.toLowerCase();
158
+ for (const attr of this.attributes) {
159
+ if (((_a = attr.tokens.key) === null || _a === void 0 ? void 0 : _a.text.toLowerCase()) === nameLower) {
160
+ return attr;
161
+ }
162
+ }
22
163
  }
164
+ /**
165
+ * Get an attribute value by its name
166
+ */
23
167
  getAttributeValue(name) {
24
168
  var _a, _b;
25
- return (_b = (_a = this.getAttribute(name)) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.text;
26
- }
27
- setAttribute(name, value) {
28
- const attr = this.getAttribute(name);
29
- if (attr) {
30
- if (value) {
31
- attr.value = { text: value };
32
- attr.range = undefined;
33
- }
34
- else {
35
- this.attributes.splice(this.attributes.indexOf(attr), 1);
169
+ return (_b = (_a = this.getAttribute(name)) === null || _a === void 0 ? void 0 : _a.tokens.value) === null || _b === void 0 ? void 0 : _b.text;
170
+ }
171
+ /**
172
+ * Set an attribute value by its name. If no attribute exists with this name, it is created
173
+ */
174
+ setAttributeValue(name, value) {
175
+ if (value === undefined) {
176
+ this.removeAttribute(name);
177
+ }
178
+ else {
179
+ let attr = this.getAttribute(name);
180
+ //create an attribute with this name if we don't have one yet
181
+ if (!attr) {
182
+ attr = (0, creators_1.createSGAttribute)(name, value);
183
+ this.attributes.push(attr);
36
184
  }
185
+ attr.value = value;
37
186
  }
38
- else if (value) {
39
- this.attributes.push({
40
- key: { text: name },
41
- value: { text: value }
42
- });
187
+ }
188
+ /**
189
+ * Remove an attribute by its name. DO NOT USE this to edit AST (use ASTEditor)
190
+ * @returns true if an attribute was found and removed. False if no attribute was found
191
+ */
192
+ removeAttribute(name) {
193
+ var _a;
194
+ const nameLower = name.toLowerCase();
195
+ for (let i = 0; i < this.attributes.length; i++) {
196
+ if (((_a = this.attributes[i].key) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === nameLower) {
197
+ this.attributes.splice(i, 1);
198
+ return true;
199
+ }
43
200
  }
201
+ return false;
44
202
  }
45
203
  transpile(state) {
46
- return new source_map_1.SourceNode(null, null, state.srcPath, [
47
- state.indentText,
48
- '<',
49
- state.transpileToken(this.tag),
50
- ...this.transpileAttributes(state, this.attributes),
51
- ...this.transpileBody(state)
204
+ return util_1.default.sourceNodeFromTranspileResult(null, null, null, [
205
+ state.transpileToken(this.tokens.startTagOpen, '<'),
206
+ state.transpileToken(this.tokens.startTagName),
207
+ this.transpileAttributes(state, this.attributes),
208
+ this.transpileBody(state)
52
209
  ]);
53
210
  }
54
211
  transpileBody(state) {
55
- return [' />\n'];
212
+ var _a;
213
+ if (this.isSelfClosing && this.elements.length === 0) {
214
+ return util_1.default.sourceNodeFromTranspileResult(null, null, null, [
215
+ ' ',
216
+ state.transpileToken(this.tokens.startTagClose, '/>'),
217
+ state.newline
218
+ ]);
219
+ }
220
+ else {
221
+ // it is possible that the original tag isSelfClosing, but new elements have been added to it
222
+ // in that case, create a new startTagClose token for transpilation.
223
+ const startTagClose = this.isSelfClosing ? (0, creators_1.createSGToken)('>', this.tokens.startTagClose.range) : this.tokens.startTagClose;
224
+ const chunks = [
225
+ state.transpileToken(startTagClose, '>'),
226
+ state.newline
227
+ ];
228
+ state.blockDepth++;
229
+ for (const child of this.elements) {
230
+ chunks.push(state.indentText, child.transpile(state));
231
+ }
232
+ state.blockDepth--;
233
+ chunks.push(state.indentText, state.transpileToken(this.tokens.endTagOpen, '</'), state.transpileToken((_a = this.tokens.endTagName) !== null && _a !== void 0 ? _a : this.tokens.startTagName), state.transpileToken(this.tokens.endTagClose, '>'), state.newline);
234
+ return util_1.default.sourceNodeFromTranspileResult(null, null, null, chunks);
235
+ }
56
236
  }
57
237
  transpileAttributes(state, attributes) {
58
- const result = [];
238
+ const chunks = [];
59
239
  for (const attr of attributes) {
60
- result.push(' ', state.transpileToken(attr.key), '="', state.transpileToken(attr.value), '"');
240
+ chunks.push(' ', attr.transpile(state));
61
241
  }
62
- return result;
242
+ return new source_map_1.SourceNode(null, null, null, chunks);
63
243
  }
64
244
  }
65
- exports.SGTag = SGTag;
66
- class SGProlog extends SGTag {
67
- transpile(state) {
68
- return new source_map_1.SourceNode(null, null, state.srcPath, [
69
- '<?xml',
70
- ...this.transpileAttributes(state, this.attributes),
71
- ' ?>\n'
72
- ]);
73
- }
245
+ exports.SGElement = SGElement;
246
+ class SGProlog extends SGElement {
74
247
  }
75
248
  exports.SGProlog = SGProlog;
76
- class SGNode extends SGTag {
77
- constructor(tag, attributes, children = [], range) {
78
- super(tag, attributes, range);
79
- this.children = children;
80
- }
81
- transpileBody(state) {
82
- if (this.children.length > 0) {
83
- const body = ['>\n'];
84
- state.blockDepth++;
85
- body.push(...this.children.map(node => node.transpile(state)));
86
- state.blockDepth--;
87
- body.push(state.indentText, '</', this.tag.text, '>\n');
88
- return body;
89
- }
90
- else {
91
- return super.transpileBody(state);
92
- }
93
- }
249
+ class SGNode extends SGElement {
94
250
  }
95
251
  exports.SGNode = SGNode;
96
- class SGChildren extends SGNode {
97
- constructor(tag = { text: 'children' }, children = [], range) {
98
- super(tag, [], children, range);
99
- }
252
+ class SGChildren extends SGElement {
100
253
  }
101
254
  exports.SGChildren = SGChildren;
102
- class SGScript extends SGTag {
103
- constructor(tag = { text: 'script' }, attributes, cdata, range) {
104
- super(tag, attributes, range);
105
- this.cdata = cdata;
106
- if (!attributes) {
107
- this.type = 'text/brightscript';
108
- }
109
- }
255
+ class SGCustomization extends SGElement {
256
+ }
257
+ exports.SGCustomization = SGCustomization;
258
+ class SGScript extends SGElement {
110
259
  get type() {
111
260
  return this.getAttributeValue('type');
112
261
  }
113
262
  set type(value) {
114
- this.setAttribute('type', value);
263
+ this.setAttributeValue('type', value);
115
264
  }
116
265
  get uri() {
117
266
  return this.getAttributeValue('uri');
118
267
  }
119
268
  set uri(value) {
120
- this.setAttribute('uri', value);
269
+ this.setAttributeValue('uri', value);
121
270
  }
122
271
  transpileBody(state) {
123
272
  if (this.cdata) {
124
- return [
273
+ return util_1.default.sourceNodeFromTranspileResult(null, null, null, [
125
274
  '>',
126
275
  state.transpileToken(this.cdata),
127
276
  '</',
128
- this.tag.text,
129
- '>\n'
130
- ];
277
+ this.tokens.startTagName.text,
278
+ '>',
279
+ state.newline
280
+ ]);
131
281
  }
132
282
  else {
133
283
  return super.transpileBody(state);
134
284
  }
135
285
  }
136
286
  transpileAttributes(state, attributes) {
287
+ var _a, _b, _c;
137
288
  const modifiedAttributes = [];
138
289
  let foundType = false;
139
290
  const bsExtensionRegexp = /\.bs$/i;
140
291
  for (const attr of attributes) {
141
- const lowerKey = attr.key.text.toLowerCase();
142
- if (lowerKey === 'uri' && bsExtensionRegexp.exec(attr.value.text)) {
143
- modifiedAttributes.push(util_1.default.cloneSGAttribute(attr, attr.value.text.replace(bsExtensionRegexp, '.brs')));
292
+ const lowerKey = (_a = attr.tokens.key) === null || _a === void 0 ? void 0 : _a.text.toLowerCase();
293
+ if (lowerKey === 'uri' && bsExtensionRegexp.exec((_b = attr.tokens.value) === null || _b === void 0 ? void 0 : _b.text)) {
294
+ const clone = attr.clone();
295
+ clone.tokens.value.text.replace(bsExtensionRegexp, '.brs');
296
+ modifiedAttributes.push(clone);
144
297
  }
145
298
  else if (lowerKey === 'type') {
146
299
  foundType = true;
147
- if (attr.value.text.toLowerCase().endsWith('brighterscript')) {
148
- modifiedAttributes.push(util_1.default.cloneSGAttribute(attr, 'text/brightscript'));
300
+ if ((_c = attr.tokens.value) === null || _c === void 0 ? void 0 : _c.text.toLowerCase().endsWith('brighterscript')) {
301
+ modifiedAttributes.push(attr.clone());
149
302
  }
150
303
  else {
151
304
  modifiedAttributes.push(attr);
@@ -156,94 +309,141 @@ class SGScript extends SGTag {
156
309
  }
157
310
  }
158
311
  if (!foundType) {
159
- modifiedAttributes.push(creators_1.createSGAttribute('type', 'text/brightscript'));
312
+ modifiedAttributes.push((0, creators_1.createSGAttribute)('type', 'text/brightscript'));
160
313
  }
161
314
  return super.transpileAttributes(state, modifiedAttributes);
162
315
  }
163
316
  }
164
317
  exports.SGScript = SGScript;
165
- class SGField extends SGTag {
166
- constructor(tag = { text: 'field' }, attributes = [], range) {
167
- super(tag, attributes, range);
168
- }
318
+ class SGInterfaceField extends SGElement {
169
319
  get type() {
170
320
  return this.getAttributeValue('type');
171
321
  }
172
322
  set type(value) {
173
- this.setAttribute('type', value);
323
+ this.setAttributeValue('type', value);
174
324
  }
175
325
  get alias() {
176
326
  return this.getAttributeValue('alias');
177
327
  }
178
328
  set alias(value) {
179
- this.setAttribute('alias', value);
329
+ this.setAttributeValue('alias', value);
180
330
  }
181
331
  get value() {
182
332
  return this.getAttributeValue('value');
183
333
  }
184
334
  set value(value) {
185
- this.setAttribute('value', value);
335
+ this.setAttributeValue('value', value);
186
336
  }
187
337
  get onChange() {
188
338
  return this.getAttributeValue('onChange');
189
339
  }
190
340
  set onChange(value) {
191
- this.setAttribute('onChange', value);
341
+ this.setAttributeValue('onChange', value);
192
342
  }
193
343
  get alwaysNotify() {
194
344
  return this.getAttributeValue('alwaysNotify');
195
345
  }
196
346
  set alwaysNotify(value) {
197
- this.setAttribute('alwaysNotify', value);
347
+ this.setAttributeValue('alwaysNotify', value);
198
348
  }
199
349
  }
200
- exports.SGField = SGField;
201
- exports.SGFieldTypes = [
202
- 'integer', 'int', 'longinteger', 'float', 'string', 'str', 'boolean', 'bool',
203
- 'vector2d', 'color', 'time', 'uri', 'node', 'floatarray', 'intarray', 'boolarray',
204
- 'stringarray', 'vector2darray', 'colorarray', 'timearray', 'nodearray', 'assocarray',
205
- 'array', 'roarray', 'rect2d', 'rect2darray'
206
- ];
207
- class SGFunction extends SGTag {
208
- constructor(tag = { text: 'function' }, attributes = [], range) {
209
- super(tag, attributes, range);
210
- }
350
+ exports.SGInterfaceField = SGInterfaceField;
351
+ var SGFieldType;
352
+ (function (SGFieldType) {
353
+ SGFieldType["integer"] = "integer";
354
+ SGFieldType["int"] = "int";
355
+ SGFieldType["longinteger"] = "longinteger";
356
+ SGFieldType["float"] = "float";
357
+ SGFieldType["string"] = "string";
358
+ SGFieldType["str"] = "str";
359
+ SGFieldType["boolean"] = "boolean";
360
+ SGFieldType["bool"] = "bool";
361
+ SGFieldType["vector2d"] = "vector2d";
362
+ SGFieldType["color"] = "color";
363
+ SGFieldType["time"] = "time";
364
+ SGFieldType["uri"] = "uri";
365
+ SGFieldType["node"] = "node";
366
+ SGFieldType["floatarray"] = "floatarray";
367
+ SGFieldType["intarray"] = "intarray";
368
+ SGFieldType["boolarray"] = "boolarray";
369
+ SGFieldType["stringarray"] = "stringarray";
370
+ SGFieldType["vector2darray"] = "vector2darray";
371
+ SGFieldType["colorarray"] = "colorarray";
372
+ SGFieldType["timearray"] = "timearray";
373
+ SGFieldType["nodearray"] = "nodearray";
374
+ SGFieldType["assocarray"] = "assocarray";
375
+ SGFieldType["array"] = "array";
376
+ SGFieldType["roarray"] = "roarray";
377
+ SGFieldType["rect2d"] = "rect2d";
378
+ SGFieldType["rect2darray"] = "rect2darray";
379
+ })(SGFieldType = exports.SGFieldType || (exports.SGFieldType = {}));
380
+ exports.SGFieldTypes = Object.keys(SGFieldType);
381
+ class SGInterfaceFunction extends SGElement {
211
382
  get name() {
212
383
  return this.getAttributeValue('name');
213
384
  }
214
385
  set name(value) {
215
- this.setAttribute('name', value);
386
+ this.setAttributeValue('name', value);
216
387
  }
217
388
  }
218
- exports.SGFunction = SGFunction;
219
- class SGInterface extends SGTag {
220
- constructor(tag = { text: 'interface' }, content, range) {
221
- super(tag, [], range);
222
- this.fields = [];
223
- this.functions = [];
224
- if (content) {
225
- for (const tag of content) {
226
- if (xml_1.isSGField(tag)) {
227
- this.fields.push(tag);
228
- }
229
- else if (xml_1.isSGFunction(tag)) {
230
- this.functions.push(tag);
231
- }
232
- else {
233
- throw new Error(`Unexpected tag ${tag.tag.text}`);
234
- }
389
+ exports.SGInterfaceFunction = SGInterfaceFunction;
390
+ class SGInterface extends SGElement {
391
+ get fields() {
392
+ return this.getElementsByTagName('field');
393
+ }
394
+ get functions() {
395
+ return this.getElementsByTagName('function');
396
+ }
397
+ get members() {
398
+ var _a;
399
+ const result = [];
400
+ for (const node of this.elements) {
401
+ const tagName = (_a = node.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase();
402
+ if (tagName === 'field' || tagName === 'function') {
403
+ result.push(node);
235
404
  }
236
405
  }
406
+ return result;
237
407
  }
408
+ /**
409
+ * Check if there's an SGField with the specified name
410
+ */
411
+ hasField(id) {
412
+ var _a;
413
+ for (const node of this.elements) {
414
+ const tagName = (_a = node.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase();
415
+ if (tagName === 'field' && node.id === id) {
416
+ return true;
417
+ }
418
+ }
419
+ return false;
420
+ }
421
+ /**
422
+ * Check if there's an SGFunction with the specified name
423
+ */
424
+ hasFunction(name) {
425
+ var _a;
426
+ for (const node of this.elements) {
427
+ const tagName = (_a = node.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase();
428
+ if (tagName === 'function' && node.name === name) {
429
+ return true;
430
+ }
431
+ }
432
+ return false;
433
+ }
434
+ /**
435
+ * Find a field by its ID
436
+ */
238
437
  getField(id) {
239
438
  return this.fields.find(field => field.id === id);
240
439
  }
440
+ /**
441
+ * Set the value of a field. Creates a new field if one does not already exist with this ID
442
+ */
241
443
  setField(id, type, onChange, alwaysNotify, alias) {
242
444
  let field = this.getField(id);
243
445
  if (!field) {
244
- field = new SGField();
245
- field.id = id;
246
- this.fields.push(field);
446
+ field = this.addChild((0, creators_1.createSGInterfaceField)(id));
247
447
  }
248
448
  field.type = type;
249
449
  field.onChange = onChange;
@@ -254,101 +454,254 @@ class SGInterface extends SGTag {
254
454
  field.alwaysNotify = alwaysNotify ? 'true' : 'false';
255
455
  }
256
456
  field.alias = alias;
457
+ return field;
458
+ }
459
+ /**
460
+ * Remove a field from the interface
461
+ * @returns true if a field was found and removed. Returns false if no field was found with that name
462
+ */
463
+ removeField(id) {
464
+ var _a;
465
+ for (let i = 0; i < this.elements.length; i++) {
466
+ const node = this.elements[i];
467
+ if (((_a = node.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'field' && node.id === id) {
468
+ this.elements.splice(i, 1);
469
+ return true;
470
+ }
471
+ }
472
+ return false;
257
473
  }
474
+ /**
475
+ * Get the interface function with the specified name
476
+ */
258
477
  getFunction(name) {
259
- return this.functions.find(field => field.name === name);
478
+ return this.functions.find(func => func.name === name);
260
479
  }
480
+ /**
481
+ * Add or replace a function on the interface
482
+ */
261
483
  setFunction(name) {
262
484
  let func = this.getFunction(name);
263
485
  if (!func) {
264
- func = new SGFunction();
265
- func.name = name;
266
- this.functions.push(func);
486
+ func = this.addChild((0, creators_1.createSGInterfaceFunction)(name));
267
487
  }
268
- }
269
- transpileBody(state) {
270
- const body = ['>\n'];
271
- state.blockDepth++;
272
- if (this.fields.length > 0) {
273
- body.push(...this.fields.map(node => node.transpile(state)));
274
- }
275
- if (this.functions.length > 0) {
276
- body.push(...this.functions.map(node => node.transpile(state)));
488
+ return func;
489
+ }
490
+ /**
491
+ * Remove a function from the interface
492
+ * @returns true if a function was found and removed. Returns false if no function was found with that name
493
+ */
494
+ removeFunction(name) {
495
+ var _a;
496
+ for (let i = 0; i < this.elements.length; i++) {
497
+ const node = this.elements[i];
498
+ if (((_a = node.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'function' && node.getAttributeValue('name') === name) {
499
+ this.elements.splice(i, 1);
500
+ return true;
501
+ }
277
502
  }
278
- state.blockDepth--;
279
- body.push(state.indentText, '</', this.tag.text, '>\n');
280
- return body;
503
+ return false;
281
504
  }
282
505
  }
283
506
  exports.SGInterface = SGInterface;
284
- class SGComponent extends SGTag {
285
- constructor(tag = { text: 'component' }, attributes, content, range) {
286
- super(tag, attributes, range);
287
- this.scripts = [];
288
- if (content) {
289
- for (const tag of content) {
290
- if (xml_1.isSGInterface(tag)) {
291
- this.api = tag;
292
- }
293
- else if (xml_1.isSGScript(tag)) {
294
- this.scripts.push(tag);
295
- }
296
- else if (xml_1.isSGChildren(tag)) {
297
- this.children = tag;
298
- }
299
- else {
300
- throw new Error(`Unexpected tag ${tag.tag.text}`);
301
- }
302
- }
507
+ /**
508
+ * The `<component>` element in SceneGraph. Not to be confused about usages of components like `<Rectangle>`, those are considered `SGNode` instances.
509
+ */
510
+ class SGComponent extends SGElement {
511
+ /**
512
+ * Get all the <Field> and <Function> elements across all <Interface> nodes in this component
513
+ */
514
+ get interfaceMembers() {
515
+ const members = [];
516
+ for (const ifaceNode of this.getElementsByTagName('interface')) {
517
+ members.push(...ifaceNode.members);
303
518
  }
304
- }
519
+ return members;
520
+ }
521
+ get scriptElements() {
522
+ return this.getElementsByTagName('script');
523
+ }
524
+ /**
525
+ * Get the <interface> element from this component (if present), or undefined if not.
526
+ * NOTE: Roku supports and merges multiple <interface> elements in a component, but this
527
+ * property points to the FIRST one. If you need to check whether a member exists,
528
+ * look through `this.interfaceMemebers` instead.
529
+ */
530
+ get interfaceElement() {
531
+ return this.getElementsByTagName('interface')[0];
532
+ }
533
+ /**
534
+ * Get the `<children>` element of this component. (not to be confused with the AST `childTags` property).
535
+ * If there are multiope `<children>` elements, this function will return the last `<children>` tag because that's what Roku devices do.
536
+ */
537
+ get childrenElement() {
538
+ const children = this.getElementsByTagName('children');
539
+ return children[children.length - 1];
540
+ }
541
+ get customizationElements() {
542
+ return this.getElementsByTagName('customization');
543
+ }
544
+ /**
545
+ * Specifies the name of the component, that allows you to create the component in your application.
546
+ * For example, if the name of the component is `CastMemberInfo`, you could create instances of the component declaratively
547
+ * in a child node element of a component `<children>` element (`<CastMemberInfo/>`), or using BrightScript in a `<script>`
548
+ * element (`createObject("roSGNode","CastMemberInfo")`).
549
+ *
550
+ * The name attribute is case-sensitive. You cannot successfully create or declare a component unless the component name exactly
551
+ * matches the name attribute, including case. Also be aware that two components with the exact same name in the same application
552
+ * components directory will have undefined and generally undesirable results if you attempt to create a component object with that name in the application.
553
+ */
305
554
  get name() {
306
555
  return this.getAttributeValue('name');
307
556
  }
308
557
  set name(value) {
309
- this.setAttribute('name', value);
310
- }
558
+ this.setAttributeValue('name', value);
559
+ }
560
+ /**
561
+ * Specifies the name of the built-in or extended SceneGraph scene or node class whose functionality is extended by this component.
562
+ *
563
+ * For example, `extends="Group"` specifies that the component has all of the functionality of the Group node class (it can have child nodes, has translation/scale/rotation fields, and so forth).
564
+ *
565
+ * By default, a component extends the Group node class.
566
+ */
311
567
  get extends() {
312
568
  return this.getAttributeValue('extends');
313
569
  }
314
570
  set extends(value) {
315
- this.setAttribute('extends', value);
571
+ this.setAttributeValue('extends', value);
572
+ }
573
+ /**
574
+ * Specifies the ID of a node declared in the XML file to have the initial remote control focus when the component is instantiated.
575
+ */
576
+ get initialFocus() {
577
+ return this.getAttributeValue('initialFocus');
578
+ }
579
+ set initialFocus(value) {
580
+ this.setAttributeValue('initialFocus', value);
581
+ }
582
+ /**
583
+ * Specifies the version of the SceneGraph API. The default is 1.0 if not specified.
584
+ */
585
+ get version() {
586
+ return this.getAttributeValue('version');
587
+ }
588
+ set version(value) {
589
+ this.setAttributeValue('version', value);
590
+ }
591
+ /**
592
+ * Does the specified field exist in the component interface?
593
+ */
594
+ hasInterfaceField(id) {
595
+ for (const ifaceNode of this.getElementsByTagName('interface')) {
596
+ if (ifaceNode.hasField(id)) {
597
+ return true;
598
+ }
599
+ }
600
+ return false;
601
+ }
602
+ /**
603
+ * Does the specified function exist in the component interface?
604
+ */
605
+ hasInterfaceFunction(name) {
606
+ for (const ifaceNode of this.getElementsByTagName('interface')) {
607
+ if (ifaceNode.hasFunction(name)) {
608
+ return true;
609
+ }
610
+ }
611
+ return false;
612
+ }
613
+ /**
614
+ * Get an interface field with the specified name
615
+ */
616
+ getInterfaceField(name) {
617
+ for (const ifaceNode of this.getElementsByTagName('interface')) {
618
+ const field = ifaceNode.getField(name);
619
+ if (field) {
620
+ return field;
621
+ }
622
+ }
316
623
  }
317
- transpileBody(state) {
318
- const body = ['>\n'];
319
- state.blockDepth++;
320
- if (this.api) {
321
- body.push(this.api.transpile(state));
624
+ /**
625
+ * Return the first SGInterface node found, or insert a new one then return it
626
+ */
627
+ ensureInterfaceNode() {
628
+ for (const el of this.elements) {
629
+ if (el.tokens.startTagName.text.toLowerCase() === 'interface') {
630
+ return el;
631
+ }
632
+ }
633
+ return this.addChild((0, creators_1.createSGInterface)());
634
+ }
635
+ /**
636
+ * Create or update a <field> interface element.
637
+ * This will create a new `<interface>` element if there are none on the component already
638
+ */
639
+ setInterfaceField(id, type, onChange, alwaysNotify, alias) {
640
+ let ifaceNode = this.ensureInterfaceNode();
641
+ return ifaceNode.setField(id, type, onChange, alwaysNotify, alias);
642
+ }
643
+ /**
644
+ * Create or update a <function> interface element.
645
+ * This will create a new `<interface>` element if there are none on the component already
646
+ */
647
+ setInterfaceFunction(name) {
648
+ let ifaceNode = this.ensureInterfaceNode();
649
+ return ifaceNode.setFunction(name);
650
+ }
651
+ /**
652
+ * Remove an interface field.
653
+ * @returns true if a field was found and removed. Returns false if no field was found with that name
654
+ */
655
+ removeInterfaceField(id) {
656
+ for (const ifaceNode of this.getElementsByTagName('interface')) {
657
+ if (ifaceNode.removeField(id)) {
658
+ return true;
659
+ }
322
660
  }
323
- if (this.scripts.length > 0) {
324
- body.push(...this.scripts.map(node => node.transpile(state)));
661
+ return false;
662
+ }
663
+ /**
664
+ * Get an interface field with the specified name
665
+ */
666
+ getInterfaceFunction(name) {
667
+ for (const ifaceNode of this.getElementsByTagName('interface')) {
668
+ const func = ifaceNode.getFunction(name);
669
+ if (func) {
670
+ return func;
671
+ }
325
672
  }
326
- if (this.children) {
327
- body.push(this.children.transpile(state));
673
+ }
674
+ /**
675
+ * Remove an interface function.
676
+ * @returns true if a function was found and removed. Returns false if no function was found with that name
677
+ */
678
+ removeInterfaceFunction(name) {
679
+ for (const ifaceNode of this.getElementsByTagName('interface')) {
680
+ if (ifaceNode.removeFunction(name)) {
681
+ return true;
682
+ }
328
683
  }
329
- state.blockDepth--;
330
- body.push(state.indentText, '</', this.tag.text, '>\n');
331
- return body;
684
+ return false;
332
685
  }
333
686
  }
334
687
  exports.SGComponent = SGComponent;
335
688
  class SGAst {
336
- constructor(prolog, root, component) {
337
- this.prolog = prolog;
338
- this.root = root;
339
- this.component = component;
689
+ constructor(options = {}) {
690
+ this.prologElement = options.prologElement;
691
+ this.rootElement = options.rootElement;
692
+ this.componentElement = options.componentElement;
340
693
  }
341
694
  transpile(state) {
342
695
  const chunks = [];
343
696
  //write XML prolog
344
- if (this.prolog) {
345
- chunks.push(this.prolog.transpile(state));
697
+ if (this.prologElement) {
698
+ chunks.push(this.prologElement.transpile(state));
346
699
  }
347
- if (this.component) {
700
+ if (this.componentElement) {
348
701
  //write content
349
- chunks.push(this.component.transpile(state));
702
+ chunks.push(this.componentElement.transpile(state));
350
703
  }
351
- return chunks;
704
+ return new source_map_1.SourceNode(null, null, null, chunks);
352
705
  }
353
706
  }
354
707
  exports.SGAst = SGAst;