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