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
package/dist/util.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.util = exports.standardizePath = exports.Util = void 0;
|
|
3
|
+
exports.MAX_PARAM_COUNT = exports.util = exports.standardizePath = exports.Util = void 0;
|
|
4
4
|
const fs = require("fs");
|
|
5
5
|
const fsExtra = require("fs-extra");
|
|
6
6
|
const jsonc_parser_1 = require("jsonc-parser");
|
|
@@ -13,7 +13,7 @@ const BooleanType_1 = require("./types/BooleanType");
|
|
|
13
13
|
const DoubleType_1 = require("./types/DoubleType");
|
|
14
14
|
const DynamicType_1 = require("./types/DynamicType");
|
|
15
15
|
const FloatType_1 = require("./types/FloatType");
|
|
16
|
-
const
|
|
16
|
+
const TypedFunctionType_1 = require("./types/TypedFunctionType");
|
|
17
17
|
const IntegerType_1 = require("./types/IntegerType");
|
|
18
18
|
const InvalidType_1 = require("./types/InvalidType");
|
|
19
19
|
const LongIntegerType_1 = require("./types/LongIntegerType");
|
|
@@ -22,10 +22,13 @@ const StringType_1 = require("./types/StringType");
|
|
|
22
22
|
const VoidType_1 = require("./types/VoidType");
|
|
23
23
|
const Parser_1 = require("./parser/Parser");
|
|
24
24
|
const Logger_1 = require("./Logger");
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
const
|
|
25
|
+
const TokenKind_1 = require("./lexer/TokenKind");
|
|
26
|
+
const reflection_1 = require("./astUtils/reflection");
|
|
27
|
+
const visitors_1 = require("./astUtils/visitors");
|
|
28
28
|
const source_map_1 = require("source-map");
|
|
29
|
+
const SGTypes_1 = require("./parser/SGTypes");
|
|
30
|
+
const LazyType_1 = require("./types/LazyType");
|
|
31
|
+
const FunctionType_1 = require("./types/FunctionType");
|
|
29
32
|
class Util {
|
|
30
33
|
clearConsole() {
|
|
31
34
|
// process.stdout.write('\x1Bc');
|
|
@@ -125,7 +128,7 @@ class Util {
|
|
|
125
128
|
colIndex++;
|
|
126
129
|
}
|
|
127
130
|
}
|
|
128
|
-
return
|
|
131
|
+
return this.createRange(lineIndex, colIndex, lineIndex, colIndex + length);
|
|
129
132
|
}
|
|
130
133
|
/**
|
|
131
134
|
* Load the contents of a config file.
|
|
@@ -154,16 +157,19 @@ class Util {
|
|
|
154
157
|
//load the project file
|
|
155
158
|
let projectFileContents = fsExtra.readFileSync(configFilePath).toString();
|
|
156
159
|
let parseErrors = [];
|
|
157
|
-
let projectConfig = jsonc_parser_1.parse(projectFileContents, parseErrors);
|
|
160
|
+
let projectConfig = (0, jsonc_parser_1.parse)(projectFileContents, parseErrors);
|
|
158
161
|
if (parseErrors.length > 0) {
|
|
159
162
|
let err = parseErrors[0];
|
|
160
|
-
let diagnostic = Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.bsConfigJsonHasSyntaxErrors(jsonc_parser_1.printParseErrorCode(parseErrors[0].error))), { file: {
|
|
163
|
+
let diagnostic = Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.bsConfigJsonHasSyntaxErrors((0, jsonc_parser_1.printParseErrorCode)(parseErrors[0].error))), { file: {
|
|
161
164
|
srcPath: configFilePath
|
|
162
165
|
}, range: this.getRangeFromOffsetLength(projectFileContents, err.offset, err.length) });
|
|
163
166
|
throw diagnostic; //eslint-disable-line @typescript-eslint/no-throw-literal
|
|
164
167
|
}
|
|
165
|
-
this.resolvePluginPaths(projectConfig, configFilePath);
|
|
166
168
|
let projectFileCwd = path.dirname(configFilePath);
|
|
169
|
+
//`plugins` paths should be relative to the current bsconfig
|
|
170
|
+
this.resolvePathsRelativeTo(projectConfig, 'plugins', projectFileCwd);
|
|
171
|
+
//`require` paths should be relative to cwd
|
|
172
|
+
exports.util.resolvePathsRelativeTo(projectConfig, 'require', projectFileCwd);
|
|
167
173
|
let result;
|
|
168
174
|
//if the project has a base file, load it
|
|
169
175
|
if (projectConfig && typeof projectConfig.extends === 'string') {
|
|
@@ -191,26 +197,22 @@ class Util {
|
|
|
191
197
|
}
|
|
192
198
|
}
|
|
193
199
|
/**
|
|
194
|
-
*
|
|
195
|
-
* and
|
|
196
|
-
* @param
|
|
197
|
-
* @param configFilePath Path of the configuration file
|
|
200
|
+
* Convert relative paths to absolute paths, relative to the given directory. Also de-dupes the paths. Modifies the array in-place
|
|
201
|
+
* @param paths the list of paths to be resolved and deduped
|
|
202
|
+
* @param relativeDir the path to the folder where the paths should be resolved relative to. This should be an absolute path
|
|
198
203
|
*/
|
|
199
|
-
|
|
204
|
+
resolvePathsRelativeTo(collection, key, relativeDir) {
|
|
200
205
|
var _a;
|
|
201
|
-
if (
|
|
202
|
-
|
|
203
|
-
const exists = {};
|
|
204
|
-
config.plugins = config.plugins.map(p => {
|
|
205
|
-
return (p === null || p === void 0 ? void 0 : p.startsWith('.')) ? path.resolve(relPath, p) : p;
|
|
206
|
-
}).filter(p => {
|
|
207
|
-
if (!p || exists[p]) {
|
|
208
|
-
return false;
|
|
209
|
-
}
|
|
210
|
-
exists[p] = true;
|
|
211
|
-
return true;
|
|
212
|
-
});
|
|
206
|
+
if (!collection[key]) {
|
|
207
|
+
return;
|
|
213
208
|
}
|
|
209
|
+
const result = new Set();
|
|
210
|
+
for (const p of (_a = collection[key]) !== null && _a !== void 0 ? _a : []) {
|
|
211
|
+
if (p) {
|
|
212
|
+
result.add((p === null || p === void 0 ? void 0 : p.startsWith('.')) ? path.resolve(relativeDir, p) : p);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
collection[key] = [...result];
|
|
214
216
|
}
|
|
215
217
|
/**
|
|
216
218
|
* Do work within the scope of a changed current working directory
|
|
@@ -424,10 +426,10 @@ class Util {
|
|
|
424
426
|
findBeginningVariableExpression(dottedGet) {
|
|
425
427
|
let left = dottedGet;
|
|
426
428
|
while (left) {
|
|
427
|
-
if (
|
|
429
|
+
if ((0, reflection_1.isVariableExpression)(left)) {
|
|
428
430
|
return left;
|
|
429
431
|
}
|
|
430
|
-
else if (
|
|
432
|
+
else if ((0, reflection_1.isDottedGetExpression)(left)) {
|
|
431
433
|
left = left.obj;
|
|
432
434
|
}
|
|
433
435
|
else {
|
|
@@ -598,11 +600,12 @@ class Util {
|
|
|
598
600
|
*/
|
|
599
601
|
diagnosticIsSuppressed(diagnostic) {
|
|
600
602
|
var _a, _b;
|
|
603
|
+
const diagnosticCode = typeof diagnostic.code === 'string' ? diagnostic.code.toLowerCase() : diagnostic.code;
|
|
601
604
|
for (let flag of (_b = (_a = diagnostic.file) === null || _a === void 0 ? void 0 : _a.commentFlags) !== null && _b !== void 0 ? _b : []) {
|
|
602
605
|
//this diagnostic is affected by this flag
|
|
603
606
|
if (this.rangeContains(flag.affectedRange, diagnostic.range.start)) {
|
|
604
607
|
//if the flag acts upon this diagnostic's code
|
|
605
|
-
if (flag.codes === null || flag.codes.includes(
|
|
608
|
+
if (flag.codes === null || flag.codes.includes(diagnosticCode)) {
|
|
606
609
|
return true;
|
|
607
610
|
}
|
|
608
611
|
}
|
|
@@ -807,6 +810,40 @@ class Util {
|
|
|
807
810
|
}
|
|
808
811
|
};
|
|
809
812
|
}
|
|
813
|
+
/**
|
|
814
|
+
* Given a list of ranges, create a range that starts with the first non-null lefthand range, and ends with the first non-null
|
|
815
|
+
* righthand range. Returns undefined if none of the items have a range.
|
|
816
|
+
*/
|
|
817
|
+
createBoundingRange(...locatables) {
|
|
818
|
+
let leftmostRange;
|
|
819
|
+
let rightmostRange;
|
|
820
|
+
for (let i = 0; i < locatables.length; i++) {
|
|
821
|
+
//set the leftmost non-null-range item
|
|
822
|
+
const left = locatables[i];
|
|
823
|
+
//the range might be a getter, so access it exactly once
|
|
824
|
+
const leftRange = left === null || left === void 0 ? void 0 : left.range;
|
|
825
|
+
if (!leftmostRange && leftRange) {
|
|
826
|
+
leftmostRange = leftRange;
|
|
827
|
+
}
|
|
828
|
+
//set the rightmost non-null-range item
|
|
829
|
+
const right = locatables[locatables.length - 1 - i];
|
|
830
|
+
//the range might be a getter, so access it exactly once
|
|
831
|
+
const rightRange = right === null || right === void 0 ? void 0 : right.range;
|
|
832
|
+
if (!rightmostRange && rightRange) {
|
|
833
|
+
rightmostRange = rightRange;
|
|
834
|
+
}
|
|
835
|
+
//if we have both sides, quit
|
|
836
|
+
if (leftmostRange && rightmostRange) {
|
|
837
|
+
break;
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
if (leftmostRange) {
|
|
841
|
+
return this.createRangeFromPositions(leftmostRange.start, rightmostRange.end);
|
|
842
|
+
}
|
|
843
|
+
else {
|
|
844
|
+
return undefined;
|
|
845
|
+
}
|
|
846
|
+
}
|
|
810
847
|
/**
|
|
811
848
|
* Create a `Position` object. Prefer this over `Position.create` for performance reasons
|
|
812
849
|
*/
|
|
@@ -831,71 +868,95 @@ class Util {
|
|
|
831
868
|
/**
|
|
832
869
|
* Convert a token into a BscType
|
|
833
870
|
*/
|
|
834
|
-
tokenToBscType(token,
|
|
871
|
+
tokenToBscType(token, allowBrighterscriptTypes = true, currentNamespaceName) {
|
|
835
872
|
if (!token) {
|
|
836
873
|
return new DynamicType_1.DynamicType();
|
|
837
874
|
}
|
|
838
875
|
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
839
876
|
switch (token.kind) {
|
|
840
|
-
case
|
|
841
|
-
|
|
842
|
-
case
|
|
877
|
+
case TokenKind_1.TokenKind.Boolean:
|
|
878
|
+
return new BooleanType_1.BooleanType(token.text);
|
|
879
|
+
case TokenKind_1.TokenKind.True:
|
|
880
|
+
case TokenKind_1.TokenKind.False:
|
|
843
881
|
return new BooleanType_1.BooleanType();
|
|
844
|
-
case
|
|
845
|
-
|
|
882
|
+
case TokenKind_1.TokenKind.Double:
|
|
883
|
+
return new DoubleType_1.DoubleType(token.text);
|
|
884
|
+
case TokenKind_1.TokenKind.DoubleLiteral:
|
|
846
885
|
return new DoubleType_1.DoubleType();
|
|
847
|
-
case
|
|
848
|
-
return new DynamicType_1.DynamicType();
|
|
849
|
-
case
|
|
850
|
-
|
|
886
|
+
case TokenKind_1.TokenKind.Dynamic:
|
|
887
|
+
return new DynamicType_1.DynamicType(token.text);
|
|
888
|
+
case TokenKind_1.TokenKind.Float:
|
|
889
|
+
return new FloatType_1.FloatType(token.text);
|
|
890
|
+
case TokenKind_1.TokenKind.FloatLiteral:
|
|
851
891
|
return new FloatType_1.FloatType();
|
|
852
|
-
case
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
case
|
|
892
|
+
case TokenKind_1.TokenKind.Function:
|
|
893
|
+
return new FunctionType_1.FunctionType();
|
|
894
|
+
case TokenKind_1.TokenKind.Integer:
|
|
895
|
+
return new IntegerType_1.IntegerType(token.text);
|
|
896
|
+
case TokenKind_1.TokenKind.IntegerLiteral:
|
|
857
897
|
return new IntegerType_1.IntegerType();
|
|
858
|
-
case
|
|
859
|
-
return new InvalidType_1.InvalidType();
|
|
860
|
-
case
|
|
861
|
-
|
|
898
|
+
case TokenKind_1.TokenKind.Invalid:
|
|
899
|
+
return new InvalidType_1.InvalidType(token.text);
|
|
900
|
+
case TokenKind_1.TokenKind.LongInteger:
|
|
901
|
+
return new LongIntegerType_1.LongIntegerType(token.text);
|
|
902
|
+
case TokenKind_1.TokenKind.LongIntegerLiteral:
|
|
862
903
|
return new LongIntegerType_1.LongIntegerType();
|
|
863
|
-
case
|
|
864
|
-
return new ObjectType_1.ObjectType();
|
|
865
|
-
case
|
|
866
|
-
|
|
867
|
-
case
|
|
868
|
-
case
|
|
869
|
-
case
|
|
904
|
+
case TokenKind_1.TokenKind.Object:
|
|
905
|
+
return new ObjectType_1.ObjectType(token.text);
|
|
906
|
+
case TokenKind_1.TokenKind.String:
|
|
907
|
+
return new StringType_1.StringType(token.text);
|
|
908
|
+
case TokenKind_1.TokenKind.StringLiteral:
|
|
909
|
+
case TokenKind_1.TokenKind.TemplateStringExpressionBegin:
|
|
910
|
+
case TokenKind_1.TokenKind.TemplateStringExpressionEnd:
|
|
911
|
+
case TokenKind_1.TokenKind.TemplateStringQuasi:
|
|
870
912
|
return new StringType_1.StringType();
|
|
871
|
-
case
|
|
872
|
-
return new VoidType_1.VoidType();
|
|
873
|
-
case
|
|
874
|
-
|
|
913
|
+
case TokenKind_1.TokenKind.Void:
|
|
914
|
+
return new VoidType_1.VoidType(token.text);
|
|
915
|
+
case TokenKind_1.TokenKind.Identifier:
|
|
916
|
+
let typeText = token.text.trim().toLowerCase();
|
|
917
|
+
let typeClass;
|
|
918
|
+
switch (typeText) {
|
|
875
919
|
case 'boolean':
|
|
876
|
-
|
|
920
|
+
typeClass = new BooleanType_1.BooleanType(token.text);
|
|
921
|
+
break;
|
|
877
922
|
case 'double':
|
|
878
|
-
|
|
923
|
+
typeClass = new DoubleType_1.DoubleType(token.text);
|
|
924
|
+
break;
|
|
879
925
|
case 'float':
|
|
880
|
-
|
|
926
|
+
typeClass = new FloatType_1.FloatType(token.text);
|
|
927
|
+
break;
|
|
881
928
|
case 'function':
|
|
882
|
-
|
|
929
|
+
typeClass = new TypedFunctionType_1.TypedFunctionType(new DynamicType_1.DynamicType(token.text));
|
|
930
|
+
break;
|
|
883
931
|
case 'integer':
|
|
884
|
-
|
|
932
|
+
typeClass = new IntegerType_1.IntegerType(token.text);
|
|
933
|
+
break;
|
|
885
934
|
case 'invalid':
|
|
886
|
-
|
|
935
|
+
typeClass = new InvalidType_1.InvalidType(token.text);
|
|
936
|
+
break;
|
|
887
937
|
case 'longinteger':
|
|
888
|
-
|
|
938
|
+
typeClass = new LongIntegerType_1.LongIntegerType(token.text);
|
|
939
|
+
break;
|
|
889
940
|
case 'object':
|
|
890
|
-
|
|
941
|
+
typeClass = new ObjectType_1.ObjectType(token.text);
|
|
942
|
+
break;
|
|
891
943
|
case 'string':
|
|
892
|
-
|
|
944
|
+
typeClass = new StringType_1.StringType(token.text);
|
|
945
|
+
break;
|
|
893
946
|
case 'void':
|
|
894
|
-
|
|
947
|
+
typeClass = new VoidType_1.VoidType(token.text);
|
|
948
|
+
break;
|
|
949
|
+
case 'dynamic':
|
|
950
|
+
typeClass = new DynamicType_1.DynamicType(token.text);
|
|
951
|
+
break;
|
|
895
952
|
}
|
|
896
|
-
if (
|
|
897
|
-
|
|
953
|
+
if (!typeClass && allowBrighterscriptTypes) {
|
|
954
|
+
typeClass = new LazyType_1.LazyType((context) => {
|
|
955
|
+
var _a, _b;
|
|
956
|
+
return (_b = (_a = context === null || context === void 0 ? void 0 : context.scope) === null || _a === void 0 ? void 0 : _a.getNamedTypeStatement(typeText, currentNamespaceName === null || currentNamespaceName === void 0 ? void 0 : currentNamespaceName.getName())) === null || _b === void 0 ? void 0 : _b.getThisBscType();
|
|
957
|
+
});
|
|
898
958
|
}
|
|
959
|
+
return typeClass;
|
|
899
960
|
}
|
|
900
961
|
}
|
|
901
962
|
/**
|
|
@@ -976,19 +1037,22 @@ class Util {
|
|
|
976
1037
|
const expressions = [expression];
|
|
977
1038
|
const variableExpressions = [];
|
|
978
1039
|
const uniqueVarNames = new Set();
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
expression === null || expression === void 0 ? void 0 : expression.walk((expression) => {
|
|
982
|
-
if (astUtils_1.isExpression(expression)) {
|
|
1040
|
+
function expressionWalker(expression) {
|
|
1041
|
+
if ((0, reflection_1.isExpression)(expression)) {
|
|
983
1042
|
expressions.push(expression);
|
|
984
1043
|
}
|
|
985
|
-
if (
|
|
1044
|
+
if ((0, reflection_1.isVariableExpression)(expression)) {
|
|
986
1045
|
variableExpressions.push(expression);
|
|
987
1046
|
uniqueVarNames.add(expression.name.text);
|
|
988
1047
|
}
|
|
989
|
-
}
|
|
990
|
-
|
|
1048
|
+
}
|
|
1049
|
+
// Collect all expressions. Most of these expressions are fairly small so this should be quick!
|
|
1050
|
+
// This should only be called during transpile time and only when we actually need it.
|
|
1051
|
+
expression === null || expression === void 0 ? void 0 : expression.walk(expressionWalker, {
|
|
1052
|
+
walkMode: visitors_1.WalkMode.visitExpressions
|
|
991
1053
|
});
|
|
1054
|
+
//handle the expression itself (for situations when expression is a VariableExpression)
|
|
1055
|
+
expressionWalker(expression);
|
|
992
1056
|
return { expressions: expressions, varExpressions: variableExpressions, uniqueVarNames: [...uniqueVarNames] };
|
|
993
1057
|
}
|
|
994
1058
|
/**
|
|
@@ -1006,20 +1070,25 @@ class Util {
|
|
|
1006
1070
|
return new source_map_1.SourceNode(null, null, source, chunks);
|
|
1007
1071
|
}
|
|
1008
1072
|
/**
|
|
1009
|
-
* Creates a new SGAttribute object, but keeps the existing Range references (since those
|
|
1073
|
+
* Creates a new SGAttribute object, but keeps the existing Range references (since those should be immutable)
|
|
1010
1074
|
*/
|
|
1011
1075
|
cloneSGAttribute(attr, value) {
|
|
1012
|
-
return {
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1076
|
+
return new SGTypes_1.SGAttribute({ text: attr.tokens.key.text, range: attr.range }, { text: '=' }, { text: '"' }, { text: value, range: attr.tokens.value.range }, { text: '"' });
|
|
1077
|
+
}
|
|
1078
|
+
/**
|
|
1079
|
+
* Shorthand for creating a new source node
|
|
1080
|
+
*/
|
|
1081
|
+
sourceNode(source, locatable, code) {
|
|
1082
|
+
if (code !== undefined) {
|
|
1083
|
+
const node = new source_map_1.SourceNode(null, null, source, code);
|
|
1084
|
+
if (locatable.range) {
|
|
1085
|
+
//convert 0-based Range line to 1-based SourceNode line
|
|
1086
|
+
node.line = locatable.range.start.line + 1;
|
|
1087
|
+
//SourceNode columns are 0-based so no conversion necessary
|
|
1088
|
+
node.column = locatable.range.start.character;
|
|
1089
|
+
}
|
|
1090
|
+
return node;
|
|
1091
|
+
}
|
|
1023
1092
|
}
|
|
1024
1093
|
/**
|
|
1025
1094
|
* Remove leading simple protocols from a path (if present)
|
|
@@ -1033,10 +1102,13 @@ class Util {
|
|
|
1033
1102
|
return pkgPath;
|
|
1034
1103
|
}
|
|
1035
1104
|
}
|
|
1105
|
+
/**
|
|
1106
|
+
* Converts a path into a standardized format (drive letter to lower, remove extra slashes, use single slash type, resolve relative parts, etc...)
|
|
1107
|
+
*/
|
|
1036
1108
|
standardizePath(thePath) {
|
|
1037
1109
|
return exports.util.driveLetterToLower(rokuDeploy.standardizePath(thePath));
|
|
1038
1110
|
}
|
|
1039
|
-
|
|
1111
|
+
/**
|
|
1040
1112
|
* Copy the version of bslib from local node_modules to the staging folder
|
|
1041
1113
|
*/
|
|
1042
1114
|
async copyBslibToStaging(stagingDir) {
|
|
@@ -1077,13 +1149,60 @@ class Util {
|
|
|
1077
1149
|
};
|
|
1078
1150
|
}
|
|
1079
1151
|
/**
|
|
1080
|
-
*
|
|
1152
|
+
* Gets the minimum and maximum number of allowed params
|
|
1153
|
+
* @param params The list of callable parameters to check
|
|
1154
|
+
* @returns the minimum and maximum number of allowed params
|
|
1155
|
+
*/
|
|
1156
|
+
getMinMaxParamCount(params) {
|
|
1157
|
+
//get min/max parameter count for callable
|
|
1158
|
+
let minParams = 0;
|
|
1159
|
+
let maxParams = 0;
|
|
1160
|
+
let continueCheckingForRequired = true;
|
|
1161
|
+
for (let param of params) {
|
|
1162
|
+
maxParams++;
|
|
1163
|
+
//optional parameters must come last, so we can assume that minParams won't increase once we hit
|
|
1164
|
+
//the first isOptional
|
|
1165
|
+
if (continueCheckingForRequired && !param.isOptional) {
|
|
1166
|
+
minParams++;
|
|
1167
|
+
}
|
|
1168
|
+
else {
|
|
1169
|
+
continueCheckingForRequired = false;
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
return { min: minParams, max: maxParams };
|
|
1173
|
+
}
|
|
1174
|
+
/**
|
|
1175
|
+
* Gets the minimum and maximum number of allowed params for ALL functions with the name of the function call
|
|
1176
|
+
* @param callablesByLowerName The map of callable containers
|
|
1177
|
+
* @param expCall function call expression to use for the name
|
|
1178
|
+
* @returns the minimum and maximum number of allowed params
|
|
1179
|
+
*/
|
|
1180
|
+
getMinMaxParamCountByFunctionCall(callablesByLowerName, expCall) {
|
|
1181
|
+
const callablesWithThisName = this.getCallableContainersByName(callablesByLowerName, expCall);
|
|
1182
|
+
if ((callablesWithThisName === null || callablesWithThisName === void 0 ? void 0 : callablesWithThisName.length) > 0) {
|
|
1183
|
+
const paramCount = { min: exports.MAX_PARAM_COUNT, max: 0 };
|
|
1184
|
+
for (const callableContainer of callablesWithThisName) {
|
|
1185
|
+
let specificParamCount = exports.util.getMinMaxParamCount(callableContainer.callable.params);
|
|
1186
|
+
if (specificParamCount.max > paramCount.max) {
|
|
1187
|
+
paramCount.max = specificParamCount.max;
|
|
1188
|
+
}
|
|
1189
|
+
if (specificParamCount.min < paramCount.min) {
|
|
1190
|
+
paramCount.min = specificParamCount.min;
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
return paramCount;
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
/**
|
|
1197
|
+
* Finds the array of callables from a container map, based on the name of the function call
|
|
1081
1198
|
* If the callable was called in a function in a namespace, functions in that namespace are preferred
|
|
1199
|
+
* @param callablesByLowerName The map of callable containers
|
|
1200
|
+
* @param expCall function call expression to use for the name
|
|
1082
1201
|
* @return an array with callable containers - could be empty if nothing was found
|
|
1083
1202
|
*/
|
|
1084
|
-
|
|
1203
|
+
getCallableContainersByName(callablesByLowerName, expCall) {
|
|
1085
1204
|
let callablesWithThisName = [];
|
|
1086
|
-
const lowerName = expCall.name.toLowerCase();
|
|
1205
|
+
const lowerName = expCall.name.text.toLowerCase();
|
|
1087
1206
|
if (expCall.functionExpression.namespaceName) {
|
|
1088
1207
|
// prefer namespaced function
|
|
1089
1208
|
const potentialNamespacedCallable = expCall.functionExpression.namespaceName.getName(Parser_1.ParseMode.BrightScript).toLowerCase() + '_' + lowerName;
|
|
@@ -1095,6 +1214,131 @@ class Util {
|
|
|
1095
1214
|
}
|
|
1096
1215
|
return callablesWithThisName;
|
|
1097
1216
|
}
|
|
1217
|
+
/**
|
|
1218
|
+
* Sort an array of objects that have a Range
|
|
1219
|
+
*/
|
|
1220
|
+
sortByRange(locatables) {
|
|
1221
|
+
//sort the tokens by range
|
|
1222
|
+
return locatables.sort((a, b) => {
|
|
1223
|
+
//start line
|
|
1224
|
+
if (a.range.start.line < b.range.start.line) {
|
|
1225
|
+
return -1;
|
|
1226
|
+
}
|
|
1227
|
+
if (a.range.start.line > b.range.start.line) {
|
|
1228
|
+
return 1;
|
|
1229
|
+
}
|
|
1230
|
+
//start char
|
|
1231
|
+
if (a.range.start.character < b.range.start.character) {
|
|
1232
|
+
return -1;
|
|
1233
|
+
}
|
|
1234
|
+
if (a.range.start.character > b.range.start.character) {
|
|
1235
|
+
return 1;
|
|
1236
|
+
}
|
|
1237
|
+
//end line
|
|
1238
|
+
if (a.range.end.line < b.range.end.line) {
|
|
1239
|
+
return -1;
|
|
1240
|
+
}
|
|
1241
|
+
if (a.range.end.line > b.range.end.line) {
|
|
1242
|
+
return 1;
|
|
1243
|
+
}
|
|
1244
|
+
//end char
|
|
1245
|
+
if (a.range.end.character < b.range.end.character) {
|
|
1246
|
+
return -1;
|
|
1247
|
+
}
|
|
1248
|
+
else if (a.range.end.character > b.range.end.character) {
|
|
1249
|
+
return 1;
|
|
1250
|
+
}
|
|
1251
|
+
return 0;
|
|
1252
|
+
});
|
|
1253
|
+
}
|
|
1254
|
+
/**
|
|
1255
|
+
* Split the given text and return ranges for each chunk.
|
|
1256
|
+
* Only works for single-line strings
|
|
1257
|
+
*/
|
|
1258
|
+
splitGetRange(separator, text, range) {
|
|
1259
|
+
const chunks = text.split(separator);
|
|
1260
|
+
const result = [];
|
|
1261
|
+
let offset = 0;
|
|
1262
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
1263
|
+
const chunk = chunks[i];
|
|
1264
|
+
//only keep nonzero chunks
|
|
1265
|
+
if (chunk.length > 0) {
|
|
1266
|
+
result.push({
|
|
1267
|
+
text: chunk,
|
|
1268
|
+
range: this.createRange(range.start.line, range.start.character + offset, range.end.line, range.start.character + offset + chunk.length)
|
|
1269
|
+
});
|
|
1270
|
+
}
|
|
1271
|
+
offset += chunk.length + separator.length;
|
|
1272
|
+
}
|
|
1273
|
+
return result;
|
|
1274
|
+
}
|
|
1275
|
+
/*
|
|
1276
|
+
* Wrap the given code in a markdown code fence (with the language)
|
|
1277
|
+
*/
|
|
1278
|
+
mdFence(code, language = '') {
|
|
1279
|
+
return '```' + language + '\n' + code + '\n```';
|
|
1280
|
+
}
|
|
1281
|
+
/**
|
|
1282
|
+
* Finds a callable from a container map based on the name AND number of arguments
|
|
1283
|
+
* If the callable was called in a function in a namespace, functions in that namespace are preferred
|
|
1284
|
+
* The first callable that matches the name AND will accept the number of arguments given is returned
|
|
1285
|
+
* @return a callable containers that matches the call
|
|
1286
|
+
*/
|
|
1287
|
+
getCallableContainerByFunctionCall(callablesByLowerName, expCall) {
|
|
1288
|
+
const callablesWithThisName = this.getCallableContainersByName(callablesByLowerName, expCall);
|
|
1289
|
+
if ((callablesWithThisName === null || callablesWithThisName === void 0 ? void 0 : callablesWithThisName.length) > 0) {
|
|
1290
|
+
for (const callableContainer of callablesWithThisName) {
|
|
1291
|
+
const paramCount = exports.util.getMinMaxParamCount(callableContainer.callable.params);
|
|
1292
|
+
if (paramCount.min <= expCall.args.length && paramCount.max >= expCall.args.length) {
|
|
1293
|
+
return callableContainer;
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
/**
|
|
1299
|
+
* Gets each part of the dotted get.
|
|
1300
|
+
* @param expression
|
|
1301
|
+
* @returns an array of the parts of the dotted get. If not fully a dotted get, then returns undefined
|
|
1302
|
+
*/
|
|
1303
|
+
getAllDottedGetParts(expression) {
|
|
1304
|
+
var _a, _b;
|
|
1305
|
+
const parts = [];
|
|
1306
|
+
let nextPart = expression;
|
|
1307
|
+
while (nextPart) {
|
|
1308
|
+
if ((0, reflection_1.isDottedGetExpression)(nextPart)) {
|
|
1309
|
+
parts.push((_a = nextPart === null || nextPart === void 0 ? void 0 : nextPart.name) === null || _a === void 0 ? void 0 : _a.text);
|
|
1310
|
+
nextPart = nextPart.obj;
|
|
1311
|
+
}
|
|
1312
|
+
else if ((0, reflection_1.isVariableExpression)(nextPart)) {
|
|
1313
|
+
parts.push((_b = nextPart === null || nextPart === void 0 ? void 0 : nextPart.name) === null || _b === void 0 ? void 0 : _b.text);
|
|
1314
|
+
break;
|
|
1315
|
+
}
|
|
1316
|
+
else {
|
|
1317
|
+
//we found a non-DottedGet expression, so return because this whole operation is invalid.
|
|
1318
|
+
return undefined;
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
return parts.reverse();
|
|
1322
|
+
}
|
|
1323
|
+
/**
|
|
1324
|
+
* Returns an integer if valid, or undefined. Eliminates checking for NaN
|
|
1325
|
+
*/
|
|
1326
|
+
parseInt(value) {
|
|
1327
|
+
const result = parseInt(value);
|
|
1328
|
+
if (!isNaN(result)) {
|
|
1329
|
+
return result;
|
|
1330
|
+
}
|
|
1331
|
+
else {
|
|
1332
|
+
return undefined;
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
/**
|
|
1336
|
+
* Converts a range to a string in the format 1:2-3:4
|
|
1337
|
+
*/
|
|
1338
|
+
rangeToString(range) {
|
|
1339
|
+
var _a, _b, _c, _d;
|
|
1340
|
+
return `${(_a = range === null || range === void 0 ? void 0 : range.start) === null || _a === void 0 ? void 0 : _a.line}:${(_b = range === null || range === void 0 ? void 0 : range.start) === null || _b === void 0 ? void 0 : _b.character}-${(_c = range === null || range === void 0 ? void 0 : range.end) === null || _c === void 0 ? void 0 : _c.line}:${(_d = range === null || range === void 0 ? void 0 : range.end) === null || _d === void 0 ? void 0 : _d.character}`;
|
|
1341
|
+
}
|
|
1098
1342
|
}
|
|
1099
1343
|
exports.Util = Util;
|
|
1100
1344
|
/**
|
|
@@ -1111,4 +1355,5 @@ function standardizePath(stringParts, ...expressions) {
|
|
|
1111
1355
|
exports.standardizePath = standardizePath;
|
|
1112
1356
|
exports.util = new Util();
|
|
1113
1357
|
exports.default = exports.util;
|
|
1358
|
+
exports.MAX_PARAM_COUNT = 32;
|
|
1114
1359
|
//# sourceMappingURL=util.js.map
|