brighterscript 1.0.0-alpha.2 → 1.0.0-alpha.22
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 +643 -253
- package/README.md +33 -9
- package/bsconfig.schema.json +22 -2
- package/dist/BsConfig.d.ts +9 -0
- package/dist/Cache.d.ts +5 -6
- package/dist/Cache.js +12 -11
- 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.d.ts +2 -2
- package/dist/DependencyGraph.js +20 -7
- package/dist/DependencyGraph.js.map +1 -1
- package/dist/DiagnosticCollection.d.ts +3 -3
- package/dist/DiagnosticCollection.js +11 -11
- package/dist/DiagnosticCollection.js.map +1 -1
- package/dist/DiagnosticFilterer.js +5 -4
- 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 +51 -39
- package/dist/LanguageServer.js +316 -232
- 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 +212 -95
- package/dist/Program.js.map +1 -1
- package/dist/ProgramBuilder.d.ts +4 -0
- package/dist/ProgramBuilder.js +36 -20
- package/dist/ProgramBuilder.js.map +1 -1
- package/dist/Scope.d.ts +126 -29
- package/dist/Scope.js +433 -156
- 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 +55 -13
- package/dist/SymbolTable.js.map +1 -1
- package/dist/XmlScope.d.ts +7 -2
- package/dist/XmlScope.js +65 -27
- package/dist/XmlScope.js.map +1 -1
- package/dist/astUtils/AstEditor.d.ts +65 -0
- package/dist/astUtils/AstEditor.js +239 -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 +254 -0
- package/dist/astUtils/AstEditor.spec.js.map +1 -0
- package/dist/astUtils/creators.d.ts +28 -6
- package/dist/astUtils/creators.js +137 -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 +32 -10
- package/dist/astUtils/reflection.js +82 -7
- 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 +76 -51
- package/dist/astUtils/visitors.js +31 -11
- package/dist/astUtils/visitors.js.map +1 -1
- package/dist/astUtils/visitors.spec.js +126 -32
- 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 +108 -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 +130 -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 +10 -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 +717 -147
- package/dist/files/BrsFile.Class.spec.js.map +1 -1
- package/dist/files/BrsFile.d.ts +70 -30
- package/dist/files/BrsFile.js +719 -353
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/BrsFile.spec.js +1238 -449
- package/dist/files/BrsFile.spec.js.map +1 -1
- package/dist/files/XmlFile.d.ts +6 -5
- package/dist/files/XmlFile.js +38 -30
- 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 +28 -5
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +133 -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 +9 -0
- package/dist/parser/BrsTranspileState.js +14 -0
- package/dist/parser/BrsTranspileState.js.map +1 -1
- package/dist/parser/Expression.d.ts +150 -34
- package/dist/parser/Expression.js +335 -165
- 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 +153 -30
- package/dist/parser/Parser.js +1100 -503
- 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 +202 -48
- package/dist/parser/Statement.js +648 -193
- 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/EnumType.d.ts +22 -0
- package/dist/types/EnumType.js +55 -0
- package/dist/types/EnumType.js.map +1 -0
- 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 +91 -21
- package/dist/util.js +364 -114
- package/dist/util.js.map +1 -1
- package/dist/validators/ClassValidator.d.ts +19 -2
- package/dist/validators/ClassValidator.js +164 -103
- package/dist/validators/ClassValidator.js.map +1 -1
- package/package.json +30 -19
- 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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NullCoalescingExpression = exports.TernaryExpression = exports.AnnotationExpression = exports.TaggedTemplateStringExpression = exports.TemplateStringExpression = exports.TemplateStringQuasiExpression = exports.CallfuncExpression = exports.NewExpression = exports.SourceLiteralExpression = exports.VariableExpression = exports.UnaryExpression = exports.AALiteralExpression = exports.AAMemberExpression = exports.ArrayLiteralExpression = exports.EscapedCharCodeLiteralExpression = exports.LiteralExpression = exports.GroupingExpression = exports.IndexedGetExpression = exports.XmlAttributeGetExpression = exports.DottedGetExpression = exports.NamespacedVariableNameExpression = exports.FunctionParameterExpression = exports.FunctionExpression = exports.CallExpression = exports.BinaryExpression = exports.Expression = void 0;
|
|
4
|
-
const
|
|
3
|
+
exports.ArrayTypeExpression = exports.TypeExpression = exports.RegexLiteralExpression = exports.NullCoalescingExpression = exports.TernaryExpression = exports.AnnotationExpression = exports.TaggedTemplateStringExpression = exports.TemplateStringExpression = exports.TemplateStringQuasiExpression = exports.CallfuncExpression = exports.NewExpression = exports.SourceLiteralExpression = exports.VariableExpression = exports.UnaryExpression = exports.AALiteralExpression = exports.AAMemberExpression = exports.ArrayLiteralExpression = exports.EscapedCharCodeLiteralExpression = exports.LiteralExpression = exports.GroupingExpression = exports.IndexedGetExpression = exports.XmlAttributeGetExpression = exports.DottedGetExpression = exports.NamespacedVariableNameExpression = exports.FunctionParameterExpression = exports.FunctionExpression = exports.CallExpression = exports.BinaryExpression = exports.Expression = void 0;
|
|
4
|
+
const TokenKind_1 = require("../lexer/TokenKind");
|
|
5
5
|
const util_1 = require("../util");
|
|
6
6
|
const Parser_1 = require("./Parser");
|
|
7
7
|
const fileUrl = require("file-url");
|
|
@@ -10,7 +10,9 @@ const reflection_1 = require("../astUtils/reflection");
|
|
|
10
10
|
const VoidType_1 = require("../types/VoidType");
|
|
11
11
|
const DynamicType_1 = require("../types/DynamicType");
|
|
12
12
|
const SymbolTable_1 = require("../SymbolTable");
|
|
13
|
-
const
|
|
13
|
+
const TypedFunctionType_1 = require("../types/TypedFunctionType");
|
|
14
|
+
const ObjectType_1 = require("../types/ObjectType");
|
|
15
|
+
const ArrayType_1 = require("../types/ArrayType");
|
|
14
16
|
/** A BrightScript expression */
|
|
15
17
|
class Expression {
|
|
16
18
|
constructor() {
|
|
@@ -27,7 +29,7 @@ class BinaryExpression extends Expression {
|
|
|
27
29
|
this.left = left;
|
|
28
30
|
this.operator = operator;
|
|
29
31
|
this.right = right;
|
|
30
|
-
this.range = util_1.default.
|
|
32
|
+
this.range = util_1.default.createBoundingRange(this.left, this.right);
|
|
31
33
|
}
|
|
32
34
|
transpile(state) {
|
|
33
35
|
return [
|
|
@@ -40,14 +42,18 @@ class BinaryExpression extends Expression {
|
|
|
40
42
|
}
|
|
41
43
|
walk(visitor, options) {
|
|
42
44
|
if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
|
|
43
|
-
visitors_1.walk(this, 'left', visitor, options);
|
|
44
|
-
visitors_1.walk(this, 'right', visitor, options);
|
|
45
|
+
(0, visitors_1.walk)(this, 'left', visitor, options);
|
|
46
|
+
(0, visitors_1.walk)(this, 'right', visitor, options);
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
50
|
exports.BinaryExpression = BinaryExpression;
|
|
49
51
|
class CallExpression extends Expression {
|
|
50
|
-
constructor(callee,
|
|
52
|
+
constructor(callee,
|
|
53
|
+
/**
|
|
54
|
+
* Can either be `(`, or `?(` for optional chaining
|
|
55
|
+
*/
|
|
56
|
+
openingParen, closingParen, args,
|
|
51
57
|
/**
|
|
52
58
|
* The namespace that currently wraps this call expression. This is NOT the namespace of the callee...that will be represented in the callee expression itself.
|
|
53
59
|
*/
|
|
@@ -58,7 +64,7 @@ class CallExpression extends Expression {
|
|
|
58
64
|
this.closingParen = closingParen;
|
|
59
65
|
this.args = args;
|
|
60
66
|
this.namespaceName = namespaceName;
|
|
61
|
-
this.range = util_1.default.
|
|
67
|
+
this.range = util_1.default.createBoundingRange(this.callee, this.closingParen);
|
|
62
68
|
}
|
|
63
69
|
transpile(state, nameOverride) {
|
|
64
70
|
let result = [];
|
|
@@ -83,17 +89,15 @@ class CallExpression extends Expression {
|
|
|
83
89
|
}
|
|
84
90
|
walk(visitor, options) {
|
|
85
91
|
if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
|
|
86
|
-
visitors_1.walk(this, 'callee', visitor, options);
|
|
87
|
-
|
|
88
|
-
visitors_1.walk(this.args, i, visitor, options, this);
|
|
89
|
-
}
|
|
92
|
+
(0, visitors_1.walk)(this, 'callee', visitor, options);
|
|
93
|
+
(0, visitors_1.walkArray)(this.args, visitor, options, this);
|
|
90
94
|
}
|
|
91
95
|
}
|
|
92
96
|
}
|
|
93
97
|
exports.CallExpression = CallExpression;
|
|
94
|
-
CallExpression.MaximumArguments =
|
|
98
|
+
CallExpression.MaximumArguments = util_1.MAX_PARAM_COUNT;
|
|
95
99
|
class FunctionExpression extends Expression {
|
|
96
|
-
constructor(parameters, body, functionType, end, leftParen, rightParen, asToken,
|
|
100
|
+
constructor(parameters, body, functionType, end, leftParen, rightParen, asToken, returnType,
|
|
97
101
|
/**
|
|
98
102
|
* If this function is enclosed within another function, this will reference that parent function
|
|
99
103
|
*/
|
|
@@ -106,7 +110,7 @@ class FunctionExpression extends Expression {
|
|
|
106
110
|
this.leftParen = leftParen;
|
|
107
111
|
this.rightParen = rightParen;
|
|
108
112
|
this.asToken = asToken;
|
|
109
|
-
this.
|
|
113
|
+
this.returnType = returnType;
|
|
110
114
|
this.parentFunction = parentFunction;
|
|
111
115
|
this.namespaceName = namespaceName;
|
|
112
116
|
this.parentSymbolTable = parentSymbolTable;
|
|
@@ -120,27 +124,46 @@ class FunctionExpression extends Expression {
|
|
|
120
124
|
* A list of all child functions declared directly within this function
|
|
121
125
|
*/
|
|
122
126
|
this.childFunctionExpressions = [];
|
|
123
|
-
if (this.
|
|
124
|
-
this.
|
|
127
|
+
if (this.returnType) {
|
|
128
|
+
this._returnType = this.returnType.type;
|
|
125
129
|
}
|
|
126
130
|
else if (this.functionType.text.toLowerCase() === 'sub') {
|
|
127
|
-
this.
|
|
131
|
+
this._returnType = new VoidType_1.VoidType();
|
|
128
132
|
}
|
|
129
133
|
else {
|
|
130
|
-
this.
|
|
134
|
+
this._returnType = new DynamicType_1.DynamicType();
|
|
131
135
|
}
|
|
132
136
|
this.symbolTable = new SymbolTable_1.SymbolTable(parentSymbolTable);
|
|
133
137
|
for (let param of parameters) {
|
|
134
|
-
this.symbolTable.addSymbol(param.name.text, param.name.range, param.
|
|
138
|
+
this.symbolTable.addSymbol(param.name.text, param.name.range, param.getType());
|
|
135
139
|
}
|
|
136
140
|
}
|
|
141
|
+
get range() {
|
|
142
|
+
return this.cacheRange();
|
|
143
|
+
}
|
|
137
144
|
/**
|
|
138
|
-
* The range of the function
|
|
139
|
-
* and ending with the last n' in 'end function' or 'b' in 'end sub'
|
|
145
|
+
* The range of the function
|
|
140
146
|
*/
|
|
141
|
-
|
|
142
|
-
var _a
|
|
143
|
-
|
|
147
|
+
cacheRange() {
|
|
148
|
+
var _a;
|
|
149
|
+
if (!this._range) {
|
|
150
|
+
this._range = util_1.default.createBoundingRange(this.functionType, this.leftParen, ...((_a = this.parameters) !== null && _a !== void 0 ? _a : []), this.rightParen, this.asToken, this.returnType, this.body, this.end);
|
|
151
|
+
}
|
|
152
|
+
return this._range;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* The type this function returns
|
|
156
|
+
*/
|
|
157
|
+
getReturnType() {
|
|
158
|
+
return this._returnType;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* The range of the function declaration, starting at the 'f' in function or 's' in sub (or the open paren if the keyword is missing),
|
|
162
|
+
* and ending with the last character in the returnTypeToken, or the 's' in 'as', or the rightParen
|
|
163
|
+
*/
|
|
164
|
+
get functionDeclarationRange() {
|
|
165
|
+
var _a;
|
|
166
|
+
return util_1.default.createBoundingRange(this.functionType, this.leftParen, ...((_a = this.parameters) !== null && _a !== void 0 ? _a : []), this.rightParen, this.asToken, this.returnType);
|
|
144
167
|
}
|
|
145
168
|
transpile(state, name, includeBody = true) {
|
|
146
169
|
let results = [];
|
|
@@ -170,7 +193,7 @@ class FunctionExpression extends Expression {
|
|
|
170
193
|
//as
|
|
171
194
|
state.transpileToken(this.asToken), ' ',
|
|
172
195
|
//return type
|
|
173
|
-
state.sourceNode(this.
|
|
196
|
+
state.sourceNode(this.returnType, this.getReturnType().toTypeString(state.typeContext)));
|
|
174
197
|
}
|
|
175
198
|
if (includeBody) {
|
|
176
199
|
state.lineage.unshift(this);
|
|
@@ -178,9 +201,11 @@ class FunctionExpression extends Expression {
|
|
|
178
201
|
state.lineage.shift();
|
|
179
202
|
results.push(...body);
|
|
180
203
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
204
|
+
if (this.end) {
|
|
205
|
+
results.push('\n');
|
|
206
|
+
//'end sub'|'end function'
|
|
207
|
+
results.push(state.indent(), state.transpileToken(this.end));
|
|
208
|
+
}
|
|
184
209
|
return results;
|
|
185
210
|
}
|
|
186
211
|
getTypedef(state, name) {
|
|
@@ -188,43 +213,38 @@ class FunctionExpression extends Expression {
|
|
|
188
213
|
}
|
|
189
214
|
walk(visitor, options) {
|
|
190
215
|
if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
|
|
191
|
-
|
|
192
|
-
visitors_1.walk(this.parameters, i, visitor, options, this);
|
|
193
|
-
}
|
|
216
|
+
(0, visitors_1.walkArray)(this.parameters, visitor, options, this);
|
|
194
217
|
//This is the core of full-program walking...it allows us to step into sub functions
|
|
195
218
|
if (options.walkMode & visitors_1.InternalWalkMode.recurseChildFunctions) {
|
|
196
|
-
visitors_1.walk(this, '
|
|
219
|
+
(0, visitors_1.walk)(this, 'returnType', visitor, options);
|
|
220
|
+
(0, visitors_1.walk)(this, 'body', visitor, options);
|
|
197
221
|
}
|
|
198
222
|
}
|
|
199
223
|
}
|
|
200
224
|
getFunctionType() {
|
|
201
|
-
let functionType = new
|
|
225
|
+
let functionType = new TypedFunctionType_1.TypedFunctionType(this.getReturnType());
|
|
202
226
|
functionType.isSub = this.functionType.text === 'sub';
|
|
203
227
|
for (let param of this.parameters) {
|
|
204
|
-
|
|
205
|
-
//TODO compute optional parameters
|
|
206
|
-
functionType.addParameter(param.name.text, param.type, isRequired);
|
|
228
|
+
functionType.addParameter(param.name.text, param.getType(), param.isOptional);
|
|
207
229
|
}
|
|
208
230
|
return functionType;
|
|
209
231
|
}
|
|
210
232
|
}
|
|
211
233
|
exports.FunctionExpression = FunctionExpression;
|
|
212
234
|
class FunctionParameterExpression extends Expression {
|
|
213
|
-
constructor(name,
|
|
235
|
+
constructor(name, typeInContext, equalsToken, defaultValue, asToken, type, namespaceName) {
|
|
214
236
|
super();
|
|
215
237
|
this.name = name;
|
|
216
|
-
this.
|
|
238
|
+
this.typeInContext = typeInContext;
|
|
217
239
|
this.equalsToken = equalsToken;
|
|
218
240
|
this.defaultValue = defaultValue;
|
|
219
241
|
this.asToken = asToken;
|
|
220
|
-
this.
|
|
242
|
+
this.type = type;
|
|
221
243
|
this.namespaceName = namespaceName;
|
|
244
|
+
this.range = util_1.default.createBoundingRange(this.name, this.equalsToken, this.defaultValue, this.asToken, this.type);
|
|
222
245
|
}
|
|
223
|
-
|
|
224
|
-
return
|
|
225
|
-
start: this.name.range.start,
|
|
226
|
-
end: this.typeToken ? this.typeToken.range.end : this.name.range.end
|
|
227
|
-
};
|
|
246
|
+
getType() {
|
|
247
|
+
return this.typeInContext;
|
|
228
248
|
}
|
|
229
249
|
transpile(state) {
|
|
230
250
|
let result = [
|
|
@@ -241,16 +261,20 @@ class FunctionParameterExpression extends Expression {
|
|
|
241
261
|
result.push(' ');
|
|
242
262
|
result.push(state.transpileToken(this.asToken));
|
|
243
263
|
result.push(' ');
|
|
244
|
-
result.push(state.sourceNode(this.
|
|
264
|
+
result.push(state.sourceNode(this.type, this.getType().toTypeString(state.typeContext)));
|
|
245
265
|
}
|
|
246
266
|
return result;
|
|
247
267
|
}
|
|
248
268
|
walk(visitor, options) {
|
|
249
269
|
// eslint-disable-next-line no-bitwise
|
|
250
270
|
if (this.defaultValue && options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
|
|
251
|
-
visitors_1.walk(this, 'defaultValue', visitor, options);
|
|
271
|
+
(0, visitors_1.walk)(this, 'defaultValue', visitor, options);
|
|
272
|
+
(0, visitors_1.walk)(this, 'type', visitor, options);
|
|
252
273
|
}
|
|
253
274
|
}
|
|
275
|
+
get isOptional() {
|
|
276
|
+
return !!this.defaultValue;
|
|
277
|
+
}
|
|
254
278
|
}
|
|
255
279
|
exports.FunctionParameterExpression = FunctionParameterExpression;
|
|
256
280
|
class NamespacedVariableNameExpression extends Expression {
|
|
@@ -268,20 +292,20 @@ class NamespacedVariableNameExpression extends Expression {
|
|
|
268
292
|
}
|
|
269
293
|
getNameParts() {
|
|
270
294
|
let parts = [];
|
|
271
|
-
if (reflection_1.isVariableExpression(this.expression)) {
|
|
295
|
+
if ((0, reflection_1.isVariableExpression)(this.expression)) {
|
|
272
296
|
parts.push(this.expression.name.text);
|
|
273
297
|
}
|
|
274
298
|
else {
|
|
275
299
|
let expr = this.expression;
|
|
276
300
|
parts.push(expr.name.text);
|
|
277
|
-
while (reflection_1.isVariableExpression(expr) === false) {
|
|
301
|
+
while ((0, reflection_1.isVariableExpression)(expr) === false) {
|
|
278
302
|
expr = expr.obj;
|
|
279
303
|
parts.unshift(expr.name.text);
|
|
280
304
|
}
|
|
281
305
|
}
|
|
282
306
|
return parts;
|
|
283
307
|
}
|
|
284
|
-
getName(parseMode) {
|
|
308
|
+
getName(parseMode = Parser_1.ParseMode.BrighterScript) {
|
|
285
309
|
if (parseMode === Parser_1.ParseMode.BrighterScript) {
|
|
286
310
|
return this.getNameParts().join('.');
|
|
287
311
|
}
|
|
@@ -291,18 +315,22 @@ class NamespacedVariableNameExpression extends Expression {
|
|
|
291
315
|
}
|
|
292
316
|
walk(visitor, options) {
|
|
293
317
|
if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
|
|
294
|
-
visitors_1.walk(this, 'expression', visitor, options);
|
|
318
|
+
(0, visitors_1.walk)(this, 'expression', visitor, options);
|
|
295
319
|
}
|
|
296
320
|
}
|
|
297
321
|
}
|
|
298
322
|
exports.NamespacedVariableNameExpression = NamespacedVariableNameExpression;
|
|
299
323
|
class DottedGetExpression extends Expression {
|
|
300
|
-
constructor(obj, name,
|
|
324
|
+
constructor(obj, name,
|
|
325
|
+
/**
|
|
326
|
+
* Can either be `.`, or `?.` for optional chaining
|
|
327
|
+
*/
|
|
328
|
+
dot) {
|
|
301
329
|
super();
|
|
302
330
|
this.obj = obj;
|
|
303
331
|
this.name = name;
|
|
304
332
|
this.dot = dot;
|
|
305
|
-
this.range = util_1.default.
|
|
333
|
+
this.range = util_1.default.createBoundingRange(this.obj, this.dot, this.name);
|
|
306
334
|
}
|
|
307
335
|
transpile(state) {
|
|
308
336
|
//if the callee starts with a namespace name, transpile the name
|
|
@@ -312,52 +340,63 @@ class DottedGetExpression extends Expression {
|
|
|
312
340
|
else {
|
|
313
341
|
return [
|
|
314
342
|
...this.obj.transpile(state),
|
|
315
|
-
|
|
343
|
+
state.transpileToken(this.dot),
|
|
316
344
|
state.transpileToken(this.name)
|
|
317
345
|
];
|
|
318
346
|
}
|
|
319
347
|
}
|
|
320
348
|
walk(visitor, options) {
|
|
321
349
|
if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
|
|
322
|
-
visitors_1.walk(this, 'obj', visitor, options);
|
|
350
|
+
(0, visitors_1.walk)(this, 'obj', visitor, options);
|
|
323
351
|
}
|
|
324
352
|
}
|
|
325
353
|
}
|
|
326
354
|
exports.DottedGetExpression = DottedGetExpression;
|
|
327
355
|
class XmlAttributeGetExpression extends Expression {
|
|
328
|
-
constructor(obj, name,
|
|
356
|
+
constructor(obj, name,
|
|
357
|
+
/**
|
|
358
|
+
* Can either be `@`, or `?@` for optional chaining
|
|
359
|
+
*/
|
|
360
|
+
at) {
|
|
329
361
|
super();
|
|
330
362
|
this.obj = obj;
|
|
331
363
|
this.name = name;
|
|
332
364
|
this.at = at;
|
|
333
|
-
this.range = util_1.default.
|
|
365
|
+
this.range = util_1.default.createBoundingRange(this.obj, this.at, this.name);
|
|
334
366
|
}
|
|
335
367
|
transpile(state) {
|
|
336
368
|
return [
|
|
337
369
|
...this.obj.transpile(state),
|
|
338
|
-
|
|
370
|
+
state.transpileToken(this.at),
|
|
339
371
|
state.transpileToken(this.name)
|
|
340
372
|
];
|
|
341
373
|
}
|
|
342
374
|
walk(visitor, options) {
|
|
343
375
|
if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
|
|
344
|
-
visitors_1.walk(this, 'obj', visitor, options);
|
|
376
|
+
(0, visitors_1.walk)(this, 'obj', visitor, options);
|
|
345
377
|
}
|
|
346
378
|
}
|
|
347
379
|
}
|
|
348
380
|
exports.XmlAttributeGetExpression = XmlAttributeGetExpression;
|
|
349
381
|
class IndexedGetExpression extends Expression {
|
|
350
|
-
constructor(obj, index,
|
|
382
|
+
constructor(obj, index,
|
|
383
|
+
/**
|
|
384
|
+
* Can either be `[` or `?[`. If `?.[` is used, this will be `[` and `optionalChainingToken` will be `?.`
|
|
385
|
+
*/
|
|
386
|
+
openingSquare, closingSquare, questionDotToken // ? or ?.
|
|
387
|
+
) {
|
|
351
388
|
super();
|
|
352
389
|
this.obj = obj;
|
|
353
390
|
this.index = index;
|
|
354
391
|
this.openingSquare = openingSquare;
|
|
355
392
|
this.closingSquare = closingSquare;
|
|
356
|
-
this.
|
|
393
|
+
this.questionDotToken = questionDotToken;
|
|
394
|
+
this.range = util_1.default.createBoundingRange(this.obj, this.openingSquare, this.questionDotToken, this.openingSquare, this.index, this.closingSquare);
|
|
357
395
|
}
|
|
358
396
|
transpile(state) {
|
|
359
397
|
return [
|
|
360
398
|
...this.obj.transpile(state),
|
|
399
|
+
this.questionDotToken ? state.transpileToken(this.questionDotToken) : '',
|
|
361
400
|
state.transpileToken(this.openingSquare),
|
|
362
401
|
...this.index.transpile(state),
|
|
363
402
|
state.transpileToken(this.closingSquare)
|
|
@@ -365,8 +404,8 @@ class IndexedGetExpression extends Expression {
|
|
|
365
404
|
}
|
|
366
405
|
walk(visitor, options) {
|
|
367
406
|
if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
|
|
368
|
-
visitors_1.walk(this, 'obj', visitor, options);
|
|
369
|
-
visitors_1.walk(this, 'index', visitor, options);
|
|
407
|
+
(0, visitors_1.walk)(this, 'obj', visitor, options);
|
|
408
|
+
(0, visitors_1.walk)(this, 'index', visitor, options);
|
|
370
409
|
}
|
|
371
410
|
}
|
|
372
411
|
}
|
|
@@ -376,7 +415,7 @@ class GroupingExpression extends Expression {
|
|
|
376
415
|
super();
|
|
377
416
|
this.tokens = tokens;
|
|
378
417
|
this.expression = expression;
|
|
379
|
-
this.range = util_1.default.
|
|
418
|
+
this.range = util_1.default.createBoundingRange(this.tokens.left, this.expression, this.tokens.right);
|
|
380
419
|
}
|
|
381
420
|
transpile(state) {
|
|
382
421
|
return [
|
|
@@ -387,7 +426,7 @@ class GroupingExpression extends Expression {
|
|
|
387
426
|
}
|
|
388
427
|
walk(visitor, options) {
|
|
389
428
|
if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
|
|
390
|
-
visitors_1.walk(this, 'expression', visitor, options);
|
|
429
|
+
(0, visitors_1.walk)(this, 'expression', visitor, options);
|
|
391
430
|
}
|
|
392
431
|
}
|
|
393
432
|
}
|
|
@@ -396,18 +435,16 @@ class LiteralExpression extends Expression {
|
|
|
396
435
|
constructor(token) {
|
|
397
436
|
super();
|
|
398
437
|
this.token = token;
|
|
438
|
+
this.range = this.token.range;
|
|
399
439
|
this.type = util_1.default.tokenToBscType(token);
|
|
400
440
|
}
|
|
401
|
-
get range() {
|
|
402
|
-
return this.token.range;
|
|
403
|
-
}
|
|
404
441
|
transpile(state) {
|
|
405
442
|
let text;
|
|
406
|
-
if (this.token.kind ===
|
|
443
|
+
if (this.token.kind === TokenKind_1.TokenKind.TemplateStringQuasi) {
|
|
407
444
|
//wrap quasis with quotes (and escape inner quotemarks)
|
|
408
445
|
text = `"${this.token.text.replace(/"/g, '""')}"`;
|
|
409
446
|
}
|
|
410
|
-
else if (reflection_1.isStringType(this.type)) {
|
|
447
|
+
else if ((0, reflection_1.isStringType)(this.type)) {
|
|
411
448
|
text = this.token.text;
|
|
412
449
|
//add trailing quotemark if it's missing. We will have already generated a diagnostic for this.
|
|
413
450
|
if (text.endsWith('"') === false) {
|
|
@@ -448,12 +485,13 @@ class EscapedCharCodeLiteralExpression extends Expression {
|
|
|
448
485
|
exports.EscapedCharCodeLiteralExpression = EscapedCharCodeLiteralExpression;
|
|
449
486
|
class ArrayLiteralExpression extends Expression {
|
|
450
487
|
constructor(elements, open, close, hasSpread = false) {
|
|
488
|
+
var _a;
|
|
451
489
|
super();
|
|
452
490
|
this.elements = elements;
|
|
453
491
|
this.open = open;
|
|
454
492
|
this.close = close;
|
|
455
493
|
this.hasSpread = hasSpread;
|
|
456
|
-
this.range = util_1.default.
|
|
494
|
+
this.range = util_1.default.createBoundingRange(this.open, ...((_a = this.elements) !== null && _a !== void 0 ? _a : []), this.close);
|
|
457
495
|
}
|
|
458
496
|
transpile(state) {
|
|
459
497
|
let result = [];
|
|
@@ -463,7 +501,7 @@ class ArrayLiteralExpression extends Expression {
|
|
|
463
501
|
for (let i = 0; i < this.elements.length; i++) {
|
|
464
502
|
let previousElement = this.elements[i - 1];
|
|
465
503
|
let element = this.elements[i];
|
|
466
|
-
if (reflection_1.isCommentStatement(element)) {
|
|
504
|
+
if ((0, reflection_1.isCommentStatement)(element)) {
|
|
467
505
|
//if the comment is on the same line as opening square or previous statement, don't add newline
|
|
468
506
|
if (util_1.default.linesTouch(this.open, element) || util_1.default.linesTouch(previousElement, element)) {
|
|
469
507
|
result.push(' ');
|
|
@@ -478,15 +516,6 @@ class ArrayLiteralExpression extends Expression {
|
|
|
478
516
|
else {
|
|
479
517
|
result.push('\n');
|
|
480
518
|
result.push(state.indent(), ...element.transpile(state));
|
|
481
|
-
//add a comma if we know there will be another non-comment statement after this
|
|
482
|
-
for (let j = i + 1; j < this.elements.length; j++) {
|
|
483
|
-
let el = this.elements[j];
|
|
484
|
-
//add a comma if there will be another element after this
|
|
485
|
-
if (reflection_1.isCommentStatement(el) === false) {
|
|
486
|
-
result.push(',');
|
|
487
|
-
break;
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
519
|
}
|
|
491
520
|
}
|
|
492
521
|
state.blockDepth--;
|
|
@@ -500,9 +529,7 @@ class ArrayLiteralExpression extends Expression {
|
|
|
500
529
|
}
|
|
501
530
|
walk(visitor, options) {
|
|
502
531
|
if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
|
|
503
|
-
|
|
504
|
-
visitors_1.walk(this.elements, i, visitor, options, this);
|
|
505
|
-
}
|
|
532
|
+
(0, visitors_1.walkArray)(this.elements, visitor, options, this);
|
|
506
533
|
}
|
|
507
534
|
}
|
|
508
535
|
}
|
|
@@ -510,29 +537,44 @@ exports.ArrayLiteralExpression = ArrayLiteralExpression;
|
|
|
510
537
|
class AAMemberExpression extends Expression {
|
|
511
538
|
constructor(keyToken, colonToken,
|
|
512
539
|
/** The expression evaluated to determine the member's initial value. */
|
|
513
|
-
value) {
|
|
540
|
+
value, type) {
|
|
514
541
|
super();
|
|
515
542
|
this.keyToken = keyToken;
|
|
516
543
|
this.colonToken = colonToken;
|
|
517
544
|
this.value = value;
|
|
518
|
-
this.
|
|
545
|
+
this.type = type;
|
|
546
|
+
this.range = util_1.default.createBoundingRange(this.keyToken, this.colonToken, this.value);
|
|
519
547
|
}
|
|
520
548
|
transpile(state) {
|
|
521
549
|
//TODO move the logic from AALiteralExpression loop into this function
|
|
522
550
|
return [];
|
|
523
551
|
}
|
|
524
552
|
walk(visitor, options) {
|
|
525
|
-
visitors_1.walk(this, 'value', visitor, options);
|
|
553
|
+
(0, visitors_1.walk)(this, 'value', visitor, options);
|
|
526
554
|
}
|
|
527
555
|
}
|
|
528
556
|
exports.AAMemberExpression = AAMemberExpression;
|
|
529
557
|
class AALiteralExpression extends Expression {
|
|
530
|
-
constructor(elements, open, close) {
|
|
558
|
+
constructor(elements, open, close, functionExpression) {
|
|
559
|
+
var _a;
|
|
531
560
|
super();
|
|
532
561
|
this.elements = elements;
|
|
533
562
|
this.open = open;
|
|
534
563
|
this.close = close;
|
|
535
|
-
this.
|
|
564
|
+
this.functionExpression = functionExpression;
|
|
565
|
+
this.symbolTable = new SymbolTable_1.SymbolTable();
|
|
566
|
+
this.memberTable = new SymbolTable_1.SymbolTable();
|
|
567
|
+
this.range = util_1.default.createBoundingRange(this.open, ...((_a = this.elements) !== null && _a !== void 0 ? _a : []), this.close);
|
|
568
|
+
this.buildSymbolTable();
|
|
569
|
+
}
|
|
570
|
+
buildSymbolTable() {
|
|
571
|
+
this.symbolTable.clear();
|
|
572
|
+
this.symbolTable.addSymbol('m', { start: this.open.range.start, end: this.close.range.end }, new ObjectType_1.ObjectType('object', this.memberTable));
|
|
573
|
+
for (const element of this.elements) {
|
|
574
|
+
if ((0, reflection_1.isAAMemberExpression)(element)) {
|
|
575
|
+
this.memberTable.addSymbol(element.keyToken.text, element.keyToken.range, (0, Parser_1.getBscTypeFromExpression)(element.value, this.functionExpression));
|
|
576
|
+
}
|
|
577
|
+
}
|
|
536
578
|
}
|
|
537
579
|
transpile(state) {
|
|
538
580
|
let result = [];
|
|
@@ -540,7 +582,7 @@ class AALiteralExpression extends Expression {
|
|
|
540
582
|
result.push(state.transpileToken(this.open));
|
|
541
583
|
let hasChildren = this.elements.length > 0;
|
|
542
584
|
//add newline if the object has children and the first child isn't a comment starting on the same line as opening curly
|
|
543
|
-
if (hasChildren && (reflection_1.isCommentStatement(this.elements[0]) === false || !util_1.default.linesTouch(this.elements[0], this.open))) {
|
|
585
|
+
if (hasChildren && ((0, reflection_1.isCommentStatement)(this.elements[0]) === false || !util_1.default.linesTouch(this.elements[0], this.open))) {
|
|
544
586
|
result.push('\n');
|
|
545
587
|
}
|
|
546
588
|
state.blockDepth++;
|
|
@@ -549,7 +591,7 @@ class AALiteralExpression extends Expression {
|
|
|
549
591
|
let previousElement = this.elements[i - 1];
|
|
550
592
|
let nextElement = this.elements[i + 1];
|
|
551
593
|
//don't indent if comment is same-line
|
|
552
|
-
if (reflection_1.isCommentStatement(element) &&
|
|
594
|
+
if ((0, reflection_1.isCommentStatement)(element) &&
|
|
553
595
|
(util_1.default.linesTouch(this.open, element) || util_1.default.linesTouch(previousElement, element))) {
|
|
554
596
|
result.push(' ');
|
|
555
597
|
//indent line
|
|
@@ -558,7 +600,7 @@ class AALiteralExpression extends Expression {
|
|
|
558
600
|
result.push(state.indent());
|
|
559
601
|
}
|
|
560
602
|
//render comments
|
|
561
|
-
if (reflection_1.isCommentStatement(element)) {
|
|
603
|
+
if ((0, reflection_1.isCommentStatement)(element)) {
|
|
562
604
|
result.push(...element.transpile(state));
|
|
563
605
|
}
|
|
564
606
|
else {
|
|
@@ -566,23 +608,11 @@ class AALiteralExpression extends Expression {
|
|
|
566
608
|
result.push(state.transpileToken(element.keyToken));
|
|
567
609
|
//colon
|
|
568
610
|
result.push(state.transpileToken(element.colonToken), ' ');
|
|
569
|
-
//determine if comments are the only members left in the array
|
|
570
|
-
let onlyCommentsRemaining = true;
|
|
571
|
-
for (let j = i + 1; j < this.elements.length; j++) {
|
|
572
|
-
if (reflection_1.isCommentStatement(this.elements[j]) === false) {
|
|
573
|
-
onlyCommentsRemaining = false;
|
|
574
|
-
break;
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
611
|
//value
|
|
578
612
|
result.push(...element.value.transpile(state));
|
|
579
|
-
//add trailing comma if not final element (excluding comments)
|
|
580
|
-
if (i !== this.elements.length - 1 && onlyCommentsRemaining === false) {
|
|
581
|
-
result.push(',');
|
|
582
|
-
}
|
|
583
613
|
}
|
|
584
614
|
//if next element is a same-line comment, skip the newline
|
|
585
|
-
if (nextElement && reflection_1.isCommentStatement(nextElement) && nextElement.range.start.line === element.range.start.line) {
|
|
615
|
+
if (nextElement && (0, reflection_1.isCommentStatement)(nextElement) && nextElement.range.start.line === element.range.start.line) {
|
|
586
616
|
//add a newline between statements
|
|
587
617
|
}
|
|
588
618
|
else {
|
|
@@ -600,14 +630,7 @@ class AALiteralExpression extends Expression {
|
|
|
600
630
|
}
|
|
601
631
|
walk(visitor, options) {
|
|
602
632
|
if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
|
|
603
|
-
|
|
604
|
-
if (reflection_1.isCommentStatement(this.elements[i])) {
|
|
605
|
-
visitors_1.walk(this.elements, i, visitor, options, this);
|
|
606
|
-
}
|
|
607
|
-
else {
|
|
608
|
-
visitors_1.walk(this.elements, i, visitor, options, this);
|
|
609
|
-
}
|
|
610
|
-
}
|
|
633
|
+
(0, visitors_1.walkArray)(this.elements, visitor, options, this);
|
|
611
634
|
}
|
|
612
635
|
}
|
|
613
636
|
}
|
|
@@ -617,7 +640,7 @@ class UnaryExpression extends Expression {
|
|
|
617
640
|
super();
|
|
618
641
|
this.operator = operator;
|
|
619
642
|
this.right = right;
|
|
620
|
-
this.range = util_1.default.
|
|
643
|
+
this.range = util_1.default.createBoundingRange(this.operator, this.right);
|
|
621
644
|
}
|
|
622
645
|
transpile(state) {
|
|
623
646
|
return [
|
|
@@ -628,7 +651,7 @@ class UnaryExpression extends Expression {
|
|
|
628
651
|
}
|
|
629
652
|
walk(visitor, options) {
|
|
630
653
|
if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
|
|
631
|
-
visitors_1.walk(this, 'right', visitor, options);
|
|
654
|
+
(0, visitors_1.walk)(this, 'right', visitor, options);
|
|
632
655
|
}
|
|
633
656
|
}
|
|
634
657
|
}
|
|
@@ -686,28 +709,30 @@ class SourceLiteralExpression extends Expression {
|
|
|
686
709
|
transpile(state) {
|
|
687
710
|
let text;
|
|
688
711
|
switch (this.token.kind) {
|
|
689
|
-
case
|
|
690
|
-
|
|
712
|
+
case TokenKind_1.TokenKind.SourceFilePathLiteral:
|
|
713
|
+
const pathUrl = fileUrl(state.srcPath);
|
|
714
|
+
text = `"${pathUrl.substring(0, 4)}" + "${pathUrl.substring(4)}"`;
|
|
691
715
|
break;
|
|
692
|
-
case
|
|
716
|
+
case TokenKind_1.TokenKind.SourceLineNumLiteral:
|
|
693
717
|
text = `${this.token.range.start.line + 1}`;
|
|
694
718
|
break;
|
|
695
|
-
case
|
|
719
|
+
case TokenKind_1.TokenKind.FunctionNameLiteral:
|
|
696
720
|
text = `"${this.getFunctionName(state, Parser_1.ParseMode.BrightScript)}"`;
|
|
697
721
|
break;
|
|
698
|
-
case
|
|
722
|
+
case TokenKind_1.TokenKind.SourceFunctionNameLiteral:
|
|
699
723
|
text = `"${this.getFunctionName(state, Parser_1.ParseMode.BrighterScript)}"`;
|
|
700
724
|
break;
|
|
701
|
-
case
|
|
702
|
-
|
|
725
|
+
case TokenKind_1.TokenKind.SourceLocationLiteral:
|
|
726
|
+
const locationUrl = fileUrl(state.srcPath);
|
|
727
|
+
text = `"${locationUrl.substring(0, 4)}" + "${locationUrl.substring(4)}:${this.token.range.start.line + 1}"`;
|
|
703
728
|
break;
|
|
704
|
-
case
|
|
729
|
+
case TokenKind_1.TokenKind.PkgPathLiteral:
|
|
705
730
|
text = `"${state.file.pkgPath.replace(/\.bs$/i, '.brs')}"`;
|
|
706
731
|
break;
|
|
707
|
-
case
|
|
732
|
+
case TokenKind_1.TokenKind.PkgLocationLiteral:
|
|
708
733
|
text = `"${state.file.pkgPath.replace(/\.bs$/i, '.brs')}:" + str(LINE_NUM)`;
|
|
709
734
|
break;
|
|
710
|
-
case
|
|
735
|
+
case TokenKind_1.TokenKind.LineNumLiteral:
|
|
711
736
|
default:
|
|
712
737
|
//use the original text (because it looks like a variable)
|
|
713
738
|
text = this.token.text;
|
|
@@ -732,7 +757,7 @@ class NewExpression extends Expression {
|
|
|
732
757
|
super();
|
|
733
758
|
this.newKeyword = newKeyword;
|
|
734
759
|
this.call = call;
|
|
735
|
-
this.range = util_1.default.
|
|
760
|
+
this.range = util_1.default.createBoundingRange(this.newKeyword, this.call);
|
|
736
761
|
}
|
|
737
762
|
/**
|
|
738
763
|
* The name of the class to initialize (with optional namespace prefixed)
|
|
@@ -754,14 +779,14 @@ class NewExpression extends Expression {
|
|
|
754
779
|
}
|
|
755
780
|
walk(visitor, options) {
|
|
756
781
|
if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
|
|
757
|
-
visitors_1.walk(this, 'call', visitor, options);
|
|
782
|
+
(0, visitors_1.walk)(this, 'call', visitor, options);
|
|
758
783
|
}
|
|
759
784
|
}
|
|
760
785
|
}
|
|
761
786
|
exports.NewExpression = NewExpression;
|
|
762
787
|
class CallfuncExpression extends Expression {
|
|
763
788
|
constructor(callee, operator, methodName, openingParen, args, closingParen) {
|
|
764
|
-
var _a
|
|
789
|
+
var _a;
|
|
765
790
|
super();
|
|
766
791
|
this.callee = callee;
|
|
767
792
|
this.operator = operator;
|
|
@@ -769,7 +794,7 @@ class CallfuncExpression extends Expression {
|
|
|
769
794
|
this.openingParen = openingParen;
|
|
770
795
|
this.args = args;
|
|
771
796
|
this.closingParen = closingParen;
|
|
772
|
-
this.range = util_1.default.
|
|
797
|
+
this.range = util_1.default.createBoundingRange(this.callee, this.operator, this.methodName, this.openingParen, ...((_a = this.args) !== null && _a !== void 0 ? _a : []), this.closingParen);
|
|
773
798
|
}
|
|
774
799
|
transpile(state) {
|
|
775
800
|
let result = [];
|
|
@@ -796,10 +821,8 @@ class CallfuncExpression extends Expression {
|
|
|
796
821
|
}
|
|
797
822
|
walk(visitor, options) {
|
|
798
823
|
if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
|
|
799
|
-
visitors_1.walk(this, 'callee', visitor, options);
|
|
800
|
-
|
|
801
|
-
visitors_1.walk(this.args, i, visitor, options, this);
|
|
802
|
-
}
|
|
824
|
+
(0, visitors_1.walk)(this, 'callee', visitor, options);
|
|
825
|
+
(0, visitors_1.walkArray)(this.args, visitor, options, this);
|
|
803
826
|
}
|
|
804
827
|
}
|
|
805
828
|
}
|
|
@@ -810,9 +833,10 @@ exports.CallfuncExpression = CallfuncExpression;
|
|
|
810
833
|
*/
|
|
811
834
|
class TemplateStringQuasiExpression extends Expression {
|
|
812
835
|
constructor(expressions) {
|
|
836
|
+
var _a;
|
|
813
837
|
super();
|
|
814
838
|
this.expressions = expressions;
|
|
815
|
-
this.range = util_1.default.
|
|
839
|
+
this.range = util_1.default.createBoundingRange(...((_a = this.expressions) !== null && _a !== void 0 ? _a : []));
|
|
816
840
|
}
|
|
817
841
|
transpile(state, skipEmptyStrings = true) {
|
|
818
842
|
let result = [];
|
|
@@ -830,21 +854,21 @@ class TemplateStringQuasiExpression extends Expression {
|
|
|
830
854
|
}
|
|
831
855
|
walk(visitor, options) {
|
|
832
856
|
if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
|
|
833
|
-
|
|
834
|
-
visitors_1.walk(this.expressions, i, visitor, options, this);
|
|
835
|
-
}
|
|
857
|
+
(0, visitors_1.walkArray)(this.expressions, visitor, options, this);
|
|
836
858
|
}
|
|
837
859
|
}
|
|
838
860
|
}
|
|
839
861
|
exports.TemplateStringQuasiExpression = TemplateStringQuasiExpression;
|
|
840
862
|
class TemplateStringExpression extends Expression {
|
|
841
863
|
constructor(openingBacktick, quasis, expressions, closingBacktick) {
|
|
864
|
+
var _a;
|
|
842
865
|
super();
|
|
843
866
|
this.openingBacktick = openingBacktick;
|
|
844
867
|
this.quasis = quasis;
|
|
845
868
|
this.expressions = expressions;
|
|
846
869
|
this.closingBacktick = closingBacktick;
|
|
847
|
-
|
|
870
|
+
//the expression always starts and ends with a quasi, so we don't need to consider the expression locations
|
|
871
|
+
this.range = util_1.default.createBoundingRange(this.openingBacktick, ...((_a = this.quasis) !== null && _a !== void 0 ? _a : []), this.closingBacktick);
|
|
848
872
|
}
|
|
849
873
|
transpile(state) {
|
|
850
874
|
if (this.quasis.length === 1 && this.expressions.length === 0) {
|
|
@@ -868,8 +892,8 @@ class TemplateStringExpression extends Expression {
|
|
|
868
892
|
add(...quasi.transpile(state));
|
|
869
893
|
if (expression) {
|
|
870
894
|
//skip the toString wrapper around certain expressions
|
|
871
|
-
if (reflection_1.isEscapedCharCodeLiteralExpression(expression) ||
|
|
872
|
-
(reflection_1.isLiteralExpression(expression) && reflection_1.isStringType(expression.type))) {
|
|
895
|
+
if ((0, reflection_1.isEscapedCharCodeLiteralExpression)(expression) ||
|
|
896
|
+
((0, reflection_1.isLiteralExpression)(expression) && (0, reflection_1.isStringType)(expression.type))) {
|
|
873
897
|
add(...expression.transpile(state));
|
|
874
898
|
//wrap all other expressions with a bslib_toString call to prevent runtime type mismatch errors
|
|
875
899
|
}
|
|
@@ -884,10 +908,10 @@ class TemplateStringExpression extends Expression {
|
|
|
884
908
|
if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
|
|
885
909
|
//walk the quasis and expressions in left-to-right order
|
|
886
910
|
for (let i = 0; i < this.quasis.length; i++) {
|
|
887
|
-
visitors_1.walk(this.quasis, i, visitor, options, this);
|
|
911
|
+
(0, visitors_1.walk)(this.quasis, i, visitor, options, this);
|
|
888
912
|
//this skips the final loop iteration since we'll always have one more quasi than expression
|
|
889
913
|
if (this.expressions[i]) {
|
|
890
|
-
visitors_1.walk(this.expressions, i, visitor, options, this);
|
|
914
|
+
(0, visitors_1.walk)(this.expressions, i, visitor, options, this);
|
|
891
915
|
}
|
|
892
916
|
}
|
|
893
917
|
}
|
|
@@ -896,13 +920,15 @@ class TemplateStringExpression extends Expression {
|
|
|
896
920
|
exports.TemplateStringExpression = TemplateStringExpression;
|
|
897
921
|
class TaggedTemplateStringExpression extends Expression {
|
|
898
922
|
constructor(tagName, openingBacktick, quasis, expressions, closingBacktick) {
|
|
923
|
+
var _a;
|
|
899
924
|
super();
|
|
900
925
|
this.tagName = tagName;
|
|
901
926
|
this.openingBacktick = openingBacktick;
|
|
902
927
|
this.quasis = quasis;
|
|
903
928
|
this.expressions = expressions;
|
|
904
929
|
this.closingBacktick = closingBacktick;
|
|
905
|
-
|
|
930
|
+
//the expression always starts and ends with a quasi, so we don't need to consider the expression locations
|
|
931
|
+
this.range = util_1.default.createBoundingRange(this.tagName, this.openingBacktick, ...((_a = this.quasis) !== null && _a !== void 0 ? _a : []), this.closingBacktick);
|
|
906
932
|
}
|
|
907
933
|
transpile(state) {
|
|
908
934
|
let result = [];
|
|
@@ -932,10 +958,10 @@ class TaggedTemplateStringExpression extends Expression {
|
|
|
932
958
|
if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
|
|
933
959
|
//walk the quasis and expressions in left-to-right order
|
|
934
960
|
for (let i = 0; i < this.quasis.length; i++) {
|
|
935
|
-
visitors_1.walk(this.quasis, i, visitor, options, this);
|
|
961
|
+
(0, visitors_1.walk)(this.quasis, i, visitor, options, this);
|
|
936
962
|
//this skips the final loop iteration since we'll always have one more quasi than expression
|
|
937
963
|
if (this.expressions[i]) {
|
|
938
|
-
visitors_1.walk(this.expressions, i, visitor, options, this);
|
|
964
|
+
(0, visitors_1.walk)(this.expressions, i, visitor, options, this);
|
|
939
965
|
}
|
|
940
966
|
}
|
|
941
967
|
}
|
|
@@ -948,7 +974,15 @@ class AnnotationExpression extends Expression {
|
|
|
948
974
|
this.atToken = atToken;
|
|
949
975
|
this.nameToken = nameToken;
|
|
950
976
|
this.name = nameToken.text;
|
|
951
|
-
|
|
977
|
+
}
|
|
978
|
+
get range() {
|
|
979
|
+
return this.cacheRange();
|
|
980
|
+
}
|
|
981
|
+
cacheRange() {
|
|
982
|
+
if (!this._range) {
|
|
983
|
+
this._range = util_1.default.createBoundingRange(this.atToken, this.nameToken, this.call);
|
|
984
|
+
}
|
|
985
|
+
return this._range;
|
|
952
986
|
}
|
|
953
987
|
/**
|
|
954
988
|
* Convert annotation arguments to JavaScript types
|
|
@@ -978,14 +1012,13 @@ class AnnotationExpression extends Expression {
|
|
|
978
1012
|
exports.AnnotationExpression = AnnotationExpression;
|
|
979
1013
|
class TernaryExpression extends Expression {
|
|
980
1014
|
constructor(test, questionMarkToken, consequent, colonToken, alternate) {
|
|
981
|
-
var _a, _b, _c;
|
|
982
1015
|
super();
|
|
983
1016
|
this.test = test;
|
|
984
1017
|
this.questionMarkToken = questionMarkToken;
|
|
985
1018
|
this.consequent = consequent;
|
|
986
1019
|
this.colonToken = colonToken;
|
|
987
1020
|
this.alternate = alternate;
|
|
988
|
-
this.range = util_1.default.
|
|
1021
|
+
this.range = util_1.default.createBoundingRange(this.test, this.questionMarkToken, this.consequent, this.colonToken, this.alternate);
|
|
989
1022
|
}
|
|
990
1023
|
transpile(state) {
|
|
991
1024
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
@@ -1014,21 +1047,20 @@ class TernaryExpression extends Expression {
|
|
|
1014
1047
|
}
|
|
1015
1048
|
walk(visitor, options) {
|
|
1016
1049
|
if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
|
|
1017
|
-
visitors_1.walk(this, 'test', visitor, options);
|
|
1018
|
-
visitors_1.walk(this, 'consequent', visitor, options);
|
|
1019
|
-
visitors_1.walk(this, 'alternate', visitor, options);
|
|
1050
|
+
(0, visitors_1.walk)(this, 'test', visitor, options);
|
|
1051
|
+
(0, visitors_1.walk)(this, 'consequent', visitor, options);
|
|
1052
|
+
(0, visitors_1.walk)(this, 'alternate', visitor, options);
|
|
1020
1053
|
}
|
|
1021
1054
|
}
|
|
1022
1055
|
}
|
|
1023
1056
|
exports.TernaryExpression = TernaryExpression;
|
|
1024
1057
|
class NullCoalescingExpression extends Expression {
|
|
1025
1058
|
constructor(consequent, questionQuestionToken, alternate) {
|
|
1026
|
-
var _a;
|
|
1027
1059
|
super();
|
|
1028
1060
|
this.consequent = consequent;
|
|
1029
1061
|
this.questionQuestionToken = questionQuestionToken;
|
|
1030
1062
|
this.alternate = alternate;
|
|
1031
|
-
this.range = util_1.default.
|
|
1063
|
+
this.range = util_1.default.createBoundingRange(this.consequent, this.questionQuestionToken, this.alternate);
|
|
1032
1064
|
}
|
|
1033
1065
|
transpile(state) {
|
|
1034
1066
|
let result = [];
|
|
@@ -1039,7 +1071,7 @@ class NullCoalescingExpression extends Expression {
|
|
|
1039
1071
|
let hasMutatingExpression = [
|
|
1040
1072
|
...consequentInfo.expressions,
|
|
1041
1073
|
...alternateInfo.expressions
|
|
1042
|
-
].find(e => reflection_1.isCallExpression(e) || reflection_1.isCallfuncExpression(e) || reflection_1.isDottedGetExpression(e));
|
|
1074
|
+
].find(e => (0, reflection_1.isCallExpression)(e) || (0, reflection_1.isCallfuncExpression)(e) || (0, reflection_1.isDottedGetExpression)(e));
|
|
1043
1075
|
if (hasMutatingExpression) {
|
|
1044
1076
|
result.push(`(function(`,
|
|
1045
1077
|
//write all the scope variables as parameters.
|
|
@@ -1058,37 +1090,175 @@ class NullCoalescingExpression extends Expression {
|
|
|
1058
1090
|
}
|
|
1059
1091
|
walk(visitor, options) {
|
|
1060
1092
|
if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
|
|
1061
|
-
visitors_1.walk(this, 'consequent', visitor, options);
|
|
1062
|
-
visitors_1.walk(this, 'alternate', visitor, options);
|
|
1093
|
+
(0, visitors_1.walk)(this, 'consequent', visitor, options);
|
|
1094
|
+
(0, visitors_1.walk)(this, 'alternate', visitor, options);
|
|
1063
1095
|
}
|
|
1064
1096
|
}
|
|
1065
1097
|
}
|
|
1066
1098
|
exports.NullCoalescingExpression = NullCoalescingExpression;
|
|
1099
|
+
class RegexLiteralExpression extends Expression {
|
|
1100
|
+
constructor(tokens) {
|
|
1101
|
+
super();
|
|
1102
|
+
this.tokens = tokens;
|
|
1103
|
+
this.range = this.tokens.regexLiteral.range;
|
|
1104
|
+
}
|
|
1105
|
+
transpile(state) {
|
|
1106
|
+
var _a, _b;
|
|
1107
|
+
let text = (_b = (_a = this.tokens.regexLiteral) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : '';
|
|
1108
|
+
let flags = '';
|
|
1109
|
+
//get any flags from the end
|
|
1110
|
+
const flagMatch = /\/([a-z]+)$/i.exec(text);
|
|
1111
|
+
if (flagMatch) {
|
|
1112
|
+
text = text.substring(0, flagMatch.index + 1);
|
|
1113
|
+
flags = flagMatch[1];
|
|
1114
|
+
}
|
|
1115
|
+
let pattern = text
|
|
1116
|
+
//remove leading and trailing slashes
|
|
1117
|
+
.substring(1, text.length - 1)
|
|
1118
|
+
//escape quotemarks
|
|
1119
|
+
.split('"').join('" + chr(34) + "');
|
|
1120
|
+
return [
|
|
1121
|
+
state.sourceNode(this.tokens.regexLiteral, [
|
|
1122
|
+
'CreateObject("roRegex", ',
|
|
1123
|
+
`"${pattern}", `,
|
|
1124
|
+
`"${flags}"`,
|
|
1125
|
+
')'
|
|
1126
|
+
])
|
|
1127
|
+
];
|
|
1128
|
+
}
|
|
1129
|
+
walk(visitor, options) {
|
|
1130
|
+
//nothing to walk
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
exports.RegexLiteralExpression = RegexLiteralExpression;
|
|
1134
|
+
class TypeExpression extends Expression {
|
|
1135
|
+
constructor(tokens, namespaceName) {
|
|
1136
|
+
super();
|
|
1137
|
+
this.tokens = tokens;
|
|
1138
|
+
this.namespaceName = namespaceName;
|
|
1139
|
+
this.range = util_1.default.createBoundingRange(this.tokens.type);
|
|
1140
|
+
}
|
|
1141
|
+
/**
|
|
1142
|
+
* The this TypeExpression refers to
|
|
1143
|
+
*/
|
|
1144
|
+
get type() {
|
|
1145
|
+
if (this._type) {
|
|
1146
|
+
return this._type;
|
|
1147
|
+
}
|
|
1148
|
+
this._type = this.getType(Parser_1.ParseMode.BrighterScript);
|
|
1149
|
+
return this._type;
|
|
1150
|
+
}
|
|
1151
|
+
/**
|
|
1152
|
+
* Derive a BscType from the type token
|
|
1153
|
+
* Can deal with multiple brackets to make multidimensional arrays, eg. float[][]
|
|
1154
|
+
* Defaults to `DynamicType`
|
|
1155
|
+
*/
|
|
1156
|
+
getType(parseMode = Parser_1.ParseMode.BrighterScript) {
|
|
1157
|
+
let exprType = this.tokens.type
|
|
1158
|
+
? util_1.default.tokenToBscType(this.tokens.type, parseMode === Parser_1.ParseMode.BrighterScript, this.namespaceName)
|
|
1159
|
+
: new DynamicType_1.DynamicType();
|
|
1160
|
+
return exprType;
|
|
1161
|
+
}
|
|
1162
|
+
/**
|
|
1163
|
+
* Is this a valid, (eg. known) type?
|
|
1164
|
+
*/
|
|
1165
|
+
isValidType(parseMode = Parser_1.ParseMode.BrighterScript) {
|
|
1166
|
+
return !!util_1.default.tokenToBscType(this.tokens.type, parseMode === Parser_1.ParseMode.BrighterScript, this.namespaceName);
|
|
1167
|
+
}
|
|
1168
|
+
/**
|
|
1169
|
+
* Gives a human readable string that says the type
|
|
1170
|
+
* @returns text to display to show the type
|
|
1171
|
+
*/
|
|
1172
|
+
getText() {
|
|
1173
|
+
let result = this.tokens.type.text;
|
|
1174
|
+
return result;
|
|
1175
|
+
}
|
|
1176
|
+
transpile(state) {
|
|
1177
|
+
let result = [];
|
|
1178
|
+
//type declaration
|
|
1179
|
+
result.push(state.sourceNode({ range: this.range }, this.type.toTypeString(state.typeContext)));
|
|
1180
|
+
return result;
|
|
1181
|
+
}
|
|
1182
|
+
walk(visitor, options) {
|
|
1183
|
+
//nothing to walk
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
exports.TypeExpression = TypeExpression;
|
|
1187
|
+
class ArrayTypeExpression extends TypeExpression {
|
|
1188
|
+
constructor(innerTypes, // this is an array so that in the future when we support union types
|
|
1189
|
+
bracketTokens, namespaceName) {
|
|
1190
|
+
super({}, namespaceName);
|
|
1191
|
+
this.innerTypes = innerTypes;
|
|
1192
|
+
this.bracketTokens = bracketTokens;
|
|
1193
|
+
this.namespaceName = namespaceName;
|
|
1194
|
+
this.range = util_1.default.createBoundingRange(this.bracketTokens.leftBracket, this.bracketTokens.rightBracket, ...this.innerTypes);
|
|
1195
|
+
}
|
|
1196
|
+
/*
|
|
1197
|
+
* TODO - Support union types
|
|
1198
|
+
*/
|
|
1199
|
+
get defaultTypeExpression() {
|
|
1200
|
+
return this.innerTypes[0];
|
|
1201
|
+
}
|
|
1202
|
+
/**
|
|
1203
|
+
* Derive a BscType from the type token
|
|
1204
|
+
* Returns an array type with the inner types based on the inner type expressions
|
|
1205
|
+
*/
|
|
1206
|
+
getType(parseMode = Parser_1.ParseMode.BrighterScript) {
|
|
1207
|
+
const innerBscTypes = this.innerTypes.map(inner => inner.getType(parseMode));
|
|
1208
|
+
return new ArrayType_1.ArrayType(...innerBscTypes);
|
|
1209
|
+
}
|
|
1210
|
+
/**
|
|
1211
|
+
* Is this a valid, (eg. known) type?
|
|
1212
|
+
*/
|
|
1213
|
+
isValidType(parseMode = Parser_1.ParseMode.BrighterScript) {
|
|
1214
|
+
if (parseMode === Parser_1.ParseMode.BrighterScript) {
|
|
1215
|
+
return this.innerTypes.reduce((validSoFar, innerType) => {
|
|
1216
|
+
return validSoFar && innerType.isValidType(parseMode);
|
|
1217
|
+
}, true);
|
|
1218
|
+
}
|
|
1219
|
+
return false;
|
|
1220
|
+
}
|
|
1221
|
+
/**
|
|
1222
|
+
* Gives a human readable string that says the type
|
|
1223
|
+
* @returns text to display to show the type
|
|
1224
|
+
*/
|
|
1225
|
+
getText() {
|
|
1226
|
+
return this.defaultTypeExpression.getText() + '[]';
|
|
1227
|
+
}
|
|
1228
|
+
walk(visitor, options) {
|
|
1229
|
+
if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
|
|
1230
|
+
for (let i = 0; i < this.innerTypes.length; i++) {
|
|
1231
|
+
(0, visitors_1.walk)(this.innerTypes, i, visitor, options, this);
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
exports.ArrayTypeExpression = ArrayTypeExpression;
|
|
1067
1237
|
function expressionToValue(expr, strict) {
|
|
1068
1238
|
if (!expr) {
|
|
1069
1239
|
return null;
|
|
1070
1240
|
}
|
|
1071
|
-
if (reflection_1.isUnaryExpression(expr) && reflection_1.isLiteralNumber(expr.right)) {
|
|
1241
|
+
if ((0, reflection_1.isUnaryExpression)(expr) && (0, reflection_1.isLiteralNumber)(expr.right)) {
|
|
1072
1242
|
return numberExpressionToValue(expr.right, expr.operator.text);
|
|
1073
1243
|
}
|
|
1074
|
-
if (reflection_1.isLiteralString(expr)) {
|
|
1244
|
+
if ((0, reflection_1.isLiteralString)(expr)) {
|
|
1075
1245
|
//remove leading and trailing quotes
|
|
1076
1246
|
return expr.token.text.replace(/^"/, '').replace(/"$/, '');
|
|
1077
1247
|
}
|
|
1078
|
-
if (reflection_1.isLiteralNumber(expr)) {
|
|
1248
|
+
if ((0, reflection_1.isLiteralNumber)(expr)) {
|
|
1079
1249
|
return numberExpressionToValue(expr);
|
|
1080
1250
|
}
|
|
1081
|
-
if (reflection_1.isLiteralBoolean(expr)) {
|
|
1251
|
+
if ((0, reflection_1.isLiteralBoolean)(expr)) {
|
|
1082
1252
|
return expr.token.text.toLowerCase() === 'true';
|
|
1083
1253
|
}
|
|
1084
|
-
if (reflection_1.isArrayLiteralExpression(expr)) {
|
|
1254
|
+
if ((0, reflection_1.isArrayLiteralExpression)(expr)) {
|
|
1085
1255
|
return expr.elements
|
|
1086
|
-
.filter(e => !reflection_1.isCommentStatement(e))
|
|
1256
|
+
.filter(e => !(0, reflection_1.isCommentStatement)(e))
|
|
1087
1257
|
.map(e => expressionToValue(e, strict));
|
|
1088
1258
|
}
|
|
1089
|
-
if (reflection_1.isAALiteralExpression(expr)) {
|
|
1259
|
+
if ((0, reflection_1.isAALiteralExpression)(expr)) {
|
|
1090
1260
|
return expr.elements.reduce((acc, e) => {
|
|
1091
|
-
if (!reflection_1.isCommentStatement(e)) {
|
|
1261
|
+
if (!(0, reflection_1.isCommentStatement)(e)) {
|
|
1092
1262
|
acc[e.keyToken.text] = expressionToValue(e.value, strict);
|
|
1093
1263
|
}
|
|
1094
1264
|
return acc;
|
|
@@ -1097,7 +1267,7 @@ function expressionToValue(expr, strict) {
|
|
|
1097
1267
|
return strict ? null : expr;
|
|
1098
1268
|
}
|
|
1099
1269
|
function numberExpressionToValue(expr, operator = '') {
|
|
1100
|
-
if (reflection_1.isIntegerType(expr.type) || reflection_1.isLongIntegerType(expr.type)) {
|
|
1270
|
+
if ((0, reflection_1.isIntegerType)(expr.type) || (0, reflection_1.isLongIntegerType)(expr.type)) {
|
|
1101
1271
|
return parseInt(operator + expr.token.text);
|
|
1102
1272
|
}
|
|
1103
1273
|
else {
|