brighterscript 1.0.0-alpha.2 → 1.0.0-alpha.20
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 +542 -253
- package/README.md +30 -9
- package/bsconfig.schema.json +13 -1
- package/dist/BsConfig.d.ts +4 -0
- package/dist/Cache.d.ts +3 -8
- package/dist/Cache.js +9 -14
- package/dist/Cache.js.map +1 -1
- package/dist/CodeActionUtil.d.ts +11 -2
- package/dist/CodeActionUtil.js +17 -3
- package/dist/CodeActionUtil.js.map +1 -1
- package/dist/CommentFlagProcessor.d.ts +4 -4
- package/dist/CommentFlagProcessor.js +5 -3
- package/dist/CommentFlagProcessor.js.map +1 -1
- package/dist/DependencyGraph.js +5 -4
- package/dist/DependencyGraph.js.map +1 -1
- package/dist/DiagnosticFilterer.js +1 -1
- package/dist/DiagnosticFilterer.js.map +1 -1
- package/dist/DiagnosticMessages.d.ts +59 -4
- package/dist/DiagnosticMessages.js +65 -7
- package/dist/DiagnosticMessages.js.map +1 -1
- package/dist/LanguageServer.d.ts +4 -14
- package/dist/LanguageServer.js +40 -26
- package/dist/LanguageServer.js.map +1 -1
- package/dist/Logger.d.ts +2 -0
- package/dist/Logger.js +10 -8
- package/dist/Logger.js.map +1 -1
- package/dist/PluginInterface.d.ts +7 -3
- package/dist/PluginInterface.js +9 -0
- package/dist/PluginInterface.js.map +1 -1
- package/dist/Program.d.ts +43 -25
- package/dist/Program.js +180 -82
- package/dist/Program.js.map +1 -1
- package/dist/ProgramBuilder.d.ts +4 -0
- package/dist/ProgramBuilder.js +30 -14
- package/dist/ProgramBuilder.js.map +1 -1
- package/dist/Scope.d.ts +100 -28
- package/dist/Scope.js +382 -154
- package/dist/Scope.js.map +1 -1
- package/dist/SemanticTokenUtils.d.ts +14 -0
- package/dist/SemanticTokenUtils.js +81 -0
- package/dist/SemanticTokenUtils.js.map +1 -0
- package/dist/SymbolTable.d.ts +10 -4
- package/dist/SymbolTable.js +40 -13
- package/dist/SymbolTable.js.map +1 -1
- package/dist/XmlScope.d.ts +8 -3
- package/dist/XmlScope.js +65 -27
- package/dist/XmlScope.js.map +1 -1
- package/dist/astUtils/AstEditor.d.ts +33 -0
- package/dist/astUtils/AstEditor.js +107 -0
- package/dist/astUtils/AstEditor.js.map +1 -0
- package/dist/{types/FunctionType.spec.d.ts → astUtils/AstEditor.spec.d.ts} +0 -0
- package/dist/astUtils/AstEditor.spec.js +170 -0
- package/dist/astUtils/AstEditor.spec.js.map +1 -0
- package/dist/astUtils/creators.d.ts +24 -6
- package/dist/astUtils/creators.js +130 -19
- package/dist/astUtils/creators.js.map +1 -1
- package/dist/astUtils/creators.spec.js +14 -4
- package/dist/astUtils/creators.spec.js.map +1 -1
- package/dist/astUtils/reflection.d.ts +27 -8
- package/dist/astUtils/reflection.js +66 -1
- package/dist/astUtils/reflection.js.map +1 -1
- package/dist/astUtils/reflection.spec.js +130 -119
- package/dist/astUtils/reflection.spec.js.map +1 -1
- package/dist/astUtils/stackedVisitor.js.map +1 -1
- package/dist/astUtils/stackedVisitor.spec.js +13 -13
- package/dist/astUtils/stackedVisitor.spec.js.map +1 -1
- package/dist/astUtils/visitors.d.ts +17 -2
- package/dist/astUtils/visitors.js +2 -2
- package/dist/astUtils/visitors.js.map +1 -1
- package/dist/astUtils/visitors.spec.js +31 -29
- package/dist/astUtils/visitors.spec.js.map +1 -1
- package/dist/astUtils/xml.d.ts +4 -3
- package/dist/astUtils/xml.js +8 -3
- package/dist/astUtils/xml.js.map +1 -1
- package/dist/bscPlugin/BscPlugin.d.ts +7 -1
- package/dist/bscPlugin/BscPlugin.js +28 -0
- package/dist/bscPlugin/BscPlugin.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +4 -4
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +26 -26
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.d.ts +9 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +97 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.d.ts +1 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js +73 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +1 -0
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.d.ts +8 -0
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js +52 -0
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js.map +1 -0
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.d.ts +1 -0
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js +32 -0
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js.map +1 -0
- package/dist/bscPlugin/validation/BrsFileValidator.d.ts +9 -0
- package/dist/bscPlugin/validation/BrsFileValidator.js +66 -0
- package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -0
- package/dist/bscPlugin/validation/ScopeValidator.d.ts +29 -0
- package/dist/bscPlugin/validation/ScopeValidator.js +183 -0
- package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -0
- package/dist/cli.js +9 -3
- package/dist/cli.js.map +1 -1
- package/dist/diagnosticUtils.d.ts +1 -0
- package/dist/diagnosticUtils.js +15 -8
- package/dist/diagnosticUtils.js.map +1 -1
- package/dist/examples/plugins/removePrint.js +12 -14
- package/dist/examples/plugins/removePrint.js.map +1 -1
- package/dist/files/BrsFile.Class.spec.js +634 -145
- package/dist/files/BrsFile.Class.spec.js.map +1 -1
- package/dist/files/BrsFile.d.ts +62 -30
- package/dist/files/BrsFile.js +683 -335
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/BrsFile.spec.js +1055 -449
- package/dist/files/BrsFile.spec.js.map +1 -1
- package/dist/files/XmlFile.d.ts +11 -10
- package/dist/files/XmlFile.js +33 -26
- package/dist/files/XmlFile.js.map +1 -1
- package/dist/files/XmlFile.spec.js +302 -237
- package/dist/files/XmlFile.spec.js.map +1 -1
- package/dist/files/tests/imports.spec.js +44 -42
- package/dist/files/tests/imports.spec.js.map +1 -1
- package/dist/files/tests/optionalChaning.spec.d.ts +1 -0
- package/dist/files/tests/optionalChaning.spec.js +88 -0
- package/dist/files/tests/optionalChaning.spec.js.map +1 -0
- package/dist/globalCallables.d.ts +3 -1
- package/dist/globalCallables.js +424 -152
- package/dist/globalCallables.js.map +1 -1
- package/dist/index.d.ts +13 -3
- package/dist/index.js +23 -4
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +129 -16
- package/dist/lexer/Lexer.d.ts +19 -1
- package/dist/lexer/Lexer.js +127 -21
- package/dist/lexer/Lexer.js.map +1 -1
- package/dist/lexer/Lexer.spec.js +657 -536
- package/dist/lexer/Lexer.spec.js.map +1 -1
- package/dist/lexer/Token.d.ts +2 -2
- package/dist/lexer/TokenKind.d.ts +13 -1
- package/dist/lexer/TokenKind.js +60 -3
- package/dist/lexer/TokenKind.js.map +1 -1
- package/dist/parser/BrsTranspileState.d.ts +7 -0
- package/dist/parser/BrsTranspileState.js +9 -0
- package/dist/parser/BrsTranspileState.js.map +1 -1
- package/dist/parser/Expression.d.ts +150 -34
- package/dist/parser/Expression.js +337 -150
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Parser.Class.spec.js +189 -89
- package/dist/parser/Parser.Class.spec.js.map +1 -1
- package/dist/parser/Parser.d.ts +152 -29
- package/dist/parser/Parser.js +1095 -501
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/Parser.spec.js +687 -266
- package/dist/parser/Parser.spec.js.map +1 -1
- package/dist/parser/SGParser.d.ts +41 -4
- package/dist/parser/SGParser.js +186 -175
- package/dist/parser/SGParser.js.map +1 -1
- package/dist/parser/SGParser.spec.js +35 -22
- package/dist/parser/SGParser.spec.js.map +1 -1
- package/dist/parser/SGTypes.d.ts +206 -38
- package/dist/parser/SGTypes.js +470 -161
- package/dist/parser/SGTypes.js.map +1 -1
- package/dist/parser/SGTypes.spec.d.ts +1 -0
- package/dist/parser/SGTypes.spec.js +351 -0
- package/dist/parser/SGTypes.spec.js.map +1 -0
- package/dist/parser/Statement.d.ts +194 -40
- package/dist/parser/Statement.js +597 -160
- package/dist/parser/Statement.js.map +1 -1
- package/dist/parser/Statement.spec.js +11 -11
- package/dist/parser/Statement.spec.js.map +1 -1
- package/dist/parser/TranspileState.d.ts +1 -1
- package/dist/parser/TranspileState.js +15 -7
- package/dist/parser/TranspileState.js.map +1 -1
- package/dist/parser/tests/Parser.spec.d.ts +10 -9
- package/dist/parser/tests/Parser.spec.js +15 -11
- package/dist/parser/tests/Parser.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/For.spec.js +60 -60
- package/dist/parser/tests/controlFlow/For.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/ForEach.spec.js +40 -39
- package/dist/parser/tests/controlFlow/ForEach.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/If.spec.js +213 -194
- package/dist/parser/tests/controlFlow/If.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/While.spec.js +37 -37
- package/dist/parser/tests/controlFlow/While.spec.js.map +1 -1
- package/dist/parser/tests/expression/Additive.spec.js +30 -30
- package/dist/parser/tests/expression/Additive.spec.js.map +1 -1
- package/dist/parser/tests/expression/ArrayLiterals.spec.js +119 -119
- package/dist/parser/tests/expression/ArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +162 -138
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/expression/Boolean.spec.js +24 -24
- package/dist/parser/tests/expression/Boolean.spec.js.map +1 -1
- package/dist/parser/tests/expression/Call.spec.js +41 -40
- package/dist/parser/tests/expression/Call.spec.js.map +1 -1
- package/dist/parser/tests/expression/Exponential.spec.js +17 -17
- package/dist/parser/tests/expression/Exponential.spec.js.map +1 -1
- package/dist/parser/tests/expression/Function.spec.js +256 -256
- package/dist/parser/tests/expression/Function.spec.js.map +1 -1
- package/dist/parser/tests/expression/Indexing.spec.js +87 -87
- package/dist/parser/tests/expression/Indexing.spec.js.map +1 -1
- package/dist/parser/tests/expression/Multiplicative.spec.js +37 -37
- package/dist/parser/tests/expression/Multiplicative.spec.js.map +1 -1
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +75 -63
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/PrefixUnary.spec.js +41 -41
- package/dist/parser/tests/expression/PrefixUnary.spec.js.map +1 -1
- package/dist/parser/tests/expression/Primary.spec.js +41 -41
- package/dist/parser/tests/expression/Primary.spec.js.map +1 -1
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.d.ts +1 -0
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +171 -0
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.js.map +1 -0
- package/dist/parser/tests/expression/Relational.spec.js +43 -43
- package/dist/parser/tests/expression/Relational.spec.js.map +1 -1
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.js +9 -9
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js +28 -28
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TernaryExpression.spec.js +102 -102
- package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
- package/dist/parser/tests/statement/AssignmentOperators.spec.js +36 -36
- package/dist/parser/tests/statement/AssignmentOperators.spec.js.map +1 -1
- package/dist/parser/tests/statement/Declaration.spec.js +44 -44
- package/dist/parser/tests/statement/Declaration.spec.js.map +1 -1
- package/dist/parser/tests/statement/Dim.spec.js +21 -21
- package/dist/parser/tests/statement/Dim.spec.js.map +1 -1
- package/dist/parser/tests/statement/Enum.spec.d.ts +1 -0
- package/dist/parser/tests/statement/Enum.spec.js +840 -0
- package/dist/parser/tests/statement/Enum.spec.js.map +1 -0
- package/dist/parser/tests/statement/For.spec.d.ts +1 -0
- package/dist/parser/tests/statement/For.spec.js +46 -0
- package/dist/parser/tests/statement/For.spec.js.map +1 -0
- package/dist/parser/tests/statement/ForEach.spec.d.ts +1 -0
- package/dist/parser/tests/statement/ForEach.spec.js +37 -0
- package/dist/parser/tests/statement/ForEach.spec.js.map +1 -0
- package/dist/parser/tests/statement/Function.spec.js +198 -197
- package/dist/parser/tests/statement/Function.spec.js.map +1 -1
- package/dist/parser/tests/statement/Goto.spec.js +15 -14
- package/dist/parser/tests/statement/Goto.spec.js.map +1 -1
- package/dist/parser/tests/statement/Increment.spec.js +50 -50
- package/dist/parser/tests/statement/Increment.spec.js.map +1 -1
- package/dist/parser/tests/statement/InterfaceStatement.spec.d.ts +1 -0
- package/dist/parser/tests/statement/InterfaceStatement.spec.js +254 -0
- package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +1 -0
- package/dist/parser/tests/statement/LibraryStatement.spec.js +17 -17
- package/dist/parser/tests/statement/LibraryStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Misc.spec.js +108 -106
- package/dist/parser/tests/statement/Misc.spec.js.map +1 -1
- package/dist/parser/tests/statement/PrintStatement.spec.js +40 -40
- package/dist/parser/tests/statement/PrintStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/ReturnStatement.spec.js +46 -46
- package/dist/parser/tests/statement/ReturnStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Set.spec.js +83 -83
- package/dist/parser/tests/statement/Set.spec.js.map +1 -1
- package/dist/parser/tests/statement/Stop.spec.js +12 -11
- package/dist/parser/tests/statement/Stop.spec.js.map +1 -1
- package/dist/parser/tests/statement/Throw.spec.js +5 -5
- package/dist/parser/tests/statement/Throw.spec.js.map +1 -1
- package/dist/parser/tests/statement/TryCatch.spec.js +15 -13
- package/dist/parser/tests/statement/TryCatch.spec.js.map +1 -1
- package/dist/preprocessor/Chunk.d.ts +1 -1
- package/dist/preprocessor/Chunk.js.map +1 -1
- package/dist/preprocessor/Manifest.d.ts +5 -5
- package/dist/preprocessor/Manifest.js +14 -35
- package/dist/preprocessor/Manifest.js.map +1 -1
- package/dist/preprocessor/Manifest.spec.d.ts +1 -0
- package/dist/preprocessor/Manifest.spec.js +78 -103
- package/dist/preprocessor/Manifest.spec.js.map +1 -1
- package/dist/preprocessor/Preprocessor.d.ts +1 -1
- package/dist/preprocessor/Preprocessor.js +8 -8
- package/dist/preprocessor/Preprocessor.js.map +1 -1
- package/dist/preprocessor/Preprocessor.spec.js +49 -49
- package/dist/preprocessor/Preprocessor.spec.js.map +1 -1
- package/dist/preprocessor/PreprocessorParser.spec.js +72 -72
- package/dist/preprocessor/PreprocessorParser.spec.js.map +1 -1
- package/dist/roku-types/data.json +21891 -0
- package/dist/roku-types/index.d.ts +6776 -0
- package/dist/roku-types/index.js +11 -0
- package/dist/roku-types/index.js.map +1 -0
- package/dist/types/ArrayType.d.ts +8 -5
- package/dist/types/ArrayType.js +52 -12
- package/dist/types/ArrayType.js.map +1 -1
- package/dist/types/ArrayType.spec.js +72 -11
- package/dist/types/ArrayType.spec.js.map +1 -1
- package/dist/types/BooleanType.d.ts +4 -2
- package/dist/types/BooleanType.js +9 -4
- package/dist/types/BooleanType.js.map +1 -1
- package/dist/types/BooleanType.spec.js +5 -3
- package/dist/types/BooleanType.spec.js.map +1 -1
- package/dist/types/BscType.d.ts +20 -5
- package/dist/types/BscType.js +24 -0
- package/dist/types/BscType.js.map +1 -1
- package/dist/types/CustomType.d.ts +8 -6
- package/dist/types/CustomType.js +20 -11
- package/dist/types/CustomType.js.map +1 -1
- package/dist/types/DoubleType.d.ts +2 -0
- package/dist/types/DoubleType.js +14 -9
- package/dist/types/DoubleType.js.map +1 -1
- package/dist/types/DoubleType.spec.js +5 -3
- package/dist/types/DoubleType.spec.js.map +1 -1
- package/dist/types/DynamicType.d.ts +2 -0
- package/dist/types/DynamicType.js +6 -2
- package/dist/types/DynamicType.js.map +1 -1
- package/dist/types/DynamicType.spec.js +2 -2
- package/dist/types/DynamicType.spec.js.map +1 -1
- package/dist/types/FloatType.d.ts +2 -0
- package/dist/types/FloatType.js +14 -9
- package/dist/types/FloatType.js.map +1 -1
- package/dist/types/FloatType.spec.js +4 -2
- package/dist/types/FloatType.spec.js.map +1 -1
- package/dist/types/FunctionType.d.ts +7 -31
- package/dist/types/FunctionType.js +11 -57
- package/dist/types/FunctionType.js.map +1 -1
- package/dist/types/IntegerType.d.ts +2 -0
- package/dist/types/IntegerType.js +14 -9
- package/dist/types/IntegerType.js.map +1 -1
- package/dist/types/IntegerType.spec.js +5 -3
- package/dist/types/IntegerType.spec.js.map +1 -1
- package/dist/types/InterfaceType.d.ts +13 -4
- package/dist/types/InterfaceType.js +48 -8
- package/dist/types/InterfaceType.js.map +1 -1
- package/dist/types/InterfaceType.spec.d.ts +1 -0
- package/dist/types/InterfaceType.spec.js +194 -0
- package/dist/types/InterfaceType.spec.js.map +1 -0
- package/dist/types/InvalidType.d.ts +4 -2
- package/dist/types/InvalidType.js +10 -5
- package/dist/types/InvalidType.js.map +1 -1
- package/dist/types/InvalidType.spec.js +4 -2
- package/dist/types/InvalidType.spec.js.map +1 -1
- package/dist/types/LazyType.d.ts +8 -7
- package/dist/types/LazyType.js +22 -10
- package/dist/types/LazyType.js.map +1 -1
- package/dist/types/LongIntegerType.d.ts +2 -0
- package/dist/types/LongIntegerType.js +14 -9
- package/dist/types/LongIntegerType.js.map +1 -1
- package/dist/types/LongIntegerType.spec.js +4 -2
- package/dist/types/LongIntegerType.spec.js.map +1 -1
- package/dist/types/ObjectType.d.ts +8 -4
- package/dist/types/ObjectType.js +9 -4
- package/dist/types/ObjectType.js.map +1 -1
- package/dist/types/ObjectType.spec.js +2 -2
- package/dist/types/ObjectType.spec.js.map +1 -1
- package/dist/types/StringType.d.ts +4 -2
- package/dist/types/StringType.js +9 -4
- package/dist/types/StringType.js.map +1 -1
- package/dist/types/StringType.spec.js +4 -2
- package/dist/types/StringType.spec.js.map +1 -1
- package/dist/types/TypedFunctionType.d.ts +28 -0
- package/dist/types/TypedFunctionType.js +88 -0
- package/dist/types/TypedFunctionType.js.map +1 -0
- package/dist/types/TypedFunctionType.spec.d.ts +1 -0
- package/dist/types/TypedFunctionType.spec.js +37 -0
- package/dist/types/TypedFunctionType.spec.js.map +1 -0
- package/dist/types/UninitializedType.js +3 -3
- package/dist/types/UninitializedType.js.map +1 -1
- package/dist/types/VoidType.d.ts +4 -2
- package/dist/types/VoidType.js +8 -4
- package/dist/types/VoidType.js.map +1 -1
- package/dist/types/VoidType.spec.js +2 -2
- package/dist/types/VoidType.spec.js.map +1 -1
- package/dist/types/helpers.d.ts +42 -0
- package/dist/types/helpers.js +118 -0
- package/dist/types/helpers.js.map +1 -0
- package/dist/util.d.ts +87 -16
- package/dist/util.js +339 -94
- package/dist/util.js.map +1 -1
- package/dist/validators/ClassValidator.d.ts +19 -2
- package/dist/validators/ClassValidator.js +163 -102
- package/dist/validators/ClassValidator.js.map +1 -1
- package/package.json +26 -15
- package/dist/astUtils/index.d.ts +0 -7
- package/dist/astUtils/index.js +0 -26
- package/dist/astUtils/index.js.map +0 -1
- package/dist/lexer/index.d.ts +0 -3
- package/dist/lexer/index.js +0 -17
- package/dist/lexer/index.js.map +0 -1
- package/dist/parser/index.d.ts +0 -3
- package/dist/parser/index.js +0 -16
- package/dist/parser/index.js.map +0 -1
- package/dist/preprocessor/index.d.ts +0 -3
- package/dist/preprocessor/index.js +0 -16
- package/dist/preprocessor/index.js.map +0 -1
- package/dist/types/FunctionType.spec.js +0 -23
- package/dist/types/FunctionType.spec.js.map +0 -1
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.failStatementType = exports.rangeToArray = void 0;
|
|
4
4
|
const chai_1 = require("chai");
|
|
5
|
-
const
|
|
5
|
+
const Lexer_1 = require("../lexer/Lexer");
|
|
6
|
+
const TokenKind_1 = require("../lexer/TokenKind");
|
|
6
7
|
const Expression_1 = require("./Expression");
|
|
7
8
|
const Parser_1 = require("./Parser");
|
|
8
9
|
const Statement_1 = require("./Statement");
|
|
@@ -10,19 +11,24 @@ const vscode_languageserver_1 = require("vscode-languageserver");
|
|
|
10
11
|
const DiagnosticMessages_1 = require("../DiagnosticMessages");
|
|
11
12
|
const reflection_1 = require("../astUtils/reflection");
|
|
12
13
|
const testHelpers_spec_1 = require("../testHelpers.spec");
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
14
|
+
const BrsTranspileState_1 = require("./BrsTranspileState");
|
|
15
|
+
const source_map_1 = require("source-map");
|
|
16
|
+
const BrsFile_1 = require("../files/BrsFile");
|
|
17
|
+
const Program_1 = require("../Program");
|
|
18
|
+
const SymbolTable_1 = require("../SymbolTable");
|
|
19
|
+
const TypedFunctionType_1 = require("../types/TypedFunctionType");
|
|
20
|
+
const LazyType_1 = require("../types/LazyType");
|
|
17
21
|
const IntegerType_1 = require("../types/IntegerType");
|
|
22
|
+
const StringType_1 = require("../types/StringType");
|
|
18
23
|
const ObjectType_1 = require("../types/ObjectType");
|
|
19
|
-
const
|
|
20
|
-
const
|
|
24
|
+
const CustomType_1 = require("../types/CustomType");
|
|
25
|
+
const VoidType_1 = require("../types/VoidType");
|
|
21
26
|
const DynamicType_1 = require("../types/DynamicType");
|
|
22
27
|
const util_1 = require("../util");
|
|
28
|
+
const ArrayType_1 = require("../types/ArrayType");
|
|
23
29
|
describe('parser', () => {
|
|
24
30
|
it('emits empty object when empty token list is provided', () => {
|
|
25
|
-
chai_1.expect(Parser_1.Parser.parse([])).to.deep.include({
|
|
31
|
+
(0, chai_1.expect)(Parser_1.Parser.parse([])).to.deep.include({
|
|
26
32
|
statements: [],
|
|
27
33
|
diagnostics: []
|
|
28
34
|
});
|
|
@@ -40,7 +46,7 @@ describe('parser', () => {
|
|
|
40
46
|
humansAreAlive = false
|
|
41
47
|
end sub
|
|
42
48
|
`);
|
|
43
|
-
chai_1.expect(parser.references.functionExpressions[0].symbolTable.
|
|
49
|
+
(0, chai_1.expect)(parser.references.functionExpressions[0].symbolTable.getOwnSymbols().map(x => x.name).sort()).to.eql([
|
|
44
50
|
'herd',
|
|
45
51
|
'humansAreAlive',
|
|
46
52
|
'i',
|
|
@@ -49,7 +55,7 @@ describe('parser', () => {
|
|
|
49
55
|
'zombie'
|
|
50
56
|
]);
|
|
51
57
|
parser.invalidateReferences();
|
|
52
|
-
chai_1.expect(parser.references.functionExpressions[0].symbolTable.
|
|
58
|
+
(0, chai_1.expect)(parser.references.functionExpressions[0].symbolTable.getOwnSymbols().map(x => x.name).sort()).to.eql([
|
|
53
59
|
'herd',
|
|
54
60
|
'humansAreAlive',
|
|
55
61
|
'i',
|
|
@@ -69,13 +75,17 @@ describe('parser', () => {
|
|
|
69
75
|
end sub
|
|
70
76
|
`);
|
|
71
77
|
parser.invalidateReferences();
|
|
72
|
-
chai_1.expect(parser.references.functionExpressions
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
(0, chai_1.expect)(parser.references.functionExpressions.map(x => {
|
|
79
|
+
return x.symbolTable.getOwnSymbols().map(x => x.name);
|
|
80
|
+
})).to.eql([
|
|
81
|
+
[
|
|
82
|
+
'outerName',
|
|
83
|
+
'speak',
|
|
84
|
+
'age'
|
|
85
|
+
],
|
|
86
|
+
[
|
|
87
|
+
'innerName'
|
|
88
|
+
]
|
|
79
89
|
]);
|
|
80
90
|
});
|
|
81
91
|
it('gets called if references are missing', () => {
|
|
@@ -86,7 +96,7 @@ describe('parser', () => {
|
|
|
86
96
|
sub UnusedFunction()
|
|
87
97
|
end sub
|
|
88
98
|
`);
|
|
89
|
-
chai_1.expect(parser.references.functionStatements.map(x => x.name.text)).to.eql([
|
|
99
|
+
(0, chai_1.expect)(parser.references.functionStatements.map(x => x.name.text)).to.eql([
|
|
90
100
|
'main',
|
|
91
101
|
'UnusedFunction'
|
|
92
102
|
]);
|
|
@@ -94,12 +104,69 @@ describe('parser', () => {
|
|
|
94
104
|
parser.ast.statements.splice(1);
|
|
95
105
|
//tell the parser we modified the AST and need to regenerate references
|
|
96
106
|
parser.invalidateReferences();
|
|
97
|
-
chai_1.expect(parser['_references']).not.to.exist;
|
|
107
|
+
(0, chai_1.expect)(parser['_references']).not.to.exist;
|
|
98
108
|
//calling `references` automatically regenerates the references
|
|
99
|
-
chai_1.expect(parser.references.functionStatements.map(x => x.name.text)).to.eql([
|
|
109
|
+
(0, chai_1.expect)(parser.references.functionStatements.map(x => x.name.text)).to.eql([
|
|
100
110
|
'main'
|
|
101
111
|
]);
|
|
102
112
|
});
|
|
113
|
+
function expressionsToStrings(expressions) {
|
|
114
|
+
return [...expressions.values()].map(x => {
|
|
115
|
+
const file = new BrsFile_1.BrsFile('', '', new Program_1.Program({}));
|
|
116
|
+
const state = new BrsTranspileState_1.BrsTranspileState(file);
|
|
117
|
+
return new source_map_1.SourceNode(null, null, null, x.transpile(state)).toString();
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
it('works for references.expressions', () => {
|
|
121
|
+
const parser = Parser_1.Parser.parse(`
|
|
122
|
+
a += 1 + 2
|
|
123
|
+
a++
|
|
124
|
+
a--
|
|
125
|
+
some.node@.doCallfunc()
|
|
126
|
+
bravo(3 + 4).jump(callMe())
|
|
127
|
+
obj = {
|
|
128
|
+
val1: someValue
|
|
129
|
+
}
|
|
130
|
+
arr = [
|
|
131
|
+
one
|
|
132
|
+
]
|
|
133
|
+
thing = alpha.bravo
|
|
134
|
+
alpha.charlie()
|
|
135
|
+
delta(alpha.delta)
|
|
136
|
+
call1().a.b.call2()
|
|
137
|
+
class Person
|
|
138
|
+
name as string = "bob"
|
|
139
|
+
end class
|
|
140
|
+
function thing(p1 = name.space.getSomething())
|
|
141
|
+
|
|
142
|
+
end function
|
|
143
|
+
`);
|
|
144
|
+
const expected = [
|
|
145
|
+
'a += 1 + 2',
|
|
146
|
+
'a++',
|
|
147
|
+
'a--',
|
|
148
|
+
//currently the "toString" does a transpile, so that's why this is different.
|
|
149
|
+
'some.node.callfunc("doCallfunc", invalid)',
|
|
150
|
+
'3 + 4',
|
|
151
|
+
'callMe()',
|
|
152
|
+
'bravo(3 + 4).jump(callMe())',
|
|
153
|
+
'someValue',
|
|
154
|
+
'{\n val1: someValue\n}',
|
|
155
|
+
'one',
|
|
156
|
+
'[\n one\n]',
|
|
157
|
+
'alpha.bravo',
|
|
158
|
+
'alpha.charlie()',
|
|
159
|
+
'alpha.delta',
|
|
160
|
+
'delta(alpha.delta)',
|
|
161
|
+
'call1().a.b.call2()',
|
|
162
|
+
'"bob"',
|
|
163
|
+
'name.space.getSomething()'
|
|
164
|
+
].sort();
|
|
165
|
+
(0, chai_1.expect)(expressionsToStrings(parser.references.expressions).sort()).to.eql(expected);
|
|
166
|
+
//tell the parser we modified the AST and need to regenerate references
|
|
167
|
+
parser.invalidateReferences();
|
|
168
|
+
(0, chai_1.expect)(expressionsToStrings(parser.references.expressions).sort()).to.eql(expected);
|
|
169
|
+
});
|
|
103
170
|
});
|
|
104
171
|
describe('callfunc operator', () => {
|
|
105
172
|
it('is not allowed in brightscript mode', () => {
|
|
@@ -109,7 +176,7 @@ describe('parser', () => {
|
|
|
109
176
|
node@.doSomething(1, 2)
|
|
110
177
|
end sub
|
|
111
178
|
`, Parser_1.ParseMode.BrightScript);
|
|
112
|
-
chai_1.expect((_a = parser.diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.bsFeatureNotSupportedInBrsFiles('callfunc operator').message);
|
|
179
|
+
(0, chai_1.expect)((_a = parser.diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.bsFeatureNotSupportedInBrsFiles('callfunc operator').message);
|
|
113
180
|
});
|
|
114
181
|
it('does not cause parse errors', () => {
|
|
115
182
|
var _a, _b, _c, _d, _e;
|
|
@@ -118,13 +185,96 @@ describe('parser', () => {
|
|
|
118
185
|
node@.doSomething(1, 2)
|
|
119
186
|
end sub
|
|
120
187
|
`, Parser_1.ParseMode.BrighterScript);
|
|
121
|
-
chai_1.expect((_a = parser.diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
122
|
-
chai_1.expect((_e = (_d = (_c = (_b = parser.statements[0]) === null || _b === void 0 ? void 0 : _b.func) === null || _c === void 0 ? void 0 : _c.body) === null || _d === void 0 ? void 0 : _d.statements[0]) === null || _e === void 0 ? void 0 : _e.expression).to.be.instanceof(Expression_1.CallfuncExpression);
|
|
188
|
+
(0, chai_1.expect)((_a = parser.diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
189
|
+
(0, chai_1.expect)((_e = (_d = (_c = (_b = parser.statements[0]) === null || _b === void 0 ? void 0 : _b.func) === null || _c === void 0 ? void 0 : _c.body) === null || _d === void 0 ? void 0 : _d.statements[0]) === null || _e === void 0 ? void 0 : _e.expression).to.be.instanceof(Expression_1.CallfuncExpression);
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
describe('optional chaining operator', () => {
|
|
193
|
+
function getExpression(text, options) {
|
|
194
|
+
const parser = parse(text, options === null || options === void 0 ? void 0 : options.parseMode);
|
|
195
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser);
|
|
196
|
+
const expressions = [...parser.references.expressions];
|
|
197
|
+
if (options === null || options === void 0 ? void 0 : options.matcher) {
|
|
198
|
+
return expressions.find(options.matcher);
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
return expressions[0];
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
it('works for ?.', () => {
|
|
205
|
+
const expression = getExpression(`value = person?.name`);
|
|
206
|
+
(0, chai_1.expect)(expression).to.be.instanceOf(Expression_1.DottedGetExpression);
|
|
207
|
+
(0, chai_1.expect)(expression.dot.kind).to.eql(TokenKind_1.TokenKind.QuestionDot);
|
|
208
|
+
});
|
|
209
|
+
it('works for ?[', () => {
|
|
210
|
+
const expression = getExpression(`value = person?["name"]`, { matcher: reflection_1.isIndexedGetExpression });
|
|
211
|
+
(0, chai_1.expect)(expression).to.be.instanceOf(Expression_1.IndexedGetExpression);
|
|
212
|
+
(0, chai_1.expect)(expression.openingSquare.kind).to.eql(TokenKind_1.TokenKind.QuestionLeftSquare);
|
|
213
|
+
(0, chai_1.expect)(expression.questionDotToken).not.to.exist;
|
|
214
|
+
});
|
|
215
|
+
it('works for ?.[', () => {
|
|
216
|
+
var _a;
|
|
217
|
+
const expression = getExpression(`value = person?.["name"]`, { matcher: reflection_1.isIndexedGetExpression });
|
|
218
|
+
(0, chai_1.expect)(expression).to.be.instanceOf(Expression_1.IndexedGetExpression);
|
|
219
|
+
(0, chai_1.expect)(expression.openingSquare.kind).to.eql(TokenKind_1.TokenKind.LeftSquareBracket);
|
|
220
|
+
(0, chai_1.expect)((_a = expression.questionDotToken) === null || _a === void 0 ? void 0 : _a.kind).to.eql(TokenKind_1.TokenKind.QuestionDot);
|
|
221
|
+
});
|
|
222
|
+
it('works for ?@', () => {
|
|
223
|
+
const expression = getExpression(`value = someXml?@someAttr`);
|
|
224
|
+
(0, chai_1.expect)(expression).to.be.instanceOf(Expression_1.XmlAttributeGetExpression);
|
|
225
|
+
(0, chai_1.expect)(expression.at.kind).to.eql(TokenKind_1.TokenKind.QuestionAt);
|
|
226
|
+
});
|
|
227
|
+
it('works for ?(', () => {
|
|
228
|
+
const expression = getExpression(`value = person.getName?()`);
|
|
229
|
+
(0, chai_1.expect)(expression).to.be.instanceOf(Expression_1.CallExpression);
|
|
230
|
+
(0, chai_1.expect)(expression.openingParen.kind).to.eql(TokenKind_1.TokenKind.QuestionLeftParen);
|
|
231
|
+
});
|
|
232
|
+
it('works for print statements using question mark', () => {
|
|
233
|
+
const { statements } = parse(`
|
|
234
|
+
?[1]
|
|
235
|
+
?(1+1)
|
|
236
|
+
`);
|
|
237
|
+
(0, chai_1.expect)(statements[0]).to.be.instanceOf(Statement_1.PrintStatement);
|
|
238
|
+
(0, chai_1.expect)(statements[1]).to.be.instanceOf(Statement_1.PrintStatement);
|
|
239
|
+
});
|
|
240
|
+
//TODO enable this once we properly parse IIFEs
|
|
241
|
+
it.skip('works for ?( in anonymous function', () => {
|
|
242
|
+
const expression = getExpression(`thing = (function() : end function)?()`);
|
|
243
|
+
(0, chai_1.expect)(expression).to.be.instanceOf(Expression_1.CallExpression);
|
|
244
|
+
(0, chai_1.expect)(expression.openingParen.kind).to.eql(TokenKind_1.TokenKind.QuestionLeftParen);
|
|
245
|
+
});
|
|
246
|
+
it('works for ?( in new call', () => {
|
|
247
|
+
const expression = getExpression(`thing = new Person?()`, { parseMode: Parser_1.ParseMode.BrighterScript });
|
|
248
|
+
(0, chai_1.expect)(expression).to.be.instanceOf(Expression_1.NewExpression);
|
|
249
|
+
(0, chai_1.expect)(expression.call.openingParen.kind).to.eql(TokenKind_1.TokenKind.QuestionLeftParen);
|
|
250
|
+
});
|
|
251
|
+
it('distinguishes between optional chaining and ternary expression', () => {
|
|
252
|
+
const parser = parse(`
|
|
253
|
+
sub main()
|
|
254
|
+
name = person?["name"]
|
|
255
|
+
isTrue = true
|
|
256
|
+
key = isTrue ? ["name"] : ["age"]
|
|
257
|
+
end sub
|
|
258
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
259
|
+
(0, chai_1.expect)(parser.references.assignmentStatements[0].value).is.instanceof(Expression_1.IndexedGetExpression);
|
|
260
|
+
(0, chai_1.expect)(parser.references.assignmentStatements[2].value).is.instanceof(Expression_1.TernaryExpression);
|
|
261
|
+
});
|
|
262
|
+
it('distinguishes between optional chaining and ternary expression', () => {
|
|
263
|
+
const parser = parse(`
|
|
264
|
+
sub main()
|
|
265
|
+
'optional chain. the lack of whitespace between ? and [ matters
|
|
266
|
+
key = isTrue ?["name"] : getDefault()
|
|
267
|
+
'ternary
|
|
268
|
+
key = isTrue ? ["name"] : getDefault()
|
|
269
|
+
end sub
|
|
270
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
271
|
+
(0, chai_1.expect)(parser.references.assignmentStatements[0].value).is.instanceof(Expression_1.IndexedGetExpression);
|
|
272
|
+
(0, chai_1.expect)(parser.references.assignmentStatements[1].value).is.instanceof(Expression_1.TernaryExpression);
|
|
123
273
|
});
|
|
124
274
|
});
|
|
125
275
|
describe('diagnostic locations', () => {
|
|
126
276
|
it('tracks basic diagnostic locations', () => {
|
|
127
|
-
chai_1.expect(parse(`
|
|
277
|
+
(0, chai_1.expect)(parse(`
|
|
128
278
|
sub main()
|
|
129
279
|
call()a
|
|
130
280
|
end sub
|
|
@@ -140,8 +290,8 @@ describe('parser', () => {
|
|
|
140
290
|
return "6c5cdf1"
|
|
141
291
|
end functionasdf
|
|
142
292
|
`).diagnostics;
|
|
143
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.exist.and.to.eql(DiagnosticMessages_1.DiagnosticMessages.expectedStatementOrFunctionCallButReceivedExpression().message);
|
|
144
|
-
chai_1.expect((_b = diagnostics[0]) === null || _b === void 0 ? void 0 : _b.range).to.eql(vscode_languageserver_1.Range.create(3, 20, 3, 32));
|
|
293
|
+
(0, chai_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.exist.and.to.eql(DiagnosticMessages_1.DiagnosticMessages.expectedStatementOrFunctionCallButReceivedExpression().message);
|
|
294
|
+
(0, chai_1.expect)((_b = diagnostics[0]) === null || _b === void 0 ? void 0 : _b.range).to.eql(vscode_languageserver_1.Range.create(3, 20, 3, 32));
|
|
145
295
|
});
|
|
146
296
|
});
|
|
147
297
|
describe('parse', () => {
|
|
@@ -154,7 +304,7 @@ describe('parser', () => {
|
|
|
154
304
|
end function()
|
|
155
305
|
end sub
|
|
156
306
|
`);
|
|
157
|
-
testHelpers_spec_1.expectZeroDiagnostics(parser);
|
|
307
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser);
|
|
158
308
|
});
|
|
159
309
|
it('supports grouped iife in assignment', () => {
|
|
160
310
|
const parser = parse(`
|
|
@@ -165,7 +315,7 @@ describe('parser', () => {
|
|
|
165
315
|
end function)()
|
|
166
316
|
end sub
|
|
167
317
|
`);
|
|
168
|
-
testHelpers_spec_1.expectZeroDiagnostics(parser);
|
|
318
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser);
|
|
169
319
|
});
|
|
170
320
|
it('supports returning iife call', () => {
|
|
171
321
|
const parser = parse(`
|
|
@@ -174,11 +324,11 @@ describe('parser', () => {
|
|
|
174
324
|
end sub)()
|
|
175
325
|
end sub
|
|
176
326
|
`);
|
|
177
|
-
testHelpers_spec_1.expectZeroDiagnostics(parser);
|
|
327
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser);
|
|
178
328
|
});
|
|
179
329
|
it('supports using "interface" as parameter name', () => {
|
|
180
330
|
var _a;
|
|
181
|
-
chai_1.expect((_a = parse(`
|
|
331
|
+
(0, chai_1.expect)((_a = parse(`
|
|
182
332
|
sub main(interface as object)
|
|
183
333
|
end sub
|
|
184
334
|
`, Parser_1.ParseMode.BrighterScript).diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
@@ -186,7 +336,7 @@ describe('parser', () => {
|
|
|
186
336
|
describe('namespace', () => {
|
|
187
337
|
it('catches namespaces declared not at root level', () => {
|
|
188
338
|
var _a;
|
|
189
|
-
chai_1.expect((_a = parse(`
|
|
339
|
+
(0, chai_1.expect)((_a = parse(`
|
|
190
340
|
sub main()
|
|
191
341
|
namespace Name.Space
|
|
192
342
|
end namespace
|
|
@@ -199,8 +349,8 @@ describe('parser', () => {
|
|
|
199
349
|
namespace Name.Space
|
|
200
350
|
end namespace
|
|
201
351
|
`, Parser_1.ParseMode.BrighterScript);
|
|
202
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
203
|
-
chai_1.expect(statements[0]).to.be.instanceof(Statement_1.NamespaceStatement);
|
|
352
|
+
(0, chai_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
353
|
+
(0, chai_1.expect)(statements[0]).to.be.instanceof(Statement_1.NamespaceStatement);
|
|
204
354
|
});
|
|
205
355
|
it('includes body', () => {
|
|
206
356
|
var _a;
|
|
@@ -210,9 +360,9 @@ describe('parser', () => {
|
|
|
210
360
|
end sub
|
|
211
361
|
end namespace
|
|
212
362
|
`, Parser_1.ParseMode.BrighterScript);
|
|
213
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
214
|
-
chai_1.expect(statements[0]).to.be.instanceof(Statement_1.NamespaceStatement);
|
|
215
|
-
chai_1.expect(statements[0].body.statements[0]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
363
|
+
(0, chai_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
364
|
+
(0, chai_1.expect)(statements[0]).to.be.instanceof(Statement_1.NamespaceStatement);
|
|
365
|
+
(0, chai_1.expect)(statements[0].body.statements[0]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
216
366
|
});
|
|
217
367
|
it('supports comments and newlines', () => {
|
|
218
368
|
var _a;
|
|
@@ -228,7 +378,7 @@ describe('parser', () => {
|
|
|
228
378
|
'comment
|
|
229
379
|
end namespace 'comment
|
|
230
380
|
`, Parser_1.ParseMode.BrighterScript);
|
|
231
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
381
|
+
(0, chai_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
232
382
|
});
|
|
233
383
|
it('catches missing name', () => {
|
|
234
384
|
var _a;
|
|
@@ -236,7 +386,7 @@ describe('parser', () => {
|
|
|
236
386
|
namespace
|
|
237
387
|
end namespace
|
|
238
388
|
`, Parser_1.ParseMode.BrighterScript);
|
|
239
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.expectedIdentifierAfterKeyword('namespace').message);
|
|
389
|
+
(0, chai_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.expectedIdentifierAfterKeyword('namespace').message);
|
|
240
390
|
});
|
|
241
391
|
it('recovers after missing `end namespace`', () => {
|
|
242
392
|
var _a, _b, _c;
|
|
@@ -245,9 +395,9 @@ describe('parser', () => {
|
|
|
245
395
|
sub main()
|
|
246
396
|
end sub
|
|
247
397
|
`, Parser_1.ParseMode.BrighterScript);
|
|
248
|
-
chai_1.expect(parser.ast.statements[0]).to.be.instanceof(Statement_1.NamespaceStatement);
|
|
249
|
-
chai_1.expect((_a = parser.diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.couldNotFindMatchingEndKeyword('namespace').message);
|
|
250
|
-
chai_1.expect((_c = (_b = parser.ast.statements[0]) === null || _b === void 0 ? void 0 : _b.body) === null || _c === void 0 ? void 0 : _c.statements[0]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
398
|
+
(0, chai_1.expect)(parser.ast.statements[0]).to.be.instanceof(Statement_1.NamespaceStatement);
|
|
399
|
+
(0, chai_1.expect)((_a = parser.diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.couldNotFindMatchingEndKeyword('namespace').message);
|
|
400
|
+
(0, chai_1.expect)((_c = (_b = parser.ast.statements[0]) === null || _b === void 0 ? void 0 : _b.body) === null || _c === void 0 ? void 0 : _c.statements[0]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
251
401
|
});
|
|
252
402
|
it('adds diagnostic when encountering namespace in brightscript mode', () => {
|
|
253
403
|
var _a;
|
|
@@ -255,7 +405,7 @@ describe('parser', () => {
|
|
|
255
405
|
namespace Name.Space
|
|
256
406
|
end namespace
|
|
257
407
|
`);
|
|
258
|
-
chai_1.expect((_a = parser.diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.bsFeatureNotSupportedInBrsFiles('namespace').message);
|
|
408
|
+
(0, chai_1.expect)((_a = parser.diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.bsFeatureNotSupportedInBrsFiles('namespace').message);
|
|
259
409
|
});
|
|
260
410
|
it('declares a symbol table for the namespace', () => {
|
|
261
411
|
let parser = parse(`
|
|
@@ -269,13 +419,13 @@ describe('parser', () => {
|
|
|
269
419
|
end function
|
|
270
420
|
end namespace
|
|
271
421
|
`, Parser_1.ParseMode.BrighterScript);
|
|
272
|
-
chai_1.expect(parser.ast.statements[0]).to.be.instanceof(Statement_1.NamespaceStatement);
|
|
422
|
+
(0, chai_1.expect)(parser.ast.statements[0]).to.be.instanceof(Statement_1.NamespaceStatement);
|
|
273
423
|
const namespaceStmt = parser.ast.statements[0];
|
|
274
|
-
chai_1.expect(namespaceStmt.symbolTable).to.be.instanceof(SymbolTable_1.SymbolTable);
|
|
275
|
-
chai_1.expect(namespaceStmt.symbolTable.getSymbolType('funcInt').toString()).to.equal('function funcInt() as integer');
|
|
276
|
-
chai_1.expect(namespaceStmt.symbolTable.getSymbolType('funcStr')).to.be.instanceof(
|
|
424
|
+
(0, chai_1.expect)(namespaceStmt.symbolTable).to.be.instanceof(SymbolTable_1.SymbolTable);
|
|
425
|
+
(0, chai_1.expect)(namespaceStmt.symbolTable.getSymbolType('funcInt').toString()).to.equal('function funcInt() as integer');
|
|
426
|
+
(0, chai_1.expect)(namespaceStmt.symbolTable.getSymbolType('funcStr')).to.be.instanceof(TypedFunctionType_1.TypedFunctionType);
|
|
277
427
|
const strFunctionType = namespaceStmt.symbolTable.getSymbolType('funcStr');
|
|
278
|
-
chai_1.expect(strFunctionType.returnType.toString()).to.equal('string');
|
|
428
|
+
(0, chai_1.expect)(strFunctionType.returnType.toString()).to.equal('string');
|
|
279
429
|
});
|
|
280
430
|
it('adds a fully qualified name of a function in a namespace to the parsers symbol table', () => {
|
|
281
431
|
let parser = parse(`
|
|
@@ -289,13 +439,13 @@ describe('parser', () => {
|
|
|
289
439
|
end function
|
|
290
440
|
end namespace
|
|
291
441
|
`, Parser_1.ParseMode.BrighterScript);
|
|
292
|
-
chai_1.expect(parser.symbolTable.getSymbolType('Name.Space.funcInt')).to.be.instanceof(
|
|
293
|
-
chai_1.expect(parser.symbolTable.getSymbolType('Name.Space.funcStr')).to.be.instanceof(
|
|
442
|
+
(0, chai_1.expect)(parser.symbolTable.getSymbolType('Name.Space.funcInt')).to.be.instanceof(TypedFunctionType_1.TypedFunctionType);
|
|
443
|
+
(0, chai_1.expect)(parser.symbolTable.getSymbolType('Name.Space.funcStr')).to.be.instanceof(TypedFunctionType_1.TypedFunctionType);
|
|
294
444
|
});
|
|
295
445
|
});
|
|
296
446
|
it('supports << operator', () => {
|
|
297
447
|
var _a;
|
|
298
|
-
chai_1.expect((_a = parse(`
|
|
448
|
+
(0, chai_1.expect)((_a = parse(`
|
|
299
449
|
sub main()
|
|
300
450
|
print ((r << 24) + (g << 16) + (b << 8) + a)
|
|
301
451
|
end sub
|
|
@@ -303,7 +453,7 @@ describe('parser', () => {
|
|
|
303
453
|
});
|
|
304
454
|
it('supports >> operator', () => {
|
|
305
455
|
var _a;
|
|
306
|
-
chai_1.expect((_a = parse(`
|
|
456
|
+
(0, chai_1.expect)((_a = parse(`
|
|
307
457
|
sub main()
|
|
308
458
|
print ((r >> 24) + (g >> 16) + (b >> 8) + a)
|
|
309
459
|
end sub
|
|
@@ -311,7 +461,7 @@ describe('parser', () => {
|
|
|
311
461
|
});
|
|
312
462
|
it('allows global function names with same as token to be called', () => {
|
|
313
463
|
var _a;
|
|
314
|
-
chai_1.expect((_a = parse(`
|
|
464
|
+
(0, chai_1.expect)((_a = parse(`
|
|
315
465
|
sub main()
|
|
316
466
|
print string(123)
|
|
317
467
|
end sub
|
|
@@ -325,18 +475,18 @@ describe('parser', () => {
|
|
|
325
475
|
age = personXml.firstChild@age
|
|
326
476
|
end sub
|
|
327
477
|
`);
|
|
328
|
-
chai_1.expect((_a = parser.diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.not.exist;
|
|
478
|
+
(0, chai_1.expect)((_a = parser.diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.not.exist;
|
|
329
479
|
let statements = parser.statements[0].func.body.statements;
|
|
330
480
|
let first = statements[0].value;
|
|
331
|
-
chai_1.expect(first).to.be.instanceof(Expression_1.XmlAttributeGetExpression);
|
|
332
|
-
chai_1.expect(first.name.text).to.equal('firstName');
|
|
333
|
-
chai_1.expect(first.at.text).to.equal('@');
|
|
334
|
-
chai_1.expect(first.obj.name.text).to.equal('personXml');
|
|
481
|
+
(0, chai_1.expect)(first).to.be.instanceof(Expression_1.XmlAttributeGetExpression);
|
|
482
|
+
(0, chai_1.expect)(first.name.text).to.equal('firstName');
|
|
483
|
+
(0, chai_1.expect)(first.at.text).to.equal('@');
|
|
484
|
+
(0, chai_1.expect)(first.obj.name.text).to.equal('personXml');
|
|
335
485
|
let second = statements[1].value;
|
|
336
|
-
chai_1.expect(second).to.be.instanceof(Expression_1.XmlAttributeGetExpression);
|
|
337
|
-
chai_1.expect(second.name.text).to.equal('age');
|
|
338
|
-
chai_1.expect(second.at.text).to.equal('@');
|
|
339
|
-
chai_1.expect(second.obj.name.text).to.equal('firstChild');
|
|
486
|
+
(0, chai_1.expect)(second).to.be.instanceof(Expression_1.XmlAttributeGetExpression);
|
|
487
|
+
(0, chai_1.expect)(second.name.text).to.equal('age');
|
|
488
|
+
(0, chai_1.expect)(second.at.text).to.equal('@');
|
|
489
|
+
(0, chai_1.expect)(second.obj.name.text).to.equal('firstChild');
|
|
340
490
|
});
|
|
341
491
|
it('does not allow chaining of @ symbols', () => {
|
|
342
492
|
let parser = parse(`
|
|
@@ -345,58 +495,58 @@ describe('parser', () => {
|
|
|
345
495
|
name = personXml@name@age@shoeSize
|
|
346
496
|
end sub
|
|
347
497
|
`);
|
|
348
|
-
chai_1.expect(parser.diagnostics).not.to.be.empty;
|
|
498
|
+
(0, chai_1.expect)(parser.diagnostics).not.to.be.empty;
|
|
349
499
|
});
|
|
350
500
|
it('unknown function type does not invalidate rest of function', () => {
|
|
351
501
|
let { statements, diagnostics } = parse(`
|
|
352
502
|
function log() as UNKNOWN_TYPE
|
|
353
503
|
end function
|
|
354
504
|
`, Parser_1.ParseMode.BrightScript);
|
|
355
|
-
chai_1.expect(diagnostics.length).to.be.greaterThan(0);
|
|
356
|
-
chai_1.expect(statements[0]).to.exist;
|
|
505
|
+
(0, chai_1.expect)(diagnostics.length).to.be.greaterThan(0);
|
|
506
|
+
(0, chai_1.expect)(statements[0]).to.exist;
|
|
357
507
|
});
|
|
358
508
|
it('unknown function type is not a problem in Brighterscript mode', () => {
|
|
359
509
|
let { statements, diagnostics } = parse(`
|
|
360
510
|
function log() as UNKNOWN_TYPE
|
|
361
511
|
end function
|
|
362
512
|
`, Parser_1.ParseMode.BrighterScript);
|
|
363
|
-
chai_1.expect(diagnostics.length).to.equal(0);
|
|
364
|
-
chai_1.expect(statements[0]).to.exist;
|
|
513
|
+
(0, chai_1.expect)(diagnostics.length).to.equal(0);
|
|
514
|
+
(0, chai_1.expect)(statements[0]).to.exist;
|
|
365
515
|
});
|
|
366
516
|
it('allows namespaced function type in Brighterscript mode', () => {
|
|
367
517
|
let { statements, diagnostics } = parse(`
|
|
368
518
|
function log() as SOME_NAMESPACE.UNKNOWN_TYPE
|
|
369
519
|
end function
|
|
370
520
|
`, Parser_1.ParseMode.BrighterScript);
|
|
371
|
-
chai_1.expect(diagnostics.length).to.equal(0);
|
|
372
|
-
chai_1.expect(statements[0]).to.exist;
|
|
521
|
+
(0, chai_1.expect)(diagnostics.length).to.equal(0);
|
|
522
|
+
(0, chai_1.expect)(statements[0]).to.exist;
|
|
373
523
|
});
|
|
374
524
|
it('allows custom parameter types in BrighterscriptMode', () => {
|
|
375
525
|
let { statements, diagnostics } = parse(`
|
|
376
526
|
sub foo(value as UNKNOWN_TYPE)
|
|
377
527
|
end sub
|
|
378
528
|
`, Parser_1.ParseMode.BrighterScript);
|
|
379
|
-
chai_1.expect(diagnostics.length).to.equal(0);
|
|
380
|
-
chai_1.expect(statements[0]).to.exist;
|
|
529
|
+
(0, chai_1.expect)(diagnostics.length).to.equal(0);
|
|
530
|
+
(0, chai_1.expect)(statements[0]).to.exist;
|
|
381
531
|
});
|
|
382
532
|
it('does not allow custom parameter types in Brightscript Mode', () => {
|
|
383
533
|
let { diagnostics } = parse(`
|
|
384
534
|
sub foo(value as UNKNOWN_TYPE)
|
|
385
535
|
end sub
|
|
386
536
|
`, Parser_1.ParseMode.BrightScript);
|
|
387
|
-
chai_1.expect(diagnostics.length).not.to.equal(0);
|
|
537
|
+
(0, chai_1.expect)(diagnostics.length).not.to.equal(0);
|
|
388
538
|
});
|
|
389
539
|
it('allows custom namespaced parameter types in BrighterscriptMode', () => {
|
|
390
540
|
let { statements, diagnostics } = parse(`
|
|
391
541
|
sub foo(value as SOME_NAMESPACE.UNKNOWN_TYPE)
|
|
392
542
|
end sub
|
|
393
543
|
`, Parser_1.ParseMode.BrighterScript);
|
|
394
|
-
chai_1.expect(diagnostics.length).to.equal(0);
|
|
395
|
-
chai_1.expect(statements[0]).to.exist;
|
|
544
|
+
(0, chai_1.expect)(diagnostics.length).to.equal(0);
|
|
545
|
+
(0, chai_1.expect)(statements[0]).to.exist;
|
|
396
546
|
});
|
|
397
547
|
it('works with conditionals', () => {
|
|
398
548
|
var _a;
|
|
399
|
-
chai_1.expect((_a = parse(`
|
|
549
|
+
(0, chai_1.expect)((_a = parse(`
|
|
400
550
|
function printNumber()
|
|
401
551
|
if true then
|
|
402
552
|
print 1
|
|
@@ -408,11 +558,11 @@ describe('parser', () => {
|
|
|
408
558
|
});
|
|
409
559
|
it('supports single-line if statements', () => {
|
|
410
560
|
var _a;
|
|
411
|
-
chai_1.expect((_a = parse(`If true Then print "error" : Stop`).diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.not.exist;
|
|
561
|
+
(0, chai_1.expect)((_a = parse(`If true Then print "error" : Stop`).diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.not.exist;
|
|
412
562
|
});
|
|
413
563
|
it('works with excess newlines', () => {
|
|
414
564
|
var _a;
|
|
415
|
-
let { tokens } =
|
|
565
|
+
let { tokens } = Lexer_1.Lexer.scan('function boolToNumber() as string\n\n' +
|
|
416
566
|
' if true then\n\n' +
|
|
417
567
|
' print 1\n\n' +
|
|
418
568
|
' elseif true then\n\n' +
|
|
@@ -421,39 +571,39 @@ describe('parser', () => {
|
|
|
421
571
|
' print 1\n\n' +
|
|
422
572
|
' end if\n\n' +
|
|
423
573
|
'end function\n\n');
|
|
424
|
-
chai_1.expect((_a = Parser_1.Parser.parse(tokens).diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.not.exist;
|
|
574
|
+
(0, chai_1.expect)((_a = Parser_1.Parser.parse(tokens).diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.not.exist;
|
|
425
575
|
});
|
|
426
576
|
it('does not invalidate entire file when line ends with a period', () => {
|
|
427
|
-
let { tokens } =
|
|
577
|
+
let { tokens } = Lexer_1.Lexer.scan(`
|
|
428
578
|
sub main()
|
|
429
579
|
person.a
|
|
430
580
|
end sub
|
|
431
581
|
|
|
432
582
|
`);
|
|
433
583
|
let { diagnostics } = Parser_1.Parser.parse(tokens);
|
|
434
|
-
chai_1.expect(diagnostics).to.be.lengthOf(1, 'Error count should be 0');
|
|
584
|
+
(0, chai_1.expect)(diagnostics).to.be.lengthOf(1, 'Error count should be 0');
|
|
435
585
|
});
|
|
436
586
|
it.skip('allows printing object with trailing period', () => {
|
|
437
|
-
let { tokens } =
|
|
587
|
+
let { tokens } = Lexer_1.Lexer.scan(`print a.`);
|
|
438
588
|
let { statements, diagnostics } = Parser_1.Parser.parse(tokens);
|
|
439
589
|
let printStatement = statements[0];
|
|
440
|
-
chai_1.expect(diagnostics).to.be.empty;
|
|
441
|
-
chai_1.expect(printStatement).to.be.instanceof(Statement_1.PrintStatement);
|
|
442
|
-
chai_1.expect(printStatement.expressions[0]).to.be.instanceof(Expression_1.DottedGetExpression);
|
|
590
|
+
(0, chai_1.expect)(diagnostics).to.be.empty;
|
|
591
|
+
(0, chai_1.expect)(printStatement).to.be.instanceof(Statement_1.PrintStatement);
|
|
592
|
+
(0, chai_1.expect)(printStatement.expressions[0]).to.be.instanceof(Expression_1.DottedGetExpression);
|
|
443
593
|
});
|
|
444
594
|
describe('comments', () => {
|
|
445
595
|
it('combines multi-line comments', () => {
|
|
446
|
-
let { tokens } =
|
|
596
|
+
let { tokens } = Lexer_1.Lexer.scan(`
|
|
447
597
|
'line 1
|
|
448
598
|
'line 2
|
|
449
599
|
'line 3
|
|
450
600
|
`);
|
|
451
601
|
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
452
|
-
chai_1.expect(diagnostics).to.be.lengthOf(0, 'Error count should be 0');
|
|
453
|
-
chai_1.expect(statements[0].text).to.equal(`'line 1\n'line 2\n'line 3`);
|
|
602
|
+
(0, chai_1.expect)(diagnostics).to.be.lengthOf(0, 'Error count should be 0');
|
|
603
|
+
(0, chai_1.expect)(statements[0].text).to.equal(`'line 1\n'line 2\n'line 3`);
|
|
454
604
|
});
|
|
455
605
|
it('does not combile comments separated by newlines', () => {
|
|
456
|
-
let { tokens } =
|
|
606
|
+
let { tokens } = Lexer_1.Lexer.scan(`
|
|
457
607
|
'line 1
|
|
458
608
|
|
|
459
609
|
'line 2
|
|
@@ -461,57 +611,57 @@ describe('parser', () => {
|
|
|
461
611
|
'line 3
|
|
462
612
|
`);
|
|
463
613
|
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
464
|
-
chai_1.expect(diagnostics).to.be.lengthOf(0, 'Error count should be 0');
|
|
465
|
-
chai_1.expect(statements).to.be.lengthOf(3);
|
|
466
|
-
chai_1.expect(statements[0].text).to.equal(`'line 1`);
|
|
467
|
-
chai_1.expect(statements[1].text).to.equal(`'line 2`);
|
|
468
|
-
chai_1.expect(statements[2].text).to.equal(`'line 3`);
|
|
614
|
+
(0, chai_1.expect)(diagnostics).to.be.lengthOf(0, 'Error count should be 0');
|
|
615
|
+
(0, chai_1.expect)(statements).to.be.lengthOf(3);
|
|
616
|
+
(0, chai_1.expect)(statements[0].text).to.equal(`'line 1`);
|
|
617
|
+
(0, chai_1.expect)(statements[1].text).to.equal(`'line 2`);
|
|
618
|
+
(0, chai_1.expect)(statements[2].text).to.equal(`'line 3`);
|
|
469
619
|
});
|
|
470
620
|
it('works after print statement', () => {
|
|
471
|
-
let { tokens } =
|
|
621
|
+
let { tokens } = Lexer_1.Lexer.scan(`
|
|
472
622
|
sub main()
|
|
473
623
|
print "hi" 'comment 1
|
|
474
624
|
end sub
|
|
475
625
|
`);
|
|
476
626
|
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
477
|
-
chai_1.expect(diagnostics).to.be.lengthOf(0, 'Error count should be 0');
|
|
478
|
-
chai_1.expect(statements[0].func.body.statements[1].text).to.equal(`'comment 1`);
|
|
627
|
+
(0, chai_1.expect)(diagnostics).to.be.lengthOf(0, 'Error count should be 0');
|
|
628
|
+
(0, chai_1.expect)(statements[0].func.body.statements[1].text).to.equal(`'comment 1`);
|
|
479
629
|
});
|
|
480
630
|
it('declaration-level', () => {
|
|
481
|
-
let { tokens } =
|
|
631
|
+
let { tokens } = Lexer_1.Lexer.scan(`
|
|
482
632
|
'comment 1
|
|
483
633
|
function a()
|
|
484
634
|
end function
|
|
485
635
|
'comment 2
|
|
486
636
|
`);
|
|
487
637
|
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
488
|
-
chai_1.expect(diagnostics).to.be.lengthOf(0, 'Error count should be 0');
|
|
489
|
-
chai_1.expect(statements[0].text).to.equal(`'comment 1`);
|
|
490
|
-
chai_1.expect(statements[2].text).to.equal(`'comment 2`);
|
|
638
|
+
(0, chai_1.expect)(diagnostics).to.be.lengthOf(0, 'Error count should be 0');
|
|
639
|
+
(0, chai_1.expect)(statements[0].text).to.equal(`'comment 1`);
|
|
640
|
+
(0, chai_1.expect)(statements[2].text).to.equal(`'comment 2`);
|
|
491
641
|
});
|
|
492
642
|
it('works in aa literal as its own statement', () => {
|
|
493
|
-
let { tokens } =
|
|
643
|
+
let { tokens } = Lexer_1.Lexer.scan(`
|
|
494
644
|
obj = {
|
|
495
645
|
"name": true,
|
|
496
646
|
'comment
|
|
497
647
|
}
|
|
498
648
|
`);
|
|
499
649
|
let { diagnostics } = Parser_1.Parser.parse(tokens);
|
|
500
|
-
chai_1.expect(diagnostics).to.be.lengthOf(0, 'Error count should be 0');
|
|
650
|
+
(0, chai_1.expect)(diagnostics).to.be.lengthOf(0, 'Error count should be 0');
|
|
501
651
|
});
|
|
502
652
|
it('parses after function call', () => {
|
|
503
|
-
let { tokens } =
|
|
653
|
+
let { tokens } = Lexer_1.Lexer.scan(`
|
|
504
654
|
sub Main()
|
|
505
655
|
name = "Hello"
|
|
506
656
|
DoSomething(name) 'comment 1
|
|
507
657
|
end sub
|
|
508
658
|
`);
|
|
509
659
|
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
510
|
-
chai_1.expect(diagnostics).to.be.lengthOf(0, 'Should have zero diagnostics');
|
|
511
|
-
chai_1.expect(statements[0].func.body.statements[2].text).to.equal(`'comment 1`);
|
|
660
|
+
(0, chai_1.expect)(diagnostics).to.be.lengthOf(0, 'Should have zero diagnostics');
|
|
661
|
+
(0, chai_1.expect)(statements[0].func.body.statements[2].text).to.equal(`'comment 1`);
|
|
512
662
|
});
|
|
513
663
|
it('function', () => {
|
|
514
|
-
let { tokens } =
|
|
664
|
+
let { tokens } = Lexer_1.Lexer.scan(`
|
|
515
665
|
function a() 'comment 1
|
|
516
666
|
'comment 2
|
|
517
667
|
num = 1
|
|
@@ -519,14 +669,14 @@ describe('parser', () => {
|
|
|
519
669
|
end function 'comment 4
|
|
520
670
|
`);
|
|
521
671
|
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
522
|
-
chai_1.expect(diagnostics).to.be.lengthOf(0, 'Should have zero diagnostics');
|
|
523
|
-
chai_1.expect(statements[0].func.body.statements[0].text).to.equal(`'comment 1`);
|
|
524
|
-
chai_1.expect(statements[0].func.body.statements[1].text).to.equal(`'comment 2`);
|
|
525
|
-
chai_1.expect(statements[0].func.body.statements[3].text).to.equal(`'comment 3`);
|
|
526
|
-
chai_1.expect(statements[1].text).to.equal(`'comment 4`);
|
|
672
|
+
(0, chai_1.expect)(diagnostics).to.be.lengthOf(0, 'Should have zero diagnostics');
|
|
673
|
+
(0, chai_1.expect)(statements[0].func.body.statements[0].text).to.equal(`'comment 1`);
|
|
674
|
+
(0, chai_1.expect)(statements[0].func.body.statements[1].text).to.equal(`'comment 2`);
|
|
675
|
+
(0, chai_1.expect)(statements[0].func.body.statements[3].text).to.equal(`'comment 3`);
|
|
676
|
+
(0, chai_1.expect)(statements[1].text).to.equal(`'comment 4`);
|
|
527
677
|
});
|
|
528
678
|
it('if statement`', () => {
|
|
529
|
-
let { tokens } =
|
|
679
|
+
let { tokens } = Lexer_1.Lexer.scan(`
|
|
530
680
|
function a()
|
|
531
681
|
if true then 'comment 1
|
|
532
682
|
'comment 2
|
|
@@ -544,21 +694,21 @@ describe('parser', () => {
|
|
|
544
694
|
end function
|
|
545
695
|
`);
|
|
546
696
|
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
547
|
-
chai_1.expect(diagnostics).to.be.lengthOf(0, 'Should have zero diagnostics');
|
|
697
|
+
(0, chai_1.expect)(diagnostics).to.be.lengthOf(0, 'Should have zero diagnostics');
|
|
548
698
|
let fnSmt = statements[0];
|
|
549
|
-
if (reflection_1.isFunctionStatement(fnSmt)) {
|
|
699
|
+
if ((0, reflection_1.isFunctionStatement)(fnSmt)) {
|
|
550
700
|
let ifStmt = fnSmt.func.body.statements[0];
|
|
551
|
-
if (reflection_1.isIfStatement(ifStmt)) {
|
|
701
|
+
if ((0, reflection_1.isIfStatement)(ifStmt)) {
|
|
552
702
|
expectCommentWithText(ifStmt.thenBranch.statements[0], `'comment 1`);
|
|
553
703
|
expectCommentWithText(ifStmt.thenBranch.statements[1], `'comment 2`);
|
|
554
704
|
expectCommentWithText(ifStmt.thenBranch.statements[3], `'comment 3`);
|
|
555
705
|
let elseIfBranch = ifStmt.elseBranch;
|
|
556
|
-
if (reflection_1.isIfStatement(elseIfBranch)) {
|
|
706
|
+
if ((0, reflection_1.isIfStatement)(elseIfBranch)) {
|
|
557
707
|
expectCommentWithText(elseIfBranch.thenBranch.statements[0], `'comment 4`);
|
|
558
708
|
expectCommentWithText(elseIfBranch.thenBranch.statements[1], `'comment 5`);
|
|
559
709
|
expectCommentWithText(elseIfBranch.thenBranch.statements[3], `'comment 6`);
|
|
560
710
|
let elseBranch = elseIfBranch.elseBranch;
|
|
561
|
-
if (reflection_1.isBlock(elseBranch)) {
|
|
711
|
+
if ((0, reflection_1.isBlock)(elseBranch)) {
|
|
562
712
|
expectCommentWithText(elseBranch.statements[0], `'comment 7`);
|
|
563
713
|
expectCommentWithText(elseBranch.statements[1], `'comment 8`);
|
|
564
714
|
expectCommentWithText(elseBranch.statements[3], `'comment 9`);
|
|
@@ -581,7 +731,7 @@ describe('parser', () => {
|
|
|
581
731
|
}
|
|
582
732
|
});
|
|
583
733
|
it('while', () => {
|
|
584
|
-
let { tokens } =
|
|
734
|
+
let { tokens } = Lexer_1.Lexer.scan(`
|
|
585
735
|
function a()
|
|
586
736
|
while true 'comment 1
|
|
587
737
|
'comment 2
|
|
@@ -591,15 +741,15 @@ describe('parser', () => {
|
|
|
591
741
|
end function
|
|
592
742
|
`);
|
|
593
743
|
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
594
|
-
chai_1.expect(diagnostics).to.be.lengthOf(0, 'Error count should be zero');
|
|
744
|
+
(0, chai_1.expect)(diagnostics).to.be.lengthOf(0, 'Error count should be zero');
|
|
595
745
|
let stmt = statements[0].func.body.statements[0];
|
|
596
|
-
chai_1.expect(stmt.body.statements[0].text).to.equal(`'comment 1`);
|
|
597
|
-
chai_1.expect(stmt.body.statements[1].text).to.equal(`'comment 2`);
|
|
598
|
-
chai_1.expect(stmt.body.statements[3].text).to.equal(`'comment 3`);
|
|
599
|
-
chai_1.expect(statements[0].func.body.statements[1].text).to.equal(`'comment 4`);
|
|
746
|
+
(0, chai_1.expect)(stmt.body.statements[0].text).to.equal(`'comment 1`);
|
|
747
|
+
(0, chai_1.expect)(stmt.body.statements[1].text).to.equal(`'comment 2`);
|
|
748
|
+
(0, chai_1.expect)(stmt.body.statements[3].text).to.equal(`'comment 3`);
|
|
749
|
+
(0, chai_1.expect)(statements[0].func.body.statements[1].text).to.equal(`'comment 4`);
|
|
600
750
|
});
|
|
601
751
|
it('for', () => {
|
|
602
|
-
let { tokens } =
|
|
752
|
+
let { tokens } = Lexer_1.Lexer.scan(`
|
|
603
753
|
function a()
|
|
604
754
|
for i = 0 to 10 step 1 'comment 1
|
|
605
755
|
'comment 2
|
|
@@ -609,15 +759,15 @@ describe('parser', () => {
|
|
|
609
759
|
end function
|
|
610
760
|
`);
|
|
611
761
|
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
612
|
-
chai_1.expect(diagnostics).to.be.lengthOf(0, 'Error count should be zero');
|
|
762
|
+
(0, chai_1.expect)(diagnostics).to.be.lengthOf(0, 'Error count should be zero');
|
|
613
763
|
let stmt = statements[0].func.body.statements[0];
|
|
614
|
-
chai_1.expect(stmt.body.statements[0].text).to.equal(`'comment 1`);
|
|
615
|
-
chai_1.expect(stmt.body.statements[1].text).to.equal(`'comment 2`);
|
|
616
|
-
chai_1.expect(stmt.body.statements[3].text).to.equal(`'comment 3`);
|
|
617
|
-
chai_1.expect(statements[0].func.body.statements[1].text).to.equal(`'comment 4`);
|
|
764
|
+
(0, chai_1.expect)(stmt.body.statements[0].text).to.equal(`'comment 1`);
|
|
765
|
+
(0, chai_1.expect)(stmt.body.statements[1].text).to.equal(`'comment 2`);
|
|
766
|
+
(0, chai_1.expect)(stmt.body.statements[3].text).to.equal(`'comment 3`);
|
|
767
|
+
(0, chai_1.expect)(statements[0].func.body.statements[1].text).to.equal(`'comment 4`);
|
|
618
768
|
});
|
|
619
769
|
it('for each', () => {
|
|
620
|
-
let { tokens } =
|
|
770
|
+
let { tokens } = Lexer_1.Lexer.scan(`
|
|
621
771
|
function a()
|
|
622
772
|
for each val in [1,2,3] 'comment 1
|
|
623
773
|
'comment 2
|
|
@@ -627,12 +777,12 @@ describe('parser', () => {
|
|
|
627
777
|
end function
|
|
628
778
|
`);
|
|
629
779
|
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
630
|
-
chai_1.expect(diagnostics).to.be.lengthOf(0, 'Error count should be zero');
|
|
780
|
+
(0, chai_1.expect)(diagnostics).to.be.lengthOf(0, 'Error count should be zero');
|
|
631
781
|
let stmt = statements[0].func.body.statements[0];
|
|
632
|
-
chai_1.expect(stmt.body.statements[0].text).to.equal(`'comment 1`);
|
|
633
|
-
chai_1.expect(stmt.body.statements[1].text).to.equal(`'comment 2`);
|
|
634
|
-
chai_1.expect(stmt.body.statements[3].text).to.equal(`'comment 3`);
|
|
635
|
-
chai_1.expect(statements[0].func.body.statements[1].text).to.equal(`'comment 4`);
|
|
782
|
+
(0, chai_1.expect)(stmt.body.statements[0].text).to.equal(`'comment 1`);
|
|
783
|
+
(0, chai_1.expect)(stmt.body.statements[1].text).to.equal(`'comment 2`);
|
|
784
|
+
(0, chai_1.expect)(stmt.body.statements[3].text).to.equal(`'comment 3`);
|
|
785
|
+
(0, chai_1.expect)(statements[0].func.body.statements[1].text).to.equal(`'comment 4`);
|
|
636
786
|
});
|
|
637
787
|
});
|
|
638
788
|
});
|
|
@@ -644,7 +794,7 @@ describe('parser', () => {
|
|
|
644
794
|
then = true
|
|
645
795
|
end sub
|
|
646
796
|
`);
|
|
647
|
-
chai_1.expect(diagnostics).to.be.lengthOf(1);
|
|
797
|
+
(0, chai_1.expect)(diagnostics).to.be.lengthOf(1);
|
|
648
798
|
});
|
|
649
799
|
it('is allowed as an AA property name', () => {
|
|
650
800
|
var _a;
|
|
@@ -657,7 +807,7 @@ describe('parser', () => {
|
|
|
657
807
|
print person.then
|
|
658
808
|
end sub
|
|
659
809
|
`);
|
|
660
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
810
|
+
(0, chai_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
661
811
|
});
|
|
662
812
|
});
|
|
663
813
|
it('"end" is not allowed as a local identifier', () => {
|
|
@@ -666,20 +816,20 @@ describe('parser', () => {
|
|
|
666
816
|
end = true
|
|
667
817
|
end sub
|
|
668
818
|
`);
|
|
669
|
-
chai_1.expect(diagnostics).to.be.length.greaterThan(0);
|
|
819
|
+
(0, chai_1.expect)(diagnostics).to.be.length.greaterThan(0);
|
|
670
820
|
});
|
|
671
821
|
it('none of them can be used as local variables', () => {
|
|
672
|
-
let reservedWords = new Set(
|
|
822
|
+
let reservedWords = new Set(TokenKind_1.ReservedWords);
|
|
673
823
|
//remove the rem keyword because it's a comment...won't cause error
|
|
674
824
|
reservedWords.delete('rem');
|
|
675
825
|
for (let reservedWord of reservedWords) {
|
|
676
|
-
let { tokens } =
|
|
826
|
+
let { tokens } = Lexer_1.Lexer.scan(`
|
|
677
827
|
sub main()
|
|
678
828
|
${reservedWord} = true
|
|
679
829
|
end sub
|
|
680
830
|
`);
|
|
681
831
|
let { diagnostics } = Parser_1.Parser.parse(tokens);
|
|
682
|
-
chai_1.expect(diagnostics, `assigning to reserved word "${reservedWord}" should have been an error`).to.be.length.greaterThan(0);
|
|
832
|
+
(0, chai_1.expect)(diagnostics, `assigning to reserved word "${reservedWord}" should have been an error`).to.be.length.greaterThan(0);
|
|
683
833
|
}
|
|
684
834
|
});
|
|
685
835
|
});
|
|
@@ -689,24 +839,24 @@ describe('parser', () => {
|
|
|
689
839
|
let { statements, diagnostics } = parse(`
|
|
690
840
|
import "somePath"
|
|
691
841
|
`, Parser_1.ParseMode.BrighterScript);
|
|
692
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
693
|
-
chai_1.expect(statements[0]).to.be.instanceof(Statement_1.ImportStatement);
|
|
842
|
+
(0, chai_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
843
|
+
(0, chai_1.expect)(statements[0]).to.be.instanceof(Statement_1.ImportStatement);
|
|
694
844
|
});
|
|
695
845
|
it('catches import statements used in brightscript files', () => {
|
|
696
846
|
var _a;
|
|
697
847
|
let { statements, diagnostics } = parse(`
|
|
698
848
|
import "somePath"
|
|
699
849
|
`, Parser_1.ParseMode.BrightScript);
|
|
700
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.eql(DiagnosticMessages_1.DiagnosticMessages.bsFeatureNotSupportedInBrsFiles('import statements').message);
|
|
701
|
-
chai_1.expect(statements[0]).to.be.instanceof(Statement_1.ImportStatement);
|
|
850
|
+
(0, chai_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.eql(DiagnosticMessages_1.DiagnosticMessages.bsFeatureNotSupportedInBrsFiles('import statements').message);
|
|
851
|
+
(0, chai_1.expect)(statements[0]).to.be.instanceof(Statement_1.ImportStatement);
|
|
702
852
|
});
|
|
703
|
-
it('
|
|
853
|
+
it('catches missing file path', () => {
|
|
704
854
|
var _a;
|
|
705
855
|
let { statements, diagnostics } = parse(`
|
|
706
856
|
import
|
|
707
857
|
`, Parser_1.ParseMode.BrighterScript);
|
|
708
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.expectedStringLiteralAfterKeyword('import').message);
|
|
709
|
-
chai_1.expect(statements[0]).to.be.instanceof(Statement_1.ImportStatement);
|
|
858
|
+
(0, chai_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.expectedStringLiteralAfterKeyword('import').message);
|
|
859
|
+
(0, chai_1.expect)(statements[0]).to.be.instanceof(Statement_1.ImportStatement);
|
|
710
860
|
});
|
|
711
861
|
});
|
|
712
862
|
describe('Annotations', () => {
|
|
@@ -717,7 +867,7 @@ describe('parser', () => {
|
|
|
717
867
|
sub main()
|
|
718
868
|
end sub
|
|
719
869
|
`, Parser_1.ParseMode.BrighterScript);
|
|
720
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.
|
|
870
|
+
(0, chai_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.unexpectedToken('@').message);
|
|
721
871
|
});
|
|
722
872
|
it('properly handles empty annotation above class method', () => {
|
|
723
873
|
var _a;
|
|
@@ -729,7 +879,7 @@ describe('parser', () => {
|
|
|
729
879
|
end sub
|
|
730
880
|
end class
|
|
731
881
|
`, Parser_1.ParseMode.BrighterScript);
|
|
732
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.expectedIdentifier().message);
|
|
882
|
+
(0, chai_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.expectedIdentifier().message);
|
|
733
883
|
});
|
|
734
884
|
it('parses with error if annotation is not followed by a statement', () => {
|
|
735
885
|
var _a, _b, _c, _d;
|
|
@@ -743,11 +893,11 @@ describe('parser', () => {
|
|
|
743
893
|
end class
|
|
744
894
|
@meta1
|
|
745
895
|
`, Parser_1.ParseMode.BrighterScript);
|
|
746
|
-
chai_1.expect(diagnostics.length).to.equal(4);
|
|
747
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.unusedAnnotation().message);
|
|
748
|
-
chai_1.expect((_b = diagnostics[1]) === null || _b === void 0 ? void 0 : _b.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.unusedAnnotation().message);
|
|
749
|
-
chai_1.expect((_c = diagnostics[2]) === null || _c === void 0 ? void 0 : _c.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.unusedAnnotation().message);
|
|
750
|
-
chai_1.expect((_d = diagnostics[3]) === null || _d === void 0 ? void 0 : _d.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.unusedAnnotation().message);
|
|
896
|
+
(0, chai_1.expect)(diagnostics.length).to.equal(4);
|
|
897
|
+
(0, chai_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.unusedAnnotation().message);
|
|
898
|
+
(0, chai_1.expect)((_b = diagnostics[1]) === null || _b === void 0 ? void 0 : _b.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.unusedAnnotation().message);
|
|
899
|
+
(0, chai_1.expect)((_c = diagnostics[2]) === null || _c === void 0 ? void 0 : _c.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.unusedAnnotation().message);
|
|
900
|
+
(0, chai_1.expect)((_d = diagnostics[3]) === null || _d === void 0 ? void 0 : _d.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.unusedAnnotation().message);
|
|
751
901
|
});
|
|
752
902
|
it('attaches an annotation to next statement', () => {
|
|
753
903
|
var _a;
|
|
@@ -759,18 +909,18 @@ describe('parser', () => {
|
|
|
759
909
|
@meta2 sub init()
|
|
760
910
|
end sub
|
|
761
911
|
`, Parser_1.ParseMode.BrighterScript);
|
|
762
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
763
|
-
chai_1.expect(statements[0]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
912
|
+
(0, chai_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
913
|
+
(0, chai_1.expect)(statements[0]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
764
914
|
let fn = statements[0];
|
|
765
|
-
chai_1.expect(fn.annotations).to.exist;
|
|
766
|
-
chai_1.expect(fn.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
767
|
-
chai_1.expect(fn.annotations[0].nameToken.text).to.equal('meta1');
|
|
768
|
-
chai_1.expect(fn.annotations[0].name).to.equal('meta1');
|
|
769
|
-
chai_1.expect(statements[1]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
915
|
+
(0, chai_1.expect)(fn.annotations).to.exist;
|
|
916
|
+
(0, chai_1.expect)(fn.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
917
|
+
(0, chai_1.expect)(fn.annotations[0].nameToken.text).to.equal('meta1');
|
|
918
|
+
(0, chai_1.expect)(fn.annotations[0].name).to.equal('meta1');
|
|
919
|
+
(0, chai_1.expect)(statements[1]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
770
920
|
fn = statements[1];
|
|
771
|
-
chai_1.expect(fn.annotations).to.exist;
|
|
772
|
-
chai_1.expect(fn.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
773
|
-
chai_1.expect(fn.annotations[0].nameToken.text).to.equal('meta2');
|
|
921
|
+
(0, chai_1.expect)(fn.annotations).to.exist;
|
|
922
|
+
(0, chai_1.expect)(fn.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
923
|
+
(0, chai_1.expect)(fn.annotations[0].nameToken.text).to.equal('meta2');
|
|
774
924
|
});
|
|
775
925
|
it('attaches annotations inside a function body', () => {
|
|
776
926
|
var _a, _b;
|
|
@@ -780,13 +930,13 @@ describe('parser', () => {
|
|
|
780
930
|
print "hello"
|
|
781
931
|
end function
|
|
782
932
|
`, Parser_1.ParseMode.BrighterScript);
|
|
783
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
933
|
+
(0, chai_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
784
934
|
let fn = statements[0];
|
|
785
935
|
let fnStatements = fn.func.body.statements;
|
|
786
936
|
let stat = fnStatements[0];
|
|
787
|
-
chai_1.expect(stat).to.exist;
|
|
788
|
-
chai_1.expect((_b = stat.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
789
|
-
chai_1.expect(stat.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
937
|
+
(0, chai_1.expect)(stat).to.exist;
|
|
938
|
+
(0, chai_1.expect)((_b = stat.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
939
|
+
(0, chai_1.expect)(stat.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
790
940
|
});
|
|
791
941
|
it('attaches multiple annotations to next statement', () => {
|
|
792
942
|
var _a;
|
|
@@ -796,14 +946,14 @@ describe('parser', () => {
|
|
|
796
946
|
function main()
|
|
797
947
|
end function
|
|
798
948
|
`, Parser_1.ParseMode.BrighterScript);
|
|
799
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
800
|
-
chai_1.expect(statements[0]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
949
|
+
(0, chai_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
950
|
+
(0, chai_1.expect)(statements[0]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
801
951
|
let fn = statements[0];
|
|
802
|
-
chai_1.expect(fn.annotations).to.exist;
|
|
803
|
-
chai_1.expect(fn.annotations.length).to.equal(3);
|
|
804
|
-
chai_1.expect(fn.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
805
|
-
chai_1.expect(fn.annotations[1]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
806
|
-
chai_1.expect(fn.annotations[2]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
952
|
+
(0, chai_1.expect)(fn.annotations).to.exist;
|
|
953
|
+
(0, chai_1.expect)(fn.annotations.length).to.equal(3);
|
|
954
|
+
(0, chai_1.expect)(fn.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
955
|
+
(0, chai_1.expect)(fn.annotations[1]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
956
|
+
(0, chai_1.expect)(fn.annotations[2]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
807
957
|
});
|
|
808
958
|
it('allows annotations with parameters', () => {
|
|
809
959
|
var _a;
|
|
@@ -812,12 +962,12 @@ describe('parser', () => {
|
|
|
812
962
|
function main()
|
|
813
963
|
end function
|
|
814
964
|
`, Parser_1.ParseMode.BrighterScript);
|
|
815
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
965
|
+
(0, chai_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
816
966
|
let fn = statements[0];
|
|
817
|
-
chai_1.expect(fn.annotations).to.exist;
|
|
818
|
-
chai_1.expect(fn.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
819
|
-
chai_1.expect(fn.annotations[0].nameToken.text).to.equal('meta1');
|
|
820
|
-
chai_1.expect(fn.annotations[0].call).to.be.instanceof(Expression_1.CallExpression);
|
|
967
|
+
(0, chai_1.expect)(fn.annotations).to.exist;
|
|
968
|
+
(0, chai_1.expect)(fn.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
969
|
+
(0, chai_1.expect)(fn.annotations[0].nameToken.text).to.equal('meta1');
|
|
970
|
+
(0, chai_1.expect)(fn.annotations[0].call).to.be.instanceof(Expression_1.CallExpression);
|
|
821
971
|
});
|
|
822
972
|
it('attaches annotations to a class', () => {
|
|
823
973
|
var _a, _b;
|
|
@@ -829,10 +979,10 @@ describe('parser', () => {
|
|
|
829
979
|
end function
|
|
830
980
|
end class
|
|
831
981
|
`, Parser_1.ParseMode.BrighterScript);
|
|
832
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
982
|
+
(0, chai_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
833
983
|
let cs = statements[0];
|
|
834
|
-
chai_1.expect((_b = cs.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
835
|
-
chai_1.expect(cs.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
984
|
+
(0, chai_1.expect)((_b = cs.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
985
|
+
(0, chai_1.expect)(cs.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
836
986
|
});
|
|
837
987
|
it('attaches annotations to multiple clases', () => {
|
|
838
988
|
var _a, _b, _c;
|
|
@@ -850,15 +1000,15 @@ describe('parser', () => {
|
|
|
850
1000
|
end function
|
|
851
1001
|
end class
|
|
852
1002
|
`, Parser_1.ParseMode.BrighterScript);
|
|
853
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
1003
|
+
(0, chai_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
854
1004
|
let cs = statements[0];
|
|
855
|
-
chai_1.expect((_b = cs.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
856
|
-
chai_1.expect(cs.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
857
|
-
chai_1.expect(cs.annotations[0].name).to.equal('meta1');
|
|
1005
|
+
(0, chai_1.expect)((_b = cs.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
1006
|
+
(0, chai_1.expect)(cs.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
1007
|
+
(0, chai_1.expect)(cs.annotations[0].name).to.equal('meta1');
|
|
858
1008
|
let cs2 = statements[1];
|
|
859
|
-
chai_1.expect((_c = cs2.annotations) === null || _c === void 0 ? void 0 : _c.length).to.equal(1);
|
|
860
|
-
chai_1.expect(cs2.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
861
|
-
chai_1.expect(cs2.annotations[0].name).to.equal('meta2');
|
|
1009
|
+
(0, chai_1.expect)((_c = cs2.annotations) === null || _c === void 0 ? void 0 : _c.length).to.equal(1);
|
|
1010
|
+
(0, chai_1.expect)(cs2.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
1011
|
+
(0, chai_1.expect)(cs2.annotations[0].name).to.equal('meta2');
|
|
862
1012
|
});
|
|
863
1013
|
it('attaches annotations to a namespaced class', () => {
|
|
864
1014
|
var _a, _b;
|
|
@@ -872,11 +1022,11 @@ describe('parser', () => {
|
|
|
872
1022
|
end class
|
|
873
1023
|
end namespace
|
|
874
1024
|
`, Parser_1.ParseMode.BrighterScript);
|
|
875
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
1025
|
+
(0, chai_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
876
1026
|
let ns = statements[0];
|
|
877
1027
|
let cs = ns.body.statements[0];
|
|
878
|
-
chai_1.expect((_b = cs.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
879
|
-
chai_1.expect(cs.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
1028
|
+
(0, chai_1.expect)((_b = cs.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
1029
|
+
(0, chai_1.expect)(cs.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
880
1030
|
});
|
|
881
1031
|
it('attaches annotations to a namespaced class - multiple', () => {
|
|
882
1032
|
var _a, _b, _c;
|
|
@@ -896,16 +1046,16 @@ describe('parser', () => {
|
|
|
896
1046
|
end class
|
|
897
1047
|
end namespace
|
|
898
1048
|
`, Parser_1.ParseMode.BrighterScript);
|
|
899
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
1049
|
+
(0, chai_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
900
1050
|
let ns = statements[0];
|
|
901
1051
|
let cs = ns.body.statements[0];
|
|
902
|
-
chai_1.expect((_b = cs.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
903
|
-
chai_1.expect(cs.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
904
|
-
chai_1.expect(cs.annotations[0].name).to.equal('meta1');
|
|
1052
|
+
(0, chai_1.expect)((_b = cs.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
1053
|
+
(0, chai_1.expect)(cs.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
1054
|
+
(0, chai_1.expect)(cs.annotations[0].name).to.equal('meta1');
|
|
905
1055
|
let cs2 = ns.body.statements[1];
|
|
906
|
-
chai_1.expect((_c = cs2.annotations) === null || _c === void 0 ? void 0 : _c.length).to.equal(1);
|
|
907
|
-
chai_1.expect(cs2.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
908
|
-
chai_1.expect(cs2.annotations[0].name).to.equal('meta2');
|
|
1056
|
+
(0, chai_1.expect)((_c = cs2.annotations) === null || _c === void 0 ? void 0 : _c.length).to.equal(1);
|
|
1057
|
+
(0, chai_1.expect)(cs2.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
1058
|
+
(0, chai_1.expect)(cs2.annotations[0].name).to.equal('meta2');
|
|
909
1059
|
});
|
|
910
1060
|
it('attaches annotations to a class constructor', () => {
|
|
911
1061
|
var _a, _b;
|
|
@@ -920,11 +1070,11 @@ describe('parser', () => {
|
|
|
920
1070
|
end function
|
|
921
1071
|
end class
|
|
922
1072
|
`, Parser_1.ParseMode.BrighterScript);
|
|
923
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
1073
|
+
(0, chai_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
924
1074
|
let cs = statements[0];
|
|
925
1075
|
let stat = cs.body[0];
|
|
926
|
-
chai_1.expect((_b = stat.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
927
|
-
chai_1.expect(stat.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
1076
|
+
(0, chai_1.expect)((_b = stat.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
1077
|
+
(0, chai_1.expect)(stat.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
928
1078
|
});
|
|
929
1079
|
it('attaches annotations to a class methods', () => {
|
|
930
1080
|
var _a, _b;
|
|
@@ -939,11 +1089,11 @@ describe('parser', () => {
|
|
|
939
1089
|
end function
|
|
940
1090
|
end class
|
|
941
1091
|
`, Parser_1.ParseMode.BrighterScript);
|
|
942
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
1092
|
+
(0, chai_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
943
1093
|
let cs = statements[0];
|
|
944
1094
|
let stat = cs.body[1];
|
|
945
|
-
chai_1.expect((_b = stat.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
946
|
-
chai_1.expect(stat.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
1095
|
+
(0, chai_1.expect)((_b = stat.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
1096
|
+
(0, chai_1.expect)(stat.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
947
1097
|
});
|
|
948
1098
|
it('attaches annotations to a class methods, fields and constructor', () => {
|
|
949
1099
|
var _a, _b, _c, _d, _e;
|
|
@@ -967,19 +1117,19 @@ describe('parser', () => {
|
|
|
967
1117
|
public foo="bar"
|
|
968
1118
|
end class
|
|
969
1119
|
`, Parser_1.ParseMode.BrighterScript);
|
|
970
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
1120
|
+
(0, chai_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
971
1121
|
let cs = statements[0];
|
|
972
|
-
chai_1.expect((_b = cs.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(2);
|
|
973
|
-
chai_1.expect(cs.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
1122
|
+
(0, chai_1.expect)((_b = cs.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(2);
|
|
1123
|
+
(0, chai_1.expect)(cs.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
974
1124
|
let stat1 = cs.body[0];
|
|
975
1125
|
let stat2 = cs.body[1];
|
|
976
1126
|
let f1 = cs.body[2];
|
|
977
|
-
chai_1.expect((_c = stat1.annotations) === null || _c === void 0 ? void 0 : _c.length).to.equal(2);
|
|
978
|
-
chai_1.expect(stat1.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
979
|
-
chai_1.expect((_d = stat2.annotations) === null || _d === void 0 ? void 0 : _d.length).to.equal(2);
|
|
980
|
-
chai_1.expect(stat2.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
981
|
-
chai_1.expect((_e = f1.annotations) === null || _e === void 0 ? void 0 : _e.length).to.equal(2);
|
|
982
|
-
chai_1.expect(f1.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
1127
|
+
(0, chai_1.expect)((_c = stat1.annotations) === null || _c === void 0 ? void 0 : _c.length).to.equal(2);
|
|
1128
|
+
(0, chai_1.expect)(stat1.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
1129
|
+
(0, chai_1.expect)((_d = stat2.annotations) === null || _d === void 0 ? void 0 : _d.length).to.equal(2);
|
|
1130
|
+
(0, chai_1.expect)(stat2.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
1131
|
+
(0, chai_1.expect)((_e = f1.annotations) === null || _e === void 0 ? void 0 : _e.length).to.equal(2);
|
|
1132
|
+
(0, chai_1.expect)(f1.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
983
1133
|
});
|
|
984
1134
|
it('ignores annotations on commented out lines', () => {
|
|
985
1135
|
var _a;
|
|
@@ -990,9 +1140,9 @@ describe('parser', () => {
|
|
|
990
1140
|
print "hello"
|
|
991
1141
|
end function
|
|
992
1142
|
`, Parser_1.ParseMode.BrighterScript);
|
|
993
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
1143
|
+
(0, chai_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
994
1144
|
let cs = statements[0];
|
|
995
|
-
chai_1.expect(cs.annotations).to.be.undefined;
|
|
1145
|
+
(0, chai_1.expect)(cs.annotations).to.be.undefined;
|
|
996
1146
|
});
|
|
997
1147
|
it('can convert argument of an annotation to JS types', () => {
|
|
998
1148
|
var _a;
|
|
@@ -1010,22 +1160,22 @@ describe('parser', () => {
|
|
|
1010
1160
|
sub init()
|
|
1011
1161
|
end sub
|
|
1012
1162
|
`, Parser_1.ParseMode.BrighterScript);
|
|
1013
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
1014
|
-
chai_1.expect(statements[0]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
1163
|
+
(0, chai_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
1164
|
+
(0, chai_1.expect)(statements[0]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
1015
1165
|
let fn = statements[0];
|
|
1016
|
-
chai_1.expect(fn.annotations).to.exist;
|
|
1017
|
-
chai_1.expect(fn.annotations[0].getArguments()).to.deep.equal([]);
|
|
1018
|
-
chai_1.expect(statements[1]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
1166
|
+
(0, chai_1.expect)(fn.annotations).to.exist;
|
|
1167
|
+
(0, chai_1.expect)(fn.annotations[0].getArguments()).to.deep.equal([]);
|
|
1168
|
+
(0, chai_1.expect)(statements[1]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
1019
1169
|
fn = statements[1];
|
|
1020
|
-
chai_1.expect(fn.annotations).to.exist;
|
|
1021
|
-
chai_1.expect(fn.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
1022
|
-
chai_1.expect(fn.annotations[0].getArguments()).to.deep.equal([
|
|
1170
|
+
(0, chai_1.expect)(fn.annotations).to.exist;
|
|
1171
|
+
(0, chai_1.expect)(fn.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
1172
|
+
(0, chai_1.expect)(fn.annotations[0].getArguments()).to.deep.equal([
|
|
1023
1173
|
'arg', 2, true,
|
|
1024
1174
|
{ prop: 'value' }, [1, 2],
|
|
1025
1175
|
null
|
|
1026
1176
|
]);
|
|
1027
1177
|
let allArgs = fn.annotations[0].getArguments(false);
|
|
1028
|
-
chai_1.expect(allArgs.pop()).to.be.instanceOf(Expression_1.FunctionExpression);
|
|
1178
|
+
(0, chai_1.expect)(allArgs.pop()).to.be.instanceOf(Expression_1.FunctionExpression);
|
|
1029
1179
|
});
|
|
1030
1180
|
it('can handle negative numbers', () => {
|
|
1031
1181
|
var _a;
|
|
@@ -1037,11 +1187,11 @@ describe('parser', () => {
|
|
|
1037
1187
|
sub init()
|
|
1038
1188
|
end sub
|
|
1039
1189
|
`, Parser_1.ParseMode.BrighterScript);
|
|
1040
|
-
chai_1.expect((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
1041
|
-
chai_1.expect(statements[0]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
1190
|
+
(0, chai_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
1191
|
+
(0, chai_1.expect)(statements[0]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
1042
1192
|
let fn = statements[0];
|
|
1043
|
-
chai_1.expect(fn.annotations).to.exist;
|
|
1044
|
-
chai_1.expect(fn.annotations[0].getArguments()).to.deep.equal([-100]);
|
|
1193
|
+
(0, chai_1.expect)(fn.annotations).to.exist;
|
|
1194
|
+
(0, chai_1.expect)(fn.annotations[0].getArguments()).to.deep.equal([-100]);
|
|
1045
1195
|
});
|
|
1046
1196
|
});
|
|
1047
1197
|
describe('getBscTypeFromExpression', () => {
|
|
@@ -1054,8 +1204,8 @@ describe('parser', () => {
|
|
|
1054
1204
|
end sub
|
|
1055
1205
|
`);
|
|
1056
1206
|
const func = parser.ast.statements[0].func;
|
|
1057
|
-
const type = Parser_1.getBscTypeFromExpression(func.body.statements[0].value, func);
|
|
1058
|
-
chai_1.expect(type.returnType).to.be.instanceof(VoidType_1.VoidType);
|
|
1207
|
+
const type = (0, Parser_1.getBscTypeFromExpression)(func.body.statements[0].value, func);
|
|
1208
|
+
(0, chai_1.expect)(type.returnType).to.be.instanceof(VoidType_1.VoidType);
|
|
1059
1209
|
});
|
|
1060
1210
|
it('computes return type for sub with explicit return type', () => {
|
|
1061
1211
|
const parser = parse(`
|
|
@@ -1066,8 +1216,8 @@ describe('parser', () => {
|
|
|
1066
1216
|
end sub
|
|
1067
1217
|
`);
|
|
1068
1218
|
const func = parser.ast.statements[0].func;
|
|
1069
|
-
const type = Parser_1.getBscTypeFromExpression(func.body.statements[0].value, func);
|
|
1070
|
-
chai_1.expect(type.returnType).to.be.instanceof(StringType_1.StringType);
|
|
1219
|
+
const type = (0, Parser_1.getBscTypeFromExpression)(func.body.statements[0].value, func);
|
|
1220
|
+
(0, chai_1.expect)(type.returnType).to.be.instanceof(StringType_1.StringType);
|
|
1071
1221
|
});
|
|
1072
1222
|
it('supports sub with custom return type', () => {
|
|
1073
1223
|
const parser = parse(`
|
|
@@ -1080,10 +1230,25 @@ describe('parser', () => {
|
|
|
1080
1230
|
class Person
|
|
1081
1231
|
end class
|
|
1082
1232
|
`, Parser_1.ParseMode.BrighterScript);
|
|
1083
|
-
testHelpers_spec_1.expectZeroDiagnostics(parser.diagnostics);
|
|
1233
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser.diagnostics);
|
|
1084
1234
|
const func = parser.ast.statements[0].func;
|
|
1085
|
-
const type = Parser_1.getBscTypeFromExpression(func.body.statements[0].value, func);
|
|
1086
|
-
|
|
1235
|
+
const type = (0, Parser_1.getBscTypeFromExpression)(func.body.statements[0].value, func);
|
|
1236
|
+
// Return type is LazyType, because "Person" is not fully known yet
|
|
1237
|
+
(0, chai_1.expect)(type.returnType).to.be.instanceof(LazyType_1.LazyType);
|
|
1238
|
+
});
|
|
1239
|
+
it('supports function with array return type', () => {
|
|
1240
|
+
const parser = parse(`
|
|
1241
|
+
sub main()
|
|
1242
|
+
getNums = sub() as integer[]
|
|
1243
|
+
return [1,2,3]
|
|
1244
|
+
end sub
|
|
1245
|
+
end sub
|
|
1246
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1247
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser.diagnostics);
|
|
1248
|
+
const func = parser.ast.statements[0].func;
|
|
1249
|
+
const type = (0, Parser_1.getBscTypeFromExpression)(func.body.statements[0].value, func);
|
|
1250
|
+
(0, chai_1.expect)(type.returnType).to.be.instanceof(ArrayType_1.ArrayType);
|
|
1251
|
+
(0, chai_1.expect)(type.returnType.getDefaultType()).to.be.instanceof(IntegerType_1.IntegerType);
|
|
1087
1252
|
});
|
|
1088
1253
|
});
|
|
1089
1254
|
describe('symbolTable', () => {
|
|
@@ -1099,39 +1264,39 @@ describe('parser', () => {
|
|
|
1099
1264
|
class CustomKlass
|
|
1100
1265
|
end class
|
|
1101
1266
|
`, Parser_1.ParseMode.BrighterScript);
|
|
1102
|
-
testHelpers_spec_1.expectZeroDiagnostics(parser.diagnostics);
|
|
1267
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser.diagnostics);
|
|
1103
1268
|
const mainSymbolTable = parser.references.functionExpressions[0].symbolTable;
|
|
1104
|
-
chai_1.expect(mainSymbolTable.getSymbolType('someNum')).to.be.instanceof(IntegerType_1.IntegerType);
|
|
1105
|
-
chai_1.expect(mainSymbolTable.getSymbolType('someString')).to.be.instanceof(StringType_1.StringType);
|
|
1106
|
-
chai_1.expect(mainSymbolTable.getSymbolType('someObj')).to.be.instanceof(ObjectType_1.ObjectType);
|
|
1107
|
-
chai_1.expect(mainSymbolTable.getSymbolType('someCustom')).to.be.instanceof(CustomType_1.CustomType);
|
|
1269
|
+
(0, chai_1.expect)(mainSymbolTable.getSymbolType('someNum')).to.be.instanceof(IntegerType_1.IntegerType);
|
|
1270
|
+
(0, chai_1.expect)(mainSymbolTable.getSymbolType('someString')).to.be.instanceof(StringType_1.StringType);
|
|
1271
|
+
(0, chai_1.expect)(mainSymbolTable.getSymbolType('someObj')).to.be.instanceof(ObjectType_1.ObjectType);
|
|
1272
|
+
(0, chai_1.expect)(mainSymbolTable.getSymbolType('someCustom')).to.be.instanceof(CustomType_1.CustomType);
|
|
1108
1273
|
});
|
|
1109
1274
|
it('stores typed parameters in functions', () => {
|
|
1110
1275
|
const parser = parse(`
|
|
1111
1276
|
sub someFunc(param1 as string, param2 as integer)
|
|
1112
|
-
|
|
1277
|
+
temp = param2
|
|
1113
1278
|
end sub
|
|
1114
1279
|
`, Parser_1.ParseMode.BrighterScript);
|
|
1115
|
-
testHelpers_spec_1.expectZeroDiagnostics(parser.diagnostics);
|
|
1280
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser.diagnostics);
|
|
1116
1281
|
const someFuncSymbolTable = parser.references.functionExpressions[0].symbolTable;
|
|
1117
|
-
chai_1.expect(someFuncSymbolTable.getSymbolType('param1')).to.be.instanceof(StringType_1.StringType);
|
|
1118
|
-
chai_1.expect(someFuncSymbolTable.getSymbolType('param2')).to.be.instanceof(IntegerType_1.IntegerType);
|
|
1119
|
-
chai_1.expect(someFuncSymbolTable.getSymbolType('temp')).to.be.instanceof(IntegerType_1.IntegerType);
|
|
1282
|
+
(0, chai_1.expect)(someFuncSymbolTable.getSymbolType('param1')).to.be.instanceof(StringType_1.StringType);
|
|
1283
|
+
(0, chai_1.expect)(someFuncSymbolTable.getSymbolType('param2')).to.be.instanceof(IntegerType_1.IntegerType);
|
|
1284
|
+
(0, chai_1.expect)(someFuncSymbolTable.getSymbolType('temp')).to.be.instanceof(IntegerType_1.IntegerType);
|
|
1120
1285
|
});
|
|
1121
1286
|
it('properly defers typing lazy types', () => {
|
|
1122
1287
|
const parser = parse(`
|
|
1123
1288
|
sub someFunc()
|
|
1124
|
-
|
|
1289
|
+
temp = foo()
|
|
1125
1290
|
end sub
|
|
1126
1291
|
|
|
1127
1292
|
function foo() as string
|
|
1128
|
-
|
|
1293
|
+
return "foo"
|
|
1129
1294
|
end function
|
|
1130
1295
|
`, Parser_1.ParseMode.BrighterScript);
|
|
1131
|
-
testHelpers_spec_1.expectZeroDiagnostics(parser.diagnostics);
|
|
1296
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser.diagnostics);
|
|
1132
1297
|
const someFuncSymbolTable = parser.references.functionExpressions[0].symbolTable;
|
|
1133
|
-
chai_1.expect(someFuncSymbolTable.
|
|
1134
|
-
chai_1.expect(someFuncSymbolTable.getSymbolType('temp').toTypeString()).to.eq('string');
|
|
1298
|
+
(0, chai_1.expect)((0, reflection_1.isLazyType)(someFuncSymbolTable.getSymbol('temp')[0].type)).to.be.true;
|
|
1299
|
+
(0, chai_1.expect)(someFuncSymbolTable.getSymbolType('temp').toTypeString()).to.eq('string');
|
|
1135
1300
|
});
|
|
1136
1301
|
it('does not know about symbols declared in parent functions', () => {
|
|
1137
1302
|
const parser = parse(`
|
|
@@ -1142,22 +1307,62 @@ describe('parser', () => {
|
|
|
1142
1307
|
end sub
|
|
1143
1308
|
end sub
|
|
1144
1309
|
`, Parser_1.ParseMode.BrighterScript);
|
|
1145
|
-
testHelpers_spec_1.expectZeroDiagnostics(parser.diagnostics);
|
|
1310
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser.diagnostics);
|
|
1146
1311
|
const addOneSymbolTable = parser.references.functionExpressions[0].childFunctionExpressions[0].symbolTable;
|
|
1147
|
-
chai_1.expect(addOneSymbolTable.getSymbolType('oldVal')
|
|
1312
|
+
(0, chai_1.expect)((0, reflection_1.isUninitializedType)(addOneSymbolTable.getSymbolType('oldVal'))).to.be.true;
|
|
1148
1313
|
});
|
|
1149
1314
|
it('finds params', () => {
|
|
1150
1315
|
const parser = parse(`
|
|
1151
1316
|
sub alert(p1, p2 as string, p3 = 1)
|
|
1152
1317
|
end sub
|
|
1153
1318
|
`, Parser_1.ParseMode.BrighterScript);
|
|
1154
|
-
testHelpers_spec_1.expectZeroDiagnostics(parser.diagnostics);
|
|
1155
|
-
testHelpers_spec_1.expectSymbolTableEquals(parser.references.functionExpressions[0].symbolTable, [
|
|
1156
|
-
['p1', new DynamicType_1.DynamicType(), util_1.
|
|
1157
|
-
['p2', new StringType_1.StringType(), util_1.
|
|
1158
|
-
['p3', new IntegerType_1.IntegerType(), util_1.
|
|
1319
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser.diagnostics);
|
|
1320
|
+
(0, testHelpers_spec_1.expectSymbolTableEquals)(parser.references.functionExpressions[0].symbolTable, [
|
|
1321
|
+
['p1', new DynamicType_1.DynamicType(), util_1.util.createRange(1, 26, 1, 28)],
|
|
1322
|
+
['p2', new StringType_1.StringType(), util_1.util.createRange(1, 30, 1, 32)],
|
|
1323
|
+
['p3', new IntegerType_1.IntegerType(), util_1.util.createRange(1, 44, 1, 46)]
|
|
1159
1324
|
]);
|
|
1160
1325
|
});
|
|
1326
|
+
it('finds arrays of primitives', () => {
|
|
1327
|
+
const parser = parse(`
|
|
1328
|
+
function alert(numbers as integer[], words as string[]) as float[]
|
|
1329
|
+
end function
|
|
1330
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1331
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser.diagnostics);
|
|
1332
|
+
const symbolTable = parser.references.functionExpressions[0].symbolTable;
|
|
1333
|
+
const numArraySymbolType = symbolTable.getSymbolType('numbers');
|
|
1334
|
+
const wordArraySymbolType = symbolTable.getSymbolType('words');
|
|
1335
|
+
(0, chai_1.expect)((0, reflection_1.isArrayType)(numArraySymbolType)).to.be.true;
|
|
1336
|
+
(0, chai_1.expect)((0, reflection_1.isIntegerType)(numArraySymbolType.getDefaultType())).to.be.true;
|
|
1337
|
+
(0, chai_1.expect)((0, reflection_1.isArrayType)(wordArraySymbolType)).to.be.true;
|
|
1338
|
+
(0, chai_1.expect)((0, reflection_1.isStringType)(wordArraySymbolType.getDefaultType())).to.be.true;
|
|
1339
|
+
const funcReturnType = parser.references.functionExpressions[0].getReturnType();
|
|
1340
|
+
(0, chai_1.expect)((0, reflection_1.isArrayType)(funcReturnType)).to.be.true;
|
|
1341
|
+
(0, chai_1.expect)((0, reflection_1.isFloatType)(funcReturnType.getDefaultType())).to.be.true;
|
|
1342
|
+
});
|
|
1343
|
+
it('finds multidimensional arrays', () => {
|
|
1344
|
+
const parser = parse(`
|
|
1345
|
+
sub alert(data as integer[][])
|
|
1346
|
+
end sub
|
|
1347
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1348
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser.diagnostics);
|
|
1349
|
+
const symbolTable = parser.references.functionExpressions[0].symbolTable;
|
|
1350
|
+
const dataType = symbolTable.getSymbolType('data');
|
|
1351
|
+
(0, chai_1.expect)((0, reflection_1.isArrayType)(dataType)).to.be.true;
|
|
1352
|
+
(0, chai_1.expect)((0, reflection_1.isArrayType)(dataType.getDefaultType())).to.be.true;
|
|
1353
|
+
(0, chai_1.expect)((0, reflection_1.isIntegerType)(dataType.getDefaultType().getDefaultType())).to.be.true;
|
|
1354
|
+
});
|
|
1355
|
+
it('finds arrays of custom types', () => {
|
|
1356
|
+
const parser = parse(`
|
|
1357
|
+
sub alert(data as SomeKlass[])
|
|
1358
|
+
end sub
|
|
1359
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1360
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser.diagnostics);
|
|
1361
|
+
const symbolTable = parser.references.functionExpressions[0].symbolTable;
|
|
1362
|
+
const dataType = symbolTable.getSymbolType('data');
|
|
1363
|
+
(0, chai_1.expect)((0, reflection_1.isArrayType)(dataType)).to.be.true;
|
|
1364
|
+
(0, chai_1.expect)((0, reflection_1.isLazyType)(dataType.getDefaultType())).to.be.true;
|
|
1365
|
+
});
|
|
1161
1366
|
describe('loops', () => {
|
|
1162
1367
|
it('stores the loop variable in a for loop', () => {
|
|
1163
1368
|
const parser = parse(`
|
|
@@ -1167,9 +1372,9 @@ describe('parser', () => {
|
|
|
1167
1372
|
end for
|
|
1168
1373
|
end sub
|
|
1169
1374
|
`, Parser_1.ParseMode.BrighterScript);
|
|
1170
|
-
testHelpers_spec_1.expectZeroDiagnostics(parser.diagnostics);
|
|
1375
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser.diagnostics);
|
|
1171
1376
|
const currentSymbolTable = parser.references.functionExpressions[0].symbolTable;
|
|
1172
|
-
chai_1.expect(currentSymbolTable.getSymbolType('i')
|
|
1377
|
+
(0, chai_1.expect)((0, reflection_1.isIntegerType)(currentSymbolTable.getSymbolType('i'))).to.be.true;
|
|
1173
1378
|
});
|
|
1174
1379
|
it('stores the loop variable in a for each loop', () => {
|
|
1175
1380
|
const parser = parse(`
|
|
@@ -1179,15 +1384,231 @@ describe('parser', () => {
|
|
|
1179
1384
|
end for
|
|
1180
1385
|
end sub
|
|
1181
1386
|
`, Parser_1.ParseMode.BrighterScript);
|
|
1182
|
-
testHelpers_spec_1.expectZeroDiagnostics(parser.diagnostics);
|
|
1387
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser.diagnostics);
|
|
1388
|
+
const currentSymbolTable = parser.references.functionExpressions[0].symbolTable;
|
|
1389
|
+
(0, chai_1.expect)((0, reflection_1.isDynamicType)(currentSymbolTable.getSymbolType('datum'))).to.be.true;
|
|
1390
|
+
});
|
|
1391
|
+
it('determines the type of the variable in a for each if the target is an array literal', () => {
|
|
1392
|
+
const parser = parse(`
|
|
1393
|
+
sub doLoop()
|
|
1394
|
+
someData = [1,2,3]
|
|
1395
|
+
for each datum in someData
|
|
1396
|
+
print datum
|
|
1397
|
+
end for
|
|
1398
|
+
end sub
|
|
1399
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1400
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser.diagnostics);
|
|
1401
|
+
const currentSymbolTable = parser.references.functionExpressions[0].symbolTable;
|
|
1402
|
+
(0, chai_1.expect)((0, reflection_1.isIntegerType)(currentSymbolTable.getSymbolType('datum'))).to.be.true;
|
|
1403
|
+
});
|
|
1404
|
+
it('determines the type of the variable in a for each if the target is an array', () => {
|
|
1405
|
+
const parser = parse(`
|
|
1406
|
+
sub doLoop(someData as integer[])
|
|
1407
|
+
for each datum in someData
|
|
1408
|
+
print datum
|
|
1409
|
+
end for
|
|
1410
|
+
end sub
|
|
1411
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1412
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser.diagnostics);
|
|
1183
1413
|
const currentSymbolTable = parser.references.functionExpressions[0].symbolTable;
|
|
1184
|
-
chai_1.expect(currentSymbolTable.getSymbolType('datum')
|
|
1414
|
+
(0, chai_1.expect)((0, reflection_1.isIntegerType)(currentSymbolTable.getSymbolType('datum'))).to.be.true;
|
|
1185
1415
|
});
|
|
1416
|
+
it('determines the type of the variable in a for each if the target is an array of some custom type', () => {
|
|
1417
|
+
const parser = parse(`
|
|
1418
|
+
sub doLoop(someData as MyKlass[])
|
|
1419
|
+
for each datum in someData
|
|
1420
|
+
print datum.name
|
|
1421
|
+
end for
|
|
1422
|
+
end sub
|
|
1423
|
+
|
|
1424
|
+
class MyKlass
|
|
1425
|
+
name as string
|
|
1426
|
+
end class
|
|
1427
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1428
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser.diagnostics);
|
|
1429
|
+
const currentSymbolTable = parser.references.functionExpressions[0].symbolTable;
|
|
1430
|
+
(0, chai_1.expect)((0, reflection_1.isLazyType)(currentSymbolTable.getSymbol('datum')[0].type)).to.be.true;
|
|
1431
|
+
});
|
|
1432
|
+
it('determines the type of the variable in a for each if the target is a multidimensional array', () => {
|
|
1433
|
+
const parser = parse(`
|
|
1434
|
+
sub doLoop(data as float[][])
|
|
1435
|
+
for each row in data
|
|
1436
|
+
for each item in row
|
|
1437
|
+
print item
|
|
1438
|
+
end for
|
|
1439
|
+
end for
|
|
1440
|
+
end sub
|
|
1441
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1442
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser.diagnostics);
|
|
1443
|
+
const currentSymbolTable = parser.references.functionExpressions[0].symbolTable;
|
|
1444
|
+
(0, chai_1.expect)((0, reflection_1.isArrayType)(currentSymbolTable.getSymbol('row')[0].type)).to.be.true;
|
|
1445
|
+
(0, chai_1.expect)((0, reflection_1.isFloatType)(currentSymbolTable.getSymbol('item')[0].type)).to.be.true;
|
|
1446
|
+
});
|
|
1447
|
+
});
|
|
1448
|
+
});
|
|
1449
|
+
describe('tokenChain', () => {
|
|
1450
|
+
it('can find a chain of tokens', () => {
|
|
1451
|
+
const parser = parse(`
|
|
1452
|
+
sub someFunc()
|
|
1453
|
+
print m.field.childField
|
|
1454
|
+
end sub
|
|
1455
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1456
|
+
const childFieldToken = parser.getTokenAt(vscode_languageserver_1.Position.create(2, 38));
|
|
1457
|
+
const tokenChain = parser.getTokenChain(childFieldToken).chain;
|
|
1458
|
+
const tokenChainTokens = tokenChain.map(tcm => tcm.token);
|
|
1459
|
+
(0, chai_1.expect)(tokenChain.length).to.equal(3);
|
|
1460
|
+
(0, chai_1.expect)(tokenChainTokens.map(token => token.text)).to.eql(['m', 'field', 'childField']);
|
|
1461
|
+
(0, chai_1.expect)(tokenChain.map(tcm => tcm.usage)).to.eql([Parser_1.TokenUsage.Direct, Parser_1.TokenUsage.Direct, Parser_1.TokenUsage.Direct]);
|
|
1462
|
+
});
|
|
1463
|
+
it('can find a chain of tokens with function call with no args in the middle', () => {
|
|
1464
|
+
const parser = parse(`
|
|
1465
|
+
sub someFunc()
|
|
1466
|
+
print var.field.funcCall().childField
|
|
1467
|
+
end sub
|
|
1468
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1469
|
+
const childFieldToken = parser.getTokenAt(vscode_languageserver_1.Position.create(2, 49));
|
|
1470
|
+
const tokenChain = parser.getTokenChain(childFieldToken).chain;
|
|
1471
|
+
const tokenChainTokens = tokenChain.map(tcm => tcm.token);
|
|
1472
|
+
(0, chai_1.expect)(tokenChain.length).to.equal(4);
|
|
1473
|
+
(0, chai_1.expect)(tokenChainTokens.map(token => token.text)).to.eql(['var', 'field', 'funcCall', 'childField']);
|
|
1474
|
+
(0, chai_1.expect)(tokenChain[2].usage).to.eql(Parser_1.TokenUsage.Call);
|
|
1475
|
+
});
|
|
1476
|
+
it('can find a chain of tokens with function call with multiple args in the middle', () => {
|
|
1477
|
+
const parser = parse(`
|
|
1478
|
+
sub someFunc()
|
|
1479
|
+
print var.field.funcCall(1, "string", {key: value}).childField
|
|
1480
|
+
end sub
|
|
1481
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1482
|
+
const childFieldToken = parser.getTokenAt(vscode_languageserver_1.Position.create(2, 75));
|
|
1483
|
+
const tokenChain = parser.getTokenChain(childFieldToken).chain;
|
|
1484
|
+
const tokenChainTokens = tokenChain.map(tcm => tcm.token);
|
|
1485
|
+
(0, chai_1.expect)(tokenChain.length).to.equal(4);
|
|
1486
|
+
(0, chai_1.expect)(tokenChainTokens.map(token => token.text)).to.eql(['var', 'field', 'funcCall', 'childField']);
|
|
1487
|
+
(0, chai_1.expect)(tokenChain[2].usage).to.eql(Parser_1.TokenUsage.Call);
|
|
1186
1488
|
});
|
|
1489
|
+
it('can find a chain of tokens with function call with function call inside', () => {
|
|
1490
|
+
const parser = parse(`
|
|
1491
|
+
sub someFunc()
|
|
1492
|
+
print var.field.funcCall(a(), b(), otherFunc2(c(), {d: func3(e)})).childField
|
|
1493
|
+
end sub
|
|
1494
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1495
|
+
const childFieldToken = parser.getTokenAt(vscode_languageserver_1.Position.create(2, 90));
|
|
1496
|
+
const tokenChain = parser.getTokenChain(childFieldToken).chain;
|
|
1497
|
+
const tokenChainTokens = tokenChain.map(tcm => tcm.token);
|
|
1498
|
+
(0, chai_1.expect)(tokenChain.length).to.equal(4);
|
|
1499
|
+
(0, chai_1.expect)(tokenChainTokens.map(token => token.text)).to.eql(['var', 'field', 'funcCall', 'childField']);
|
|
1500
|
+
(0, chai_1.expect)(tokenChain[2].usage).to.eql(Parser_1.TokenUsage.Call);
|
|
1501
|
+
});
|
|
1502
|
+
it('can find a chain of tokens with array references inside', () => {
|
|
1503
|
+
const parser = parse(`
|
|
1504
|
+
sub someFunc()
|
|
1505
|
+
print var.field.myArray[0].childField
|
|
1506
|
+
end sub
|
|
1507
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1508
|
+
const childFieldToken = parser.getTokenAt(vscode_languageserver_1.Position.create(2, 50));
|
|
1509
|
+
const tokenChain = parser.getTokenChain(childFieldToken).chain;
|
|
1510
|
+
const tokenChainTokens = tokenChain.map(tcm => tcm.token);
|
|
1511
|
+
(0, chai_1.expect)(tokenChain.length).to.equal(4);
|
|
1512
|
+
(0, chai_1.expect)(tokenChainTokens.map(token => token.text)).to.eql(['var', 'field', 'myArray', 'childField']);
|
|
1513
|
+
(0, chai_1.expect)(tokenChain[2].usage).to.eql(Parser_1.TokenUsage.ArrayReference);
|
|
1514
|
+
});
|
|
1515
|
+
it('includes unknown when an expression in brackets is part of the chain', () => {
|
|
1516
|
+
const parser = parse(`
|
|
1517
|
+
sub someFunc()
|
|
1518
|
+
print (1 + 1).toStr()
|
|
1519
|
+
end sub
|
|
1520
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1521
|
+
const toStrToken = parser.getTokenAt(vscode_languageserver_1.Position.create(2, 34));
|
|
1522
|
+
const tokenChainResponse = parser.getTokenChain(toStrToken);
|
|
1523
|
+
(0, chai_1.expect)(tokenChainResponse.includesUnknowableTokenType).to.be.true;
|
|
1524
|
+
});
|
|
1525
|
+
it('includes unknown when an expression in double brackets is part of the chain', () => {
|
|
1526
|
+
const parser = parse(`
|
|
1527
|
+
sub someFunc()
|
|
1528
|
+
print ((2 + 1)*3).toStr()
|
|
1529
|
+
end sub
|
|
1530
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1531
|
+
const toStrToken = parser.getTokenAt(vscode_languageserver_1.Position.create(2, 38));
|
|
1532
|
+
const tokenChainResponse = parser.getTokenChain(toStrToken);
|
|
1533
|
+
(0, chai_1.expect)(tokenChainResponse.includesUnknowableTokenType).to.be.true;
|
|
1534
|
+
});
|
|
1535
|
+
it('includes unknown when a complicated expression in brackets is part of the chain', () => {
|
|
1536
|
+
const parser = parse(`
|
|
1537
|
+
sub someFunc(currentDate, lastUpdate)
|
|
1538
|
+
print (INT((currentDate.asSeconds() - lastUpdate) / 86400)).toStr()
|
|
1539
|
+
end sub
|
|
1540
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1541
|
+
const toStrToken = parser.getTokenAt(vscode_languageserver_1.Position.create(2, 81));
|
|
1542
|
+
const tokenChainResponse = parser.getTokenChain(toStrToken);
|
|
1543
|
+
(0, chai_1.expect)(tokenChainResponse.includesUnknowableTokenType).to.be.true;
|
|
1544
|
+
});
|
|
1545
|
+
});
|
|
1546
|
+
it('includes unknown when property is referenced via brackets', () => {
|
|
1547
|
+
const parser = parse(`
|
|
1548
|
+
sub someFunc()
|
|
1549
|
+
complexObj = {prop: "hello", subObj: {prop: "foo", grandChildObj:{prop:"bar"}}}
|
|
1550
|
+
print complexObj.subObj.prop
|
|
1551
|
+
print complexObj["subObj"].prop
|
|
1552
|
+
print complexObj["subObj"]["grandChildObj"].prop
|
|
1553
|
+
end sub
|
|
1554
|
+
`, Parser_1.ParseMode.BrighterScript);
|
|
1555
|
+
const propAsChainToken = parser.getTokenAt(vscode_languageserver_1.Position.create(3, 44)); // complexObj.subObj.prop
|
|
1556
|
+
const propAsAsBracketToken = parser.getTokenAt(vscode_languageserver_1.Position.create(4, 47)); // complexObj["subObj"].prop
|
|
1557
|
+
const propAsAsDoubleBracketToken = parser.getTokenAt(vscode_languageserver_1.Position.create(5, 64)); // complexObj["subObj"]["grandChildObj"].prop
|
|
1558
|
+
let tokenChainResponse = parser.getTokenChain(propAsChainToken);
|
|
1559
|
+
(0, chai_1.expect)(tokenChainResponse.includesUnknowableTokenType).to.be.false;
|
|
1560
|
+
(0, chai_1.expect)(tokenChainResponse.chain.map(tcm => tcm.token).map(token => token.text)).to.eql(['complexObj', 'subObj', 'prop']);
|
|
1561
|
+
tokenChainResponse = parser.getTokenChain(propAsAsBracketToken);
|
|
1562
|
+
(0, chai_1.expect)(tokenChainResponse.includesUnknowableTokenType).to.be.false;
|
|
1563
|
+
(0, chai_1.expect)(tokenChainResponse.chain[0].usage).to.eql(Parser_1.TokenUsage.ArrayReference);
|
|
1564
|
+
tokenChainResponse = parser.getTokenChain(propAsAsDoubleBracketToken);
|
|
1565
|
+
(0, chai_1.expect)(tokenChainResponse.includesUnknowableTokenType).to.be.true;
|
|
1566
|
+
});
|
|
1567
|
+
it('allows token kinds from AllowedLocalIdentifiers as start of a chain', () => {
|
|
1568
|
+
const parser = parse(`
|
|
1569
|
+
sub testLocalIdentifiers(override, string, float)
|
|
1570
|
+
override.someProp.someFunc()
|
|
1571
|
+
string.someProp.someFunc()
|
|
1572
|
+
float.someProp.someFunc()
|
|
1573
|
+
end sub
|
|
1574
|
+
`, Parser_1.ParseMode.BrightScript);
|
|
1575
|
+
const overrideFuncToken = parser.getTokenAt(vscode_languageserver_1.Position.create(2, 40)); // override.someProp.someFunc()
|
|
1576
|
+
const stringFuncToken = parser.getTokenAt(vscode_languageserver_1.Position.create(3, 40)); // string.someProp.someFunc()
|
|
1577
|
+
const floatFuncToken = parser.getTokenAt(vscode_languageserver_1.Position.create(4, 38)); // float.someProp.someFunc()
|
|
1578
|
+
let tokenChainResponse = parser.getTokenChain(overrideFuncToken);
|
|
1579
|
+
(0, chai_1.expect)(tokenChainResponse.includesUnknowableTokenType).to.be.false;
|
|
1580
|
+
(0, chai_1.expect)(tokenChainResponse.chain.map(tcm => tcm.token).map(token => token.text)).to.eql(['override', 'someProp', 'someFunc']);
|
|
1581
|
+
tokenChainResponse = parser.getTokenChain(stringFuncToken);
|
|
1582
|
+
(0, chai_1.expect)(tokenChainResponse.includesUnknowableTokenType).to.be.false;
|
|
1583
|
+
(0, chai_1.expect)(tokenChainResponse.chain.map(tcm => tcm.token).map(token => token.text)).to.eql(['string', 'someProp', 'someFunc']);
|
|
1584
|
+
tokenChainResponse = parser.getTokenChain(floatFuncToken);
|
|
1585
|
+
(0, chai_1.expect)(tokenChainResponse.includesUnknowableTokenType).to.be.false;
|
|
1586
|
+
(0, chai_1.expect)(tokenChainResponse.chain.map(tcm => tcm.token).map(token => token.text)).to.eql(['float', 'someProp', 'someFunc']);
|
|
1587
|
+
});
|
|
1588
|
+
it('allows token kinds from AllowedProperties in middle of a chain', () => {
|
|
1589
|
+
const parser = parse(`
|
|
1590
|
+
sub testAllowedProperties(someObj)
|
|
1591
|
+
someObj.override.someFunc()
|
|
1592
|
+
someObj.string.someFunc()
|
|
1593
|
+
someObj.float.someFunc()
|
|
1594
|
+
end sub
|
|
1595
|
+
`, Parser_1.ParseMode.BrightScript);
|
|
1596
|
+
const overrideFuncToken = parser.getTokenAt(vscode_languageserver_1.Position.create(2, 36)); // someObj.override.someFunc()
|
|
1597
|
+
const stringFuncToken = parser.getTokenAt(vscode_languageserver_1.Position.create(3, 36)); // someObj.string.someFunc()
|
|
1598
|
+
const floatFuncToken = parser.getTokenAt(vscode_languageserver_1.Position.create(4, 36)); // someObj.float.someFunc()
|
|
1599
|
+
let tokenChainResponse = parser.getTokenChain(overrideFuncToken);
|
|
1600
|
+
(0, chai_1.expect)(tokenChainResponse.includesUnknowableTokenType).to.be.false;
|
|
1601
|
+
(0, chai_1.expect)(tokenChainResponse.chain.map(tcm => tcm.token).map(token => token.text)).to.eql(['someObj', 'override', 'someFunc']);
|
|
1602
|
+
tokenChainResponse = parser.getTokenChain(stringFuncToken);
|
|
1603
|
+
(0, chai_1.expect)(tokenChainResponse.includesUnknowableTokenType).to.be.false;
|
|
1604
|
+
(0, chai_1.expect)(tokenChainResponse.chain.map(tcm => tcm.token).map(token => token.text)).to.eql(['someObj', 'string', 'someFunc']);
|
|
1605
|
+
tokenChainResponse = parser.getTokenChain(floatFuncToken);
|
|
1606
|
+
(0, chai_1.expect)(tokenChainResponse.includesUnknowableTokenType).to.be.false;
|
|
1607
|
+
(0, chai_1.expect)(tokenChainResponse.chain.map(tcm => tcm.token).map(token => token.text)).to.eql(['someObj', 'float', 'someFunc']);
|
|
1187
1608
|
});
|
|
1188
1609
|
});
|
|
1189
1610
|
function parse(text, mode) {
|
|
1190
|
-
let { tokens } =
|
|
1611
|
+
let { tokens } = Lexer_1.Lexer.scan(text);
|
|
1191
1612
|
return Parser_1.Parser.parse(tokens, {
|
|
1192
1613
|
mode: mode
|
|
1193
1614
|
});
|
|
@@ -1202,8 +1623,8 @@ function rangeToArray(range) {
|
|
|
1202
1623
|
}
|
|
1203
1624
|
exports.rangeToArray = rangeToArray;
|
|
1204
1625
|
function expectCommentWithText(stat, text) {
|
|
1205
|
-
if (reflection_1.isCommentStatement(stat)) {
|
|
1206
|
-
chai_1.expect(stat.text).to.equal(text);
|
|
1626
|
+
if ((0, reflection_1.isCommentStatement)(stat)) {
|
|
1627
|
+
(0, chai_1.expect)(stat.text).to.equal(text);
|
|
1207
1628
|
}
|
|
1208
1629
|
else {
|
|
1209
1630
|
failStatementType(stat, 'Comment');
|