brighterscript 1.0.0-alpha.50 → 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 +3 -0
- package/bsconfig.schema.json +75 -0
- package/dist/BsConfig.d.ts +90 -5
- package/dist/CodeActionUtil.d.ts +17 -0
- package/dist/CodeActionUtil.js.map +1 -1
- package/dist/CommentFlagProcessor.d.ts +16 -12
- package/dist/CommentFlagProcessor.js +141 -59
- package/dist/CommentFlagProcessor.js.map +1 -1
- package/dist/CrossScopeValidator.js +13 -5
- package/dist/CrossScopeValidator.js.map +1 -1
- package/dist/DiagnosticManager.d.ts +1 -0
- package/dist/DiagnosticManager.js +25 -9
- package/dist/DiagnosticManager.js.map +1 -1
- package/dist/DiagnosticMessages.d.ts +61 -17
- package/dist/DiagnosticMessages.js +78 -24
- package/dist/DiagnosticMessages.js.map +1 -1
- package/dist/LanguageServer.d.ts +39 -2
- package/dist/LanguageServer.js +142 -5
- package/dist/LanguageServer.js.map +1 -1
- package/dist/Program.d.ts +62 -1
- package/dist/Program.js +185 -13
- package/dist/Program.js.map +1 -1
- package/dist/ProgramBuilder.d.ts +1 -8
- package/dist/ProgramBuilder.js +31 -11
- package/dist/ProgramBuilder.js.map +1 -1
- package/dist/Scope.d.ts +87 -6
- package/dist/Scope.js +76 -31
- 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/SymbolTable.d.ts +9 -2
- package/dist/SymbolTable.js +24 -14
- package/dist/SymbolTable.js.map +1 -1
- package/dist/astUtils/CachedLookups.js +3 -0
- package/dist/astUtils/CachedLookups.js.map +1 -1
- package/dist/astUtils/reflection.d.ts +4 -1
- package/dist/astUtils/reflection.js +24 -4
- package/dist/astUtils/reflection.js.map +1 -1
- package/dist/astUtils/visitors.d.ts +2 -1
- package/dist/astUtils/visitors.js.map +1 -1
- package/dist/bscPlugin/BscPlugin.d.ts +4 -2
- package/dist/bscPlugin/BscPlugin.js +10 -2
- package/dist/bscPlugin/BscPlugin.js.map +1 -1
- package/dist/bscPlugin/CallExpressionInfo.d.ts +1 -1
- package/dist/bscPlugin/CallExpressionInfo.js +1 -2
- package/dist/bscPlugin/CallExpressionInfo.js.map +1 -1
- package/dist/bscPlugin/FileWriter.d.ts +13 -0
- package/dist/bscPlugin/FileWriter.js +56 -1
- package/dist/bscPlugin/FileWriter.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.d.ts +106 -5
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +630 -126
- 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 +1 -1
- package/dist/bscPlugin/completions/CompletionsProcessor.js +5 -5
- package/dist/bscPlugin/completions/CompletionsProcessor.js.map +1 -1
- package/dist/bscPlugin/definition/DefinitionProvider.js +8 -0
- package/dist/bscPlugin/definition/DefinitionProvider.js.map +1 -1
- package/dist/bscPlugin/hover/HoverProcessor.js +11 -3
- package/dist/bscPlugin/hover/HoverProcessor.js.map +1 -1
- 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/serialize/FileSerializer.d.ts +1 -1
- package/dist/bscPlugin/serialize/FileSerializer.js +12 -7
- package/dist/bscPlugin/serialize/FileSerializer.js.map +1 -1
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.d.ts +7 -0
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js +87 -1
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js.map +1 -1
- package/dist/bscPlugin/validation/BrsFileValidator.d.ts +14 -0
- package/dist/bscPlugin/validation/BrsFileValidator.js +97 -21
- package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -1
- package/dist/bscPlugin/validation/ScopeValidator.d.ts +17 -0
- package/dist/bscPlugin/validation/ScopeValidator.js +162 -4
- package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -1
- package/dist/bscPlugin/validation/XmlFileValidator.js +14 -0
- package/dist/bscPlugin/validation/XmlFileValidator.js.map +1 -1
- package/dist/cli.js +13 -0
- package/dist/cli.js.map +1 -1
- package/dist/diagnosticUtils.d.ts +51 -1
- package/dist/diagnosticUtils.js +222 -1
- package/dist/diagnosticUtils.js.map +1 -1
- package/dist/files/BrsFile.d.ts +18 -2
- package/dist/files/BrsFile.js +87 -6
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/XmlFile.js +2 -1
- package/dist/files/XmlFile.js.map +1 -1
- package/dist/interfaces.d.ts +68 -23
- package/dist/interfaces.js.map +1 -1
- package/dist/lexer/Lexer.js +4 -5
- package/dist/lexer/Lexer.js.map +1 -1
- package/dist/lexer/Token.d.ts +1 -1
- package/dist/lexer/TokenKind.d.ts +8 -0
- package/dist/lexer/TokenKind.js +21 -1
- package/dist/lexer/TokenKind.js.map +1 -1
- package/dist/lsp/LspProject.d.ts +49 -1
- package/dist/lsp/Project.d.ts +33 -1
- package/dist/lsp/Project.js +129 -4
- package/dist/lsp/Project.js.map +1 -1
- package/dist/lsp/ProjectManager.d.ts +48 -2
- package/dist/lsp/ProjectManager.js +152 -9
- package/dist/lsp/ProjectManager.js.map +1 -1
- package/dist/lsp/worker/WorkerThreadProject.d.ts +27 -2
- package/dist/lsp/worker/WorkerThreadProject.js +16 -0
- package/dist/lsp/worker/WorkerThreadProject.js.map +1 -1
- package/dist/parser/AstNode.d.ts +3 -1
- package/dist/parser/AstNode.js +2 -0
- package/dist/parser/AstNode.js.map +1 -1
- package/dist/parser/Expression.d.ts +54 -5
- package/dist/parser/Expression.js +112 -7
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Parser.d.ts +24 -1
- package/dist/parser/Parser.js +180 -41
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/SGParser.d.ts +1 -0
- package/dist/parser/SGParser.js +9 -0
- package/dist/parser/SGParser.js.map +1 -1
- package/dist/parser/Statement.d.ts +6 -1
- package/dist/parser/Statement.js +22 -14
- package/dist/parser/Statement.js.map +1 -1
- package/dist/parser/TranspileState.d.ts +4 -2
- package/dist/parser/TranspileState.js +10 -4
- package/dist/parser/TranspileState.js.map +1 -1
- package/dist/roku-types/data.json +210 -3
- package/dist/types/ArrayType.js +6 -1
- package/dist/types/ArrayType.js.map +1 -1
- package/dist/types/BooleanType.js +1 -1
- package/dist/types/BooleanType.js.map +1 -1
- package/dist/types/CallFuncableType.d.ts +1 -1
- package/dist/types/ClassType.js +3 -0
- package/dist/types/ClassType.js.map +1 -1
- package/dist/types/ComponentType.js +3 -0
- package/dist/types/ComponentType.js.map +1 -1
- package/dist/types/EnumType.js +3 -0
- package/dist/types/EnumType.js.map +1 -1
- package/dist/types/IntersectionType.js +3 -0
- package/dist/types/IntersectionType.js.map +1 -1
- package/dist/types/ReferenceType.js +6 -0
- package/dist/types/ReferenceType.js.map +1 -1
- package/dist/types/TypeStatementType.d.ts +1 -0
- package/dist/types/TypeStatementType.js +12 -1
- package/dist/types/TypeStatementType.js.map +1 -1
- package/dist/types/TypedFunctionType.js +20 -10
- package/dist/types/TypedFunctionType.js.map +1 -1
- package/dist/types/UnionType.js +3 -0
- package/dist/types/UnionType.js.map +1 -1
- package/dist/types/helpers.js +6 -0
- package/dist/types/helpers.js.map +1 -1
- package/dist/util.d.ts +42 -3
- package/dist/util.js +131 -7
- package/dist/util.js.map +1 -1
- package/package.json +24 -26
- package/dist/astUtils/CachedLookups.spec.d.ts +0 -1
- package/dist/astUtils/CachedLookups.spec.js +0 -39
- package/dist/astUtils/CachedLookups.spec.js.map +0 -1
- package/dist/astUtils/Editor.spec.d.ts +0 -1
- package/dist/astUtils/Editor.spec.js +0 -258
- package/dist/astUtils/Editor.spec.js.map +0 -1
- package/dist/astUtils/creators.spec.d.ts +0 -1
- package/dist/astUtils/creators.spec.js +0 -21
- package/dist/astUtils/creators.spec.js.map +0 -1
- package/dist/astUtils/reflection.spec.d.ts +0 -1
- package/dist/astUtils/reflection.spec.js +0 -392
- 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 -1432
- 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 -311
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +0 -1
- package/dist/bscPlugin/completions/CompletionsProcessor.spec.d.ts +0 -1
- package/dist/bscPlugin/completions/CompletionsProcessor.spec.js +0 -2512
- package/dist/bscPlugin/completions/CompletionsProcessor.spec.js.map +0 -1
- package/dist/bscPlugin/definition/DefinitionProvider.spec.d.ts +0 -1
- package/dist/bscPlugin/definition/DefinitionProvider.spec.js +0 -87
- package/dist/bscPlugin/definition/DefinitionProvider.spec.js.map +0 -1
- package/dist/bscPlugin/hover/HoverProcessor.spec.d.ts +0 -1
- package/dist/bscPlugin/hover/HoverProcessor.spec.js +0 -991
- package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +0 -1
- package/dist/bscPlugin/references/ReferencesProvider.spec.d.ts +0 -1
- package/dist/bscPlugin/references/ReferencesProvider.spec.js +0 -51
- package/dist/bscPlugin/references/ReferencesProvider.spec.js.map +0 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.d.ts +0 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js +0 -564
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +0 -1
- package/dist/bscPlugin/serialize/BslibInjector.spec.d.ts +0 -1
- package/dist/bscPlugin/serialize/BslibInjector.spec.js +0 -33
- package/dist/bscPlugin/serialize/BslibInjector.spec.js.map +0 -1
- package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.d.ts +0 -1
- package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.js +0 -291
- package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.js.map +0 -1
- package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.d.ts +0 -1
- package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.js +0 -245
- package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.js.map +0 -1
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.d.ts +0 -1
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.js +0 -75
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.js.map +0 -1
- package/dist/bscPlugin/validation/BrsFileValidator.spec.d.ts +0 -1
- package/dist/bscPlugin/validation/BrsFileValidator.spec.js +0 -1517
- package/dist/bscPlugin/validation/BrsFileValidator.spec.js.map +0 -1
- package/dist/bscPlugin/validation/ScopeValidator.spec.d.ts +0 -1
- package/dist/bscPlugin/validation/ScopeValidator.spec.js +0 -6135
- package/dist/bscPlugin/validation/ScopeValidator.spec.js.map +0 -1
- package/dist/common/Sequencer.spec.d.ts +0 -1
- package/dist/common/Sequencer.spec.js +0 -75
- package/dist/common/Sequencer.spec.js.map +0 -1
- package/dist/files/BrsFile.Class.spec.d.ts +0 -1
- package/dist/files/BrsFile.Class.spec.js +0 -2035
- 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 -5848
- package/dist/files/BrsFile.spec.js.map +0 -1
- package/dist/files/LazyFileData.spec.d.ts +0 -1
- package/dist/files/LazyFileData.spec.js +0 -27
- package/dist/files/LazyFileData.spec.js.map +0 -1
- package/dist/files/XmlFile.spec.d.ts +0 -1
- package/dist/files/XmlFile.spec.js +0 -1173
- 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 -251
- package/dist/files/tests/imports.spec.js.map +0 -1
- package/dist/files/tests/optionalChaning.spec.d.ts +0 -1
- package/dist/files/tests/optionalChaning.spec.js +0 -152
- package/dist/files/tests/optionalChaning.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 -1345
- package/dist/lexer/Lexer.spec.js.map +0 -1
- package/dist/lsp/ActionQueue.spec.d.ts +0 -1
- package/dist/lsp/ActionQueue.spec.js +0 -80
- package/dist/lsp/ActionQueue.spec.js.map +0 -1
- package/dist/lsp/DocumentManager.spec.d.ts +0 -1
- package/dist/lsp/DocumentManager.spec.js +0 -103
- package/dist/lsp/DocumentManager.spec.js.map +0 -1
- package/dist/lsp/PathFilterer.spec.d.ts +0 -1
- package/dist/lsp/PathFilterer.spec.js +0 -182
- package/dist/lsp/PathFilterer.spec.js.map +0 -1
- package/dist/lsp/Project.spec.d.ts +0 -1
- package/dist/lsp/Project.spec.js +0 -267
- package/dist/lsp/Project.spec.js.map +0 -1
- package/dist/lsp/ProjectManager.spec.d.ts +0 -1
- package/dist/lsp/ProjectManager.spec.js +0 -913
- package/dist/lsp/ProjectManager.spec.js.map +0 -1
- package/dist/lsp/worker/MessageHandler.spec.d.ts +0 -1
- package/dist/lsp/worker/MessageHandler.spec.js +0 -64
- package/dist/lsp/worker/MessageHandler.spec.js.map +0 -1
- package/dist/lsp/worker/WorkerPool.spec.d.ts +0 -1
- package/dist/lsp/worker/WorkerPool.spec.js +0 -59
- package/dist/lsp/worker/WorkerPool.spec.js.map +0 -1
- package/dist/lsp/worker/WorkerThreadProject.spec.d.ts +0 -2
- package/dist/lsp/worker/WorkerThreadProject.spec.js +0 -71
- package/dist/lsp/worker/WorkerThreadProject.spec.js.map +0 -1
- package/dist/parser/AstNode.spec.d.ts +0 -1
- package/dist/parser/AstNode.spec.js +0 -1455
- package/dist/parser/AstNode.spec.js.map +0 -1
- package/dist/parser/BrightScriptDocParser.spec.d.ts +0 -1
- package/dist/parser/BrightScriptDocParser.spec.js +0 -310
- package/dist/parser/BrightScriptDocParser.spec.js.map +0 -1
- package/dist/parser/Expression.spec.d.ts +0 -1
- package/dist/parser/Expression.spec.js +0 -40
- package/dist/parser/Expression.spec.js.map +0 -1
- package/dist/parser/Parser.Class.spec.d.ts +0 -1
- package/dist/parser/Parser.Class.spec.js +0 -520
- package/dist/parser/Parser.Class.spec.js.map +0 -1
- package/dist/parser/Parser.spec.d.ts +0 -6
- package/dist/parser/Parser.spec.js +0 -2802
- 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 -130
- package/dist/parser/SGParser.spec.js.map +0 -1
- package/dist/parser/Statement.spec.d.ts +0 -1
- package/dist/parser/Statement.spec.js +0 -191
- package/dist/parser/Statement.spec.js.map +0 -1
- package/dist/parser/tests/Parser.spec.d.ts +0 -12
- package/dist/parser/tests/Parser.spec.js +0 -29
- 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 -169
- 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 -140
- 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 -694
- 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 -114
- 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 -107
- 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 -304
- 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 -342
- 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 -90
- 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 -252
- 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 -412
- 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 -302
- 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 -346
- 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 -111
- 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 -165
- package/dist/parser/tests/expression/Primary.spec.js.map +0 -1
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.d.ts +0 -1
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +0 -171
- package/dist/parser/tests/expression/RegexLiteralExpression.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 -389
- 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 -878
- package/dist/parser/tests/expression/TernaryExpression.spec.js.map +0 -1
- package/dist/parser/tests/expression/TypeExpression.spec.d.ts +0 -1
- package/dist/parser/tests/expression/TypeExpression.spec.js +0 -126
- package/dist/parser/tests/expression/TypeExpression.spec.js.map +0 -1
- package/dist/parser/tests/expression/UnaryExpression.spec.d.ts +0 -1
- package/dist/parser/tests/expression/UnaryExpression.spec.js +0 -52
- package/dist/parser/tests/expression/UnaryExpression.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/ConstStatement.spec.d.ts +0 -1
- package/dist/parser/tests/statement/ConstStatement.spec.js +0 -500
- package/dist/parser/tests/statement/ConstStatement.spec.js.map +0 -1
- package/dist/parser/tests/statement/Continue.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Continue.spec.js +0 -119
- package/dist/parser/tests/statement/Continue.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 -114
- 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 -80
- package/dist/parser/tests/statement/Dim.spec.js.map +0 -1
- package/dist/parser/tests/statement/Enum.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Enum.spec.js +0 -744
- package/dist/parser/tests/statement/Enum.spec.js.map +0 -1
- package/dist/parser/tests/statement/For.spec.d.ts +0 -1
- package/dist/parser/tests/statement/For.spec.js +0 -45
- package/dist/parser/tests/statement/For.spec.js.map +0 -1
- package/dist/parser/tests/statement/ForEach.spec.d.ts +0 -1
- package/dist/parser/tests/statement/ForEach.spec.js +0 -36
- package/dist/parser/tests/statement/ForEach.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 -343
- 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 -51
- 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 -120
- package/dist/parser/tests/statement/Increment.spec.js.map +0 -1
- package/dist/parser/tests/statement/InterfaceStatement.spec.d.ts +0 -1
- package/dist/parser/tests/statement/InterfaceStatement.spec.js +0 -110
- package/dist/parser/tests/statement/InterfaceStatement.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 -292
- 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 -200
- 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 -97
- 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 -232
- 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 -38
- 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 -38
- 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 -151
- package/dist/parser/tests/statement/TryCatch.spec.js.map +0 -1
- package/dist/preprocessor/Manifest.spec.d.ts +0 -1
- package/dist/preprocessor/Manifest.spec.js +0 -80
- package/dist/preprocessor/Manifest.spec.js.map +0 -1
- package/dist/types/ArrayType.spec.d.ts +0 -1
- package/dist/types/ArrayType.spec.js +0 -58
- 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 -18
- package/dist/types/BooleanType.spec.js.map +0 -1
- package/dist/types/BuiltInInterfaceAdder.spec.d.ts +0 -1
- package/dist/types/BuiltInInterfaceAdder.spec.js +0 -115
- package/dist/types/BuiltInInterfaceAdder.spec.js.map +0 -1
- package/dist/types/ClassType.spec.d.ts +0 -1
- package/dist/types/ClassType.spec.js +0 -76
- package/dist/types/ClassType.spec.js.map +0 -1
- package/dist/types/DoubleType.spec.d.ts +0 -1
- package/dist/types/DoubleType.spec.js +0 -20
- 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 -23
- package/dist/types/DynamicType.spec.js.map +0 -1
- package/dist/types/EnumType.spec.d.ts +0 -1
- package/dist/types/EnumType.spec.js +0 -33
- package/dist/types/EnumType.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/IntegerType.spec.d.ts +0 -1
- package/dist/types/IntegerType.spec.js +0 -16
- package/dist/types/IntegerType.spec.js.map +0 -1
- package/dist/types/InterfaceType.spec.d.ts +0 -1
- package/dist/types/InterfaceType.spec.js +0 -227
- package/dist/types/InterfaceType.spec.js.map +0 -1
- package/dist/types/IntersectionType.spec.d.ts +0 -1
- package/dist/types/IntersectionType.spec.js +0 -150
- package/dist/types/IntersectionType.spec.js.map +0 -1
- package/dist/types/InvalidType.spec.d.ts +0 -1
- package/dist/types/InvalidType.spec.js +0 -16
- package/dist/types/InvalidType.spec.js.map +0 -1
- package/dist/types/LongIntegerType.spec.d.ts +0 -1
- package/dist/types/LongIntegerType.spec.js +0 -18
- 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/ReferenceType.spec.d.ts +0 -1
- package/dist/types/ReferenceType.spec.js +0 -151
- package/dist/types/ReferenceType.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/TypedFunctionType.spec.d.ts +0 -1
- package/dist/types/TypedFunctionType.spec.js +0 -122
- package/dist/types/TypedFunctionType.spec.js.map +0 -1
- package/dist/types/UnionType.spec.d.ts +0 -1
- package/dist/types/UnionType.spec.js +0 -205
- package/dist/types/UnionType.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/types/helper.spec.d.ts +0 -1
- package/dist/types/helper.spec.js +0 -174
- package/dist/types/helper.spec.js.map +0 -1
- package/dist/types/roFunctionType.spec.d.ts +0 -1
- package/dist/types/roFunctionType.spec.js +0 -20
- package/dist/types/roFunctionType.spec.js.map +0 -1
|
@@ -1,2035 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const sinonImport = require("sinon");
|
|
4
|
-
const Program_1 = require("../Program");
|
|
5
|
-
const chai_config_spec_1 = require("../chai-config.spec");
|
|
6
|
-
const DiagnosticMessages_1 = require("../DiagnosticMessages");
|
|
7
|
-
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
8
|
-
const Parser_1 = require("../parser/Parser");
|
|
9
|
-
const testHelpers_spec_1 = require("../testHelpers.spec");
|
|
10
|
-
const util_1 = require("../util");
|
|
11
|
-
const fsExtra = require("fs-extra");
|
|
12
|
-
const BrsTranspileState_1 = require("../parser/BrsTranspileState");
|
|
13
|
-
const assert_1 = require("assert");
|
|
14
|
-
const testHelpers_spec_2 = require("../testHelpers.spec");
|
|
15
|
-
const reflection_1 = require("../astUtils/reflection");
|
|
16
|
-
const visitors_1 = require("../astUtils/visitors");
|
|
17
|
-
let sinon = sinonImport.createSandbox();
|
|
18
|
-
describe('BrsFile BrighterScript classes', () => {
|
|
19
|
-
let program;
|
|
20
|
-
let testTranspile = (0, testHelpers_spec_1.getTestTranspile)(() => [program, testHelpers_spec_2.rootDir]);
|
|
21
|
-
beforeEach(() => {
|
|
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, outDir: testHelpers_spec_2.outDir });
|
|
25
|
-
});
|
|
26
|
-
afterEach(() => {
|
|
27
|
-
sinon.restore();
|
|
28
|
-
program.dispose();
|
|
29
|
-
fsExtra.ensureDirSync(testHelpers_spec_2.tempDir);
|
|
30
|
-
fsExtra.emptyDirSync(testHelpers_spec_2.tempDir);
|
|
31
|
-
});
|
|
32
|
-
function addFile(relativePath, text) {
|
|
33
|
-
return program.setFile({ src: `${testHelpers_spec_2.rootDir}/${relativePath}`, dest: relativePath }, text);
|
|
34
|
-
}
|
|
35
|
-
it('detects all classes after parse', () => {
|
|
36
|
-
let file = program.setFile({ src: `${testHelpers_spec_2.rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
|
|
37
|
-
class Animal
|
|
38
|
-
end class
|
|
39
|
-
class Duck
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
end class
|
|
43
|
-
`);
|
|
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
|
-
});
|
|
47
|
-
it('does not cause errors with incomplete class statement', () => {
|
|
48
|
-
program.setFile({ src: `${testHelpers_spec_2.rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
|
|
49
|
-
class
|
|
50
|
-
`);
|
|
51
|
-
program.validate();
|
|
52
|
-
//if no exception was thrown, this test passes
|
|
53
|
-
});
|
|
54
|
-
it('catches child class missing super call in constructor', () => {
|
|
55
|
-
program.setFile({ src: `${testHelpers_spec_2.rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
|
|
56
|
-
class Person
|
|
57
|
-
sub new()
|
|
58
|
-
end sub
|
|
59
|
-
end class
|
|
60
|
-
class Infant extends Person
|
|
61
|
-
sub new()
|
|
62
|
-
end sub
|
|
63
|
-
end class
|
|
64
|
-
`);
|
|
65
|
-
program.validate();
|
|
66
|
-
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
67
|
-
DiagnosticMessages_1.DiagnosticMessages.classConstructorMissingSuperCall()
|
|
68
|
-
]);
|
|
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
|
-
});
|
|
91
|
-
it('access modifier is option for override', () => {
|
|
92
|
-
let file = program.setFile({ src: `${testHelpers_spec_2.rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
|
|
93
|
-
class Animal
|
|
94
|
-
sub move()
|
|
95
|
-
end sub
|
|
96
|
-
end class
|
|
97
|
-
|
|
98
|
-
class Duck extends Animal
|
|
99
|
-
override sub move()
|
|
100
|
-
end sub
|
|
101
|
-
end class
|
|
102
|
-
`);
|
|
103
|
-
program.validate();
|
|
104
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
105
|
-
let duckClass = file.ast.findChildren(reflection_1.isClassStatement, { walkMode: visitors_1.WalkMode.visitStatements }).find(x => x.tokens.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;
|
|
108
|
-
});
|
|
109
|
-
it('supports various namespace configurations', () => {
|
|
110
|
-
program.setFile({ src: `${testHelpers_spec_2.rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
|
|
111
|
-
class Animal
|
|
112
|
-
sub new()
|
|
113
|
-
bigBird = new Birds.Bird()
|
|
114
|
-
donald = new Birds.Duck()
|
|
115
|
-
end sub
|
|
116
|
-
end class
|
|
117
|
-
|
|
118
|
-
namespace Birds
|
|
119
|
-
class Bird
|
|
120
|
-
sub new()
|
|
121
|
-
dog = new Animal()
|
|
122
|
-
donald = new Duck()
|
|
123
|
-
end sub
|
|
124
|
-
end class
|
|
125
|
-
class Duck
|
|
126
|
-
end class
|
|
127
|
-
end namespace
|
|
128
|
-
`);
|
|
129
|
-
program.validate();
|
|
130
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
131
|
-
});
|
|
132
|
-
describe('super', () => {
|
|
133
|
-
it('always requires super call in child constructor', () => {
|
|
134
|
-
program.setFile('source/main.bs', `
|
|
135
|
-
class Bird
|
|
136
|
-
end class
|
|
137
|
-
class Duck extends Bird
|
|
138
|
-
sub new()
|
|
139
|
-
end sub
|
|
140
|
-
end class
|
|
141
|
-
`);
|
|
142
|
-
program.validate();
|
|
143
|
-
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
144
|
-
DiagnosticMessages_1.DiagnosticMessages.classConstructorMissingSuperCall()
|
|
145
|
-
]);
|
|
146
|
-
});
|
|
147
|
-
it('requires super call in child when parent has own `new` method', () => {
|
|
148
|
-
program.setFile('source/main.bs', `
|
|
149
|
-
class Bird
|
|
150
|
-
sub new()
|
|
151
|
-
end sub
|
|
152
|
-
end class
|
|
153
|
-
class Duck extends Bird
|
|
154
|
-
sub new()
|
|
155
|
-
end sub
|
|
156
|
-
end class
|
|
157
|
-
`);
|
|
158
|
-
program.validate();
|
|
159
|
-
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
160
|
-
DiagnosticMessages_1.DiagnosticMessages.classConstructorMissingSuperCall()
|
|
161
|
-
]);
|
|
162
|
-
});
|
|
163
|
-
it('allows non-`m` expressions and statements before the super call', () => {
|
|
164
|
-
program.setFile('source/main.bs', `
|
|
165
|
-
class Bird
|
|
166
|
-
sub new(name)
|
|
167
|
-
end sub
|
|
168
|
-
end class
|
|
169
|
-
class Duck extends Bird
|
|
170
|
-
sub new(name)
|
|
171
|
-
thing = { m: "m"}
|
|
172
|
-
print thing.m
|
|
173
|
-
name = "Donald" + "Duck"
|
|
174
|
-
super(name)
|
|
175
|
-
end sub
|
|
176
|
-
end class
|
|
177
|
-
`);
|
|
178
|
-
program.validate();
|
|
179
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
180
|
-
});
|
|
181
|
-
it('allows non-`m` expressions and statements before the super call', () => {
|
|
182
|
-
program.setFile('source/main.bs', `
|
|
183
|
-
class Bird
|
|
184
|
-
name as string
|
|
185
|
-
sub new(name as string)
|
|
186
|
-
m.name = name
|
|
187
|
-
end sub
|
|
188
|
-
end class
|
|
189
|
-
class Duck extends Bird
|
|
190
|
-
sub new()
|
|
191
|
-
m.name = m.name + "Duck"
|
|
192
|
-
super("Flappy")
|
|
193
|
-
end sub
|
|
194
|
-
end class
|
|
195
|
-
`);
|
|
196
|
-
program.validate();
|
|
197
|
-
(0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.classConstructorIllegalUseOfMBeforeSuperCall()), { location: { range: vscode_languageserver_1.Range.create(9, 24, 9, 25) } }), Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.classConstructorIllegalUseOfMBeforeSuperCall()), { location: { range: vscode_languageserver_1.Range.create(9, 33, 9, 34) } })]);
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
describe('transpile', () => {
|
|
201
|
-
it('does not mess with AST when injecting `super()` call', async () => {
|
|
202
|
-
const file = program.setFile('source/classes.bs', `
|
|
203
|
-
class Parent
|
|
204
|
-
end class
|
|
205
|
-
|
|
206
|
-
class Child extends parent
|
|
207
|
-
sub new()
|
|
208
|
-
super()
|
|
209
|
-
end sub
|
|
210
|
-
end class
|
|
211
|
-
`);
|
|
212
|
-
(0, chai_config_spec_1.expect)(file.ast.statements[1].body[0].func.body.statements[0].expression.callee.tokens.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.tokens.name.text).to.eql('super');
|
|
215
|
-
});
|
|
216
|
-
it('follows correct sequence for property initializers', async () => {
|
|
217
|
-
await testTranspile(`
|
|
218
|
-
class Animal
|
|
219
|
-
species1 = "Animal"
|
|
220
|
-
sub new()
|
|
221
|
-
print "From Animal: " + m.species1
|
|
222
|
-
end sub
|
|
223
|
-
end class
|
|
224
|
-
class Duck extends Animal
|
|
225
|
-
species2 = "Duck"
|
|
226
|
-
sub new()
|
|
227
|
-
super()
|
|
228
|
-
print "From Duck: " + m.species2
|
|
229
|
-
end sub
|
|
230
|
-
end class
|
|
231
|
-
`, `
|
|
232
|
-
sub __Animal_method_new()
|
|
233
|
-
m.species1 = "Animal"
|
|
234
|
-
print "From Animal: " + m.species1
|
|
235
|
-
end sub
|
|
236
|
-
function __Animal_builder()
|
|
237
|
-
instance = {}
|
|
238
|
-
instance.new = __Animal_method_new
|
|
239
|
-
return instance
|
|
240
|
-
end function
|
|
241
|
-
function Animal()
|
|
242
|
-
instance = __Animal_builder()
|
|
243
|
-
instance.new()
|
|
244
|
-
return instance
|
|
245
|
-
end function
|
|
246
|
-
sub __Duck_method_new()
|
|
247
|
-
m.super0_new()
|
|
248
|
-
m.species2 = "Duck"
|
|
249
|
-
print "From Duck: " + m.species2
|
|
250
|
-
end sub
|
|
251
|
-
function __Duck_builder()
|
|
252
|
-
instance = __Animal_builder()
|
|
253
|
-
instance.super0_new = instance.new
|
|
254
|
-
instance.new = __Duck_method_new
|
|
255
|
-
return instance
|
|
256
|
-
end function
|
|
257
|
-
function Duck()
|
|
258
|
-
instance = __Duck_builder()
|
|
259
|
-
instance.new()
|
|
260
|
-
return instance
|
|
261
|
-
end function
|
|
262
|
-
`, 'trim', 'source/main.bs');
|
|
263
|
-
});
|
|
264
|
-
it('allows comments as first line of constructor', async () => {
|
|
265
|
-
await testTranspile(`
|
|
266
|
-
class Animal
|
|
267
|
-
end class
|
|
268
|
-
class Duck extends Animal
|
|
269
|
-
sub new()
|
|
270
|
-
'comment should not cause double super call
|
|
271
|
-
super()
|
|
272
|
-
end sub
|
|
273
|
-
end class
|
|
274
|
-
`, `
|
|
275
|
-
sub __Animal_method_new()
|
|
276
|
-
end sub
|
|
277
|
-
function __Animal_builder()
|
|
278
|
-
instance = {}
|
|
279
|
-
instance.new = __Animal_method_new
|
|
280
|
-
return instance
|
|
281
|
-
end function
|
|
282
|
-
function Animal()
|
|
283
|
-
instance = __Animal_builder()
|
|
284
|
-
instance.new()
|
|
285
|
-
return instance
|
|
286
|
-
end function
|
|
287
|
-
sub __Duck_method_new()
|
|
288
|
-
'comment should not cause double super call
|
|
289
|
-
m.super0_new()
|
|
290
|
-
end sub
|
|
291
|
-
function __Duck_builder()
|
|
292
|
-
instance = __Animal_builder()
|
|
293
|
-
instance.super0_new = instance.new
|
|
294
|
-
instance.new = __Duck_method_new
|
|
295
|
-
return instance
|
|
296
|
-
end function
|
|
297
|
-
function Duck()
|
|
298
|
-
instance = __Duck_builder()
|
|
299
|
-
instance.new()
|
|
300
|
-
return instance
|
|
301
|
-
end function
|
|
302
|
-
`);
|
|
303
|
-
});
|
|
304
|
-
it('does not inject a call to super if one exists', async () => {
|
|
305
|
-
await testTranspile(`
|
|
306
|
-
class Animal
|
|
307
|
-
end class
|
|
308
|
-
class Duck extends Animal
|
|
309
|
-
sub new()
|
|
310
|
-
print "I am a statement which does not use m"
|
|
311
|
-
super()
|
|
312
|
-
end sub
|
|
313
|
-
end class
|
|
314
|
-
`, `
|
|
315
|
-
sub __Animal_method_new()
|
|
316
|
-
end sub
|
|
317
|
-
function __Animal_builder()
|
|
318
|
-
instance = {}
|
|
319
|
-
instance.new = __Animal_method_new
|
|
320
|
-
return instance
|
|
321
|
-
end function
|
|
322
|
-
function Animal()
|
|
323
|
-
instance = __Animal_builder()
|
|
324
|
-
instance.new()
|
|
325
|
-
return instance
|
|
326
|
-
end function
|
|
327
|
-
sub __Duck_method_new()
|
|
328
|
-
print "I am a statement which does not use m"
|
|
329
|
-
m.super0_new()
|
|
330
|
-
end sub
|
|
331
|
-
function __Duck_builder()
|
|
332
|
-
instance = __Animal_builder()
|
|
333
|
-
instance.super0_new = instance.new
|
|
334
|
-
instance.new = __Duck_method_new
|
|
335
|
-
return instance
|
|
336
|
-
end function
|
|
337
|
-
function Duck()
|
|
338
|
-
instance = __Duck_builder()
|
|
339
|
-
instance.new()
|
|
340
|
-
return instance
|
|
341
|
-
end function
|
|
342
|
-
`);
|
|
343
|
-
});
|
|
344
|
-
it('handles class inheritance inferred constructor calls', async () => {
|
|
345
|
-
await testTranspile(`
|
|
346
|
-
class Animal
|
|
347
|
-
className1 = "Animal"
|
|
348
|
-
end class
|
|
349
|
-
class Duck extends Animal
|
|
350
|
-
className2 = "Duck"
|
|
351
|
-
end class
|
|
352
|
-
class BabyDuck extends Duck
|
|
353
|
-
className3 = "BabyDuck"
|
|
354
|
-
end class
|
|
355
|
-
`, `
|
|
356
|
-
sub __Animal_method_new()
|
|
357
|
-
m.className1 = "Animal"
|
|
358
|
-
end sub
|
|
359
|
-
function __Animal_builder()
|
|
360
|
-
instance = {}
|
|
361
|
-
instance.new = __Animal_method_new
|
|
362
|
-
return instance
|
|
363
|
-
end function
|
|
364
|
-
function Animal()
|
|
365
|
-
instance = __Animal_builder()
|
|
366
|
-
instance.new()
|
|
367
|
-
return instance
|
|
368
|
-
end function
|
|
369
|
-
sub __Duck_method_new()
|
|
370
|
-
m.super0_new()
|
|
371
|
-
m.className2 = "Duck"
|
|
372
|
-
end sub
|
|
373
|
-
function __Duck_builder()
|
|
374
|
-
instance = __Animal_builder()
|
|
375
|
-
instance.super0_new = instance.new
|
|
376
|
-
instance.new = __Duck_method_new
|
|
377
|
-
return instance
|
|
378
|
-
end function
|
|
379
|
-
function Duck()
|
|
380
|
-
instance = __Duck_builder()
|
|
381
|
-
instance.new()
|
|
382
|
-
return instance
|
|
383
|
-
end function
|
|
384
|
-
sub __BabyDuck_method_new()
|
|
385
|
-
m.super1_new()
|
|
386
|
-
m.className3 = "BabyDuck"
|
|
387
|
-
end sub
|
|
388
|
-
function __BabyDuck_builder()
|
|
389
|
-
instance = __Duck_builder()
|
|
390
|
-
instance.super1_new = instance.new
|
|
391
|
-
instance.new = __BabyDuck_method_new
|
|
392
|
-
return instance
|
|
393
|
-
end function
|
|
394
|
-
function BabyDuck()
|
|
395
|
-
instance = __BabyDuck_builder()
|
|
396
|
-
instance.new()
|
|
397
|
-
return instance
|
|
398
|
-
end function
|
|
399
|
-
`, undefined, 'source/main.bs');
|
|
400
|
-
});
|
|
401
|
-
it('works with namespaces', async () => {
|
|
402
|
-
await testTranspile(`
|
|
403
|
-
namespace Birds.WaterFowl
|
|
404
|
-
class Duck
|
|
405
|
-
end class
|
|
406
|
-
class BabyDuck extends Duck
|
|
407
|
-
end class
|
|
408
|
-
end namespace
|
|
409
|
-
`, `
|
|
410
|
-
sub __Birds_WaterFowl_Duck_method_new()
|
|
411
|
-
end sub
|
|
412
|
-
function __Birds_WaterFowl_Duck_builder()
|
|
413
|
-
instance = {}
|
|
414
|
-
instance.new = __Birds_WaterFowl_Duck_method_new
|
|
415
|
-
return instance
|
|
416
|
-
end function
|
|
417
|
-
function Birds_WaterFowl_Duck()
|
|
418
|
-
instance = __Birds_WaterFowl_Duck_builder()
|
|
419
|
-
instance.new()
|
|
420
|
-
return instance
|
|
421
|
-
end function
|
|
422
|
-
sub __Birds_WaterFowl_BabyDuck_method_new()
|
|
423
|
-
m.super0_new()
|
|
424
|
-
end sub
|
|
425
|
-
function __Birds_WaterFowl_BabyDuck_builder()
|
|
426
|
-
instance = __Birds_WaterFowl_Duck_builder()
|
|
427
|
-
instance.super0_new = instance.new
|
|
428
|
-
instance.new = __Birds_WaterFowl_BabyDuck_method_new
|
|
429
|
-
return instance
|
|
430
|
-
end function
|
|
431
|
-
function Birds_WaterFowl_BabyDuck()
|
|
432
|
-
instance = __Birds_WaterFowl_BabyDuck_builder()
|
|
433
|
-
instance.new()
|
|
434
|
-
return instance
|
|
435
|
-
end function
|
|
436
|
-
`, undefined, 'source/main.bs');
|
|
437
|
-
});
|
|
438
|
-
it('works for simple class', async () => {
|
|
439
|
-
await testTranspile(`
|
|
440
|
-
class Duck
|
|
441
|
-
end class
|
|
442
|
-
`, `
|
|
443
|
-
sub __Duck_method_new()
|
|
444
|
-
end sub
|
|
445
|
-
function __Duck_builder()
|
|
446
|
-
instance = {}
|
|
447
|
-
instance.new = __Duck_method_new
|
|
448
|
-
return instance
|
|
449
|
-
end function
|
|
450
|
-
function Duck()
|
|
451
|
-
instance = __Duck_builder()
|
|
452
|
-
instance.new()
|
|
453
|
-
return instance
|
|
454
|
-
end function
|
|
455
|
-
`, undefined, 'source/main.bs');
|
|
456
|
-
});
|
|
457
|
-
it('inherits the parameters of the last known constructor', async () => {
|
|
458
|
-
await testTranspile(`
|
|
459
|
-
class Animal
|
|
460
|
-
sub new(p1)
|
|
461
|
-
end sub
|
|
462
|
-
end class
|
|
463
|
-
class Bird extends Animal
|
|
464
|
-
end class
|
|
465
|
-
class Duck extends Bird
|
|
466
|
-
sub new(p1, p2)
|
|
467
|
-
super(p1)
|
|
468
|
-
m.p2 = p2
|
|
469
|
-
end sub
|
|
470
|
-
private p2 as dynamic
|
|
471
|
-
end class
|
|
472
|
-
class BabyDuck extends Duck
|
|
473
|
-
end class
|
|
474
|
-
`, `
|
|
475
|
-
sub __Animal_method_new(p1)
|
|
476
|
-
end sub
|
|
477
|
-
function __Animal_builder()
|
|
478
|
-
instance = {}
|
|
479
|
-
instance.new = __Animal_method_new
|
|
480
|
-
return instance
|
|
481
|
-
end function
|
|
482
|
-
function Animal(p1)
|
|
483
|
-
instance = __Animal_builder()
|
|
484
|
-
instance.new(p1)
|
|
485
|
-
return instance
|
|
486
|
-
end function
|
|
487
|
-
sub __Bird_method_new(p1)
|
|
488
|
-
m.super0_new(p1)
|
|
489
|
-
end sub
|
|
490
|
-
function __Bird_builder()
|
|
491
|
-
instance = __Animal_builder()
|
|
492
|
-
instance.super0_new = instance.new
|
|
493
|
-
instance.new = __Bird_method_new
|
|
494
|
-
return instance
|
|
495
|
-
end function
|
|
496
|
-
function Bird(p1)
|
|
497
|
-
instance = __Bird_builder()
|
|
498
|
-
instance.new(p1)
|
|
499
|
-
return instance
|
|
500
|
-
end function
|
|
501
|
-
sub __Duck_method_new(p1, p2)
|
|
502
|
-
m.super1_new(p1)
|
|
503
|
-
m.p2 = invalid
|
|
504
|
-
m.p2 = p2
|
|
505
|
-
end sub
|
|
506
|
-
function __Duck_builder()
|
|
507
|
-
instance = __Bird_builder()
|
|
508
|
-
instance.super1_new = instance.new
|
|
509
|
-
instance.new = __Duck_method_new
|
|
510
|
-
return instance
|
|
511
|
-
end function
|
|
512
|
-
function Duck(p1, p2)
|
|
513
|
-
instance = __Duck_builder()
|
|
514
|
-
instance.new(p1, p2)
|
|
515
|
-
return instance
|
|
516
|
-
end function
|
|
517
|
-
sub __BabyDuck_method_new(p1, p2)
|
|
518
|
-
m.super2_new(p1, p2)
|
|
519
|
-
end sub
|
|
520
|
-
function __BabyDuck_builder()
|
|
521
|
-
instance = __Duck_builder()
|
|
522
|
-
instance.super2_new = instance.new
|
|
523
|
-
instance.new = __BabyDuck_method_new
|
|
524
|
-
return instance
|
|
525
|
-
end function
|
|
526
|
-
function BabyDuck(p1, p2)
|
|
527
|
-
instance = __BabyDuck_builder()
|
|
528
|
-
instance.new(p1, p2)
|
|
529
|
-
return instance
|
|
530
|
-
end function
|
|
531
|
-
`);
|
|
532
|
-
});
|
|
533
|
-
it('registers the constructor and properly handles its parameters', async () => {
|
|
534
|
-
await testTranspile(`
|
|
535
|
-
class Duck
|
|
536
|
-
sub new(name as string, age as integer)
|
|
537
|
-
end sub
|
|
538
|
-
end class
|
|
539
|
-
`, `
|
|
540
|
-
sub __Duck_method_new(name as string, age as integer)
|
|
541
|
-
end sub
|
|
542
|
-
function __Duck_builder()
|
|
543
|
-
instance = {}
|
|
544
|
-
instance.new = __Duck_method_new
|
|
545
|
-
return instance
|
|
546
|
-
end function
|
|
547
|
-
function Duck(name as string, age as integer)
|
|
548
|
-
instance = __Duck_builder()
|
|
549
|
-
instance.new(name, age)
|
|
550
|
-
return instance
|
|
551
|
-
end function
|
|
552
|
-
`, undefined, 'source/main.bs');
|
|
553
|
-
});
|
|
554
|
-
it('properly handles child class constructor override and super calls', async () => {
|
|
555
|
-
await testTranspile(`
|
|
556
|
-
class Animal
|
|
557
|
-
sub new(name as string)
|
|
558
|
-
end sub
|
|
559
|
-
|
|
560
|
-
sub DoSomething()
|
|
561
|
-
end sub
|
|
562
|
-
end class
|
|
563
|
-
|
|
564
|
-
class Duck extends Animal
|
|
565
|
-
sub new(name as string, age as integer)
|
|
566
|
-
super(name)
|
|
567
|
-
super.DoSomething()
|
|
568
|
-
end sub
|
|
569
|
-
end class
|
|
570
|
-
`, `
|
|
571
|
-
sub __Animal_method_new(name as string)
|
|
572
|
-
end sub
|
|
573
|
-
sub __Animal_method_DoSomething()
|
|
574
|
-
end sub
|
|
575
|
-
function __Animal_builder()
|
|
576
|
-
instance = {}
|
|
577
|
-
instance.new = __Animal_method_new
|
|
578
|
-
instance.DoSomething = __Animal_method_DoSomething
|
|
579
|
-
return instance
|
|
580
|
-
end function
|
|
581
|
-
function Animal(name as string)
|
|
582
|
-
instance = __Animal_builder()
|
|
583
|
-
instance.new(name)
|
|
584
|
-
return instance
|
|
585
|
-
end function
|
|
586
|
-
sub __Duck_method_new(name as string, age as integer)
|
|
587
|
-
m.super0_new(name)
|
|
588
|
-
m.super0_DoSomething()
|
|
589
|
-
end sub
|
|
590
|
-
function __Duck_builder()
|
|
591
|
-
instance = __Animal_builder()
|
|
592
|
-
instance.super0_new = instance.new
|
|
593
|
-
instance.new = __Duck_method_new
|
|
594
|
-
return instance
|
|
595
|
-
end function
|
|
596
|
-
function Duck(name as string, age as integer)
|
|
597
|
-
instance = __Duck_builder()
|
|
598
|
-
instance.new(name, age)
|
|
599
|
-
return instance
|
|
600
|
-
end function
|
|
601
|
-
`, undefined, 'source/main.bs');
|
|
602
|
-
});
|
|
603
|
-
it('transpiles super in nested blocks', async () => {
|
|
604
|
-
await testTranspile(`
|
|
605
|
-
class Creature
|
|
606
|
-
sub new(name as string)
|
|
607
|
-
end sub
|
|
608
|
-
function sayHello(text)
|
|
609
|
-
? text
|
|
610
|
-
end function
|
|
611
|
-
end class
|
|
612
|
-
|
|
613
|
-
class Duck extends Creature
|
|
614
|
-
override function sayHello(text)
|
|
615
|
-
text = "The duck says " + text
|
|
616
|
-
if text <> invalid
|
|
617
|
-
super.sayHello(text)
|
|
618
|
-
end if
|
|
619
|
-
end function
|
|
620
|
-
end class
|
|
621
|
-
`, `
|
|
622
|
-
sub __Creature_method_new(name as string)
|
|
623
|
-
end sub
|
|
624
|
-
function __Creature_method_sayHello(text)
|
|
625
|
-
? text
|
|
626
|
-
end function
|
|
627
|
-
function __Creature_builder()
|
|
628
|
-
instance = {}
|
|
629
|
-
instance.new = __Creature_method_new
|
|
630
|
-
instance.sayHello = __Creature_method_sayHello
|
|
631
|
-
return instance
|
|
632
|
-
end function
|
|
633
|
-
function Creature(name as string)
|
|
634
|
-
instance = __Creature_builder()
|
|
635
|
-
instance.new(name)
|
|
636
|
-
return instance
|
|
637
|
-
end function
|
|
638
|
-
sub __Duck_method_new(name as string)
|
|
639
|
-
m.super0_new(name)
|
|
640
|
-
end sub
|
|
641
|
-
function __Duck_method_sayHello(text)
|
|
642
|
-
text = "The duck says " + text
|
|
643
|
-
if text <> invalid
|
|
644
|
-
m.super0_sayHello(text)
|
|
645
|
-
end if
|
|
646
|
-
end function
|
|
647
|
-
function __Duck_builder()
|
|
648
|
-
instance = __Creature_builder()
|
|
649
|
-
instance.super0_new = instance.new
|
|
650
|
-
instance.new = __Duck_method_new
|
|
651
|
-
instance.super0_sayHello = instance.sayHello
|
|
652
|
-
instance.sayHello = __Duck_method_sayHello
|
|
653
|
-
return instance
|
|
654
|
-
end function
|
|
655
|
-
function Duck(name as string)
|
|
656
|
-
instance = __Duck_builder()
|
|
657
|
-
instance.new(name)
|
|
658
|
-
return instance
|
|
659
|
-
end function
|
|
660
|
-
`, 'trim', 'source/main.bs');
|
|
661
|
-
});
|
|
662
|
-
it('properly transpiles classes from outside current namespace', async () => {
|
|
663
|
-
addFile('source/Animals.bs', `
|
|
664
|
-
namespace Animals
|
|
665
|
-
class Duck
|
|
666
|
-
end class
|
|
667
|
-
end namespace
|
|
668
|
-
class Bird
|
|
669
|
-
end class
|
|
670
|
-
`);
|
|
671
|
-
await testTranspile(`
|
|
672
|
-
namespace Animals
|
|
673
|
-
sub init()
|
|
674
|
-
donaldDuck = new Duck()
|
|
675
|
-
daffyDuck = new Animals.Duck()
|
|
676
|
-
bigBird = new Bird()
|
|
677
|
-
end sub
|
|
678
|
-
end namespace
|
|
679
|
-
`, `
|
|
680
|
-
sub Animals_init()
|
|
681
|
-
donaldDuck = Animals_Duck()
|
|
682
|
-
daffyDuck = Animals_Duck()
|
|
683
|
-
bigBird = Bird()
|
|
684
|
-
end sub
|
|
685
|
-
`, undefined, 'source/main.bs');
|
|
686
|
-
});
|
|
687
|
-
it('properly transpiles new statement for missing class ', async () => {
|
|
688
|
-
await testTranspile(`
|
|
689
|
-
sub main()
|
|
690
|
-
bob = new Human()
|
|
691
|
-
end sub
|
|
692
|
-
`, `
|
|
693
|
-
sub main()
|
|
694
|
-
bob = Human()
|
|
695
|
-
end sub
|
|
696
|
-
`, undefined, 'source/main.bs', false);
|
|
697
|
-
});
|
|
698
|
-
it('new keyword transpiles correctly', async () => {
|
|
699
|
-
addFile('source/Animal.bs', `
|
|
700
|
-
class Animal
|
|
701
|
-
sub new(name as string)
|
|
702
|
-
end sub
|
|
703
|
-
end class
|
|
704
|
-
`);
|
|
705
|
-
await testTranspile(`
|
|
706
|
-
sub main()
|
|
707
|
-
a = new Animal("donald")
|
|
708
|
-
end sub
|
|
709
|
-
`, `
|
|
710
|
-
sub main()
|
|
711
|
-
a = Animal("donald")
|
|
712
|
-
end sub
|
|
713
|
-
`, undefined, 'source/main.bs');
|
|
714
|
-
});
|
|
715
|
-
it('calls super ', async () => {
|
|
716
|
-
const { file } = await testTranspile(`
|
|
717
|
-
class Parent
|
|
718
|
-
sub new()
|
|
719
|
-
end sub
|
|
720
|
-
end class
|
|
721
|
-
class Child extends Parent
|
|
722
|
-
sub new()
|
|
723
|
-
end sub
|
|
724
|
-
end class
|
|
725
|
-
`, `
|
|
726
|
-
sub __Parent_method_new()
|
|
727
|
-
end sub
|
|
728
|
-
function __Parent_builder()
|
|
729
|
-
instance = {}
|
|
730
|
-
instance.new = __Parent_method_new
|
|
731
|
-
return instance
|
|
732
|
-
end function
|
|
733
|
-
function Parent()
|
|
734
|
-
instance = __Parent_builder()
|
|
735
|
-
instance.new()
|
|
736
|
-
return instance
|
|
737
|
-
end function
|
|
738
|
-
sub __Child_method_new()
|
|
739
|
-
m.super0_new()
|
|
740
|
-
end sub
|
|
741
|
-
function __Child_builder()
|
|
742
|
-
instance = __Parent_builder()
|
|
743
|
-
instance.super0_new = instance.new
|
|
744
|
-
instance.new = __Child_method_new
|
|
745
|
-
return instance
|
|
746
|
-
end function
|
|
747
|
-
function Child()
|
|
748
|
-
instance = __Child_builder()
|
|
749
|
-
instance.new()
|
|
750
|
-
return instance
|
|
751
|
-
end function
|
|
752
|
-
`, undefined, undefined, false);
|
|
753
|
-
//the AST should not be permanently modified
|
|
754
|
-
const constructor = file.ast.statements[0].body[0];
|
|
755
|
-
(0, chai_config_spec_1.expect)(constructor.func.body.statements).to.be.lengthOf(0);
|
|
756
|
-
});
|
|
757
|
-
it('adds field initializers', async () => {
|
|
758
|
-
const { file } = await testTranspile(`
|
|
759
|
-
class Person
|
|
760
|
-
sub new()
|
|
761
|
-
end sub
|
|
762
|
-
name = "Bob"
|
|
763
|
-
end class
|
|
764
|
-
`, `
|
|
765
|
-
sub __Person_method_new()
|
|
766
|
-
m.name = "Bob"
|
|
767
|
-
end sub
|
|
768
|
-
function __Person_builder()
|
|
769
|
-
instance = {}
|
|
770
|
-
instance.new = __Person_method_new
|
|
771
|
-
return instance
|
|
772
|
-
end function
|
|
773
|
-
function Person()
|
|
774
|
-
instance = __Person_builder()
|
|
775
|
-
instance.new()
|
|
776
|
-
return instance
|
|
777
|
-
end function
|
|
778
|
-
`);
|
|
779
|
-
//the AST should not be permanently modified
|
|
780
|
-
const constructor = file.ast.statements[0].body[0];
|
|
781
|
-
(0, chai_config_spec_1.expect)(constructor.func.body.statements).to.be.lengthOf(0);
|
|
782
|
-
});
|
|
783
|
-
it('does not screw up local variable references', async () => {
|
|
784
|
-
await testTranspile(`
|
|
785
|
-
class Animal
|
|
786
|
-
sub new(name as string)
|
|
787
|
-
m.name = name
|
|
788
|
-
end sub
|
|
789
|
-
|
|
790
|
-
name as string
|
|
791
|
-
|
|
792
|
-
sub move(distanceInMeters as integer)
|
|
793
|
-
print m.name + " moved " + distanceInMeters.ToStr() + " meters"
|
|
794
|
-
end sub
|
|
795
|
-
end class
|
|
796
|
-
|
|
797
|
-
class Duck extends Animal
|
|
798
|
-
override sub move(distanceInMeters as integer)
|
|
799
|
-
print "Waddling..."
|
|
800
|
-
super.move(distanceInMeters)
|
|
801
|
-
end sub
|
|
802
|
-
end class
|
|
803
|
-
|
|
804
|
-
class BabyDuck extends Duck
|
|
805
|
-
override sub move(distanceInMeters as integer)
|
|
806
|
-
super.move(distanceInMeters)
|
|
807
|
-
print "Fell over...I'm new at this"
|
|
808
|
-
end sub
|
|
809
|
-
end class
|
|
810
|
-
|
|
811
|
-
sub Main()
|
|
812
|
-
smokey = new Animal("Smokey")
|
|
813
|
-
smokey.move(1)
|
|
814
|
-
'> Bear moved 1 meters
|
|
815
|
-
|
|
816
|
-
donald = new Duck("Donald")
|
|
817
|
-
donald.move(2)
|
|
818
|
-
'> Waddling...\\nDonald moved 2 meters
|
|
819
|
-
|
|
820
|
-
dewey = new BabyDuck("Dewey")
|
|
821
|
-
dewey.move(3)
|
|
822
|
-
'> Waddling...\\nDewey moved 2 meters\\nFell over...I'm new at this
|
|
823
|
-
end sub
|
|
824
|
-
`, `
|
|
825
|
-
sub __Animal_method_new(name as string)
|
|
826
|
-
m.name = invalid
|
|
827
|
-
m.name = name
|
|
828
|
-
end sub
|
|
829
|
-
sub __Animal_method_move(distanceInMeters as integer)
|
|
830
|
-
print m.name + " moved " + distanceInMeters.ToStr() + " meters"
|
|
831
|
-
end sub
|
|
832
|
-
function __Animal_builder()
|
|
833
|
-
instance = {}
|
|
834
|
-
instance.new = __Animal_method_new
|
|
835
|
-
instance.move = __Animal_method_move
|
|
836
|
-
return instance
|
|
837
|
-
end function
|
|
838
|
-
function Animal(name as string)
|
|
839
|
-
instance = __Animal_builder()
|
|
840
|
-
instance.new(name)
|
|
841
|
-
return instance
|
|
842
|
-
end function
|
|
843
|
-
sub __Duck_method_new(name as string)
|
|
844
|
-
m.super0_new(name)
|
|
845
|
-
end sub
|
|
846
|
-
sub __Duck_method_move(distanceInMeters as integer)
|
|
847
|
-
print "Waddling..."
|
|
848
|
-
m.super0_move(distanceInMeters)
|
|
849
|
-
end sub
|
|
850
|
-
function __Duck_builder()
|
|
851
|
-
instance = __Animal_builder()
|
|
852
|
-
instance.super0_new = instance.new
|
|
853
|
-
instance.new = __Duck_method_new
|
|
854
|
-
instance.super0_move = instance.move
|
|
855
|
-
instance.move = __Duck_method_move
|
|
856
|
-
return instance
|
|
857
|
-
end function
|
|
858
|
-
function Duck(name as string)
|
|
859
|
-
instance = __Duck_builder()
|
|
860
|
-
instance.new(name)
|
|
861
|
-
return instance
|
|
862
|
-
end function
|
|
863
|
-
sub __BabyDuck_method_new(name as string)
|
|
864
|
-
m.super1_new(name)
|
|
865
|
-
end sub
|
|
866
|
-
sub __BabyDuck_method_move(distanceInMeters as integer)
|
|
867
|
-
m.super1_move(distanceInMeters)
|
|
868
|
-
print "Fell over...I'm new at this"
|
|
869
|
-
end sub
|
|
870
|
-
function __BabyDuck_builder()
|
|
871
|
-
instance = __Duck_builder()
|
|
872
|
-
instance.super1_new = instance.new
|
|
873
|
-
instance.new = __BabyDuck_method_new
|
|
874
|
-
instance.super1_move = instance.move
|
|
875
|
-
instance.move = __BabyDuck_method_move
|
|
876
|
-
return instance
|
|
877
|
-
end function
|
|
878
|
-
function BabyDuck(name as string)
|
|
879
|
-
instance = __BabyDuck_builder()
|
|
880
|
-
instance.new(name)
|
|
881
|
-
return instance
|
|
882
|
-
end function
|
|
883
|
-
|
|
884
|
-
sub Main()
|
|
885
|
-
smokey = Animal("Smokey")
|
|
886
|
-
smokey.move(1)
|
|
887
|
-
'> Bear moved 1 meters
|
|
888
|
-
|
|
889
|
-
donald = Duck("Donald")
|
|
890
|
-
donald.move(2)
|
|
891
|
-
'> Waddling...\\nDonald moved 2 meters
|
|
892
|
-
|
|
893
|
-
dewey = BabyDuck("Dewey")
|
|
894
|
-
dewey.move(3)
|
|
895
|
-
'> Waddling...\\nDewey moved 2 meters\\nFell over...I'm new at this
|
|
896
|
-
end sub
|
|
897
|
-
`, 'trim', 'source/main.bs');
|
|
898
|
-
});
|
|
899
|
-
it('calculates the proper super index', async () => {
|
|
900
|
-
await testTranspile(`
|
|
901
|
-
class Duck
|
|
902
|
-
public sub walk(meters as integer)
|
|
903
|
-
print "Walked " + meters.ToStr() + " meters"
|
|
904
|
-
end sub
|
|
905
|
-
end class
|
|
906
|
-
|
|
907
|
-
class BabyDuck extends Duck
|
|
908
|
-
public override sub walk(meters as integer)
|
|
909
|
-
print "Tripped"
|
|
910
|
-
super.walk(meters)
|
|
911
|
-
end sub
|
|
912
|
-
end class
|
|
913
|
-
`, `
|
|
914
|
-
sub __Duck_method_new()
|
|
915
|
-
end sub
|
|
916
|
-
sub __Duck_method_walk(meters as integer)
|
|
917
|
-
print "Walked " + meters.ToStr() + " meters"
|
|
918
|
-
end sub
|
|
919
|
-
function __Duck_builder()
|
|
920
|
-
instance = {}
|
|
921
|
-
instance.new = __Duck_method_new
|
|
922
|
-
instance.walk = __Duck_method_walk
|
|
923
|
-
return instance
|
|
924
|
-
end function
|
|
925
|
-
function Duck()
|
|
926
|
-
instance = __Duck_builder()
|
|
927
|
-
instance.new()
|
|
928
|
-
return instance
|
|
929
|
-
end function
|
|
930
|
-
sub __BabyDuck_method_new()
|
|
931
|
-
m.super0_new()
|
|
932
|
-
end sub
|
|
933
|
-
sub __BabyDuck_method_walk(meters as integer)
|
|
934
|
-
print "Tripped"
|
|
935
|
-
m.super0_walk(meters)
|
|
936
|
-
end sub
|
|
937
|
-
function __BabyDuck_builder()
|
|
938
|
-
instance = __Duck_builder()
|
|
939
|
-
instance.super0_new = instance.new
|
|
940
|
-
instance.new = __BabyDuck_method_new
|
|
941
|
-
instance.super0_walk = instance.walk
|
|
942
|
-
instance.walk = __BabyDuck_method_walk
|
|
943
|
-
return instance
|
|
944
|
-
end function
|
|
945
|
-
function BabyDuck()
|
|
946
|
-
instance = __BabyDuck_builder()
|
|
947
|
-
instance.new()
|
|
948
|
-
return instance
|
|
949
|
-
end function
|
|
950
|
-
`, 'trim', 'source/main.bs');
|
|
951
|
-
});
|
|
952
|
-
it('adds namespacing to constructors on field definitions', async () => {
|
|
953
|
-
await testTranspile(`
|
|
954
|
-
namespace MyNS
|
|
955
|
-
class KlassOne
|
|
956
|
-
other = new KlassTwo()
|
|
957
|
-
end class
|
|
958
|
-
|
|
959
|
-
class KlassTwo
|
|
960
|
-
end class
|
|
961
|
-
end namespace
|
|
962
|
-
`, `
|
|
963
|
-
sub __MyNS_KlassOne_method_new()
|
|
964
|
-
m.other = MyNS_KlassTwo()
|
|
965
|
-
end sub
|
|
966
|
-
function __MyNS_KlassOne_builder()
|
|
967
|
-
instance = {}
|
|
968
|
-
instance.new = __MyNS_KlassOne_method_new
|
|
969
|
-
return instance
|
|
970
|
-
end function
|
|
971
|
-
function MyNS_KlassOne()
|
|
972
|
-
instance = __MyNS_KlassOne_builder()
|
|
973
|
-
instance.new()
|
|
974
|
-
return instance
|
|
975
|
-
end function
|
|
976
|
-
sub __MyNS_KlassTwo_method_new()
|
|
977
|
-
end sub
|
|
978
|
-
function __MyNS_KlassTwo_builder()
|
|
979
|
-
instance = {}
|
|
980
|
-
instance.new = __MyNS_KlassTwo_method_new
|
|
981
|
-
return instance
|
|
982
|
-
end function
|
|
983
|
-
function MyNS_KlassTwo()
|
|
984
|
-
instance = __MyNS_KlassTwo_builder()
|
|
985
|
-
instance.new()
|
|
986
|
-
return instance
|
|
987
|
-
end function
|
|
988
|
-
`, 'trim', 'source/main.bs');
|
|
989
|
-
});
|
|
990
|
-
it('works with enums as field initial values inside a namespace', async () => {
|
|
991
|
-
await testTranspile(`
|
|
992
|
-
namespace MyNS
|
|
993
|
-
class HasEnumKlass
|
|
994
|
-
enumValue = MyEnum.A
|
|
995
|
-
end class
|
|
996
|
-
enum MyEnum
|
|
997
|
-
A = "A"
|
|
998
|
-
B = "B"
|
|
999
|
-
end enum
|
|
1000
|
-
end namespace
|
|
1001
|
-
`, `
|
|
1002
|
-
sub __MyNS_HasEnumKlass_method_new()
|
|
1003
|
-
m.enumValue = "A"
|
|
1004
|
-
end sub
|
|
1005
|
-
function __MyNS_HasEnumKlass_builder()
|
|
1006
|
-
instance = {}
|
|
1007
|
-
instance.new = __MyNS_HasEnumKlass_method_new
|
|
1008
|
-
return instance
|
|
1009
|
-
end function
|
|
1010
|
-
function MyNS_HasEnumKlass()
|
|
1011
|
-
instance = __MyNS_HasEnumKlass_builder()
|
|
1012
|
-
instance.new()
|
|
1013
|
-
return instance
|
|
1014
|
-
end function
|
|
1015
|
-
`, 'trim', 'source/main.bs');
|
|
1016
|
-
});
|
|
1017
|
-
it('allows enums as super args inside a namespace', async () => {
|
|
1018
|
-
await testTranspile(`
|
|
1019
|
-
namespace MyNS
|
|
1020
|
-
class SubKlass extends SuperKlass
|
|
1021
|
-
sub new()
|
|
1022
|
-
super(MyEnum.B)
|
|
1023
|
-
end sub
|
|
1024
|
-
end class
|
|
1025
|
-
|
|
1026
|
-
class SuperKlass
|
|
1027
|
-
sub new(enumVal as MyEnum)
|
|
1028
|
-
print enumVal
|
|
1029
|
-
end sub
|
|
1030
|
-
end class
|
|
1031
|
-
|
|
1032
|
-
enum MyEnum
|
|
1033
|
-
A = "A"
|
|
1034
|
-
B = "B"
|
|
1035
|
-
end enum
|
|
1036
|
-
end namespace
|
|
1037
|
-
`, `
|
|
1038
|
-
sub __MyNS_SubKlass_method_new()
|
|
1039
|
-
m.super0_new("B")
|
|
1040
|
-
end sub
|
|
1041
|
-
function __MyNS_SubKlass_builder()
|
|
1042
|
-
instance = __MyNS_SuperKlass_builder()
|
|
1043
|
-
instance.super0_new = instance.new
|
|
1044
|
-
instance.new = __MyNS_SubKlass_method_new
|
|
1045
|
-
return instance
|
|
1046
|
-
end function
|
|
1047
|
-
function MyNS_SubKlass()
|
|
1048
|
-
instance = __MyNS_SubKlass_builder()
|
|
1049
|
-
instance.new()
|
|
1050
|
-
return instance
|
|
1051
|
-
end function
|
|
1052
|
-
sub __MyNS_SuperKlass_method_new(enumVal as dynamic)
|
|
1053
|
-
print enumVal
|
|
1054
|
-
end sub
|
|
1055
|
-
function __MyNS_SuperKlass_builder()
|
|
1056
|
-
instance = {}
|
|
1057
|
-
instance.new = __MyNS_SuperKlass_method_new
|
|
1058
|
-
return instance
|
|
1059
|
-
end function
|
|
1060
|
-
function MyNS_SuperKlass(enumVal as dynamic)
|
|
1061
|
-
instance = __MyNS_SuperKlass_builder()
|
|
1062
|
-
instance.new(enumVal)
|
|
1063
|
-
return instance
|
|
1064
|
-
end function
|
|
1065
|
-
`, 'trim', 'source/main.bs');
|
|
1066
|
-
});
|
|
1067
|
-
it('works with enums as values referenced in a namespace directly', async () => {
|
|
1068
|
-
await testTranspile(`
|
|
1069
|
-
namespace MyNS
|
|
1070
|
-
class HasEnumKlass
|
|
1071
|
-
myArray = [true, true] as boolean[]
|
|
1072
|
-
sub new()
|
|
1073
|
-
m.myArray[MyEnum.A] = true
|
|
1074
|
-
m.myArray[MyEnum.B] = false
|
|
1075
|
-
end sub
|
|
1076
|
-
end class
|
|
1077
|
-
enum MyEnum
|
|
1078
|
-
A = 0
|
|
1079
|
-
B = 1
|
|
1080
|
-
end enum
|
|
1081
|
-
end namespace
|
|
1082
|
-
`, `
|
|
1083
|
-
sub __MyNS_HasEnumKlass_method_new()
|
|
1084
|
-
m.myArray = [
|
|
1085
|
-
true
|
|
1086
|
-
true
|
|
1087
|
-
]
|
|
1088
|
-
m.myArray[0] = true
|
|
1089
|
-
m.myArray[1] = false
|
|
1090
|
-
end sub
|
|
1091
|
-
function __MyNS_HasEnumKlass_builder()
|
|
1092
|
-
instance = {}
|
|
1093
|
-
instance.new = __MyNS_HasEnumKlass_method_new
|
|
1094
|
-
return instance
|
|
1095
|
-
end function
|
|
1096
|
-
function MyNS_HasEnumKlass()
|
|
1097
|
-
instance = __MyNS_HasEnumKlass_builder()
|
|
1098
|
-
instance.new()
|
|
1099
|
-
return instance
|
|
1100
|
-
end function
|
|
1101
|
-
`, 'trim', 'source/main.bs');
|
|
1102
|
-
});
|
|
1103
|
-
it('works with enums as values referenced in a namespace with namespace', async () => {
|
|
1104
|
-
await testTranspile(`
|
|
1105
|
-
namespace MyNS
|
|
1106
|
-
class HasEnumKlass
|
|
1107
|
-
myArray = [true, true] as boolean[]
|
|
1108
|
-
sub new()
|
|
1109
|
-
m.myArray[MyNS.MyEnum.A] = true
|
|
1110
|
-
m.myArray[MyNS.MyEnum.B] = false
|
|
1111
|
-
end sub
|
|
1112
|
-
end class
|
|
1113
|
-
enum MyEnum
|
|
1114
|
-
A = 0
|
|
1115
|
-
B = 1
|
|
1116
|
-
end enum
|
|
1117
|
-
end namespace
|
|
1118
|
-
`, `
|
|
1119
|
-
sub __MyNS_HasEnumKlass_method_new()
|
|
1120
|
-
m.myArray = [
|
|
1121
|
-
true
|
|
1122
|
-
true
|
|
1123
|
-
]
|
|
1124
|
-
m.myArray[0] = true
|
|
1125
|
-
m.myArray[1] = false
|
|
1126
|
-
end sub
|
|
1127
|
-
function __MyNS_HasEnumKlass_builder()
|
|
1128
|
-
instance = {}
|
|
1129
|
-
instance.new = __MyNS_HasEnumKlass_method_new
|
|
1130
|
-
return instance
|
|
1131
|
-
end function
|
|
1132
|
-
function MyNS_HasEnumKlass()
|
|
1133
|
-
instance = __MyNS_HasEnumKlass_builder()
|
|
1134
|
-
instance.new()
|
|
1135
|
-
return instance
|
|
1136
|
-
end function
|
|
1137
|
-
`, 'trim', 'source/main.bs');
|
|
1138
|
-
});
|
|
1139
|
-
it('allows namespaced class function as function parameters', async () => {
|
|
1140
|
-
await testTranspile(`
|
|
1141
|
-
namespace Alpha
|
|
1142
|
-
function foo()
|
|
1143
|
-
return 1
|
|
1144
|
-
end function
|
|
1145
|
-
|
|
1146
|
-
function callSomeFunc(f as function)
|
|
1147
|
-
return f()
|
|
1148
|
-
end function
|
|
1149
|
-
|
|
1150
|
-
sub callFoo()
|
|
1151
|
-
callSomeFunc(foo)
|
|
1152
|
-
end sub
|
|
1153
|
-
end namespace
|
|
1154
|
-
`, `
|
|
1155
|
-
function Alpha_foo()
|
|
1156
|
-
return 1
|
|
1157
|
-
end function
|
|
1158
|
-
|
|
1159
|
-
function Alpha_callSomeFunc(f as function)
|
|
1160
|
-
return f()
|
|
1161
|
-
end function
|
|
1162
|
-
|
|
1163
|
-
sub Alpha_callFoo()
|
|
1164
|
-
Alpha_callSomeFunc(Alpha_foo)
|
|
1165
|
-
end sub
|
|
1166
|
-
`, 'trim', 'source/main.bs');
|
|
1167
|
-
});
|
|
1168
|
-
it('allows namespaced class constructors as function parameters', async () => {
|
|
1169
|
-
await testTranspile(`
|
|
1170
|
-
namespace Alpha
|
|
1171
|
-
class Button
|
|
1172
|
-
end class
|
|
1173
|
-
|
|
1174
|
-
function callSomeFunc(f as function)
|
|
1175
|
-
return f()
|
|
1176
|
-
end function
|
|
1177
|
-
|
|
1178
|
-
sub makeButton()
|
|
1179
|
-
callSomeFunc(Button)
|
|
1180
|
-
end sub
|
|
1181
|
-
end namespace
|
|
1182
|
-
`, `
|
|
1183
|
-
sub __Alpha_Button_method_new()
|
|
1184
|
-
end sub
|
|
1185
|
-
function __Alpha_Button_builder()
|
|
1186
|
-
instance = {}
|
|
1187
|
-
instance.new = __Alpha_Button_method_new
|
|
1188
|
-
return instance
|
|
1189
|
-
end function
|
|
1190
|
-
function Alpha_Button()
|
|
1191
|
-
instance = __Alpha_Button_builder()
|
|
1192
|
-
instance.new()
|
|
1193
|
-
return instance
|
|
1194
|
-
end function
|
|
1195
|
-
|
|
1196
|
-
function Alpha_callSomeFunc(f as function)
|
|
1197
|
-
return f()
|
|
1198
|
-
end function
|
|
1199
|
-
|
|
1200
|
-
sub Alpha_makeButton()
|
|
1201
|
-
Alpha_callSomeFunc(Alpha_Button)
|
|
1202
|
-
end sub
|
|
1203
|
-
`, 'trim', 'source/main.bs');
|
|
1204
|
-
});
|
|
1205
|
-
it('allows class constructors as functions in array', async () => {
|
|
1206
|
-
await testTranspile(`
|
|
1207
|
-
namespace Alpha
|
|
1208
|
-
class Button
|
|
1209
|
-
end class
|
|
1210
|
-
|
|
1211
|
-
class ButtonContainer
|
|
1212
|
-
private button = new Alpha.Button()
|
|
1213
|
-
|
|
1214
|
-
sub new()
|
|
1215
|
-
m.init()
|
|
1216
|
-
end sub
|
|
1217
|
-
|
|
1218
|
-
sub init()
|
|
1219
|
-
button = new Alpha.Button()
|
|
1220
|
-
items = [m.button, button, Alpha.Button]
|
|
1221
|
-
end sub
|
|
1222
|
-
end class
|
|
1223
|
-
end namespace
|
|
1224
|
-
`, `
|
|
1225
|
-
sub __Alpha_Button_method_new()
|
|
1226
|
-
end sub
|
|
1227
|
-
function __Alpha_Button_builder()
|
|
1228
|
-
instance = {}
|
|
1229
|
-
instance.new = __Alpha_Button_method_new
|
|
1230
|
-
return instance
|
|
1231
|
-
end function
|
|
1232
|
-
function Alpha_Button()
|
|
1233
|
-
instance = __Alpha_Button_builder()
|
|
1234
|
-
instance.new()
|
|
1235
|
-
return instance
|
|
1236
|
-
end function
|
|
1237
|
-
sub __Alpha_ButtonContainer_method_new()
|
|
1238
|
-
m.button = Alpha_Button()
|
|
1239
|
-
m.init()
|
|
1240
|
-
end sub
|
|
1241
|
-
sub __Alpha_ButtonContainer_method_init()
|
|
1242
|
-
button = Alpha_Button()
|
|
1243
|
-
items = [
|
|
1244
|
-
m.button
|
|
1245
|
-
button
|
|
1246
|
-
Alpha_Button
|
|
1247
|
-
]
|
|
1248
|
-
end sub
|
|
1249
|
-
function __Alpha_ButtonContainer_builder()
|
|
1250
|
-
instance = {}
|
|
1251
|
-
instance.new = __Alpha_ButtonContainer_method_new
|
|
1252
|
-
instance.init = __Alpha_ButtonContainer_method_init
|
|
1253
|
-
return instance
|
|
1254
|
-
end function
|
|
1255
|
-
function Alpha_ButtonContainer()
|
|
1256
|
-
instance = __Alpha_ButtonContainer_builder()
|
|
1257
|
-
instance.new()
|
|
1258
|
-
return instance
|
|
1259
|
-
end function
|
|
1260
|
-
`, 'trim', 'source/main.bs');
|
|
1261
|
-
});
|
|
1262
|
-
it('puts leading comments from methods in correct place', async () => {
|
|
1263
|
-
await testTranspile(`
|
|
1264
|
-
class Duck
|
|
1265
|
-
' hatch from egg
|
|
1266
|
-
sub new()
|
|
1267
|
-
end sub
|
|
1268
|
-
' it must be a duck
|
|
1269
|
-
sub quack()
|
|
1270
|
-
' what does a duck say?
|
|
1271
|
-
print "quack"
|
|
1272
|
-
end sub
|
|
1273
|
-
end class
|
|
1274
|
-
`, `
|
|
1275
|
-
' hatch from egg
|
|
1276
|
-
sub __Duck_method_new()
|
|
1277
|
-
end sub
|
|
1278
|
-
' it must be a duck
|
|
1279
|
-
sub __Duck_method_quack()
|
|
1280
|
-
' what does a duck say?
|
|
1281
|
-
print "quack"
|
|
1282
|
-
end sub
|
|
1283
|
-
function __Duck_builder()
|
|
1284
|
-
instance = {}
|
|
1285
|
-
' hatch from egg
|
|
1286
|
-
instance.new = __Duck_method_new
|
|
1287
|
-
' it must be a duck
|
|
1288
|
-
instance.quack = __Duck_method_quack
|
|
1289
|
-
return instance
|
|
1290
|
-
end function
|
|
1291
|
-
function Duck()
|
|
1292
|
-
instance = __Duck_builder()
|
|
1293
|
-
instance.new()
|
|
1294
|
-
return instance
|
|
1295
|
-
end function
|
|
1296
|
-
`, undefined, 'source/main.bs');
|
|
1297
|
-
});
|
|
1298
|
-
it('puts leading comments from fields in correct place', async () => {
|
|
1299
|
-
await testTranspile(`
|
|
1300
|
-
class Duck
|
|
1301
|
-
' what kind of duck?
|
|
1302
|
-
type as string = "mallard"
|
|
1303
|
-
end class
|
|
1304
|
-
`, `
|
|
1305
|
-
sub __Duck_method_new()
|
|
1306
|
-
' what kind of duck?
|
|
1307
|
-
m.type = "mallard"
|
|
1308
|
-
end sub
|
|
1309
|
-
function __Duck_builder()
|
|
1310
|
-
instance = {}
|
|
1311
|
-
instance.new = __Duck_method_new
|
|
1312
|
-
return instance
|
|
1313
|
-
end function
|
|
1314
|
-
function Duck()
|
|
1315
|
-
instance = __Duck_builder()
|
|
1316
|
-
instance.new()
|
|
1317
|
-
return instance
|
|
1318
|
-
end function
|
|
1319
|
-
`, undefined, 'source/main.bs');
|
|
1320
|
-
});
|
|
1321
|
-
});
|
|
1322
|
-
it('detects using `new` keyword on non-classes', () => {
|
|
1323
|
-
program.setFile('source/main.bs', `
|
|
1324
|
-
sub quack()
|
|
1325
|
-
end sub
|
|
1326
|
-
sub main()
|
|
1327
|
-
duck = new quack()
|
|
1328
|
-
end sub
|
|
1329
|
-
`);
|
|
1330
|
-
program.validate();
|
|
1331
|
-
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1332
|
-
DiagnosticMessages_1.DiagnosticMessages.expressionIsNotConstructable('quack')
|
|
1333
|
-
]);
|
|
1334
|
-
});
|
|
1335
|
-
it('detects missing call to super', () => {
|
|
1336
|
-
program.setFile('source/main.bs', `
|
|
1337
|
-
class Animal
|
|
1338
|
-
sub new()
|
|
1339
|
-
end sub
|
|
1340
|
-
end class
|
|
1341
|
-
class Duck extends Animal
|
|
1342
|
-
sub new()
|
|
1343
|
-
end sub
|
|
1344
|
-
end class
|
|
1345
|
-
`);
|
|
1346
|
-
program.validate();
|
|
1347
|
-
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1348
|
-
DiagnosticMessages_1.DiagnosticMessages.classConstructorMissingSuperCall()
|
|
1349
|
-
]);
|
|
1350
|
-
});
|
|
1351
|
-
it('detects direct circular extends', () => {
|
|
1352
|
-
//direct
|
|
1353
|
-
program.setFile('source/Direct.bs', `
|
|
1354
|
-
class Parent extends Child
|
|
1355
|
-
end class
|
|
1356
|
-
|
|
1357
|
-
class Child extends Parent
|
|
1358
|
-
end class
|
|
1359
|
-
`);
|
|
1360
|
-
program.validate();
|
|
1361
|
-
(0, chai_config_spec_1.expect)(program.getDiagnostics().map(x => x.message).sort()).to.eql([
|
|
1362
|
-
DiagnosticMessages_1.DiagnosticMessages.circularReferenceDetected(['Child', 'Parent', 'Child']).message,
|
|
1363
|
-
DiagnosticMessages_1.DiagnosticMessages.circularReferenceDetected(['Parent', 'Child', 'Parent']).message
|
|
1364
|
-
]);
|
|
1365
|
-
});
|
|
1366
|
-
it('detects indirect circular extends', () => {
|
|
1367
|
-
//direct
|
|
1368
|
-
program.setFile('source/Indirect.bs', `
|
|
1369
|
-
class Parent extends Grandchild
|
|
1370
|
-
end class
|
|
1371
|
-
|
|
1372
|
-
class Child extends Parent
|
|
1373
|
-
end class
|
|
1374
|
-
|
|
1375
|
-
class Grandchild extends Child
|
|
1376
|
-
end class
|
|
1377
|
-
`);
|
|
1378
|
-
program.validate();
|
|
1379
|
-
(0, chai_config_spec_1.expect)(program.getDiagnostics().map(x => x.message).sort()).to.eql([
|
|
1380
|
-
DiagnosticMessages_1.DiagnosticMessages.circularReferenceDetected(['Child', 'Parent', 'Grandchild', 'Child']).message,
|
|
1381
|
-
DiagnosticMessages_1.DiagnosticMessages.circularReferenceDetected(['Grandchild', 'Child', 'Parent', 'Grandchild']).message,
|
|
1382
|
-
DiagnosticMessages_1.DiagnosticMessages.circularReferenceDetected(['Parent', 'Grandchild', 'Child', 'Parent']).message
|
|
1383
|
-
]);
|
|
1384
|
-
});
|
|
1385
|
-
it('transpiles super method calls twice', async () => {
|
|
1386
|
-
program.setFile('source/lib.bs', `
|
|
1387
|
-
class Being
|
|
1388
|
-
function think()
|
|
1389
|
-
print "thinking..."
|
|
1390
|
-
end function
|
|
1391
|
-
end class
|
|
1392
|
-
|
|
1393
|
-
class Human extends Being
|
|
1394
|
-
function think()
|
|
1395
|
-
super.think()
|
|
1396
|
-
end function
|
|
1397
|
-
end class
|
|
1398
|
-
`);
|
|
1399
|
-
await program.build({ outDir: testHelpers_spec_2.outDir });
|
|
1400
|
-
fsExtra.emptyDirSync(testHelpers_spec_2.outDir);
|
|
1401
|
-
await program.build({ outDir: testHelpers_spec_2.outDir });
|
|
1402
|
-
(0, chai_config_spec_1.expect)(fsExtra.readFileSync((0, util_1.standardizePath) `${testHelpers_spec_2.outDir}/source/lib.brs`).toString().trimEnd()).to.eql((0, testHelpers_spec_1.trim) `
|
|
1403
|
-
sub __Being_method_new()
|
|
1404
|
-
end sub
|
|
1405
|
-
function __Being_method_think()
|
|
1406
|
-
print "thinking..."
|
|
1407
|
-
end function
|
|
1408
|
-
function __Being_builder()
|
|
1409
|
-
instance = {}
|
|
1410
|
-
instance.new = __Being_method_new
|
|
1411
|
-
instance.think = __Being_method_think
|
|
1412
|
-
return instance
|
|
1413
|
-
end function
|
|
1414
|
-
function Being()
|
|
1415
|
-
instance = __Being_builder()
|
|
1416
|
-
instance.new()
|
|
1417
|
-
return instance
|
|
1418
|
-
end function
|
|
1419
|
-
sub __Human_method_new()
|
|
1420
|
-
m.super0_new()
|
|
1421
|
-
end sub
|
|
1422
|
-
function __Human_method_think()
|
|
1423
|
-
m.super0_think()
|
|
1424
|
-
end function
|
|
1425
|
-
function __Human_builder()
|
|
1426
|
-
instance = __Being_builder()
|
|
1427
|
-
instance.super0_new = instance.new
|
|
1428
|
-
instance.new = __Human_method_new
|
|
1429
|
-
instance.think = __Human_method_think
|
|
1430
|
-
return instance
|
|
1431
|
-
end function
|
|
1432
|
-
function Human()
|
|
1433
|
-
instance = __Human_builder()
|
|
1434
|
-
instance.new()
|
|
1435
|
-
return instance
|
|
1436
|
-
end function
|
|
1437
|
-
`);
|
|
1438
|
-
});
|
|
1439
|
-
it('detects duplicate member names', () => {
|
|
1440
|
-
program.setFile('source/main.bs', `
|
|
1441
|
-
class Animal
|
|
1442
|
-
public name
|
|
1443
|
-
public name
|
|
1444
|
-
public sub name()
|
|
1445
|
-
end sub
|
|
1446
|
-
public sub age()
|
|
1447
|
-
end sub
|
|
1448
|
-
public sub age()
|
|
1449
|
-
end sub
|
|
1450
|
-
public age
|
|
1451
|
-
end class
|
|
1452
|
-
`);
|
|
1453
|
-
program.validate();
|
|
1454
|
-
(0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.duplicateIdentifier('name')), { location: { range: vscode_languageserver_1.Range.create(3, 23, 3, 27) } }), Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.duplicateIdentifier('name')), { location: { range: vscode_languageserver_1.Range.create(4, 27, 4, 31) } }), Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.duplicateIdentifier('age')), { location: { range: vscode_languageserver_1.Range.create(8, 27, 8, 30) } }), Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.duplicateIdentifier('age')), { location: { range: vscode_languageserver_1.Range.create(10, 23, 10, 26) } })]);
|
|
1455
|
-
});
|
|
1456
|
-
it('detects mismatched member type in child class', () => {
|
|
1457
|
-
program.setFile('source/main.bs', `
|
|
1458
|
-
class Animal
|
|
1459
|
-
public name
|
|
1460
|
-
end class
|
|
1461
|
-
class Duck extends Animal
|
|
1462
|
-
public override function name()
|
|
1463
|
-
return "Donald"
|
|
1464
|
-
end function
|
|
1465
|
-
end class
|
|
1466
|
-
`);
|
|
1467
|
-
program.validate();
|
|
1468
|
-
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1469
|
-
DiagnosticMessages_1.DiagnosticMessages.childFieldTypeNotAssignableToBaseProperty('Duck', 'Animal', 'name', 'function name() as dynamic', 'dynamic')
|
|
1470
|
-
]);
|
|
1471
|
-
});
|
|
1472
|
-
it('allows untyped overridden field in child class', () => {
|
|
1473
|
-
program.setFile('source/main.bs', `
|
|
1474
|
-
class Animal
|
|
1475
|
-
public name
|
|
1476
|
-
end class
|
|
1477
|
-
class Duck extends Animal
|
|
1478
|
-
public name
|
|
1479
|
-
end class
|
|
1480
|
-
`);
|
|
1481
|
-
program.validate();
|
|
1482
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1483
|
-
});
|
|
1484
|
-
it('allows overridden property name in child class', () => {
|
|
1485
|
-
program.setFile('source/main.bs', `
|
|
1486
|
-
class Bird
|
|
1487
|
-
public name = "bird"
|
|
1488
|
-
end class
|
|
1489
|
-
class Duck extends Bird
|
|
1490
|
-
public name = "duck"
|
|
1491
|
-
end class
|
|
1492
|
-
`);
|
|
1493
|
-
program.validate();
|
|
1494
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1495
|
-
});
|
|
1496
|
-
it('flags incompatible child field type changes', () => {
|
|
1497
|
-
program.setFile('source/main.bs', `
|
|
1498
|
-
class Bird
|
|
1499
|
-
public age = 12
|
|
1500
|
-
public name = "bird"
|
|
1501
|
-
public owner as Person
|
|
1502
|
-
end class
|
|
1503
|
-
class Duck extends Bird
|
|
1504
|
-
public age = 12.2 'should be integer, but a float can be assigned to an int
|
|
1505
|
-
public name = 12 'should be string but is integer
|
|
1506
|
-
public owner as string
|
|
1507
|
-
end class
|
|
1508
|
-
`);
|
|
1509
|
-
program.validate();
|
|
1510
|
-
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1511
|
-
DiagnosticMessages_1.DiagnosticMessages.cannotFindName('Person'),
|
|
1512
|
-
DiagnosticMessages_1.DiagnosticMessages.childFieldTypeNotAssignableToBaseProperty('Duck', 'Bird', 'name', 'integer', 'string'),
|
|
1513
|
-
DiagnosticMessages_1.DiagnosticMessages.childFieldTypeNotAssignableToBaseProperty('Duck', 'Bird', 'owner', 'string', 'Person')
|
|
1514
|
-
]);
|
|
1515
|
-
});
|
|
1516
|
-
it('detects overridden methods without override keyword', () => {
|
|
1517
|
-
program.setFile('source/main.bs', `
|
|
1518
|
-
class Animal
|
|
1519
|
-
sub speak()
|
|
1520
|
-
end sub
|
|
1521
|
-
end class
|
|
1522
|
-
class Duck extends Animal
|
|
1523
|
-
sub speak()
|
|
1524
|
-
end sub
|
|
1525
|
-
end class
|
|
1526
|
-
`);
|
|
1527
|
-
program.validate();
|
|
1528
|
-
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1529
|
-
DiagnosticMessages_1.DiagnosticMessages.missingOverrideKeyword('Animal')
|
|
1530
|
-
]);
|
|
1531
|
-
});
|
|
1532
|
-
it('detects overridden methods with different visibility', () => {
|
|
1533
|
-
program.setFile('source/main.bs', `
|
|
1534
|
-
class Animal
|
|
1535
|
-
sub speakInPublic()
|
|
1536
|
-
end sub
|
|
1537
|
-
protected sub speakWithFriends()
|
|
1538
|
-
end sub
|
|
1539
|
-
private sub speakWithFamily()
|
|
1540
|
-
end sub
|
|
1541
|
-
end class
|
|
1542
|
-
class Duck extends Animal
|
|
1543
|
-
private override sub speakInPublic()
|
|
1544
|
-
end sub
|
|
1545
|
-
public override sub speakWithFriends()
|
|
1546
|
-
end sub
|
|
1547
|
-
override sub speakWithFamily()
|
|
1548
|
-
end sub
|
|
1549
|
-
end class
|
|
1550
|
-
`);
|
|
1551
|
-
program.validate();
|
|
1552
|
-
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1553
|
-
DiagnosticMessages_1.DiagnosticMessages.mismatchedOverriddenMemberVisibility('Duck', 'speakInPublic', 'private', 'public', 'Animal'),
|
|
1554
|
-
DiagnosticMessages_1.DiagnosticMessages.mismatchedOverriddenMemberVisibility('Duck', 'speakWithFriends', 'public', 'protected', 'Animal'),
|
|
1555
|
-
DiagnosticMessages_1.DiagnosticMessages.mismatchedOverriddenMemberVisibility('Duck', 'speakWithFamily', 'public', 'private', 'Animal')
|
|
1556
|
-
]);
|
|
1557
|
-
});
|
|
1558
|
-
it('allows overridden methods with matching visibility', () => {
|
|
1559
|
-
program.setFile('source/main.bs', `
|
|
1560
|
-
class Animal
|
|
1561
|
-
sub speakInPublic()
|
|
1562
|
-
end sub
|
|
1563
|
-
protected sub speakWithFriends()
|
|
1564
|
-
end sub
|
|
1565
|
-
private sub speakWithFamily()
|
|
1566
|
-
end sub
|
|
1567
|
-
end class
|
|
1568
|
-
class Duck extends Animal
|
|
1569
|
-
override sub speakInPublic()
|
|
1570
|
-
end sub
|
|
1571
|
-
protected override sub speakWithFriends()
|
|
1572
|
-
end sub
|
|
1573
|
-
private override sub speakWithFamily()
|
|
1574
|
-
end sub
|
|
1575
|
-
end class
|
|
1576
|
-
`);
|
|
1577
|
-
program.validate();
|
|
1578
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1579
|
-
});
|
|
1580
|
-
describe('detects unknown parent class', () => {
|
|
1581
|
-
it('non-namespaced parent from outside namespace', () => {
|
|
1582
|
-
program.setFile('source/main.bs', `
|
|
1583
|
-
class Duck extends Animal
|
|
1584
|
-
sub speak()
|
|
1585
|
-
end sub
|
|
1586
|
-
end class
|
|
1587
|
-
|
|
1588
|
-
namespace Vertibrates
|
|
1589
|
-
class Animal
|
|
1590
|
-
end class
|
|
1591
|
-
end namespace
|
|
1592
|
-
`);
|
|
1593
|
-
program.validate();
|
|
1594
|
-
(0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.cannotFindName('Animal')), { location: { range: vscode_languageserver_1.Range.create(1, 35, 1, 41) } })]);
|
|
1595
|
-
});
|
|
1596
|
-
it('non-namespaced parent from within namespace', () => {
|
|
1597
|
-
program.setFile('source/main.bs', `
|
|
1598
|
-
namespace Vertibrates
|
|
1599
|
-
class Duck extends Animal
|
|
1600
|
-
sub speak()
|
|
1601
|
-
end sub
|
|
1602
|
-
end class
|
|
1603
|
-
end namespace
|
|
1604
|
-
`);
|
|
1605
|
-
program.validate();
|
|
1606
|
-
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1607
|
-
DiagnosticMessages_1.DiagnosticMessages.cannotFindName('Animal')
|
|
1608
|
-
]);
|
|
1609
|
-
});
|
|
1610
|
-
it('non-namespaced name from outside namespace alongside existing namespace', () => {
|
|
1611
|
-
program.setFile('source/main.bs', `
|
|
1612
|
-
namespace Vertibrates
|
|
1613
|
-
class Animal
|
|
1614
|
-
end class
|
|
1615
|
-
end namespace
|
|
1616
|
-
|
|
1617
|
-
class Duck extends Animal
|
|
1618
|
-
sub speak()
|
|
1619
|
-
end sub
|
|
1620
|
-
end class
|
|
1621
|
-
`);
|
|
1622
|
-
program.validate();
|
|
1623
|
-
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1624
|
-
DiagnosticMessages_1.DiagnosticMessages.cannotFindName('Animal')
|
|
1625
|
-
]);
|
|
1626
|
-
});
|
|
1627
|
-
it('namespaced parent class from outside namespace', () => {
|
|
1628
|
-
program.setFile('source/vertibrates.bs', `
|
|
1629
|
-
namespace Vertibrates
|
|
1630
|
-
class Bird
|
|
1631
|
-
end class
|
|
1632
|
-
end namespace
|
|
1633
|
-
`);
|
|
1634
|
-
program.setFile('source/Duck.bs', `
|
|
1635
|
-
class Duck extends Vertibrates.GroundedBird
|
|
1636
|
-
sub speak()
|
|
1637
|
-
end sub
|
|
1638
|
-
end class
|
|
1639
|
-
`);
|
|
1640
|
-
program.validate();
|
|
1641
|
-
(0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.cannotFindName('GroundedBird', 'Vertibrates.GroundedBird', 'Vertibrates', 'namespace'))]);
|
|
1642
|
-
});
|
|
1643
|
-
it('namespaced parent class from inside namespace', () => {
|
|
1644
|
-
program.setFile('source/vertibrates.bs', `
|
|
1645
|
-
namespace Vertibrates
|
|
1646
|
-
class Bird
|
|
1647
|
-
end class
|
|
1648
|
-
end namespace
|
|
1649
|
-
`);
|
|
1650
|
-
program.setFile('source/Duck.bs', `
|
|
1651
|
-
namespace Birdies
|
|
1652
|
-
class Duck extends Vertibrates.GroundedBird
|
|
1653
|
-
sub speak()
|
|
1654
|
-
end sub
|
|
1655
|
-
end class
|
|
1656
|
-
end namespace
|
|
1657
|
-
`);
|
|
1658
|
-
program.validate();
|
|
1659
|
-
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1660
|
-
DiagnosticMessages_1.DiagnosticMessages.cannotFindName('GroundedBird', 'Vertibrates.GroundedBird', 'Vertibrates', 'namespace').message
|
|
1661
|
-
]);
|
|
1662
|
-
});
|
|
1663
|
-
});
|
|
1664
|
-
it('catches newable class without namespace name', () => {
|
|
1665
|
-
program.setFile('source/main.bs', `
|
|
1666
|
-
namespace NameA.NameB
|
|
1667
|
-
class Duck
|
|
1668
|
-
end class
|
|
1669
|
-
end namespace
|
|
1670
|
-
sub main()
|
|
1671
|
-
' this should be an error because the proper name is NameA.NameB.Duck"
|
|
1672
|
-
d = new Duck()
|
|
1673
|
-
end sub
|
|
1674
|
-
`);
|
|
1675
|
-
program.validate();
|
|
1676
|
-
(0, testHelpers_spec_1.expectDiagnosticsIncludes)(program, [
|
|
1677
|
-
DiagnosticMessages_1.DiagnosticMessages.cannotFindFunction('Duck').message,
|
|
1678
|
-
DiagnosticMessages_1.DiagnosticMessages.expressionIsNotConstructable('Duck')
|
|
1679
|
-
]);
|
|
1680
|
-
});
|
|
1681
|
-
it('supports newable class namespace inference', () => {
|
|
1682
|
-
program.setFile('source/main.bs', `
|
|
1683
|
-
namespace NameA.NameB
|
|
1684
|
-
class Duck
|
|
1685
|
-
end class
|
|
1686
|
-
sub main()
|
|
1687
|
-
d = new Duck()
|
|
1688
|
-
end sub
|
|
1689
|
-
end namespace
|
|
1690
|
-
`);
|
|
1691
|
-
program.validate();
|
|
1692
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1693
|
-
});
|
|
1694
|
-
it('catches extending unknown namespaced class', () => {
|
|
1695
|
-
program.setFile('source/main.bs', `
|
|
1696
|
-
namespace NameA.NameB
|
|
1697
|
-
class Animal
|
|
1698
|
-
end class
|
|
1699
|
-
class Duck extends NameA.NameB.AnimalNotDefined
|
|
1700
|
-
end class
|
|
1701
|
-
end namespace
|
|
1702
|
-
`);
|
|
1703
|
-
program.validate();
|
|
1704
|
-
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1705
|
-
DiagnosticMessages_1.DiagnosticMessages.cannotFindName('AnimalNotDefined', 'NameA.NameB.AnimalNotDefined', 'NameA.NameB', 'namespace')
|
|
1706
|
-
]);
|
|
1707
|
-
});
|
|
1708
|
-
it('supports omitting namespace prefix for items in same namespace', () => {
|
|
1709
|
-
program.setFile('source/main.bs', `
|
|
1710
|
-
namespace NameA.NameB
|
|
1711
|
-
class Animal
|
|
1712
|
-
end class
|
|
1713
|
-
class Duck extends Animal
|
|
1714
|
-
end class
|
|
1715
|
-
end namespace
|
|
1716
|
-
`);
|
|
1717
|
-
program.validate();
|
|
1718
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1719
|
-
});
|
|
1720
|
-
it('catches duplicate root-level class declarations', () => {
|
|
1721
|
-
program.setFile('source/main.bs', `
|
|
1722
|
-
class Animal
|
|
1723
|
-
end class
|
|
1724
|
-
class Animal
|
|
1725
|
-
end class
|
|
1726
|
-
`);
|
|
1727
|
-
program.validate();
|
|
1728
|
-
(0, testHelpers_spec_1.expectDiagnosticsIncludes)(program, [
|
|
1729
|
-
DiagnosticMessages_1.DiagnosticMessages.nameCollision('Class', 'Class', 'Animal')
|
|
1730
|
-
]);
|
|
1731
|
-
});
|
|
1732
|
-
it('catches duplicate namespace-level class declarations', () => {
|
|
1733
|
-
program.setFile('source/main.bs', `
|
|
1734
|
-
namespace NameA.NameB
|
|
1735
|
-
class Animal
|
|
1736
|
-
end class
|
|
1737
|
-
class Animal
|
|
1738
|
-
end class
|
|
1739
|
-
end namespace
|
|
1740
|
-
`);
|
|
1741
|
-
program.validate();
|
|
1742
|
-
(0, testHelpers_spec_1.expectDiagnosticsIncludes)(program, [
|
|
1743
|
-
DiagnosticMessages_1.DiagnosticMessages.nameCollision('Class', 'Class', 'NameA.NameB.Animal').message
|
|
1744
|
-
]);
|
|
1745
|
-
});
|
|
1746
|
-
it('allows namespaced class name which is the same as a global class', () => {
|
|
1747
|
-
program.setFile('source/main.bs', `
|
|
1748
|
-
namespace NameA.NameB
|
|
1749
|
-
class Animal
|
|
1750
|
-
name as string
|
|
1751
|
-
end class
|
|
1752
|
-
|
|
1753
|
-
sub printThisAnimalName(ani as Animal) ' this refers to NameA.NameB.Animal
|
|
1754
|
-
print ani.name
|
|
1755
|
-
end sub
|
|
1756
|
-
end namespace
|
|
1757
|
-
|
|
1758
|
-
class Animal
|
|
1759
|
-
doesNotHaveName as string
|
|
1760
|
-
end class
|
|
1761
|
-
`);
|
|
1762
|
-
program.validate();
|
|
1763
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1764
|
-
});
|
|
1765
|
-
it('catches class with same name as function', () => {
|
|
1766
|
-
program.setFile('source/main.bs', `
|
|
1767
|
-
class Animal
|
|
1768
|
-
end class
|
|
1769
|
-
sub Animal()
|
|
1770
|
-
end sub
|
|
1771
|
-
`);
|
|
1772
|
-
program.validate();
|
|
1773
|
-
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1774
|
-
DiagnosticMessages_1.DiagnosticMessages.nameCollision('Class', 'Function', 'Animal').message,
|
|
1775
|
-
DiagnosticMessages_1.DiagnosticMessages.nameCollision('Function', 'Class', 'Animal').message
|
|
1776
|
-
]);
|
|
1777
|
-
});
|
|
1778
|
-
it('catches class with same name (but different case) as function', () => {
|
|
1779
|
-
program.setFile('source/main.bs', `
|
|
1780
|
-
class ANIMAL
|
|
1781
|
-
end class
|
|
1782
|
-
sub animal()
|
|
1783
|
-
end sub
|
|
1784
|
-
`);
|
|
1785
|
-
program.validate();
|
|
1786
|
-
(0, testHelpers_spec_1.expectDiagnosticsIncludes)(program, [
|
|
1787
|
-
DiagnosticMessages_1.DiagnosticMessages.nameCollision('Class', 'Function', 'animal').message,
|
|
1788
|
-
DiagnosticMessages_1.DiagnosticMessages.nameCollision('Function', 'Class', 'ANIMAL').message
|
|
1789
|
-
]);
|
|
1790
|
-
});
|
|
1791
|
-
it('catches variable with same name as class', () => {
|
|
1792
|
-
program.setFile('source/main.bs', `
|
|
1793
|
-
class Animal
|
|
1794
|
-
end class
|
|
1795
|
-
sub main()
|
|
1796
|
-
animal = new Animal()
|
|
1797
|
-
end sub
|
|
1798
|
-
`);
|
|
1799
|
-
program.validate();
|
|
1800
|
-
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1801
|
-
DiagnosticMessages_1.DiagnosticMessages.localVarShadowedByScopedFunction().message
|
|
1802
|
-
]);
|
|
1803
|
-
});
|
|
1804
|
-
it('allows extending classes with more than one dot in the filename', () => {
|
|
1805
|
-
program.setFile('source/testclass.bs', `
|
|
1806
|
-
class Foo
|
|
1807
|
-
end class
|
|
1808
|
-
|
|
1809
|
-
class Bar extends Foo
|
|
1810
|
-
sub new()
|
|
1811
|
-
super()
|
|
1812
|
-
end sub
|
|
1813
|
-
end class
|
|
1814
|
-
`);
|
|
1815
|
-
program.setFile('source/testclass_no_testdot.bs', `
|
|
1816
|
-
class BarNoDot extends Foo
|
|
1817
|
-
sub new()
|
|
1818
|
-
super()
|
|
1819
|
-
end sub
|
|
1820
|
-
end class
|
|
1821
|
-
`);
|
|
1822
|
-
program.setFile('source/testclass.dot.bs', `
|
|
1823
|
-
class BarDot extends Foo
|
|
1824
|
-
sub new()
|
|
1825
|
-
super()
|
|
1826
|
-
end sub
|
|
1827
|
-
end class
|
|
1828
|
-
`);
|
|
1829
|
-
program.validate();
|
|
1830
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1831
|
-
});
|
|
1832
|
-
it('computes correct super index for grandchild class', async () => {
|
|
1833
|
-
program.setFile('source/main.bs', `
|
|
1834
|
-
sub Main()
|
|
1835
|
-
c = new App.ClassC()
|
|
1836
|
-
end sub
|
|
1837
|
-
|
|
1838
|
-
namespace App
|
|
1839
|
-
class ClassA
|
|
1840
|
-
end class
|
|
1841
|
-
|
|
1842
|
-
class ClassB extends ClassA
|
|
1843
|
-
end class
|
|
1844
|
-
end namespace
|
|
1845
|
-
`);
|
|
1846
|
-
await testTranspile(`
|
|
1847
|
-
namespace App
|
|
1848
|
-
class ClassC extends ClassB
|
|
1849
|
-
sub new()
|
|
1850
|
-
super()
|
|
1851
|
-
end sub
|
|
1852
|
-
end class
|
|
1853
|
-
end namespace
|
|
1854
|
-
`, `
|
|
1855
|
-
sub __App_ClassC_method_new()
|
|
1856
|
-
m.super1_new()
|
|
1857
|
-
end sub
|
|
1858
|
-
function __App_ClassC_builder()
|
|
1859
|
-
instance = __App_ClassB_builder()
|
|
1860
|
-
instance.super1_new = instance.new
|
|
1861
|
-
instance.new = __App_ClassC_method_new
|
|
1862
|
-
return instance
|
|
1863
|
-
end function
|
|
1864
|
-
function App_ClassC()
|
|
1865
|
-
instance = __App_ClassC_builder()
|
|
1866
|
-
instance.new()
|
|
1867
|
-
return instance
|
|
1868
|
-
end function
|
|
1869
|
-
`, 'trim', 'source/App.ClassC.bs');
|
|
1870
|
-
});
|
|
1871
|
-
it('computes correct super index for namespaced child class and global parent class', async () => {
|
|
1872
|
-
program.setFile('source/ClassA.bs', `
|
|
1873
|
-
class ClassA
|
|
1874
|
-
end class
|
|
1875
|
-
`);
|
|
1876
|
-
await testTranspile(`
|
|
1877
|
-
namespace App
|
|
1878
|
-
class ClassB extends ClassA
|
|
1879
|
-
end class
|
|
1880
|
-
end namespace
|
|
1881
|
-
`, `
|
|
1882
|
-
sub __App_ClassB_method_new()
|
|
1883
|
-
m.super0_new()
|
|
1884
|
-
end sub
|
|
1885
|
-
function __App_ClassB_builder()
|
|
1886
|
-
instance = __ClassA_builder()
|
|
1887
|
-
instance.super0_new = instance.new
|
|
1888
|
-
instance.new = __App_ClassB_method_new
|
|
1889
|
-
return instance
|
|
1890
|
-
end function
|
|
1891
|
-
function App_ClassB()
|
|
1892
|
-
instance = __App_ClassB_builder()
|
|
1893
|
-
instance.new()
|
|
1894
|
-
return instance
|
|
1895
|
-
end function
|
|
1896
|
-
`, 'trim', 'source/App.ClassB.bs');
|
|
1897
|
-
});
|
|
1898
|
-
it('does not crash when parent class is missing', () => {
|
|
1899
|
-
const file = program.setFile('source/ClassB.bs', `
|
|
1900
|
-
class ClassB extends ClassA
|
|
1901
|
-
end class
|
|
1902
|
-
`);
|
|
1903
|
-
(0, assert_1.doesNotThrow)(() => {
|
|
1904
|
-
const classStatements = file.ast.findChildren(reflection_1.isClassStatement);
|
|
1905
|
-
classStatements[0]['getParentClassIndex'](new BrsTranspileState_1.BrsTranspileState(file));
|
|
1906
|
-
});
|
|
1907
|
-
});
|
|
1908
|
-
it('does not crash when child has field with same name as sub in parent', () => {
|
|
1909
|
-
program.setFile('source/main.bs', `
|
|
1910
|
-
class Parent
|
|
1911
|
-
public function helloWorld()
|
|
1912
|
-
end function
|
|
1913
|
-
end class
|
|
1914
|
-
class Child extends Parent
|
|
1915
|
-
public helloWorld as string
|
|
1916
|
-
end class
|
|
1917
|
-
`);
|
|
1918
|
-
program.validate();
|
|
1919
|
-
});
|
|
1920
|
-
it('does not crash when child has method with same name as field in parent', () => {
|
|
1921
|
-
program.setFile('source/main.bs', `
|
|
1922
|
-
class Parent
|
|
1923
|
-
public helloWorld as string
|
|
1924
|
-
end class
|
|
1925
|
-
class Child extends Parent
|
|
1926
|
-
public function helloWorld()
|
|
1927
|
-
end function
|
|
1928
|
-
end class
|
|
1929
|
-
`);
|
|
1930
|
-
program.validate();
|
|
1931
|
-
});
|
|
1932
|
-
it('extending namespaced class transpiles properly', async () => {
|
|
1933
|
-
await testTranspile(`
|
|
1934
|
-
namespace App
|
|
1935
|
-
class CoreClass
|
|
1936
|
-
sub new()
|
|
1937
|
-
print "CoreClass.new()"
|
|
1938
|
-
end sub
|
|
1939
|
-
end class
|
|
1940
|
-
end namespace
|
|
1941
|
-
namespace App.Logic
|
|
1942
|
-
class FirstClass extends App.CoreClass
|
|
1943
|
-
end class
|
|
1944
|
-
class SecondClass extends FirstClass
|
|
1945
|
-
end class
|
|
1946
|
-
end namespace
|
|
1947
|
-
namespace App.OtherLogic
|
|
1948
|
-
class FinalClass extends App.Logic.SecondClass
|
|
1949
|
-
end class
|
|
1950
|
-
end namespace
|
|
1951
|
-
`, `
|
|
1952
|
-
sub __App_CoreClass_method_new()
|
|
1953
|
-
print "CoreClass.new()"
|
|
1954
|
-
end sub
|
|
1955
|
-
function __App_CoreClass_builder()
|
|
1956
|
-
instance = {}
|
|
1957
|
-
instance.new = __App_CoreClass_method_new
|
|
1958
|
-
return instance
|
|
1959
|
-
end function
|
|
1960
|
-
function App_CoreClass()
|
|
1961
|
-
instance = __App_CoreClass_builder()
|
|
1962
|
-
instance.new()
|
|
1963
|
-
return instance
|
|
1964
|
-
end function
|
|
1965
|
-
sub __App_Logic_FirstClass_method_new()
|
|
1966
|
-
m.super0_new()
|
|
1967
|
-
end sub
|
|
1968
|
-
function __App_Logic_FirstClass_builder()
|
|
1969
|
-
instance = __App_CoreClass_builder()
|
|
1970
|
-
instance.super0_new = instance.new
|
|
1971
|
-
instance.new = __App_Logic_FirstClass_method_new
|
|
1972
|
-
return instance
|
|
1973
|
-
end function
|
|
1974
|
-
function App_Logic_FirstClass()
|
|
1975
|
-
instance = __App_Logic_FirstClass_builder()
|
|
1976
|
-
instance.new()
|
|
1977
|
-
return instance
|
|
1978
|
-
end function
|
|
1979
|
-
sub __App_Logic_SecondClass_method_new()
|
|
1980
|
-
m.super1_new()
|
|
1981
|
-
end sub
|
|
1982
|
-
function __App_Logic_SecondClass_builder()
|
|
1983
|
-
instance = __App_Logic_FirstClass_builder()
|
|
1984
|
-
instance.super1_new = instance.new
|
|
1985
|
-
instance.new = __App_Logic_SecondClass_method_new
|
|
1986
|
-
return instance
|
|
1987
|
-
end function
|
|
1988
|
-
function App_Logic_SecondClass()
|
|
1989
|
-
instance = __App_Logic_SecondClass_builder()
|
|
1990
|
-
instance.new()
|
|
1991
|
-
return instance
|
|
1992
|
-
end function
|
|
1993
|
-
sub __App_OtherLogic_FinalClass_method_new()
|
|
1994
|
-
m.super2_new()
|
|
1995
|
-
end sub
|
|
1996
|
-
function __App_OtherLogic_FinalClass_builder()
|
|
1997
|
-
instance = __App_Logic_SecondClass_builder()
|
|
1998
|
-
instance.super2_new = instance.new
|
|
1999
|
-
instance.new = __App_OtherLogic_FinalClass_method_new
|
|
2000
|
-
return instance
|
|
2001
|
-
end function
|
|
2002
|
-
function App_OtherLogic_FinalClass()
|
|
2003
|
-
instance = __App_OtherLogic_FinalClass_builder()
|
|
2004
|
-
instance.new()
|
|
2005
|
-
return instance
|
|
2006
|
-
end function
|
|
2007
|
-
`);
|
|
2008
|
-
});
|
|
2009
|
-
it('detects calling class constructors with too many parameters', () => {
|
|
2010
|
-
program.setFile('source/main.bs', `
|
|
2011
|
-
class Parameterless
|
|
2012
|
-
sub new()
|
|
2013
|
-
end sub
|
|
2014
|
-
end class
|
|
2015
|
-
|
|
2016
|
-
class OneParam
|
|
2017
|
-
sub new(param1)
|
|
2018
|
-
end sub
|
|
2019
|
-
end class
|
|
2020
|
-
|
|
2021
|
-
sub main()
|
|
2022
|
-
c1 = new Parameterless(1)
|
|
2023
|
-
c2 = new OneParam(1, 2)
|
|
2024
|
-
c2 = new OneParam()
|
|
2025
|
-
end sub
|
|
2026
|
-
`);
|
|
2027
|
-
program.validate();
|
|
2028
|
-
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
2029
|
-
DiagnosticMessages_1.DiagnosticMessages.mismatchArgumentCount(0, 1),
|
|
2030
|
-
DiagnosticMessages_1.DiagnosticMessages.mismatchArgumentCount(1, 2),
|
|
2031
|
-
DiagnosticMessages_1.DiagnosticMessages.mismatchArgumentCount(1, 0)
|
|
2032
|
-
]);
|
|
2033
|
-
});
|
|
2034
|
-
});
|
|
2035
|
-
//# sourceMappingURL=BrsFile.Class.spec.js.map
|