brighterscript 1.0.0-alpha.5 → 1.0.0-alpha.51
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 +79 -138
- package/bsconfig.schema.json +196 -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 +161 -43
- 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 +29 -4
- package/dist/CodeActionUtil.js +22 -5
- package/dist/CodeActionUtil.js.map +1 -1
- package/dist/CommentFlagProcessor.d.ts +20 -15
- package/dist/CommentFlagProcessor.js +143 -58
- package/dist/CommentFlagProcessor.js.map +1 -1
- package/dist/CrossScopeValidator.d.ts +68 -0
- package/dist/CrossScopeValidator.js +650 -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 +83 -0
- package/dist/DiagnosticManager.js +422 -0
- package/dist/DiagnosticManager.js.map +1 -0
- package/dist/DiagnosticMessages.d.ts +602 -196
- package/dist/DiagnosticMessages.js +926 -342
- 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 +136 -104
- package/dist/LanguageServer.js +577 -741
- 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 +302 -98
- package/dist/Program.js +1613 -726
- package/dist/Program.js.map +1 -1
- package/dist/ProgramBuilder.d.ts +39 -22
- package/dist/ProgramBuilder.js +245 -179
- package/dist/ProgramBuilder.js.map +1 -1
- package/dist/Scope.d.ts +227 -106
- package/dist/Scope.js +609 -557
- package/dist/Scope.js.map +1 -1
- package/dist/ScopeNamespaceLookup.d.ts +73 -0
- package/dist/ScopeNamespaceLookup.js +242 -0
- package/dist/ScopeNamespaceLookup.js.map +1 -0
- 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 +145 -26
- package/dist/SymbolTable.js +575 -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 +337 -0
- package/dist/astUtils/CachedLookups.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/creators.d.ts +54 -19
- package/dist/astUtils/creators.js +242 -42
- package/dist/astUtils/creators.js.map +1 -1
- package/dist/astUtils/reflection.d.ts +199 -85
- package/dist/astUtils/reflection.js +518 -145
- package/dist/astUtils/reflection.js.map +1 -1
- package/dist/astUtils/stackedVisitor.js.map +1 -1
- package/dist/astUtils/visitors.d.ts +117 -53
- package/dist/astUtils/visitors.js +95 -15
- package/dist/astUtils/visitors.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 +26 -4
- package/dist/bscPlugin/BscPlugin.js +96 -4
- package/dist/bscPlugin/BscPlugin.js.map +1 -1
- package/dist/bscPlugin/CallExpressionInfo.d.ts +36 -0
- package/dist/bscPlugin/CallExpressionInfo.js +142 -0
- package/dist/bscPlugin/CallExpressionInfo.js.map +1 -0
- package/dist/bscPlugin/FileWriter.d.ts +19 -0
- package/dist/bscPlugin/FileWriter.js +79 -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 +109 -7
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +676 -26
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
- package/dist/bscPlugin/codeActions/FixAllCodeActionsProcessor.d.ts +17 -0
- package/dist/bscPlugin/codeActions/FixAllCodeActionsProcessor.js +66 -0
- package/dist/bscPlugin/codeActions/FixAllCodeActionsProcessor.js.map +1 -0
- package/dist/bscPlugin/codeActions/codeActionHelpers.d.ts +18 -0
- package/dist/bscPlugin/codeActions/codeActionHelpers.js +31 -0
- package/dist/bscPlugin/codeActions/codeActionHelpers.js.map +1 -0
- 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/definition/DefinitionProvider.d.ts +13 -0
- package/dist/bscPlugin/definition/DefinitionProvider.js +220 -0
- package/dist/bscPlugin/definition/DefinitionProvider.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 +238 -0
- package/dist/bscPlugin/hover/HoverProcessor.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/selectionRanges/SelectionRangesProcessor.d.ts +7 -0
- package/dist/bscPlugin/selectionRanges/SelectionRangesProcessor.js +77 -0
- package/dist/bscPlugin/selectionRanges/SelectionRangesProcessor.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/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 +80 -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/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/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 +34 -0
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js +504 -0
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.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 +51 -0
- package/dist/bscPlugin/validation/BrsFileValidator.js +714 -0
- package/dist/bscPlugin/validation/BrsFileValidator.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 +158 -0
- package/dist/bscPlugin/validation/ScopeValidator.js +1481 -0
- package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -0
- package/dist/bscPlugin/validation/XmlFileValidator.d.ts +8 -0
- package/dist/bscPlugin/validation/XmlFileValidator.js +50 -0
- package/dist/bscPlugin/validation/XmlFileValidator.js.map +1 -0
- package/dist/cli.js +140 -28
- 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/deferred.d.ts +5 -3
- package/dist/deferred.js +10 -0
- package/dist/deferred.js.map +1 -1
- package/dist/diagnosticUtils.d.ts +61 -4
- package/dist/diagnosticUtils.js +285 -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.d.ts +161 -87
- package/dist/files/BrsFile.js +919 -936
- package/dist/files/BrsFile.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/XmlFile.d.ts +80 -41
- package/dist/files/XmlFile.js +162 -137
- package/dist/files/XmlFile.js.map +1 -1
- 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 +987 -125
- package/dist/interfaces.js +21 -0
- package/dist/interfaces.js.map +1 -1
- package/dist/lexer/Lexer.d.ts +51 -12
- package/dist/lexer/Lexer.js +214 -65
- package/dist/lexer/Lexer.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 +48 -2
- package/dist/lexer/TokenKind.js +167 -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/DocumentManager.d.ts +63 -0
- package/dist/lsp/DocumentManager.js +122 -0
- package/dist/lsp/DocumentManager.js.map +1 -0
- package/dist/lsp/LspProject.d.ts +287 -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/Project.d.ts +200 -0
- package/dist/lsp/Project.js +562 -0
- package/dist/lsp/Project.js.map +1 -0
- package/dist/lsp/ProjectManager.d.ts +288 -0
- package/dist/lsp/ProjectManager.js +967 -0
- package/dist/lsp/ProjectManager.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/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/WorkerThreadProject.d.ts +168 -0
- package/dist/lsp/worker/WorkerThreadProject.js +205 -0
- package/dist/lsp/worker/WorkerThreadProject.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.js +14 -0
- package/dist/lsp/worker/run.js.map +1 -0
- package/dist/parser/AstNode.d.ts +205 -0
- package/dist/parser/AstNode.js +305 -0
- package/dist/parser/AstNode.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/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 +601 -220
- package/dist/parser/Expression.js +1516 -502
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Parser.d.ts +137 -121
- package/dist/parser/Parser.js +1808 -982
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/SGParser.d.ts +30 -13
- package/dist/parser/SGParser.js +94 -56
- package/dist/parser/SGParser.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 +854 -267
- package/dist/parser/Statement.js +2416 -621
- package/dist/parser/Statement.js.map +1 -1
- package/dist/parser/TranspileState.d.ts +30 -14
- package/dist/parser/TranspileState.js +124 -27
- package/dist/parser/TranspileState.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/roku-types/data.json +20554 -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 +95 -25
- package/dist/types/ArrayType.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/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/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 +63 -0
- package/dist/types/ClassType.js.map +1 -0
- package/dist/types/ComponentType.d.ts +22 -0
- package/dist/types/ComponentType.js +110 -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/DynamicType.d.ts +13 -5
- package/dist/types/DynamicType.js +26 -5
- package/dist/types/DynamicType.js.map +1 -1
- package/dist/types/EnumType.d.ts +42 -0
- package/dist/types/EnumType.js +101 -0
- package/dist/types/EnumType.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/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/InterfaceType.d.ts +14 -6
- package/dist/types/InterfaceType.js +30 -15
- package/dist/types/InterfaceType.js.map +1 -1
- package/dist/types/IntersectionType.d.ts +29 -0
- package/dist/types/IntersectionType.js +256 -0
- package/dist/types/IntersectionType.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/LongIntegerType.d.ts +10 -5
- package/dist/types/LongIntegerType.js +21 -17
- package/dist/types/LongIntegerType.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/ReferenceType.d.ts +123 -0
- package/dist/types/ReferenceType.js +726 -0
- package/dist/types/ReferenceType.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/TypeStatementType.d.ts +19 -0
- package/dist/types/TypeStatementType.js +56 -0
- package/dist/types/TypeStatementType.js.map +1 -0
- package/dist/types/TypedFunctionType.d.ts +34 -0
- package/dist/types/TypedFunctionType.js +157 -0
- package/dist/types/TypedFunctionType.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 +196 -0
- package/dist/types/UnionType.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/helpers.d.ts +51 -0
- package/dist/types/helpers.js +329 -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/util.d.ts +325 -185
- package/dist/util.js +2135 -568
- 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 +183 -138
- package/CHANGELOG.md +0 -1188
- package/dist/astUtils/creators.spec.js +0 -21
- package/dist/astUtils/creators.spec.js.map +0 -1
- 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/astUtils/reflection.spec.d.ts +0 -1
- package/dist/astUtils/reflection.spec.js +0 -292
- package/dist/astUtils/reflection.spec.js.map +0 -1
- package/dist/astUtils/stackedVisitor.spec.d.ts +0 -1
- package/dist/astUtils/stackedVisitor.spec.js +0 -79
- package/dist/astUtils/stackedVisitor.spec.js.map +0 -1
- package/dist/astUtils/visitors.spec.d.ts +0 -1
- package/dist/astUtils/visitors.spec.js +0 -854
- package/dist/astUtils/visitors.spec.js.map +0 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.d.ts +0 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +0 -194
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.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.d.ts +0 -1
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.spec.js +0 -45
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.spec.js.map +0 -1
- package/dist/files/BrsFile.Class.spec.d.ts +0 -1
- package/dist/files/BrsFile.Class.spec.js +0 -1081
- package/dist/files/BrsFile.Class.spec.js.map +0 -1
- package/dist/files/BrsFile.spec.d.ts +0 -1
- package/dist/files/BrsFile.spec.js +0 -2524
- package/dist/files/BrsFile.spec.js.map +0 -1
- package/dist/files/XmlFile.spec.d.ts +0 -1
- package/dist/files/XmlFile.spec.js +0 -1065
- package/dist/files/XmlFile.spec.js.map +0 -1
- package/dist/files/tests/imports.spec.d.ts +0 -1
- package/dist/files/tests/imports.spec.js +0 -241
- package/dist/files/tests/imports.spec.js.map +0 -1
- package/dist/lexer/Character.spec.d.ts +0 -1
- package/dist/lexer/Character.spec.js +0 -27
- package/dist/lexer/Character.spec.js.map +0 -1
- package/dist/lexer/Lexer.spec.d.ts +0 -1
- package/dist/lexer/Lexer.spec.js +0 -1101
- package/dist/lexer/Lexer.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/Parser.Class.spec.d.ts +0 -1
- package/dist/parser/Parser.Class.spec.js +0 -390
- package/dist/parser/Parser.Class.spec.js.map +0 -1
- package/dist/parser/Parser.spec.d.ts +0 -4
- package/dist/parser/Parser.spec.js +0 -1216
- package/dist/parser/Parser.spec.js.map +0 -1
- package/dist/parser/SGParser.spec.d.ts +0 -1
- package/dist/parser/SGParser.spec.js +0 -145
- package/dist/parser/SGParser.spec.js.map +0 -1
- package/dist/parser/SGTypes.spec.d.ts +0 -1
- package/dist/parser/SGTypes.spec.js +0 -351
- package/dist/parser/SGTypes.spec.js.map +0 -1
- package/dist/parser/Statement.spec.d.ts +0 -1
- package/dist/parser/Statement.spec.js +0 -94
- package/dist/parser/Statement.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/parser/tests/Parser.spec.d.ts +0 -18
- package/dist/parser/tests/Parser.spec.js +0 -35
- package/dist/parser/tests/Parser.spec.js.map +0 -1
- package/dist/parser/tests/controlFlow/For.spec.d.ts +0 -1
- package/dist/parser/tests/controlFlow/For.spec.js +0 -161
- package/dist/parser/tests/controlFlow/For.spec.js.map +0 -1
- package/dist/parser/tests/controlFlow/ForEach.spec.d.ts +0 -1
- package/dist/parser/tests/controlFlow/ForEach.spec.js +0 -106
- package/dist/parser/tests/controlFlow/ForEach.spec.js.map +0 -1
- package/dist/parser/tests/controlFlow/If.spec.d.ts +0 -1
- package/dist/parser/tests/controlFlow/If.spec.js +0 -551
- package/dist/parser/tests/controlFlow/If.spec.js.map +0 -1
- package/dist/parser/tests/controlFlow/While.spec.d.ts +0 -1
- package/dist/parser/tests/controlFlow/While.spec.js +0 -107
- package/dist/parser/tests/controlFlow/While.spec.js.map +0 -1
- package/dist/parser/tests/expression/Additive.spec.d.ts +0 -1
- package/dist/parser/tests/expression/Additive.spec.js +0 -99
- package/dist/parser/tests/expression/Additive.spec.js.map +0 -1
- package/dist/parser/tests/expression/ArrayLiterals.spec.d.ts +0 -1
- package/dist/parser/tests/expression/ArrayLiterals.spec.js +0 -254
- package/dist/parser/tests/expression/ArrayLiterals.spec.js.map +0 -1
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.d.ts +0 -1
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +0 -266
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +0 -1
- package/dist/parser/tests/expression/Boolean.spec.d.ts +0 -1
- package/dist/parser/tests/expression/Boolean.spec.js +0 -83
- package/dist/parser/tests/expression/Boolean.spec.js.map +0 -1
- package/dist/parser/tests/expression/Call.spec.d.ts +0 -1
- package/dist/parser/tests/expression/Call.spec.js +0 -134
- package/dist/parser/tests/expression/Call.spec.js.map +0 -1
- package/dist/parser/tests/expression/Exponential.spec.d.ts +0 -1
- package/dist/parser/tests/expression/Exponential.spec.js +0 -37
- package/dist/parser/tests/expression/Exponential.spec.js.map +0 -1
- package/dist/parser/tests/expression/Function.spec.d.ts +0 -1
- package/dist/parser/tests/expression/Function.spec.js +0 -403
- package/dist/parser/tests/expression/Function.spec.js.map +0 -1
- package/dist/parser/tests/expression/Indexing.spec.d.ts +0 -1
- package/dist/parser/tests/expression/Indexing.spec.js +0 -219
- package/dist/parser/tests/expression/Indexing.spec.js.map +0 -1
- package/dist/parser/tests/expression/Multiplicative.spec.d.ts +0 -1
- package/dist/parser/tests/expression/Multiplicative.spec.js +0 -67
- package/dist/parser/tests/expression/Multiplicative.spec.js.map +0 -1
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.d.ts +0 -1
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +0 -201
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +0 -1
- package/dist/parser/tests/expression/PrefixUnary.spec.d.ts +0 -1
- package/dist/parser/tests/expression/PrefixUnary.spec.js +0 -105
- package/dist/parser/tests/expression/PrefixUnary.spec.js.map +0 -1
- package/dist/parser/tests/expression/Primary.spec.d.ts +0 -1
- package/dist/parser/tests/expression/Primary.spec.js +0 -149
- package/dist/parser/tests/expression/Primary.spec.js.map +0 -1
- package/dist/parser/tests/expression/Relational.spec.d.ts +0 -1
- package/dist/parser/tests/expression/Relational.spec.js +0 -83
- package/dist/parser/tests/expression/Relational.spec.js.map +0 -1
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.d.ts +0 -1
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.js +0 -201
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.js.map +0 -1
- package/dist/parser/tests/expression/TemplateStringExpression.spec.d.ts +0 -1
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js +0 -202
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +0 -1
- package/dist/parser/tests/expression/TernaryExpression.spec.d.ts +0 -1
- package/dist/parser/tests/expression/TernaryExpression.spec.js +0 -323
- package/dist/parser/tests/expression/TernaryExpression.spec.js.map +0 -1
- package/dist/parser/tests/statement/AssignmentOperators.spec.d.ts +0 -1
- package/dist/parser/tests/statement/AssignmentOperators.spec.js +0 -79
- package/dist/parser/tests/statement/AssignmentOperators.spec.js.map +0 -1
- package/dist/parser/tests/statement/Declaration.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Declaration.spec.js +0 -108
- package/dist/parser/tests/statement/Declaration.spec.js.map +0 -1
- package/dist/parser/tests/statement/Dim.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Dim.spec.js +0 -73
- package/dist/parser/tests/statement/Dim.spec.js.map +0 -1
- package/dist/parser/tests/statement/Function.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Function.spec.js +0 -332
- package/dist/parser/tests/statement/Function.spec.js.map +0 -1
- package/dist/parser/tests/statement/Goto.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Goto.spec.js +0 -50
- package/dist/parser/tests/statement/Goto.spec.js.map +0 -1
- package/dist/parser/tests/statement/Increment.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Increment.spec.js +0 -117
- package/dist/parser/tests/statement/Increment.spec.js.map +0 -1
- package/dist/parser/tests/statement/LibraryStatement.spec.d.ts +0 -1
- package/dist/parser/tests/statement/LibraryStatement.spec.js +0 -74
- package/dist/parser/tests/statement/LibraryStatement.spec.js.map +0 -1
- package/dist/parser/tests/statement/Misc.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Misc.spec.js +0 -333
- package/dist/parser/tests/statement/Misc.spec.js.map +0 -1
- package/dist/parser/tests/statement/PrintStatement.spec.d.ts +0 -1
- package/dist/parser/tests/statement/PrintStatement.spec.js +0 -181
- package/dist/parser/tests/statement/PrintStatement.spec.js.map +0 -1
- package/dist/parser/tests/statement/ReturnStatement.spec.d.ts +0 -1
- package/dist/parser/tests/statement/ReturnStatement.spec.js +0 -94
- package/dist/parser/tests/statement/ReturnStatement.spec.js.map +0 -1
- package/dist/parser/tests/statement/Set.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Set.spec.js +0 -218
- package/dist/parser/tests/statement/Set.spec.js.map +0 -1
- package/dist/parser/tests/statement/Stop.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Stop.spec.js +0 -37
- package/dist/parser/tests/statement/Stop.spec.js.map +0 -1
- package/dist/parser/tests/statement/Throw.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Throw.spec.js +0 -35
- package/dist/parser/tests/statement/Throw.spec.js.map +0 -1
- package/dist/parser/tests/statement/TryCatch.spec.d.ts +0 -1
- package/dist/parser/tests/statement/TryCatch.spec.js +0 -140
- package/dist/parser/tests/statement/TryCatch.spec.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/Manifest.spec.d.ts +0 -0
- package/dist/preprocessor/Manifest.spec.js +0 -105
- package/dist/preprocessor/Manifest.spec.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.d.ts +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.d.ts +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/ArrayType.spec.d.ts +0 -1
- package/dist/types/ArrayType.spec.js +0 -30
- package/dist/types/ArrayType.spec.js.map +0 -1
- package/dist/types/BooleanType.spec.d.ts +0 -1
- package/dist/types/BooleanType.spec.js +0 -12
- package/dist/types/BooleanType.spec.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/DoubleType.spec.d.ts +0 -1
- package/dist/types/DoubleType.spec.js +0 -12
- package/dist/types/DoubleType.spec.js.map +0 -1
- package/dist/types/DynamicType.spec.d.ts +0 -1
- package/dist/types/DynamicType.spec.js +0 -12
- package/dist/types/DynamicType.spec.js.map +0 -1
- package/dist/types/FloatType.spec.d.ts +0 -1
- package/dist/types/FloatType.spec.js +0 -12
- package/dist/types/FloatType.spec.js.map +0 -1
- package/dist/types/FunctionType.spec.d.ts +0 -1
- package/dist/types/FunctionType.spec.js +0 -29
- package/dist/types/FunctionType.spec.js.map +0 -1
- package/dist/types/IntegerType.spec.d.ts +0 -1
- package/dist/types/IntegerType.spec.js +0 -12
- package/dist/types/IntegerType.spec.js.map +0 -1
- package/dist/types/InvalidType.spec.d.ts +0 -1
- package/dist/types/InvalidType.spec.js +0 -12
- package/dist/types/InvalidType.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/types/LongIntegerType.spec.d.ts +0 -1
- package/dist/types/LongIntegerType.spec.js +0 -12
- package/dist/types/LongIntegerType.spec.js.map +0 -1
- package/dist/types/ObjectType.spec.d.ts +0 -1
- package/dist/types/ObjectType.spec.js +0 -12
- package/dist/types/ObjectType.spec.js.map +0 -1
- package/dist/types/StringType.spec.d.ts +0 -1
- package/dist/types/StringType.spec.js +0 -12
- package/dist/types/StringType.spec.js.map +0 -1
- package/dist/types/VoidType.spec.d.ts +0 -1
- package/dist/types/VoidType.spec.js +0 -12
- package/dist/types/VoidType.spec.js.map +0 -1
- /package/dist/{astUtils/creators.spec.d.ts → lsp/worker/run.d.ts} +0 -0
|
@@ -1,1216 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.failStatementType = exports.rangeToArray = void 0;
|
|
4
|
-
const chai_1 = require("chai");
|
|
5
|
-
const lexer_1 = require("../lexer");
|
|
6
|
-
const Expression_1 = require("./Expression");
|
|
7
|
-
const Parser_1 = require("./Parser");
|
|
8
|
-
const Statement_1 = require("./Statement");
|
|
9
|
-
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
10
|
-
const DiagnosticMessages_1 = require("../DiagnosticMessages");
|
|
11
|
-
const reflection_1 = require("../astUtils/reflection");
|
|
12
|
-
const testHelpers_spec_1 = require("../testHelpers.spec");
|
|
13
|
-
const VoidType_1 = require("../types/VoidType");
|
|
14
|
-
const FunctionType_1 = require("../types/FunctionType");
|
|
15
|
-
const StringType_1 = require("../types/StringType");
|
|
16
|
-
const CustomType_1 = require("../types/CustomType");
|
|
17
|
-
const IntegerType_1 = require("../types/IntegerType");
|
|
18
|
-
const ObjectType_1 = require("../types/ObjectType");
|
|
19
|
-
const LazyType_1 = require("../types/LazyType");
|
|
20
|
-
const SymbolTable_1 = require("../SymbolTable");
|
|
21
|
-
const DynamicType_1 = require("../types/DynamicType");
|
|
22
|
-
const util_1 = require("../util");
|
|
23
|
-
describe('parser', () => {
|
|
24
|
-
it('emits empty object when empty token list is provided', () => {
|
|
25
|
-
chai_1.expect(Parser_1.Parser.parse([])).to.deep.include({
|
|
26
|
-
statements: [],
|
|
27
|
-
diagnostics: []
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
describe('findReferences', () => {
|
|
31
|
-
it('recomputes localVars', () => {
|
|
32
|
-
const parser = Parser_1.Parser.parse(`
|
|
33
|
-
sub main(herd)
|
|
34
|
-
for each zombie in herd
|
|
35
|
-
isAlive = false
|
|
36
|
-
end for
|
|
37
|
-
for i = 0 to 10 step 1
|
|
38
|
-
j = i
|
|
39
|
-
end for
|
|
40
|
-
humansAreAlive = false
|
|
41
|
-
end sub
|
|
42
|
-
`);
|
|
43
|
-
chai_1.expect(parser.references.functionExpressions[0].symbolTable.ownSymbols.map(x => x.name).sort()).to.eql([
|
|
44
|
-
'herd',
|
|
45
|
-
'humansAreAlive',
|
|
46
|
-
'i',
|
|
47
|
-
'isAlive',
|
|
48
|
-
'j',
|
|
49
|
-
'zombie'
|
|
50
|
-
]);
|
|
51
|
-
parser.invalidateReferences();
|
|
52
|
-
chai_1.expect(parser.references.functionExpressions[0].symbolTable.ownSymbols.map(x => x.name).sort()).to.eql([
|
|
53
|
-
'herd',
|
|
54
|
-
'humansAreAlive',
|
|
55
|
-
'i',
|
|
56
|
-
'isAlive',
|
|
57
|
-
'j',
|
|
58
|
-
'zombie'
|
|
59
|
-
]);
|
|
60
|
-
});
|
|
61
|
-
it('assigns localVars to correct function expression bucket', () => {
|
|
62
|
-
const parser = Parser_1.Parser.parse(`
|
|
63
|
-
sub main()
|
|
64
|
-
outerName = "bob"
|
|
65
|
-
speak = sub()
|
|
66
|
-
innerName = "innerBob"
|
|
67
|
-
end sub
|
|
68
|
-
age = 12
|
|
69
|
-
end sub
|
|
70
|
-
`);
|
|
71
|
-
parser.invalidateReferences();
|
|
72
|
-
chai_1.expect(parser.references.functionExpressions[0].symbolTable.ownSymbols.map(x => x.name)).to.eql([
|
|
73
|
-
'outerName',
|
|
74
|
-
'speak',
|
|
75
|
-
'age'
|
|
76
|
-
]);
|
|
77
|
-
chai_1.expect(parser.references.functionExpressions[1].symbolTable.ownSymbols.map(x => x.name)).to.eql([
|
|
78
|
-
'innerName'
|
|
79
|
-
]);
|
|
80
|
-
});
|
|
81
|
-
it('gets called if references are missing', () => {
|
|
82
|
-
const parser = Parser_1.Parser.parse(`
|
|
83
|
-
sub main()
|
|
84
|
-
end sub
|
|
85
|
-
|
|
86
|
-
sub UnusedFunction()
|
|
87
|
-
end sub
|
|
88
|
-
`);
|
|
89
|
-
chai_1.expect(parser.references.functionStatements.map(x => x.name.text)).to.eql([
|
|
90
|
-
'main',
|
|
91
|
-
'UnusedFunction'
|
|
92
|
-
]);
|
|
93
|
-
//simulate a tree-shaking plugin by removing the `UnusedFunction`
|
|
94
|
-
parser.ast.statements.splice(1);
|
|
95
|
-
//tell the parser we modified the AST and need to regenerate references
|
|
96
|
-
parser.invalidateReferences();
|
|
97
|
-
chai_1.expect(parser['_references']).not.to.exist;
|
|
98
|
-
//calling `references` automatically regenerates the references
|
|
99
|
-
chai_1.expect(parser.references.functionStatements.map(x => x.name.text)).to.eql([
|
|
100
|
-
'main'
|
|
101
|
-
]);
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
describe('callfunc operator', () => {
|
|
105
|
-
it('is not allowed in brightscript mode', () => {
|
|
106
|
-
var _a;
|
|
107
|
-
let parser = parse(`
|
|
108
|
-
sub main(node as dynamic)
|
|
109
|
-
node@.doSomething(1, 2)
|
|
110
|
-
end sub
|
|
111
|
-
`, Parser_1.ParseMode.BrightScript);
|
|
112
|
-
chai_1.expect((_a = parser.diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.bsFeatureNotSupportedInBrsFiles('callfunc operator').message);
|
|
113
|
-
});
|
|
114
|
-
it('does not cause parse errors', () => {
|
|
115
|
-
var _a, _b, _c, _d, _e;
|
|
116
|
-
let parser = parse(`
|
|
117
|
-
sub main(node as dynamic)
|
|
118
|
-
node@.doSomething(1, 2)
|
|
119
|
-
end sub
|
|
120
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
121
|
-
chai_1.expect((_a = parser.diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
122
|
-
chai_1.expect((_e = (_d = (_c = (_b = parser.statements[0]) === null || _b === void 0 ? void 0 : _b.func) === null || _c === void 0 ? void 0 : _c.body) === null || _d === void 0 ? void 0 : _d.statements[0]) === null || _e === void 0 ? void 0 : _e.expression).to.be.instanceof(Expression_1.CallfuncExpression);
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
describe('diagnostic locations', () => {
|
|
126
|
-
it('tracks basic diagnostic locations', () => {
|
|
127
|
-
chai_1.expect(parse(`
|
|
128
|
-
sub main()
|
|
129
|
-
call()a
|
|
130
|
-
end sub
|
|
131
|
-
`).diagnostics.map(x => rangeToArray(x.range))).to.eql([
|
|
132
|
-
[2, 26, 2, 27],
|
|
133
|
-
[2, 27, 2, 28]
|
|
134
|
-
]);
|
|
135
|
-
});
|
|
136
|
-
it.skip('handles edge cases', () => {
|
|
137
|
-
var _a, _b;
|
|
138
|
-
let diagnostics = parse(`
|
|
139
|
-
function BuildCommit()
|
|
140
|
-
return "6c5cdf1"
|
|
141
|
-
end functionasdf
|
|
142
|
-
`).diagnostics;
|
|
143
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.exist.and.to.eql(DiagnosticMessages_1.DiagnosticMessages.expectedStatementOrFunctionCallButReceivedExpression().message);
|
|
144
|
-
chai_1.expect((_b = diagnostics[0]) === null || _b === void 0 ? void 0 : _b.range).to.eql(vscode_languageserver_1.Range.create(3, 20, 3, 32));
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
describe('parse', () => {
|
|
148
|
-
it('supports ungrouped iife in assignment', () => {
|
|
149
|
-
const parser = parse(`
|
|
150
|
-
sub main()
|
|
151
|
-
result = sub()
|
|
152
|
-
end sub()
|
|
153
|
-
result = function()
|
|
154
|
-
end function()
|
|
155
|
-
end sub
|
|
156
|
-
`);
|
|
157
|
-
testHelpers_spec_1.expectZeroDiagnostics(parser);
|
|
158
|
-
});
|
|
159
|
-
it('supports grouped iife in assignment', () => {
|
|
160
|
-
const parser = parse(`
|
|
161
|
-
sub main()
|
|
162
|
-
result = (sub()
|
|
163
|
-
end sub)()
|
|
164
|
-
result = (function()
|
|
165
|
-
end function)()
|
|
166
|
-
end sub
|
|
167
|
-
`);
|
|
168
|
-
testHelpers_spec_1.expectZeroDiagnostics(parser);
|
|
169
|
-
});
|
|
170
|
-
it('supports returning iife call', () => {
|
|
171
|
-
const parser = parse(`
|
|
172
|
-
sub main()
|
|
173
|
-
return (sub()
|
|
174
|
-
end sub)()
|
|
175
|
-
end sub
|
|
176
|
-
`);
|
|
177
|
-
testHelpers_spec_1.expectZeroDiagnostics(parser);
|
|
178
|
-
});
|
|
179
|
-
it('supports using "interface" as parameter name', () => {
|
|
180
|
-
var _a;
|
|
181
|
-
chai_1.expect((_a = parse(`
|
|
182
|
-
sub main(interface as object)
|
|
183
|
-
end sub
|
|
184
|
-
`, Parser_1.ParseMode.BrighterScript).diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
185
|
-
});
|
|
186
|
-
describe('namespace', () => {
|
|
187
|
-
it('catches namespaces declared not at root level', () => {
|
|
188
|
-
var _a;
|
|
189
|
-
chai_1.expect((_a = parse(`
|
|
190
|
-
sub main()
|
|
191
|
-
namespace Name.Space
|
|
192
|
-
end namespace
|
|
193
|
-
end sub
|
|
194
|
-
`, Parser_1.ParseMode.BrighterScript).diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.keywordMustBeDeclaredAtRootLevel('namespace').message);
|
|
195
|
-
});
|
|
196
|
-
it('parses empty namespace', () => {
|
|
197
|
-
var _a;
|
|
198
|
-
let { statements, diagnostics } = parse(`
|
|
199
|
-
namespace Name.Space
|
|
200
|
-
end namespace
|
|
201
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
202
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
203
|
-
chai_1.expect(statements[0]).to.be.instanceof(Statement_1.NamespaceStatement);
|
|
204
|
-
});
|
|
205
|
-
it('includes body', () => {
|
|
206
|
-
var _a;
|
|
207
|
-
let { statements, diagnostics } = parse(`
|
|
208
|
-
namespace Name.Space
|
|
209
|
-
sub main()
|
|
210
|
-
end sub
|
|
211
|
-
end namespace
|
|
212
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
213
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
214
|
-
chai_1.expect(statements[0]).to.be.instanceof(Statement_1.NamespaceStatement);
|
|
215
|
-
chai_1.expect(statements[0].body.statements[0]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
216
|
-
});
|
|
217
|
-
it('supports comments and newlines', () => {
|
|
218
|
-
var _a;
|
|
219
|
-
let { diagnostics } = parse(`
|
|
220
|
-
namespace Name.Space 'comment
|
|
221
|
-
|
|
222
|
-
'comment
|
|
223
|
-
|
|
224
|
-
sub main() 'comment
|
|
225
|
-
end sub 'comment
|
|
226
|
-
'comment
|
|
227
|
-
|
|
228
|
-
'comment
|
|
229
|
-
end namespace 'comment
|
|
230
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
231
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
232
|
-
});
|
|
233
|
-
it('catches missing name', () => {
|
|
234
|
-
var _a;
|
|
235
|
-
let { diagnostics } = parse(`
|
|
236
|
-
namespace
|
|
237
|
-
end namespace
|
|
238
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
239
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.expectedIdentifierAfterKeyword('namespace').message);
|
|
240
|
-
});
|
|
241
|
-
it('recovers after missing `end namespace`', () => {
|
|
242
|
-
var _a, _b, _c;
|
|
243
|
-
let parser = parse(`
|
|
244
|
-
namespace Name.Space
|
|
245
|
-
sub main()
|
|
246
|
-
end sub
|
|
247
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
248
|
-
chai_1.expect(parser.ast.statements[0]).to.be.instanceof(Statement_1.NamespaceStatement);
|
|
249
|
-
chai_1.expect((_a = parser.diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.couldNotFindMatchingEndKeyword('namespace').message);
|
|
250
|
-
chai_1.expect((_c = (_b = parser.ast.statements[0]) === null || _b === void 0 ? void 0 : _b.body) === null || _c === void 0 ? void 0 : _c.statements[0]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
251
|
-
});
|
|
252
|
-
it('adds diagnostic when encountering namespace in brightscript mode', () => {
|
|
253
|
-
var _a;
|
|
254
|
-
let parser = Parser_1.Parser.parse(`
|
|
255
|
-
namespace Name.Space
|
|
256
|
-
end namespace
|
|
257
|
-
`);
|
|
258
|
-
chai_1.expect((_a = parser.diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.bsFeatureNotSupportedInBrsFiles('namespace').message);
|
|
259
|
-
});
|
|
260
|
-
it('declares a symbol table for the namespace', () => {
|
|
261
|
-
let parser = parse(`
|
|
262
|
-
namespace Name.Space
|
|
263
|
-
function funcInt() as integer
|
|
264
|
-
return 3
|
|
265
|
-
end function
|
|
266
|
-
|
|
267
|
-
function funcStr() as string
|
|
268
|
-
return "hello"
|
|
269
|
-
end function
|
|
270
|
-
end namespace
|
|
271
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
272
|
-
chai_1.expect(parser.ast.statements[0]).to.be.instanceof(Statement_1.NamespaceStatement);
|
|
273
|
-
const namespaceStmt = parser.ast.statements[0];
|
|
274
|
-
chai_1.expect(namespaceStmt.symbolTable).to.be.instanceof(SymbolTable_1.SymbolTable);
|
|
275
|
-
chai_1.expect(namespaceStmt.symbolTable.getSymbolType('funcInt').toString()).to.equal('function funcInt() as integer');
|
|
276
|
-
chai_1.expect(namespaceStmt.symbolTable.getSymbolType('funcStr')).to.be.instanceof(FunctionType_1.FunctionType);
|
|
277
|
-
const strFunctionType = namespaceStmt.symbolTable.getSymbolType('funcStr');
|
|
278
|
-
chai_1.expect(strFunctionType.returnType.toString()).to.equal('string');
|
|
279
|
-
});
|
|
280
|
-
it('adds a fully qualified name of a function in a namespace to the parsers symbol table', () => {
|
|
281
|
-
let parser = parse(`
|
|
282
|
-
namespace Name.Space
|
|
283
|
-
function funcInt() as integer
|
|
284
|
-
return 3
|
|
285
|
-
end function
|
|
286
|
-
|
|
287
|
-
function funcStr() as string
|
|
288
|
-
return "hello"
|
|
289
|
-
end function
|
|
290
|
-
end namespace
|
|
291
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
292
|
-
chai_1.expect(parser.symbolTable.getSymbolType('Name.Space.funcInt')).to.be.instanceof(FunctionType_1.FunctionType);
|
|
293
|
-
chai_1.expect(parser.symbolTable.getSymbolType('Name.Space.funcStr')).to.be.instanceof(FunctionType_1.FunctionType);
|
|
294
|
-
});
|
|
295
|
-
});
|
|
296
|
-
it('supports << operator', () => {
|
|
297
|
-
var _a;
|
|
298
|
-
chai_1.expect((_a = parse(`
|
|
299
|
-
sub main()
|
|
300
|
-
print ((r << 24) + (g << 16) + (b << 8) + a)
|
|
301
|
-
end sub
|
|
302
|
-
`).diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
303
|
-
});
|
|
304
|
-
it('supports >> operator', () => {
|
|
305
|
-
var _a;
|
|
306
|
-
chai_1.expect((_a = parse(`
|
|
307
|
-
sub main()
|
|
308
|
-
print ((r >> 24) + (g >> 16) + (b >> 8) + a)
|
|
309
|
-
end sub
|
|
310
|
-
`).diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
311
|
-
});
|
|
312
|
-
it('allows global function names with same as token to be called', () => {
|
|
313
|
-
var _a;
|
|
314
|
-
chai_1.expect((_a = parse(`
|
|
315
|
-
sub main()
|
|
316
|
-
print string(123)
|
|
317
|
-
end sub
|
|
318
|
-
`).diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
319
|
-
});
|
|
320
|
-
it('supports @ symbol between names', () => {
|
|
321
|
-
var _a;
|
|
322
|
-
let parser = parse(`
|
|
323
|
-
sub main()
|
|
324
|
-
firstName = personXml@firstName
|
|
325
|
-
age = personXml.firstChild@age
|
|
326
|
-
end sub
|
|
327
|
-
`);
|
|
328
|
-
chai_1.expect((_a = parser.diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.not.exist;
|
|
329
|
-
let statements = parser.statements[0].func.body.statements;
|
|
330
|
-
let first = statements[0].value;
|
|
331
|
-
chai_1.expect(first).to.be.instanceof(Expression_1.XmlAttributeGetExpression);
|
|
332
|
-
chai_1.expect(first.name.text).to.equal('firstName');
|
|
333
|
-
chai_1.expect(first.at.text).to.equal('@');
|
|
334
|
-
chai_1.expect(first.obj.name.text).to.equal('personXml');
|
|
335
|
-
let second = statements[1].value;
|
|
336
|
-
chai_1.expect(second).to.be.instanceof(Expression_1.XmlAttributeGetExpression);
|
|
337
|
-
chai_1.expect(second.name.text).to.equal('age');
|
|
338
|
-
chai_1.expect(second.at.text).to.equal('@');
|
|
339
|
-
chai_1.expect(second.obj.name.text).to.equal('firstChild');
|
|
340
|
-
});
|
|
341
|
-
it('does not allow chaining of @ symbols', () => {
|
|
342
|
-
let parser = parse(`
|
|
343
|
-
sub main()
|
|
344
|
-
personXml = invalid
|
|
345
|
-
name = personXml@name@age@shoeSize
|
|
346
|
-
end sub
|
|
347
|
-
`);
|
|
348
|
-
chai_1.expect(parser.diagnostics).not.to.be.empty;
|
|
349
|
-
});
|
|
350
|
-
it('unknown function type does not invalidate rest of function', () => {
|
|
351
|
-
let { statements, diagnostics } = parse(`
|
|
352
|
-
function log() as UNKNOWN_TYPE
|
|
353
|
-
end function
|
|
354
|
-
`, Parser_1.ParseMode.BrightScript);
|
|
355
|
-
chai_1.expect(diagnostics.length).to.be.greaterThan(0);
|
|
356
|
-
chai_1.expect(statements[0]).to.exist;
|
|
357
|
-
});
|
|
358
|
-
it('unknown function type is not a problem in Brighterscript mode', () => {
|
|
359
|
-
let { statements, diagnostics } = parse(`
|
|
360
|
-
function log() as UNKNOWN_TYPE
|
|
361
|
-
end function
|
|
362
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
363
|
-
chai_1.expect(diagnostics.length).to.equal(0);
|
|
364
|
-
chai_1.expect(statements[0]).to.exist;
|
|
365
|
-
});
|
|
366
|
-
it('allows namespaced function type in Brighterscript mode', () => {
|
|
367
|
-
let { statements, diagnostics } = parse(`
|
|
368
|
-
function log() as SOME_NAMESPACE.UNKNOWN_TYPE
|
|
369
|
-
end function
|
|
370
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
371
|
-
chai_1.expect(diagnostics.length).to.equal(0);
|
|
372
|
-
chai_1.expect(statements[0]).to.exist;
|
|
373
|
-
});
|
|
374
|
-
it('allows custom parameter types in BrighterscriptMode', () => {
|
|
375
|
-
let { statements, diagnostics } = parse(`
|
|
376
|
-
sub foo(value as UNKNOWN_TYPE)
|
|
377
|
-
end sub
|
|
378
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
379
|
-
chai_1.expect(diagnostics.length).to.equal(0);
|
|
380
|
-
chai_1.expect(statements[0]).to.exist;
|
|
381
|
-
});
|
|
382
|
-
it('does not allow custom parameter types in Brightscript Mode', () => {
|
|
383
|
-
let { diagnostics } = parse(`
|
|
384
|
-
sub foo(value as UNKNOWN_TYPE)
|
|
385
|
-
end sub
|
|
386
|
-
`, Parser_1.ParseMode.BrightScript);
|
|
387
|
-
chai_1.expect(diagnostics.length).not.to.equal(0);
|
|
388
|
-
});
|
|
389
|
-
it('allows custom namespaced parameter types in BrighterscriptMode', () => {
|
|
390
|
-
let { statements, diagnostics } = parse(`
|
|
391
|
-
sub foo(value as SOME_NAMESPACE.UNKNOWN_TYPE)
|
|
392
|
-
end sub
|
|
393
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
394
|
-
chai_1.expect(diagnostics.length).to.equal(0);
|
|
395
|
-
chai_1.expect(statements[0]).to.exist;
|
|
396
|
-
});
|
|
397
|
-
it('works with conditionals', () => {
|
|
398
|
-
var _a;
|
|
399
|
-
chai_1.expect((_a = parse(`
|
|
400
|
-
function printNumber()
|
|
401
|
-
if true then
|
|
402
|
-
print 1
|
|
403
|
-
else if true
|
|
404
|
-
return false
|
|
405
|
-
end if
|
|
406
|
-
end function
|
|
407
|
-
`).diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
408
|
-
});
|
|
409
|
-
it('supports single-line if statements', () => {
|
|
410
|
-
var _a;
|
|
411
|
-
chai_1.expect((_a = parse(`If true Then print "error" : Stop`).diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.not.exist;
|
|
412
|
-
});
|
|
413
|
-
it('works with excess newlines', () => {
|
|
414
|
-
var _a;
|
|
415
|
-
let { tokens } = lexer_1.Lexer.scan('function boolToNumber() as string\n\n' +
|
|
416
|
-
' if true then\n\n' +
|
|
417
|
-
' print 1\n\n' +
|
|
418
|
-
' elseif true then\n\n' +
|
|
419
|
-
' print 0\n\n' +
|
|
420
|
-
' else\n\n' +
|
|
421
|
-
' print 1\n\n' +
|
|
422
|
-
' end if\n\n' +
|
|
423
|
-
'end function\n\n');
|
|
424
|
-
chai_1.expect((_a = Parser_1.Parser.parse(tokens).diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.not.exist;
|
|
425
|
-
});
|
|
426
|
-
it('does not invalidate entire file when line ends with a period', () => {
|
|
427
|
-
let { tokens } = lexer_1.Lexer.scan(`
|
|
428
|
-
sub main()
|
|
429
|
-
person.a
|
|
430
|
-
end sub
|
|
431
|
-
|
|
432
|
-
`);
|
|
433
|
-
let { diagnostics } = Parser_1.Parser.parse(tokens);
|
|
434
|
-
chai_1.expect(diagnostics).to.be.lengthOf(1, 'Error count should be 0');
|
|
435
|
-
});
|
|
436
|
-
it.skip('allows printing object with trailing period', () => {
|
|
437
|
-
let { tokens } = lexer_1.Lexer.scan(`print a.`);
|
|
438
|
-
let { statements, diagnostics } = Parser_1.Parser.parse(tokens);
|
|
439
|
-
let printStatement = statements[0];
|
|
440
|
-
chai_1.expect(diagnostics).to.be.empty;
|
|
441
|
-
chai_1.expect(printStatement).to.be.instanceof(Statement_1.PrintStatement);
|
|
442
|
-
chai_1.expect(printStatement.expressions[0]).to.be.instanceof(Expression_1.DottedGetExpression);
|
|
443
|
-
});
|
|
444
|
-
describe('comments', () => {
|
|
445
|
-
it('combines multi-line comments', () => {
|
|
446
|
-
let { tokens } = lexer_1.Lexer.scan(`
|
|
447
|
-
'line 1
|
|
448
|
-
'line 2
|
|
449
|
-
'line 3
|
|
450
|
-
`);
|
|
451
|
-
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
452
|
-
chai_1.expect(diagnostics).to.be.lengthOf(0, 'Error count should be 0');
|
|
453
|
-
chai_1.expect(statements[0].text).to.equal(`'line 1\n'line 2\n'line 3`);
|
|
454
|
-
});
|
|
455
|
-
it('does not combile comments separated by newlines', () => {
|
|
456
|
-
let { tokens } = lexer_1.Lexer.scan(`
|
|
457
|
-
'line 1
|
|
458
|
-
|
|
459
|
-
'line 2
|
|
460
|
-
|
|
461
|
-
'line 3
|
|
462
|
-
`);
|
|
463
|
-
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
464
|
-
chai_1.expect(diagnostics).to.be.lengthOf(0, 'Error count should be 0');
|
|
465
|
-
chai_1.expect(statements).to.be.lengthOf(3);
|
|
466
|
-
chai_1.expect(statements[0].text).to.equal(`'line 1`);
|
|
467
|
-
chai_1.expect(statements[1].text).to.equal(`'line 2`);
|
|
468
|
-
chai_1.expect(statements[2].text).to.equal(`'line 3`);
|
|
469
|
-
});
|
|
470
|
-
it('works after print statement', () => {
|
|
471
|
-
let { tokens } = lexer_1.Lexer.scan(`
|
|
472
|
-
sub main()
|
|
473
|
-
print "hi" 'comment 1
|
|
474
|
-
end sub
|
|
475
|
-
`);
|
|
476
|
-
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
477
|
-
chai_1.expect(diagnostics).to.be.lengthOf(0, 'Error count should be 0');
|
|
478
|
-
chai_1.expect(statements[0].func.body.statements[1].text).to.equal(`'comment 1`);
|
|
479
|
-
});
|
|
480
|
-
it('declaration-level', () => {
|
|
481
|
-
let { tokens } = lexer_1.Lexer.scan(`
|
|
482
|
-
'comment 1
|
|
483
|
-
function a()
|
|
484
|
-
end function
|
|
485
|
-
'comment 2
|
|
486
|
-
`);
|
|
487
|
-
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
488
|
-
chai_1.expect(diagnostics).to.be.lengthOf(0, 'Error count should be 0');
|
|
489
|
-
chai_1.expect(statements[0].text).to.equal(`'comment 1`);
|
|
490
|
-
chai_1.expect(statements[2].text).to.equal(`'comment 2`);
|
|
491
|
-
});
|
|
492
|
-
it('works in aa literal as its own statement', () => {
|
|
493
|
-
let { tokens } = lexer_1.Lexer.scan(`
|
|
494
|
-
obj = {
|
|
495
|
-
"name": true,
|
|
496
|
-
'comment
|
|
497
|
-
}
|
|
498
|
-
`);
|
|
499
|
-
let { diagnostics } = Parser_1.Parser.parse(tokens);
|
|
500
|
-
chai_1.expect(diagnostics).to.be.lengthOf(0, 'Error count should be 0');
|
|
501
|
-
});
|
|
502
|
-
it('parses after function call', () => {
|
|
503
|
-
let { tokens } = lexer_1.Lexer.scan(`
|
|
504
|
-
sub Main()
|
|
505
|
-
name = "Hello"
|
|
506
|
-
DoSomething(name) 'comment 1
|
|
507
|
-
end sub
|
|
508
|
-
`);
|
|
509
|
-
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
510
|
-
chai_1.expect(diagnostics).to.be.lengthOf(0, 'Should have zero diagnostics');
|
|
511
|
-
chai_1.expect(statements[0].func.body.statements[2].text).to.equal(`'comment 1`);
|
|
512
|
-
});
|
|
513
|
-
it('function', () => {
|
|
514
|
-
let { tokens } = lexer_1.Lexer.scan(`
|
|
515
|
-
function a() 'comment 1
|
|
516
|
-
'comment 2
|
|
517
|
-
num = 1
|
|
518
|
-
'comment 3
|
|
519
|
-
end function 'comment 4
|
|
520
|
-
`);
|
|
521
|
-
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
522
|
-
chai_1.expect(diagnostics).to.be.lengthOf(0, 'Should have zero diagnostics');
|
|
523
|
-
chai_1.expect(statements[0].func.body.statements[0].text).to.equal(`'comment 1`);
|
|
524
|
-
chai_1.expect(statements[0].func.body.statements[1].text).to.equal(`'comment 2`);
|
|
525
|
-
chai_1.expect(statements[0].func.body.statements[3].text).to.equal(`'comment 3`);
|
|
526
|
-
chai_1.expect(statements[1].text).to.equal(`'comment 4`);
|
|
527
|
-
});
|
|
528
|
-
it('if statement`', () => {
|
|
529
|
-
let { tokens } = lexer_1.Lexer.scan(`
|
|
530
|
-
function a()
|
|
531
|
-
if true then 'comment 1
|
|
532
|
-
'comment 2
|
|
533
|
-
print "hello"
|
|
534
|
-
'comment 3
|
|
535
|
-
else if true then 'comment 4
|
|
536
|
-
'comment 5
|
|
537
|
-
print "hello"
|
|
538
|
-
'comment 6
|
|
539
|
-
else 'comment 7
|
|
540
|
-
'comment 8
|
|
541
|
-
print "hello"
|
|
542
|
-
'comment 9
|
|
543
|
-
end if 'comment 10
|
|
544
|
-
end function
|
|
545
|
-
`);
|
|
546
|
-
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
547
|
-
chai_1.expect(diagnostics).to.be.lengthOf(0, 'Should have zero diagnostics');
|
|
548
|
-
let fnSmt = statements[0];
|
|
549
|
-
if (reflection_1.isFunctionStatement(fnSmt)) {
|
|
550
|
-
let ifStmt = fnSmt.func.body.statements[0];
|
|
551
|
-
if (reflection_1.isIfStatement(ifStmt)) {
|
|
552
|
-
expectCommentWithText(ifStmt.thenBranch.statements[0], `'comment 1`);
|
|
553
|
-
expectCommentWithText(ifStmt.thenBranch.statements[1], `'comment 2`);
|
|
554
|
-
expectCommentWithText(ifStmt.thenBranch.statements[3], `'comment 3`);
|
|
555
|
-
let elseIfBranch = ifStmt.elseBranch;
|
|
556
|
-
if (reflection_1.isIfStatement(elseIfBranch)) {
|
|
557
|
-
expectCommentWithText(elseIfBranch.thenBranch.statements[0], `'comment 4`);
|
|
558
|
-
expectCommentWithText(elseIfBranch.thenBranch.statements[1], `'comment 5`);
|
|
559
|
-
expectCommentWithText(elseIfBranch.thenBranch.statements[3], `'comment 6`);
|
|
560
|
-
let elseBranch = elseIfBranch.elseBranch;
|
|
561
|
-
if (reflection_1.isBlock(elseBranch)) {
|
|
562
|
-
expectCommentWithText(elseBranch.statements[0], `'comment 7`);
|
|
563
|
-
expectCommentWithText(elseBranch.statements[1], `'comment 8`);
|
|
564
|
-
expectCommentWithText(elseBranch.statements[3], `'comment 9`);
|
|
565
|
-
}
|
|
566
|
-
else {
|
|
567
|
-
failStatementType(elseBranch, 'Block');
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
else {
|
|
571
|
-
failStatementType(elseIfBranch, 'If');
|
|
572
|
-
}
|
|
573
|
-
expectCommentWithText(fnSmt.func.body.statements[1], `'comment 10`);
|
|
574
|
-
}
|
|
575
|
-
else {
|
|
576
|
-
failStatementType(ifStmt, 'If');
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
else {
|
|
580
|
-
failStatementType(fnSmt, 'Function');
|
|
581
|
-
}
|
|
582
|
-
});
|
|
583
|
-
it('while', () => {
|
|
584
|
-
let { tokens } = lexer_1.Lexer.scan(`
|
|
585
|
-
function a()
|
|
586
|
-
while true 'comment 1
|
|
587
|
-
'comment 2
|
|
588
|
-
print "true"
|
|
589
|
-
'comment 3
|
|
590
|
-
end while 'comment 4
|
|
591
|
-
end function
|
|
592
|
-
`);
|
|
593
|
-
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
594
|
-
chai_1.expect(diagnostics).to.be.lengthOf(0, 'Error count should be zero');
|
|
595
|
-
let stmt = statements[0].func.body.statements[0];
|
|
596
|
-
chai_1.expect(stmt.body.statements[0].text).to.equal(`'comment 1`);
|
|
597
|
-
chai_1.expect(stmt.body.statements[1].text).to.equal(`'comment 2`);
|
|
598
|
-
chai_1.expect(stmt.body.statements[3].text).to.equal(`'comment 3`);
|
|
599
|
-
chai_1.expect(statements[0].func.body.statements[1].text).to.equal(`'comment 4`);
|
|
600
|
-
});
|
|
601
|
-
it('for', () => {
|
|
602
|
-
let { tokens } = lexer_1.Lexer.scan(`
|
|
603
|
-
function a()
|
|
604
|
-
for i = 0 to 10 step 1 'comment 1
|
|
605
|
-
'comment 2
|
|
606
|
-
print 1
|
|
607
|
-
'comment 3
|
|
608
|
-
end for 'comment 4
|
|
609
|
-
end function
|
|
610
|
-
`);
|
|
611
|
-
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
612
|
-
chai_1.expect(diagnostics).to.be.lengthOf(0, 'Error count should be zero');
|
|
613
|
-
let stmt = statements[0].func.body.statements[0];
|
|
614
|
-
chai_1.expect(stmt.body.statements[0].text).to.equal(`'comment 1`);
|
|
615
|
-
chai_1.expect(stmt.body.statements[1].text).to.equal(`'comment 2`);
|
|
616
|
-
chai_1.expect(stmt.body.statements[3].text).to.equal(`'comment 3`);
|
|
617
|
-
chai_1.expect(statements[0].func.body.statements[1].text).to.equal(`'comment 4`);
|
|
618
|
-
});
|
|
619
|
-
it('for each', () => {
|
|
620
|
-
let { tokens } = lexer_1.Lexer.scan(`
|
|
621
|
-
function a()
|
|
622
|
-
for each val in [1,2,3] 'comment 1
|
|
623
|
-
'comment 2
|
|
624
|
-
print 1
|
|
625
|
-
'comment 3
|
|
626
|
-
end for 'comment 4
|
|
627
|
-
end function
|
|
628
|
-
`);
|
|
629
|
-
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
630
|
-
chai_1.expect(diagnostics).to.be.lengthOf(0, 'Error count should be zero');
|
|
631
|
-
let stmt = statements[0].func.body.statements[0];
|
|
632
|
-
chai_1.expect(stmt.body.statements[0].text).to.equal(`'comment 1`);
|
|
633
|
-
chai_1.expect(stmt.body.statements[1].text).to.equal(`'comment 2`);
|
|
634
|
-
chai_1.expect(stmt.body.statements[3].text).to.equal(`'comment 3`);
|
|
635
|
-
chai_1.expect(statements[0].func.body.statements[1].text).to.equal(`'comment 4`);
|
|
636
|
-
});
|
|
637
|
-
});
|
|
638
|
-
});
|
|
639
|
-
describe('reservedWords', () => {
|
|
640
|
-
describe('`then`', () => {
|
|
641
|
-
it('is not allowed as a local identifier', () => {
|
|
642
|
-
let { diagnostics } = parse(`
|
|
643
|
-
sub main()
|
|
644
|
-
then = true
|
|
645
|
-
end sub
|
|
646
|
-
`);
|
|
647
|
-
chai_1.expect(diagnostics).to.be.lengthOf(1);
|
|
648
|
-
});
|
|
649
|
-
it('is allowed as an AA property name', () => {
|
|
650
|
-
var _a;
|
|
651
|
-
let { diagnostics } = parse(`
|
|
652
|
-
sub main()
|
|
653
|
-
person = {
|
|
654
|
-
then: true
|
|
655
|
-
}
|
|
656
|
-
person.then = false
|
|
657
|
-
print person.then
|
|
658
|
-
end sub
|
|
659
|
-
`);
|
|
660
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
661
|
-
});
|
|
662
|
-
});
|
|
663
|
-
it('"end" is not allowed as a local identifier', () => {
|
|
664
|
-
let { diagnostics } = parse(`
|
|
665
|
-
sub main()
|
|
666
|
-
end = true
|
|
667
|
-
end sub
|
|
668
|
-
`);
|
|
669
|
-
chai_1.expect(diagnostics).to.be.length.greaterThan(0);
|
|
670
|
-
});
|
|
671
|
-
it('none of them can be used as local variables', () => {
|
|
672
|
-
let reservedWords = new Set(lexer_1.ReservedWords);
|
|
673
|
-
//remove the rem keyword because it's a comment...won't cause error
|
|
674
|
-
reservedWords.delete('rem');
|
|
675
|
-
for (let reservedWord of reservedWords) {
|
|
676
|
-
let { tokens } = lexer_1.Lexer.scan(`
|
|
677
|
-
sub main()
|
|
678
|
-
${reservedWord} = true
|
|
679
|
-
end sub
|
|
680
|
-
`);
|
|
681
|
-
let { diagnostics } = Parser_1.Parser.parse(tokens);
|
|
682
|
-
chai_1.expect(diagnostics, `assigning to reserved word "${reservedWord}" should have been an error`).to.be.length.greaterThan(0);
|
|
683
|
-
}
|
|
684
|
-
});
|
|
685
|
-
});
|
|
686
|
-
describe('import keyword', () => {
|
|
687
|
-
it('parses without errors', () => {
|
|
688
|
-
var _a;
|
|
689
|
-
let { statements, diagnostics } = parse(`
|
|
690
|
-
import "somePath"
|
|
691
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
692
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
693
|
-
chai_1.expect(statements[0]).to.be.instanceof(Statement_1.ImportStatement);
|
|
694
|
-
});
|
|
695
|
-
it('catches import statements used in brightscript files', () => {
|
|
696
|
-
var _a;
|
|
697
|
-
let { statements, diagnostics } = parse(`
|
|
698
|
-
import "somePath"
|
|
699
|
-
`, Parser_1.ParseMode.BrightScript);
|
|
700
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.eql(DiagnosticMessages_1.DiagnosticMessages.bsFeatureNotSupportedInBrsFiles('import statements').message);
|
|
701
|
-
chai_1.expect(statements[0]).to.be.instanceof(Statement_1.ImportStatement);
|
|
702
|
-
});
|
|
703
|
-
it('catchs missing file path', () => {
|
|
704
|
-
var _a;
|
|
705
|
-
let { statements, diagnostics } = parse(`
|
|
706
|
-
import
|
|
707
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
708
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.expectedStringLiteralAfterKeyword('import').message);
|
|
709
|
-
chai_1.expect(statements[0]).to.be.instanceof(Statement_1.ImportStatement);
|
|
710
|
-
});
|
|
711
|
-
});
|
|
712
|
-
describe('Annotations', () => {
|
|
713
|
-
it('parses with error if malformed', () => {
|
|
714
|
-
var _a;
|
|
715
|
-
let { diagnostics } = parse(`
|
|
716
|
-
@
|
|
717
|
-
sub main()
|
|
718
|
-
end sub
|
|
719
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
720
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.foundUnexpectedToken('@').message);
|
|
721
|
-
});
|
|
722
|
-
it('properly handles empty annotation above class method', () => {
|
|
723
|
-
var _a;
|
|
724
|
-
//this code used to cause an infinite loop, so the fact that the test passes/fails on its own is a success!
|
|
725
|
-
let { diagnostics } = parse(`
|
|
726
|
-
class Person
|
|
727
|
-
@
|
|
728
|
-
sub new()
|
|
729
|
-
end sub
|
|
730
|
-
end class
|
|
731
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
732
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.expectedIdentifier().message);
|
|
733
|
-
});
|
|
734
|
-
it('parses with error if annotation is not followed by a statement', () => {
|
|
735
|
-
var _a, _b, _c, _d;
|
|
736
|
-
let { diagnostics } = parse(`
|
|
737
|
-
sub main()
|
|
738
|
-
@meta2
|
|
739
|
-
end sub
|
|
740
|
-
class MyClass
|
|
741
|
-
@meta3
|
|
742
|
-
@meta4
|
|
743
|
-
end class
|
|
744
|
-
@meta1
|
|
745
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
746
|
-
chai_1.expect(diagnostics.length).to.equal(4);
|
|
747
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.unusedAnnotation().message);
|
|
748
|
-
chai_1.expect((_b = diagnostics[1]) === null || _b === void 0 ? void 0 : _b.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.unusedAnnotation().message);
|
|
749
|
-
chai_1.expect((_c = diagnostics[2]) === null || _c === void 0 ? void 0 : _c.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.unusedAnnotation().message);
|
|
750
|
-
chai_1.expect((_d = diagnostics[3]) === null || _d === void 0 ? void 0 : _d.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.unusedAnnotation().message);
|
|
751
|
-
});
|
|
752
|
-
it('attaches an annotation to next statement', () => {
|
|
753
|
-
var _a;
|
|
754
|
-
let { statements, diagnostics } = parse(`
|
|
755
|
-
@meta1
|
|
756
|
-
function main()
|
|
757
|
-
end function
|
|
758
|
-
|
|
759
|
-
@meta2 sub init()
|
|
760
|
-
end sub
|
|
761
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
762
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
763
|
-
chai_1.expect(statements[0]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
764
|
-
let fn = statements[0];
|
|
765
|
-
chai_1.expect(fn.annotations).to.exist;
|
|
766
|
-
chai_1.expect(fn.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
767
|
-
chai_1.expect(fn.annotations[0].nameToken.text).to.equal('meta1');
|
|
768
|
-
chai_1.expect(fn.annotations[0].name).to.equal('meta1');
|
|
769
|
-
chai_1.expect(statements[1]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
770
|
-
fn = statements[1];
|
|
771
|
-
chai_1.expect(fn.annotations).to.exist;
|
|
772
|
-
chai_1.expect(fn.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
773
|
-
chai_1.expect(fn.annotations[0].nameToken.text).to.equal('meta2');
|
|
774
|
-
});
|
|
775
|
-
it('attaches annotations inside a function body', () => {
|
|
776
|
-
var _a, _b;
|
|
777
|
-
let { statements, diagnostics } = parse(`
|
|
778
|
-
function main()
|
|
779
|
-
@meta1
|
|
780
|
-
print "hello"
|
|
781
|
-
end function
|
|
782
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
783
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
784
|
-
let fn = statements[0];
|
|
785
|
-
let fnStatements = fn.func.body.statements;
|
|
786
|
-
let stat = fnStatements[0];
|
|
787
|
-
chai_1.expect(stat).to.exist;
|
|
788
|
-
chai_1.expect((_b = stat.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
789
|
-
chai_1.expect(stat.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
790
|
-
});
|
|
791
|
-
it('attaches multiple annotations to next statement', () => {
|
|
792
|
-
var _a;
|
|
793
|
-
let { statements, diagnostics } = parse(`
|
|
794
|
-
@meta1
|
|
795
|
-
@meta2 @meta3
|
|
796
|
-
function main()
|
|
797
|
-
end function
|
|
798
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
799
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
800
|
-
chai_1.expect(statements[0]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
801
|
-
let fn = statements[0];
|
|
802
|
-
chai_1.expect(fn.annotations).to.exist;
|
|
803
|
-
chai_1.expect(fn.annotations.length).to.equal(3);
|
|
804
|
-
chai_1.expect(fn.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
805
|
-
chai_1.expect(fn.annotations[1]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
806
|
-
chai_1.expect(fn.annotations[2]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
807
|
-
});
|
|
808
|
-
it('allows annotations with parameters', () => {
|
|
809
|
-
var _a;
|
|
810
|
-
let { statements, diagnostics } = parse(`
|
|
811
|
-
@meta1("arg", 2, true, { prop: "value" })
|
|
812
|
-
function main()
|
|
813
|
-
end function
|
|
814
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
815
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
816
|
-
let fn = statements[0];
|
|
817
|
-
chai_1.expect(fn.annotations).to.exist;
|
|
818
|
-
chai_1.expect(fn.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
819
|
-
chai_1.expect(fn.annotations[0].nameToken.text).to.equal('meta1');
|
|
820
|
-
chai_1.expect(fn.annotations[0].call).to.be.instanceof(Expression_1.CallExpression);
|
|
821
|
-
});
|
|
822
|
-
it('attaches annotations to a class', () => {
|
|
823
|
-
var _a, _b;
|
|
824
|
-
let { statements, diagnostics } = parse(`
|
|
825
|
-
@meta1
|
|
826
|
-
class MyClass
|
|
827
|
-
function main()
|
|
828
|
-
print "hello"
|
|
829
|
-
end function
|
|
830
|
-
end class
|
|
831
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
832
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
833
|
-
let cs = statements[0];
|
|
834
|
-
chai_1.expect((_b = cs.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
835
|
-
chai_1.expect(cs.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
836
|
-
});
|
|
837
|
-
it('attaches annotations to multiple clases', () => {
|
|
838
|
-
var _a, _b, _c;
|
|
839
|
-
let { statements, diagnostics } = parse(`
|
|
840
|
-
@meta1
|
|
841
|
-
class MyClass
|
|
842
|
-
function main()
|
|
843
|
-
print "hello"
|
|
844
|
-
end function
|
|
845
|
-
end class
|
|
846
|
-
@meta2
|
|
847
|
-
class MyClass2
|
|
848
|
-
function main()
|
|
849
|
-
print "hello"
|
|
850
|
-
end function
|
|
851
|
-
end class
|
|
852
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
853
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
854
|
-
let cs = statements[0];
|
|
855
|
-
chai_1.expect((_b = cs.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
856
|
-
chai_1.expect(cs.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
857
|
-
chai_1.expect(cs.annotations[0].name).to.equal('meta1');
|
|
858
|
-
let cs2 = statements[1];
|
|
859
|
-
chai_1.expect((_c = cs2.annotations) === null || _c === void 0 ? void 0 : _c.length).to.equal(1);
|
|
860
|
-
chai_1.expect(cs2.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
861
|
-
chai_1.expect(cs2.annotations[0].name).to.equal('meta2');
|
|
862
|
-
});
|
|
863
|
-
it('attaches annotations to a namespaced class', () => {
|
|
864
|
-
var _a, _b;
|
|
865
|
-
let { statements, diagnostics } = parse(`
|
|
866
|
-
namespace ns
|
|
867
|
-
@meta1
|
|
868
|
-
class MyClass
|
|
869
|
-
function main()
|
|
870
|
-
print "hello"
|
|
871
|
-
end function
|
|
872
|
-
end class
|
|
873
|
-
end namespace
|
|
874
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
875
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
876
|
-
let ns = statements[0];
|
|
877
|
-
let cs = ns.body.statements[0];
|
|
878
|
-
chai_1.expect((_b = cs.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
879
|
-
chai_1.expect(cs.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
880
|
-
});
|
|
881
|
-
it('attaches annotations to a namespaced class - multiple', () => {
|
|
882
|
-
var _a, _b, _c;
|
|
883
|
-
let { statements, diagnostics } = parse(`
|
|
884
|
-
namespace ns
|
|
885
|
-
@meta1
|
|
886
|
-
class MyClass
|
|
887
|
-
function main()
|
|
888
|
-
print "hello"
|
|
889
|
-
end function
|
|
890
|
-
end class
|
|
891
|
-
@meta2
|
|
892
|
-
class MyClass2
|
|
893
|
-
function main()
|
|
894
|
-
print "hello"
|
|
895
|
-
end function
|
|
896
|
-
end class
|
|
897
|
-
end namespace
|
|
898
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
899
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
900
|
-
let ns = statements[0];
|
|
901
|
-
let cs = ns.body.statements[0];
|
|
902
|
-
chai_1.expect((_b = cs.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
903
|
-
chai_1.expect(cs.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
904
|
-
chai_1.expect(cs.annotations[0].name).to.equal('meta1');
|
|
905
|
-
let cs2 = ns.body.statements[1];
|
|
906
|
-
chai_1.expect((_c = cs2.annotations) === null || _c === void 0 ? void 0 : _c.length).to.equal(1);
|
|
907
|
-
chai_1.expect(cs2.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
908
|
-
chai_1.expect(cs2.annotations[0].name).to.equal('meta2');
|
|
909
|
-
});
|
|
910
|
-
it('attaches annotations to a class constructor', () => {
|
|
911
|
-
var _a, _b;
|
|
912
|
-
let { statements, diagnostics } = parse(`
|
|
913
|
-
class MyClass
|
|
914
|
-
@meta1
|
|
915
|
-
function new()
|
|
916
|
-
print "hello"
|
|
917
|
-
end function
|
|
918
|
-
function methodA()
|
|
919
|
-
print "hello"
|
|
920
|
-
end function
|
|
921
|
-
end class
|
|
922
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
923
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
924
|
-
let cs = statements[0];
|
|
925
|
-
let stat = cs.body[0];
|
|
926
|
-
chai_1.expect((_b = stat.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
927
|
-
chai_1.expect(stat.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
928
|
-
});
|
|
929
|
-
it('attaches annotations to a class methods', () => {
|
|
930
|
-
var _a, _b;
|
|
931
|
-
let { statements, diagnostics } = parse(`
|
|
932
|
-
class MyClass
|
|
933
|
-
function new()
|
|
934
|
-
print "hello"
|
|
935
|
-
end function
|
|
936
|
-
@meta1
|
|
937
|
-
function methodA()
|
|
938
|
-
print "hello"
|
|
939
|
-
end function
|
|
940
|
-
end class
|
|
941
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
942
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
943
|
-
let cs = statements[0];
|
|
944
|
-
let stat = cs.body[1];
|
|
945
|
-
chai_1.expect((_b = stat.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
946
|
-
chai_1.expect(stat.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
947
|
-
});
|
|
948
|
-
it('attaches annotations to a class methods, fields and constructor', () => {
|
|
949
|
-
var _a, _b, _c, _d, _e;
|
|
950
|
-
let { statements, diagnostics } = parse(`
|
|
951
|
-
@meta2
|
|
952
|
-
@meta1
|
|
953
|
-
class MyClass
|
|
954
|
-
@meta3
|
|
955
|
-
@meta4
|
|
956
|
-
function new()
|
|
957
|
-
print "hello"
|
|
958
|
-
end function
|
|
959
|
-
@meta5
|
|
960
|
-
@meta6
|
|
961
|
-
function methodA()
|
|
962
|
-
print "hello"
|
|
963
|
-
end function
|
|
964
|
-
|
|
965
|
-
@meta5
|
|
966
|
-
@meta6
|
|
967
|
-
public foo="bar"
|
|
968
|
-
end class
|
|
969
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
970
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
971
|
-
let cs = statements[0];
|
|
972
|
-
chai_1.expect((_b = cs.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(2);
|
|
973
|
-
chai_1.expect(cs.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
974
|
-
let stat1 = cs.body[0];
|
|
975
|
-
let stat2 = cs.body[1];
|
|
976
|
-
let f1 = cs.body[2];
|
|
977
|
-
chai_1.expect((_c = stat1.annotations) === null || _c === void 0 ? void 0 : _c.length).to.equal(2);
|
|
978
|
-
chai_1.expect(stat1.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
979
|
-
chai_1.expect((_d = stat2.annotations) === null || _d === void 0 ? void 0 : _d.length).to.equal(2);
|
|
980
|
-
chai_1.expect(stat2.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
981
|
-
chai_1.expect((_e = f1.annotations) === null || _e === void 0 ? void 0 : _e.length).to.equal(2);
|
|
982
|
-
chai_1.expect(f1.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
983
|
-
});
|
|
984
|
-
it('ignores annotations on commented out lines', () => {
|
|
985
|
-
var _a;
|
|
986
|
-
let { statements, diagnostics } = parse(`
|
|
987
|
-
'@meta1
|
|
988
|
-
' @meta1
|
|
989
|
-
function new()
|
|
990
|
-
print "hello"
|
|
991
|
-
end function
|
|
992
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
993
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
994
|
-
let cs = statements[0];
|
|
995
|
-
chai_1.expect(cs.annotations).to.be.undefined;
|
|
996
|
-
});
|
|
997
|
-
it('can convert argument of an annotation to JS types', () => {
|
|
998
|
-
var _a;
|
|
999
|
-
let { statements, diagnostics } = parse(`
|
|
1000
|
-
@meta1
|
|
1001
|
-
function main()
|
|
1002
|
-
end function
|
|
1003
|
-
|
|
1004
|
-
@meta2(
|
|
1005
|
-
"arg", 2, true,
|
|
1006
|
-
{ prop: "value" }, [1, 2],
|
|
1007
|
-
sub()
|
|
1008
|
-
end sub
|
|
1009
|
-
)
|
|
1010
|
-
sub init()
|
|
1011
|
-
end sub
|
|
1012
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1013
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
1014
|
-
chai_1.expect(statements[0]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
1015
|
-
let fn = statements[0];
|
|
1016
|
-
chai_1.expect(fn.annotations).to.exist;
|
|
1017
|
-
chai_1.expect(fn.annotations[0].getArguments()).to.deep.equal([]);
|
|
1018
|
-
chai_1.expect(statements[1]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
1019
|
-
fn = statements[1];
|
|
1020
|
-
chai_1.expect(fn.annotations).to.exist;
|
|
1021
|
-
chai_1.expect(fn.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
1022
|
-
chai_1.expect(fn.annotations[0].getArguments()).to.deep.equal([
|
|
1023
|
-
'arg', 2, true,
|
|
1024
|
-
{ prop: 'value' }, [1, 2],
|
|
1025
|
-
null
|
|
1026
|
-
]);
|
|
1027
|
-
let allArgs = fn.annotations[0].getArguments(false);
|
|
1028
|
-
chai_1.expect(allArgs.pop()).to.be.instanceOf(Expression_1.FunctionExpression);
|
|
1029
|
-
});
|
|
1030
|
-
it('can handle negative numbers', () => {
|
|
1031
|
-
var _a;
|
|
1032
|
-
let { statements, diagnostics } = parse(`
|
|
1033
|
-
@meta(-100)
|
|
1034
|
-
function main()
|
|
1035
|
-
end function
|
|
1036
|
-
|
|
1037
|
-
sub init()
|
|
1038
|
-
end sub
|
|
1039
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1040
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
1041
|
-
chai_1.expect(statements[0]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
1042
|
-
let fn = statements[0];
|
|
1043
|
-
chai_1.expect(fn.annotations).to.exist;
|
|
1044
|
-
chai_1.expect(fn.annotations[0].getArguments()).to.deep.equal([-100]);
|
|
1045
|
-
});
|
|
1046
|
-
});
|
|
1047
|
-
describe('getBscTypeFromExpression', () => {
|
|
1048
|
-
it('computes void type for sub with no return type', () => {
|
|
1049
|
-
const parser = parse(`
|
|
1050
|
-
sub main()
|
|
1051
|
-
getMessage = sub()
|
|
1052
|
-
print "hello"
|
|
1053
|
-
end sub
|
|
1054
|
-
end sub
|
|
1055
|
-
`);
|
|
1056
|
-
const func = parser.ast.statements[0].func;
|
|
1057
|
-
const type = Parser_1.getBscTypeFromExpression(func.body.statements[0].value, func);
|
|
1058
|
-
chai_1.expect(type.returnType).to.be.instanceof(VoidType_1.VoidType);
|
|
1059
|
-
});
|
|
1060
|
-
it('computes return type for sub with explicit return type', () => {
|
|
1061
|
-
const parser = parse(`
|
|
1062
|
-
sub main()
|
|
1063
|
-
getMessage = sub() as string
|
|
1064
|
-
return "hello"
|
|
1065
|
-
end sub
|
|
1066
|
-
end sub
|
|
1067
|
-
`);
|
|
1068
|
-
const func = parser.ast.statements[0].func;
|
|
1069
|
-
const type = Parser_1.getBscTypeFromExpression(func.body.statements[0].value, func);
|
|
1070
|
-
chai_1.expect(type.returnType).to.be.instanceof(StringType_1.StringType);
|
|
1071
|
-
});
|
|
1072
|
-
it('supports sub with custom return type', () => {
|
|
1073
|
-
const parser = parse(`
|
|
1074
|
-
sub main()
|
|
1075
|
-
getPerson = sub() as Person
|
|
1076
|
-
return new Person()
|
|
1077
|
-
end sub
|
|
1078
|
-
end sub
|
|
1079
|
-
|
|
1080
|
-
class Person
|
|
1081
|
-
end class
|
|
1082
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1083
|
-
testHelpers_spec_1.expectZeroDiagnostics(parser.diagnostics);
|
|
1084
|
-
const func = parser.ast.statements[0].func;
|
|
1085
|
-
const type = Parser_1.getBscTypeFromExpression(func.body.statements[0].value, func);
|
|
1086
|
-
chai_1.expect(type.returnType).to.be.instanceof(CustomType_1.CustomType);
|
|
1087
|
-
});
|
|
1088
|
-
});
|
|
1089
|
-
describe('symbolTable', () => {
|
|
1090
|
-
it('stores the types', () => {
|
|
1091
|
-
const parser = parse(`
|
|
1092
|
-
sub main()
|
|
1093
|
-
someNum = 123
|
|
1094
|
-
someString = "hello world"
|
|
1095
|
-
someObj = {foo: "bar"}
|
|
1096
|
-
someCustom = new CustomKlass()
|
|
1097
|
-
end sub
|
|
1098
|
-
|
|
1099
|
-
class CustomKlass
|
|
1100
|
-
end class
|
|
1101
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1102
|
-
testHelpers_spec_1.expectZeroDiagnostics(parser.diagnostics);
|
|
1103
|
-
const mainSymbolTable = parser.references.functionExpressions[0].symbolTable;
|
|
1104
|
-
chai_1.expect(mainSymbolTable.getSymbolType('someNum')).to.be.instanceof(IntegerType_1.IntegerType);
|
|
1105
|
-
chai_1.expect(mainSymbolTable.getSymbolType('someString')).to.be.instanceof(StringType_1.StringType);
|
|
1106
|
-
chai_1.expect(mainSymbolTable.getSymbolType('someObj')).to.be.instanceof(ObjectType_1.ObjectType);
|
|
1107
|
-
chai_1.expect(mainSymbolTable.getSymbolType('someCustom')).to.be.instanceof(CustomType_1.CustomType);
|
|
1108
|
-
});
|
|
1109
|
-
it('stores typed parameters in functions', () => {
|
|
1110
|
-
const parser = parse(`
|
|
1111
|
-
sub someFunc(param1 as string, param2 as integer)
|
|
1112
|
-
temp = param2
|
|
1113
|
-
end sub
|
|
1114
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1115
|
-
testHelpers_spec_1.expectZeroDiagnostics(parser.diagnostics);
|
|
1116
|
-
const someFuncSymbolTable = parser.references.functionExpressions[0].symbolTable;
|
|
1117
|
-
chai_1.expect(someFuncSymbolTable.getSymbolType('param1')).to.be.instanceof(StringType_1.StringType);
|
|
1118
|
-
chai_1.expect(someFuncSymbolTable.getSymbolType('param2')).to.be.instanceof(IntegerType_1.IntegerType);
|
|
1119
|
-
chai_1.expect(someFuncSymbolTable.getSymbolType('temp')).to.be.instanceof(IntegerType_1.IntegerType);
|
|
1120
|
-
});
|
|
1121
|
-
it('properly defers typing lazy types', () => {
|
|
1122
|
-
const parser = parse(`
|
|
1123
|
-
sub someFunc()
|
|
1124
|
-
temp = foo()
|
|
1125
|
-
end sub
|
|
1126
|
-
|
|
1127
|
-
function foo() as string
|
|
1128
|
-
return "foo"
|
|
1129
|
-
end function
|
|
1130
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1131
|
-
testHelpers_spec_1.expectZeroDiagnostics(parser.diagnostics);
|
|
1132
|
-
const someFuncSymbolTable = parser.references.functionExpressions[0].symbolTable;
|
|
1133
|
-
chai_1.expect(someFuncSymbolTable.getSymbolType('temp')).to.be.instanceof(LazyType_1.LazyType);
|
|
1134
|
-
chai_1.expect(someFuncSymbolTable.getSymbolType('temp').toTypeString()).to.eq('string');
|
|
1135
|
-
});
|
|
1136
|
-
it('does not know about symbols declared in parent functions', () => {
|
|
1137
|
-
const parser = parse(`
|
|
1138
|
-
sub main()
|
|
1139
|
-
count = 0
|
|
1140
|
-
addOne = sub()
|
|
1141
|
-
oldVal = count
|
|
1142
|
-
end sub
|
|
1143
|
-
end sub
|
|
1144
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1145
|
-
testHelpers_spec_1.expectZeroDiagnostics(parser.diagnostics);
|
|
1146
|
-
const addOneSymbolTable = parser.references.functionExpressions[0].childFunctionExpressions[0].symbolTable;
|
|
1147
|
-
chai_1.expect(addOneSymbolTable.getSymbolType('oldVal').toString()).to.eq('uninitialized');
|
|
1148
|
-
});
|
|
1149
|
-
it('finds params', () => {
|
|
1150
|
-
const parser = parse(`
|
|
1151
|
-
sub alert(p1, p2 as string, p3 = 1)
|
|
1152
|
-
end sub
|
|
1153
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1154
|
-
testHelpers_spec_1.expectZeroDiagnostics(parser.diagnostics);
|
|
1155
|
-
testHelpers_spec_1.expectSymbolTableEquals(parser.references.functionExpressions[0].symbolTable, [
|
|
1156
|
-
['p1', new DynamicType_1.DynamicType(), util_1.default.createRange(1, 26, 1, 28)],
|
|
1157
|
-
['p2', new StringType_1.StringType(), util_1.default.createRange(1, 30, 1, 32)],
|
|
1158
|
-
['p3', new IntegerType_1.IntegerType(), util_1.default.createRange(1, 44, 1, 46)]
|
|
1159
|
-
]);
|
|
1160
|
-
});
|
|
1161
|
-
describe('loops', () => {
|
|
1162
|
-
it('stores the loop variable in a for loop', () => {
|
|
1163
|
-
const parser = parse(`
|
|
1164
|
-
sub main()
|
|
1165
|
-
for i = 0 to 10 step 10
|
|
1166
|
-
print i
|
|
1167
|
-
end for
|
|
1168
|
-
end sub
|
|
1169
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1170
|
-
testHelpers_spec_1.expectZeroDiagnostics(parser.diagnostics);
|
|
1171
|
-
const currentSymbolTable = parser.references.functionExpressions[0].symbolTable;
|
|
1172
|
-
chai_1.expect(currentSymbolTable.getSymbolType('i').toString()).to.eq('integer');
|
|
1173
|
-
});
|
|
1174
|
-
it('stores the loop variable in a for each loop', () => {
|
|
1175
|
-
const parser = parse(`
|
|
1176
|
-
sub doLoop(someData)
|
|
1177
|
-
for each datum in someData
|
|
1178
|
-
print datum
|
|
1179
|
-
end for
|
|
1180
|
-
end sub
|
|
1181
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1182
|
-
testHelpers_spec_1.expectZeroDiagnostics(parser.diagnostics);
|
|
1183
|
-
const currentSymbolTable = parser.references.functionExpressions[0].symbolTable;
|
|
1184
|
-
chai_1.expect(currentSymbolTable.getSymbolType('datum').toString()).to.eq('dynamic');
|
|
1185
|
-
});
|
|
1186
|
-
});
|
|
1187
|
-
});
|
|
1188
|
-
});
|
|
1189
|
-
function parse(text, mode) {
|
|
1190
|
-
let { tokens } = lexer_1.Lexer.scan(text);
|
|
1191
|
-
return Parser_1.Parser.parse(tokens, {
|
|
1192
|
-
mode: mode
|
|
1193
|
-
});
|
|
1194
|
-
}
|
|
1195
|
-
function rangeToArray(range) {
|
|
1196
|
-
return [
|
|
1197
|
-
range.start.line,
|
|
1198
|
-
range.start.character,
|
|
1199
|
-
range.end.line,
|
|
1200
|
-
range.end.character
|
|
1201
|
-
];
|
|
1202
|
-
}
|
|
1203
|
-
exports.rangeToArray = rangeToArray;
|
|
1204
|
-
function expectCommentWithText(stat, text) {
|
|
1205
|
-
if (reflection_1.isCommentStatement(stat)) {
|
|
1206
|
-
chai_1.expect(stat.text).to.equal(text);
|
|
1207
|
-
}
|
|
1208
|
-
else {
|
|
1209
|
-
failStatementType(stat, 'Comment');
|
|
1210
|
-
}
|
|
1211
|
-
}
|
|
1212
|
-
function failStatementType(stat, type) {
|
|
1213
|
-
chai_1.assert.fail(`Statement ${stat.constructor.name} line ${stat.range.start.line} is not a ${type}`);
|
|
1214
|
-
}
|
|
1215
|
-
exports.failStatementType = failStatementType;
|
|
1216
|
-
//# sourceMappingURL=Parser.spec.js.map
|