brighterscript 1.0.0-alpha.5 → 1.0.0-alpha.50
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.
- package/README.md +76 -138
- package/bsconfig.schema.json +121 -5
- package/dist/ActionPipeline.d.ts +10 -0
- package/dist/ActionPipeline.js +40 -0
- package/dist/ActionPipeline.js.map +1 -0
- package/dist/AstValidationSegmenter.d.ts +45 -0
- package/dist/AstValidationSegmenter.js +322 -0
- package/dist/AstValidationSegmenter.js.map +1 -0
- package/dist/BsConfig.d.ts +72 -39
- package/dist/BusyStatusTracker.d.ts +61 -0
- package/dist/BusyStatusTracker.js +148 -0
- package/dist/BusyStatusTracker.js.map +1 -0
- package/dist/Cache.d.ts +3 -8
- package/dist/Cache.js +9 -14
- package/dist/Cache.js.map +1 -1
- package/dist/CacheVerifier.d.ts +7 -0
- package/dist/CacheVerifier.js +20 -0
- package/dist/CacheVerifier.js.map +1 -0
- package/dist/CodeActionUtil.d.ts +12 -4
- package/dist/CodeActionUtil.js +22 -5
- package/dist/CodeActionUtil.js.map +1 -1
- package/dist/CommentFlagProcessor.d.ts +7 -6
- package/dist/CommentFlagProcessor.js +11 -8
- package/dist/CommentFlagProcessor.js.map +1 -1
- package/dist/CrossScopeValidator.d.ts +68 -0
- package/dist/CrossScopeValidator.js +642 -0
- package/dist/CrossScopeValidator.js.map +1 -0
- package/dist/DependencyGraph.d.ts +8 -3
- package/dist/DependencyGraph.js +49 -16
- package/dist/DependencyGraph.js.map +1 -1
- package/dist/DiagnosticCollection.d.ts +21 -5
- package/dist/DiagnosticCollection.js +77 -24
- package/dist/DiagnosticCollection.js.map +1 -1
- package/dist/DiagnosticFilterer.d.ts +27 -6
- package/dist/DiagnosticFilterer.js +273 -60
- package/dist/DiagnosticFilterer.js.map +1 -1
- package/dist/DiagnosticManager.d.ts +82 -0
- package/dist/DiagnosticManager.js +406 -0
- package/dist/DiagnosticManager.js.map +1 -0
- package/dist/DiagnosticMessages.d.ts +558 -196
- package/dist/DiagnosticMessages.js +870 -340
- package/dist/DiagnosticMessages.js.map +1 -1
- package/dist/DiagnosticSeverityAdjuster.d.ts +7 -0
- package/dist/DiagnosticSeverityAdjuster.js +45 -0
- package/dist/DiagnosticSeverityAdjuster.js.map +1 -0
- package/dist/FunctionScope.d.ts +28 -0
- package/dist/FunctionScope.js +52 -0
- package/dist/FunctionScope.js.map +1 -0
- package/dist/KeyedThrottler.d.ts +3 -3
- package/dist/KeyedThrottler.js +3 -3
- package/dist/KeyedThrottler.js.map +1 -1
- package/dist/LanguageServer.d.ts +100 -105
- package/dist/LanguageServer.js +444 -745
- package/dist/LanguageServer.js.map +1 -1
- package/dist/Logger.d.ts +17 -13
- package/dist/Logger.js +64 -34
- package/dist/Logger.js.map +1 -1
- package/dist/PluginInterface.d.ts +32 -10
- package/dist/PluginInterface.js +117 -7
- package/dist/PluginInterface.js.map +1 -1
- package/dist/Program.d.ts +241 -98
- package/dist/Program.js +1432 -717
- package/dist/Program.js.map +1 -1
- package/dist/ProgramBuilder.d.ts +47 -23
- package/dist/ProgramBuilder.js +224 -178
- package/dist/ProgramBuilder.js.map +1 -1
- package/dist/Scope.d.ts +149 -109
- package/dist/Scope.js +557 -550
- package/dist/Scope.js.map +1 -1
- package/dist/SemanticTokenUtils.js +5 -1
- package/dist/SemanticTokenUtils.js.map +1 -1
- package/dist/Stopwatch.d.ts +4 -0
- package/dist/Stopwatch.js +8 -1
- package/dist/Stopwatch.js.map +1 -1
- package/dist/SymbolTable.d.ts +136 -24
- package/dist/SymbolTable.js +565 -64
- package/dist/SymbolTable.js.map +1 -1
- package/dist/SymbolTypeFlag.d.ts +9 -0
- package/dist/SymbolTypeFlag.js +14 -0
- package/dist/SymbolTypeFlag.js.map +1 -0
- package/dist/Throttler.d.ts +12 -0
- package/dist/Throttler.js +39 -0
- package/dist/Throttler.js.map +1 -1
- package/dist/Watcher.d.ts +0 -3
- package/dist/Watcher.js +0 -3
- package/dist/Watcher.js.map +1 -1
- package/dist/XmlScope.d.ts +5 -15
- package/dist/XmlScope.js +34 -90
- package/dist/XmlScope.js.map +1 -1
- package/dist/astUtils/CachedLookups.d.ts +50 -0
- package/dist/astUtils/CachedLookups.js +334 -0
- package/dist/astUtils/CachedLookups.js.map +1 -0
- package/dist/astUtils/CachedLookups.spec.js +39 -0
- package/dist/astUtils/CachedLookups.spec.js.map +1 -0
- package/dist/astUtils/Editor.d.ts +69 -0
- package/dist/astUtils/Editor.js +245 -0
- package/dist/astUtils/Editor.js.map +1 -0
- package/dist/astUtils/Editor.spec.js +258 -0
- package/dist/astUtils/Editor.spec.js.map +1 -0
- package/dist/astUtils/creators.d.ts +54 -19
- package/dist/astUtils/creators.js +242 -42
- package/dist/astUtils/creators.js.map +1 -1
- package/dist/astUtils/creators.spec.js +5 -5
- package/dist/astUtils/creators.spec.js.map +1 -1
- package/dist/astUtils/reflection.d.ts +196 -85
- package/dist/astUtils/reflection.js +497 -144
- package/dist/astUtils/reflection.js.map +1 -1
- package/dist/astUtils/reflection.spec.js +267 -167
- package/dist/astUtils/reflection.spec.js.map +1 -1
- package/dist/astUtils/stackedVisitor.js.map +1 -1
- package/dist/astUtils/stackedVisitor.spec.js +14 -14
- package/dist/astUtils/stackedVisitor.spec.js.map +1 -1
- package/dist/astUtils/visitors.d.ts +116 -53
- package/dist/astUtils/visitors.js +95 -15
- package/dist/astUtils/visitors.js.map +1 -1
- package/dist/astUtils/visitors.spec.js +629 -51
- package/dist/astUtils/visitors.spec.js.map +1 -1
- package/dist/astUtils/xml.d.ts +9 -8
- package/dist/astUtils/xml.js +12 -7
- package/dist/astUtils/xml.js.map +1 -1
- package/dist/bscPlugin/BscPlugin.d.ts +24 -4
- package/dist/bscPlugin/BscPlugin.js +88 -4
- package/dist/bscPlugin/BscPlugin.js.map +1 -1
- package/dist/bscPlugin/CallExpressionInfo.d.ts +36 -0
- package/dist/bscPlugin/CallExpressionInfo.js +143 -0
- package/dist/bscPlugin/CallExpressionInfo.js.map +1 -0
- package/dist/bscPlugin/FileWriter.d.ts +6 -0
- package/dist/bscPlugin/FileWriter.js +24 -0
- package/dist/bscPlugin/FileWriter.js.map +1 -0
- package/dist/bscPlugin/SignatureHelpUtil.d.ts +10 -0
- package/dist/bscPlugin/SignatureHelpUtil.js +137 -0
- package/dist/bscPlugin/SignatureHelpUtil.js.map +1 -0
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.d.ts +6 -5
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +173 -27
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +138 -21
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/completions/CompletionsProcessor.d.ts +65 -0
- package/dist/bscPlugin/completions/CompletionsProcessor.js +633 -0
- package/dist/bscPlugin/completions/CompletionsProcessor.js.map +1 -0
- package/dist/bscPlugin/completions/CompletionsProcessor.spec.js +2512 -0
- package/dist/bscPlugin/completions/CompletionsProcessor.spec.js.map +1 -0
- package/dist/bscPlugin/definition/DefinitionProvider.d.ts +13 -0
- package/dist/bscPlugin/definition/DefinitionProvider.js +212 -0
- package/dist/bscPlugin/definition/DefinitionProvider.js.map +1 -0
- package/dist/bscPlugin/definition/DefinitionProvider.spec.js +87 -0
- package/dist/bscPlugin/definition/DefinitionProvider.spec.js.map +1 -0
- package/dist/bscPlugin/fileProviders/FileProvider.d.ts +9 -0
- package/dist/bscPlugin/fileProviders/FileProvider.js +51 -0
- package/dist/bscPlugin/fileProviders/FileProvider.js.map +1 -0
- package/dist/bscPlugin/hover/HoverProcessor.d.ts +18 -0
- package/dist/bscPlugin/hover/HoverProcessor.js +230 -0
- package/dist/bscPlugin/hover/HoverProcessor.js.map +1 -0
- package/dist/bscPlugin/hover/HoverProcessor.spec.js +991 -0
- package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +1 -0
- package/dist/bscPlugin/references/ReferencesProvider.d.ts +12 -0
- package/dist/bscPlugin/references/ReferencesProvider.js +57 -0
- package/dist/bscPlugin/references/ReferencesProvider.js.map +1 -0
- package/dist/bscPlugin/references/ReferencesProvider.spec.d.ts +1 -0
- package/dist/bscPlugin/references/ReferencesProvider.spec.js +51 -0
- package/dist/bscPlugin/references/ReferencesProvider.spec.js.map +1 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.d.ts +14 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +164 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.d.ts +1 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js +564 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +1 -0
- package/dist/bscPlugin/serialize/BslibInjector.spec.d.ts +1 -0
- package/dist/bscPlugin/serialize/BslibInjector.spec.js +33 -0
- package/dist/bscPlugin/serialize/BslibInjector.spec.js.map +1 -0
- package/dist/bscPlugin/serialize/BslibManager.d.ts +12 -0
- package/dist/bscPlugin/serialize/BslibManager.js +46 -0
- package/dist/bscPlugin/serialize/BslibManager.js.map +1 -0
- package/dist/bscPlugin/serialize/FileSerializer.d.ts +9 -0
- package/dist/bscPlugin/serialize/FileSerializer.js +75 -0
- package/dist/bscPlugin/serialize/FileSerializer.js.map +1 -0
- package/dist/bscPlugin/symbols/DocumentSymbolProcessor.d.ts +7 -0
- package/dist/bscPlugin/symbols/DocumentSymbolProcessor.js +22 -0
- package/dist/bscPlugin/symbols/DocumentSymbolProcessor.js.map +1 -0
- package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.d.ts +1 -0
- package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.js +291 -0
- package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.js.map +1 -0
- package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.d.ts +7 -0
- package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.js +26 -0
- package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.js.map +1 -0
- package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.d.ts +1 -0
- package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.js +245 -0
- package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.js.map +1 -0
- package/dist/bscPlugin/symbols/symbolUtils.d.ts +5 -0
- package/dist/bscPlugin/symbols/symbolUtils.js +141 -0
- package/dist/bscPlugin/symbols/symbolUtils.js.map +1 -0
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.d.ts +27 -0
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js +418 -0
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js.map +1 -0
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.d.ts +1 -0
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.js +75 -0
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.js.map +1 -0
- package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.d.ts +12 -0
- package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.js +99 -0
- package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.js.map +1 -0
- package/dist/bscPlugin/validation/BrsFileAfterValidator.d.ts +7 -0
- package/dist/bscPlugin/validation/BrsFileAfterValidator.js +18 -0
- package/dist/bscPlugin/validation/BrsFileAfterValidator.js.map +1 -0
- package/dist/bscPlugin/validation/BrsFileValidator.d.ts +37 -0
- package/dist/bscPlugin/validation/BrsFileValidator.js +638 -0
- package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -0
- package/dist/bscPlugin/validation/BrsFileValidator.spec.d.ts +1 -0
- package/dist/bscPlugin/validation/BrsFileValidator.spec.js +1517 -0
- package/dist/bscPlugin/validation/BrsFileValidator.spec.js.map +1 -0
- package/dist/bscPlugin/validation/ProgramValidator.d.ts +11 -0
- package/dist/bscPlugin/validation/ProgramValidator.js +33 -0
- package/dist/bscPlugin/validation/ProgramValidator.js.map +1 -0
- package/dist/bscPlugin/validation/ScopeValidator.d.ts +141 -0
- package/dist/bscPlugin/validation/ScopeValidator.js +1323 -0
- package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -0
- package/dist/bscPlugin/validation/ScopeValidator.spec.d.ts +1 -0
- package/dist/bscPlugin/validation/ScopeValidator.spec.js +6135 -0
- package/dist/bscPlugin/validation/ScopeValidator.spec.js.map +1 -0
- package/dist/bscPlugin/validation/XmlFileValidator.d.ts +8 -0
- package/dist/bscPlugin/validation/XmlFileValidator.js +36 -0
- package/dist/bscPlugin/validation/XmlFileValidator.js.map +1 -0
- package/dist/cli.js +126 -27
- package/dist/cli.js.map +1 -1
- package/dist/common/Sequencer.d.ts +53 -0
- package/dist/common/Sequencer.js +233 -0
- package/dist/common/Sequencer.js.map +1 -0
- package/dist/common/Sequencer.spec.d.ts +1 -0
- package/dist/common/Sequencer.spec.js +75 -0
- package/dist/common/Sequencer.spec.js.map +1 -0
- package/dist/deferred.d.ts +5 -3
- package/dist/deferred.js +10 -0
- package/dist/deferred.js.map +1 -1
- package/dist/diagnosticUtils.d.ts +10 -3
- package/dist/diagnosticUtils.js +64 -25
- package/dist/diagnosticUtils.js.map +1 -1
- package/dist/examples/plugins/removePrint.d.ts +2 -2
- package/dist/examples/plugins/removePrint.js +8 -12
- package/dist/examples/plugins/removePrint.js.map +1 -1
- package/dist/files/AssetFile.d.ts +24 -0
- package/dist/files/AssetFile.js +25 -0
- package/dist/files/AssetFile.js.map +1 -0
- package/dist/files/BrsFile.Class.spec.js +1213 -259
- package/dist/files/BrsFile.Class.spec.js.map +1 -1
- package/dist/files/BrsFile.d.ts +145 -87
- package/dist/files/BrsFile.js +836 -934
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/BrsFile.spec.js +4226 -902
- package/dist/files/BrsFile.spec.js.map +1 -1
- package/dist/files/BscFile.d.ts +102 -0
- package/dist/files/BscFile.js +15 -0
- package/dist/files/BscFile.js.map +1 -0
- package/dist/files/Factory.d.ts +25 -0
- package/dist/files/Factory.js +22 -0
- package/dist/files/Factory.js.map +1 -0
- package/dist/files/LazyFileData.d.ts +21 -0
- package/dist/files/LazyFileData.js +54 -0
- package/dist/files/LazyFileData.js.map +1 -0
- package/dist/files/LazyFileData.spec.d.ts +1 -0
- package/dist/files/LazyFileData.spec.js +27 -0
- package/dist/files/LazyFileData.spec.js.map +1 -0
- package/dist/files/XmlFile.d.ts +80 -41
- package/dist/files/XmlFile.js +161 -137
- package/dist/files/XmlFile.js.map +1 -1
- package/dist/files/XmlFile.spec.js +444 -336
- package/dist/files/XmlFile.spec.js.map +1 -1
- package/dist/files/tests/imports.spec.js +62 -52
- package/dist/files/tests/imports.spec.js.map +1 -1
- package/dist/files/tests/optionalChaning.spec.d.ts +1 -0
- package/dist/files/tests/optionalChaning.spec.js +152 -0
- package/dist/files/tests/optionalChaning.spec.js.map +1 -0
- package/dist/globalCallables.d.ts +3 -1
- package/dist/globalCallables.js +424 -184
- package/dist/globalCallables.js.map +1 -1
- package/dist/index.d.ts +32 -4
- package/dist/index.js +54 -7
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +942 -125
- package/dist/interfaces.js +21 -0
- package/dist/interfaces.js.map +1 -1
- package/dist/lexer/Character.spec.js +5 -5
- package/dist/lexer/Character.spec.js.map +1 -1
- package/dist/lexer/Lexer.d.ts +51 -12
- package/dist/lexer/Lexer.js +215 -65
- package/dist/lexer/Lexer.js.map +1 -1
- package/dist/lexer/Lexer.spec.js +812 -568
- package/dist/lexer/Lexer.spec.js.map +1 -1
- package/dist/lexer/Token.d.ts +27 -11
- package/dist/lexer/Token.js +10 -2
- package/dist/lexer/Token.js.map +1 -1
- package/dist/lexer/TokenKind.d.ts +40 -2
- package/dist/lexer/TokenKind.js +147 -10
- package/dist/lexer/TokenKind.js.map +1 -1
- package/dist/logging.d.ts +14 -0
- package/dist/logging.js +29 -0
- package/dist/logging.js.map +1 -0
- package/dist/lsp/ActionQueue.d.ts +35 -0
- package/dist/lsp/ActionQueue.js +115 -0
- package/dist/lsp/ActionQueue.js.map +1 -0
- package/dist/lsp/ActionQueue.spec.d.ts +1 -0
- package/dist/lsp/ActionQueue.spec.js +80 -0
- package/dist/lsp/ActionQueue.spec.js.map +1 -0
- package/dist/lsp/DocumentManager.d.ts +63 -0
- package/dist/lsp/DocumentManager.js +122 -0
- package/dist/lsp/DocumentManager.js.map +1 -0
- package/dist/lsp/DocumentManager.spec.d.ts +1 -0
- package/dist/lsp/DocumentManager.spec.js +103 -0
- package/dist/lsp/DocumentManager.spec.js.map +1 -0
- package/dist/lsp/LspProject.d.ts +239 -0
- package/dist/lsp/LspProject.js +3 -0
- package/dist/lsp/LspProject.js.map +1 -0
- package/dist/lsp/PathFilterer.d.ts +75 -0
- package/dist/lsp/PathFilterer.js +196 -0
- package/dist/lsp/PathFilterer.js.map +1 -0
- package/dist/lsp/PathFilterer.spec.d.ts +1 -0
- package/dist/lsp/PathFilterer.spec.js +182 -0
- package/dist/lsp/PathFilterer.spec.js.map +1 -0
- package/dist/lsp/Project.d.ts +168 -0
- package/dist/lsp/Project.js +437 -0
- package/dist/lsp/Project.js.map +1 -0
- package/dist/lsp/Project.spec.d.ts +1 -0
- package/dist/lsp/Project.spec.js +267 -0
- package/dist/lsp/Project.spec.js.map +1 -0
- package/dist/lsp/ProjectManager.d.ts +242 -0
- package/dist/lsp/ProjectManager.js +824 -0
- package/dist/lsp/ProjectManager.js.map +1 -0
- package/dist/lsp/ProjectManager.spec.d.ts +1 -0
- package/dist/lsp/ProjectManager.spec.js +913 -0
- package/dist/lsp/ProjectManager.spec.js.map +1 -0
- package/dist/lsp/ReaderWriterManager.d.ts +21 -0
- package/dist/lsp/ReaderWriterManager.js +60 -0
- package/dist/lsp/ReaderWriterManager.js.map +1 -0
- package/dist/lsp/worker/MessageHandler.d.ts +99 -0
- package/dist/lsp/worker/MessageHandler.js +138 -0
- package/dist/lsp/worker/MessageHandler.js.map +1 -0
- package/dist/lsp/worker/MessageHandler.spec.d.ts +1 -0
- package/dist/lsp/worker/MessageHandler.spec.js +64 -0
- package/dist/lsp/worker/MessageHandler.spec.js.map +1 -0
- package/dist/lsp/worker/WorkerPool.d.ts +38 -0
- package/dist/lsp/worker/WorkerPool.js +78 -0
- package/dist/lsp/worker/WorkerPool.js.map +1 -0
- package/dist/lsp/worker/WorkerPool.spec.d.ts +1 -0
- package/dist/lsp/worker/WorkerPool.spec.js +59 -0
- package/dist/lsp/worker/WorkerPool.spec.js.map +1 -0
- package/dist/lsp/worker/WorkerThreadProject.d.ts +143 -0
- package/dist/lsp/worker/WorkerThreadProject.js +189 -0
- package/dist/lsp/worker/WorkerThreadProject.js.map +1 -0
- package/dist/lsp/worker/WorkerThreadProject.spec.d.ts +2 -0
- package/dist/lsp/worker/WorkerThreadProject.spec.js +71 -0
- package/dist/lsp/worker/WorkerThreadProject.spec.js.map +1 -0
- package/dist/lsp/worker/WorkerThreadProjectRunner.d.ts +15 -0
- package/dist/lsp/worker/WorkerThreadProjectRunner.js +58 -0
- package/dist/lsp/worker/WorkerThreadProjectRunner.js.map +1 -0
- package/dist/lsp/worker/run.d.ts +1 -0
- package/dist/lsp/worker/run.js +14 -0
- package/dist/lsp/worker/run.js.map +1 -0
- package/dist/parser/AstNode.d.ts +203 -0
- package/dist/parser/AstNode.js +303 -0
- package/dist/parser/AstNode.js.map +1 -0
- package/dist/parser/AstNode.spec.d.ts +1 -0
- package/dist/parser/AstNode.spec.js +1455 -0
- package/dist/parser/AstNode.spec.js.map +1 -0
- package/dist/parser/BrightScriptDocParser.d.ts +56 -0
- package/dist/parser/BrightScriptDocParser.js +294 -0
- package/dist/parser/BrightScriptDocParser.js.map +1 -0
- package/dist/parser/BrightScriptDocParser.spec.d.ts +1 -0
- package/dist/parser/BrightScriptDocParser.spec.js +310 -0
- package/dist/parser/BrightScriptDocParser.spec.js.map +1 -0
- package/dist/parser/BrsTranspileState.d.ts +22 -3
- package/dist/parser/BrsTranspileState.js +19 -0
- package/dist/parser/BrsTranspileState.js.map +1 -1
- package/dist/parser/Expression.d.ts +553 -221
- package/dist/parser/Expression.js +1414 -505
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Expression.spec.d.ts +1 -0
- package/dist/parser/Expression.spec.js +40 -0
- package/dist/parser/Expression.spec.js.map +1 -0
- package/dist/parser/Parser.Class.spec.js +255 -125
- package/dist/parser/Parser.Class.spec.js.map +1 -1
- package/dist/parser/Parser.d.ts +117 -124
- package/dist/parser/Parser.js +1669 -982
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/Parser.spec.d.ts +3 -1
- package/dist/parser/Parser.spec.js +2111 -525
- package/dist/parser/Parser.spec.js.map +1 -1
- package/dist/parser/SGParser.d.ts +29 -13
- package/dist/parser/SGParser.js +85 -56
- package/dist/parser/SGParser.js.map +1 -1
- package/dist/parser/SGParser.spec.js +30 -45
- package/dist/parser/SGParser.spec.js.map +1 -1
- package/dist/parser/SGTypes.d.ts +134 -46
- package/dist/parser/SGTypes.js +206 -115
- package/dist/parser/SGTypes.js.map +1 -1
- package/dist/parser/Statement.d.ts +849 -267
- package/dist/parser/Statement.js +2412 -625
- package/dist/parser/Statement.js.map +1 -1
- package/dist/parser/Statement.spec.js +133 -36
- package/dist/parser/Statement.spec.js.map +1 -1
- package/dist/parser/TranspileState.d.ts +26 -12
- package/dist/parser/TranspileState.js +115 -24
- package/dist/parser/TranspileState.js.map +1 -1
- package/dist/parser/tests/Parser.spec.d.ts +3 -9
- package/dist/parser/tests/Parser.spec.js +7 -13
- package/dist/parser/tests/Parser.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/For.spec.js +83 -75
- package/dist/parser/tests/controlFlow/For.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/ForEach.spec.js +85 -51
- package/dist/parser/tests/controlFlow/ForEach.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/If.spec.js +382 -239
- package/dist/parser/tests/controlFlow/If.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/While.spec.js +52 -45
- package/dist/parser/tests/controlFlow/While.spec.js.map +1 -1
- package/dist/parser/tests/expression/Additive.spec.js +51 -43
- package/dist/parser/tests/expression/Additive.spec.js.map +1 -1
- package/dist/parser/tests/expression/ArrayLiterals.spec.js +192 -142
- package/dist/parser/tests/expression/ArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +236 -160
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/expression/Boolean.spec.js +41 -34
- package/dist/parser/tests/expression/Boolean.spec.js.map +1 -1
- package/dist/parser/tests/expression/Call.spec.js +173 -55
- package/dist/parser/tests/expression/Call.spec.js.map +1 -1
- package/dist/parser/tests/expression/Exponential.spec.js +20 -20
- package/dist/parser/tests/expression/Exponential.spec.js.map +1 -1
- package/dist/parser/tests/expression/Function.spec.js +291 -282
- package/dist/parser/tests/expression/Function.spec.js.map +1 -1
- package/dist/parser/tests/expression/Indexing.spec.js +193 -110
- package/dist/parser/tests/expression/Indexing.spec.js.map +1 -1
- package/dist/parser/tests/expression/Multiplicative.spec.js +42 -42
- package/dist/parser/tests/expression/Multiplicative.spec.js.map +1 -1
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +260 -115
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/PrefixUnary.spec.js +58 -52
- package/dist/parser/tests/expression/PrefixUnary.spec.js.map +1 -1
- package/dist/parser/tests/expression/Primary.spec.js +76 -60
- package/dist/parser/tests/expression/Primary.spec.js.map +1 -1
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.d.ts +1 -0
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +171 -0
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.js.map +1 -0
- package/dist/parser/tests/expression/Relational.spec.js +50 -50
- package/dist/parser/tests/expression/Relational.spec.js.map +1 -1
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.js +31 -31
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js +281 -94
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TernaryExpression.spec.js +747 -192
- package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TypeExpression.spec.d.ts +1 -0
- package/dist/parser/tests/expression/TypeExpression.spec.js +126 -0
- package/dist/parser/tests/expression/TypeExpression.spec.js.map +1 -0
- package/dist/parser/tests/expression/UnaryExpression.spec.d.ts +1 -0
- package/dist/parser/tests/expression/UnaryExpression.spec.js +52 -0
- package/dist/parser/tests/expression/UnaryExpression.spec.js.map +1 -0
- package/dist/parser/tests/statement/AssignmentOperators.spec.js +44 -44
- package/dist/parser/tests/statement/AssignmentOperators.spec.js.map +1 -1
- package/dist/parser/tests/statement/ConstStatement.spec.d.ts +1 -0
- package/dist/parser/tests/statement/ConstStatement.spec.js +500 -0
- package/dist/parser/tests/statement/ConstStatement.spec.js.map +1 -0
- package/dist/parser/tests/statement/Continue.spec.d.ts +1 -0
- package/dist/parser/tests/statement/Continue.spec.js +119 -0
- package/dist/parser/tests/statement/Continue.spec.js.map +1 -0
- package/dist/parser/tests/statement/Declaration.spec.js +61 -55
- package/dist/parser/tests/statement/Declaration.spec.js.map +1 -1
- package/dist/parser/tests/statement/Dim.spec.js +29 -22
- package/dist/parser/tests/statement/Dim.spec.js.map +1 -1
- package/dist/parser/tests/statement/Enum.spec.d.ts +1 -0
- package/dist/parser/tests/statement/Enum.spec.js +744 -0
- package/dist/parser/tests/statement/Enum.spec.js.map +1 -0
- package/dist/parser/tests/statement/For.spec.d.ts +1 -0
- package/dist/parser/tests/statement/For.spec.js +45 -0
- package/dist/parser/tests/statement/For.spec.js.map +1 -0
- package/dist/parser/tests/statement/ForEach.spec.d.ts +1 -0
- package/dist/parser/tests/statement/ForEach.spec.js +36 -0
- package/dist/parser/tests/statement/ForEach.spec.js.map +1 -0
- package/dist/parser/tests/statement/Function.spec.js +226 -215
- package/dist/parser/tests/statement/Function.spec.js.map +1 -1
- package/dist/parser/tests/statement/Goto.spec.js +16 -15
- package/dist/parser/tests/statement/Goto.spec.js.map +1 -1
- package/dist/parser/tests/statement/Increment.spec.js +64 -61
- package/dist/parser/tests/statement/Increment.spec.js.map +1 -1
- package/dist/parser/tests/statement/InterfaceStatement.spec.d.ts +1 -0
- package/dist/parser/tests/statement/InterfaceStatement.spec.js +110 -0
- package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +1 -0
- package/dist/parser/tests/statement/LibraryStatement.spec.js +22 -22
- package/dist/parser/tests/statement/LibraryStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Misc.spec.js +127 -168
- package/dist/parser/tests/statement/Misc.spec.js.map +1 -1
- package/dist/parser/tests/statement/PrintStatement.spec.js +133 -114
- package/dist/parser/tests/statement/PrintStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/ReturnStatement.spec.js +57 -54
- package/dist/parser/tests/statement/ReturnStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Set.spec.js +131 -117
- package/dist/parser/tests/statement/Set.spec.js.map +1 -1
- package/dist/parser/tests/statement/Stop.spec.js +14 -13
- package/dist/parser/tests/statement/Stop.spec.js.map +1 -1
- package/dist/parser/tests/statement/Throw.spec.js +11 -8
- package/dist/parser/tests/statement/Throw.spec.js.map +1 -1
- package/dist/parser/tests/statement/TryCatch.spec.js +26 -15
- package/dist/parser/tests/statement/TryCatch.spec.js.map +1 -1
- package/dist/preprocessor/Manifest.d.ts +6 -6
- package/dist/preprocessor/Manifest.js +17 -38
- package/dist/preprocessor/Manifest.js.map +1 -1
- package/dist/preprocessor/Manifest.spec.d.ts +1 -0
- package/dist/preprocessor/Manifest.spec.js +78 -103
- package/dist/preprocessor/Manifest.spec.js.map +1 -1
- package/dist/roku-types/data.json +20347 -0
- package/dist/roku-types/index.d.ts +5726 -0
- package/dist/roku-types/index.js +11 -0
- package/dist/roku-types/index.js.map +1 -0
- package/dist/types/ArrayType.d.ts +12 -5
- package/dist/types/ArrayType.js +89 -24
- package/dist/types/ArrayType.js.map +1 -1
- package/dist/types/ArrayType.spec.js +39 -11
- package/dist/types/ArrayType.spec.js.map +1 -1
- package/dist/types/AssociativeArrayType.d.ts +15 -0
- package/dist/types/AssociativeArrayType.js +64 -0
- package/dist/types/AssociativeArrayType.js.map +1 -0
- package/dist/types/BaseFunctionType.d.ts +10 -0
- package/dist/types/BaseFunctionType.js +26 -0
- package/dist/types/BaseFunctionType.js.map +1 -0
- package/dist/types/BooleanType.d.ts +9 -5
- package/dist/types/BooleanType.js +19 -8
- package/dist/types/BooleanType.js.map +1 -1
- package/dist/types/BooleanType.spec.js +10 -4
- package/dist/types/BooleanType.spec.js.map +1 -1
- package/dist/types/BscType.d.ts +41 -3
- package/dist/types/BscType.js +152 -0
- package/dist/types/BscType.js.map +1 -1
- package/dist/types/BscTypeKind.d.ts +28 -0
- package/dist/types/BscTypeKind.js +33 -0
- package/dist/types/BscTypeKind.js.map +1 -0
- package/dist/types/BuiltInInterfaceAdder.d.ts +28 -0
- package/dist/types/BuiltInInterfaceAdder.js +212 -0
- package/dist/types/BuiltInInterfaceAdder.js.map +1 -0
- package/dist/types/BuiltInInterfaceAdder.spec.d.ts +1 -0
- package/dist/types/BuiltInInterfaceAdder.spec.js +115 -0
- package/dist/types/BuiltInInterfaceAdder.spec.js.map +1 -0
- package/dist/types/CallFuncableType.d.ts +24 -0
- package/dist/types/CallFuncableType.js +91 -0
- package/dist/types/CallFuncableType.js.map +1 -0
- package/dist/types/ClassType.d.ts +17 -0
- package/dist/types/ClassType.js +60 -0
- package/dist/types/ClassType.js.map +1 -0
- package/dist/types/ClassType.spec.d.ts +1 -0
- package/dist/types/ClassType.spec.js +76 -0
- package/dist/types/ClassType.spec.js.map +1 -0
- package/dist/types/ComponentType.d.ts +22 -0
- package/dist/types/ComponentType.js +107 -0
- package/dist/types/ComponentType.js.map +1 -0
- package/dist/types/DoubleType.d.ts +10 -5
- package/dist/types/DoubleType.js +21 -17
- package/dist/types/DoubleType.js.map +1 -1
- package/dist/types/DoubleType.spec.js +12 -4
- package/dist/types/DoubleType.spec.js.map +1 -1
- package/dist/types/DynamicType.d.ts +13 -5
- package/dist/types/DynamicType.js +26 -5
- package/dist/types/DynamicType.js.map +1 -1
- package/dist/types/DynamicType.spec.js +16 -5
- package/dist/types/DynamicType.spec.js.map +1 -1
- package/dist/types/EnumType.d.ts +42 -0
- package/dist/types/EnumType.js +98 -0
- package/dist/types/EnumType.js.map +1 -0
- package/dist/types/EnumType.spec.d.ts +1 -0
- package/dist/types/EnumType.spec.js +33 -0
- package/dist/types/EnumType.spec.js.map +1 -0
- package/dist/types/FloatType.d.ts +10 -5
- package/dist/types/FloatType.js +21 -17
- package/dist/types/FloatType.js.map +1 -1
- package/dist/types/FloatType.spec.js +4 -4
- package/dist/types/FloatType.spec.js.map +1 -1
- package/dist/types/FunctionType.d.ts +8 -22
- package/dist/types/FunctionType.js +25 -63
- package/dist/types/FunctionType.js.map +1 -1
- package/dist/types/InheritableType.d.ts +29 -0
- package/dist/types/InheritableType.js +173 -0
- package/dist/types/InheritableType.js.map +1 -0
- package/dist/types/InlineInterfaceType.d.ts +5 -0
- package/dist/types/InlineInterfaceType.js +17 -0
- package/dist/types/InlineInterfaceType.js.map +1 -0
- package/dist/types/IntegerType.d.ts +10 -5
- package/dist/types/IntegerType.js +21 -17
- package/dist/types/IntegerType.js.map +1 -1
- package/dist/types/IntegerType.spec.js +8 -4
- package/dist/types/IntegerType.spec.js.map +1 -1
- package/dist/types/InterfaceType.d.ts +14 -6
- package/dist/types/InterfaceType.js +30 -15
- package/dist/types/InterfaceType.js.map +1 -1
- package/dist/types/InterfaceType.spec.d.ts +1 -0
- package/dist/types/InterfaceType.spec.js +227 -0
- package/dist/types/InterfaceType.spec.js.map +1 -0
- package/dist/types/IntersectionType.d.ts +29 -0
- package/dist/types/IntersectionType.js +253 -0
- package/dist/types/IntersectionType.js.map +1 -0
- package/dist/types/IntersectionType.spec.d.ts +1 -0
- package/dist/types/IntersectionType.spec.js +150 -0
- package/dist/types/IntersectionType.spec.js.map +1 -0
- package/dist/types/InvalidType.d.ts +10 -5
- package/dist/types/InvalidType.js +21 -9
- package/dist/types/InvalidType.js.map +1 -1
- package/dist/types/InvalidType.spec.js +8 -4
- package/dist/types/InvalidType.spec.js.map +1 -1
- package/dist/types/LongIntegerType.d.ts +10 -5
- package/dist/types/LongIntegerType.js +21 -17
- package/dist/types/LongIntegerType.js.map +1 -1
- package/dist/types/LongIntegerType.spec.js +10 -4
- package/dist/types/LongIntegerType.spec.js.map +1 -1
- package/dist/types/NamespaceType.d.ts +12 -0
- package/dist/types/NamespaceType.js +28 -0
- package/dist/types/NamespaceType.js.map +1 -0
- package/dist/types/ObjectType.d.ts +12 -5
- package/dist/types/ObjectType.js +25 -8
- package/dist/types/ObjectType.js.map +1 -1
- package/dist/types/ObjectType.spec.js +3 -3
- package/dist/types/ObjectType.spec.js.map +1 -1
- package/dist/types/ReferenceType.d.ts +123 -0
- package/dist/types/ReferenceType.js +720 -0
- package/dist/types/ReferenceType.js.map +1 -0
- package/dist/types/ReferenceType.spec.d.ts +1 -0
- package/dist/types/ReferenceType.spec.js +151 -0
- package/dist/types/ReferenceType.spec.js.map +1 -0
- package/dist/types/StringType.d.ts +12 -5
- package/dist/types/StringType.js +23 -8
- package/dist/types/StringType.js.map +1 -1
- package/dist/types/StringType.spec.js +3 -3
- package/dist/types/StringType.spec.js.map +1 -1
- package/dist/types/TypeStatementType.d.ts +18 -0
- package/dist/types/TypeStatementType.js +45 -0
- package/dist/types/TypeStatementType.js.map +1 -0
- package/dist/types/TypedFunctionType.d.ts +34 -0
- package/dist/types/TypedFunctionType.js +147 -0
- package/dist/types/TypedFunctionType.js.map +1 -0
- package/dist/types/TypedFunctionType.spec.d.ts +1 -0
- package/dist/types/TypedFunctionType.spec.js +122 -0
- package/dist/types/TypedFunctionType.spec.js.map +1 -0
- package/dist/types/UninitializedType.d.ts +11 -6
- package/dist/types/UninitializedType.js +20 -11
- package/dist/types/UninitializedType.js.map +1 -1
- package/dist/types/UnionType.d.ts +27 -0
- package/dist/types/UnionType.js +193 -0
- package/dist/types/UnionType.js.map +1 -0
- package/dist/types/UnionType.spec.d.ts +1 -0
- package/dist/types/UnionType.spec.js +205 -0
- package/dist/types/UnionType.spec.js.map +1 -0
- package/dist/types/VoidType.d.ts +11 -5
- package/dist/types/VoidType.js +22 -8
- package/dist/types/VoidType.js.map +1 -1
- package/dist/types/VoidType.spec.js +3 -3
- package/dist/types/VoidType.spec.js.map +1 -1
- package/dist/types/helper.spec.d.ts +1 -0
- package/dist/types/helper.spec.js +174 -0
- package/dist/types/helper.spec.js.map +1 -0
- package/dist/types/helpers.d.ts +51 -0
- package/dist/types/helpers.js +323 -0
- package/dist/types/helpers.js.map +1 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/index.js +39 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/roFunctionType.d.ts +11 -0
- package/dist/types/roFunctionType.js +37 -0
- package/dist/types/roFunctionType.js.map +1 -0
- package/dist/types/roFunctionType.spec.d.ts +1 -0
- package/dist/types/roFunctionType.spec.js +20 -0
- package/dist/types/roFunctionType.spec.js.map +1 -0
- package/dist/util.d.ts +288 -187
- package/dist/util.js +2018 -575
- package/dist/util.js.map +1 -1
- package/dist/validators/ClassValidator.d.ts +9 -15
- package/dist/validators/ClassValidator.js +93 -138
- package/dist/validators/ClassValidator.js.map +1 -1
- package/package.json +185 -138
- package/CHANGELOG.md +0 -1188
- package/dist/astUtils/index.d.ts +0 -7
- package/dist/astUtils/index.js +0 -26
- package/dist/astUtils/index.js.map +0 -1
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.d.ts +0 -7
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.js +0 -63
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.js.map +0 -1
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.spec.js +0 -45
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.spec.js.map +0 -1
- package/dist/lexer/index.d.ts +0 -3
- package/dist/lexer/index.js +0 -17
- package/dist/lexer/index.js.map +0 -1
- package/dist/parser/SGTypes.spec.js +0 -351
- package/dist/parser/SGTypes.spec.js.map +0 -1
- package/dist/parser/index.d.ts +0 -3
- package/dist/parser/index.js +0 -16
- package/dist/parser/index.js.map +0 -1
- package/dist/preprocessor/Chunk.d.ts +0 -82
- package/dist/preprocessor/Chunk.js +0 -77
- package/dist/preprocessor/Chunk.js.map +0 -1
- package/dist/preprocessor/Preprocessor.d.ts +0 -60
- package/dist/preprocessor/Preprocessor.js +0 -156
- package/dist/preprocessor/Preprocessor.js.map +0 -1
- package/dist/preprocessor/Preprocessor.spec.js +0 -152
- package/dist/preprocessor/Preprocessor.spec.js.map +0 -1
- package/dist/preprocessor/PreprocessorParser.d.ts +0 -61
- package/dist/preprocessor/PreprocessorParser.js +0 -194
- package/dist/preprocessor/PreprocessorParser.js.map +0 -1
- package/dist/preprocessor/PreprocessorParser.spec.js +0 -116
- package/dist/preprocessor/PreprocessorParser.spec.js.map +0 -1
- package/dist/preprocessor/index.d.ts +0 -3
- package/dist/preprocessor/index.js +0 -16
- package/dist/preprocessor/index.js.map +0 -1
- package/dist/types/CustomType.d.ts +0 -10
- package/dist/types/CustomType.js +0 -35
- package/dist/types/CustomType.js.map +0 -1
- package/dist/types/FunctionType.spec.js +0 -29
- package/dist/types/FunctionType.spec.js.map +0 -1
- package/dist/types/LazyType.d.ts +0 -15
- package/dist/types/LazyType.js +0 -32
- package/dist/types/LazyType.js.map +0 -1
- /package/dist/{bscPlugin/semanticTokens/SemanticTokensProcessor.spec.d.ts → astUtils/CachedLookups.spec.d.ts} +0 -0
- /package/dist/{parser/SGTypes.spec.d.ts → astUtils/Editor.spec.d.ts} +0 -0
- /package/dist/{preprocessor/Preprocessor.spec.d.ts → bscPlugin/completions/CompletionsProcessor.spec.d.ts} +0 -0
- /package/dist/{preprocessor/PreprocessorParser.spec.d.ts → bscPlugin/definition/DefinitionProvider.spec.d.ts} +0 -0
- /package/dist/{types/FunctionType.spec.d.ts → bscPlugin/hover/HoverProcessor.spec.d.ts} +0 -0
|
@@ -0,0 +1,1517 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const chai_config_spec_1 = require("../../chai-config.spec");
|
|
4
|
+
const DiagnosticMessages_1 = require("../../DiagnosticMessages");
|
|
5
|
+
const testHelpers_spec_1 = require("../../testHelpers.spec");
|
|
6
|
+
const Program_1 = require("../../Program");
|
|
7
|
+
const reflection_1 = require("../../astUtils/reflection");
|
|
8
|
+
const util_1 = require("../../util");
|
|
9
|
+
const visitors_1 = require("../../astUtils/visitors");
|
|
10
|
+
const ClassType_1 = require("../../types/ClassType");
|
|
11
|
+
const FloatType_1 = require("../../types/FloatType");
|
|
12
|
+
const IntegerType_1 = require("../../types/IntegerType");
|
|
13
|
+
const InterfaceType_1 = require("../../types/InterfaceType");
|
|
14
|
+
const StringType_1 = require("../../types/StringType");
|
|
15
|
+
const ArrayType_1 = require("../../types/ArrayType");
|
|
16
|
+
const DynamicType_1 = require("../../types/DynamicType");
|
|
17
|
+
const TypedFunctionType_1 = require("../../types/TypedFunctionType");
|
|
18
|
+
const Parser_1 = require("../../parser/Parser");
|
|
19
|
+
const AssociativeArrayType_1 = require("../../types/AssociativeArrayType");
|
|
20
|
+
const types_1 = require("../../types");
|
|
21
|
+
const TypeStatementType_1 = require("../../types/TypeStatementType");
|
|
22
|
+
describe('BrsFileValidator', () => {
|
|
23
|
+
let program;
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
program = new Program_1.Program({
|
|
26
|
+
rootDir: testHelpers_spec_1.rootDir
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
it('links dotted get expression parents', () => {
|
|
30
|
+
const file = program.setFile('source/main.bs', `
|
|
31
|
+
sub main()
|
|
32
|
+
print {}.beta.charlie
|
|
33
|
+
end sub
|
|
34
|
+
`);
|
|
35
|
+
program.validate();
|
|
36
|
+
const func = file.parser.ast.statements[0];
|
|
37
|
+
const print = func.func.body.statements[0];
|
|
38
|
+
(0, chai_config_spec_1.expect)(print.parent).to.equal(func.func.body);
|
|
39
|
+
const charlie = print.expressions[0];
|
|
40
|
+
(0, chai_config_spec_1.expect)(charlie.parent).to.equal(print);
|
|
41
|
+
const beta = charlie.obj;
|
|
42
|
+
(0, chai_config_spec_1.expect)(beta.parent).to.equal(charlie);
|
|
43
|
+
const aaLiteral = beta.obj;
|
|
44
|
+
(0, chai_config_spec_1.expect)(aaLiteral.parent).to.equal(beta);
|
|
45
|
+
});
|
|
46
|
+
it('links namespace name dotted get parents', () => {
|
|
47
|
+
const { ast } = program.setFile('source/main.bs', `
|
|
48
|
+
namespace alpha.bravo
|
|
49
|
+
class Delta extends alpha.bravo.Charlie
|
|
50
|
+
end class
|
|
51
|
+
class Charlie
|
|
52
|
+
end class
|
|
53
|
+
end namespace
|
|
54
|
+
`);
|
|
55
|
+
const namespace = ast.findChild(reflection_1.isNamespaceStatement);
|
|
56
|
+
const deltaClass = namespace.findChild(reflection_1.isClassStatement);
|
|
57
|
+
(0, chai_config_spec_1.expect)(deltaClass.parent).to.equal(namespace.body);
|
|
58
|
+
const charlie = deltaClass.parentClassName.expression;
|
|
59
|
+
(0, chai_config_spec_1.expect)(charlie.parent).to.equal(deltaClass.parentClassName);
|
|
60
|
+
const bravo = charlie.obj;
|
|
61
|
+
(0, chai_config_spec_1.expect)(bravo.parent).to.equal(charlie);
|
|
62
|
+
const alpha = bravo.obj;
|
|
63
|
+
(0, chai_config_spec_1.expect)(alpha.parent).to.equal(bravo);
|
|
64
|
+
});
|
|
65
|
+
describe('namespace validation', () => {
|
|
66
|
+
it('succeeds if namespaces are defined inside other namespaces', () => {
|
|
67
|
+
program.setFile('source/main.bs', `
|
|
68
|
+
namespace alpha
|
|
69
|
+
' random comment
|
|
70
|
+
namespace bravo
|
|
71
|
+
' random comment
|
|
72
|
+
sub main()
|
|
73
|
+
end sub
|
|
74
|
+
end namespace
|
|
75
|
+
end namespace
|
|
76
|
+
`);
|
|
77
|
+
program.validate();
|
|
78
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
79
|
+
});
|
|
80
|
+
it('fails if namespaces are defined inside a function', () => {
|
|
81
|
+
program.setFile('source/main.bs', `
|
|
82
|
+
function f()
|
|
83
|
+
namespace alpha
|
|
84
|
+
end namespace
|
|
85
|
+
end function
|
|
86
|
+
`);
|
|
87
|
+
program.validate();
|
|
88
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
89
|
+
DiagnosticMessages_1.DiagnosticMessages.keywordMustBeDeclaredAtNamespaceLevel('namespace')
|
|
90
|
+
]);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
it('allows classes in correct locations', () => {
|
|
94
|
+
program.setFile('source/main.bs', `
|
|
95
|
+
class Alpha
|
|
96
|
+
end class
|
|
97
|
+
namespace Beta
|
|
98
|
+
class Charlie
|
|
99
|
+
end class
|
|
100
|
+
namespace Delta
|
|
101
|
+
class Echo
|
|
102
|
+
end class
|
|
103
|
+
end namespace
|
|
104
|
+
end namespace
|
|
105
|
+
`);
|
|
106
|
+
program.validate();
|
|
107
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
108
|
+
});
|
|
109
|
+
it('flags classes in wrong locations', () => {
|
|
110
|
+
program.setFile('source/main.bs', `
|
|
111
|
+
function test()
|
|
112
|
+
class Alpha
|
|
113
|
+
end class
|
|
114
|
+
if true then
|
|
115
|
+
class Beta
|
|
116
|
+
end class
|
|
117
|
+
end if
|
|
118
|
+
end function
|
|
119
|
+
`);
|
|
120
|
+
program.validate();
|
|
121
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.keywordMustBeDeclaredAtNamespaceLevel('class')), { location: { range: util_1.util.createRange(2, 16, 2, 27) } }), Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.keywordMustBeDeclaredAtNamespaceLevel('class')), { location: { range: util_1.util.createRange(5, 20, 5, 30) } })]);
|
|
122
|
+
});
|
|
123
|
+
it('allows enums in correct locations', () => {
|
|
124
|
+
program.setFile('source/main.bs', `
|
|
125
|
+
enum Alpha
|
|
126
|
+
value1
|
|
127
|
+
end enum
|
|
128
|
+
namespace Beta
|
|
129
|
+
enum Charlie
|
|
130
|
+
value1
|
|
131
|
+
end enum
|
|
132
|
+
namespace Delta
|
|
133
|
+
enum Echo
|
|
134
|
+
value1
|
|
135
|
+
end enum
|
|
136
|
+
end namespace
|
|
137
|
+
end namespace
|
|
138
|
+
`);
|
|
139
|
+
program.validate();
|
|
140
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
141
|
+
});
|
|
142
|
+
it('flags enums in wrong locations', () => {
|
|
143
|
+
program.setFile('source/main.bs', `
|
|
144
|
+
function test()
|
|
145
|
+
enum Alpha
|
|
146
|
+
value1
|
|
147
|
+
end enum
|
|
148
|
+
if true then
|
|
149
|
+
enum Beta
|
|
150
|
+
value1
|
|
151
|
+
end enum
|
|
152
|
+
end if
|
|
153
|
+
end function
|
|
154
|
+
`);
|
|
155
|
+
program.validate();
|
|
156
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.keywordMustBeDeclaredAtNamespaceLevel('enum')), { location: { range: util_1.util.createRange(2, 16, 2, 26) } }), Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.keywordMustBeDeclaredAtNamespaceLevel('enum')), { location: { range: util_1.util.createRange(6, 20, 6, 29) } })]);
|
|
157
|
+
});
|
|
158
|
+
it('allows functions in correct locations', () => {
|
|
159
|
+
program.setFile('source/main.bs', `
|
|
160
|
+
function Alpha()
|
|
161
|
+
end function
|
|
162
|
+
namespace Beta
|
|
163
|
+
function Charlie()
|
|
164
|
+
end function
|
|
165
|
+
namespace Delta
|
|
166
|
+
function Echo()
|
|
167
|
+
end function
|
|
168
|
+
end namespace
|
|
169
|
+
end namespace
|
|
170
|
+
`);
|
|
171
|
+
program.validate();
|
|
172
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
173
|
+
});
|
|
174
|
+
it('flags functions in wrong locations', () => {
|
|
175
|
+
program.setFile('source/main.bs', `
|
|
176
|
+
function test()
|
|
177
|
+
function Alpha()
|
|
178
|
+
end function
|
|
179
|
+
if true then
|
|
180
|
+
function Beta()
|
|
181
|
+
end function
|
|
182
|
+
end if
|
|
183
|
+
end function
|
|
184
|
+
`);
|
|
185
|
+
program.validate();
|
|
186
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.keywordMustBeDeclaredAtNamespaceLevel('function')), { location: { range: util_1.util.createRange(2, 16, 2, 30) } }), Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.keywordMustBeDeclaredAtNamespaceLevel('function')), { location: { range: util_1.util.createRange(5, 20, 5, 33) } })]);
|
|
187
|
+
});
|
|
188
|
+
it('allows namespaces in correct locations', () => {
|
|
189
|
+
program.setFile('source/main.bs', `
|
|
190
|
+
namespace Alpha
|
|
191
|
+
end namespace
|
|
192
|
+
namespace Beta
|
|
193
|
+
namespace Charlie
|
|
194
|
+
end namespace
|
|
195
|
+
namespace Delta
|
|
196
|
+
namespace Echo
|
|
197
|
+
end namespace
|
|
198
|
+
end namespace
|
|
199
|
+
end namespace
|
|
200
|
+
`);
|
|
201
|
+
program.validate();
|
|
202
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
203
|
+
});
|
|
204
|
+
it('flags namespaces in wrong locations', () => {
|
|
205
|
+
program.setFile('source/main.bs', `
|
|
206
|
+
function test()
|
|
207
|
+
namespace Alpha
|
|
208
|
+
end namespace
|
|
209
|
+
if true then
|
|
210
|
+
namespace Beta
|
|
211
|
+
end namespace
|
|
212
|
+
end if
|
|
213
|
+
end function
|
|
214
|
+
`);
|
|
215
|
+
program.validate();
|
|
216
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.keywordMustBeDeclaredAtNamespaceLevel('namespace')), { location: { range: util_1.util.createRange(2, 16, 2, 31) } }), Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.keywordMustBeDeclaredAtNamespaceLevel('namespace')), { location: { range: util_1.util.createRange(5, 20, 5, 34) } })]);
|
|
217
|
+
});
|
|
218
|
+
it('allows interfaces in correct locations', () => {
|
|
219
|
+
program.setFile('source/main.bs', `
|
|
220
|
+
interface Alpha
|
|
221
|
+
prop as string
|
|
222
|
+
end interface
|
|
223
|
+
namespace Beta
|
|
224
|
+
interface Charlie
|
|
225
|
+
prop as string
|
|
226
|
+
end interface
|
|
227
|
+
namespace Delta
|
|
228
|
+
interface Echo
|
|
229
|
+
prop as string
|
|
230
|
+
end interface
|
|
231
|
+
end namespace
|
|
232
|
+
end namespace
|
|
233
|
+
`);
|
|
234
|
+
program.validate();
|
|
235
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
236
|
+
});
|
|
237
|
+
it('flags interfaces in wrong locations', () => {
|
|
238
|
+
program.setFile('source/main.bs', `
|
|
239
|
+
function test()
|
|
240
|
+
interface Alpha
|
|
241
|
+
prop as string
|
|
242
|
+
end interface
|
|
243
|
+
if true then
|
|
244
|
+
interface Beta
|
|
245
|
+
prop as string
|
|
246
|
+
end interface
|
|
247
|
+
end if
|
|
248
|
+
end function
|
|
249
|
+
`);
|
|
250
|
+
program.validate();
|
|
251
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.keywordMustBeDeclaredAtNamespaceLevel('interface')), { location: { range: util_1.util.createRange(2, 16, 2, 31) } }), Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.keywordMustBeDeclaredAtNamespaceLevel('interface')), { location: { range: util_1.util.createRange(6, 20, 6, 34) } })]);
|
|
252
|
+
});
|
|
253
|
+
it('allows consts in correct locations', () => {
|
|
254
|
+
program.setFile('source/main.bs', `
|
|
255
|
+
const Alpha = 1
|
|
256
|
+
namespace Beta
|
|
257
|
+
const Charlie = 2
|
|
258
|
+
namespace Delta
|
|
259
|
+
const Echo = 3
|
|
260
|
+
end namespace
|
|
261
|
+
end namespace
|
|
262
|
+
`);
|
|
263
|
+
program.validate();
|
|
264
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
265
|
+
});
|
|
266
|
+
it('flags consts in wrong locations', () => {
|
|
267
|
+
program.setFile('source/main.bs', `
|
|
268
|
+
function test()
|
|
269
|
+
const Alpha = 1
|
|
270
|
+
if true then
|
|
271
|
+
const Beta = 2
|
|
272
|
+
end if
|
|
273
|
+
end function
|
|
274
|
+
`);
|
|
275
|
+
program.validate();
|
|
276
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.keywordMustBeDeclaredAtNamespaceLevel('const')), { location: { range: util_1.util.createRange(2, 16, 2, 27) } }), Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.keywordMustBeDeclaredAtNamespaceLevel('const')), { location: { range: util_1.util.createRange(4, 20, 4, 30) } })]);
|
|
277
|
+
});
|
|
278
|
+
describe('for each', () => {
|
|
279
|
+
it('handles getting default type of array of AAs with reference types', () => {
|
|
280
|
+
const mainFile = program.setFile('source/main.bs', `
|
|
281
|
+
function test()
|
|
282
|
+
settings = []
|
|
283
|
+
screensData = [
|
|
284
|
+
{ id: "home", actions: [Actions.TrackUser1, Actions.Next], listMode: ListModes.Avatar },
|
|
285
|
+
{ id: "home", actions: [Actions.TrackUser1, Actions.Next], listMode: ListModes.Small },
|
|
286
|
+
{ id: "test", actions: [Actions.TrackUser2, Actions.Next], listMode: ListModes.Profile },
|
|
287
|
+
{ id: "autoplay", actions: [Actions.TrackUser2, Actions.Next], listMode: ListModes.Large }
|
|
288
|
+
]
|
|
289
|
+
|
|
290
|
+
for each screenData in screensData
|
|
291
|
+
if screenData.id = "test"
|
|
292
|
+
settings.push(screenData)
|
|
293
|
+
end if
|
|
294
|
+
end for
|
|
295
|
+
return settings
|
|
296
|
+
end function
|
|
297
|
+
|
|
298
|
+
enum Actions
|
|
299
|
+
TrackUser1
|
|
300
|
+
TrackUser2
|
|
301
|
+
Next
|
|
302
|
+
end enum
|
|
303
|
+
|
|
304
|
+
enum ListModes
|
|
305
|
+
Avatar
|
|
306
|
+
Small
|
|
307
|
+
Profile
|
|
308
|
+
Large
|
|
309
|
+
end enum
|
|
310
|
+
`);
|
|
311
|
+
program.validate();
|
|
312
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
313
|
+
const forStmt = mainFile.ast.findChild(reflection_1.isForEachStatement);
|
|
314
|
+
const insideFor = forStmt.body.statements[0];
|
|
315
|
+
const screensDataType = insideFor.getSymbolTable().getSymbolType('screensData', { flags: 1 /* SymbolTypeFlag.runtime */ });
|
|
316
|
+
(0, testHelpers_spec_1.expectTypeToBe)(screensDataType, ArrayType_1.ArrayType);
|
|
317
|
+
const screenDataType = insideFor.getSymbolTable().getSymbolType('screenData', { flags: 1 /* SymbolTypeFlag.runtime */ });
|
|
318
|
+
(0, testHelpers_spec_1.expectTypeToBe)(screenDataType, AssociativeArrayType_1.AssociativeArrayType);
|
|
319
|
+
});
|
|
320
|
+
it('handles getting default type of array of reference types', () => {
|
|
321
|
+
const mainFile = program.setFile('source/main.bs', `
|
|
322
|
+
function test()
|
|
323
|
+
result = []
|
|
324
|
+
actions = [Actions.TrackUser1, Actions.Next2]
|
|
325
|
+
|
|
326
|
+
for each action in actions
|
|
327
|
+
if action = Actions.Next2
|
|
328
|
+
actions.push(action)
|
|
329
|
+
end if
|
|
330
|
+
end for
|
|
331
|
+
return result
|
|
332
|
+
end function
|
|
333
|
+
|
|
334
|
+
enum Actions
|
|
335
|
+
TrackUser1
|
|
336
|
+
TrackUser2
|
|
337
|
+
Next2
|
|
338
|
+
end enum
|
|
339
|
+
`);
|
|
340
|
+
program.validate();
|
|
341
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
342
|
+
const forStmt = mainFile.ast.findChild(reflection_1.isForEachStatement);
|
|
343
|
+
const insideFor = forStmt.body.statements[0];
|
|
344
|
+
const actionsType = insideFor.getSymbolTable().getSymbolType('actions', { flags: 1 /* SymbolTypeFlag.runtime */ });
|
|
345
|
+
(0, testHelpers_spec_1.expectTypeToBe)(actionsType, ArrayType_1.ArrayType);
|
|
346
|
+
const actionType = insideFor.getSymbolTable().getSymbolType('action', { flags: 1 /* SymbolTypeFlag.runtime */ });
|
|
347
|
+
(0, testHelpers_spec_1.expectTypeToBe)(actionType, DynamicType_1.DynamicType);
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
describe('typecast statement', () => {
|
|
351
|
+
it('allows being at start of file', () => {
|
|
352
|
+
program.setFile('source/main.bs', `
|
|
353
|
+
typecast m as object
|
|
354
|
+
|
|
355
|
+
sub noop()
|
|
356
|
+
end sub
|
|
357
|
+
`);
|
|
358
|
+
program.validate();
|
|
359
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
360
|
+
});
|
|
361
|
+
it('has diagnostic if more than one usage per block', () => {
|
|
362
|
+
program.setFile('source/main.bs', `
|
|
363
|
+
typecast m as object
|
|
364
|
+
typecast m as integer
|
|
365
|
+
|
|
366
|
+
sub noop()
|
|
367
|
+
typecast m as object
|
|
368
|
+
typecast m as string
|
|
369
|
+
end sub
|
|
370
|
+
`);
|
|
371
|
+
program.validate();
|
|
372
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
373
|
+
DiagnosticMessages_1.DiagnosticMessages.unexpectedStatementLocation('typecast', 'at the top of the file or beginning of function or namespace').message,
|
|
374
|
+
DiagnosticMessages_1.DiagnosticMessages.unexpectedStatementLocation('typecast', 'at the top of the file or beginning of function or namespace').message
|
|
375
|
+
]);
|
|
376
|
+
});
|
|
377
|
+
it('has diagnostic if not typecasting m', () => {
|
|
378
|
+
program.setFile('source/main.bs', `
|
|
379
|
+
typecast alpha.beta.notM as object ' error
|
|
380
|
+
|
|
381
|
+
const notM = "also not m"
|
|
382
|
+
|
|
383
|
+
sub noop()
|
|
384
|
+
typecast notM as object ' error
|
|
385
|
+
end sub
|
|
386
|
+
|
|
387
|
+
sub foo()
|
|
388
|
+
typecast M as object ' no error!
|
|
389
|
+
end sub
|
|
390
|
+
|
|
391
|
+
namespace alpha.beta
|
|
392
|
+
const notM = "namespaced not m"
|
|
393
|
+
end namespace
|
|
394
|
+
`);
|
|
395
|
+
program.validate();
|
|
396
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
397
|
+
DiagnosticMessages_1.DiagnosticMessages.invalidTypecastStatementApplication('alpha.beta.notM').message,
|
|
398
|
+
DiagnosticMessages_1.DiagnosticMessages.invalidTypecastStatementApplication('notM').message
|
|
399
|
+
]);
|
|
400
|
+
});
|
|
401
|
+
it('has diagnostic if not first in file', () => {
|
|
402
|
+
program.setFile('source/main.bs', `
|
|
403
|
+
sub noop()
|
|
404
|
+
end sub
|
|
405
|
+
|
|
406
|
+
typecast m as object
|
|
407
|
+
`);
|
|
408
|
+
program.validate();
|
|
409
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
410
|
+
DiagnosticMessages_1.DiagnosticMessages.unexpectedStatementLocation('typecast', 'at the top of the file or beginning of function or namespace').message
|
|
411
|
+
]);
|
|
412
|
+
});
|
|
413
|
+
it('allows being at start of function ', () => {
|
|
414
|
+
program.setFile('source/main.bs', `
|
|
415
|
+
interface Thing
|
|
416
|
+
value as integer
|
|
417
|
+
end interface
|
|
418
|
+
|
|
419
|
+
sub noop()
|
|
420
|
+
typecast m as Thing
|
|
421
|
+
print m.value
|
|
422
|
+
end sub
|
|
423
|
+
`);
|
|
424
|
+
program.validate();
|
|
425
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
426
|
+
});
|
|
427
|
+
it('has diagnostic when not at start of function', () => {
|
|
428
|
+
program.setFile('source/main.bs', `
|
|
429
|
+
interface Thing
|
|
430
|
+
value as integer
|
|
431
|
+
end interface
|
|
432
|
+
|
|
433
|
+
sub noop()
|
|
434
|
+
print m.value
|
|
435
|
+
typecast m as Thing
|
|
436
|
+
end sub
|
|
437
|
+
`);
|
|
438
|
+
program.validate();
|
|
439
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
440
|
+
DiagnosticMessages_1.DiagnosticMessages.unexpectedStatementLocation('typecast', 'at the top of the file or beginning of function or namespace').message
|
|
441
|
+
]);
|
|
442
|
+
});
|
|
443
|
+
it('sets the type of m', () => {
|
|
444
|
+
program.setFile('source/types.bs', `
|
|
445
|
+
interface Thing1
|
|
446
|
+
value as integer
|
|
447
|
+
end interface
|
|
448
|
+
|
|
449
|
+
interface Thing2
|
|
450
|
+
value as string
|
|
451
|
+
end interface
|
|
452
|
+
|
|
453
|
+
interface Thing3
|
|
454
|
+
value as float
|
|
455
|
+
end interface
|
|
456
|
+
`);
|
|
457
|
+
const file = program.setFile('source/main.bs', `
|
|
458
|
+
import "types.bs"
|
|
459
|
+
typecast m as Thing1
|
|
460
|
+
|
|
461
|
+
sub func1()
|
|
462
|
+
x = m.value
|
|
463
|
+
print x
|
|
464
|
+
end sub
|
|
465
|
+
|
|
466
|
+
sub func2()
|
|
467
|
+
typecast m as Thing2
|
|
468
|
+
x = m.value
|
|
469
|
+
print x
|
|
470
|
+
end sub
|
|
471
|
+
|
|
472
|
+
sub func3()
|
|
473
|
+
aa = {
|
|
474
|
+
innerFunc: sub()
|
|
475
|
+
typecast m as Thing3
|
|
476
|
+
x = m.value
|
|
477
|
+
print x
|
|
478
|
+
end sub
|
|
479
|
+
}
|
|
480
|
+
end sub
|
|
481
|
+
`);
|
|
482
|
+
program.validate();
|
|
483
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
484
|
+
const assigns = [];
|
|
485
|
+
// find places in AST where "x" is assigned
|
|
486
|
+
file.ast.walk((0, visitors_1.createVisitor)({
|
|
487
|
+
AssignmentStatement: (stmt) => {
|
|
488
|
+
if (stmt.tokens.name.text.toLowerCase() === 'x') {
|
|
489
|
+
assigns.push(stmt);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
}), { walkMode: visitors_1.WalkMode.visitAllRecursive });
|
|
493
|
+
// func1 - uses file level typecast
|
|
494
|
+
(0, testHelpers_spec_1.expectTypeToBe)(assigns[0].getSymbolTable().getSymbolType('m', { flags: 1 /* SymbolTypeFlag.runtime */ }), InterfaceType_1.InterfaceType);
|
|
495
|
+
(0, chai_config_spec_1.expect)(assigns[0].getSymbolTable().getSymbolType('m', { flags: 1 /* SymbolTypeFlag.runtime */ }).toString()).to.eq('Thing1');
|
|
496
|
+
(0, testHelpers_spec_1.expectTypeToBe)(assigns[0].getSymbolTable().getSymbolType('x', { flags: 1 /* SymbolTypeFlag.runtime */ }), IntegerType_1.IntegerType);
|
|
497
|
+
// func2 - uses func level typecast
|
|
498
|
+
(0, testHelpers_spec_1.expectTypeToBe)(assigns[1].getSymbolTable().getSymbolType('m', { flags: 1 /* SymbolTypeFlag.runtime */ }), InterfaceType_1.InterfaceType);
|
|
499
|
+
(0, chai_config_spec_1.expect)(assigns[1].getSymbolTable().getSymbolType('m', { flags: 1 /* SymbolTypeFlag.runtime */ }).toString()).to.eq('Thing2');
|
|
500
|
+
(0, testHelpers_spec_1.expectTypeToBe)(assigns[1].getSymbolTable().getSymbolType('x', { flags: 1 /* SymbolTypeFlag.runtime */ }), StringType_1.StringType);
|
|
501
|
+
// func3 - uses innerFunc level typecast
|
|
502
|
+
(0, testHelpers_spec_1.expectTypeToBe)(assigns[2].getSymbolTable().getSymbolType('m', { flags: 1 /* SymbolTypeFlag.runtime */ }), InterfaceType_1.InterfaceType);
|
|
503
|
+
(0, chai_config_spec_1.expect)(assigns[2].getSymbolTable().getSymbolType('m', { flags: 1 /* SymbolTypeFlag.runtime */ }).toString()).to.eq('Thing3');
|
|
504
|
+
(0, testHelpers_spec_1.expectTypeToBe)(assigns[2].getSymbolTable().getSymbolType('x', { flags: 1 /* SymbolTypeFlag.runtime */ }), FloatType_1.FloatType);
|
|
505
|
+
});
|
|
506
|
+
it('should allow classes to override m typecast', () => {
|
|
507
|
+
program.setFile('source/types.bs', `
|
|
508
|
+
interface Thing1
|
|
509
|
+
value as integer
|
|
510
|
+
end interface
|
|
511
|
+
`);
|
|
512
|
+
const file = program.setFile('source/main.bs', `
|
|
513
|
+
import "types.bs"
|
|
514
|
+
typecast m as Thing1
|
|
515
|
+
|
|
516
|
+
class TestKlass
|
|
517
|
+
value as string
|
|
518
|
+
|
|
519
|
+
sub method1()
|
|
520
|
+
x = m.value
|
|
521
|
+
print x
|
|
522
|
+
end sub
|
|
523
|
+
|
|
524
|
+
sub method2()
|
|
525
|
+
typecast m as Thing1
|
|
526
|
+
x = m.value
|
|
527
|
+
print x
|
|
528
|
+
end sub
|
|
529
|
+
end class
|
|
530
|
+
`);
|
|
531
|
+
program.validate();
|
|
532
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
533
|
+
const assigns = [];
|
|
534
|
+
// find places in AST where "x" is assigned
|
|
535
|
+
file.ast.walk((0, visitors_1.createVisitor)({
|
|
536
|
+
AssignmentStatement: (stmt) => {
|
|
537
|
+
if (stmt.tokens.name.text.toLowerCase() === 'x') {
|
|
538
|
+
assigns.push(stmt);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
}), { walkMode: visitors_1.WalkMode.visitAllRecursive });
|
|
542
|
+
// method1 - uses class 'm'
|
|
543
|
+
(0, testHelpers_spec_1.expectTypeToBe)(assigns[0].getSymbolTable().getSymbolType('m', { flags: 1 /* SymbolTypeFlag.runtime */ }), ClassType_1.ClassType);
|
|
544
|
+
(0, chai_config_spec_1.expect)(assigns[0].getSymbolTable().getSymbolType('m', { flags: 1 /* SymbolTypeFlag.runtime */ }).toString()).to.eq('TestKlass');
|
|
545
|
+
(0, testHelpers_spec_1.expectTypeToBe)(assigns[0].getSymbolTable().getSymbolType('x', { flags: 1 /* SymbolTypeFlag.runtime */ }), StringType_1.StringType);
|
|
546
|
+
// method2 - uses func level typecast
|
|
547
|
+
(0, testHelpers_spec_1.expectTypeToBe)(assigns[1].getSymbolTable().getSymbolType('m', { flags: 1 /* SymbolTypeFlag.runtime */ }), InterfaceType_1.InterfaceType);
|
|
548
|
+
(0, chai_config_spec_1.expect)(assigns[1].getSymbolTable().getSymbolType('m', { flags: 1 /* SymbolTypeFlag.runtime */ }).toString()).to.eq('Thing1');
|
|
549
|
+
(0, testHelpers_spec_1.expectTypeToBe)(assigns[1].getSymbolTable().getSymbolType('x', { flags: 1 /* SymbolTypeFlag.runtime */ }), IntegerType_1.IntegerType);
|
|
550
|
+
});
|
|
551
|
+
it('has diagnostic when used in a class', () => {
|
|
552
|
+
program.setFile('source/main.bs', `
|
|
553
|
+
class TestKlass
|
|
554
|
+
typecast m as object
|
|
555
|
+
|
|
556
|
+
value as string
|
|
557
|
+
|
|
558
|
+
sub method1()
|
|
559
|
+
x = m.value
|
|
560
|
+
print x
|
|
561
|
+
end sub
|
|
562
|
+
end class
|
|
563
|
+
`);
|
|
564
|
+
program.validate();
|
|
565
|
+
(0, testHelpers_spec_1.expectHasDiagnostics)(program);
|
|
566
|
+
});
|
|
567
|
+
it('is allowed in namespace', () => {
|
|
568
|
+
program.setFile('source/types.bs', `
|
|
569
|
+
interface Thing1
|
|
570
|
+
value as integer
|
|
571
|
+
end interface
|
|
572
|
+
`);
|
|
573
|
+
const file = program.setFile('source/main.bs', `
|
|
574
|
+
import "types.bs"
|
|
575
|
+
|
|
576
|
+
namespace Alpha.Beta
|
|
577
|
+
typecast m as Thing1
|
|
578
|
+
|
|
579
|
+
sub method1()
|
|
580
|
+
x = m.value
|
|
581
|
+
print x
|
|
582
|
+
end sub
|
|
583
|
+
end namespace
|
|
584
|
+
`);
|
|
585
|
+
program.validate();
|
|
586
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
587
|
+
// find places in AST where "x" is assigned
|
|
588
|
+
const assigns = [];
|
|
589
|
+
file.ast.walk((0, visitors_1.createVisitor)({
|
|
590
|
+
AssignmentStatement: (stmt) => {
|
|
591
|
+
if (stmt.tokens.name.text.toLowerCase() === 'x') {
|
|
592
|
+
assigns.push(stmt);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
}), { walkMode: visitors_1.WalkMode.visitAllRecursive });
|
|
596
|
+
// method1 - uses Thing1 'm'
|
|
597
|
+
(0, testHelpers_spec_1.expectTypeToBe)(assigns[0].getSymbolTable().getSymbolType('m', { flags: 1 /* SymbolTypeFlag.runtime */ }), InterfaceType_1.InterfaceType);
|
|
598
|
+
(0, chai_config_spec_1.expect)(assigns[0].getSymbolTable().getSymbolType('m', { flags: 1 /* SymbolTypeFlag.runtime */ }).toString()).to.eq('Thing1');
|
|
599
|
+
(0, testHelpers_spec_1.expectTypeToBe)(assigns[0].getSymbolTable().getSymbolType('x', { flags: 1 /* SymbolTypeFlag.runtime */ }), IntegerType_1.IntegerType);
|
|
600
|
+
});
|
|
601
|
+
});
|
|
602
|
+
describe('alias statement', () => {
|
|
603
|
+
it('allows being at start of file', () => {
|
|
604
|
+
program.setFile('source/main.bs', `
|
|
605
|
+
alias x = lcase
|
|
606
|
+
sub noop()
|
|
607
|
+
end sub
|
|
608
|
+
`);
|
|
609
|
+
program.validate();
|
|
610
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
611
|
+
});
|
|
612
|
+
it('no diagnostic if more than one usage per block', () => {
|
|
613
|
+
program.setFile('source/main.bs', `
|
|
614
|
+
alias x = lcase
|
|
615
|
+
alias y = Str
|
|
616
|
+
sub noop()
|
|
617
|
+
print x(y(1))
|
|
618
|
+
end sub
|
|
619
|
+
`);
|
|
620
|
+
program.validate();
|
|
621
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
622
|
+
});
|
|
623
|
+
it('has diagnostic if used not at top of file', () => {
|
|
624
|
+
program.setFile('source/main.bs', `
|
|
625
|
+
namespace alpha
|
|
626
|
+
alias x = lcase
|
|
627
|
+
sub noop()
|
|
628
|
+
alias y = str
|
|
629
|
+
print "hello"
|
|
630
|
+
end sub
|
|
631
|
+
end namespace
|
|
632
|
+
`);
|
|
633
|
+
program.validate();
|
|
634
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
635
|
+
DiagnosticMessages_1.DiagnosticMessages.unexpectedStatementLocation('alias', 'at the top of the file').message,
|
|
636
|
+
DiagnosticMessages_1.DiagnosticMessages.unexpectedStatementLocation('alias', 'at the top of the file').message
|
|
637
|
+
]);
|
|
638
|
+
});
|
|
639
|
+
it('sets the type of the name', () => {
|
|
640
|
+
program.setFile('source/types.bs', `
|
|
641
|
+
interface Thing1
|
|
642
|
+
value as string
|
|
643
|
+
end interface
|
|
644
|
+
namespace alpha.beta
|
|
645
|
+
function piAsStr()
|
|
646
|
+
return "3.14"
|
|
647
|
+
end function
|
|
648
|
+
const eulerAsStr = "2.78"
|
|
649
|
+
end namespace
|
|
650
|
+
function lowercase(text as string) as string
|
|
651
|
+
return lcase(text)
|
|
652
|
+
end function
|
|
653
|
+
`);
|
|
654
|
+
const file = program.setFile('source/main.bs', `
|
|
655
|
+
import "types.bs"
|
|
656
|
+
alias t = Thing1
|
|
657
|
+
alias p = alpha.beta.piAsStr
|
|
658
|
+
alias e = alpha.beta.eulerAsStr
|
|
659
|
+
alias l = lowercase
|
|
660
|
+
namespace ns1.ns2
|
|
661
|
+
function lowercase(x as integer) as integer
|
|
662
|
+
return x
|
|
663
|
+
end function
|
|
664
|
+
sub func1(usedAsType as t)
|
|
665
|
+
x = usedAsType.value
|
|
666
|
+
print
|
|
667
|
+
print l(x)
|
|
668
|
+
print l(p())
|
|
669
|
+
print l(e)
|
|
670
|
+
end sub
|
|
671
|
+
end namespace
|
|
672
|
+
`);
|
|
673
|
+
program.validate();
|
|
674
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
675
|
+
let func;
|
|
676
|
+
// find places in AST where "x" is assigned
|
|
677
|
+
file.ast.walk((0, visitors_1.createVisitor)({
|
|
678
|
+
FunctionStatement: (stmt) => {
|
|
679
|
+
if (stmt.getName(Parser_1.ParseMode.BrighterScript) === 'ns1.ns2.func1') {
|
|
680
|
+
func = stmt.func;
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
}), { walkMode: visitors_1.WalkMode.visitAllRecursive });
|
|
684
|
+
const symbolTable = func.getSymbolTable();
|
|
685
|
+
(0, testHelpers_spec_1.expectTypeToBe)(symbolTable.getSymbolType('t', { flags: 2 /* SymbolTypeFlag.typetime */ }), InterfaceType_1.InterfaceType);
|
|
686
|
+
const tType = symbolTable.getSymbolType('t', { flags: 2 /* SymbolTypeFlag.typetime */ });
|
|
687
|
+
(0, chai_config_spec_1.expect)(tType.name).to.eq('Thing1');
|
|
688
|
+
(0, testHelpers_spec_1.expectTypeToBe)(symbolTable.getSymbolType('p', { flags: 1 /* SymbolTypeFlag.runtime */ }), TypedFunctionType_1.TypedFunctionType);
|
|
689
|
+
(0, testHelpers_spec_1.expectTypeToBe)(symbolTable.getSymbolType('e', { flags: 1 /* SymbolTypeFlag.runtime */ }), StringType_1.StringType);
|
|
690
|
+
(0, testHelpers_spec_1.expectTypeToBe)(symbolTable.getSymbolType('l', { flags: 1 /* SymbolTypeFlag.runtime */ }), TypedFunctionType_1.TypedFunctionType);
|
|
691
|
+
});
|
|
692
|
+
it('has diagnostic when rhs not found', () => {
|
|
693
|
+
program.setFile('source/main.bs', `
|
|
694
|
+
alias x = notThere
|
|
695
|
+
sub noop()
|
|
696
|
+
end sub
|
|
697
|
+
`);
|
|
698
|
+
program.validate();
|
|
699
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
700
|
+
DiagnosticMessages_1.DiagnosticMessages.cannotFindName('notThere').message
|
|
701
|
+
]);
|
|
702
|
+
});
|
|
703
|
+
});
|
|
704
|
+
describe('type statement', () => {
|
|
705
|
+
it('allows being at top of ast', () => {
|
|
706
|
+
program.setFile('source/main.bs', `
|
|
707
|
+
type x = string
|
|
708
|
+
sub noop(input as x)
|
|
709
|
+
print input
|
|
710
|
+
end sub
|
|
711
|
+
`);
|
|
712
|
+
program.validate();
|
|
713
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
714
|
+
});
|
|
715
|
+
it('no diagnostic if more than one usage per block', () => {
|
|
716
|
+
program.setFile('source/main.bs', `
|
|
717
|
+
type x = string
|
|
718
|
+
type y = integer
|
|
719
|
+
sub noop(input as x) as y
|
|
720
|
+
return input.len()
|
|
721
|
+
end sub
|
|
722
|
+
`);
|
|
723
|
+
program.validate();
|
|
724
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
725
|
+
});
|
|
726
|
+
it('has diagnostic if used not at top of file', () => {
|
|
727
|
+
program.setFile('source/main.bs', `
|
|
728
|
+
namespace alpha
|
|
729
|
+
sub noop()
|
|
730
|
+
type y = string
|
|
731
|
+
print "hello"
|
|
732
|
+
end sub
|
|
733
|
+
end namespace
|
|
734
|
+
`);
|
|
735
|
+
program.validate();
|
|
736
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
737
|
+
DiagnosticMessages_1.DiagnosticMessages.keywordMustBeDeclaredAtNamespaceLevel('type').message
|
|
738
|
+
]);
|
|
739
|
+
});
|
|
740
|
+
it('sets the type of the name', () => {
|
|
741
|
+
program.setFile('source/types.bs', `
|
|
742
|
+
interface Thing1
|
|
743
|
+
value as string
|
|
744
|
+
end interface
|
|
745
|
+
namespace alpha.beta
|
|
746
|
+
enum someEnum
|
|
747
|
+
up = "up"
|
|
748
|
+
down = "down"
|
|
749
|
+
end enum
|
|
750
|
+
end namespace
|
|
751
|
+
`);
|
|
752
|
+
const file = program.setFile('source/main.bs', `
|
|
753
|
+
import "types.bs"
|
|
754
|
+
type t = Thing1
|
|
755
|
+
type t2 = alpha.beta.someEnum
|
|
756
|
+
|
|
757
|
+
namespace ns1.ns2
|
|
758
|
+
function getDirection(x as t) as t2
|
|
759
|
+
if x.value = "go up" then
|
|
760
|
+
return alpha.beta.someEnum.up
|
|
761
|
+
else
|
|
762
|
+
return alpha.beta.someEnum.down
|
|
763
|
+
end if
|
|
764
|
+
end function
|
|
765
|
+
end namespace
|
|
766
|
+
`);
|
|
767
|
+
program.validate();
|
|
768
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
769
|
+
let func;
|
|
770
|
+
// find places in AST where "x" is assigned
|
|
771
|
+
file.ast.walk((0, visitors_1.createVisitor)({
|
|
772
|
+
FunctionStatement: (stmt) => {
|
|
773
|
+
if (stmt.getName(Parser_1.ParseMode.BrighterScript) === 'ns1.ns2.getDirection') {
|
|
774
|
+
func = stmt.func;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
}), { walkMode: visitors_1.WalkMode.visitAllRecursive });
|
|
778
|
+
const symbolTable = func.getSymbolTable();
|
|
779
|
+
(0, testHelpers_spec_1.expectTypeToBe)(symbolTable.getSymbolType('t', { flags: 2 /* SymbolTypeFlag.typetime */ }), TypeStatementType_1.TypeStatementType);
|
|
780
|
+
const tType = symbolTable.getSymbolType('t', { flags: 2 /* SymbolTypeFlag.typetime */ });
|
|
781
|
+
(0, chai_config_spec_1.expect)(tType.name).to.eq('t');
|
|
782
|
+
(0, testHelpers_spec_1.expectTypeToBe)(tType.wrappedType, InterfaceType_1.InterfaceType);
|
|
783
|
+
(0, chai_config_spec_1.expect)(tType.wrappedType.name).to.eq('Thing1');
|
|
784
|
+
(0, testHelpers_spec_1.expectTypeToBe)(symbolTable.getSymbolType('t2', { flags: 2 /* SymbolTypeFlag.typetime */ }), TypeStatementType_1.TypeStatementType);
|
|
785
|
+
const t2Type = symbolTable.getSymbolType('t2', { flags: 2 /* SymbolTypeFlag.typetime */ });
|
|
786
|
+
(0, testHelpers_spec_1.expectTypeToBe)(t2Type.wrappedType, types_1.EnumType);
|
|
787
|
+
(0, chai_config_spec_1.expect)(t2Type.wrappedType.name).to.eq('alpha.beta.someEnum');
|
|
788
|
+
});
|
|
789
|
+
it('has diagnostic when rhs not found', () => {
|
|
790
|
+
program.setFile('source/main.bs', `
|
|
791
|
+
type x = notThere
|
|
792
|
+
sub noop()
|
|
793
|
+
end sub
|
|
794
|
+
`);
|
|
795
|
+
program.validate();
|
|
796
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
797
|
+
DiagnosticMessages_1.DiagnosticMessages.cannotFindName('notThere').message
|
|
798
|
+
]);
|
|
799
|
+
});
|
|
800
|
+
});
|
|
801
|
+
describe('conditional compile', () => {
|
|
802
|
+
it('allows top level definitions inside #if block', () => {
|
|
803
|
+
program.setFile('source/main.bs', `
|
|
804
|
+
#const debug = true
|
|
805
|
+
#if debug
|
|
806
|
+
function f()
|
|
807
|
+
return 3.14
|
|
808
|
+
end function
|
|
809
|
+
#end if
|
|
810
|
+
`);
|
|
811
|
+
program.validate();
|
|
812
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
813
|
+
});
|
|
814
|
+
it('does not allow top level definitions inside #if block inside a function', () => {
|
|
815
|
+
program.setFile('source/main.bs', `
|
|
816
|
+
#const debug = true
|
|
817
|
+
function f()
|
|
818
|
+
#if debug
|
|
819
|
+
namespace alpha
|
|
820
|
+
end namespace
|
|
821
|
+
#end if
|
|
822
|
+
end function
|
|
823
|
+
`);
|
|
824
|
+
program.validate();
|
|
825
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
826
|
+
DiagnosticMessages_1.DiagnosticMessages.keywordMustBeDeclaredAtNamespaceLevel('namespace')
|
|
827
|
+
]);
|
|
828
|
+
});
|
|
829
|
+
it('shows diagnostic for #error', () => {
|
|
830
|
+
program.setFile('source/main.bs', `
|
|
831
|
+
#const debug = true
|
|
832
|
+
function f()
|
|
833
|
+
#if debug
|
|
834
|
+
#error This is a conditional compile error
|
|
835
|
+
#end if
|
|
836
|
+
end function
|
|
837
|
+
`);
|
|
838
|
+
program.validate();
|
|
839
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
840
|
+
DiagnosticMessages_1.DiagnosticMessages.hashError('This is a conditional compile error')
|
|
841
|
+
]);
|
|
842
|
+
});
|
|
843
|
+
it('does not show diagnostic for #error when inside false CC block', () => {
|
|
844
|
+
program.setFile('source/main.bs', `
|
|
845
|
+
#const debug = false
|
|
846
|
+
function f()
|
|
847
|
+
#if debug
|
|
848
|
+
#error This is a conditional compile error
|
|
849
|
+
#end if
|
|
850
|
+
end function
|
|
851
|
+
`);
|
|
852
|
+
program.validate();
|
|
853
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
854
|
+
});
|
|
855
|
+
});
|
|
856
|
+
describe('types', () => {
|
|
857
|
+
it('sets assignments of invalid as dynamic', () => {
|
|
858
|
+
const file = program.setFile('source/main.bs', `
|
|
859
|
+
sub test()
|
|
860
|
+
channel = invalid
|
|
861
|
+
if true
|
|
862
|
+
channel = {
|
|
863
|
+
height: 123
|
|
864
|
+
}
|
|
865
|
+
end if
|
|
866
|
+
|
|
867
|
+
height = 0
|
|
868
|
+
if channel <> invalid then
|
|
869
|
+
height += channel.height
|
|
870
|
+
end if
|
|
871
|
+
end sub
|
|
872
|
+
`);
|
|
873
|
+
program.validate();
|
|
874
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
875
|
+
const func = file.ast.statements[0].findChild(reflection_1.isFunctionExpression, { walkMode: visitors_1.WalkMode.visitAllRecursive });
|
|
876
|
+
const table = func.body.getSymbolTable();
|
|
877
|
+
const data = {};
|
|
878
|
+
const channelType = table.getSymbolType('channel', { flags: 1 /* SymbolTypeFlag.runtime */, data: data });
|
|
879
|
+
(0, testHelpers_spec_1.expectTypeToBe)(channelType, DynamicType_1.DynamicType);
|
|
880
|
+
});
|
|
881
|
+
it('sets default arg of invalid as dynamic', () => {
|
|
882
|
+
const file = program.setFile('source/main.bs', `
|
|
883
|
+
sub test(channel = invalid)
|
|
884
|
+
if true
|
|
885
|
+
channel = {
|
|
886
|
+
height: 123
|
|
887
|
+
}
|
|
888
|
+
end if
|
|
889
|
+
|
|
890
|
+
height = 0
|
|
891
|
+
if channel <> invalid then
|
|
892
|
+
height += channel.height
|
|
893
|
+
end if
|
|
894
|
+
end sub
|
|
895
|
+
`);
|
|
896
|
+
program.validate();
|
|
897
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
898
|
+
const func = file.ast.statements[0].findChild(reflection_1.isFunctionExpression, { walkMode: visitors_1.WalkMode.visitAllRecursive });
|
|
899
|
+
const table = func.body.getSymbolTable();
|
|
900
|
+
const data = {};
|
|
901
|
+
const channelType = table.getSymbolType('channel', { flags: 1 /* SymbolTypeFlag.runtime */, data: data });
|
|
902
|
+
(0, testHelpers_spec_1.expectTypeToBe)(channelType, DynamicType_1.DynamicType);
|
|
903
|
+
});
|
|
904
|
+
});
|
|
905
|
+
describe('instances of types', () => {
|
|
906
|
+
it('sets assigned variables as instances', () => {
|
|
907
|
+
const file = program.setFile('source/main.bs', `
|
|
908
|
+
sub makeKlass()
|
|
909
|
+
x = new Klass()
|
|
910
|
+
end sub
|
|
911
|
+
|
|
912
|
+
class Klass
|
|
913
|
+
end class
|
|
914
|
+
`);
|
|
915
|
+
program.validate();
|
|
916
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
917
|
+
const func = file.ast.statements[0].findChild(reflection_1.isFunctionExpression, { walkMode: visitors_1.WalkMode.visitAllRecursive });
|
|
918
|
+
const table = func.body.getSymbolTable();
|
|
919
|
+
const data = {};
|
|
920
|
+
const xType = table.getSymbolType('x', { flags: 1 /* SymbolTypeFlag.runtime */, data: data });
|
|
921
|
+
(0, testHelpers_spec_1.expectTypeToBe)(xType, ClassType_1.ClassType);
|
|
922
|
+
(0, chai_config_spec_1.expect)(data.isInstance).to.be.true;
|
|
923
|
+
(0, chai_config_spec_1.expect)(table.isSymbolTypeInstance('x')).to.be.true;
|
|
924
|
+
});
|
|
925
|
+
it('sets params as instances', () => {
|
|
926
|
+
const file = program.setFile('source/main.bs', `
|
|
927
|
+
sub makeKlass(x as Klass, n = x.name)
|
|
928
|
+
end sub
|
|
929
|
+
|
|
930
|
+
class Klass
|
|
931
|
+
name as string
|
|
932
|
+
end class
|
|
933
|
+
`);
|
|
934
|
+
program.validate();
|
|
935
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
936
|
+
const func = file.ast.statements[0].findChild(reflection_1.isFunctionExpression, { walkMode: visitors_1.WalkMode.visitAllRecursive });
|
|
937
|
+
const table = func.getSymbolTable();
|
|
938
|
+
const data = {};
|
|
939
|
+
const xType = table.getSymbolType('x', { flags: 1 /* SymbolTypeFlag.runtime */, data: data });
|
|
940
|
+
(0, testHelpers_spec_1.expectTypeToBe)(xType, ClassType_1.ClassType);
|
|
941
|
+
(0, chai_config_spec_1.expect)(data.isInstance).to.be.true;
|
|
942
|
+
(0, chai_config_spec_1.expect)(table.isSymbolTypeInstance('x')).to.be.true;
|
|
943
|
+
const nType = table.getSymbolType('n', { flags: 1 /* SymbolTypeFlag.runtime */, data: data });
|
|
944
|
+
(0, testHelpers_spec_1.expectTypeToBe)(nType, StringType_1.StringType);
|
|
945
|
+
(0, chai_config_spec_1.expect)(data.isInstance).to.be.true;
|
|
946
|
+
(0, chai_config_spec_1.expect)(table.isSymbolTypeInstance('n')).to.be.true;
|
|
947
|
+
});
|
|
948
|
+
it('allows super as instance', () => {
|
|
949
|
+
const file = program.setFile('source/main.bs', `
|
|
950
|
+
class SuperKlass
|
|
951
|
+
name as string
|
|
952
|
+
sub new(name as string)
|
|
953
|
+
m.name = name
|
|
954
|
+
end sub
|
|
955
|
+
end class
|
|
956
|
+
|
|
957
|
+
class Klass extends SuperKlass
|
|
958
|
+
sub new()
|
|
959
|
+
super("hello")
|
|
960
|
+
end sub
|
|
961
|
+
|
|
962
|
+
function getName()
|
|
963
|
+
return super.name
|
|
964
|
+
end function
|
|
965
|
+
end class
|
|
966
|
+
`);
|
|
967
|
+
program.validate();
|
|
968
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
969
|
+
const klass = file.ast.statements[1];
|
|
970
|
+
const newTable = klass.methods[0].func.body.getSymbolTable();
|
|
971
|
+
let data = {};
|
|
972
|
+
const newSuperType = newTable.getSymbolType('super', { flags: 1 /* SymbolTypeFlag.runtime */, data: data });
|
|
973
|
+
(0, testHelpers_spec_1.expectTypeToBe)(newSuperType, ClassType_1.ClassType);
|
|
974
|
+
(0, chai_config_spec_1.expect)(data.isInstance).to.be.true;
|
|
975
|
+
const getNameTable = klass.methods[0].func.body.getSymbolTable();
|
|
976
|
+
data = {};
|
|
977
|
+
const getNameSuperType = getNameTable.getSymbolType('super', { flags: 1 /* SymbolTypeFlag.runtime */, data: data });
|
|
978
|
+
(0, testHelpers_spec_1.expectTypeToBe)(getNameSuperType, ClassType_1.ClassType);
|
|
979
|
+
(0, chai_config_spec_1.expect)(data.isInstance).to.be.true;
|
|
980
|
+
});
|
|
981
|
+
});
|
|
982
|
+
describe('types in comments', () => {
|
|
983
|
+
describe('@param', () => {
|
|
984
|
+
it('uses @param type in brs file', () => {
|
|
985
|
+
const file = program.setFile('source/main.brs', `
|
|
986
|
+
' @param {string} name
|
|
987
|
+
function sayHello(name)
|
|
988
|
+
print "Hello " + name
|
|
989
|
+
end function
|
|
990
|
+
`);
|
|
991
|
+
program.validate();
|
|
992
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
993
|
+
let data = {};
|
|
994
|
+
(0, testHelpers_spec_1.expectTypeToBe)(file.ast.findChild(reflection_1.isFunctionParameterExpression).getType({
|
|
995
|
+
flags: 1 /* SymbolTypeFlag.runtime */, data: data
|
|
996
|
+
}), StringType_1.StringType);
|
|
997
|
+
data = {};
|
|
998
|
+
const printSymbolTable = file.ast.findChild(reflection_1.isPrintStatement).getSymbolTable();
|
|
999
|
+
(0, testHelpers_spec_1.expectTypeToBe)(printSymbolTable.getSymbolType('name', {
|
|
1000
|
+
flags: 1 /* SymbolTypeFlag.runtime */, data: data
|
|
1001
|
+
}), StringType_1.StringType);
|
|
1002
|
+
(0, chai_config_spec_1.expect)(data.isFromDocComment).to.be.true;
|
|
1003
|
+
});
|
|
1004
|
+
it('handles no type in @param tag', () => {
|
|
1005
|
+
const file = program.setFile('source/main.brs', `
|
|
1006
|
+
' @param name
|
|
1007
|
+
function sayHello(name)
|
|
1008
|
+
print "Hello " + name
|
|
1009
|
+
end function
|
|
1010
|
+
`);
|
|
1011
|
+
program.validate();
|
|
1012
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1013
|
+
let data = {};
|
|
1014
|
+
(0, testHelpers_spec_1.expectTypeToBe)(file.ast.findChild(reflection_1.isFunctionParameterExpression).getType({
|
|
1015
|
+
flags: 1 /* SymbolTypeFlag.runtime */, data: data
|
|
1016
|
+
}), DynamicType_1.DynamicType);
|
|
1017
|
+
data = {};
|
|
1018
|
+
const printSymbolTable = file.ast.findChild(reflection_1.isPrintStatement).getSymbolTable();
|
|
1019
|
+
(0, testHelpers_spec_1.expectTypeToBe)(printSymbolTable.getSymbolType('name', {
|
|
1020
|
+
flags: 1 /* SymbolTypeFlag.runtime */, data: data
|
|
1021
|
+
}), DynamicType_1.DynamicType);
|
|
1022
|
+
});
|
|
1023
|
+
it('uses @param type in brs file that can refer to a custom type', () => {
|
|
1024
|
+
const file = program.setFile('source/main.brs', `
|
|
1025
|
+
' @param {Klass} myClass
|
|
1026
|
+
function sayHello(myClass)
|
|
1027
|
+
print "Hello " + myClass.name
|
|
1028
|
+
end function
|
|
1029
|
+
`);
|
|
1030
|
+
program.setFile('source/klass.bs', `
|
|
1031
|
+
class Klass
|
|
1032
|
+
name as string
|
|
1033
|
+
end class
|
|
1034
|
+
`);
|
|
1035
|
+
program.validate();
|
|
1036
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1037
|
+
const data = {};
|
|
1038
|
+
const funcParamExpr = file.ast.findChild(reflection_1.isFunctionParameterExpression);
|
|
1039
|
+
(0, testHelpers_spec_1.expectTypeToBe)(funcParamExpr.getType({
|
|
1040
|
+
flags: 2 /* SymbolTypeFlag.typetime */, data: data
|
|
1041
|
+
}), ClassType_1.ClassType);
|
|
1042
|
+
const myClassType = file.ast.findChild(reflection_1.isPrintStatement).getSymbolTable().getSymbolType('myClass', {
|
|
1043
|
+
flags: 1 /* SymbolTypeFlag.runtime */, data: data
|
|
1044
|
+
});
|
|
1045
|
+
(0, testHelpers_spec_1.expectTypeToBe)(myClassType, ClassType_1.ClassType);
|
|
1046
|
+
(0, testHelpers_spec_1.expectTypeToBe)(myClassType.getMemberType('name', { flags: 1 /* SymbolTypeFlag.runtime */ }), StringType_1.StringType);
|
|
1047
|
+
(0, chai_config_spec_1.expect)(data.isFromDocComment).to.be.true;
|
|
1048
|
+
});
|
|
1049
|
+
it('uses @param type in brs file that can refer to a built in type', () => {
|
|
1050
|
+
const file = program.setFile('source/main.brs', `
|
|
1051
|
+
' @param {roDeviceInfo} info
|
|
1052
|
+
function sayHello(info)
|
|
1053
|
+
print "Hello " + info.getModel()
|
|
1054
|
+
end function
|
|
1055
|
+
`);
|
|
1056
|
+
program.validate();
|
|
1057
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1058
|
+
const data = {};
|
|
1059
|
+
(0, testHelpers_spec_1.expectTypeToBe)(file.ast.findChild(reflection_1.isFunctionParameterExpression).getType({
|
|
1060
|
+
flags: 2 /* SymbolTypeFlag.typetime */, data: data
|
|
1061
|
+
}), InterfaceType_1.InterfaceType);
|
|
1062
|
+
const infoType = file.ast.findChild(reflection_1.isPrintStatement).getSymbolTable().getSymbolType('info', {
|
|
1063
|
+
flags: 1 /* SymbolTypeFlag.runtime */, data: data
|
|
1064
|
+
});
|
|
1065
|
+
(0, testHelpers_spec_1.expectTypeToBe)(infoType, InterfaceType_1.InterfaceType);
|
|
1066
|
+
(0, testHelpers_spec_1.expectTypeToBe)(infoType.getMemberType('getModel', { flags: 1 /* SymbolTypeFlag.runtime */ }), TypedFunctionType_1.TypedFunctionType);
|
|
1067
|
+
(0, chai_config_spec_1.expect)(data.isFromDocComment).to.be.true;
|
|
1068
|
+
});
|
|
1069
|
+
it('allows jsdoc comment style /** prefix', () => {
|
|
1070
|
+
const file = program.setFile('source/main.brs', `
|
|
1071
|
+
' /**
|
|
1072
|
+
' * @param {string} info
|
|
1073
|
+
' */
|
|
1074
|
+
function sayHello(info)
|
|
1075
|
+
print "Hello " + info
|
|
1076
|
+
end function
|
|
1077
|
+
`);
|
|
1078
|
+
program.validate();
|
|
1079
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1080
|
+
const data = {};
|
|
1081
|
+
(0, testHelpers_spec_1.expectTypeToBe)(file.ast.findChild(reflection_1.isFunctionParameterExpression).getType({
|
|
1082
|
+
flags: 1 /* SymbolTypeFlag.runtime */, data: data
|
|
1083
|
+
}), StringType_1.StringType);
|
|
1084
|
+
const infoType = file.ast.findChild(reflection_1.isPrintStatement).getSymbolTable().getSymbolType('info', {
|
|
1085
|
+
flags: 1 /* SymbolTypeFlag.runtime */, data: data
|
|
1086
|
+
});
|
|
1087
|
+
(0, testHelpers_spec_1.expectTypeToBe)(infoType, StringType_1.StringType);
|
|
1088
|
+
(0, chai_config_spec_1.expect)(data.isFromDocComment).to.be.true;
|
|
1089
|
+
});
|
|
1090
|
+
it('ignores types it cannot find', () => {
|
|
1091
|
+
const file = program.setFile('source/main.brs', `
|
|
1092
|
+
' @param {TypeNotThere} info
|
|
1093
|
+
function sayHello(info)
|
|
1094
|
+
print "Hello " + info.prop
|
|
1095
|
+
end function
|
|
1096
|
+
`);
|
|
1097
|
+
program.validate();
|
|
1098
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1099
|
+
DiagnosticMessages_1.DiagnosticMessages.cannotFindName('TypeNotThere').message
|
|
1100
|
+
]);
|
|
1101
|
+
const data = {};
|
|
1102
|
+
(0, testHelpers_spec_1.expectTypeToBe)(file.ast.findChild(reflection_1.isFunctionParameterExpression).getType({
|
|
1103
|
+
flags: 1 /* SymbolTypeFlag.runtime */, data: data
|
|
1104
|
+
}), DynamicType_1.DynamicType);
|
|
1105
|
+
const infoType = file.ast.findChild(reflection_1.isPrintStatement).getSymbolTable().getSymbolType('info', {
|
|
1106
|
+
flags: 1 /* SymbolTypeFlag.runtime */, data: data
|
|
1107
|
+
});
|
|
1108
|
+
(0, testHelpers_spec_1.expectTypeToBe)(infoType, DynamicType_1.DynamicType);
|
|
1109
|
+
(0, chai_config_spec_1.expect)(data.isFromDocComment).to.be.true;
|
|
1110
|
+
});
|
|
1111
|
+
it('allows built-in type in @param in Brightscript mode', () => {
|
|
1112
|
+
const file = program.setFile('source/main.brs', `
|
|
1113
|
+
' @param {roAssociativeArray} thing
|
|
1114
|
+
function sayHello(thing)
|
|
1115
|
+
print "Hello " + thing.name
|
|
1116
|
+
end function
|
|
1117
|
+
`);
|
|
1118
|
+
program.validate();
|
|
1119
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1120
|
+
let data = {};
|
|
1121
|
+
(0, testHelpers_spec_1.expectTypeToBe)(file.ast.findChild(reflection_1.isFunctionParameterExpression).getType({
|
|
1122
|
+
flags: 1 /* SymbolTypeFlag.runtime */, data: data
|
|
1123
|
+
}), InterfaceType_1.InterfaceType);
|
|
1124
|
+
data = {};
|
|
1125
|
+
const printSymbolTable = file.ast.findChild(reflection_1.isPrintStatement).getSymbolTable();
|
|
1126
|
+
const thingType = printSymbolTable.getSymbolType('thing', {
|
|
1127
|
+
flags: 1 /* SymbolTypeFlag.runtime */, data: data
|
|
1128
|
+
});
|
|
1129
|
+
(0, testHelpers_spec_1.expectTypeToBe)(thingType, InterfaceType_1.InterfaceType);
|
|
1130
|
+
(0, chai_config_spec_1.expect)(thingType.toString()).to.eql('roAssociativeArray');
|
|
1131
|
+
(0, chai_config_spec_1.expect)(data.isFromDocComment).to.be.true;
|
|
1132
|
+
});
|
|
1133
|
+
});
|
|
1134
|
+
describe('@return', () => {
|
|
1135
|
+
it('uses @return type in brs file', () => {
|
|
1136
|
+
const file = program.setFile('source/main.brs', `
|
|
1137
|
+
' @return {string}
|
|
1138
|
+
function getPie()
|
|
1139
|
+
return "pumpkin"
|
|
1140
|
+
end function
|
|
1141
|
+
`);
|
|
1142
|
+
program.validate();
|
|
1143
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1144
|
+
const data = {};
|
|
1145
|
+
const funcStmt = file.ast.findChild(reflection_1.isFunctionStatement);
|
|
1146
|
+
const funcType = funcStmt.getType({ flags: 1 /* SymbolTypeFlag.runtime */, data: data });
|
|
1147
|
+
(0, testHelpers_spec_1.expectTypeToBe)(funcType, TypedFunctionType_1.TypedFunctionType);
|
|
1148
|
+
const returnType = funcType.returnType;
|
|
1149
|
+
(0, testHelpers_spec_1.expectTypeToBe)(returnType, StringType_1.StringType);
|
|
1150
|
+
});
|
|
1151
|
+
it('allows unknown type when using @return tag', () => {
|
|
1152
|
+
const file = program.setFile('source/main.brs', `
|
|
1153
|
+
' @return {TypeNotThere}
|
|
1154
|
+
function getPie()
|
|
1155
|
+
return "pumpkin"
|
|
1156
|
+
end function
|
|
1157
|
+
`);
|
|
1158
|
+
program.validate();
|
|
1159
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1160
|
+
DiagnosticMessages_1.DiagnosticMessages.cannotFindName('TypeNotThere').message
|
|
1161
|
+
]);
|
|
1162
|
+
const data = {};
|
|
1163
|
+
const funcStmt = file.ast.findChild(reflection_1.isFunctionStatement);
|
|
1164
|
+
const funcType = funcStmt.getType({ flags: 1 /* SymbolTypeFlag.runtime */, data: data });
|
|
1165
|
+
(0, testHelpers_spec_1.expectTypeToBe)(funcType, TypedFunctionType_1.TypedFunctionType);
|
|
1166
|
+
const returnType = funcType.returnType;
|
|
1167
|
+
(0, testHelpers_spec_1.expectTypeToBe)(returnType, DynamicType_1.DynamicType);
|
|
1168
|
+
});
|
|
1169
|
+
it('validates return statements against @return tag with valid type', () => {
|
|
1170
|
+
const file = program.setFile('source/main.brs', `
|
|
1171
|
+
' @return {integer}
|
|
1172
|
+
function getPie()
|
|
1173
|
+
return "pumpkin"
|
|
1174
|
+
end function
|
|
1175
|
+
`);
|
|
1176
|
+
program.validate();
|
|
1177
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1178
|
+
DiagnosticMessages_1.DiagnosticMessages.returnTypeMismatch('string', 'integer').message
|
|
1179
|
+
]);
|
|
1180
|
+
const data = {};
|
|
1181
|
+
const funcStmt = file.ast.findChild(reflection_1.isFunctionStatement);
|
|
1182
|
+
const funcType = funcStmt.getType({ flags: 1 /* SymbolTypeFlag.runtime */, data: data });
|
|
1183
|
+
(0, testHelpers_spec_1.expectTypeToBe)(funcType, TypedFunctionType_1.TypedFunctionType);
|
|
1184
|
+
const returnType = funcType.returnType;
|
|
1185
|
+
(0, testHelpers_spec_1.expectTypeToBe)(returnType, IntegerType_1.IntegerType);
|
|
1186
|
+
});
|
|
1187
|
+
it('checks return statements against @return tag with valid custom type', () => {
|
|
1188
|
+
const file = program.setFile('source/main.brs', `
|
|
1189
|
+
' @return {alpha.Klass}
|
|
1190
|
+
function getPie()
|
|
1191
|
+
return alpha_Klass()
|
|
1192
|
+
end function
|
|
1193
|
+
`);
|
|
1194
|
+
program.setFile('source/klass.bs', `
|
|
1195
|
+
namespace alpha
|
|
1196
|
+
class Klass
|
|
1197
|
+
name as string
|
|
1198
|
+
end class
|
|
1199
|
+
end namespace
|
|
1200
|
+
`);
|
|
1201
|
+
program.validate();
|
|
1202
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1203
|
+
const data = {};
|
|
1204
|
+
const funcStmt = file.ast.findChild(reflection_1.isFunctionStatement);
|
|
1205
|
+
const funcType = funcStmt.getType({ flags: 2 /* SymbolTypeFlag.typetime */, data: data });
|
|
1206
|
+
(0, testHelpers_spec_1.expectTypeToBe)(funcType, TypedFunctionType_1.TypedFunctionType);
|
|
1207
|
+
const returnType = funcType.returnType;
|
|
1208
|
+
(0, testHelpers_spec_1.expectTypeToBe)(returnType, ClassType_1.ClassType);
|
|
1209
|
+
});
|
|
1210
|
+
it('validates return statements against @return tag with valid custom type', () => {
|
|
1211
|
+
program.setFile('source/main.brs', `
|
|
1212
|
+
' @return {alpha.Klass}
|
|
1213
|
+
function getPie()
|
|
1214
|
+
return "foo"
|
|
1215
|
+
end function
|
|
1216
|
+
`);
|
|
1217
|
+
program.setFile('source/klass.bs', `
|
|
1218
|
+
namespace alpha
|
|
1219
|
+
class Klass
|
|
1220
|
+
name as string
|
|
1221
|
+
end class
|
|
1222
|
+
end namespace
|
|
1223
|
+
`);
|
|
1224
|
+
program.validate();
|
|
1225
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1226
|
+
DiagnosticMessages_1.DiagnosticMessages.returnTypeMismatch('string', 'alpha.Klass').message
|
|
1227
|
+
]);
|
|
1228
|
+
});
|
|
1229
|
+
});
|
|
1230
|
+
describe('@type', () => {
|
|
1231
|
+
it('uses @type type in brs file', () => {
|
|
1232
|
+
const file = program.setFile('source/main.brs', `
|
|
1233
|
+
function getPie() as string
|
|
1234
|
+
' @type {string}
|
|
1235
|
+
pieType = getFruit()
|
|
1236
|
+
return pieType
|
|
1237
|
+
end function
|
|
1238
|
+
|
|
1239
|
+
function getFruit()
|
|
1240
|
+
return "apple"
|
|
1241
|
+
end function
|
|
1242
|
+
`);
|
|
1243
|
+
program.validate();
|
|
1244
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1245
|
+
const data = {};
|
|
1246
|
+
const funcStmt = file.ast.findChild(reflection_1.isFunctionStatement);
|
|
1247
|
+
const returnStmt = funcStmt.findChild(reflection_1.isReturnStatement);
|
|
1248
|
+
const varType = returnStmt.getSymbolTable().getSymbolType('pieType', { flags: 1 /* SymbolTypeFlag.runtime */, data: data });
|
|
1249
|
+
(0, testHelpers_spec_1.expectTypeToBe)(varType, StringType_1.StringType);
|
|
1250
|
+
});
|
|
1251
|
+
it('allows unknown type when using @type tag', () => {
|
|
1252
|
+
const file = program.setFile('source/main.brs', `
|
|
1253
|
+
|
|
1254
|
+
function getValue()
|
|
1255
|
+
' @type {unknown}
|
|
1256
|
+
something = {}
|
|
1257
|
+
return something
|
|
1258
|
+
end function
|
|
1259
|
+
`);
|
|
1260
|
+
program.validate();
|
|
1261
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1262
|
+
DiagnosticMessages_1.DiagnosticMessages.cannotFindName('unknown').message
|
|
1263
|
+
]);
|
|
1264
|
+
const data = {};
|
|
1265
|
+
const funcStmt = file.ast.findChild(reflection_1.isFunctionStatement);
|
|
1266
|
+
const funcType = funcStmt.getType({ flags: 1 /* SymbolTypeFlag.runtime */, data: data });
|
|
1267
|
+
(0, testHelpers_spec_1.expectTypeToBe)(funcType, TypedFunctionType_1.TypedFunctionType);
|
|
1268
|
+
const returnType = funcType.returnType;
|
|
1269
|
+
(0, testHelpers_spec_1.expectTypeToBe)(returnType, DynamicType_1.DynamicType);
|
|
1270
|
+
});
|
|
1271
|
+
it('treats variable as type given in @type', () => {
|
|
1272
|
+
const file = program.setFile('source/main.brs', `
|
|
1273
|
+
function getModelName()
|
|
1274
|
+
' @type {roDeviceInfo}
|
|
1275
|
+
info = getData()
|
|
1276
|
+
return info.getModel()
|
|
1277
|
+
end function
|
|
1278
|
+
|
|
1279
|
+
function getData()
|
|
1280
|
+
return {}
|
|
1281
|
+
end function
|
|
1282
|
+
`);
|
|
1283
|
+
program.validate();
|
|
1284
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1285
|
+
const data = {};
|
|
1286
|
+
const assignStmt = file.ast.findChild(reflection_1.isAssignmentStatement);
|
|
1287
|
+
const infoType = assignStmt.getSymbolTable().getSymbolType('info', { flags: 1 /* SymbolTypeFlag.runtime */, data: data });
|
|
1288
|
+
(0, testHelpers_spec_1.expectTypeToBe)(infoType, InterfaceType_1.InterfaceType);
|
|
1289
|
+
(0, chai_config_spec_1.expect)(infoType.toString()).to.eq('roDeviceInfo');
|
|
1290
|
+
(0, chai_config_spec_1.expect)(data.isFromDocComment).to.be.true;
|
|
1291
|
+
});
|
|
1292
|
+
});
|
|
1293
|
+
// Skipped until we can figure out how to handle @var tags
|
|
1294
|
+
describe.skip('@var', () => {
|
|
1295
|
+
it('uses @var type in brs file to define types of variables', () => {
|
|
1296
|
+
const file = program.setFile('source/main.brs', `
|
|
1297
|
+
function getPie() as string
|
|
1298
|
+
' @var {string} someDate
|
|
1299
|
+
if m.top.isTrue
|
|
1300
|
+
someDate = getDate()
|
|
1301
|
+
else
|
|
1302
|
+
someDate = m.date2
|
|
1303
|
+
end if
|
|
1304
|
+
|
|
1305
|
+
if m.someProp
|
|
1306
|
+
someDate = m.someProp.date
|
|
1307
|
+
end if
|
|
1308
|
+
|
|
1309
|
+
return someDate
|
|
1310
|
+
end function
|
|
1311
|
+
|
|
1312
|
+
function getDate()
|
|
1313
|
+
return "Dec 25"
|
|
1314
|
+
end function
|
|
1315
|
+
`);
|
|
1316
|
+
program.validate();
|
|
1317
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1318
|
+
const data = {};
|
|
1319
|
+
const funcStmt = file.ast.findChild(reflection_1.isFunctionStatement);
|
|
1320
|
+
const returnStmt = funcStmt.findChild(reflection_1.isReturnStatement);
|
|
1321
|
+
const varType = returnStmt.getSymbolTable().getSymbolType('someDate', { flags: 1 /* SymbolTypeFlag.runtime */, data: data });
|
|
1322
|
+
(0, testHelpers_spec_1.expectTypeToBe)(varType, StringType_1.StringType);
|
|
1323
|
+
});
|
|
1324
|
+
});
|
|
1325
|
+
});
|
|
1326
|
+
describe('try/catch', () => {
|
|
1327
|
+
it('allows omitting the exception variable in standard brightscript mode', () => {
|
|
1328
|
+
program.setFile('source/main.brs', `
|
|
1329
|
+
sub new()
|
|
1330
|
+
try
|
|
1331
|
+
print "hello"
|
|
1332
|
+
catch
|
|
1333
|
+
print "error"
|
|
1334
|
+
end try
|
|
1335
|
+
end sub
|
|
1336
|
+
`);
|
|
1337
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1338
|
+
});
|
|
1339
|
+
it('shows diagnostic when omitting the exception variable in standard brightscript mode', () => {
|
|
1340
|
+
program.setFile('source/main.brs', `
|
|
1341
|
+
sub new()
|
|
1342
|
+
try
|
|
1343
|
+
print "hello"
|
|
1344
|
+
catch
|
|
1345
|
+
print "error"
|
|
1346
|
+
end try
|
|
1347
|
+
end sub
|
|
1348
|
+
`);
|
|
1349
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, []);
|
|
1350
|
+
});
|
|
1351
|
+
it('shows diagnostics when using when omitting the exception variable in standard brightscript mode', () => {
|
|
1352
|
+
program.setFile('source/main.brs', `
|
|
1353
|
+
sub new()
|
|
1354
|
+
try
|
|
1355
|
+
print "hello"
|
|
1356
|
+
catch
|
|
1357
|
+
print "error"
|
|
1358
|
+
end try
|
|
1359
|
+
end sub
|
|
1360
|
+
`);
|
|
1361
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, []);
|
|
1362
|
+
});
|
|
1363
|
+
});
|
|
1364
|
+
describe('function return values', () => {
|
|
1365
|
+
it('catches sub with return value', () => {
|
|
1366
|
+
program.setFile('source/main.brs', `
|
|
1367
|
+
sub test()
|
|
1368
|
+
return true
|
|
1369
|
+
end sub
|
|
1370
|
+
`);
|
|
1371
|
+
program.validate();
|
|
1372
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1373
|
+
Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.voidFunctionMayNotReturnValue('sub')), { location: util_1.util.createLocation(2, 20, 2, 31, (0, util_1.standardizePath) `${testHelpers_spec_1.rootDir}/source/main.brs`) }),
|
|
1374
|
+
DiagnosticMessages_1.DiagnosticMessages.returnTypeMismatch('boolean', 'void', {})
|
|
1375
|
+
]);
|
|
1376
|
+
});
|
|
1377
|
+
it('catches sub as void with return value', () => {
|
|
1378
|
+
program.setFile('source/main.brs', `
|
|
1379
|
+
sub test() as void
|
|
1380
|
+
return true
|
|
1381
|
+
end sub
|
|
1382
|
+
`);
|
|
1383
|
+
program.validate();
|
|
1384
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1385
|
+
Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.voidFunctionMayNotReturnValue('sub')), { location: util_1.util.createLocation(2, 20, 2, 31, (0, util_1.standardizePath) `${testHelpers_spec_1.rootDir}/source/main.brs`) }),
|
|
1386
|
+
DiagnosticMessages_1.DiagnosticMessages.returnTypeMismatch('boolean', 'void', {})
|
|
1387
|
+
]);
|
|
1388
|
+
});
|
|
1389
|
+
it('catches function as void with return value', () => {
|
|
1390
|
+
program.setFile('source/main.brs', `
|
|
1391
|
+
function test() as void
|
|
1392
|
+
return true
|
|
1393
|
+
end function
|
|
1394
|
+
`);
|
|
1395
|
+
program.validate();
|
|
1396
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1397
|
+
Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.voidFunctionMayNotReturnValue('function')), { location: util_1.util.createLocation(2, 20, 2, 31, (0, util_1.standardizePath) `${testHelpers_spec_1.rootDir}/source/main.brs`) }),
|
|
1398
|
+
DiagnosticMessages_1.DiagnosticMessages.returnTypeMismatch('boolean', 'void', {})
|
|
1399
|
+
]);
|
|
1400
|
+
});
|
|
1401
|
+
it('catches sub as <type> without return value', () => {
|
|
1402
|
+
program.setFile('source/main.brs', `
|
|
1403
|
+
sub test() as integer
|
|
1404
|
+
return
|
|
1405
|
+
end sub
|
|
1406
|
+
`);
|
|
1407
|
+
program.validate();
|
|
1408
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1409
|
+
Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.nonVoidFunctionMustReturnValue('sub')), { location: util_1.util.createLocation(2, 20, 2, 26, (0, util_1.standardizePath) `${testHelpers_spec_1.rootDir}/source/main.brs`) }),
|
|
1410
|
+
DiagnosticMessages_1.DiagnosticMessages.returnTypeMismatch('void', 'integer', {})
|
|
1411
|
+
]);
|
|
1412
|
+
});
|
|
1413
|
+
it('catches function without return value', () => {
|
|
1414
|
+
program.setFile('source/main.brs', `
|
|
1415
|
+
function test()
|
|
1416
|
+
return
|
|
1417
|
+
end function
|
|
1418
|
+
`);
|
|
1419
|
+
program.validate();
|
|
1420
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.nonVoidFunctionMustReturnValue('function')), { location: util_1.util.createLocation(2, 20, 2, 26, (0, util_1.standardizePath) `${testHelpers_spec_1.rootDir}/source/main.brs`) })]);
|
|
1421
|
+
});
|
|
1422
|
+
it('catches function as <type> without return value', () => {
|
|
1423
|
+
program.setFile('source/main.brs', `
|
|
1424
|
+
function test() as integer
|
|
1425
|
+
return
|
|
1426
|
+
end function
|
|
1427
|
+
`);
|
|
1428
|
+
program.validate();
|
|
1429
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1430
|
+
Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.nonVoidFunctionMustReturnValue('function')), { location: util_1.util.createLocation(2, 20, 2, 26, (0, util_1.standardizePath) `${testHelpers_spec_1.rootDir}/source/main.brs`) }),
|
|
1431
|
+
DiagnosticMessages_1.DiagnosticMessages.returnTypeMismatch('void', 'integer', {})
|
|
1432
|
+
]);
|
|
1433
|
+
});
|
|
1434
|
+
it('catches anon sub with return value', () => {
|
|
1435
|
+
program.setFile('source/main.brs', `
|
|
1436
|
+
sub main()
|
|
1437
|
+
test = sub()
|
|
1438
|
+
return true
|
|
1439
|
+
end sub
|
|
1440
|
+
end sub
|
|
1441
|
+
`);
|
|
1442
|
+
program.validate();
|
|
1443
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1444
|
+
Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.voidFunctionMayNotReturnValue('sub')), { location: util_1.util.createLocation(3, 24, 3, 35, (0, util_1.standardizePath) `${testHelpers_spec_1.rootDir}/source/main.brs`) }),
|
|
1445
|
+
DiagnosticMessages_1.DiagnosticMessages.returnTypeMismatch('boolean', 'void', {})
|
|
1446
|
+
]);
|
|
1447
|
+
});
|
|
1448
|
+
it('catches sub as void with return value', () => {
|
|
1449
|
+
program.setFile('source/main.brs', `
|
|
1450
|
+
sub main()
|
|
1451
|
+
test = sub() as void
|
|
1452
|
+
return true
|
|
1453
|
+
end sub
|
|
1454
|
+
end sub
|
|
1455
|
+
`);
|
|
1456
|
+
program.validate();
|
|
1457
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1458
|
+
Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.voidFunctionMayNotReturnValue('sub')), { location: util_1.util.createLocation(3, 24, 3, 35, (0, util_1.standardizePath) `${testHelpers_spec_1.rootDir}/source/main.brs`) }),
|
|
1459
|
+
DiagnosticMessages_1.DiagnosticMessages.returnTypeMismatch('boolean', 'void', {})
|
|
1460
|
+
]);
|
|
1461
|
+
});
|
|
1462
|
+
it('catches function as void with return value', () => {
|
|
1463
|
+
program.setFile('source/main.brs', `
|
|
1464
|
+
sub main()
|
|
1465
|
+
test = function() as void
|
|
1466
|
+
return true
|
|
1467
|
+
end function
|
|
1468
|
+
end sub
|
|
1469
|
+
`);
|
|
1470
|
+
program.validate();
|
|
1471
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1472
|
+
Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.voidFunctionMayNotReturnValue('function')), { location: util_1.util.createLocation(3, 24, 3, 35, (0, util_1.standardizePath) `${testHelpers_spec_1.rootDir}/source/main.brs`) }),
|
|
1473
|
+
DiagnosticMessages_1.DiagnosticMessages.returnTypeMismatch('boolean', 'void', {})
|
|
1474
|
+
]);
|
|
1475
|
+
});
|
|
1476
|
+
it('catches sub as <type> without return value', () => {
|
|
1477
|
+
program.setFile('source/main.brs', `
|
|
1478
|
+
sub main()
|
|
1479
|
+
test = sub() as integer
|
|
1480
|
+
return
|
|
1481
|
+
end sub
|
|
1482
|
+
end sub
|
|
1483
|
+
`);
|
|
1484
|
+
program.validate();
|
|
1485
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1486
|
+
Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.nonVoidFunctionMustReturnValue('sub')), { location: util_1.util.createLocation(3, 24, 3, 30, (0, util_1.standardizePath) `${testHelpers_spec_1.rootDir}/source/main.brs`) }),
|
|
1487
|
+
DiagnosticMessages_1.DiagnosticMessages.returnTypeMismatch('void', 'integer', {})
|
|
1488
|
+
]);
|
|
1489
|
+
});
|
|
1490
|
+
it('catches function without return value', () => {
|
|
1491
|
+
program.setFile('source/main.brs', `
|
|
1492
|
+
sub main()
|
|
1493
|
+
test = function()
|
|
1494
|
+
return
|
|
1495
|
+
end function
|
|
1496
|
+
end sub
|
|
1497
|
+
`);
|
|
1498
|
+
program.validate();
|
|
1499
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.nonVoidFunctionMustReturnValue('function')), { location: util_1.util.createLocation(3, 24, 3, 30, (0, util_1.standardizePath) `${testHelpers_spec_1.rootDir}/source/main.brs`) })]);
|
|
1500
|
+
});
|
|
1501
|
+
it('catches function as <type> without return value', () => {
|
|
1502
|
+
program.setFile('source/main.brs', `
|
|
1503
|
+
sub main()
|
|
1504
|
+
test = function() as integer
|
|
1505
|
+
return
|
|
1506
|
+
end function
|
|
1507
|
+
end sub
|
|
1508
|
+
`);
|
|
1509
|
+
program.validate();
|
|
1510
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1511
|
+
Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.nonVoidFunctionMustReturnValue('function')), { location: util_1.util.createLocation(3, 24, 3, 30, (0, util_1.standardizePath) `${testHelpers_spec_1.rootDir}/source/main.brs`) }),
|
|
1512
|
+
DiagnosticMessages_1.DiagnosticMessages.returnTypeMismatch('void', 'integer', {})
|
|
1513
|
+
]);
|
|
1514
|
+
});
|
|
1515
|
+
});
|
|
1516
|
+
});
|
|
1517
|
+
//# sourceMappingURL=BrsFileValidator.spec.js.map
|