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/Program.js
CHANGED
|
@@ -20,10 +20,11 @@ const Manifest_1 = require("./preprocessor/Manifest");
|
|
|
20
20
|
const vscode_uri_1 = require("vscode-uri");
|
|
21
21
|
const PluginInterface_1 = require("./PluginInterface");
|
|
22
22
|
const reflection_1 = require("./astUtils/reflection");
|
|
23
|
-
const
|
|
24
|
-
const
|
|
23
|
+
const Parser_1 = require("./parser/Parser");
|
|
24
|
+
const TokenKind_1 = require("./lexer/TokenKind");
|
|
25
25
|
const BscPlugin_1 = require("./bscPlugin/BscPlugin");
|
|
26
26
|
const roku_deploy_1 = require("roku-deploy");
|
|
27
|
+
const AstEditor_1 = require("./astUtils/AstEditor");
|
|
27
28
|
const bslibNonAliasedRokuModulesPkgPath = `pkg:/source/roku_modules/rokucommunity_bslib/bslib.brs`;
|
|
28
29
|
const bslibAliasedRokuModulesPkgPath = `pkg:/source/roku_modules/bslib/bslib.brs`;
|
|
29
30
|
class Program {
|
|
@@ -112,7 +113,7 @@ class Program {
|
|
|
112
113
|
/**
|
|
113
114
|
* Get a copy of the list of files currently loaded in the program
|
|
114
115
|
*/
|
|
115
|
-
|
|
116
|
+
getAllFiles() {
|
|
116
117
|
return Object.values(this.files);
|
|
117
118
|
}
|
|
118
119
|
addScope(scope) {
|
|
@@ -263,18 +264,20 @@ class Program {
|
|
|
263
264
|
/**
|
|
264
265
|
* Update internal maps with this file reference
|
|
265
266
|
*/
|
|
266
|
-
|
|
267
|
+
assignFile(file) {
|
|
267
268
|
this.files[file.srcPath.toLowerCase()] = file;
|
|
268
269
|
this.pkgMap[file.pkgPath.toLowerCase()] = file;
|
|
270
|
+
return file;
|
|
269
271
|
}
|
|
270
272
|
/**
|
|
271
273
|
* Remove this file from internal maps
|
|
272
274
|
*/
|
|
273
|
-
|
|
275
|
+
unassignFile(file) {
|
|
274
276
|
delete this.files[file.srcPath.toLowerCase()];
|
|
275
277
|
delete this.pkgMap[file.pkgPath.toLowerCase()];
|
|
278
|
+
return file;
|
|
276
279
|
}
|
|
277
|
-
|
|
280
|
+
setFile(fileParam, fileContents) {
|
|
278
281
|
assert.ok(fileParam, 'fileParam is required');
|
|
279
282
|
let srcPath;
|
|
280
283
|
let pkgPath;
|
|
@@ -282,7 +285,7 @@ class Program {
|
|
|
282
285
|
//is a pkg path
|
|
283
286
|
if (fileParam.startsWith('pkg:/')) {
|
|
284
287
|
//srcPath is the pkgPath relative to the rootDir
|
|
285
|
-
srcPath = util_1.standardizePath `${this.options.rootDir}/${fileParam.substring(5)}`;
|
|
288
|
+
srcPath = (0, util_1.standardizePath) `${this.options.rootDir}/${fileParam.substring(5)}`;
|
|
286
289
|
pkgPath = fileParam;
|
|
287
290
|
//is a srcPath (absolute path to src file location)
|
|
288
291
|
}
|
|
@@ -293,17 +296,17 @@ class Program {
|
|
|
293
296
|
//is destPath (path relative to rootDir and `pkg:/`)
|
|
294
297
|
}
|
|
295
298
|
else {
|
|
296
|
-
srcPath = util_1.standardizePath `${this.options.rootDir}/${fileParam}`;
|
|
299
|
+
srcPath = (0, util_1.standardizePath) `${this.options.rootDir}/${fileParam}`;
|
|
297
300
|
pkgPath = util_1.util.sanitizePkgPath(fileParam);
|
|
298
301
|
}
|
|
299
302
|
//is a FileObj
|
|
300
303
|
}
|
|
301
304
|
else {
|
|
302
|
-
srcPath = util_1.standardizePath `${fileParam.src}`;
|
|
305
|
+
srcPath = (0, util_1.standardizePath) `${fileParam.src}`;
|
|
303
306
|
pkgPath = util_1.util.sanitizePkgPath(fileParam.dest);
|
|
304
307
|
}
|
|
305
308
|
const lowerPkgPath = pkgPath.toLowerCase();
|
|
306
|
-
return this.logger.time(Logger_1.LogLevel.debug, ['Program.
|
|
309
|
+
return this.logger.time(Logger_1.LogLevel.debug, ['Program.setFile()', chalk_1.default.green(srcPath)], () => {
|
|
307
310
|
assert.ok(srcPath, 'srcPath is required');
|
|
308
311
|
assert.ok(pkgPath, 'pkgPath is required');
|
|
309
312
|
//if the file is already loaded, remove it
|
|
@@ -318,47 +321,49 @@ class Program {
|
|
|
318
321
|
source: fileContents
|
|
319
322
|
};
|
|
320
323
|
if (fileExtension === '.brs' || fileExtension === '.bs') {
|
|
321
|
-
|
|
324
|
+
//add the file to the program
|
|
325
|
+
const brsFile = this.assignFile(new BrsFile_1.BrsFile(srcPath, pkgPath, this));
|
|
322
326
|
//add file to the `source` dependency list
|
|
323
327
|
if (brsFile.pkgPath.startsWith('pkg:/source/')) {
|
|
324
328
|
this.createSourceScope();
|
|
325
329
|
this.dependencyGraph.addDependency('scope:source', brsFile.dependencyGraphKey);
|
|
326
330
|
}
|
|
327
331
|
//add the file to the program
|
|
328
|
-
this.
|
|
332
|
+
this.assignFile(brsFile);
|
|
329
333
|
this.plugins.emit('beforeFileParse', beforeFileParseEvent);
|
|
330
334
|
this.logger.time(Logger_1.LogLevel.debug, ['parse', chalk_1.default.green(srcPath)], () => {
|
|
331
335
|
brsFile.parse(beforeFileParseEvent.source);
|
|
332
336
|
});
|
|
333
|
-
file
|
|
334
|
-
brsFile.attachDependencyGraph(this.dependencyGraph);
|
|
337
|
+
//notify plugins that this file has finished parsing
|
|
335
338
|
this.plugins.emit('afterFileParse', {
|
|
336
339
|
program: this,
|
|
337
340
|
file: brsFile
|
|
338
341
|
});
|
|
342
|
+
file = brsFile;
|
|
343
|
+
brsFile.attachDependencyGraph(this.dependencyGraph);
|
|
339
344
|
}
|
|
340
345
|
else if (
|
|
341
346
|
//is xml file
|
|
342
347
|
fileExtension === '.xml' &&
|
|
343
348
|
//resides in the components folder (Roku will only parse xml files in the components folder)
|
|
344
349
|
lowerPkgPath.startsWith('pkg:/components/')) {
|
|
345
|
-
let xmlFile = new XmlFile_1.XmlFile(srcPath, pkgPath, this);
|
|
346
|
-
this.setFile(xmlFile);
|
|
347
350
|
//add the file to the program
|
|
351
|
+
const xmlFile = this.assignFile(new XmlFile_1.XmlFile(srcPath, pkgPath, this));
|
|
348
352
|
this.plugins.emit('beforeFileParse', beforeFileParseEvent);
|
|
349
353
|
this.logger.time(Logger_1.LogLevel.debug, ['parse', chalk_1.default.green(srcPath)], () => {
|
|
350
354
|
xmlFile.parse(beforeFileParseEvent.source);
|
|
351
355
|
});
|
|
356
|
+
//notify plugins that this file has finished parsing
|
|
357
|
+
this.plugins.emit('afterFileParse', {
|
|
358
|
+
program: this,
|
|
359
|
+
file: xmlFile
|
|
360
|
+
});
|
|
352
361
|
file = xmlFile;
|
|
353
362
|
//create a new scope for this xml file
|
|
354
363
|
let scope = new XmlScope_1.XmlScope(xmlFile, this);
|
|
355
364
|
this.addScope(scope);
|
|
356
365
|
//register this compoent now that we have parsed it and know its component name
|
|
357
366
|
this.registerComponent(xmlFile, scope);
|
|
358
|
-
this.plugins.emit('afterFileParse', {
|
|
359
|
-
program: this,
|
|
360
|
-
file: xmlFile
|
|
361
|
-
});
|
|
362
367
|
}
|
|
363
368
|
else {
|
|
364
369
|
//TODO do we actually need to implement this? Figure out how to handle img paths
|
|
@@ -385,18 +390,18 @@ class Program {
|
|
|
385
390
|
}
|
|
386
391
|
/**
|
|
387
392
|
* Remove a set of files from the program
|
|
388
|
-
* @param
|
|
393
|
+
* @param filePaths can be an array of srcPath or destPath strings
|
|
394
|
+
* @param normalizePath should this function repair and standardize the filePaths? Passing false should have a performance boost if you can guarantee your paths are already sanitized
|
|
389
395
|
*/
|
|
390
|
-
removeFiles(srcPaths) {
|
|
396
|
+
removeFiles(srcPaths, normalizePath = true) {
|
|
391
397
|
for (let srcPath of srcPaths) {
|
|
392
|
-
this.removeFile(srcPath);
|
|
398
|
+
this.removeFile(srcPath, normalizePath);
|
|
393
399
|
}
|
|
394
400
|
}
|
|
395
401
|
/**
|
|
396
402
|
* Remove a file from the program
|
|
397
403
|
* @param filePath can be a srcPath, a pkgPath, or a destPath (same as pkgPath but without `pkg:/`)
|
|
398
404
|
* @param normalizePath should this function repair and standardize the path? Passing false should have a performance boost if you can guarantee your path is already sanitized
|
|
399
|
-
|
|
400
405
|
*/
|
|
401
406
|
removeFile(filePath, normalizePath = true) {
|
|
402
407
|
this.logger.debug('Program.removeFile()', filePath);
|
|
@@ -423,16 +428,18 @@ class Program {
|
|
|
423
428
|
});
|
|
424
429
|
}
|
|
425
430
|
//remove the file from the program
|
|
426
|
-
this.
|
|
431
|
+
this.unassignFile(file);
|
|
427
432
|
this.dependencyGraph.remove(file.dependencyGraphKey);
|
|
428
433
|
//if this is a pkg:/source file, notify the `source` scope that it has changed
|
|
429
434
|
if (file.pkgPath.startsWith('pkg:/source/')) {
|
|
430
435
|
this.dependencyGraph.removeDependency('scope:source', file.dependencyGraphKey);
|
|
431
436
|
}
|
|
432
437
|
//if this is a component, remove it from our components map
|
|
433
|
-
if (reflection_1.isXmlFile(file)) {
|
|
438
|
+
if ((0, reflection_1.isXmlFile)(file)) {
|
|
434
439
|
this.unregisterComponent(file);
|
|
435
440
|
}
|
|
441
|
+
//dispose file
|
|
442
|
+
file === null || file === void 0 ? void 0 : file.dispose();
|
|
436
443
|
this.plugins.emit('afterFileDispose', {
|
|
437
444
|
program: this,
|
|
438
445
|
file: file
|
|
@@ -483,6 +490,11 @@ class Program {
|
|
|
483
490
|
program: this,
|
|
484
491
|
file: file
|
|
485
492
|
});
|
|
493
|
+
//emit an event to allow plugins to contribute to the file validation process
|
|
494
|
+
this.plugins.emit('onFileValidate', {
|
|
495
|
+
program: this,
|
|
496
|
+
file: file
|
|
497
|
+
});
|
|
486
498
|
//call file.validate() IF the file has that function defined
|
|
487
499
|
(_a = file.validate) === null || _a === void 0 ? void 0 : _a.call(file);
|
|
488
500
|
file.isValidated = true;
|
|
@@ -524,7 +536,7 @@ class Program {
|
|
|
524
536
|
for (const key in this.files) {
|
|
525
537
|
const file = this.files[key];
|
|
526
538
|
//if this is an XmlFile, and it has a valid `componentName` property
|
|
527
|
-
if (reflection_1.isXmlFile(file)) {
|
|
539
|
+
if ((0, reflection_1.isXmlFile)(file)) {
|
|
528
540
|
const componentNameLower = (_a = file.componentName) === null || _a === void 0 ? void 0 : _a.text.toLowerCase();
|
|
529
541
|
if (componentNameLower) {
|
|
530
542
|
if (!componentsByName.has(componentNameLower)) {
|
|
@@ -562,6 +574,16 @@ class Program {
|
|
|
562
574
|
}
|
|
563
575
|
return false;
|
|
564
576
|
}
|
|
577
|
+
/**
|
|
578
|
+
* Get the files for a list of filePaths
|
|
579
|
+
* @param filePaths can be an array of srcPath or a destPath strings
|
|
580
|
+
* @param normalizePath should this function repair and standardize the paths? Passing false should have a performance boost if you can guarantee your paths are already sanitized
|
|
581
|
+
*/
|
|
582
|
+
getFiles(filePaths, normalizePath = true) {
|
|
583
|
+
return filePaths
|
|
584
|
+
.map(filePath => this.getFile(filePath, normalizePath))
|
|
585
|
+
.filter(file => file !== undefined);
|
|
586
|
+
}
|
|
565
587
|
/**
|
|
566
588
|
* Get the file at the given path
|
|
567
589
|
* @param filePath can be a srcPath, a pkgPath, or a destPath (same as pkgPath but without `pkg:/`)
|
|
@@ -592,6 +614,17 @@ class Program {
|
|
|
592
614
|
}
|
|
593
615
|
return result;
|
|
594
616
|
}
|
|
617
|
+
/**
|
|
618
|
+
* Get the first found scope for a file.
|
|
619
|
+
*/
|
|
620
|
+
getFirstScopeForFile(file) {
|
|
621
|
+
for (let key in this.scopes) {
|
|
622
|
+
let scope = this.scopes[key];
|
|
623
|
+
if (scope.hasFile(file)) {
|
|
624
|
+
return scope;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
}
|
|
595
628
|
getStatementsByName(name, originFile, namespaceName) {
|
|
596
629
|
var _a, _b;
|
|
597
630
|
let results = new Map();
|
|
@@ -601,7 +634,7 @@ class Program {
|
|
|
601
634
|
//look through all files in scope for matches
|
|
602
635
|
for (const scope of this.getScopesForFile(originFile)) {
|
|
603
636
|
for (const file of scope.getAllFiles()) {
|
|
604
|
-
if (reflection_1.isXmlFile(file) || filesSearched.has(file)) {
|
|
637
|
+
if ((0, reflection_1.isXmlFile)(file) || filesSearched.has(file)) {
|
|
605
638
|
continue;
|
|
606
639
|
}
|
|
607
640
|
filesSearched.add(file);
|
|
@@ -624,17 +657,20 @@ class Program {
|
|
|
624
657
|
//get all function names for the xml file and parents
|
|
625
658
|
let funcNames = new Set();
|
|
626
659
|
let currentScope = scope;
|
|
627
|
-
while (reflection_1.isXmlScope(currentScope)) {
|
|
628
|
-
for (let
|
|
629
|
-
if (
|
|
630
|
-
|
|
660
|
+
while ((0, reflection_1.isXmlScope)(currentScope)) {
|
|
661
|
+
for (let member of (_b = (_a = currentScope.xmlFile.ast.component) === null || _a === void 0 ? void 0 : _a.interfaceMembers) !== null && _b !== void 0 ? _b : []) {
|
|
662
|
+
if ((0, reflection_1.isSGInterfaceFunction)(member)) {
|
|
663
|
+
const name = member.name;
|
|
664
|
+
if (!filterName || name === filterName) {
|
|
665
|
+
funcNames.add(name);
|
|
666
|
+
}
|
|
631
667
|
}
|
|
632
668
|
}
|
|
633
669
|
currentScope = currentScope.getParentScope();
|
|
634
670
|
}
|
|
635
671
|
//look through all files in scope for matches
|
|
636
672
|
for (const file of scope.getOwnFiles()) {
|
|
637
|
-
if (reflection_1.isXmlFile(file) || filesSearched.has(file)) {
|
|
673
|
+
if ((0, reflection_1.isXmlFile)(file) || filesSearched.has(file)) {
|
|
638
674
|
continue;
|
|
639
675
|
}
|
|
640
676
|
filesSearched.add(file);
|
|
@@ -660,9 +696,9 @@ class Program {
|
|
|
660
696
|
return [];
|
|
661
697
|
}
|
|
662
698
|
let result = [];
|
|
663
|
-
if (reflection_1.isBrsFile(file) && file.isPositionNextToTokenKind(position,
|
|
699
|
+
if ((0, reflection_1.isBrsFile)(file) && file.parser.isPositionNextToTokenKind(position, TokenKind_1.TokenKind.Callfunc)) {
|
|
664
700
|
// is next to a @. callfunc invocation - must be an interface method
|
|
665
|
-
for (const scope of this.getScopes().filter((s) => reflection_1.isXmlScope(s))) {
|
|
701
|
+
for (const scope of this.getScopes().filter((s) => (0, reflection_1.isXmlScope)(s))) {
|
|
666
702
|
let fileLinks = this.getStatementsForXmlFile(scope);
|
|
667
703
|
for (let fileLink of fileLinks) {
|
|
668
704
|
result.push(scope.createCompletionFromFunctionStatement(fileLink.item));
|
|
@@ -676,7 +712,12 @@ class Program {
|
|
|
676
712
|
//if there are no scopes, include the global scope so we at least get the built-in functions
|
|
677
713
|
scopes = scopes.length > 0 ? scopes : [this.globalScope];
|
|
678
714
|
//get the completions from all scopes for this file
|
|
679
|
-
let allCompletions = util_1.util.flatMap(scopes.map(ctx =>
|
|
715
|
+
let allCompletions = util_1.util.flatMap(scopes.map(ctx => {
|
|
716
|
+
ctx.linkSymbolTable();
|
|
717
|
+
const completions = file.getCompletions(position, ctx);
|
|
718
|
+
ctx.unlinkSymbolTable();
|
|
719
|
+
return completions;
|
|
720
|
+
}), c => c);
|
|
680
721
|
//only keep completions common to every scope for this file
|
|
681
722
|
let keyCounts = {};
|
|
682
723
|
for (let completion of allCompletions) {
|
|
@@ -695,7 +736,7 @@ class Program {
|
|
|
695
736
|
const result = [];
|
|
696
737
|
for (const key in this.files) {
|
|
697
738
|
const file = this.files[key];
|
|
698
|
-
if (reflection_1.isBrsFile(file)) {
|
|
739
|
+
if ((0, reflection_1.isBrsFile)(file)) {
|
|
699
740
|
result.push(...file.getWorkspaceSymbols());
|
|
700
741
|
}
|
|
701
742
|
}
|
|
@@ -711,7 +752,7 @@ class Program {
|
|
|
711
752
|
if (!file) {
|
|
712
753
|
return [];
|
|
713
754
|
}
|
|
714
|
-
if (reflection_1.isBrsFile(file)) {
|
|
755
|
+
if ((0, reflection_1.isBrsFile)(file)) {
|
|
715
756
|
return file.getDefinition(position);
|
|
716
757
|
}
|
|
717
758
|
else {
|
|
@@ -732,7 +773,8 @@ class Program {
|
|
|
732
773
|
if (!file) {
|
|
733
774
|
return null;
|
|
734
775
|
}
|
|
735
|
-
|
|
776
|
+
const hover = file.getHover(position);
|
|
777
|
+
return Promise.resolve(hover);
|
|
736
778
|
}
|
|
737
779
|
/**
|
|
738
780
|
* Compute code actions for the given file and range
|
|
@@ -761,10 +803,26 @@ class Program {
|
|
|
761
803
|
}
|
|
762
804
|
return codeActions;
|
|
763
805
|
}
|
|
806
|
+
/**
|
|
807
|
+
* Get semantic tokens for the specified file
|
|
808
|
+
*/
|
|
809
|
+
getSemanticTokens(srcPath) {
|
|
810
|
+
const file = this.getFile(srcPath);
|
|
811
|
+
if (file) {
|
|
812
|
+
const result = [];
|
|
813
|
+
this.plugins.emit('onGetSemanticTokens', {
|
|
814
|
+
program: this,
|
|
815
|
+
file: file,
|
|
816
|
+
scopes: this.getScopesForFile(file),
|
|
817
|
+
semanticTokens: result
|
|
818
|
+
});
|
|
819
|
+
return result;
|
|
820
|
+
}
|
|
821
|
+
}
|
|
764
822
|
getSignatureHelp(filepath, position) {
|
|
765
823
|
var _a;
|
|
766
824
|
let file = this.getFile(filepath);
|
|
767
|
-
if (!file || !reflection_1.isBrsFile(file)) {
|
|
825
|
+
if (!file || !(0, reflection_1.isBrsFile)(file)) {
|
|
768
826
|
return [];
|
|
769
827
|
}
|
|
770
828
|
const results = new Map();
|
|
@@ -787,12 +845,14 @@ class Program {
|
|
|
787
845
|
//if m class reference.. then
|
|
788
846
|
//only get statements from the class I am in..
|
|
789
847
|
if (functionExpression) {
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
848
|
+
const currentToken = file.parser.getTokenAt(position);
|
|
849
|
+
for (let scope of this.getScopesForFile(file)) {
|
|
850
|
+
scope.linkSymbolTable();
|
|
851
|
+
let myClass = file.getClassFromToken(currentToken, functionExpression, scope);
|
|
852
|
+
if (myClass) {
|
|
853
|
+
let classes = scope.getClassHierarchy(myClass.item.getName(Parser_1.ParseMode.BrighterScript).toLowerCase());
|
|
794
854
|
//and anything from any class in scope to a non m class
|
|
795
|
-
for (let statement of [...classes].filter((i) => reflection_1.isClassMethodStatement(i.item))) {
|
|
855
|
+
for (let statement of [...classes].filter((i) => (0, reflection_1.isClassMethodStatement)(i.item))) {
|
|
796
856
|
let sigHelp = statement.file.getSignatureHelpForStatement(statement.item);
|
|
797
857
|
if (sigHelp && !results.has[sigHelp.key]) {
|
|
798
858
|
results.set(sigHelp.key, sigHelp);
|
|
@@ -800,6 +860,7 @@ class Program {
|
|
|
800
860
|
}
|
|
801
861
|
}
|
|
802
862
|
}
|
|
863
|
+
scope.unlinkSymbolTable();
|
|
803
864
|
}
|
|
804
865
|
}
|
|
805
866
|
if (identifierInfo.dotPart) {
|
|
@@ -821,7 +882,7 @@ class Program {
|
|
|
821
882
|
}
|
|
822
883
|
}
|
|
823
884
|
else if (identifierInfo.statementType === '@.') {
|
|
824
|
-
for (const scope of this.getScopes().filter((s) => reflection_1.isXmlScope(s))) {
|
|
885
|
+
for (const scope of this.getScopes().filter((s) => (0, reflection_1.isXmlScope)(s))) {
|
|
825
886
|
let fileLinks = this.getStatementsForXmlFile(scope, identifierInfo.name);
|
|
826
887
|
for (let fileLink of fileLinks) {
|
|
827
888
|
let sigHelp = fileLink.file.getSignatureHelpForStatement(fileLink.item);
|
|
@@ -860,13 +921,13 @@ class Program {
|
|
|
860
921
|
if (!itemCounts.isArgStartFound) {
|
|
861
922
|
//try to get sig help based on the name
|
|
862
923
|
index = position.character;
|
|
863
|
-
let currentToken = file.getTokenAt(position);
|
|
864
|
-
if (currentToken && currentToken.kind !==
|
|
865
|
-
name = file.getPartialVariableName(currentToken, [
|
|
924
|
+
let currentToken = file.parser.getTokenAt(position);
|
|
925
|
+
if (currentToken && currentToken.kind !== TokenKind_1.TokenKind.Comment) {
|
|
926
|
+
name = file.getPartialVariableName(currentToken, [TokenKind_1.TokenKind.New]);
|
|
866
927
|
if (!name) {
|
|
867
928
|
//try the previous token, incase we're on a bracket
|
|
868
|
-
currentToken = file.getPreviousToken(currentToken);
|
|
869
|
-
name = file.getPartialVariableName(currentToken, [
|
|
929
|
+
currentToken = file.parser.getPreviousToken(currentToken);
|
|
930
|
+
name = file.getPartialVariableName(currentToken, [TokenKind_1.TokenKind.New]);
|
|
870
931
|
}
|
|
871
932
|
if (name === null || name === void 0 ? void 0 : name.indexOf('.')) {
|
|
872
933
|
let parts = name.split('.');
|
|
@@ -1034,23 +1095,65 @@ class Program {
|
|
|
1034
1095
|
/**
|
|
1035
1096
|
* Transpile a single file and get the result as a string.
|
|
1036
1097
|
* This does not write anything to the file system.
|
|
1037
|
-
* @param srcPath
|
|
1098
|
+
* @param srcPath can be a srcPath or a destPath
|
|
1038
1099
|
*/
|
|
1039
1100
|
getTranspiledFileContents(srcPath) {
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1101
|
+
return this._getTranspiledFileContents(this.getFile(srcPath));
|
|
1102
|
+
}
|
|
1103
|
+
/**
|
|
1104
|
+
* Internal function used to transpile files.
|
|
1105
|
+
* This does not write anything to the file system
|
|
1106
|
+
*/
|
|
1107
|
+
_getTranspiledFileContents(file, outputPath) {
|
|
1108
|
+
const editor = new AstEditor_1.AstEditor();
|
|
1109
|
+
this.plugins.emit('beforeFileTranspile', {
|
|
1110
|
+
file: file,
|
|
1111
|
+
program: this,
|
|
1112
|
+
outputPath: outputPath,
|
|
1113
|
+
editor: editor
|
|
1114
|
+
});
|
|
1115
|
+
//if we have any edits, assume the file needs to be transpiled
|
|
1116
|
+
if (editor.hasChanges) {
|
|
1117
|
+
//use the `editor` because it'll track the previous value for us and revert later on
|
|
1118
|
+
editor.setProperty(file, 'needsTranspiled', true);
|
|
1119
|
+
}
|
|
1120
|
+
//transpile the file
|
|
1121
|
+
const result = file.transpile();
|
|
1122
|
+
//generate the typedef if enabled
|
|
1123
|
+
let typedef;
|
|
1124
|
+
if ((0, reflection_1.isBrsFile)(file) && this.options.emitDefinitions) {
|
|
1125
|
+
typedef = file.getTypedef();
|
|
1126
|
+
}
|
|
1127
|
+
const event = {
|
|
1128
|
+
file: file,
|
|
1129
|
+
program: this,
|
|
1130
|
+
outputPath: outputPath,
|
|
1131
|
+
editor: editor,
|
|
1132
|
+
code: result.code,
|
|
1133
|
+
map: result.map,
|
|
1134
|
+
typedef: typedef
|
|
1135
|
+
};
|
|
1136
|
+
this.plugins.emit('afterFileTranspile', event);
|
|
1137
|
+
//undo all `editor` edits that may have been applied to this file.
|
|
1138
|
+
editor.undoAll();
|
|
1139
|
+
return {
|
|
1140
|
+
srcPath: file.srcPath,
|
|
1141
|
+
pkgPath: file.pkgPath,
|
|
1142
|
+
code: event.code,
|
|
1143
|
+
map: event.map,
|
|
1144
|
+
typedef: event.typedef
|
|
1145
|
+
};
|
|
1043
1146
|
}
|
|
1044
1147
|
async transpile(fileEntries, stagingFolderPath) {
|
|
1045
1148
|
// map fileEntries using their path as key to avoid excessive "find()" operations
|
|
1046
1149
|
const mappedFileEntries = fileEntries.reduce((collection, entry) => {
|
|
1047
|
-
collection[util_1.standardizePath `${entry.src}`] = entry;
|
|
1150
|
+
collection[(0, util_1.standardizePath) `${entry.src}`] = entry;
|
|
1048
1151
|
return collection;
|
|
1049
1152
|
}, {});
|
|
1050
1153
|
const entries = [];
|
|
1051
1154
|
for (const key in this.files) {
|
|
1052
1155
|
const file = this.files[key];
|
|
1053
|
-
let filePathObj = mappedFileEntries[util_1.standardizePath `${file.srcPath}`];
|
|
1156
|
+
let filePathObj = mappedFileEntries[(0, util_1.standardizePath) `${file.srcPath}`];
|
|
1054
1157
|
if (!filePathObj) {
|
|
1055
1158
|
//this file has been added in-memory, from a plugin, for example
|
|
1056
1159
|
filePathObj = {
|
|
@@ -1066,48 +1169,41 @@ class Program {
|
|
|
1066
1169
|
//change any .bs file extension to .brs
|
|
1067
1170
|
.replace(/\.bs$/gi, '.brs');
|
|
1068
1171
|
//prepend the staging folder path
|
|
1069
|
-
outputPath = util_1.standardizePath `${stagingFolderPath}/${outputPath}`;
|
|
1172
|
+
outputPath = (0, util_1.standardizePath) `${stagingFolderPath}/${outputPath}`;
|
|
1070
1173
|
entries.push({
|
|
1071
1174
|
file: file,
|
|
1072
|
-
|
|
1175
|
+
program: this,
|
|
1176
|
+
outputPath: outputPath,
|
|
1177
|
+
editor: new AstEditor_1.AstEditor()
|
|
1073
1178
|
});
|
|
1074
1179
|
}
|
|
1180
|
+
const astEditor = new AstEditor_1.AstEditor();
|
|
1075
1181
|
this.plugins.emit('beforeProgramTranspile', {
|
|
1076
1182
|
program: this,
|
|
1077
|
-
entries: entries
|
|
1183
|
+
entries: entries,
|
|
1184
|
+
editor: astEditor
|
|
1078
1185
|
});
|
|
1079
1186
|
const promises = entries.map(async (entry) => {
|
|
1080
1187
|
//skip transpiling typedef files
|
|
1081
|
-
if (reflection_1.isBrsFile(entry.file) && entry.file.isTypedef) {
|
|
1188
|
+
if ((0, reflection_1.isBrsFile)(entry.file) && entry.file.isTypedef) {
|
|
1082
1189
|
return;
|
|
1083
1190
|
}
|
|
1084
|
-
this.plugins.emit('beforeFileTranspile', {
|
|
1085
|
-
program: this,
|
|
1086
|
-
file: entry.file,
|
|
1087
|
-
outputPath: entry.outputPath
|
|
1088
|
-
});
|
|
1089
1191
|
const { file, outputPath } = entry;
|
|
1090
|
-
const
|
|
1192
|
+
const fileTranspileResult = this._getTranspiledFileContents(file, outputPath);
|
|
1091
1193
|
//make sure the full dir path exists
|
|
1092
1194
|
await fsExtra.ensureDir(path.dirname(outputPath));
|
|
1093
1195
|
if (await fsExtra.pathExists(outputPath)) {
|
|
1094
1196
|
throw new Error(`Error while transpiling "${file.srcPath}". A file already exists at "${outputPath}" and will not be overwritten.`);
|
|
1095
1197
|
}
|
|
1096
|
-
const writeMapPromise =
|
|
1198
|
+
const writeMapPromise = fileTranspileResult.map ? fsExtra.writeFile(`${outputPath}.map`, fileTranspileResult.map.toString()) : null;
|
|
1097
1199
|
await Promise.all([
|
|
1098
|
-
fsExtra.writeFile(outputPath,
|
|
1200
|
+
fsExtra.writeFile(outputPath, fileTranspileResult.code),
|
|
1099
1201
|
writeMapPromise
|
|
1100
1202
|
]);
|
|
1101
|
-
if (
|
|
1102
|
-
const typedef = file.getTypedef();
|
|
1203
|
+
if (fileTranspileResult.typedef) {
|
|
1103
1204
|
const typedefPath = outputPath.replace(/\.brs$/i, '.d.bs');
|
|
1104
|
-
await fsExtra.writeFile(typedefPath, typedef);
|
|
1205
|
+
await fsExtra.writeFile(typedefPath, fileTranspileResult.typedef);
|
|
1105
1206
|
}
|
|
1106
|
-
this.plugins.emit('afterFileTranspile', {
|
|
1107
|
-
program: this,
|
|
1108
|
-
file: entry.file,
|
|
1109
|
-
outputPath: entry.outputPath
|
|
1110
|
-
});
|
|
1111
1207
|
});
|
|
1112
1208
|
//if there's no bslib file already loaded into the program, copy it to the staging directory
|
|
1113
1209
|
if (!this.getFile(bslibAliasedRokuModulesPkgPath) && !this.getFile(`pkg:/source/bslib.brs`)) {
|
|
@@ -1116,8 +1212,10 @@ class Program {
|
|
|
1116
1212
|
await Promise.all(promises);
|
|
1117
1213
|
this.plugins.emit('afterProgramTranspile', {
|
|
1118
1214
|
program: this,
|
|
1119
|
-
entries: entries
|
|
1215
|
+
entries: entries,
|
|
1216
|
+
editor: astEditor
|
|
1120
1217
|
});
|
|
1218
|
+
astEditor.undoAll();
|
|
1121
1219
|
}
|
|
1122
1220
|
/**
|
|
1123
1221
|
* Find a list of files in the program that have a function with the given name (case INsensitive)
|
|
@@ -1127,7 +1225,7 @@ class Program {
|
|
|
1127
1225
|
const lowerFunctionName = functionName.toLowerCase();
|
|
1128
1226
|
//find every file with this function defined
|
|
1129
1227
|
for (const file of Object.values(this.files)) {
|
|
1130
|
-
if (reflection_1.isBrsFile(file)) {
|
|
1228
|
+
if ((0, reflection_1.isBrsFile)(file)) {
|
|
1131
1229
|
//TODO handle namespace-relative function calls
|
|
1132
1230
|
//if the file has a function with this name
|
|
1133
1231
|
if (file.parser.references.functionStatementLookup.get(lowerFunctionName) !== undefined) {
|
|
@@ -1138,14 +1236,14 @@ class Program {
|
|
|
1138
1236
|
return files;
|
|
1139
1237
|
}
|
|
1140
1238
|
/**
|
|
1141
|
-
* Find a list of files in the program that have a
|
|
1239
|
+
* Find a list of files in the program that have a class with the given name (case INsensitive)
|
|
1142
1240
|
*/
|
|
1143
1241
|
findFilesForClass(className) {
|
|
1144
1242
|
const files = [];
|
|
1145
1243
|
const lowerClassName = className.toLowerCase();
|
|
1146
1244
|
//find every file with this class defined
|
|
1147
1245
|
for (const file of Object.values(this.files)) {
|
|
1148
|
-
if (reflection_1.isBrsFile(file)) {
|
|
1246
|
+
if ((0, reflection_1.isBrsFile)(file)) {
|
|
1149
1247
|
//TODO handle namespace-relative classes
|
|
1150
1248
|
//if the file has a function with this name
|
|
1151
1249
|
if (file.parser.references.classStatementLookup.get(lowerClassName) !== undefined) {
|
|
@@ -1167,7 +1265,7 @@ class Program {
|
|
|
1167
1265
|
try {
|
|
1168
1266
|
//we only load this manifest once, so do it sync to improve speed downstream
|
|
1169
1267
|
contents = fsExtra.readFileSync(manifestPath, 'utf-8');
|
|
1170
|
-
this._manifest = Manifest_1.parseManifest(contents);
|
|
1268
|
+
this._manifest = (0, Manifest_1.parseManifest)(contents);
|
|
1171
1269
|
}
|
|
1172
1270
|
catch (err) {
|
|
1173
1271
|
this._manifest = new Map();
|