brighterscript 0.66.0-alpha.1 → 0.66.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +224 -10
- package/README.md +13 -3
- package/bsconfig.schema.json +15 -0
- package/dist/ActionPipeline.d.ts +10 -0
- package/dist/ActionPipeline.js +40 -0
- package/dist/ActionPipeline.js.map +1 -0
- package/dist/AstValidationSegmenter.d.ts +25 -0
- package/dist/AstValidationSegmenter.js +150 -0
- package/dist/AstValidationSegmenter.js.map +1 -0
- package/dist/BsConfig.d.ts +13 -4
- package/dist/BusyStatusTracker.d.ts +31 -0
- package/dist/BusyStatusTracker.js +83 -0
- package/dist/BusyStatusTracker.js.map +1 -0
- package/dist/Cache.js +3 -3
- package/dist/Cache.js.map +1 -1
- package/dist/CacheVerifier.d.ts +0 -1
- package/dist/CodeActionUtil.d.ts +2 -2
- package/dist/CommentFlagProcessor.d.ts +4 -3
- package/dist/CommentFlagProcessor.js.map +1 -1
- package/dist/DiagnosticCollection.js +8 -5
- package/dist/DiagnosticCollection.js.map +1 -1
- package/dist/DiagnosticMessages.d.ts +34 -4
- package/dist/DiagnosticMessages.js +59 -4
- package/dist/DiagnosticMessages.js.map +1 -1
- package/dist/FunctionScope.d.ts +1 -1
- package/dist/LanguageServer.d.ts +23 -1
- package/dist/LanguageServer.js +139 -57
- package/dist/LanguageServer.js.map +1 -1
- package/dist/Logger.d.ts +3 -2
- package/dist/Logger.js +10 -2
- package/dist/Logger.js.map +1 -1
- package/dist/PluginInterface.d.ts +11 -2
- package/dist/PluginInterface.js +69 -10
- package/dist/PluginInterface.js.map +1 -1
- package/dist/Program.d.ts +138 -49
- package/dist/Program.js +644 -349
- package/dist/Program.js.map +1 -1
- package/dist/ProgramBuilder.d.ts +10 -4
- package/dist/ProgramBuilder.js +76 -74
- package/dist/ProgramBuilder.js.map +1 -1
- package/dist/Scope.d.ts +52 -49
- package/dist/Scope.js +298 -274
- package/dist/Scope.js.map +1 -1
- package/dist/SymbolTable.d.ts +35 -14
- package/dist/SymbolTable.js +90 -29
- package/dist/SymbolTable.js.map +1 -1
- package/dist/Throttler.d.ts +12 -0
- package/dist/Throttler.js +39 -0
- package/dist/Throttler.js.map +1 -1
- package/dist/XmlScope.d.ts +7 -4
- package/dist/XmlScope.js +52 -12
- package/dist/XmlScope.js.map +1 -1
- package/dist/astUtils/{AstEditor.d.ts → Editor.d.ts} +6 -1
- package/dist/astUtils/{AstEditor.js → Editor.js} +9 -3
- package/dist/astUtils/Editor.js.map +1 -0
- package/dist/astUtils/{AstEditor.spec.js → Editor.spec.js} +10 -6
- package/dist/astUtils/Editor.spec.js.map +1 -0
- package/dist/astUtils/creators.d.ts +3 -1
- package/dist/astUtils/creators.js +14 -4
- package/dist/astUtils/creators.js.map +1 -1
- package/dist/astUtils/reflection.d.ts +37 -9
- package/dist/astUtils/reflection.js +83 -14
- package/dist/astUtils/reflection.js.map +1 -1
- package/dist/astUtils/reflection.spec.js +87 -5
- package/dist/astUtils/reflection.spec.js.map +1 -1
- package/dist/astUtils/visitors.d.ts +14 -3
- package/dist/astUtils/visitors.js +22 -2
- package/dist/astUtils/visitors.js.map +1 -1
- package/dist/astUtils/visitors.spec.js +58 -7
- package/dist/astUtils/visitors.spec.js.map +1 -1
- package/dist/bscPlugin/BscPlugin.d.ts +10 -2
- package/dist/bscPlugin/BscPlugin.js +24 -4
- package/dist/bscPlugin/BscPlugin.js.map +1 -1
- package/dist/bscPlugin/CallExpressionInfo.d.ts +3 -3
- package/dist/bscPlugin/CallExpressionInfo.js.map +1 -1
- package/dist/bscPlugin/FileWriter.d.ts +6 -0
- package/dist/bscPlugin/FileWriter.js +24 -0
- package/dist/bscPlugin/FileWriter.js.map +1 -0
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +8 -8
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +4 -4
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/completions/CompletionsProcessor.d.ts +50 -1
- package/dist/bscPlugin/completions/CompletionsProcessor.js +445 -23
- package/dist/bscPlugin/completions/CompletionsProcessor.js.map +1 -1
- package/dist/bscPlugin/completions/CompletionsProcessor.spec.js +1737 -0
- package/dist/bscPlugin/completions/CompletionsProcessor.spec.js.map +1 -0
- package/dist/bscPlugin/fileProviders/FileProvider.d.ts +9 -0
- package/dist/bscPlugin/fileProviders/FileProvider.js +51 -0
- package/dist/bscPlugin/fileProviders/FileProvider.js.map +1 -0
- package/dist/bscPlugin/hover/HoverProcessor.d.ts +7 -3
- package/dist/bscPlugin/hover/HoverProcessor.js +133 -103
- package/dist/bscPlugin/hover/HoverProcessor.js.map +1 -1
- package/dist/bscPlugin/hover/HoverProcessor.spec.js +241 -29
- package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.d.ts +1 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +43 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js +22 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/serialize/BslibInjector.spec.js +19 -0
- package/dist/bscPlugin/serialize/BslibInjector.spec.js.map +1 -0
- package/dist/bscPlugin/serialize/BslibManager.d.ts +9 -0
- package/dist/bscPlugin/serialize/BslibManager.js +40 -0
- package/dist/bscPlugin/serialize/BslibManager.js.map +1 -0
- package/dist/bscPlugin/serialize/FileSerializer.d.ts +9 -0
- package/dist/bscPlugin/serialize/FileSerializer.js +72 -0
- package/dist/bscPlugin/serialize/FileSerializer.js.map +1 -0
- package/dist/bscPlugin/transpile/{BrsFilePreTranspileProcessor.d.ts → BrsFileTranspileProcessor.d.ts} +4 -2
- package/dist/bscPlugin/transpile/{BrsFilePreTranspileProcessor.js → BrsFileTranspileProcessor.js} +29 -5
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js.map +1 -0
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.d.ts +1 -0
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.js +41 -0
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.js.map +1 -0
- package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.d.ts +2 -2
- package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.js.map +1 -1
- package/dist/bscPlugin/validation/BrsFileValidator.d.ts +0 -4
- package/dist/bscPlugin/validation/BrsFileValidator.js +34 -29
- package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -1
- package/dist/bscPlugin/validation/BrsFileValidator.spec.js +1 -1
- package/dist/bscPlugin/validation/BrsFileValidator.spec.js.map +1 -1
- package/dist/bscPlugin/validation/ScopeValidator.d.ts +28 -7
- package/dist/bscPlugin/validation/ScopeValidator.js +393 -205
- package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -1
- package/dist/bscPlugin/validation/ScopeValidator.spec.d.ts +1 -0
- package/dist/bscPlugin/validation/ScopeValidator.spec.js +2038 -0
- package/dist/bscPlugin/validation/ScopeValidator.spec.js.map +1 -0
- package/dist/bscPlugin/validation/XmlFileValidator.js +2 -2
- package/dist/bscPlugin/validation/XmlFileValidator.js.map +1 -1
- package/dist/cli.js +104 -13
- package/dist/cli.js.map +1 -1
- package/dist/deferred.d.ts +3 -3
- package/dist/deferred.js.map +1 -1
- package/dist/diagnosticUtils.d.ts +8 -2
- package/dist/diagnosticUtils.js +45 -16
- package/dist/diagnosticUtils.js.map +1 -1
- package/dist/examples/plugins/removePrint.js +1 -1
- package/dist/examples/plugins/removePrint.js.map +1 -1
- package/dist/files/AssetFile.d.ts +26 -0
- package/dist/files/AssetFile.js +26 -0
- package/dist/files/AssetFile.js.map +1 -0
- package/dist/files/BrsFile.Class.spec.js +383 -56
- package/dist/files/BrsFile.Class.spec.js.map +1 -1
- package/dist/files/BrsFile.d.ts +73 -46
- package/dist/files/BrsFile.js +370 -534
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/BrsFile.spec.js +1139 -682
- package/dist/files/BrsFile.spec.js.map +1 -1
- package/dist/files/Factory.d.ts +25 -0
- package/dist/files/Factory.js +22 -0
- package/dist/files/Factory.js.map +1 -0
- package/dist/files/File.d.ts +106 -0
- package/dist/files/File.js +16 -0
- package/dist/files/File.js.map +1 -0
- package/dist/files/LazyFileData.d.ts +20 -0
- package/dist/files/LazyFileData.js +54 -0
- package/dist/files/LazyFileData.js.map +1 -0
- package/dist/files/LazyFileData.spec.d.ts +1 -0
- package/dist/files/LazyFileData.spec.js +27 -0
- package/dist/files/LazyFileData.spec.js.map +1 -0
- package/dist/files/XmlFile.d.ts +56 -23
- package/dist/files/XmlFile.js +88 -60
- package/dist/files/XmlFile.js.map +1 -1
- package/dist/files/XmlFile.spec.js +64 -93
- package/dist/files/XmlFile.spec.js.map +1 -1
- package/dist/files/tests/imports.spec.js +21 -8
- package/dist/files/tests/imports.spec.js.map +1 -1
- package/dist/files/tests/optionalChaning.spec.js +14 -14
- package/dist/files/tests/optionalChaning.spec.js.map +1 -1
- package/dist/globalCallables.js +88 -84
- package/dist/globalCallables.js.map +1 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +389 -94
- package/dist/interfaces.js +13 -2
- package/dist/interfaces.js.map +1 -1
- package/dist/lexer/Lexer.d.ts +12 -0
- package/dist/lexer/Lexer.js +28 -8
- package/dist/lexer/Lexer.js.map +1 -1
- package/dist/lexer/Lexer.spec.js +40 -0
- package/dist/lexer/Lexer.spec.js.map +1 -1
- package/dist/lexer/Token.d.ts +4 -0
- package/dist/lexer/Token.js.map +1 -1
- package/dist/lexer/TokenKind.d.ts +5 -0
- package/dist/lexer/TokenKind.js +14 -2
- package/dist/lexer/TokenKind.js.map +1 -1
- package/dist/parser/AstNode.d.ts +9 -2
- package/dist/parser/AstNode.js +16 -0
- package/dist/parser/AstNode.js.map +1 -1
- package/dist/parser/BrsTranspileState.d.ts +3 -2
- package/dist/parser/BrsTranspileState.js +3 -2
- package/dist/parser/BrsTranspileState.js.map +1 -1
- package/dist/parser/Expression.d.ts +21 -5
- package/dist/parser/Expression.js +130 -35
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Parser.Class.spec.js +103 -1
- package/dist/parser/Parser.Class.spec.js.map +1 -1
- package/dist/parser/Parser.d.ts +7 -0
- package/dist/parser/Parser.js +117 -21
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/Parser.spec.js +557 -5
- package/dist/parser/Parser.spec.js.map +1 -1
- package/dist/parser/SGParser.d.ts +4 -4
- package/dist/parser/SGParser.js +3 -3
- package/dist/parser/SGParser.js.map +1 -1
- package/dist/parser/SGParser.spec.js +2 -2
- package/dist/parser/SGParser.spec.js.map +1 -1
- package/dist/parser/SGTypes.d.ts +2 -2
- package/dist/parser/Statement.d.ts +37 -12
- package/dist/parser/Statement.js +153 -46
- package/dist/parser/Statement.js.map +1 -1
- package/dist/parser/tests/Parser.spec.js +2 -1
- package/dist/parser/tests/Parser.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/For.spec.js +16 -8
- package/dist/parser/tests/controlFlow/For.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/ForEach.spec.js +12 -6
- package/dist/parser/tests/controlFlow/ForEach.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/While.spec.js +8 -4
- package/dist/parser/tests/controlFlow/While.spec.js.map +1 -1
- package/dist/parser/tests/expression/Call.spec.js +4 -4
- package/dist/parser/tests/expression/Call.spec.js.map +1 -1
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +29 -29
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +10 -10
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.js +24 -24
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js +75 -36
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TernaryExpression.spec.js +36 -36
- package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/UnaryExpression.spec.d.ts +1 -0
- package/dist/parser/tests/expression/UnaryExpression.spec.js +52 -0
- package/dist/parser/tests/expression/UnaryExpression.spec.js.map +1 -0
- package/dist/parser/tests/statement/ConstStatement.spec.js +71 -22
- package/dist/parser/tests/statement/ConstStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Continue.spec.js +2 -2
- package/dist/parser/tests/statement/Continue.spec.js.map +1 -1
- package/dist/parser/tests/statement/Enum.spec.js +38 -285
- package/dist/parser/tests/statement/Enum.spec.js.map +1 -1
- package/dist/parser/tests/statement/For.spec.js +6 -6
- package/dist/parser/tests/statement/For.spec.js.map +1 -1
- package/dist/parser/tests/statement/ForEach.spec.js +4 -4
- package/dist/parser/tests/statement/ForEach.spec.js.map +1 -1
- package/dist/parser/tests/statement/InterfaceStatement.spec.js +26 -10
- package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/PrintStatement.spec.js +16 -13
- package/dist/parser/tests/statement/PrintStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/ReturnStatement.spec.js +5 -3
- package/dist/parser/tests/statement/ReturnStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Set.spec.js +26 -13
- package/dist/parser/tests/statement/Set.spec.js.map +1 -1
- package/dist/preprocessor/Manifest.d.ts +1 -1
- package/dist/preprocessor/Manifest.js +2 -2
- package/dist/preprocessor/Manifest.js.map +1 -1
- package/dist/roku-types/data.json +244 -294
- package/dist/roku-types/index.d.ts +17 -38
- package/dist/types/ArrayType.d.ts +4 -1
- package/dist/types/ArrayType.js +46 -6
- package/dist/types/ArrayType.js.map +1 -1
- package/dist/types/ArrayType.spec.js +32 -3
- package/dist/types/ArrayType.spec.js.map +1 -1
- package/dist/types/AssociativeArrayType.d.ts +11 -0
- package/dist/types/AssociativeArrayType.js +52 -0
- package/dist/types/AssociativeArrayType.js.map +1 -0
- package/dist/types/BaseFunctionType.d.ts +9 -0
- package/dist/types/BaseFunctionType.js +25 -0
- package/dist/types/BaseFunctionType.js.map +1 -0
- package/dist/types/BooleanType.d.ts +2 -1
- package/dist/types/BooleanType.js +8 -2
- package/dist/types/BooleanType.js.map +1 -1
- package/dist/types/BscType.d.ts +10 -6
- package/dist/types/BscType.js +69 -16
- package/dist/types/BscType.js.map +1 -1
- package/dist/types/BscTypeKind.d.ts +3 -0
- package/dist/types/BscTypeKind.js +3 -0
- package/dist/types/BscTypeKind.js.map +1 -1
- package/dist/types/BuiltInInterfaceAdder.d.ts +23 -0
- package/dist/types/BuiltInInterfaceAdder.js +164 -0
- package/dist/types/BuiltInInterfaceAdder.js.map +1 -0
- package/dist/types/BuiltInInterfaceAdder.spec.d.ts +1 -0
- package/dist/types/BuiltInInterfaceAdder.spec.js +116 -0
- package/dist/types/BuiltInInterfaceAdder.spec.js.map +1 -0
- package/dist/types/ClassType.d.ts +10 -4
- package/dist/types/ClassType.js +32 -5
- package/dist/types/ClassType.js.map +1 -1
- package/dist/types/ClassType.spec.js +5 -3
- package/dist/types/ClassType.spec.js.map +1 -1
- package/dist/types/ComponentType.d.ts +26 -0
- package/dist/types/ComponentType.js +83 -0
- package/dist/types/ComponentType.js.map +1 -0
- package/dist/types/DoubleType.d.ts +2 -1
- package/dist/types/DoubleType.js +9 -2
- package/dist/types/DoubleType.js.map +1 -1
- package/dist/types/DynamicType.d.ts +2 -2
- package/dist/types/DynamicType.js +3 -1
- package/dist/types/DynamicType.js.map +1 -1
- package/dist/types/EnumType.d.ts +24 -6
- package/dist/types/EnumType.js +29 -7
- package/dist/types/EnumType.js.map +1 -1
- package/dist/types/FloatType.d.ts +2 -1
- package/dist/types/FloatType.js +9 -2
- package/dist/types/FloatType.js.map +1 -1
- package/dist/types/FunctionType.d.ts +8 -20
- package/dist/types/FunctionType.js +17 -45
- package/dist/types/FunctionType.js.map +1 -1
- package/dist/types/InheritableType.d.ts +7 -4
- package/dist/types/InheritableType.js +67 -3
- package/dist/types/InheritableType.js.map +1 -1
- package/dist/types/IntegerType.d.ts +2 -1
- package/dist/types/IntegerType.js +9 -2
- package/dist/types/IntegerType.js.map +1 -1
- package/dist/types/InterfaceType.d.ts +6 -4
- package/dist/types/InterfaceType.js +8 -11
- package/dist/types/InterfaceType.js.map +1 -1
- package/dist/types/InterfaceType.spec.js +30 -2
- package/dist/types/InterfaceType.spec.js.map +1 -1
- package/dist/types/InvalidType.d.ts +2 -1
- package/dist/types/InvalidType.js +7 -1
- package/dist/types/InvalidType.js.map +1 -1
- package/dist/types/LongIntegerType.d.ts +2 -1
- package/dist/types/LongIntegerType.js +9 -2
- package/dist/types/LongIntegerType.js.map +1 -1
- package/dist/types/NamespaceType.d.ts +2 -1
- package/dist/types/NamespaceType.js +3 -0
- package/dist/types/NamespaceType.js.map +1 -1
- package/dist/types/ObjectType.d.ts +2 -2
- package/dist/types/ObjectType.js +5 -10
- package/dist/types/ObjectType.js.map +1 -1
- package/dist/types/ReferenceType.d.ts +15 -3
- package/dist/types/ReferenceType.js +173 -24
- package/dist/types/ReferenceType.js.map +1 -1
- package/dist/types/ReferenceType.spec.js +21 -6
- package/dist/types/ReferenceType.spec.js.map +1 -1
- package/dist/types/StringType.d.ts +2 -1
- package/dist/types/StringType.js +9 -2
- package/dist/types/StringType.js.map +1 -1
- package/dist/types/TypedFunctionType.d.ts +33 -0
- package/dist/types/TypedFunctionType.js +106 -0
- package/dist/types/TypedFunctionType.js.map +1 -0
- package/dist/types/TypedFunctionType.spec.d.ts +1 -0
- package/dist/types/TypedFunctionType.spec.js +122 -0
- package/dist/types/TypedFunctionType.spec.js.map +1 -0
- package/dist/types/UninitializedType.d.ts +2 -1
- package/dist/types/UninitializedType.js +1 -1
- package/dist/types/UninitializedType.js.map +1 -1
- package/dist/types/UnionType.d.ts +4 -2
- package/dist/types/UnionType.js +36 -4
- package/dist/types/UnionType.js.map +1 -1
- package/dist/types/UnionType.spec.js +46 -19
- package/dist/types/UnionType.spec.js.map +1 -1
- package/dist/types/VoidType.d.ts +2 -1
- package/dist/types/VoidType.js +7 -2
- package/dist/types/VoidType.js.map +1 -1
- package/dist/types/helper.spec.js +15 -0
- package/dist/types/helper.spec.js.map +1 -1
- package/dist/types/helpers.d.ts +5 -0
- package/dist/types/helpers.js +50 -3
- package/dist/types/helpers.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/util.d.ts +71 -15
- package/dist/util.js +578 -150
- package/dist/util.js.map +1 -1
- package/dist/validators/ClassValidator.d.ts +0 -1
- package/dist/validators/ClassValidator.js +0 -22
- package/dist/validators/ClassValidator.js.map +1 -1
- package/package.json +3 -2
- package/dist/astUtils/AstEditor.js.map +0 -1
- package/dist/astUtils/AstEditor.spec.js.map +0 -1
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js.map +0 -1
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js +0 -31
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js.map +0 -1
- package/dist/types/FunctionType.spec.js +0 -23
- package/dist/types/FunctionType.spec.js.map +0 -1
- /package/dist/astUtils/{AstEditor.spec.d.ts → Editor.spec.d.ts} +0 -0
- /package/dist/bscPlugin/{transpile/BrsFilePreTranspileProcessor.spec.d.ts → completions/CompletionsProcessor.spec.d.ts} +0 -0
- /package/dist/{types/FunctionType.spec.d.ts → bscPlugin/serialize/BslibInjector.spec.d.ts} +0 -0
|
@@ -20,6 +20,7 @@ const SymbolTable_1 = require("../SymbolTable");
|
|
|
20
20
|
const IntegerType_1 = require("../types/IntegerType");
|
|
21
21
|
const FloatType_1 = require("../types/FloatType");
|
|
22
22
|
const StringType_1 = require("../types/StringType");
|
|
23
|
+
const types_1 = require("../types");
|
|
23
24
|
describe('parser', () => {
|
|
24
25
|
it('emits empty object when empty token list is provided', () => {
|
|
25
26
|
(0, chai_config_spec_1.expect)(Parser_1.Parser.parse([])).to.deep.include({
|
|
@@ -52,12 +53,18 @@ describe('parser', () => {
|
|
|
52
53
|
});
|
|
53
54
|
function expressionsToStrings(expressions) {
|
|
54
55
|
return [...expressions.values()].map(x => {
|
|
55
|
-
const file = new BrsFile_1.BrsFile(
|
|
56
|
+
const file = new BrsFile_1.BrsFile({
|
|
57
|
+
srcPath: '',
|
|
58
|
+
destPath: '',
|
|
59
|
+
program: new Program_1.Program({})
|
|
60
|
+
});
|
|
56
61
|
const state = new BrsTranspileState_1.BrsTranspileState(file);
|
|
57
62
|
return new source_map_1.SourceNode(null, null, null, x.transpile(state)).toString();
|
|
58
63
|
});
|
|
59
64
|
}
|
|
60
|
-
|
|
65
|
+
// eslint-disable-next-line func-names, prefer-arrow-callback
|
|
66
|
+
it('works for references.expressions', function () {
|
|
67
|
+
this.timeout(5000); // this test takes a long time on github
|
|
61
68
|
const parser = Parser_1.Parser.parse(`
|
|
62
69
|
b += "plus-equal"
|
|
63
70
|
a += 1 + 2
|
|
@@ -552,14 +559,100 @@ describe('parser', () => {
|
|
|
552
559
|
let { diagnostics } = Parser_1.Parser.parse(tokens);
|
|
553
560
|
(0, chai_config_spec_1.expect)(diagnostics).to.be.lengthOf(1, 'Error count should be 0');
|
|
554
561
|
});
|
|
555
|
-
it
|
|
562
|
+
it('allows printing object with trailing period', () => {
|
|
556
563
|
let { tokens } = Lexer_1.Lexer.scan(`print a.`);
|
|
557
|
-
let {
|
|
564
|
+
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
565
|
+
let printStatement = statements[0];
|
|
566
|
+
(0, testHelpers_spec_1.expectDiagnosticsIncludes)(diagnostics, DiagnosticMessages_1.DiagnosticMessages.expectedPropertyNameAfterPeriod());
|
|
567
|
+
(0, chai_config_spec_1.expect)(printStatement).to.be.instanceof(Statement_1.PrintStatement);
|
|
568
|
+
(0, chai_config_spec_1.expect)(printStatement.expressions[0]).to.be.instanceof(Expression_1.VariableExpression);
|
|
569
|
+
});
|
|
570
|
+
it('allows printing object with trailing period with multiple dotted gets', () => {
|
|
571
|
+
let { tokens } = Lexer_1.Lexer.scan(`print a.b.`);
|
|
572
|
+
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
558
573
|
let printStatement = statements[0];
|
|
559
|
-
(0,
|
|
574
|
+
(0, testHelpers_spec_1.expectDiagnosticsIncludes)(diagnostics, DiagnosticMessages_1.DiagnosticMessages.expectedPropertyNameAfterPeriod());
|
|
560
575
|
(0, chai_config_spec_1.expect)(printStatement).to.be.instanceof(Statement_1.PrintStatement);
|
|
561
576
|
(0, chai_config_spec_1.expect)(printStatement.expressions[0]).to.be.instanceof(Expression_1.DottedGetExpression);
|
|
562
577
|
});
|
|
578
|
+
describe('incomplete statements in the ast', () => {
|
|
579
|
+
it('adds variable expressions to the ast', () => {
|
|
580
|
+
let { tokens } = Lexer_1.Lexer.scan(`
|
|
581
|
+
function a()
|
|
582
|
+
NameA.
|
|
583
|
+
end function
|
|
584
|
+
|
|
585
|
+
namespace NameA
|
|
586
|
+
sub noop()
|
|
587
|
+
end sub
|
|
588
|
+
end namespace
|
|
589
|
+
`);
|
|
590
|
+
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
591
|
+
(0, testHelpers_spec_1.expectDiagnosticsIncludes)(diagnostics, DiagnosticMessages_1.DiagnosticMessages.expectedStatementOrFunctionCallButReceivedExpression());
|
|
592
|
+
let stmt = statements[0].func.body.statements[0];
|
|
593
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isExpressionStatement)(stmt)).to.be.true;
|
|
594
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isVariableExpression)((stmt).expression)).to.be.true;
|
|
595
|
+
(0, chai_config_spec_1.expect)(stmt.expression.name.text).to.equal('NameA');
|
|
596
|
+
});
|
|
597
|
+
it('adds unended call statements', () => {
|
|
598
|
+
let { tokens } = Lexer_1.Lexer.scan(`
|
|
599
|
+
function a()
|
|
600
|
+
lcase(
|
|
601
|
+
end function
|
|
602
|
+
`);
|
|
603
|
+
let { statements } = Parser_1.Parser.parse(tokens);
|
|
604
|
+
let stmt = statements[0].func.body.statements[0];
|
|
605
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isExpressionStatement)(stmt)).to.be.true;
|
|
606
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isCallExpression)((stmt).expression)).to.be.true;
|
|
607
|
+
(0, chai_config_spec_1.expect)(stmt.expression.callee.name.text).to.equal('lcase');
|
|
608
|
+
});
|
|
609
|
+
it('adds unended indexed get statements', () => {
|
|
610
|
+
let { tokens } = Lexer_1.Lexer.scan(`
|
|
611
|
+
function a()
|
|
612
|
+
nums[
|
|
613
|
+
end function
|
|
614
|
+
|
|
615
|
+
const nums = [1, 2, 3]
|
|
616
|
+
`);
|
|
617
|
+
let { statements } = Parser_1.Parser.parse(tokens);
|
|
618
|
+
let stmt = statements[0].func.body.statements[0];
|
|
619
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isExpressionStatement)(stmt)).to.be.true;
|
|
620
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isIndexedGetExpression)((stmt).expression)).to.be.true;
|
|
621
|
+
(0, chai_config_spec_1.expect)(stmt.expression.obj.name.text).to.equal('nums');
|
|
622
|
+
});
|
|
623
|
+
it('adds dotted gets', () => {
|
|
624
|
+
let { tokens } = Lexer_1.Lexer.scan(`
|
|
625
|
+
function foo(a as KlassA)
|
|
626
|
+
a.b.
|
|
627
|
+
end function
|
|
628
|
+
|
|
629
|
+
class KlassA
|
|
630
|
+
b as KlassB
|
|
631
|
+
end class
|
|
632
|
+
|
|
633
|
+
class KlassB
|
|
634
|
+
sub noop()
|
|
635
|
+
end sub
|
|
636
|
+
end class
|
|
637
|
+
`);
|
|
638
|
+
let { statements } = Parser_1.Parser.parse(tokens);
|
|
639
|
+
let stmt = statements[0].func.body.statements[0];
|
|
640
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isExpressionStatement)(stmt)).to.be.true;
|
|
641
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isDottedGetExpression)((stmt).expression)).to.be.true;
|
|
642
|
+
(0, chai_config_spec_1.expect)(stmt.expression.obj.name.text).to.equal('a');
|
|
643
|
+
(0, chai_config_spec_1.expect)(stmt.expression.name.text).to.equal('b');
|
|
644
|
+
});
|
|
645
|
+
it('adds function statement with missing type after as', () => {
|
|
646
|
+
var _a;
|
|
647
|
+
let parser = parse(`
|
|
648
|
+
sub foo(thing as )
|
|
649
|
+
print thing
|
|
650
|
+
end sub
|
|
651
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
652
|
+
(0, chai_config_spec_1.expect)((_a = parser.diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.exist;
|
|
653
|
+
(0, chai_config_spec_1.expect)(parser.ast.statements[0]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
654
|
+
});
|
|
655
|
+
});
|
|
563
656
|
describe('comments', () => {
|
|
564
657
|
it('combines multi-line comments', () => {
|
|
565
658
|
let { tokens } = Lexer_1.Lexer.scan(`
|
|
@@ -1196,6 +1289,15 @@ describe('parser', () => {
|
|
|
1196
1289
|
});
|
|
1197
1290
|
});
|
|
1198
1291
|
describe('type casts', () => {
|
|
1292
|
+
it('is not allowed in brightscript mode', () => {
|
|
1293
|
+
var _a;
|
|
1294
|
+
let parser = parse(`
|
|
1295
|
+
sub main(node as dynamic)
|
|
1296
|
+
print lcase((node as string))
|
|
1297
|
+
end sub
|
|
1298
|
+
`, Parser_1.ParseMode.BrightScript);
|
|
1299
|
+
(0, chai_config_spec_1.expect)((_a = parser.diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.bsFeatureNotSupportedInBrsFiles('type cast').message);
|
|
1300
|
+
});
|
|
1199
1301
|
it('allows type casts after function calls', () => {
|
|
1200
1302
|
var _a;
|
|
1201
1303
|
let { statements, diagnostics } = parse(`
|
|
@@ -1301,6 +1403,456 @@ describe('parser', () => {
|
|
|
1301
1403
|
(0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.exist;
|
|
1302
1404
|
});
|
|
1303
1405
|
});
|
|
1406
|
+
describe('union types', () => {
|
|
1407
|
+
it('is not allowed in brightscript mode', () => {
|
|
1408
|
+
let parser = parse(`
|
|
1409
|
+
sub main(param as string or integer)
|
|
1410
|
+
print param
|
|
1411
|
+
end sub
|
|
1412
|
+
`, Parser_1.ParseMode.BrightScript);
|
|
1413
|
+
(0, testHelpers_spec_1.expectDiagnosticsIncludes)(parser.diagnostics, [DiagnosticMessages_1.DiagnosticMessages.expectedStatementOrFunctionCallButReceivedExpression()]);
|
|
1414
|
+
});
|
|
1415
|
+
it('allows union types in parameters', () => {
|
|
1416
|
+
let { diagnostics } = parse(`
|
|
1417
|
+
sub main(param as string or integer)
|
|
1418
|
+
print param
|
|
1419
|
+
end sub
|
|
1420
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1421
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1422
|
+
});
|
|
1423
|
+
it('allows union types in type casts', () => {
|
|
1424
|
+
let { diagnostics } = parse(`
|
|
1425
|
+
sub main(val)
|
|
1426
|
+
printThing(val as string or integer)
|
|
1427
|
+
end sub
|
|
1428
|
+
|
|
1429
|
+
sub printThing(thing as string or integer)
|
|
1430
|
+
print thing
|
|
1431
|
+
end sub
|
|
1432
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1433
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1434
|
+
});
|
|
1435
|
+
});
|
|
1436
|
+
describe('typed arrays', () => {
|
|
1437
|
+
it('is not allowed in brightscript mode', () => {
|
|
1438
|
+
let parser = parse(`
|
|
1439
|
+
sub main(things as string[])
|
|
1440
|
+
print things
|
|
1441
|
+
end sub
|
|
1442
|
+
`, Parser_1.ParseMode.BrightScript);
|
|
1443
|
+
(0, testHelpers_spec_1.expectDiagnosticsIncludes)(parser.diagnostics, [DiagnosticMessages_1.DiagnosticMessages.bsFeatureNotSupportedInBrsFiles('typed arrays')]);
|
|
1444
|
+
});
|
|
1445
|
+
it('is allowed in brighterscript mode', () => {
|
|
1446
|
+
let { statements, diagnostics } = parse(`
|
|
1447
|
+
sub main(things as string[])
|
|
1448
|
+
print things
|
|
1449
|
+
end sub
|
|
1450
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1451
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1452
|
+
const paramType = statements[0].func.parameters[0].getType({ flags: SymbolTable_1.SymbolTypeFlag.typetime });
|
|
1453
|
+
(0, testHelpers_spec_1.expectTypeToBe)(paramType, types_1.ArrayType);
|
|
1454
|
+
(0, testHelpers_spec_1.expectTypeToBe)(paramType.defaultType, StringType_1.StringType);
|
|
1455
|
+
});
|
|
1456
|
+
it('allows multi dimensional arrays', () => {
|
|
1457
|
+
let { statements, diagnostics } = parse(`
|
|
1458
|
+
sub main(things as string[][])
|
|
1459
|
+
print things
|
|
1460
|
+
end sub
|
|
1461
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1462
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1463
|
+
const paramType = statements[0].func.parameters[0].getType({ flags: SymbolTable_1.SymbolTypeFlag.typetime });
|
|
1464
|
+
(0, testHelpers_spec_1.expectTypeToBe)(paramType, types_1.ArrayType);
|
|
1465
|
+
(0, testHelpers_spec_1.expectTypeToBe)(paramType.defaultType, types_1.ArrayType);
|
|
1466
|
+
(0, testHelpers_spec_1.expectTypeToBe)(paramType.defaultType.defaultType, StringType_1.StringType);
|
|
1467
|
+
});
|
|
1468
|
+
it('allows arrays as return types', () => {
|
|
1469
|
+
let { statements, diagnostics } = parse(`
|
|
1470
|
+
function getFourPrimes() as integer[]
|
|
1471
|
+
return [2, 3, 5, 7]
|
|
1472
|
+
end function
|
|
1473
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1474
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1475
|
+
const paramType = statements[0].func.returnTypeExpression.getType({ flags: SymbolTable_1.SymbolTypeFlag.typetime });
|
|
1476
|
+
(0, testHelpers_spec_1.expectTypeToBe)(paramType, types_1.ArrayType);
|
|
1477
|
+
(0, testHelpers_spec_1.expectTypeToBe)(paramType.defaultType, IntegerType_1.IntegerType);
|
|
1478
|
+
});
|
|
1479
|
+
it('allows arrays in union types', () => {
|
|
1480
|
+
let { statements, diagnostics } = parse(`
|
|
1481
|
+
sub foo(x as integer or integer[] or string or string[])
|
|
1482
|
+
print x
|
|
1483
|
+
end sub
|
|
1484
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1485
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1486
|
+
const paramType = statements[0].func.parameters[0].getType({ flags: SymbolTable_1.SymbolTypeFlag.typetime });
|
|
1487
|
+
(0, testHelpers_spec_1.expectTypeToBe)(paramType, types_1.UnionType);
|
|
1488
|
+
(0, chai_config_spec_1.expect)(paramType.toString().includes('Array<string>')).to.be.true;
|
|
1489
|
+
(0, chai_config_spec_1.expect)(paramType.toString().includes('Array<integer>')).to.be.true;
|
|
1490
|
+
});
|
|
1491
|
+
});
|
|
1492
|
+
describe('interfaces', () => {
|
|
1493
|
+
it('allows fields and methods', () => {
|
|
1494
|
+
let { statements, diagnostics } = parse(`
|
|
1495
|
+
interface SomeIFace
|
|
1496
|
+
name as string
|
|
1497
|
+
height as integer
|
|
1498
|
+
function getValue(thing as float) as object
|
|
1499
|
+
function getMe() as SomeIFace
|
|
1500
|
+
sub noop()
|
|
1501
|
+
end interface
|
|
1502
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1503
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1504
|
+
(0, chai_config_spec_1.expect)(statements.length).to.eq(1);
|
|
1505
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isInterfaceStatement)(statements[0])).to.be.true;
|
|
1506
|
+
});
|
|
1507
|
+
it('allows untyped fields', () => {
|
|
1508
|
+
let { statements, diagnostics } = parse(`
|
|
1509
|
+
interface HasUntyped
|
|
1510
|
+
name
|
|
1511
|
+
end interface
|
|
1512
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1513
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1514
|
+
(0, chai_config_spec_1.expect)(statements.length).to.eq(1);
|
|
1515
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isInterfaceStatement)(statements[0])).to.be.true;
|
|
1516
|
+
});
|
|
1517
|
+
it('allows optional fields', () => {
|
|
1518
|
+
let { statements, diagnostics } = parse(`
|
|
1519
|
+
interface HasOptional
|
|
1520
|
+
optional name as string
|
|
1521
|
+
optional height
|
|
1522
|
+
end interface
|
|
1523
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1524
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1525
|
+
(0, chai_config_spec_1.expect)(statements.length).to.eq(1);
|
|
1526
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isInterfaceStatement)(statements[0])).to.be.true;
|
|
1527
|
+
const iface = statements[0];
|
|
1528
|
+
iface.fields.forEach(f => (0, chai_config_spec_1.expect)(f.isOptional).to.be.true);
|
|
1529
|
+
const ifaceType = iface.getType({ flags: SymbolTable_1.SymbolTypeFlag.typetime });
|
|
1530
|
+
// eslint-disable-next-line no-bitwise
|
|
1531
|
+
ifaceType.getMemberTable().getAllSymbols(SymbolTable_1.SymbolTypeFlag.runtime).forEach(sym => (0, chai_config_spec_1.expect)(sym.flags & SymbolTable_1.SymbolTypeFlag.optional).to.eq(SymbolTable_1.SymbolTypeFlag.optional));
|
|
1532
|
+
});
|
|
1533
|
+
it('allows fields named optional', () => {
|
|
1534
|
+
let { statements, diagnostics } = parse(`
|
|
1535
|
+
interface IsJustOptional
|
|
1536
|
+
optional
|
|
1537
|
+
someThingElse
|
|
1538
|
+
end interface
|
|
1539
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1540
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1541
|
+
(0, chai_config_spec_1.expect)(statements.length).to.eq(1);
|
|
1542
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isInterfaceStatement)(statements[0])).to.be.true;
|
|
1543
|
+
const iface = statements[0];
|
|
1544
|
+
iface.fields.forEach(f => (0, chai_config_spec_1.expect)(f.isOptional).to.be.false);
|
|
1545
|
+
const ifaceType = iface.getType({ flags: SymbolTable_1.SymbolTypeFlag.typetime });
|
|
1546
|
+
const iFaceMembers = ifaceType.getMemberTable().getAllSymbols(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
1547
|
+
(0, chai_config_spec_1.expect)(iFaceMembers.length).to.eq(2);
|
|
1548
|
+
// eslint-disable-next-line no-bitwise
|
|
1549
|
+
iFaceMembers.forEach(sym => (0, chai_config_spec_1.expect)(sym.flags & SymbolTable_1.SymbolTypeFlag.optional).to.eq(0));
|
|
1550
|
+
});
|
|
1551
|
+
it('allows fields named optional that are also optional', () => {
|
|
1552
|
+
let { statements, diagnostics } = parse(`
|
|
1553
|
+
interface IsJustOptional
|
|
1554
|
+
optional optional
|
|
1555
|
+
end interface
|
|
1556
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1557
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1558
|
+
(0, chai_config_spec_1.expect)(statements.length).to.eq(1);
|
|
1559
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isInterfaceStatement)(statements[0])).to.be.true;
|
|
1560
|
+
const iface = statements[0];
|
|
1561
|
+
iface.fields.forEach(f => (0, chai_config_spec_1.expect)(f.isOptional).to.be.true);
|
|
1562
|
+
const ifaceType = iface.getType({ flags: SymbolTable_1.SymbolTypeFlag.typetime });
|
|
1563
|
+
const iFaceMembers = ifaceType.getMemberTable().getAllSymbols(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
1564
|
+
(0, chai_config_spec_1.expect)(iFaceMembers.length).to.eq(1);
|
|
1565
|
+
// eslint-disable-next-line no-bitwise
|
|
1566
|
+
iFaceMembers.forEach(sym => (0, chai_config_spec_1.expect)(sym.flags & SymbolTable_1.SymbolTypeFlag.optional).to.eq(SymbolTable_1.SymbolTypeFlag.optional));
|
|
1567
|
+
});
|
|
1568
|
+
it('allows optional methods', () => {
|
|
1569
|
+
let { statements, diagnostics } = parse(`
|
|
1570
|
+
interface HasOptional
|
|
1571
|
+
optional function getValue() as boolean
|
|
1572
|
+
optional sub noop()
|
|
1573
|
+
optional function process()
|
|
1574
|
+
end interface
|
|
1575
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1576
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1577
|
+
(0, chai_config_spec_1.expect)(statements.length).to.eq(1);
|
|
1578
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isInterfaceStatement)(statements[0])).to.be.true;
|
|
1579
|
+
const iface = statements[0];
|
|
1580
|
+
iface.methods.forEach(m => (0, chai_config_spec_1.expect)(m.isOptional).to.equal(true));
|
|
1581
|
+
const ifaceType = iface.getType({ flags: SymbolTable_1.SymbolTypeFlag.typetime });
|
|
1582
|
+
// eslint-disable-next-line no-bitwise
|
|
1583
|
+
ifaceType.getMemberTable().getAllSymbols(SymbolTable_1.SymbolTypeFlag.runtime).forEach(sym => (0, chai_config_spec_1.expect)(sym.flags & SymbolTable_1.SymbolTypeFlag.optional).to.eq(SymbolTable_1.SymbolTypeFlag.optional));
|
|
1584
|
+
});
|
|
1585
|
+
it('allows fields named `as` that are also optional', () => {
|
|
1586
|
+
let { statements, diagnostics } = parse(`
|
|
1587
|
+
interface IsJustOptional
|
|
1588
|
+
optional as
|
|
1589
|
+
end interface
|
|
1590
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1591
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1592
|
+
(0, chai_config_spec_1.expect)(statements.length).to.eq(1);
|
|
1593
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isInterfaceStatement)(statements[0])).to.be.true;
|
|
1594
|
+
const iface = statements[0];
|
|
1595
|
+
iface.fields.forEach(f => (0, chai_config_spec_1.expect)(f.isOptional).to.be.true);
|
|
1596
|
+
const ifaceType = iface.getType({ flags: SymbolTable_1.SymbolTypeFlag.typetime });
|
|
1597
|
+
const iFaceMembers = ifaceType.getMemberTable().getAllSymbols(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
1598
|
+
(0, chai_config_spec_1.expect)(iFaceMembers.length).to.eq(1);
|
|
1599
|
+
// eslint-disable-next-line no-bitwise
|
|
1600
|
+
iFaceMembers.forEach(sym => (0, chai_config_spec_1.expect)(sym.flags & SymbolTable_1.SymbolTypeFlag.optional).to.eq(SymbolTable_1.SymbolTypeFlag.optional));
|
|
1601
|
+
});
|
|
1602
|
+
it('allows fields named `as` that are also typed', () => {
|
|
1603
|
+
let { statements, diagnostics } = parse(`
|
|
1604
|
+
interface IsJustOptional
|
|
1605
|
+
optional as as string
|
|
1606
|
+
end interface
|
|
1607
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1608
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1609
|
+
(0, chai_config_spec_1.expect)(statements.length).to.eq(1);
|
|
1610
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isInterfaceStatement)(statements[0])).to.be.true;
|
|
1611
|
+
const iface = statements[0];
|
|
1612
|
+
iface.fields.forEach(f => (0, chai_config_spec_1.expect)(f.isOptional).to.be.true);
|
|
1613
|
+
const ifaceType = iface.getType({ flags: SymbolTable_1.SymbolTypeFlag.typetime });
|
|
1614
|
+
const iFaceMembers = ifaceType.getMemberTable().getAllSymbols(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
1615
|
+
(0, chai_config_spec_1.expect)(iFaceMembers.length).to.eq(1);
|
|
1616
|
+
// eslint-disable-next-line no-bitwise
|
|
1617
|
+
iFaceMembers.forEach(sym => (0, chai_config_spec_1.expect)(sym.flags & SymbolTable_1.SymbolTypeFlag.optional).to.eq(SymbolTable_1.SymbolTypeFlag.optional));
|
|
1618
|
+
});
|
|
1619
|
+
it('allows fields named `optional` that are also typed', () => {
|
|
1620
|
+
let { statements, diagnostics } = parse(`
|
|
1621
|
+
interface IsJustOptional
|
|
1622
|
+
optional as string
|
|
1623
|
+
end interface
|
|
1624
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1625
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1626
|
+
(0, chai_config_spec_1.expect)(statements.length).to.eq(1);
|
|
1627
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isInterfaceStatement)(statements[0])).to.be.true;
|
|
1628
|
+
const iface = statements[0];
|
|
1629
|
+
iface.fields.forEach(f => (0, chai_config_spec_1.expect)(f.isOptional).to.be.false);
|
|
1630
|
+
const ifaceType = iface.getType({ flags: SymbolTable_1.SymbolTypeFlag.typetime });
|
|
1631
|
+
const iFaceMembers = ifaceType.getMemberTable().getAllSymbols(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
1632
|
+
(0, chai_config_spec_1.expect)(iFaceMembers.length).to.eq(1);
|
|
1633
|
+
// eslint-disable-next-line no-bitwise
|
|
1634
|
+
iFaceMembers.forEach(sym => (0, chai_config_spec_1.expect)(sym.flags & SymbolTable_1.SymbolTypeFlag.optional).to.eq(0));
|
|
1635
|
+
});
|
|
1636
|
+
});
|
|
1637
|
+
describe('leadingTrivia', () => {
|
|
1638
|
+
it('gets leading trivia from functions', () => {
|
|
1639
|
+
let { statements } = parse(`
|
|
1640
|
+
' Nice function, bro
|
|
1641
|
+
function foo()
|
|
1642
|
+
return 1
|
|
1643
|
+
end function
|
|
1644
|
+
`);
|
|
1645
|
+
const funcStatements = statements.filter(reflection_1.isFunctionStatement);
|
|
1646
|
+
const fooTrivia = funcStatements[0].getLeadingTrivia();
|
|
1647
|
+
(0, chai_config_spec_1.expect)(fooTrivia.length).to.be.greaterThan(0);
|
|
1648
|
+
(0, chai_config_spec_1.expect)(fooTrivia.filter(t => t.kind === TokenKind_1.TokenKind.Comment).length).to.eq(1);
|
|
1649
|
+
});
|
|
1650
|
+
it('gets multiple lines of leading trivia', () => {
|
|
1651
|
+
let { statements } = parse(`
|
|
1652
|
+
' Say hello to someone
|
|
1653
|
+
'
|
|
1654
|
+
' @param {string} name the person you want to say hello to.
|
|
1655
|
+
sub sayHello(name as string = "world")
|
|
1656
|
+
end sub
|
|
1657
|
+
`);
|
|
1658
|
+
const funcStatements = statements.filter(reflection_1.isFunctionStatement);
|
|
1659
|
+
const helloTrivia = funcStatements[0].getLeadingTrivia();
|
|
1660
|
+
(0, chai_config_spec_1.expect)(helloTrivia.length).to.be.greaterThan(0);
|
|
1661
|
+
(0, chai_config_spec_1.expect)(helloTrivia.filter(t => t.kind === TokenKind_1.TokenKind.Comment).length).to.eq(3);
|
|
1662
|
+
});
|
|
1663
|
+
it('gets leading trivia from classes', () => {
|
|
1664
|
+
let { statements } = parse(`
|
|
1665
|
+
' hello
|
|
1666
|
+
' classes
|
|
1667
|
+
class Hello
|
|
1668
|
+
end class
|
|
1669
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1670
|
+
const classStatements = statements.filter(reflection_1.isClassStatement);
|
|
1671
|
+
const trivia = classStatements[0].getLeadingTrivia();
|
|
1672
|
+
(0, chai_config_spec_1.expect)(trivia.length).to.be.greaterThan(0);
|
|
1673
|
+
(0, chai_config_spec_1.expect)(trivia.filter(t => t.kind === TokenKind_1.TokenKind.Comment).length).to.eq(2);
|
|
1674
|
+
});
|
|
1675
|
+
it('gets leading trivia from functions with annotations', () => {
|
|
1676
|
+
let { statements } = parse(`
|
|
1677
|
+
' hello comment 1
|
|
1678
|
+
' hello comment 2
|
|
1679
|
+
@annotation
|
|
1680
|
+
sub sayHello(name as string = "world")
|
|
1681
|
+
end sub
|
|
1682
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1683
|
+
const funcStatements = statements.filter(reflection_1.isFunctionStatement);
|
|
1684
|
+
const helloTrivia = funcStatements[0].getLeadingTrivia();
|
|
1685
|
+
(0, chai_config_spec_1.expect)(helloTrivia.length).to.be.greaterThan(0);
|
|
1686
|
+
(0, chai_config_spec_1.expect)(helloTrivia.filter(t => t.kind === TokenKind_1.TokenKind.Comment).length).to.eq(2);
|
|
1687
|
+
});
|
|
1688
|
+
it('gets leading trivia from class methods', () => {
|
|
1689
|
+
let { statements } = parse(`
|
|
1690
|
+
' hello
|
|
1691
|
+
' classes
|
|
1692
|
+
class Hello
|
|
1693
|
+
|
|
1694
|
+
' Gets the value of PI
|
|
1695
|
+
' Not a dessert
|
|
1696
|
+
function getPi() as float
|
|
1697
|
+
return 3.14
|
|
1698
|
+
end function
|
|
1699
|
+
|
|
1700
|
+
' Gets a dessert
|
|
1701
|
+
function getPie() as string
|
|
1702
|
+
return "Apple Pie"
|
|
1703
|
+
end function
|
|
1704
|
+
end class
|
|
1705
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1706
|
+
const classStatement = statements.filter(reflection_1.isClassStatement)[0];
|
|
1707
|
+
const methodStatements = classStatement.methods;
|
|
1708
|
+
// function getPi()
|
|
1709
|
+
let trivia = methodStatements[0].getLeadingTrivia();
|
|
1710
|
+
(0, chai_config_spec_1.expect)(trivia.length).to.be.greaterThan(0);
|
|
1711
|
+
(0, chai_config_spec_1.expect)(trivia.filter(t => t.kind === TokenKind_1.TokenKind.Comment).length).to.eq(2);
|
|
1712
|
+
// function getPie()
|
|
1713
|
+
trivia = methodStatements[1].getLeadingTrivia();
|
|
1714
|
+
(0, chai_config_spec_1.expect)(trivia.length).to.be.greaterThan(0);
|
|
1715
|
+
(0, chai_config_spec_1.expect)(trivia.filter(t => t.kind === TokenKind_1.TokenKind.Comment).length).to.eq(1);
|
|
1716
|
+
});
|
|
1717
|
+
it('gets leading trivia from class fields', () => {
|
|
1718
|
+
let { statements } = parse(`
|
|
1719
|
+
' hello
|
|
1720
|
+
' classes
|
|
1721
|
+
class Thing
|
|
1722
|
+
' like the sky
|
|
1723
|
+
' or a blueberry, evn though that's purple
|
|
1724
|
+
color = "blue"
|
|
1725
|
+
|
|
1726
|
+
' My name
|
|
1727
|
+
public name as string
|
|
1728
|
+
|
|
1729
|
+
' Only I know how old I am
|
|
1730
|
+
private age = 42
|
|
1731
|
+
end class
|
|
1732
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1733
|
+
const classStatement = statements.filter(reflection_1.isClassStatement)[0];
|
|
1734
|
+
const fieldStatements = classStatement.fields;
|
|
1735
|
+
// color = "blue"
|
|
1736
|
+
let trivia = fieldStatements[0].getLeadingTrivia();
|
|
1737
|
+
(0, chai_config_spec_1.expect)(trivia.length).to.be.greaterThan(0);
|
|
1738
|
+
(0, chai_config_spec_1.expect)(trivia.filter(t => t.kind === TokenKind_1.TokenKind.Comment).length).to.eq(2);
|
|
1739
|
+
// public name as string
|
|
1740
|
+
trivia = fieldStatements[1].getLeadingTrivia();
|
|
1741
|
+
(0, chai_config_spec_1.expect)(trivia.length).to.be.greaterThan(0);
|
|
1742
|
+
(0, chai_config_spec_1.expect)(trivia.filter(t => t.kind === TokenKind_1.TokenKind.Comment).length).to.eq(1);
|
|
1743
|
+
// private age = 42
|
|
1744
|
+
trivia = fieldStatements[2].getLeadingTrivia();
|
|
1745
|
+
(0, chai_config_spec_1.expect)(trivia.length).to.be.greaterThan(0);
|
|
1746
|
+
(0, chai_config_spec_1.expect)(trivia.filter(t => t.kind === TokenKind_1.TokenKind.Comment).length).to.eq(1);
|
|
1747
|
+
});
|
|
1748
|
+
it('gets leading trivia from interfaces', () => {
|
|
1749
|
+
let { statements } = parse(`
|
|
1750
|
+
' Description of interface
|
|
1751
|
+
interface myIface
|
|
1752
|
+
' comment
|
|
1753
|
+
someField as integer
|
|
1754
|
+
|
|
1755
|
+
'comment
|
|
1756
|
+
function someFunc() as string
|
|
1757
|
+
end interface
|
|
1758
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1759
|
+
const ifaceStatement = statements.filter(reflection_1.isInterfaceStatement)[0];
|
|
1760
|
+
const fieldStatements = ifaceStatement.fields;
|
|
1761
|
+
const methodStatements = ifaceStatement.methods;
|
|
1762
|
+
// interface myIface
|
|
1763
|
+
let trivia = ifaceStatement.getLeadingTrivia();
|
|
1764
|
+
(0, chai_config_spec_1.expect)(trivia.length).to.be.greaterThan(0);
|
|
1765
|
+
(0, chai_config_spec_1.expect)(trivia.filter(t => t.kind === TokenKind_1.TokenKind.Comment).length).to.eq(1);
|
|
1766
|
+
// someField as integer
|
|
1767
|
+
trivia = fieldStatements[0].getLeadingTrivia();
|
|
1768
|
+
(0, chai_config_spec_1.expect)(trivia.length).to.be.greaterThan(0);
|
|
1769
|
+
(0, chai_config_spec_1.expect)(trivia.filter(t => t.kind === TokenKind_1.TokenKind.Comment).length).to.eq(1);
|
|
1770
|
+
// function someFunc() as string
|
|
1771
|
+
trivia = methodStatements[0].getLeadingTrivia();
|
|
1772
|
+
(0, chai_config_spec_1.expect)(trivia.length).to.be.greaterThan(0);
|
|
1773
|
+
(0, chai_config_spec_1.expect)(trivia.filter(t => t.kind === TokenKind_1.TokenKind.Comment).length).to.eq(1);
|
|
1774
|
+
});
|
|
1775
|
+
it('gets leading trivia from namespaces', () => {
|
|
1776
|
+
let { statements } = parse(`
|
|
1777
|
+
' Description of interface
|
|
1778
|
+
namespace Nested.Name.Space
|
|
1779
|
+
|
|
1780
|
+
end namespace
|
|
1781
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1782
|
+
const nameSpaceStatement = statements.filter(reflection_1.isNamespaceStatement)[0];
|
|
1783
|
+
// namespace Nested.Name.Space
|
|
1784
|
+
let trivia = nameSpaceStatement.getLeadingTrivia();
|
|
1785
|
+
(0, chai_config_spec_1.expect)(trivia.length).to.be.greaterThan(0);
|
|
1786
|
+
(0, chai_config_spec_1.expect)(trivia.filter(t => t.kind === TokenKind_1.TokenKind.Comment).length).to.eq(1);
|
|
1787
|
+
});
|
|
1788
|
+
});
|
|
1789
|
+
describe('unary/binary ordering', () => {
|
|
1790
|
+
it('creates the correct operator order for `not x = x` code', () => {
|
|
1791
|
+
let { diagnostics, statements } = parse(`
|
|
1792
|
+
function isStrNotEmpty(myStr as string) as boolean
|
|
1793
|
+
return not myStr = ""
|
|
1794
|
+
end function
|
|
1795
|
+
`);
|
|
1796
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1797
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isFunctionStatement)(statements[0])).to.be.true;
|
|
1798
|
+
const insideReturn = statements[0].func.body.statements[0].value;
|
|
1799
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isUnaryExpression)(insideReturn)).to.be.true;
|
|
1800
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isBinaryExpression)(insideReturn.right)).to.be.true;
|
|
1801
|
+
});
|
|
1802
|
+
it('creates the correct operator order for `not x + x` code', () => {
|
|
1803
|
+
let { diagnostics, statements } = parse(`
|
|
1804
|
+
function tryStuff() as integer
|
|
1805
|
+
return not 1 + 3 ' same as "not (3)" ... eg. the "flipped bits" of 3 (0000 0011) -> 1111 1100, or -4
|
|
1806
|
+
end function
|
|
1807
|
+
`);
|
|
1808
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1809
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isFunctionStatement)(statements[0])).to.be.true;
|
|
1810
|
+
const insideReturn = statements[0].func.body.statements[0].value;
|
|
1811
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isUnaryExpression)(insideReturn)).to.be.true;
|
|
1812
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isBinaryExpression)(insideReturn.right)).to.be.true;
|
|
1813
|
+
});
|
|
1814
|
+
it('creates the correct operator order for `x = not x` code', () => {
|
|
1815
|
+
let { diagnostics, statements } = parse(`
|
|
1816
|
+
function tryStuff() as boolean
|
|
1817
|
+
return 4 = not -5 ' same as "4 = 4"
|
|
1818
|
+
end function
|
|
1819
|
+
`);
|
|
1820
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1821
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isFunctionStatement)(statements[0])).to.be.true;
|
|
1822
|
+
const insideReturn = statements[0].func.body.statements[0].value;
|
|
1823
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isBinaryExpression)(insideReturn)).to.be.true;
|
|
1824
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isLiteralExpression)(insideReturn.left)).to.be.true;
|
|
1825
|
+
const right = insideReturn.right;
|
|
1826
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isUnaryExpression)(right)).to.be.true;
|
|
1827
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isUnaryExpression)(right.right)).to.be.true; // not ( - ( 5))
|
|
1828
|
+
});
|
|
1829
|
+
it('allows multiple nots', () => {
|
|
1830
|
+
let { diagnostics, statements } = parse(`
|
|
1831
|
+
function tryStuff() as integer
|
|
1832
|
+
return not not not 4
|
|
1833
|
+
end function
|
|
1834
|
+
`);
|
|
1835
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1836
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isFunctionStatement)(statements[0])).to.be.true;
|
|
1837
|
+
const insideReturn = statements[0].func.body.statements[0].value;
|
|
1838
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isUnaryExpression)(insideReturn)).to.be.true;
|
|
1839
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isUnaryExpression)(insideReturn.right)).to.be.true;
|
|
1840
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isUnaryExpression)(insideReturn.right.right)).to.be.true;
|
|
1841
|
+
});
|
|
1842
|
+
it('allows multiple -', () => {
|
|
1843
|
+
let { diagnostics, statements } = parse(`
|
|
1844
|
+
function tryStuff() as integer
|
|
1845
|
+
return - - - 4
|
|
1846
|
+
end function
|
|
1847
|
+
`);
|
|
1848
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1849
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isFunctionStatement)(statements[0])).to.be.true;
|
|
1850
|
+
const insideReturn = statements[0].func.body.statements[0].value;
|
|
1851
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isUnaryExpression)(insideReturn)).to.be.true;
|
|
1852
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isUnaryExpression)(insideReturn.right)).to.be.true;
|
|
1853
|
+
(0, chai_config_spec_1.expect)((0, reflection_1.isUnaryExpression)(insideReturn.right.right)).to.be.true;
|
|
1854
|
+
});
|
|
1855
|
+
});
|
|
1304
1856
|
});
|
|
1305
1857
|
function parse(text, mode) {
|
|
1306
1858
|
let { tokens } = Lexer_1.Lexer.scan(text);
|