brighterscript 1.0.0-alpha.23 → 1.0.0-alpha.25
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/CHANGELOG.md +585 -218
- package/README.md +45 -139
- package/bsconfig.schema.json +41 -0
- 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 +25 -0
- package/dist/AstValidationSegmenter.js +152 -0
- package/dist/AstValidationSegmenter.js.map +1 -0
- package/dist/BsConfig.d.ts +39 -4
- package/dist/BusyStatusTracker.d.ts +31 -0
- package/dist/BusyStatusTracker.js +83 -0
- package/dist/BusyStatusTracker.js.map +1 -0
- package/dist/Cache.js +3 -3
- 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 +3 -3
- package/dist/CodeActionUtil.js.map +1 -1
- package/dist/CommentFlagProcessor.d.ts +3 -2
- package/dist/CommentFlagProcessor.js +5 -4
- package/dist/CommentFlagProcessor.js.map +1 -1
- package/dist/DependencyGraph.d.ts +3 -2
- package/dist/DependencyGraph.js +11 -10
- package/dist/DependencyGraph.js.map +1 -1
- package/dist/DiagnosticCollection.js +9 -5
- package/dist/DiagnosticCollection.js.map +1 -1
- package/dist/DiagnosticFilterer.d.ts +1 -0
- package/dist/DiagnosticFilterer.js +5 -3
- package/dist/DiagnosticFilterer.js.map +1 -1
- package/dist/DiagnosticMessages.d.ts +79 -15
- package/dist/DiagnosticMessages.js +134 -21
- package/dist/DiagnosticMessages.js.map +1 -1
- package/dist/DiagnosticSeverityAdjuster.d.ts +7 -0
- package/dist/DiagnosticSeverityAdjuster.js +41 -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 +23 -11
- package/dist/LanguageServer.js +222 -87
- package/dist/LanguageServer.js.map +1 -1
- package/dist/Logger.d.ts +3 -2
- package/dist/Logger.js +11 -3
- package/dist/Logger.js.map +1 -1
- package/dist/PluginInterface.d.ts +21 -3
- package/dist/PluginInterface.js +74 -6
- package/dist/PluginInterface.js.map +1 -1
- package/dist/Program.d.ts +162 -81
- package/dist/Program.js +903 -732
- package/dist/Program.js.map +1 -1
- package/dist/ProgramBuilder.d.ts +22 -12
- package/dist/ProgramBuilder.js +132 -104
- package/dist/ProgramBuilder.js.map +1 -1
- package/dist/Scope.d.ts +95 -134
- package/dist/Scope.js +477 -551
- package/dist/Scope.js.map +1 -1
- package/dist/Stopwatch.js +1 -1
- package/dist/Stopwatch.js.map +1 -1
- package/dist/SymbolTable.d.ts +95 -29
- package/dist/SymbolTable.js +256 -102
- package/dist/SymbolTable.js.map +1 -1
- 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 +4 -6
- package/dist/XmlScope.js +74 -68
- package/dist/XmlScope.js.map +1 -1
- package/dist/astUtils/CachedLookups.d.ts +48 -0
- package/dist/astUtils/CachedLookups.js +323 -0
- package/dist/astUtils/CachedLookups.js.map +1 -0
- package/dist/astUtils/{AstEditor.d.ts → Editor.d.ts} +9 -5
- package/dist/astUtils/{AstEditor.js → Editor.js} +10 -4
- package/dist/astUtils/Editor.js.map +1 -0
- package/dist/astUtils/{AstEditor.spec.js → Editor.spec.js} +68 -64
- package/dist/astUtils/Editor.spec.js.map +1 -0
- package/dist/astUtils/creators.d.ts +10 -10
- package/dist/astUtils/creators.js +26 -16
- 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 +132 -100
- package/dist/astUtils/reflection.js +225 -166
- package/dist/astUtils/reflection.js.map +1 -1
- package/dist/astUtils/reflection.spec.js +208 -126
- package/dist/astUtils/reflection.spec.js.map +1 -1
- package/dist/astUtils/stackedVisitor.spec.js +12 -12
- package/dist/astUtils/stackedVisitor.spec.js.map +1 -1
- package/dist/astUtils/visitors.d.ts +54 -35
- package/dist/astUtils/visitors.js +29 -3
- package/dist/astUtils/visitors.js.map +1 -1
- package/dist/astUtils/visitors.spec.js +178 -33
- package/dist/astUtils/visitors.spec.js.map +1 -1
- package/dist/astUtils/xml.d.ts +9 -9
- package/dist/astUtils/xml.js +9 -9
- package/dist/astUtils/xml.js.map +1 -1
- package/dist/bscPlugin/BscPlugin.d.ts +12 -2
- package/dist/bscPlugin/BscPlugin.js +41 -3
- package/dist/bscPlugin/BscPlugin.js.map +1 -1
- package/dist/bscPlugin/CallExpressionInfo.d.ts +36 -0
- package/dist/bscPlugin/CallExpressionInfo.js +131 -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 +135 -0
- package/dist/bscPlugin/SignatureHelpUtil.js.map +1 -0
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.d.ts +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +21 -12
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +86 -12
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/completions/CompletionsProcessor.d.ts +57 -0
- package/dist/bscPlugin/completions/CompletionsProcessor.js +544 -0
- package/dist/bscPlugin/completions/CompletionsProcessor.js.map +1 -0
- package/dist/bscPlugin/completions/CompletionsProcessor.spec.js +1909 -0
- package/dist/bscPlugin/completions/CompletionsProcessor.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 +17 -0
- package/dist/bscPlugin/hover/HoverProcessor.js +188 -0
- package/dist/bscPlugin/hover/HoverProcessor.js.map +1 -0
- package/dist/bscPlugin/hover/HoverProcessor.spec.js +513 -0
- package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +1 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.d.ts +3 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +102 -29
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js +167 -6
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/serialize/BslibInjector.spec.d.ts +1 -0
- package/dist/bscPlugin/serialize/BslibInjector.spec.js +19 -0
- package/dist/bscPlugin/serialize/BslibInjector.spec.js.map +1 -0
- package/dist/bscPlugin/serialize/BslibManager.d.ts +9 -0
- package/dist/bscPlugin/serialize/BslibManager.js +40 -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 +72 -0
- package/dist/bscPlugin/serialize/FileSerializer.js.map +1 -0
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.d.ts +16 -0
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js +123 -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 +41 -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/BrsFileValidator.d.ts +22 -1
- package/dist/bscPlugin/validation/BrsFileValidator.js +316 -29
- package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -1
- package/dist/bscPlugin/validation/BrsFileValidator.spec.d.ts +1 -0
- package/dist/bscPlugin/validation/BrsFileValidator.spec.js +264 -0
- package/dist/bscPlugin/validation/BrsFileValidator.spec.js.map +1 -0
- package/dist/bscPlugin/validation/ProgramValidator.d.ts +10 -0
- package/dist/bscPlugin/validation/ProgramValidator.js +32 -0
- package/dist/bscPlugin/validation/ProgramValidator.js.map +1 -0
- package/dist/bscPlugin/validation/ScopeValidator.d.ts +56 -8
- package/dist/bscPlugin/validation/ScopeValidator.js +514 -116
- package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -1
- package/dist/bscPlugin/validation/ScopeValidator.spec.d.ts +1 -0
- package/dist/bscPlugin/validation/ScopeValidator.spec.js +2454 -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 +44 -0
- package/dist/bscPlugin/validation/XmlFileValidator.js.map +1 -0
- package/dist/cli.js +107 -8
- package/dist/cli.js.map +1 -1
- package/dist/deferred.d.ts +3 -3
- package/dist/deferred.js.map +1 -1
- package/dist/diagnosticUtils.d.ts +8 -2
- package/dist/diagnosticUtils.js +47 -17
- package/dist/diagnosticUtils.js.map +1 -1
- package/dist/examples/plugins/removePrint.js +8 -10
- package/dist/examples/plugins/removePrint.js.map +1 -1
- package/dist/files/AssetFile.d.ts +26 -0
- package/dist/files/AssetFile.js +26 -0
- package/dist/files/AssetFile.js.map +1 -0
- package/dist/files/BrsFile.Class.spec.js +529 -486
- package/dist/files/BrsFile.Class.spec.js.map +1 -1
- package/dist/files/BrsFile.d.ts +124 -112
- package/dist/files/BrsFile.js +819 -1131
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/BrsFile.spec.js +1869 -1277
- package/dist/files/BrsFile.spec.js.map +1 -1
- package/dist/files/BscFile.d.ts +104 -0
- package/dist/files/BscFile.js +16 -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 +20 -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 +70 -32
- package/dist/files/XmlFile.js +106 -117
- package/dist/files/XmlFile.js.map +1 -1
- package/dist/files/XmlFile.spec.js +325 -262
- package/dist/files/XmlFile.spec.js.map +1 -1
- package/dist/files/tests/imports.spec.js +49 -41
- package/dist/files/tests/imports.spec.js.map +1 -1
- package/dist/files/tests/optionalChaning.spec.js +104 -40
- package/dist/files/tests/optionalChaning.spec.js.map +1 -1
- package/dist/globalCallables.js +16 -18
- package/dist/globalCallables.js.map +1 -1
- package/dist/index.d.ts +13 -2
- package/dist/index.js +15 -2
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +440 -150
- package/dist/interfaces.js +27 -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 +12 -5
- package/dist/lexer/Lexer.js +28 -13
- package/dist/lexer/Lexer.js.map +1 -1
- package/dist/lexer/Lexer.spec.js +187 -134
- package/dist/lexer/Lexer.spec.js.map +1 -1
- package/dist/lexer/Token.d.ts +9 -1
- package/dist/lexer/Token.js +9 -1
- package/dist/lexer/Token.js.map +1 -1
- package/dist/lexer/TokenKind.d.ts +9 -0
- package/dist/lexer/TokenKind.js +30 -5
- package/dist/lexer/TokenKind.js.map +1 -1
- package/dist/parser/AstNode.d.ts +162 -0
- package/dist/parser/AstNode.js +225 -0
- package/dist/parser/AstNode.js.map +1 -0
- package/dist/parser/AstNode.spec.d.ts +1 -0
- package/dist/parser/AstNode.spec.js +165 -0
- package/dist/parser/AstNode.spec.js.map +1 -0
- package/dist/parser/BrsTranspileState.d.ts +4 -7
- package/dist/parser/BrsTranspileState.js +4 -12
- package/dist/parser/BrsTranspileState.js.map +1 -1
- package/dist/parser/Expression.d.ts +126 -167
- package/dist/parser/Expression.js +524 -394
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Parser.Class.spec.js +152 -146
- package/dist/parser/Parser.Class.spec.js.map +1 -1
- package/dist/parser/Parser.d.ts +45 -196
- package/dist/parser/Parser.js +470 -926
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/Parser.spec.d.ts +3 -1
- package/dist/parser/Parser.spec.js +1034 -805
- package/dist/parser/Parser.spec.js.map +1 -1
- package/dist/parser/SGParser.d.ts +9 -8
- package/dist/parser/SGParser.js +10 -8
- package/dist/parser/SGParser.js.map +1 -1
- package/dist/parser/SGParser.spec.js +27 -38
- package/dist/parser/SGParser.spec.js.map +1 -1
- package/dist/parser/SGTypes.d.ts +98 -35
- package/dist/parser/SGTypes.js +169 -99
- package/dist/parser/SGTypes.js.map +1 -1
- package/dist/parser/Statement.d.ts +208 -122
- package/dist/parser/Statement.js +599 -364
- package/dist/parser/Statement.js.map +1 -1
- package/dist/parser/Statement.spec.js +45 -21
- package/dist/parser/Statement.spec.js.map +1 -1
- package/dist/parser/TranspileState.d.ts +1 -1
- package/dist/parser/TranspileState.js +7 -12
- package/dist/parser/TranspileState.js.map +1 -1
- package/dist/parser/tests/Parser.spec.js +3 -2
- package/dist/parser/tests/Parser.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/For.spec.js +33 -23
- package/dist/parser/tests/controlFlow/For.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/ForEach.spec.js +25 -20
- package/dist/parser/tests/controlFlow/ForEach.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/If.spec.js +96 -94
- package/dist/parser/tests/controlFlow/If.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/While.spec.js +22 -16
- package/dist/parser/tests/controlFlow/While.spec.js.map +1 -1
- package/dist/parser/tests/expression/Additive.spec.js +8 -8
- package/dist/parser/tests/expression/Additive.spec.js.map +1 -1
- package/dist/parser/tests/expression/ArrayLiterals.spec.js +58 -21
- package/dist/parser/tests/expression/ArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +61 -20
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/expression/Boolean.spec.js +8 -8
- package/dist/parser/tests/expression/Boolean.spec.js.map +1 -1
- package/dist/parser/tests/expression/Call.spec.js +129 -21
- package/dist/parser/tests/expression/Call.spec.js.map +1 -1
- package/dist/parser/tests/expression/Exponential.spec.js +5 -5
- package/dist/parser/tests/expression/Exponential.spec.js.map +1 -1
- package/dist/parser/tests/expression/Function.spec.js +36 -36
- package/dist/parser/tests/expression/Function.spec.js.map +1 -1
- package/dist/parser/tests/expression/Indexing.spec.js +67 -22
- package/dist/parser/tests/expression/Indexing.spec.js.map +1 -1
- package/dist/parser/tests/expression/Multiplicative.spec.js +9 -9
- package/dist/parser/tests/expression/Multiplicative.spec.js.map +1 -1
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +123 -81
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/PrefixUnary.spec.js +12 -12
- package/dist/parser/tests/expression/PrefixUnary.spec.js.map +1 -1
- package/dist/parser/tests/expression/Primary.spec.js +12 -12
- package/dist/parser/tests/expression/Primary.spec.js.map +1 -1
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +10 -10
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/Relational.spec.js +13 -13
- package/dist/parser/tests/expression/Relational.spec.js.map +1 -1
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.js +24 -24
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js +221 -81
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TernaryExpression.spec.js +287 -105
- 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 +127 -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 +15 -15
- 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 +262 -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 +19 -19
- package/dist/parser/tests/statement/Declaration.spec.js.map +1 -1
- package/dist/parser/tests/statement/Dim.spec.js +22 -22
- package/dist/parser/tests/statement/Dim.spec.js.map +1 -1
- package/dist/parser/tests/statement/Enum.spec.js +111 -300
- package/dist/parser/tests/statement/Enum.spec.js.map +1 -1
- package/dist/parser/tests/statement/For.spec.js +9 -10
- package/dist/parser/tests/statement/For.spec.js.map +1 -1
- package/dist/parser/tests/statement/ForEach.spec.js +8 -9
- package/dist/parser/tests/statement/ForEach.spec.js.map +1 -1
- package/dist/parser/tests/statement/Function.spec.js +44 -35
- package/dist/parser/tests/statement/Function.spec.js.map +1 -1
- package/dist/parser/tests/statement/Goto.spec.js +5 -5
- package/dist/parser/tests/statement/Goto.spec.js.map +1 -1
- package/dist/parser/tests/statement/Increment.spec.js +20 -20
- package/dist/parser/tests/statement/Increment.spec.js.map +1 -1
- package/dist/parser/tests/statement/InterfaceStatement.spec.js +30 -196
- package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/LibraryStatement.spec.js +11 -11
- package/dist/parser/tests/statement/LibraryStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Misc.spec.js +16 -78
- package/dist/parser/tests/statement/Misc.spec.js.map +1 -1
- package/dist/parser/tests/statement/PrintStatement.spec.js +107 -90
- package/dist/parser/tests/statement/PrintStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/ReturnStatement.spec.js +14 -12
- package/dist/parser/tests/statement/ReturnStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Set.spec.js +48 -35
- package/dist/parser/tests/statement/Set.spec.js.map +1 -1
- package/dist/parser/tests/statement/Stop.spec.js +6 -6
- package/dist/parser/tests/statement/Stop.spec.js.map +1 -1
- package/dist/parser/tests/statement/Throw.spec.js +6 -6
- package/dist/parser/tests/statement/Throw.spec.js.map +1 -1
- package/dist/parser/tests/statement/TryCatch.spec.js +18 -16
- package/dist/parser/tests/statement/TryCatch.spec.js.map +1 -1
- package/dist/preprocessor/Manifest.d.ts +1 -1
- package/dist/preprocessor/Manifest.js +3 -3
- package/dist/preprocessor/Manifest.js.map +1 -1
- package/dist/preprocessor/Manifest.spec.js +8 -8
- package/dist/preprocessor/Manifest.spec.js.map +1 -1
- package/dist/preprocessor/Preprocessor.d.ts +5 -6
- package/dist/preprocessor/Preprocessor.js +15 -11
- package/dist/preprocessor/Preprocessor.js.map +1 -1
- package/dist/preprocessor/Preprocessor.spec.js +25 -25
- package/dist/preprocessor/Preprocessor.spec.js.map +1 -1
- package/dist/preprocessor/PreprocessorParser.d.ts +1 -1
- package/dist/preprocessor/PreprocessorParser.js +7 -1
- package/dist/preprocessor/PreprocessorParser.js.map +1 -1
- package/dist/preprocessor/PreprocessorParser.spec.js +13 -13
- package/dist/preprocessor/PreprocessorParser.spec.js.map +1 -1
- package/dist/roku-types/data.json +6544 -10519
- package/dist/roku-types/index.d.ts +662 -1934
- package/dist/types/ArrayType.d.ts +10 -9
- package/dist/types/ArrayType.js +65 -60
- package/dist/types/ArrayType.js.map +1 -1
- package/dist/types/ArrayType.spec.js +36 -68
- package/dist/types/ArrayType.spec.js.map +1 -1
- package/dist/types/AssociativeArrayType.d.ts +11 -0
- package/dist/types/AssociativeArrayType.js +52 -0
- package/dist/types/AssociativeArrayType.js.map +1 -0
- package/dist/types/BaseFunctionType.d.ts +9 -0
- package/dist/types/BaseFunctionType.js +25 -0
- package/dist/types/BaseFunctionType.js.map +1 -0
- package/dist/types/BooleanType.d.ts +8 -5
- package/dist/types/BooleanType.js +14 -7
- package/dist/types/BooleanType.js.map +1 -1
- package/dist/types/BooleanType.spec.js +10 -6
- package/dist/types/BooleanType.spec.js.map +1 -1
- package/dist/types/BscType.d.ts +32 -21
- package/dist/types/BscType.js +118 -21
- package/dist/types/BscType.js.map +1 -1
- package/dist/types/BscTypeKind.d.ts +25 -0
- package/dist/types/BscTypeKind.js +30 -0
- package/dist/types/BscTypeKind.js.map +1 -0
- package/dist/types/BuiltInInterfaceAdder.d.ts +23 -0
- package/dist/types/BuiltInInterfaceAdder.js +164 -0
- package/dist/types/BuiltInInterfaceAdder.js.map +1 -0
- package/dist/types/BuiltInInterfaceAdder.spec.d.ts +1 -0
- package/dist/types/BuiltInInterfaceAdder.spec.js +116 -0
- package/dist/types/BuiltInInterfaceAdder.spec.js.map +1 -0
- package/dist/types/ClassType.d.ts +17 -0
- package/dist/types/ClassType.js +58 -0
- package/dist/types/ClassType.js.map +1 -0
- package/dist/types/ClassType.spec.d.ts +1 -0
- package/dist/types/ClassType.spec.js +77 -0
- package/dist/types/ClassType.spec.js.map +1 -0
- package/dist/types/ComponentType.d.ts +26 -0
- package/dist/types/ComponentType.js +83 -0
- package/dist/types/ComponentType.js.map +1 -0
- package/dist/types/DoubleType.d.ts +8 -5
- package/dist/types/DoubleType.js +18 -16
- package/dist/types/DoubleType.js.map +1 -1
- package/dist/types/DoubleType.spec.js +12 -6
- package/dist/types/DoubleType.spec.js.map +1 -1
- package/dist/types/DynamicType.d.ts +10 -5
- package/dist/types/DynamicType.js +16 -4
- 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 +30 -12
- package/dist/types/EnumType.js +43 -17
- package/dist/types/EnumType.js.map +1 -1
- 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 +8 -5
- package/dist/types/FloatType.js +18 -16
- package/dist/types/FloatType.js.map +1 -1
- package/dist/types/FloatType.spec.js +4 -6
- package/dist/types/FloatType.spec.js.map +1 -1
- package/dist/types/FunctionType.d.ts +13 -8
- package/dist/types/FunctionType.js +30 -14
- package/dist/types/FunctionType.js.map +1 -1
- package/dist/types/InheritableType.d.ts +28 -0
- package/dist/types/InheritableType.js +152 -0
- package/dist/types/InheritableType.js.map +1 -0
- package/dist/types/IntegerType.d.ts +8 -5
- package/dist/types/IntegerType.js +18 -16
- package/dist/types/IntegerType.js.map +1 -1
- package/dist/types/IntegerType.spec.js +8 -6
- package/dist/types/IntegerType.spec.js.map +1 -1
- package/dist/types/InterfaceType.d.ts +12 -13
- package/dist/types/InterfaceType.js +20 -48
- package/dist/types/InterfaceType.js.map +1 -1
- package/dist/types/InterfaceType.spec.js +90 -56
- package/dist/types/InterfaceType.spec.js.map +1 -1
- package/dist/types/InvalidType.d.ts +7 -5
- package/dist/types/InvalidType.js +13 -7
- package/dist/types/InvalidType.js.map +1 -1
- package/dist/types/InvalidType.spec.js +8 -6
- package/dist/types/InvalidType.spec.js.map +1 -1
- package/dist/types/LongIntegerType.d.ts +8 -5
- package/dist/types/LongIntegerType.js +17 -15
- package/dist/types/LongIntegerType.js.map +1 -1
- package/dist/types/LongIntegerType.spec.js +10 -6
- 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 +9 -8
- package/dist/types/ObjectType.js +21 -11
- 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 +63 -0
- package/dist/types/ReferenceType.js +423 -0
- package/dist/types/ReferenceType.js.map +1 -0
- package/dist/types/ReferenceType.spec.d.ts +1 -0
- package/dist/types/ReferenceType.spec.js +137 -0
- package/dist/types/ReferenceType.spec.js.map +1 -0
- package/dist/types/StringType.d.ts +11 -5
- package/dist/types/StringType.js +18 -7
- package/dist/types/StringType.js.map +1 -1
- package/dist/types/StringType.spec.js +3 -5
- package/dist/types/StringType.spec.js.map +1 -1
- package/dist/types/TypedFunctionType.d.ts +22 -17
- package/dist/types/TypedFunctionType.js +78 -60
- package/dist/types/TypedFunctionType.js.map +1 -1
- package/dist/types/TypedFunctionType.spec.js +105 -20
- package/dist/types/TypedFunctionType.spec.js.map +1 -1
- package/dist/types/UninitializedType.d.ts +8 -6
- package/dist/types/UninitializedType.js +13 -7
- package/dist/types/UninitializedType.js.map +1 -1
- package/dist/types/UnionType.d.ts +20 -0
- package/dist/types/UnionType.js +123 -0
- package/dist/types/UnionType.js.map +1 -0
- package/dist/types/UnionType.spec.d.ts +1 -0
- package/dist/types/UnionType.spec.js +130 -0
- package/dist/types/UnionType.spec.js.map +1 -0
- package/dist/types/VoidType.d.ts +8 -5
- package/dist/types/VoidType.js +14 -7
- 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 +145 -0
- package/dist/types/helper.spec.js.map +1 -0
- package/dist/types/helpers.d.ts +19 -37
- package/dist/types/helpers.js +159 -99
- package/dist/types/helpers.js.map +1 -1
- 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/util.d.ts +167 -131
- package/dist/util.js +890 -350
- package/dist/util.js.map +1 -1
- package/dist/validators/ClassValidator.d.ts +7 -25
- package/dist/validators/ClassValidator.js +103 -194
- package/dist/validators/ClassValidator.js.map +1 -1
- package/package.json +165 -149
- package/dist/astUtils/AstEditor.js.map +0 -1
- package/dist/astUtils/AstEditor.spec.js.map +0 -1
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.d.ts +0 -8
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js +0 -40
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js.map +0 -1
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js +0 -32
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js.map +0 -1
- package/dist/parser/SGTypes.spec.js +0 -351
- package/dist/parser/SGTypes.spec.js.map +0 -1
- package/dist/types/CustomType.d.ts +0 -12
- package/dist/types/CustomType.js +0 -44
- package/dist/types/CustomType.js.map +0 -1
- package/dist/types/LazyType.d.ts +0 -16
- package/dist/types/LazyType.js +0 -44
- package/dist/types/LazyType.js.map +0 -1
- /package/dist/astUtils/{AstEditor.spec.d.ts → Editor.spec.d.ts} +0 -0
- /package/dist/bscPlugin/{transpile/BrsFilePreTranspileProcessor.spec.d.ts → completions/CompletionsProcessor.spec.d.ts} +0 -0
- /package/dist/{parser/SGTypes.spec.d.ts → bscPlugin/hover/HoverProcessor.spec.d.ts} +0 -0
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const sinonImport = require("sinon");
|
|
4
4
|
const Program_1 = require("../Program");
|
|
5
|
-
const
|
|
5
|
+
const chai_config_spec_1 = require("../chai-config.spec");
|
|
6
6
|
const DiagnosticMessages_1 = require("../DiagnosticMessages");
|
|
7
7
|
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
8
8
|
const Parser_1 = require("../parser/Parser");
|
|
@@ -11,30 +11,29 @@ const util_1 = require("../util");
|
|
|
11
11
|
const fsExtra = require("fs-extra");
|
|
12
12
|
const BrsTranspileState_1 = require("../parser/BrsTranspileState");
|
|
13
13
|
const assert_1 = require("assert");
|
|
14
|
+
const testHelpers_spec_2 = require("../testHelpers.spec");
|
|
14
15
|
const reflection_1 = require("../astUtils/reflection");
|
|
16
|
+
const visitors_1 = require("../astUtils/visitors");
|
|
15
17
|
let sinon = sinonImport.createSandbox();
|
|
16
18
|
describe('BrsFile BrighterScript classes', () => {
|
|
17
|
-
let tmpPath = (0, util_1.standardizePath) `${process.cwd()}/.tmp`;
|
|
18
|
-
let rootDir = (0, util_1.standardizePath) `${tmpPath}/rootDir`;
|
|
19
|
-
const stagingDir = (0, util_1.standardizePath) `${tmpPath}/staging`;
|
|
20
19
|
let program;
|
|
21
|
-
let testTranspile = (0, testHelpers_spec_1.getTestTranspile)(() => [program, rootDir]);
|
|
20
|
+
let testTranspile = (0, testHelpers_spec_1.getTestTranspile)(() => [program, testHelpers_spec_2.rootDir]);
|
|
22
21
|
beforeEach(() => {
|
|
23
|
-
fsExtra.ensureDirSync(rootDir);
|
|
24
|
-
fsExtra.emptyDirSync(
|
|
25
|
-
program = new Program_1.Program({ rootDir: rootDir,
|
|
22
|
+
fsExtra.ensureDirSync(testHelpers_spec_2.rootDir);
|
|
23
|
+
fsExtra.emptyDirSync(testHelpers_spec_2.tempDir);
|
|
24
|
+
program = new Program_1.Program({ rootDir: testHelpers_spec_2.rootDir, stagingDir: testHelpers_spec_2.stagingDir });
|
|
26
25
|
});
|
|
27
26
|
afterEach(() => {
|
|
28
27
|
sinon.restore();
|
|
29
28
|
program.dispose();
|
|
30
|
-
fsExtra.ensureDirSync(
|
|
31
|
-
fsExtra.emptyDirSync(
|
|
29
|
+
fsExtra.ensureDirSync(testHelpers_spec_2.tempDir);
|
|
30
|
+
fsExtra.emptyDirSync(testHelpers_spec_2.tempDir);
|
|
32
31
|
});
|
|
33
32
|
function addFile(relativePath, text) {
|
|
34
|
-
return program.setFile({ src: `${rootDir}/${relativePath}`, dest: relativePath }, text);
|
|
33
|
+
return program.setFile({ src: `${testHelpers_spec_2.rootDir}/${relativePath}`, dest: relativePath }, text);
|
|
35
34
|
}
|
|
36
35
|
it('detects all classes after parse', () => {
|
|
37
|
-
let file = program.setFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
|
|
36
|
+
let file = program.setFile({ src: `${testHelpers_spec_2.rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
|
|
38
37
|
class Animal
|
|
39
38
|
end class
|
|
40
39
|
class Duck
|
|
@@ -42,17 +41,18 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
42
41
|
|
|
43
42
|
end class
|
|
44
43
|
`);
|
|
45
|
-
|
|
44
|
+
const classStatements = file.ast.findChildren(reflection_1.isClassStatement);
|
|
45
|
+
(0, chai_config_spec_1.expect)(classStatements.map(x => x.getName(Parser_1.ParseMode.BrighterScript)).sort()).to.eql(['Animal', 'Duck']);
|
|
46
46
|
});
|
|
47
47
|
it('does not cause errors with incomplete class statement', () => {
|
|
48
|
-
program.setFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
|
|
48
|
+
program.setFile({ src: `${testHelpers_spec_2.rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
|
|
49
49
|
class
|
|
50
50
|
`);
|
|
51
51
|
program.validate();
|
|
52
52
|
//if no exception was thrown, this test passes
|
|
53
53
|
});
|
|
54
54
|
it('catches child class missing super call in constructor', () => {
|
|
55
|
-
program.setFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
|
|
55
|
+
program.setFile({ src: `${testHelpers_spec_2.rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
|
|
56
56
|
class Person
|
|
57
57
|
sub new()
|
|
58
58
|
end sub
|
|
@@ -67,8 +67,29 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
67
67
|
DiagnosticMessages_1.DiagnosticMessages.classConstructorMissingSuperCall()
|
|
68
68
|
]);
|
|
69
69
|
});
|
|
70
|
+
it('allows class named `optional`', () => {
|
|
71
|
+
program.setFile('source/main.bs', `
|
|
72
|
+
class optional
|
|
73
|
+
thing = 1
|
|
74
|
+
end class
|
|
75
|
+
`);
|
|
76
|
+
program.validate();
|
|
77
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
78
|
+
});
|
|
79
|
+
it('supports optional fields', () => {
|
|
80
|
+
program.setFile('source/main.bs', `
|
|
81
|
+
class Movie
|
|
82
|
+
name as string
|
|
83
|
+
optional subtitles as string
|
|
84
|
+
public optional isRepeatEnabled as boolean
|
|
85
|
+
private optional wasPlayed
|
|
86
|
+
end class
|
|
87
|
+
`);
|
|
88
|
+
program.validate();
|
|
89
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
90
|
+
});
|
|
70
91
|
it('access modifier is option for override', () => {
|
|
71
|
-
let file = program.setFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
|
|
92
|
+
let file = program.setFile({ src: `${testHelpers_spec_2.rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
|
|
72
93
|
class Animal
|
|
73
94
|
sub move()
|
|
74
95
|
end sub
|
|
@@ -81,12 +102,12 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
81
102
|
`);
|
|
82
103
|
program.validate();
|
|
83
104
|
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
84
|
-
let duckClass = file.
|
|
85
|
-
(0,
|
|
86
|
-
(0,
|
|
105
|
+
let duckClass = file.ast.findChildren(reflection_1.isClassStatement, { walkMode: visitors_1.WalkMode.visitStatements }).find(x => x.name.text.toLowerCase() === 'duck');
|
|
106
|
+
(0, chai_config_spec_1.expect)(duckClass).to.exist;
|
|
107
|
+
(0, chai_config_spec_1.expect)(duckClass.memberMap['move']).to.exist;
|
|
87
108
|
});
|
|
88
109
|
it('supports various namespace configurations', () => {
|
|
89
|
-
program.setFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
|
|
110
|
+
program.setFile({ src: `${testHelpers_spec_2.rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
|
|
90
111
|
class Animal
|
|
91
112
|
sub new()
|
|
92
113
|
bigBird = new Birds.Bird()
|
|
@@ -146,7 +167,7 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
146
167
|
end sub
|
|
147
168
|
end class
|
|
148
169
|
class Duck extends Bird
|
|
149
|
-
sub new()
|
|
170
|
+
sub new(name)
|
|
150
171
|
thing = { m: "m"}
|
|
151
172
|
print thing.m
|
|
152
173
|
name = "Donald" + "Duck"
|
|
@@ -160,18 +181,20 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
160
181
|
it('allows non-`m` expressions and statements before the super call', () => {
|
|
161
182
|
program.setFile('source/main.bs', `
|
|
162
183
|
class Bird
|
|
163
|
-
|
|
184
|
+
name as string
|
|
185
|
+
sub new(name as string)
|
|
186
|
+
m.name = name
|
|
164
187
|
end sub
|
|
165
188
|
end class
|
|
166
189
|
class Duck extends Bird
|
|
167
190
|
sub new()
|
|
168
191
|
m.name = m.name + "Duck"
|
|
169
|
-
super(
|
|
192
|
+
super("Flappy")
|
|
170
193
|
end sub
|
|
171
194
|
end class
|
|
172
195
|
`);
|
|
173
196
|
program.validate();
|
|
174
|
-
(0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.classConstructorIllegalUseOfMBeforeSuperCall()), { range: vscode_languageserver_1.Range.create(
|
|
197
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.classConstructorIllegalUseOfMBeforeSuperCall()), { range: vscode_languageserver_1.Range.create(9, 24, 9, 25) }), Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.classConstructorIllegalUseOfMBeforeSuperCall()), { range: vscode_languageserver_1.Range.create(9, 33, 9, 34) })]);
|
|
175
198
|
});
|
|
176
199
|
});
|
|
177
200
|
describe('transpile', () => {
|
|
@@ -186,23 +209,23 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
186
209
|
end sub
|
|
187
210
|
end class
|
|
188
211
|
`);
|
|
189
|
-
(0,
|
|
190
|
-
await program.
|
|
191
|
-
(0,
|
|
212
|
+
(0, chai_config_spec_1.expect)(file.ast.statements[1].body[0].func.body.statements[0].expression.callee.name.text).to.eql('super');
|
|
213
|
+
await program.getTranspiledFileContents(file.srcPath);
|
|
214
|
+
(0, chai_config_spec_1.expect)(file.ast.statements[1].body[0].func.body.statements[0].expression.callee.name.text).to.eql('super');
|
|
192
215
|
});
|
|
193
|
-
it('follows correct sequence for property initializers', () => {
|
|
194
|
-
testTranspile(`
|
|
216
|
+
it('follows correct sequence for property initializers', async () => {
|
|
217
|
+
await testTranspile(`
|
|
195
218
|
class Animal
|
|
196
219
|
species1 = "Animal"
|
|
197
220
|
sub new()
|
|
198
|
-
print "From Animal: " + m.
|
|
221
|
+
print "From Animal: " + m.species1
|
|
199
222
|
end sub
|
|
200
223
|
end class
|
|
201
224
|
class Duck extends Animal
|
|
202
225
|
species2 = "Duck"
|
|
203
226
|
sub new()
|
|
204
227
|
super()
|
|
205
|
-
print "From Duck: " + m.
|
|
228
|
+
print "From Duck: " + m.species2
|
|
206
229
|
end sub
|
|
207
230
|
end class
|
|
208
231
|
`, `
|
|
@@ -210,7 +233,7 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
210
233
|
instance = {}
|
|
211
234
|
instance.new = sub()
|
|
212
235
|
m.species1 = "Animal"
|
|
213
|
-
print "From Animal: " + m.
|
|
236
|
+
print "From Animal: " + m.species1
|
|
214
237
|
end sub
|
|
215
238
|
return instance
|
|
216
239
|
end function
|
|
@@ -225,7 +248,7 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
225
248
|
instance.new = sub()
|
|
226
249
|
m.super0_new()
|
|
227
250
|
m.species2 = "Duck"
|
|
228
|
-
print "From Duck: " + m.
|
|
251
|
+
print "From Duck: " + m.species2
|
|
229
252
|
end sub
|
|
230
253
|
return instance
|
|
231
254
|
end function
|
|
@@ -236,8 +259,84 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
236
259
|
end function
|
|
237
260
|
`, 'trim', 'source/main.bs');
|
|
238
261
|
});
|
|
239
|
-
it('
|
|
240
|
-
testTranspile(`
|
|
262
|
+
it('allows comments as first line of constructor', async () => {
|
|
263
|
+
await testTranspile(`
|
|
264
|
+
class Animal
|
|
265
|
+
end class
|
|
266
|
+
class Duck extends Animal
|
|
267
|
+
sub new()
|
|
268
|
+
'comment should not cause double super call
|
|
269
|
+
super()
|
|
270
|
+
end sub
|
|
271
|
+
end class
|
|
272
|
+
`, `
|
|
273
|
+
function __Animal_builder()
|
|
274
|
+
instance = {}
|
|
275
|
+
instance.new = sub()
|
|
276
|
+
end sub
|
|
277
|
+
return instance
|
|
278
|
+
end function
|
|
279
|
+
function Animal()
|
|
280
|
+
instance = __Animal_builder()
|
|
281
|
+
instance.new()
|
|
282
|
+
return instance
|
|
283
|
+
end function
|
|
284
|
+
function __Duck_builder()
|
|
285
|
+
instance = __Animal_builder()
|
|
286
|
+
instance.super0_new = instance.new
|
|
287
|
+
instance.new = sub()
|
|
288
|
+
'comment should not cause double super call
|
|
289
|
+
m.super0_new()
|
|
290
|
+
end sub
|
|
291
|
+
return instance
|
|
292
|
+
end function
|
|
293
|
+
function Duck()
|
|
294
|
+
instance = __Duck_builder()
|
|
295
|
+
instance.new()
|
|
296
|
+
return instance
|
|
297
|
+
end function
|
|
298
|
+
`);
|
|
299
|
+
});
|
|
300
|
+
it('does not inject a call to super if one exists', async () => {
|
|
301
|
+
await testTranspile(`
|
|
302
|
+
class Animal
|
|
303
|
+
end class
|
|
304
|
+
class Duck extends Animal
|
|
305
|
+
sub new()
|
|
306
|
+
print "I am a statement which does not use m"
|
|
307
|
+
super()
|
|
308
|
+
end sub
|
|
309
|
+
end class
|
|
310
|
+
`, `
|
|
311
|
+
function __Animal_builder()
|
|
312
|
+
instance = {}
|
|
313
|
+
instance.new = sub()
|
|
314
|
+
end sub
|
|
315
|
+
return instance
|
|
316
|
+
end function
|
|
317
|
+
function Animal()
|
|
318
|
+
instance = __Animal_builder()
|
|
319
|
+
instance.new()
|
|
320
|
+
return instance
|
|
321
|
+
end function
|
|
322
|
+
function __Duck_builder()
|
|
323
|
+
instance = __Animal_builder()
|
|
324
|
+
instance.super0_new = instance.new
|
|
325
|
+
instance.new = sub()
|
|
326
|
+
print "I am a statement which does not use m"
|
|
327
|
+
m.super0_new()
|
|
328
|
+
end sub
|
|
329
|
+
return instance
|
|
330
|
+
end function
|
|
331
|
+
function Duck()
|
|
332
|
+
instance = __Duck_builder()
|
|
333
|
+
instance.new()
|
|
334
|
+
return instance
|
|
335
|
+
end function
|
|
336
|
+
`);
|
|
337
|
+
});
|
|
338
|
+
it('handles class inheritance inferred constructor calls', async () => {
|
|
339
|
+
await testTranspile(`
|
|
241
340
|
class Animal
|
|
242
341
|
className1 = "Animal"
|
|
243
342
|
end class
|
|
@@ -290,8 +389,8 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
290
389
|
end function
|
|
291
390
|
`, undefined, 'source/main.bs');
|
|
292
391
|
});
|
|
293
|
-
it('works with namespaces', () => {
|
|
294
|
-
testTranspile(`
|
|
392
|
+
it('works with namespaces', async () => {
|
|
393
|
+
await testTranspile(`
|
|
295
394
|
namespace Birds.WaterFowl
|
|
296
395
|
class Duck
|
|
297
396
|
end class
|
|
@@ -325,8 +424,8 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
325
424
|
end function
|
|
326
425
|
`, undefined, 'source/main.bs');
|
|
327
426
|
});
|
|
328
|
-
it('works for simple class', () => {
|
|
329
|
-
testTranspile(`
|
|
427
|
+
it('works for simple class', async () => {
|
|
428
|
+
await testTranspile(`
|
|
330
429
|
class Duck
|
|
331
430
|
end class
|
|
332
431
|
`, `
|
|
@@ -343,8 +442,8 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
343
442
|
end function
|
|
344
443
|
`, undefined, 'source/main.bs');
|
|
345
444
|
});
|
|
346
|
-
it('registers the constructor and properly handles its parameters', () => {
|
|
347
|
-
testTranspile(`
|
|
445
|
+
it('registers the constructor and properly handles its parameters', async () => {
|
|
446
|
+
await testTranspile(`
|
|
348
447
|
class Duck
|
|
349
448
|
sub new(name as string, age as integer)
|
|
350
449
|
end sub
|
|
@@ -363,8 +462,8 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
363
462
|
end function
|
|
364
463
|
`, undefined, 'source/main.bs');
|
|
365
464
|
});
|
|
366
|
-
it('properly handles child class constructor override and super calls', () => {
|
|
367
|
-
testTranspile(`
|
|
465
|
+
it('properly handles child class constructor override and super calls', async () => {
|
|
466
|
+
await testTranspile(`
|
|
368
467
|
class Animal
|
|
369
468
|
sub new(name as string)
|
|
370
469
|
end sub
|
|
@@ -409,8 +508,8 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
409
508
|
end function
|
|
410
509
|
`, undefined, 'source/main.bs');
|
|
411
510
|
});
|
|
412
|
-
it('transpiles super in nested blocks', () => {
|
|
413
|
-
testTranspile(`
|
|
511
|
+
it('transpiles super in nested blocks', async () => {
|
|
512
|
+
await testTranspile(`
|
|
414
513
|
class Creature
|
|
415
514
|
sub new(name as string)
|
|
416
515
|
end sub
|
|
@@ -464,7 +563,7 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
464
563
|
end function
|
|
465
564
|
`, 'trim', 'source/main.bs');
|
|
466
565
|
});
|
|
467
|
-
it('properly transpiles classes from outside current namespace', () => {
|
|
566
|
+
it('properly transpiles classes from outside current namespace', async () => {
|
|
468
567
|
addFile('source/Animals.bs', `
|
|
469
568
|
namespace Animals
|
|
470
569
|
class Duck
|
|
@@ -473,7 +572,7 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
473
572
|
class Bird
|
|
474
573
|
end class
|
|
475
574
|
`);
|
|
476
|
-
testTranspile(`
|
|
575
|
+
await testTranspile(`
|
|
477
576
|
namespace Animals
|
|
478
577
|
sub init()
|
|
479
578
|
donaldDuck = new Duck()
|
|
@@ -489,8 +588,8 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
489
588
|
end sub
|
|
490
589
|
`, undefined, 'source/main.bs');
|
|
491
590
|
});
|
|
492
|
-
it('properly transpiles new statement for missing class ', () => {
|
|
493
|
-
testTranspile(`
|
|
591
|
+
it('properly transpiles new statement for missing class ', async () => {
|
|
592
|
+
await testTranspile(`
|
|
494
593
|
sub main()
|
|
495
594
|
bob = new Human()
|
|
496
595
|
end sub
|
|
@@ -500,14 +599,14 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
500
599
|
end sub
|
|
501
600
|
`, undefined, 'source/main.bs', false);
|
|
502
601
|
});
|
|
503
|
-
it('new keyword transpiles correctly', () => {
|
|
602
|
+
it('new keyword transpiles correctly', async () => {
|
|
504
603
|
addFile('source/Animal.bs', `
|
|
505
604
|
class Animal
|
|
506
605
|
sub new(name as string)
|
|
507
606
|
end sub
|
|
508
607
|
end class
|
|
509
608
|
`);
|
|
510
|
-
testTranspile(`
|
|
609
|
+
await testTranspile(`
|
|
511
610
|
sub main()
|
|
512
611
|
a = new Animal("donald")
|
|
513
612
|
end sub
|
|
@@ -517,8 +616,8 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
517
616
|
end sub
|
|
518
617
|
`, undefined, 'source/main.bs');
|
|
519
618
|
});
|
|
520
|
-
it('calls super ', () => {
|
|
521
|
-
const { file } = testTranspile(`
|
|
619
|
+
it('calls super ', async () => {
|
|
620
|
+
const { file } = await testTranspile(`
|
|
522
621
|
class Parent
|
|
523
622
|
sub new()
|
|
524
623
|
end sub
|
|
@@ -555,10 +654,10 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
555
654
|
`, undefined, undefined, false);
|
|
556
655
|
//the AST should not be permanently modified
|
|
557
656
|
const constructor = file.ast.statements[0].body[0];
|
|
558
|
-
(0,
|
|
657
|
+
(0, chai_config_spec_1.expect)(constructor.func.body.statements).to.be.lengthOf(0);
|
|
559
658
|
});
|
|
560
|
-
it('adds field initializers', () => {
|
|
561
|
-
const { file } = testTranspile(`
|
|
659
|
+
it('adds field initializers', async () => {
|
|
660
|
+
const { file } = await testTranspile(`
|
|
562
661
|
class Person
|
|
563
662
|
sub new()
|
|
564
663
|
end sub
|
|
@@ -580,10 +679,10 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
580
679
|
`);
|
|
581
680
|
//the AST should not be permanently modified
|
|
582
681
|
const constructor = file.ast.statements[0].body[0];
|
|
583
|
-
(0,
|
|
682
|
+
(0, chai_config_spec_1.expect)(constructor.func.body.statements).to.be.lengthOf(0);
|
|
584
683
|
});
|
|
585
|
-
it('does not screw up local variable references', () => {
|
|
586
|
-
testTranspile(`
|
|
684
|
+
it('does not screw up local variable references', async () => {
|
|
685
|
+
await testTranspile(`
|
|
587
686
|
class Animal
|
|
588
687
|
sub new(name as string)
|
|
589
688
|
m.name = name
|
|
@@ -690,8 +789,8 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
690
789
|
end sub
|
|
691
790
|
`, 'trim', 'source/main.bs');
|
|
692
791
|
});
|
|
693
|
-
it('calculates the proper super index', () => {
|
|
694
|
-
testTranspile(`
|
|
792
|
+
it('calculates the proper super index', async () => {
|
|
793
|
+
await testTranspile(`
|
|
695
794
|
class Duck
|
|
696
795
|
public sub walk(meters as integer)
|
|
697
796
|
print "Walked " + meters.ToStr() + " meters"
|
|
@@ -739,9 +838,308 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
739
838
|
end function
|
|
740
839
|
`, 'trim', 'source/main.bs');
|
|
741
840
|
});
|
|
841
|
+
it('adds namespacing to constructors on field definitions', async () => {
|
|
842
|
+
await testTranspile(`
|
|
843
|
+
namespace MyNS
|
|
844
|
+
class KlassOne
|
|
845
|
+
other = new KlassTwo()
|
|
846
|
+
end class
|
|
847
|
+
|
|
848
|
+
class KlassTwo
|
|
849
|
+
end class
|
|
850
|
+
end namespace
|
|
851
|
+
`, `
|
|
852
|
+
function __MyNS_KlassOne_builder()
|
|
853
|
+
instance = {}
|
|
854
|
+
instance.new = sub()
|
|
855
|
+
m.other = MyNS_KlassTwo()
|
|
856
|
+
end sub
|
|
857
|
+
return instance
|
|
858
|
+
end function
|
|
859
|
+
function MyNS_KlassOne()
|
|
860
|
+
instance = __MyNS_KlassOne_builder()
|
|
861
|
+
instance.new()
|
|
862
|
+
return instance
|
|
863
|
+
end function
|
|
864
|
+
function __MyNS_KlassTwo_builder()
|
|
865
|
+
instance = {}
|
|
866
|
+
instance.new = sub()
|
|
867
|
+
end sub
|
|
868
|
+
return instance
|
|
869
|
+
end function
|
|
870
|
+
function MyNS_KlassTwo()
|
|
871
|
+
instance = __MyNS_KlassTwo_builder()
|
|
872
|
+
instance.new()
|
|
873
|
+
return instance
|
|
874
|
+
end function
|
|
875
|
+
`, 'trim', 'source/main.bs');
|
|
876
|
+
});
|
|
877
|
+
it('works with enums as field initial values inside a namespace', async () => {
|
|
878
|
+
await testTranspile(`
|
|
879
|
+
namespace MyNS
|
|
880
|
+
class HasEnumKlass
|
|
881
|
+
enumValue = MyEnum.A
|
|
882
|
+
end class
|
|
883
|
+
enum MyEnum
|
|
884
|
+
A = "A"
|
|
885
|
+
B = "B"
|
|
886
|
+
end enum
|
|
887
|
+
end namespace
|
|
888
|
+
`, `
|
|
889
|
+
function __MyNS_HasEnumKlass_builder()
|
|
890
|
+
instance = {}
|
|
891
|
+
instance.new = sub()
|
|
892
|
+
m.enumValue = "A"
|
|
893
|
+
end sub
|
|
894
|
+
return instance
|
|
895
|
+
end function
|
|
896
|
+
function MyNS_HasEnumKlass()
|
|
897
|
+
instance = __MyNS_HasEnumKlass_builder()
|
|
898
|
+
instance.new()
|
|
899
|
+
return instance
|
|
900
|
+
end function
|
|
901
|
+
`, 'trim', 'source/main.bs');
|
|
902
|
+
});
|
|
903
|
+
it('allows enums as super args inside a namespace', async () => {
|
|
904
|
+
await testTranspile(`
|
|
905
|
+
namespace MyNS
|
|
906
|
+
class SubKlass extends SuperKlass
|
|
907
|
+
sub new()
|
|
908
|
+
super(MyEnum.B)
|
|
909
|
+
end sub
|
|
910
|
+
end class
|
|
911
|
+
|
|
912
|
+
class SuperKlass
|
|
913
|
+
sub new(enumVal as MyEnum)
|
|
914
|
+
print enumVal
|
|
915
|
+
end sub
|
|
916
|
+
end class
|
|
917
|
+
|
|
918
|
+
enum MyEnum
|
|
919
|
+
A = "A"
|
|
920
|
+
B = "B"
|
|
921
|
+
end enum
|
|
922
|
+
end namespace
|
|
923
|
+
`, `
|
|
924
|
+
function __MyNS_SubKlass_builder()
|
|
925
|
+
instance = __MyNS_SuperKlass_builder()
|
|
926
|
+
instance.super0_new = instance.new
|
|
927
|
+
instance.new = sub()
|
|
928
|
+
m.super0_new("B")
|
|
929
|
+
end sub
|
|
930
|
+
return instance
|
|
931
|
+
end function
|
|
932
|
+
function MyNS_SubKlass()
|
|
933
|
+
instance = __MyNS_SubKlass_builder()
|
|
934
|
+
instance.new()
|
|
935
|
+
return instance
|
|
936
|
+
end function
|
|
937
|
+
function __MyNS_SuperKlass_builder()
|
|
938
|
+
instance = {}
|
|
939
|
+
instance.new = sub(enumVal as dynamic)
|
|
940
|
+
print enumVal
|
|
941
|
+
end sub
|
|
942
|
+
return instance
|
|
943
|
+
end function
|
|
944
|
+
function MyNS_SuperKlass(enumVal as dynamic)
|
|
945
|
+
instance = __MyNS_SuperKlass_builder()
|
|
946
|
+
instance.new(enumVal)
|
|
947
|
+
return instance
|
|
948
|
+
end function
|
|
949
|
+
`, 'trim', 'source/main.bs');
|
|
950
|
+
});
|
|
951
|
+
it('works with enums as values referenced in a namespace directly', async () => {
|
|
952
|
+
await testTranspile(`
|
|
953
|
+
namespace MyNS
|
|
954
|
+
class HasEnumKlass
|
|
955
|
+
myArray = [true, true] as boolean[]
|
|
956
|
+
sub new()
|
|
957
|
+
m.myArray[MyEnum.A] = true
|
|
958
|
+
m.myArray[MyEnum.B] = false
|
|
959
|
+
end sub
|
|
960
|
+
end class
|
|
961
|
+
enum MyEnum
|
|
962
|
+
A = 0
|
|
963
|
+
B = 1
|
|
964
|
+
end enum
|
|
965
|
+
end namespace
|
|
966
|
+
`, `
|
|
967
|
+
function __MyNS_HasEnumKlass_builder()
|
|
968
|
+
instance = {}
|
|
969
|
+
instance.new = sub()
|
|
970
|
+
m.myArray = [
|
|
971
|
+
true
|
|
972
|
+
true
|
|
973
|
+
]
|
|
974
|
+
m.myArray[0] = true
|
|
975
|
+
m.myArray[1] = false
|
|
976
|
+
end sub
|
|
977
|
+
return instance
|
|
978
|
+
end function
|
|
979
|
+
function MyNS_HasEnumKlass()
|
|
980
|
+
instance = __MyNS_HasEnumKlass_builder()
|
|
981
|
+
instance.new()
|
|
982
|
+
return instance
|
|
983
|
+
end function
|
|
984
|
+
`, 'trim', 'source/main.bs');
|
|
985
|
+
});
|
|
986
|
+
it('works with enums as values referenced in a namespace with namespace', async () => {
|
|
987
|
+
await testTranspile(`
|
|
988
|
+
namespace MyNS
|
|
989
|
+
class HasEnumKlass
|
|
990
|
+
myArray = [true, true] as boolean[]
|
|
991
|
+
sub new()
|
|
992
|
+
m.myArray[MyNS.MyEnum.A] = true
|
|
993
|
+
m.myArray[MyNS.MyEnum.B] = false
|
|
994
|
+
end sub
|
|
995
|
+
end class
|
|
996
|
+
enum MyEnum
|
|
997
|
+
A = 0
|
|
998
|
+
B = 1
|
|
999
|
+
end enum
|
|
1000
|
+
end namespace
|
|
1001
|
+
`, `
|
|
1002
|
+
function __MyNS_HasEnumKlass_builder()
|
|
1003
|
+
instance = {}
|
|
1004
|
+
instance.new = sub()
|
|
1005
|
+
m.myArray = [
|
|
1006
|
+
true
|
|
1007
|
+
true
|
|
1008
|
+
]
|
|
1009
|
+
m.myArray[0] = true
|
|
1010
|
+
m.myArray[1] = false
|
|
1011
|
+
end sub
|
|
1012
|
+
return instance
|
|
1013
|
+
end function
|
|
1014
|
+
function MyNS_HasEnumKlass()
|
|
1015
|
+
instance = __MyNS_HasEnumKlass_builder()
|
|
1016
|
+
instance.new()
|
|
1017
|
+
return instance
|
|
1018
|
+
end function
|
|
1019
|
+
`, 'trim', 'source/main.bs');
|
|
1020
|
+
});
|
|
1021
|
+
it('allows namespaced class function as function parameters', async () => {
|
|
1022
|
+
await testTranspile(`
|
|
1023
|
+
namespace Alpha
|
|
1024
|
+
function foo()
|
|
1025
|
+
return 1
|
|
1026
|
+
end function
|
|
1027
|
+
|
|
1028
|
+
function callSomeFunc(f as function)
|
|
1029
|
+
return f()
|
|
1030
|
+
end function
|
|
1031
|
+
|
|
1032
|
+
sub callFoo()
|
|
1033
|
+
callSomeFunc(foo)
|
|
1034
|
+
end sub
|
|
1035
|
+
end namespace
|
|
1036
|
+
`, `
|
|
1037
|
+
function Alpha_foo()
|
|
1038
|
+
return 1
|
|
1039
|
+
end function
|
|
1040
|
+
|
|
1041
|
+
function Alpha_callSomeFunc(f as function)
|
|
1042
|
+
return f()
|
|
1043
|
+
end function
|
|
1044
|
+
|
|
1045
|
+
sub Alpha_callFoo()
|
|
1046
|
+
Alpha_callSomeFunc(Alpha_foo)
|
|
1047
|
+
end sub
|
|
1048
|
+
`, 'trim', 'source/main.bs');
|
|
1049
|
+
});
|
|
1050
|
+
it('allows namespaced class constructors as function parameters', async () => {
|
|
1051
|
+
await testTranspile(`
|
|
1052
|
+
namespace Alpha
|
|
1053
|
+
class Button
|
|
1054
|
+
end class
|
|
1055
|
+
|
|
1056
|
+
function callSomeFunc(f as function)
|
|
1057
|
+
return f()
|
|
1058
|
+
end function
|
|
1059
|
+
|
|
1060
|
+
sub makeButton()
|
|
1061
|
+
callSomeFunc(Button)
|
|
1062
|
+
end sub
|
|
1063
|
+
end namespace
|
|
1064
|
+
`, `
|
|
1065
|
+
function __Alpha_Button_builder()
|
|
1066
|
+
instance = {}
|
|
1067
|
+
instance.new = sub()
|
|
1068
|
+
end sub
|
|
1069
|
+
return instance
|
|
1070
|
+
end function
|
|
1071
|
+
function Alpha_Button()
|
|
1072
|
+
instance = __Alpha_Button_builder()
|
|
1073
|
+
instance.new()
|
|
1074
|
+
return instance
|
|
1075
|
+
end function
|
|
1076
|
+
|
|
1077
|
+
function Alpha_callSomeFunc(f as function)
|
|
1078
|
+
return f()
|
|
1079
|
+
end function
|
|
1080
|
+
|
|
1081
|
+
sub Alpha_makeButton()
|
|
1082
|
+
Alpha_callSomeFunc(Alpha_Button)
|
|
1083
|
+
end sub
|
|
1084
|
+
`, 'trim', 'source/main.bs');
|
|
1085
|
+
});
|
|
1086
|
+
it('allows class constructors as functions in array', async () => {
|
|
1087
|
+
await testTranspile(`
|
|
1088
|
+
namespace Alpha
|
|
1089
|
+
class Button
|
|
1090
|
+
end class
|
|
1091
|
+
|
|
1092
|
+
class ButtonContainer
|
|
1093
|
+
private button = new Alpha.Button()
|
|
1094
|
+
|
|
1095
|
+
sub new()
|
|
1096
|
+
m.init()
|
|
1097
|
+
end sub
|
|
1098
|
+
|
|
1099
|
+
sub init()
|
|
1100
|
+
button = new Alpha.Button()
|
|
1101
|
+
items = [m.button, button, Alpha.Button]
|
|
1102
|
+
end sub
|
|
1103
|
+
end class
|
|
1104
|
+
end namespace
|
|
1105
|
+
`, `
|
|
1106
|
+
function __Alpha_Button_builder()
|
|
1107
|
+
instance = {}
|
|
1108
|
+
instance.new = sub()
|
|
1109
|
+
end sub
|
|
1110
|
+
return instance
|
|
1111
|
+
end function
|
|
1112
|
+
function Alpha_Button()
|
|
1113
|
+
instance = __Alpha_Button_builder()
|
|
1114
|
+
instance.new()
|
|
1115
|
+
return instance
|
|
1116
|
+
end function
|
|
1117
|
+
function __Alpha_ButtonContainer_builder()
|
|
1118
|
+
instance = {}
|
|
1119
|
+
instance.new = sub()
|
|
1120
|
+
m.button = Alpha_Button()
|
|
1121
|
+
m.init()
|
|
1122
|
+
end sub
|
|
1123
|
+
instance.init = sub()
|
|
1124
|
+
button = Alpha_Button()
|
|
1125
|
+
items = [
|
|
1126
|
+
m.button
|
|
1127
|
+
Alpha_button
|
|
1128
|
+
Alpha_Button
|
|
1129
|
+
]
|
|
1130
|
+
end sub
|
|
1131
|
+
return instance
|
|
1132
|
+
end function
|
|
1133
|
+
function Alpha_ButtonContainer()
|
|
1134
|
+
instance = __Alpha_ButtonContainer_builder()
|
|
1135
|
+
instance.new()
|
|
1136
|
+
return instance
|
|
1137
|
+
end function
|
|
1138
|
+
`, 'trim', 'source/main.bs');
|
|
1139
|
+
});
|
|
742
1140
|
});
|
|
743
1141
|
it('detects using `new` keyword on non-classes', () => {
|
|
744
|
-
program.setFile(
|
|
1142
|
+
program.setFile('source/main.bs', `
|
|
745
1143
|
sub quack()
|
|
746
1144
|
end sub
|
|
747
1145
|
sub main()
|
|
@@ -754,13 +1152,13 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
754
1152
|
]);
|
|
755
1153
|
});
|
|
756
1154
|
it('detects missing call to super', () => {
|
|
757
|
-
program.setFile(
|
|
1155
|
+
program.setFile('source/main.bs', `
|
|
758
1156
|
class Animal
|
|
759
|
-
sub new
|
|
1157
|
+
sub new()
|
|
760
1158
|
end sub
|
|
761
1159
|
end class
|
|
762
1160
|
class Duck extends Animal
|
|
763
|
-
sub new
|
|
1161
|
+
sub new()
|
|
764
1162
|
end sub
|
|
765
1163
|
end class
|
|
766
1164
|
`);
|
|
@@ -770,9 +1168,9 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
770
1168
|
]);
|
|
771
1169
|
});
|
|
772
1170
|
it.skip('detects calls to unknown m methods', () => {
|
|
773
|
-
program.setFile('source/main.
|
|
1171
|
+
program.setFile('source/main.bs', `
|
|
774
1172
|
class Animal
|
|
775
|
-
sub new
|
|
1173
|
+
sub new()
|
|
776
1174
|
m.methodThatDoesNotExist()
|
|
777
1175
|
end sub
|
|
778
1176
|
end class
|
|
@@ -792,7 +1190,7 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
792
1190
|
end class
|
|
793
1191
|
`);
|
|
794
1192
|
program.validate();
|
|
795
|
-
(0,
|
|
1193
|
+
(0, chai_config_spec_1.expect)(program.getDiagnostics().map(x => x.message).sort()).to.eql([
|
|
796
1194
|
DiagnosticMessages_1.DiagnosticMessages.circularReferenceDetected(['Child', 'Parent', 'Child'], 'source').message,
|
|
797
1195
|
DiagnosticMessages_1.DiagnosticMessages.circularReferenceDetected(['Parent', 'Child', 'Parent'], 'source').message
|
|
798
1196
|
]);
|
|
@@ -810,7 +1208,7 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
810
1208
|
end class
|
|
811
1209
|
`);
|
|
812
1210
|
program.validate();
|
|
813
|
-
(0,
|
|
1211
|
+
(0, chai_config_spec_1.expect)(program.getDiagnostics().map(x => x.message).sort()).to.eql([
|
|
814
1212
|
DiagnosticMessages_1.DiagnosticMessages.circularReferenceDetected(['Child', 'Parent', 'Grandchild', 'Child'], 'source').message,
|
|
815
1213
|
DiagnosticMessages_1.DiagnosticMessages.circularReferenceDetected(['Grandchild', 'Child', 'Parent', 'Grandchild'], 'source').message,
|
|
816
1214
|
DiagnosticMessages_1.DiagnosticMessages.circularReferenceDetected(['Parent', 'Grandchild', 'Child', 'Parent'], 'source').message
|
|
@@ -830,10 +1228,10 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
830
1228
|
end function
|
|
831
1229
|
end class
|
|
832
1230
|
`);
|
|
833
|
-
await program.
|
|
834
|
-
fsExtra.emptyDirSync(stagingDir);
|
|
835
|
-
await program.
|
|
836
|
-
(0,
|
|
1231
|
+
await program.build({ stagingDir: testHelpers_spec_2.stagingDir });
|
|
1232
|
+
fsExtra.emptyDirSync(testHelpers_spec_2.stagingDir);
|
|
1233
|
+
await program.build({ stagingDir: testHelpers_spec_2.stagingDir });
|
|
1234
|
+
(0, chai_config_spec_1.expect)(fsExtra.readFileSync((0, util_1.standardizePath) `${testHelpers_spec_2.stagingDir}/source/lib.brs`).toString().trimEnd()).to.eql((0, testHelpers_spec_1.trim) `
|
|
837
1235
|
function __Being_builder()
|
|
838
1236
|
instance = {}
|
|
839
1237
|
instance.new = sub()
|
|
@@ -931,15 +1329,14 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
931
1329
|
public owner as Person
|
|
932
1330
|
end class
|
|
933
1331
|
class Duck extends Bird
|
|
934
|
-
public age = 12.2 'should be integer but
|
|
1332
|
+
public age = 12.2 'should be integer, but a float can be assigned to an int
|
|
935
1333
|
public name = 12 'should be string but is integer
|
|
936
1334
|
public owner as string
|
|
937
1335
|
end class
|
|
938
1336
|
`);
|
|
939
1337
|
program.validate();
|
|
940
1338
|
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
941
|
-
DiagnosticMessages_1.DiagnosticMessages.
|
|
942
|
-
DiagnosticMessages_1.DiagnosticMessages.childFieldTypeNotAssignableToBaseProperty('Duck', 'Bird', 'age', 'float', 'integer'),
|
|
1339
|
+
DiagnosticMessages_1.DiagnosticMessages.cannotFindName('Person'),
|
|
943
1340
|
DiagnosticMessages_1.DiagnosticMessages.childFieldTypeNotAssignableToBaseProperty('Duck', 'Bird', 'name', 'integer', 'string'),
|
|
944
1341
|
DiagnosticMessages_1.DiagnosticMessages.childFieldTypeNotAssignableToBaseProperty('Duck', 'Bird', 'owner', 'string', 'Person')
|
|
945
1342
|
]);
|
|
@@ -1016,13 +1413,13 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
1016
1413
|
end sub
|
|
1017
1414
|
end class
|
|
1018
1415
|
|
|
1019
|
-
|
|
1416
|
+
namespace Vertibrates
|
|
1020
1417
|
class Animal
|
|
1021
1418
|
end class
|
|
1022
|
-
|
|
1023
|
-
|
|
1419
|
+
end namespace
|
|
1420
|
+
`);
|
|
1024
1421
|
program.validate();
|
|
1025
|
-
(0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.
|
|
1422
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.cannotFindName('Animal')), { range: vscode_languageserver_1.Range.create(1, 35, 1, 41) })]);
|
|
1026
1423
|
});
|
|
1027
1424
|
it('non-namespaced parent from within namespace', () => {
|
|
1028
1425
|
program.setFile('source/main.bs', `
|
|
@@ -1031,11 +1428,11 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
1031
1428
|
sub speak()
|
|
1032
1429
|
end sub
|
|
1033
1430
|
end class
|
|
1034
|
-
|
|
1035
|
-
|
|
1431
|
+
end namespace
|
|
1432
|
+
`);
|
|
1036
1433
|
program.validate();
|
|
1037
1434
|
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1038
|
-
DiagnosticMessages_1.DiagnosticMessages.
|
|
1435
|
+
DiagnosticMessages_1.DiagnosticMessages.cannotFindName('Animal')
|
|
1039
1436
|
]);
|
|
1040
1437
|
});
|
|
1041
1438
|
it('non-namespaced name from outside namespace alongside existing namespace', () => {
|
|
@@ -1043,7 +1440,7 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
1043
1440
|
namespace Vertibrates
|
|
1044
1441
|
class Animal
|
|
1045
1442
|
end class
|
|
1046
|
-
|
|
1443
|
+
end namespace
|
|
1047
1444
|
|
|
1048
1445
|
class Duck extends Animal
|
|
1049
1446
|
sub speak()
|
|
@@ -1052,7 +1449,7 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
1052
1449
|
`);
|
|
1053
1450
|
program.validate();
|
|
1054
1451
|
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1055
|
-
DiagnosticMessages_1.DiagnosticMessages.
|
|
1452
|
+
DiagnosticMessages_1.DiagnosticMessages.cannotFindName('Animal')
|
|
1056
1453
|
]);
|
|
1057
1454
|
});
|
|
1058
1455
|
it('namespaced parent class from outside namespace', () => {
|
|
@@ -1069,8 +1466,9 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
1069
1466
|
end class
|
|
1070
1467
|
`);
|
|
1071
1468
|
program.validate();
|
|
1072
|
-
|
|
1073
|
-
|
|
1469
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.cannotFindName('GroundedBird', 'Vertibrates.GroundedBird')), { relatedInformation: [{
|
|
1470
|
+
message: `In scope 'source'`
|
|
1471
|
+
}] })]);
|
|
1074
1472
|
});
|
|
1075
1473
|
it('namespaced parent class from inside namespace', () => {
|
|
1076
1474
|
program.setFile('source/vertibrates.bs', `
|
|
@@ -1088,8 +1486,9 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
1088
1486
|
end namespace
|
|
1089
1487
|
`);
|
|
1090
1488
|
program.validate();
|
|
1091
|
-
|
|
1092
|
-
|
|
1489
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1490
|
+
DiagnosticMessages_1.DiagnosticMessages.cannotFindName('GroundedBird', 'Vertibrates.GroundedBird').message
|
|
1491
|
+
]);
|
|
1093
1492
|
});
|
|
1094
1493
|
});
|
|
1095
1494
|
it('catches newable class without namespace name', () => {
|
|
@@ -1097,15 +1496,15 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
1097
1496
|
namespace NameA.NameB
|
|
1098
1497
|
class Duck
|
|
1099
1498
|
end class
|
|
1100
|
-
|
|
1499
|
+
end namespace
|
|
1101
1500
|
sub main()
|
|
1102
1501
|
' this should be an error because the proper name is NameA.NameB.Duck"
|
|
1103
1502
|
d = new Duck()
|
|
1104
1503
|
end sub
|
|
1105
|
-
|
|
1504
|
+
`);
|
|
1106
1505
|
program.validate();
|
|
1107
1506
|
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1108
|
-
DiagnosticMessages_1.DiagnosticMessages.
|
|
1507
|
+
DiagnosticMessages_1.DiagnosticMessages.cannotFindName('Duck')
|
|
1109
1508
|
]);
|
|
1110
1509
|
});
|
|
1111
1510
|
it('supports newable class namespace inference', () => {
|
|
@@ -1113,11 +1512,11 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
1113
1512
|
namespace NameA.NameB
|
|
1114
1513
|
class Duck
|
|
1115
1514
|
end class
|
|
1116
|
-
|
|
1515
|
+
sub main()
|
|
1117
1516
|
d = new Duck()
|
|
1118
1517
|
end sub
|
|
1119
1518
|
end namespace
|
|
1120
|
-
|
|
1519
|
+
`);
|
|
1121
1520
|
program.validate();
|
|
1122
1521
|
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1123
1522
|
});
|
|
@@ -1126,13 +1525,13 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
1126
1525
|
namespace NameA.NameB
|
|
1127
1526
|
class Animal
|
|
1128
1527
|
end class
|
|
1129
|
-
class Duck extends NameA.NameB.
|
|
1528
|
+
class Duck extends NameA.NameB.AnimalNotDefined
|
|
1130
1529
|
end class
|
|
1131
1530
|
end namespace
|
|
1132
1531
|
`);
|
|
1133
1532
|
program.validate();
|
|
1134
1533
|
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1135
|
-
DiagnosticMessages_1.DiagnosticMessages.
|
|
1534
|
+
DiagnosticMessages_1.DiagnosticMessages.cannotFindName('AnimalNotDefined', 'NameA.NameB.AnimalNotDefined')
|
|
1136
1535
|
]);
|
|
1137
1536
|
});
|
|
1138
1537
|
it('supports omitting namespace prefix for items in same namespace', () => {
|
|
@@ -1142,8 +1541,8 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
1142
1541
|
end class
|
|
1143
1542
|
class Duck extends Animal
|
|
1144
1543
|
end class
|
|
1145
|
-
|
|
1146
|
-
|
|
1544
|
+
end namespace
|
|
1545
|
+
`);
|
|
1147
1546
|
program.validate();
|
|
1148
1547
|
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1149
1548
|
});
|
|
@@ -1155,8 +1554,8 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
1155
1554
|
end class
|
|
1156
1555
|
`);
|
|
1157
1556
|
program.validate();
|
|
1158
|
-
(0, testHelpers_spec_1.
|
|
1159
|
-
DiagnosticMessages_1.DiagnosticMessages.
|
|
1557
|
+
(0, testHelpers_spec_1.expectDiagnosticsIncludes)(program, [
|
|
1558
|
+
DiagnosticMessages_1.DiagnosticMessages.nameCollision('Class', 'Class', 'Animal')
|
|
1160
1559
|
]);
|
|
1161
1560
|
});
|
|
1162
1561
|
it('catches duplicate namespace-level class declarations', () => {
|
|
@@ -1169,8 +1568,8 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
1169
1568
|
end namespace
|
|
1170
1569
|
`);
|
|
1171
1570
|
program.validate();
|
|
1172
|
-
(0, testHelpers_spec_1.
|
|
1173
|
-
DiagnosticMessages_1.DiagnosticMessages.
|
|
1571
|
+
(0, testHelpers_spec_1.expectDiagnosticsIncludes)(program, [
|
|
1572
|
+
DiagnosticMessages_1.DiagnosticMessages.nameCollision('Class', 'Class', 'Animal').message
|
|
1174
1573
|
]);
|
|
1175
1574
|
});
|
|
1176
1575
|
it('catches namespaced class name which is the same as a global class', () => {
|
|
@@ -1178,24 +1577,24 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
1178
1577
|
namespace NameA.NameB
|
|
1179
1578
|
class Animal
|
|
1180
1579
|
end class
|
|
1181
|
-
|
|
1580
|
+
end namespace
|
|
1182
1581
|
class Animal
|
|
1183
1582
|
end class
|
|
1184
1583
|
`);
|
|
1185
1584
|
program.validate();
|
|
1186
1585
|
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1187
|
-
DiagnosticMessages_1.DiagnosticMessages.
|
|
1586
|
+
DiagnosticMessages_1.DiagnosticMessages.nameCollision('Class', 'Class', 'Animal').message
|
|
1188
1587
|
]);
|
|
1189
1588
|
});
|
|
1190
1589
|
it('catches class with same name as function', () => {
|
|
1191
1590
|
program.setFile('source/main.bs', `
|
|
1192
1591
|
class Animal
|
|
1193
1592
|
end class
|
|
1194
|
-
|
|
1593
|
+
sub Animal()
|
|
1195
1594
|
end sub
|
|
1196
|
-
|
|
1595
|
+
`);
|
|
1197
1596
|
program.validate();
|
|
1198
|
-
(0, testHelpers_spec_1.
|
|
1597
|
+
(0, testHelpers_spec_1.expectDiagnosticsIncludes)(program, [
|
|
1199
1598
|
DiagnosticMessages_1.DiagnosticMessages.functionCannotHaveSameNameAsClass('Animal').message
|
|
1200
1599
|
]);
|
|
1201
1600
|
});
|
|
@@ -1203,11 +1602,11 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
1203
1602
|
program.setFile('source/main.bs', `
|
|
1204
1603
|
class ANIMAL
|
|
1205
1604
|
end class
|
|
1206
|
-
|
|
1605
|
+
sub animal()
|
|
1207
1606
|
end sub
|
|
1208
|
-
|
|
1607
|
+
`);
|
|
1209
1608
|
program.validate();
|
|
1210
|
-
(0, testHelpers_spec_1.
|
|
1609
|
+
(0, testHelpers_spec_1.expectDiagnosticsIncludes)(program, [
|
|
1211
1610
|
DiagnosticMessages_1.DiagnosticMessages.functionCannotHaveSameNameAsClass('animal').message
|
|
1212
1611
|
]);
|
|
1213
1612
|
});
|
|
@@ -1215,10 +1614,10 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
1215
1614
|
program.setFile('source/main.bs', `
|
|
1216
1615
|
class Animal
|
|
1217
1616
|
end class
|
|
1218
|
-
|
|
1617
|
+
sub main()
|
|
1219
1618
|
animal = new Animal()
|
|
1220
1619
|
end sub
|
|
1221
|
-
|
|
1620
|
+
`);
|
|
1222
1621
|
program.validate();
|
|
1223
1622
|
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1224
1623
|
DiagnosticMessages_1.DiagnosticMessages.localVarSameNameAsClass('Animal').message
|
|
@@ -1230,21 +1629,21 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
1230
1629
|
end class
|
|
1231
1630
|
|
|
1232
1631
|
class Bar extends Foo
|
|
1233
|
-
sub new
|
|
1632
|
+
sub new()
|
|
1234
1633
|
super()
|
|
1235
1634
|
end sub
|
|
1236
1635
|
end class
|
|
1237
1636
|
`);
|
|
1238
1637
|
program.setFile('source/testclass_no_testdot.bs', `
|
|
1239
1638
|
class BarNoDot extends Foo
|
|
1240
|
-
sub new
|
|
1639
|
+
sub new()
|
|
1241
1640
|
super()
|
|
1242
1641
|
end sub
|
|
1243
1642
|
end class
|
|
1244
1643
|
`);
|
|
1245
1644
|
program.setFile('source/testclass.dot.bs', `
|
|
1246
1645
|
class BarDot extends Foo
|
|
1247
|
-
sub new
|
|
1646
|
+
sub new()
|
|
1248
1647
|
super()
|
|
1249
1648
|
end sub
|
|
1250
1649
|
end class
|
|
@@ -1252,7 +1651,7 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
1252
1651
|
program.validate();
|
|
1253
1652
|
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1254
1653
|
});
|
|
1255
|
-
it('computes correct super index for grandchild class', () => {
|
|
1654
|
+
it('computes correct super index for grandchild class', async () => {
|
|
1256
1655
|
program.setFile('source/main.bs', `
|
|
1257
1656
|
sub Main()
|
|
1258
1657
|
c = new App.ClassC()
|
|
@@ -1266,10 +1665,10 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
1266
1665
|
end class
|
|
1267
1666
|
end namespace
|
|
1268
1667
|
`);
|
|
1269
|
-
testTranspile(`
|
|
1668
|
+
await testTranspile(`
|
|
1270
1669
|
namespace App
|
|
1271
1670
|
class ClassC extends ClassB
|
|
1272
|
-
sub new
|
|
1671
|
+
sub new()
|
|
1273
1672
|
super()
|
|
1274
1673
|
end sub
|
|
1275
1674
|
end class
|
|
@@ -1290,17 +1689,17 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
1290
1689
|
end function
|
|
1291
1690
|
`, 'trim', 'source/App.ClassC.bs');
|
|
1292
1691
|
});
|
|
1293
|
-
it('computes correct super index for namespaced child class and global parent class', () => {
|
|
1692
|
+
it('computes correct super index for namespaced child class and global parent class', async () => {
|
|
1294
1693
|
program.setFile('source/ClassA.bs', `
|
|
1295
1694
|
class ClassA
|
|
1296
1695
|
end class
|
|
1297
1696
|
`);
|
|
1298
|
-
testTranspile(`
|
|
1697
|
+
await testTranspile(`
|
|
1299
1698
|
namespace App
|
|
1300
1699
|
class ClassB extends ClassA
|
|
1301
1700
|
end class
|
|
1302
1701
|
end namespace
|
|
1303
|
-
|
|
1702
|
+
`, `
|
|
1304
1703
|
function __App_ClassB_builder()
|
|
1305
1704
|
instance = __ClassA_builder()
|
|
1306
1705
|
instance.super0_new = instance.new
|
|
@@ -1322,364 +1721,8 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
1322
1721
|
end class
|
|
1323
1722
|
`);
|
|
1324
1723
|
(0, assert_1.doesNotThrow)(() => {
|
|
1325
|
-
file.
|
|
1326
|
-
|
|
1327
|
-
});
|
|
1328
|
-
describe('getHover', () => {
|
|
1329
|
-
const animalClassCode = `
|
|
1330
|
-
class Animal
|
|
1331
|
-
kind as string
|
|
1332
|
-
isHungry as boolean
|
|
1333
|
-
|
|
1334
|
-
sub new (kind as string)
|
|
1335
|
-
m.kind = kind
|
|
1336
|
-
m.isHungry = true ' born hungry
|
|
1337
|
-
end sub
|
|
1338
|
-
|
|
1339
|
-
sub eat(foodAmount as integer)
|
|
1340
|
-
if foodAmount > 100
|
|
1341
|
-
m.isHungry = false
|
|
1342
|
-
end if
|
|
1343
|
-
end sub
|
|
1344
|
-
|
|
1345
|
-
sub sleep()
|
|
1346
|
-
m.isHungry = false
|
|
1347
|
-
end sub
|
|
1348
|
-
|
|
1349
|
-
end class
|
|
1350
|
-
|
|
1351
|
-
class Dog extends Animal
|
|
1352
|
-
breed as string
|
|
1353
|
-
sub new (breed as string)
|
|
1354
|
-
super("Dog")
|
|
1355
|
-
m.breed = breed
|
|
1356
|
-
end sub
|
|
1357
|
-
|
|
1358
|
-
sub snooze()
|
|
1359
|
-
m.sleep()
|
|
1360
|
-
end sub
|
|
1361
|
-
end class
|
|
1362
|
-
|
|
1363
|
-
class DogHouse
|
|
1364
|
-
puppy as Dog
|
|
1365
|
-
sub new (pup as Dog)
|
|
1366
|
-
m.puppy = pup
|
|
1367
|
-
end sub
|
|
1368
|
-
end class
|
|
1369
|
-
|
|
1370
|
-
sub main()
|
|
1371
|
-
snoopy = new Dog("Beagle")
|
|
1372
|
-
biplane = new DogHouse(snoopy)
|
|
1373
|
-
print snoopy.kind ' Dog
|
|
1374
|
-
print snoopy.breed ' Beagle
|
|
1375
|
-
print snoopy.isHungry ' true
|
|
1376
|
-
feedAnimal(biplane.puppy)
|
|
1377
|
-
print snoopy.isHungry ' false
|
|
1378
|
-
end sub
|
|
1379
|
-
|
|
1380
|
-
sub feedAnimal(beast as Animal)
|
|
1381
|
-
beast.eat(100)
|
|
1382
|
-
end sub
|
|
1383
|
-
`;
|
|
1384
|
-
it('correctly parses the file', () => {
|
|
1385
|
-
program.setFile('source/animal.bs', animalClassCode);
|
|
1386
|
-
program.validate();
|
|
1387
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1388
|
-
});
|
|
1389
|
-
it('gets the correct text for m', () => {
|
|
1390
|
-
let animalCode = program.setFile('source/animal.bs', animalClassCode);
|
|
1391
|
-
program.validate();
|
|
1392
|
-
let hover = animalCode.getHover(vscode_languageserver_1.Position.create(6, 21));
|
|
1393
|
-
(0, chai_1.expect)(hover === null || hover === void 0 ? void 0 : hover.contents).to.equal([
|
|
1394
|
-
'```brightscript',
|
|
1395
|
-
'm as Animal',
|
|
1396
|
-
'```'
|
|
1397
|
-
].join('\n'));
|
|
1398
|
-
hover = animalCode.getHover(vscode_languageserver_1.Position.create(26, 20));
|
|
1399
|
-
(0, chai_1.expect)(hover === null || hover === void 0 ? void 0 : hover.contents).to.equal([
|
|
1400
|
-
'```brightscript',
|
|
1401
|
-
'm as Dog',
|
|
1402
|
-
'```'
|
|
1403
|
-
].join('\n'));
|
|
1404
|
-
});
|
|
1405
|
-
it('gets the correct text for m.field', () => {
|
|
1406
|
-
let animalCode = program.setFile('source/animal.bs', animalClassCode);
|
|
1407
|
-
program.validate();
|
|
1408
|
-
let hover = animalCode.getHover(vscode_languageserver_1.Position.create(6, 26));
|
|
1409
|
-
(0, chai_1.expect)(hover === null || hover === void 0 ? void 0 : hover.contents).to.equal([
|
|
1410
|
-
'```brightscript',
|
|
1411
|
-
'Animal.kind as string',
|
|
1412
|
-
'```'
|
|
1413
|
-
].join('\n'));
|
|
1414
|
-
hover = animalCode.getHover(vscode_languageserver_1.Position.create(26, 25));
|
|
1415
|
-
(0, chai_1.expect)(hover === null || hover === void 0 ? void 0 : hover.contents).to.equal([
|
|
1416
|
-
'```brightscript',
|
|
1417
|
-
'Dog.breed as string',
|
|
1418
|
-
'```'
|
|
1419
|
-
].join('\n'));
|
|
1420
|
-
});
|
|
1421
|
-
it('gets the correct text for m.method', () => {
|
|
1422
|
-
let animalCode = program.setFile('source/animal.bs', animalClassCode);
|
|
1423
|
-
program.validate();
|
|
1424
|
-
let hover = animalCode.getHover(vscode_languageserver_1.Position.create(30, 25));
|
|
1425
|
-
(0, chai_1.expect)(hover === null || hover === void 0 ? void 0 : hover.contents).to.equal([
|
|
1426
|
-
'```brightscript',
|
|
1427
|
-
'sub Animal.sleep() as void',
|
|
1428
|
-
'```'
|
|
1429
|
-
].join('\n'));
|
|
1430
|
-
});
|
|
1431
|
-
it('gets the correct text for obj.field', () => {
|
|
1432
|
-
let animalCode = program.setFile('source/animal.brs', animalClassCode);
|
|
1433
|
-
program.validate();
|
|
1434
|
-
let hover = animalCode.getHover(vscode_languageserver_1.Position.create(46, 33));
|
|
1435
|
-
(0, chai_1.expect)(hover).to.exist;
|
|
1436
|
-
//TODO TYPES: This should probably say 'Animal.isHungry ...' because that field is defined in Animal
|
|
1437
|
-
(0, chai_1.expect)(hover === null || hover === void 0 ? void 0 : hover.contents).to.equal([
|
|
1438
|
-
'```brightscript',
|
|
1439
|
-
'Dog.isHungry as boolean',
|
|
1440
|
-
'```'
|
|
1441
|
-
].join('\n'));
|
|
1442
|
-
});
|
|
1443
|
-
it('gets the correct text for obj.method', () => {
|
|
1444
|
-
let animalCode = program.setFile('source/animal.bs', `
|
|
1445
|
-
sub feedAnimal(beast as Animal)
|
|
1446
|
-
beast.eat(100)
|
|
1447
|
-
end sub
|
|
1448
|
-
class Animal
|
|
1449
|
-
sub eat(foodAmount as integer)
|
|
1450
|
-
end sub
|
|
1451
|
-
end class
|
|
1452
|
-
`);
|
|
1453
|
-
program.validate();
|
|
1454
|
-
let hover = animalCode.getHover(vscode_languageserver_1.Position.create(2, 29));
|
|
1455
|
-
(0, chai_1.expect)(hover === null || hover === void 0 ? void 0 : hover.contents).to.equal([
|
|
1456
|
-
'```brightscript',
|
|
1457
|
-
'sub Animal.eat(foodAmount as integer) as void',
|
|
1458
|
-
'```'
|
|
1459
|
-
].join('\n'));
|
|
1460
|
-
});
|
|
1461
|
-
});
|
|
1462
|
-
describe('getHover class members', () => {
|
|
1463
|
-
const testCode = `
|
|
1464
|
-
class Foo
|
|
1465
|
-
sub new (name as string)
|
|
1466
|
-
end sub
|
|
1467
|
-
end class
|
|
1468
|
-
|
|
1469
|
-
class Bar
|
|
1470
|
-
sub doSomething()
|
|
1471
|
-
myFoo = new Foo()
|
|
1472
|
-
end sub
|
|
1473
|
-
|
|
1474
|
-
function getInt() as integer
|
|
1475
|
-
return 1
|
|
1476
|
-
end function
|
|
1477
|
-
end class
|
|
1478
|
-
|
|
1479
|
-
class Buz
|
|
1480
|
-
myInt as integer
|
|
1481
|
-
sub new (i as integer)
|
|
1482
|
-
myInt = i
|
|
1483
|
-
end sub
|
|
1484
|
-
end class
|
|
1485
|
-
|
|
1486
|
-
class Bee extends Buz
|
|
1487
|
-
sub new (i as integer)
|
|
1488
|
-
super(i)
|
|
1489
|
-
end sub
|
|
1490
|
-
|
|
1491
|
-
sub varSameNameAsMember()
|
|
1492
|
-
myInt = 4567
|
|
1493
|
-
print myInt ' should not print m.myInt
|
|
1494
|
-
end sub
|
|
1495
|
-
end class`;
|
|
1496
|
-
it('correctly parses the file', () => {
|
|
1497
|
-
program.setFile('source/fooBar.bs', testCode);
|
|
1498
|
-
program.validate();
|
|
1499
|
-
(0, chai_1.expect)(program.getDiagnostics().length).to.equal(0);
|
|
1500
|
-
});
|
|
1501
|
-
it('gets the correct text for new Class()', () => {
|
|
1502
|
-
let file = program.setFile('source/fooBar.bs', testCode);
|
|
1503
|
-
program.validate();
|
|
1504
|
-
let hover = file.getHover(vscode_languageserver_1.Position.create(8, 34)); // new Foo("hello")
|
|
1505
|
-
(0, chai_1.expect)(hover === null || hover === void 0 ? void 0 : hover.contents).to.equal([
|
|
1506
|
-
'```brightscript',
|
|
1507
|
-
'new Foo(name as string)',
|
|
1508
|
-
'```'
|
|
1509
|
-
].join('\n'));
|
|
1510
|
-
});
|
|
1511
|
-
it('gets the correct text for created object', () => {
|
|
1512
|
-
let file = program.setFile('source/fooBar.bs', testCode);
|
|
1513
|
-
program.validate();
|
|
1514
|
-
let hover = file.getHover(vscode_languageserver_1.Position.create(8, 23)); // myFoo
|
|
1515
|
-
(0, chai_1.expect)(hover === null || hover === void 0 ? void 0 : hover.contents).to.equal([
|
|
1516
|
-
'```brightscript',
|
|
1517
|
-
'myFoo as Foo',
|
|
1518
|
-
'```'
|
|
1519
|
-
].join('\n'));
|
|
1520
|
-
});
|
|
1521
|
-
it('gets the correct text for class declaration', () => {
|
|
1522
|
-
let file = program.setFile('source/fooBar.bs', testCode);
|
|
1523
|
-
program.validate();
|
|
1524
|
-
let hover = file.getHover(vscode_languageserver_1.Position.create(6, 21)); // class Bar
|
|
1525
|
-
(0, chai_1.expect)(hover === null || hover === void 0 ? void 0 : hover.contents).to.equal([
|
|
1526
|
-
'```brightscript',
|
|
1527
|
-
'class Bar',
|
|
1528
|
-
'```'
|
|
1529
|
-
].join('\n'));
|
|
1530
|
-
});
|
|
1531
|
-
it('gets the correct text for class method declaration', () => {
|
|
1532
|
-
let file = program.setFile('source/fooBar.bs', testCode);
|
|
1533
|
-
program.validate();
|
|
1534
|
-
let hover = file.getHover(vscode_languageserver_1.Position.create(11, 29)); // getInt
|
|
1535
|
-
(0, chai_1.expect)(hover === null || hover === void 0 ? void 0 : hover.contents).to.equal([
|
|
1536
|
-
'```brightscript',
|
|
1537
|
-
'function Bar.getInt() as integer',
|
|
1538
|
-
'```'
|
|
1539
|
-
].join('\n'));
|
|
1540
|
-
});
|
|
1541
|
-
it('gets the correct text for class field declaration', () => {
|
|
1542
|
-
let file = program.setFile('source/fooBar.bs', testCode);
|
|
1543
|
-
program.validate();
|
|
1544
|
-
let hover = file.getHover(vscode_languageserver_1.Position.create(17, 20)); // myInt
|
|
1545
|
-
(0, chai_1.expect)(hover === null || hover === void 0 ? void 0 : hover.contents).to.equal([
|
|
1546
|
-
'```brightscript',
|
|
1547
|
-
'Buz.myInt as integer',
|
|
1548
|
-
'```'
|
|
1549
|
-
].join('\n'));
|
|
1550
|
-
});
|
|
1551
|
-
it('gets the correct text for super() call', () => {
|
|
1552
|
-
let file = program.setFile('source/fooBar.bs', testCode);
|
|
1553
|
-
program.validate();
|
|
1554
|
-
let hover = file.getHover(vscode_languageserver_1.Position.create(25, 23)); // super() in Bee.new
|
|
1555
|
-
(0, chai_1.expect)(hover === null || hover === void 0 ? void 0 : hover.contents).to.equal([
|
|
1556
|
-
'```brightscript',
|
|
1557
|
-
'new Buz(i as integer)',
|
|
1558
|
-
'```'
|
|
1559
|
-
].join('\n'));
|
|
1560
|
-
});
|
|
1561
|
-
it('gets the correct text for variable with same name as a member', () => {
|
|
1562
|
-
let file = program.setFile('source/fooBar.bs', testCode);
|
|
1563
|
-
program.validate();
|
|
1564
|
-
let hover = file.getHover(vscode_languageserver_1.Position.create(29, 23)); // myInt in Bee.varSameNameAsMember
|
|
1565
|
-
(0, chai_1.expect)(hover === null || hover === void 0 ? void 0 : hover.contents).to.equal([
|
|
1566
|
-
'```brightscript',
|
|
1567
|
-
'myInt as integer',
|
|
1568
|
-
'```'
|
|
1569
|
-
].join('\n'));
|
|
1570
|
-
});
|
|
1571
|
-
});
|
|
1572
|
-
describe('getSymbolTypeFromToken', () => {
|
|
1573
|
-
const testClassCode = `
|
|
1574
|
-
sub main()
|
|
1575
|
-
c = new KlassC()
|
|
1576
|
-
a = c.b.getA()
|
|
1577
|
-
num = c.b.getA().getInt()
|
|
1578
|
-
c.b.getA().printInt(num)
|
|
1579
|
-
end sub
|
|
1580
|
-
class KlassA
|
|
1581
|
-
function getInt() as integer
|
|
1582
|
-
return 1
|
|
1583
|
-
end function
|
|
1584
|
-
|
|
1585
|
-
sub printInt(i as integer)
|
|
1586
|
-
print i
|
|
1587
|
-
end sub
|
|
1588
|
-
end class
|
|
1589
|
-
|
|
1590
|
-
class KlassB
|
|
1591
|
-
|
|
1592
|
-
function getA() as KlassA
|
|
1593
|
-
return new KlassA()
|
|
1594
|
-
end function
|
|
1595
|
-
end class
|
|
1596
|
-
|
|
1597
|
-
class KlassC
|
|
1598
|
-
public b as KlassB
|
|
1599
|
-
|
|
1600
|
-
sub new ()
|
|
1601
|
-
m.b = new KlassB()
|
|
1602
|
-
end sub
|
|
1603
|
-
end class
|
|
1604
|
-
`;
|
|
1605
|
-
it('correctly parses the file', () => {
|
|
1606
|
-
program.setFile('source/klassTest.bs', testClassCode);
|
|
1607
|
-
program.validate();
|
|
1608
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1609
|
-
});
|
|
1610
|
-
describe('finding tokens', () => {
|
|
1611
|
-
let klassCode;
|
|
1612
|
-
let mainScope;
|
|
1613
|
-
beforeEach(() => {
|
|
1614
|
-
klassCode = program.setFile('source/klassTest.bs', testClassCode);
|
|
1615
|
-
const scopes = program.getScopesForFile(klassCode);
|
|
1616
|
-
(0, chai_1.expect)(scopes.length).to.eql(1);
|
|
1617
|
-
mainScope = scopes[0];
|
|
1618
|
-
mainScope.linkSymbolTable();
|
|
1619
|
-
});
|
|
1620
|
-
afterEach(() => {
|
|
1621
|
-
mainScope.unlinkSymbolTable();
|
|
1622
|
-
});
|
|
1623
|
-
it('gets correct class for m', () => {
|
|
1624
|
-
var _a;
|
|
1625
|
-
const position = vscode_languageserver_1.Position.create(28, 20); // 'm' from m.b = new KlassB()
|
|
1626
|
-
const token = klassCode.parser.getTokenAt(position);
|
|
1627
|
-
(0, chai_1.expect)(token.text).to.equal('m');
|
|
1628
|
-
const func = klassCode.getFunctionExpressionAtPosition(position);
|
|
1629
|
-
let klass = (_a = klassCode.getClassFromToken(token, func, mainScope)) === null || _a === void 0 ? void 0 : _a.item;
|
|
1630
|
-
(0, chai_1.expect)(klass).to.exist;
|
|
1631
|
-
(0, chai_1.expect)(klass.getName(Parser_1.ParseMode.BrighterScript)).to.equal('KlassC');
|
|
1632
|
-
});
|
|
1633
|
-
it('gets correct class for fieldMember', () => {
|
|
1634
|
-
var _a;
|
|
1635
|
-
const position = vscode_languageserver_1.Position.create(28, 23); // 'b' from m.b = new KlassB()
|
|
1636
|
-
const token = klassCode.parser.getTokenAt(position);
|
|
1637
|
-
(0, chai_1.expect)(token.text).to.equal('b');
|
|
1638
|
-
const func = klassCode.getFunctionExpressionAtPosition(position);
|
|
1639
|
-
let klass = (_a = klassCode.getClassFromToken(token, func, mainScope)) === null || _a === void 0 ? void 0 : _a.item;
|
|
1640
|
-
(0, chai_1.expect)(klass).to.exist;
|
|
1641
|
-
(0, chai_1.expect)(klass.getName(Parser_1.ParseMode.BrighterScript)).to.equal('KlassB');
|
|
1642
|
-
});
|
|
1643
|
-
it('gets correct class for variable', () => {
|
|
1644
|
-
var _a;
|
|
1645
|
-
const position = vscode_languageserver_1.Position.create(4, 22); // 'c' from c.b.getA().getInt()
|
|
1646
|
-
const token = klassCode.parser.getTokenAt(position);
|
|
1647
|
-
(0, chai_1.expect)(token.text).to.equal('c');
|
|
1648
|
-
const func = klassCode.getFunctionExpressionAtPosition(position);
|
|
1649
|
-
let klass = (_a = klassCode.getClassFromToken(token, func, mainScope)) === null || _a === void 0 ? void 0 : _a.item;
|
|
1650
|
-
(0, chai_1.expect)(klass).to.exist;
|
|
1651
|
-
(0, chai_1.expect)(klass.getName(Parser_1.ParseMode.BrighterScript)).to.equal('KlassC');
|
|
1652
|
-
});
|
|
1653
|
-
it('gets correct class for variable field', () => {
|
|
1654
|
-
var _a;
|
|
1655
|
-
const position = vscode_languageserver_1.Position.create(3, 23); // 'b' from c.b.getA()
|
|
1656
|
-
const token = klassCode.parser.getTokenAt(position);
|
|
1657
|
-
(0, chai_1.expect)(token.text).to.equal('b');
|
|
1658
|
-
const func = klassCode.getFunctionExpressionAtPosition(position);
|
|
1659
|
-
let klass = (_a = klassCode.getClassFromToken(token, func, mainScope)) === null || _a === void 0 ? void 0 : _a.item;
|
|
1660
|
-
(0, chai_1.expect)(klass).to.exist;
|
|
1661
|
-
(0, chai_1.expect)(klass.getName(Parser_1.ParseMode.BrighterScript)).to.equal('KlassB');
|
|
1662
|
-
});
|
|
1663
|
-
it('gets type and return class for variable function field', () => {
|
|
1664
|
-
const position = vscode_languageserver_1.Position.create(3, 28); // 'getA' from c.b.getA()
|
|
1665
|
-
const token = klassCode.parser.getTokenAt(position);
|
|
1666
|
-
(0, chai_1.expect)(token.text).to.equal('getA');
|
|
1667
|
-
const func = klassCode.getFunctionExpressionAtPosition(position);
|
|
1668
|
-
let { type, symbolContainer } = klassCode.getSymbolTypeFromToken(token, func, mainScope);
|
|
1669
|
-
(0, chai_1.expect)((0, reflection_1.isTypedFunctionType)(type)).to.be.true;
|
|
1670
|
-
(0, chai_1.expect)((0, reflection_1.isCustomType)(symbolContainer)).to.be.true;
|
|
1671
|
-
(0, chai_1.expect)(symbolContainer.name).to.equal('KlassA');
|
|
1672
|
-
});
|
|
1673
|
-
it('gets type and class for field from return value of function', () => {
|
|
1674
|
-
const position = vscode_languageserver_1.Position.create(4, 37); // 'getInt' from c.b.getA().getInt()
|
|
1675
|
-
const token = klassCode.parser.getTokenAt(position);
|
|
1676
|
-
(0, chai_1.expect)(token.text).to.equal('getInt');
|
|
1677
|
-
const func = klassCode.getFunctionExpressionAtPosition(position);
|
|
1678
|
-
let { type, symbolContainer } = klassCode.getSymbolTypeFromToken(token, func, mainScope);
|
|
1679
|
-
(0, chai_1.expect)(type).to.exist;
|
|
1680
|
-
(0, chai_1.expect)((0, reflection_1.isTypedFunctionType)(type)).to.be.true;
|
|
1681
|
-
(0, chai_1.expect)(symbolContainer).to.be.undefined; // getInt() returns integer - no class reference at this point
|
|
1682
|
-
});
|
|
1724
|
+
const classStatements = file.ast.findChildren(reflection_1.isClassStatement);
|
|
1725
|
+
classStatements[0]['getParentClassIndex'](new BrsTranspileState_1.BrsTranspileState(file));
|
|
1683
1726
|
});
|
|
1684
1727
|
});
|
|
1685
1728
|
it('does not crash when child has field with same name as sub in parent', () => {
|
|
@@ -1687,7 +1730,7 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
1687
1730
|
class Parent
|
|
1688
1731
|
public function helloWorld()
|
|
1689
1732
|
end function
|
|
1690
|
-
|
|
1733
|
+
end class
|
|
1691
1734
|
class Child extends Parent
|
|
1692
1735
|
public helloWorld as string
|
|
1693
1736
|
end class
|
|
@@ -1702,28 +1745,28 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
1702
1745
|
class Child extends Parent
|
|
1703
1746
|
public function helloWorld()
|
|
1704
1747
|
end function
|
|
1705
|
-
|
|
1748
|
+
end class
|
|
1706
1749
|
`);
|
|
1707
1750
|
program.validate();
|
|
1708
1751
|
});
|
|
1709
|
-
it
|
|
1752
|
+
it('detects calling class constructors with too many parameters', () => {
|
|
1710
1753
|
program.setFile('source/main.bs', `
|
|
1711
1754
|
class Parameterless
|
|
1712
|
-
sub new
|
|
1755
|
+
sub new()
|
|
1713
1756
|
end sub
|
|
1714
1757
|
end class
|
|
1715
1758
|
|
|
1716
1759
|
class OneParam
|
|
1717
|
-
sub new
|
|
1760
|
+
sub new(param1)
|
|
1718
1761
|
end sub
|
|
1719
1762
|
end class
|
|
1720
1763
|
|
|
1721
|
-
|
|
1764
|
+
sub main()
|
|
1722
1765
|
c1 = new Parameterless(1)
|
|
1723
1766
|
c2 = new OneParam(1, 2)
|
|
1724
1767
|
c2 = new OneParam()
|
|
1725
1768
|
end sub
|
|
1726
|
-
|
|
1769
|
+
`);
|
|
1727
1770
|
program.validate();
|
|
1728
1771
|
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1729
1772
|
DiagnosticMessages_1.DiagnosticMessages.mismatchArgumentCount(0, 1),
|