brighterscript 1.0.0-alpha.3 → 1.0.0-alpha.31
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 +1249 -285
- package/README.md +61 -131
- package/bsconfig.schema.json +68 -2
- package/dist/ActionPipeline.d.ts +10 -0
- package/dist/ActionPipeline.js +40 -0
- package/dist/ActionPipeline.js.map +1 -0
- package/dist/AstValidationSegmenter.d.ts +42 -0
- package/dist/AstValidationSegmenter.js +232 -0
- package/dist/AstValidationSegmenter.js.map +1 -0
- package/dist/BsConfig.d.ts +51 -6
- package/dist/BusyStatusTracker.d.ts +31 -0
- package/dist/BusyStatusTracker.js +83 -0
- package/dist/BusyStatusTracker.js.map +1 -0
- package/dist/Cache.d.ts +5 -6
- package/dist/Cache.js +12 -11
- package/dist/Cache.js.map +1 -1
- package/dist/CacheVerifier.d.ts +7 -0
- package/dist/CacheVerifier.js +20 -0
- package/dist/CacheVerifier.js.map +1 -0
- 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 +7 -6
- package/dist/CommentFlagProcessor.js +10 -7
- package/dist/CommentFlagProcessor.js.map +1 -1
- package/dist/CrossScopeValidator.d.ts +67 -0
- package/dist/CrossScopeValidator.js +625 -0
- package/dist/CrossScopeValidator.js.map +1 -0
- package/dist/DependencyGraph.d.ts +8 -3
- package/dist/DependencyGraph.js +49 -16
- package/dist/DependencyGraph.js.map +1 -1
- package/dist/DiagnosticCollection.d.ts +5 -3
- package/dist/DiagnosticCollection.js +18 -16
- package/dist/DiagnosticCollection.js.map +1 -1
- package/dist/DiagnosticFilterer.d.ts +8 -4
- package/dist/DiagnosticFilterer.js +77 -44
- package/dist/DiagnosticFilterer.js.map +1 -1
- package/dist/DiagnosticManager.d.ts +56 -0
- package/dist/DiagnosticManager.js +218 -0
- package/dist/DiagnosticManager.js.map +1 -0
- package/dist/DiagnosticMessages.d.ts +187 -20
- package/dist/DiagnosticMessages.js +247 -29
- package/dist/DiagnosticMessages.js.map +1 -1
- package/dist/DiagnosticSeverityAdjuster.d.ts +7 -0
- package/dist/DiagnosticSeverityAdjuster.js +41 -0
- package/dist/DiagnosticSeverityAdjuster.js.map +1 -0
- package/dist/FunctionScope.d.ts +28 -0
- package/dist/FunctionScope.js +52 -0
- package/dist/FunctionScope.js.map +1 -0
- package/dist/KeyedThrottler.d.ts +3 -3
- package/dist/KeyedThrottler.js +3 -3
- package/dist/KeyedThrottler.js.map +1 -1
- package/dist/LanguageServer.d.ts +72 -47
- package/dist/LanguageServer.js +544 -312
- package/dist/LanguageServer.js.map +1 -1
- package/dist/Logger.d.ts +9 -10
- package/dist/Logger.js +36 -30
- package/dist/Logger.js.map +1 -1
- package/dist/PluginInterface.d.ts +29 -7
- package/dist/PluginInterface.js +90 -7
- package/dist/PluginInterface.js.map +1 -1
- package/dist/Program.d.ts +199 -100
- package/dist/Program.js +1056 -700
- package/dist/Program.js.map +1 -1
- package/dist/ProgramBuilder.d.ts +29 -18
- package/dist/ProgramBuilder.js +170 -132
- package/dist/ProgramBuilder.js.map +1 -1
- package/dist/Scope.d.ts +144 -109
- package/dist/Scope.js +533 -552
- package/dist/Scope.js.map +1 -1
- package/dist/SemanticTokenUtils.d.ts +14 -0
- package/dist/SemanticTokenUtils.js +85 -0
- package/dist/SemanticTokenUtils.js.map +1 -0
- package/dist/Stopwatch.d.ts +4 -0
- package/dist/Stopwatch.js +8 -1
- package/dist/Stopwatch.js.map +1 -1
- package/dist/SymbolTable.d.ts +91 -24
- package/dist/SymbolTable.js +290 -64
- package/dist/SymbolTable.js.map +1 -1
- package/dist/SymbolTypeFlag.d.ts +9 -0
- package/dist/SymbolTypeFlag.js +14 -0
- package/dist/SymbolTypeFlag.js.map +1 -0
- package/dist/Throttler.d.ts +12 -0
- package/dist/Throttler.js +39 -0
- package/dist/Throttler.js.map +1 -1
- package/dist/Watcher.d.ts +0 -3
- package/dist/Watcher.js +0 -3
- package/dist/Watcher.js.map +1 -1
- package/dist/XmlScope.d.ts +5 -15
- package/dist/XmlScope.js +35 -87
- package/dist/XmlScope.js.map +1 -1
- package/dist/astUtils/CachedLookups.d.ts +50 -0
- package/dist/astUtils/CachedLookups.js +331 -0
- package/dist/astUtils/CachedLookups.js.map +1 -0
- package/dist/astUtils/Editor.d.ts +69 -0
- package/dist/astUtils/Editor.js +245 -0
- package/dist/astUtils/Editor.js.map +1 -0
- package/dist/astUtils/Editor.spec.js +258 -0
- package/dist/astUtils/Editor.spec.js.map +1 -0
- package/dist/astUtils/creators.d.ts +33 -10
- package/dist/astUtils/creators.js +224 -30
- package/dist/astUtils/creators.js.map +1 -1
- package/dist/astUtils/creators.spec.js +5 -5
- package/dist/astUtils/creators.spec.js.map +1 -1
- package/dist/astUtils/reflection.d.ts +146 -82
- package/dist/astUtils/reflection.js +308 -132
- package/dist/astUtils/reflection.js.map +1 -1
- package/dist/astUtils/reflection.spec.js +267 -162
- package/dist/astUtils/reflection.spec.js.map +1 -1
- package/dist/astUtils/stackedVisitor.js.map +1 -1
- package/dist/astUtils/stackedVisitor.spec.js +14 -14
- package/dist/astUtils/stackedVisitor.spec.js.map +1 -1
- package/dist/astUtils/visitors.d.ts +115 -53
- package/dist/astUtils/visitors.js +70 -13
- package/dist/astUtils/visitors.js.map +1 -1
- package/dist/astUtils/visitors.spec.js +465 -51
- package/dist/astUtils/visitors.spec.js.map +1 -1
- package/dist/astUtils/xml.d.ts +9 -8
- package/dist/astUtils/xml.js +10 -5
- package/dist/astUtils/xml.js.map +1 -1
- package/dist/bscPlugin/BscPlugin.d.ts +22 -1
- package/dist/bscPlugin/BscPlugin.js +88 -0
- package/dist/bscPlugin/BscPlugin.js.map +1 -1
- package/dist/bscPlugin/CallExpressionInfo.d.ts +36 -0
- package/dist/bscPlugin/CallExpressionInfo.js +131 -0
- package/dist/bscPlugin/CallExpressionInfo.js.map +1 -0
- package/dist/bscPlugin/FileWriter.d.ts +6 -0
- package/dist/bscPlugin/FileWriter.js +24 -0
- package/dist/bscPlugin/FileWriter.js.map +1 -0
- package/dist/bscPlugin/SignatureHelpUtil.d.ts +10 -0
- package/dist/bscPlugin/SignatureHelpUtil.js +137 -0
- package/dist/bscPlugin/SignatureHelpUtil.js.map +1 -0
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.d.ts +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +26 -17
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +94 -20
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/completions/CompletionsProcessor.d.ts +60 -0
- package/dist/bscPlugin/completions/CompletionsProcessor.js +601 -0
- package/dist/bscPlugin/completions/CompletionsProcessor.js.map +1 -0
- package/dist/bscPlugin/completions/CompletionsProcessor.spec.js +2139 -0
- package/dist/bscPlugin/completions/CompletionsProcessor.spec.js.map +1 -0
- package/dist/bscPlugin/definition/DefinitionProvider.d.ts +13 -0
- package/dist/bscPlugin/definition/DefinitionProvider.js +210 -0
- package/dist/bscPlugin/definition/DefinitionProvider.js.map +1 -0
- package/dist/bscPlugin/definition/DefinitionProvider.spec.js +88 -0
- package/dist/bscPlugin/definition/DefinitionProvider.spec.js.map +1 -0
- package/dist/bscPlugin/fileProviders/FileProvider.d.ts +9 -0
- package/dist/bscPlugin/fileProviders/FileProvider.js +51 -0
- package/dist/bscPlugin/fileProviders/FileProvider.js.map +1 -0
- package/dist/bscPlugin/hover/HoverProcessor.d.ts +18 -0
- package/dist/bscPlugin/hover/HoverProcessor.js +218 -0
- package/dist/bscPlugin/hover/HoverProcessor.js.map +1 -0
- package/dist/bscPlugin/hover/HoverProcessor.spec.d.ts +1 -0
- package/dist/bscPlugin/hover/HoverProcessor.spec.js +737 -0
- package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +1 -0
- package/dist/bscPlugin/references/ReferencesProvider.d.ts +12 -0
- package/dist/bscPlugin/references/ReferencesProvider.js +56 -0
- package/dist/bscPlugin/references/ReferencesProvider.js.map +1 -0
- package/dist/bscPlugin/references/ReferencesProvider.spec.d.ts +1 -0
- package/dist/bscPlugin/references/ReferencesProvider.spec.js +51 -0
- package/dist/bscPlugin/references/ReferencesProvider.spec.js.map +1 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.d.ts +14 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +144 -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 +504 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +1 -0
- package/dist/bscPlugin/serialize/BslibInjector.spec.d.ts +1 -0
- package/dist/bscPlugin/serialize/BslibInjector.spec.js +19 -0
- package/dist/bscPlugin/serialize/BslibInjector.spec.js.map +1 -0
- package/dist/bscPlugin/serialize/BslibManager.d.ts +9 -0
- package/dist/bscPlugin/serialize/BslibManager.js +40 -0
- package/dist/bscPlugin/serialize/BslibManager.js.map +1 -0
- package/dist/bscPlugin/serialize/FileSerializer.d.ts +9 -0
- package/dist/bscPlugin/serialize/FileSerializer.js +72 -0
- package/dist/bscPlugin/serialize/FileSerializer.js.map +1 -0
- package/dist/bscPlugin/symbols/DocumentSymbolProcessor.d.ts +7 -0
- package/dist/bscPlugin/symbols/DocumentSymbolProcessor.js +22 -0
- package/dist/bscPlugin/symbols/DocumentSymbolProcessor.js.map +1 -0
- package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.d.ts +1 -0
- package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.js +291 -0
- package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.js.map +1 -0
- package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.d.ts +7 -0
- package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.js +26 -0
- package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.js.map +1 -0
- package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.d.ts +1 -0
- package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.js +245 -0
- package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.js.map +1 -0
- package/dist/bscPlugin/symbols/symbolUtils.d.ts +5 -0
- package/dist/bscPlugin/symbols/symbolUtils.js +140 -0
- package/dist/bscPlugin/symbols/symbolUtils.js.map +1 -0
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.d.ts +21 -0
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js +199 -0
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js.map +1 -0
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.d.ts +1 -0
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.js +41 -0
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.js.map +1 -0
- package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.d.ts +12 -0
- package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.js +99 -0
- package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.js.map +1 -0
- package/dist/bscPlugin/validation/BrsFileAfterValidator.d.ts +7 -0
- package/dist/bscPlugin/validation/BrsFileAfterValidator.js +18 -0
- package/dist/bscPlugin/validation/BrsFileAfterValidator.js.map +1 -0
- package/dist/bscPlugin/validation/BrsFileValidator.d.ts +34 -0
- package/dist/bscPlugin/validation/BrsFileValidator.js +462 -0
- package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -0
- package/dist/bscPlugin/validation/BrsFileValidator.spec.d.ts +1 -0
- package/dist/bscPlugin/validation/BrsFileValidator.spec.js +758 -0
- package/dist/bscPlugin/validation/BrsFileValidator.spec.js.map +1 -0
- package/dist/bscPlugin/validation/ProgramValidator.d.ts +11 -0
- package/dist/bscPlugin/validation/ProgramValidator.js +33 -0
- package/dist/bscPlugin/validation/ProgramValidator.js.map +1 -0
- package/dist/bscPlugin/validation/ScopeValidator.d.ts +123 -0
- package/dist/bscPlugin/validation/ScopeValidator.js +1026 -0
- package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -0
- package/dist/bscPlugin/validation/ScopeValidator.spec.d.ts +1 -0
- package/dist/bscPlugin/validation/ScopeValidator.spec.js +2897 -0
- package/dist/bscPlugin/validation/ScopeValidator.spec.js.map +1 -0
- package/dist/bscPlugin/validation/XmlFileValidator.d.ts +8 -0
- package/dist/bscPlugin/validation/XmlFileValidator.js +44 -0
- package/dist/bscPlugin/validation/XmlFileValidator.js.map +1 -0
- package/dist/cli.js +117 -11
- package/dist/cli.js.map +1 -1
- package/dist/deferred.d.ts +3 -3
- package/dist/deferred.js.map +1 -1
- package/dist/diagnosticUtils.d.ts +10 -3
- package/dist/diagnosticUtils.js +58 -21
- package/dist/diagnosticUtils.js.map +1 -1
- package/dist/examples/plugins/removePrint.js +8 -12
- package/dist/examples/plugins/removePrint.js.map +1 -1
- package/dist/files/AssetFile.d.ts +24 -0
- package/dist/files/AssetFile.js +25 -0
- package/dist/files/AssetFile.js.map +1 -0
- package/dist/files/BrsFile.Class.spec.js +858 -153
- package/dist/files/BrsFile.Class.spec.js.map +1 -1
- package/dist/files/BrsFile.d.ts +147 -82
- package/dist/files/BrsFile.js +853 -911
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/BrsFile.spec.js +3056 -836
- package/dist/files/BrsFile.spec.js.map +1 -1
- package/dist/files/BscFile.d.ts +101 -0
- package/dist/files/BscFile.js +15 -0
- package/dist/files/BscFile.js.map +1 -0
- package/dist/files/Factory.d.ts +25 -0
- package/dist/files/Factory.js +22 -0
- package/dist/files/Factory.js.map +1 -0
- package/dist/files/LazyFileData.d.ts +20 -0
- package/dist/files/LazyFileData.js +54 -0
- package/dist/files/LazyFileData.js.map +1 -0
- package/dist/files/LazyFileData.spec.d.ts +1 -0
- package/dist/files/LazyFileData.spec.js +27 -0
- package/dist/files/LazyFileData.spec.js.map +1 -0
- package/dist/files/XmlFile.d.ts +73 -41
- package/dist/files/XmlFile.js +126 -138
- package/dist/files/XmlFile.js.map +1 -1
- package/dist/files/XmlFile.spec.js +450 -318
- package/dist/files/XmlFile.spec.js.map +1 -1
- package/dist/files/tests/imports.spec.js +62 -52
- 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 +152 -0
- package/dist/files/tests/optionalChaning.spec.js.map +1 -0
- package/dist/globalCallables.d.ts +3 -1
- package/dist/globalCallables.js +416 -162
- package/dist/globalCallables.js.map +1 -1
- package/dist/index.d.ts +25 -3
- package/dist/index.js +42 -5
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +717 -119
- package/dist/interfaces.js +21 -0
- package/dist/interfaces.js.map +1 -1
- package/dist/lexer/Character.spec.js +5 -5
- package/dist/lexer/Character.spec.js.map +1 -1
- package/dist/lexer/Lexer.d.ts +40 -9
- package/dist/lexer/Lexer.js +191 -49
- package/dist/lexer/Lexer.js.map +1 -1
- package/dist/lexer/Lexer.spec.js +775 -563
- package/dist/lexer/Lexer.spec.js.map +1 -1
- package/dist/lexer/Token.d.ts +11 -3
- package/dist/lexer/Token.js +10 -2
- package/dist/lexer/Token.js.map +1 -1
- package/dist/lexer/TokenKind.d.ts +27 -1
- package/dist/lexer/TokenKind.js +112 -5
- package/dist/lexer/TokenKind.js.map +1 -1
- package/dist/logging.d.ts +9 -0
- package/dist/logging.js +16 -0
- package/dist/logging.js.map +1 -0
- package/dist/parser/AstNode.d.ts +181 -0
- package/dist/parser/AstNode.js +246 -0
- package/dist/parser/AstNode.js.map +1 -0
- package/dist/parser/AstNode.spec.d.ts +1 -0
- package/dist/parser/AstNode.spec.js +165 -0
- package/dist/parser/AstNode.spec.js.map +1 -0
- package/dist/parser/BrsTranspileState.d.ts +12 -2
- package/dist/parser/BrsTranspileState.js +6 -0
- package/dist/parser/BrsTranspileState.js.map +1 -1
- package/dist/parser/Expression.d.ts +454 -210
- package/dist/parser/Expression.js +953 -498
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Parser.Class.spec.js +200 -95
- package/dist/parser/Parser.Class.spec.js.map +1 -1
- package/dist/parser/Parser.d.ts +106 -120
- package/dist/parser/Parser.js +1432 -931
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/Parser.spec.d.ts +3 -1
- package/dist/parser/Parser.spec.js +1383 -456
- package/dist/parser/Parser.spec.js.map +1 -1
- package/dist/parser/SGParser.d.ts +44 -6
- package/dist/parser/SGParser.js +212 -185
- package/dist/parser/SGParser.js.map +1 -1
- package/dist/parser/SGParser.spec.js +30 -28
- package/dist/parser/SGParser.spec.js.map +1 -1
- package/dist/parser/SGTypes.d.ts +293 -50
- package/dist/parser/SGTypes.js +540 -187
- package/dist/parser/SGTypes.js.map +1 -1
- package/dist/parser/Statement.d.ts +759 -247
- package/dist/parser/Statement.js +1785 -607
- package/dist/parser/Statement.js.map +1 -1
- package/dist/parser/Statement.spec.js +45 -34
- package/dist/parser/Statement.spec.js.map +1 -1
- package/dist/parser/TranspileState.d.ts +18 -8
- package/dist/parser/TranspileState.js +76 -12
- 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 +18 -14
- package/dist/parser/tests/Parser.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/For.spec.js +79 -69
- package/dist/parser/tests/controlFlow/For.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/ForEach.spec.js +53 -47
- package/dist/parser/tests/controlFlow/ForEach.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/If.spec.js +217 -196
- package/dist/parser/tests/controlFlow/If.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/While.spec.js +48 -42
- package/dist/parser/tests/controlFlow/While.spec.js.map +1 -1
- package/dist/parser/tests/expression/Additive.spec.js +31 -31
- package/dist/parser/tests/expression/Additive.spec.js.map +1 -1
- package/dist/parser/tests/expression/ArrayLiterals.spec.js +157 -120
- package/dist/parser/tests/expression/ArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +202 -139
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/expression/Boolean.spec.js +25 -25
- package/dist/parser/tests/expression/Boolean.spec.js.map +1 -1
- package/dist/parser/tests/expression/Call.spec.js +150 -41
- package/dist/parser/tests/expression/Call.spec.js.map +1 -1
- package/dist/parser/tests/expression/Exponential.spec.js +18 -18
- package/dist/parser/tests/expression/Exponential.spec.js.map +1 -1
- package/dist/parser/tests/expression/Function.spec.js +257 -257
- package/dist/parser/tests/expression/Function.spec.js.map +1 -1
- package/dist/parser/tests/expression/Indexing.spec.js +160 -90
- package/dist/parser/tests/expression/Indexing.spec.js.map +1 -1
- package/dist/parser/tests/expression/Multiplicative.spec.js +38 -38
- package/dist/parser/tests/expression/Multiplicative.spec.js.map +1 -1
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +196 -98
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/PrefixUnary.spec.js +42 -42
- package/dist/parser/tests/expression/PrefixUnary.spec.js.map +1 -1
- package/dist/parser/tests/expression/Primary.spec.js +42 -42
- 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 +44 -44
- package/dist/parser/tests/expression/Relational.spec.js.map +1 -1
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.js +31 -31
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js +230 -90
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TernaryExpression.spec.js +377 -148
- package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TypeExpression.spec.d.ts +1 -0
- package/dist/parser/tests/expression/TypeExpression.spec.js +126 -0
- package/dist/parser/tests/expression/TypeExpression.spec.js.map +1 -0
- package/dist/parser/tests/expression/UnaryExpression.spec.d.ts +1 -0
- package/dist/parser/tests/expression/UnaryExpression.spec.js +52 -0
- package/dist/parser/tests/expression/UnaryExpression.spec.js.map +1 -0
- package/dist/parser/tests/statement/AssignmentOperators.spec.js +37 -37
- package/dist/parser/tests/statement/AssignmentOperators.spec.js.map +1 -1
- package/dist/parser/tests/statement/ConstStatement.spec.d.ts +1 -0
- package/dist/parser/tests/statement/ConstStatement.spec.js +262 -0
- package/dist/parser/tests/statement/ConstStatement.spec.js.map +1 -0
- package/dist/parser/tests/statement/Continue.spec.d.ts +1 -0
- package/dist/parser/tests/statement/Continue.spec.js +119 -0
- package/dist/parser/tests/statement/Continue.spec.js.map +1 -0
- package/dist/parser/tests/statement/Declaration.spec.js +45 -45
- package/dist/parser/tests/statement/Declaration.spec.js.map +1 -1
- package/dist/parser/tests/statement/Dim.spec.js +22 -22
- 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 +745 -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 +45 -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 +36 -0
- package/dist/parser/tests/statement/ForEach.spec.js.map +1 -0
- package/dist/parser/tests/statement/Function.spec.js +208 -198
- package/dist/parser/tests/statement/Function.spec.js.map +1 -1
- package/dist/parser/tests/statement/Goto.spec.js +16 -15
- package/dist/parser/tests/statement/Goto.spec.js.map +1 -1
- package/dist/parser/tests/statement/Increment.spec.js +51 -51
- 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 +110 -0
- package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +1 -0
- package/dist/parser/tests/statement/LibraryStatement.spec.js +18 -18
- package/dist/parser/tests/statement/LibraryStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Misc.spec.js +123 -163
- package/dist/parser/tests/statement/Misc.spec.js.map +1 -1
- package/dist/parser/tests/statement/PrintStatement.spec.js +125 -108
- package/dist/parser/tests/statement/PrintStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/ReturnStatement.spec.js +51 -49
- package/dist/parser/tests/statement/ReturnStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Set.spec.js +110 -97
- package/dist/parser/tests/statement/Set.spec.js.map +1 -1
- package/dist/parser/tests/statement/Stop.spec.js +13 -12
- package/dist/parser/tests/statement/Stop.spec.js.map +1 -1
- package/dist/parser/tests/statement/Throw.spec.js +6 -6
- package/dist/parser/tests/statement/Throw.spec.js.map +1 -1
- package/dist/parser/tests/statement/TryCatch.spec.js +26 -15
- package/dist/parser/tests/statement/TryCatch.spec.js.map +1 -1
- package/dist/preprocessor/Manifest.d.ts +6 -6
- package/dist/preprocessor/Manifest.js +17 -38
- 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/roku-types/data.json +19369 -0
- package/dist/roku-types/index.d.ts +5497 -0
- package/dist/roku-types/index.js +11 -0
- package/dist/roku-types/index.js.map +1 -0
- package/dist/types/ArrayType.d.ts +9 -5
- package/dist/types/ArrayType.js +68 -24
- package/dist/types/ArrayType.js.map +1 -1
- package/dist/types/ArrayType.spec.js +39 -11
- package/dist/types/ArrayType.spec.js.map +1 -1
- package/dist/types/AssociativeArrayType.d.ts +14 -0
- package/dist/types/AssociativeArrayType.js +60 -0
- package/dist/types/AssociativeArrayType.js.map +1 -0
- package/dist/types/BaseFunctionType.d.ts +9 -0
- package/dist/types/BaseFunctionType.js +25 -0
- package/dist/types/BaseFunctionType.js.map +1 -0
- package/dist/types/BooleanType.d.ts +10 -5
- package/dist/types/BooleanType.js +21 -9
- package/dist/types/BooleanType.js.map +1 -1
- package/dist/types/BooleanType.spec.js +10 -4
- package/dist/types/BooleanType.spec.js.map +1 -1
- package/dist/types/BscType.d.ts +29 -3
- package/dist/types/BscType.js +121 -0
- package/dist/types/BscType.js.map +1 -1
- package/dist/types/BscTypeKind.d.ts +25 -0
- package/dist/types/BscTypeKind.js +30 -0
- package/dist/types/BscTypeKind.js.map +1 -0
- package/dist/types/BuiltInInterfaceAdder.d.ts +25 -0
- package/dist/types/BuiltInInterfaceAdder.js +201 -0
- package/dist/types/BuiltInInterfaceAdder.js.map +1 -0
- package/dist/types/BuiltInInterfaceAdder.spec.d.ts +1 -0
- package/dist/types/BuiltInInterfaceAdder.spec.js +115 -0
- package/dist/types/BuiltInInterfaceAdder.spec.js.map +1 -0
- package/dist/types/ClassType.d.ts +16 -0
- package/dist/types/ClassType.js +57 -0
- package/dist/types/ClassType.js.map +1 -0
- package/dist/types/ClassType.spec.d.ts +1 -0
- package/dist/types/ClassType.spec.js +76 -0
- package/dist/types/ClassType.spec.js.map +1 -0
- package/dist/types/ComponentType.d.ts +27 -0
- package/dist/types/ComponentType.js +83 -0
- package/dist/types/ComponentType.js.map +1 -0
- package/dist/types/DoubleType.d.ts +10 -5
- package/dist/types/DoubleType.js +25 -18
- package/dist/types/DoubleType.js.map +1 -1
- package/dist/types/DoubleType.spec.js +12 -4
- package/dist/types/DoubleType.spec.js.map +1 -1
- package/dist/types/DynamicType.d.ts +12 -5
- package/dist/types/DynamicType.js +22 -6
- package/dist/types/DynamicType.js.map +1 -1
- package/dist/types/DynamicType.spec.js +16 -5
- package/dist/types/DynamicType.spec.js.map +1 -1
- package/dist/types/EnumType.d.ts +40 -0
- package/dist/types/EnumType.js +80 -0
- package/dist/types/EnumType.js.map +1 -0
- package/dist/types/EnumType.spec.d.ts +1 -0
- package/dist/types/EnumType.spec.js +33 -0
- package/dist/types/EnumType.spec.js.map +1 -0
- package/dist/types/FloatType.d.ts +10 -5
- package/dist/types/FloatType.js +25 -18
- package/dist/types/FloatType.js.map +1 -1
- package/dist/types/FloatType.spec.js +4 -4
- package/dist/types/FloatType.spec.js.map +1 -1
- package/dist/types/FunctionType.d.ts +10 -22
- package/dist/types/FunctionType.js +26 -63
- package/dist/types/FunctionType.js.map +1 -1
- package/dist/types/InheritableType.d.ts +28 -0
- package/dist/types/InheritableType.js +157 -0
- package/dist/types/InheritableType.js.map +1 -0
- package/dist/types/IntegerType.d.ts +10 -5
- package/dist/types/IntegerType.js +25 -18
- package/dist/types/IntegerType.js.map +1 -1
- package/dist/types/IntegerType.spec.js +8 -4
- package/dist/types/IntegerType.spec.js.map +1 -1
- package/dist/types/InterfaceType.d.ts +14 -6
- package/dist/types/InterfaceType.js +26 -15
- package/dist/types/InterfaceType.js.map +1 -1
- package/dist/types/InterfaceType.spec.d.ts +1 -0
- package/dist/types/InterfaceType.spec.js +227 -0
- package/dist/types/InterfaceType.spec.js.map +1 -0
- package/dist/types/InvalidType.d.ts +9 -5
- package/dist/types/InvalidType.js +20 -9
- package/dist/types/InvalidType.js.map +1 -1
- package/dist/types/InvalidType.spec.js +8 -4
- package/dist/types/InvalidType.spec.js.map +1 -1
- package/dist/types/LongIntegerType.d.ts +10 -5
- package/dist/types/LongIntegerType.js +25 -18
- package/dist/types/LongIntegerType.js.map +1 -1
- package/dist/types/LongIntegerType.spec.js +10 -4
- package/dist/types/LongIntegerType.spec.js.map +1 -1
- package/dist/types/NamespaceType.d.ts +12 -0
- package/dist/types/NamespaceType.js +28 -0
- package/dist/types/NamespaceType.js.map +1 -0
- package/dist/types/ObjectType.d.ts +10 -5
- package/dist/types/ObjectType.js +23 -9
- package/dist/types/ObjectType.js.map +1 -1
- package/dist/types/ObjectType.spec.js +3 -3
- package/dist/types/ObjectType.spec.js.map +1 -1
- package/dist/types/ReferenceType.d.ts +79 -0
- package/dist/types/ReferenceType.js +522 -0
- package/dist/types/ReferenceType.js.map +1 -0
- package/dist/types/ReferenceType.spec.d.ts +1 -0
- package/dist/types/ReferenceType.spec.js +151 -0
- package/dist/types/ReferenceType.spec.js.map +1 -0
- package/dist/types/StringType.d.ts +13 -5
- package/dist/types/StringType.js +25 -9
- package/dist/types/StringType.js.map +1 -1
- package/dist/types/StringType.spec.js +3 -3
- package/dist/types/StringType.spec.js.map +1 -1
- package/dist/types/TypedFunctionType.d.ts +33 -0
- package/dist/types/TypedFunctionType.js +106 -0
- package/dist/types/TypedFunctionType.js.map +1 -0
- package/dist/types/TypedFunctionType.spec.d.ts +1 -0
- package/dist/types/TypedFunctionType.spec.js +122 -0
- package/dist/types/TypedFunctionType.spec.js.map +1 -0
- package/dist/types/UninitializedType.d.ts +8 -6
- package/dist/types/UninitializedType.js +15 -9
- package/dist/types/UninitializedType.js.map +1 -1
- package/dist/types/UnionType.d.ts +20 -0
- package/dist/types/UnionType.js +127 -0
- package/dist/types/UnionType.js.map +1 -0
- package/dist/types/UnionType.spec.d.ts +1 -0
- package/dist/types/UnionType.spec.js +129 -0
- package/dist/types/UnionType.spec.js.map +1 -0
- package/dist/types/VoidType.d.ts +10 -5
- package/dist/types/VoidType.js +20 -9
- package/dist/types/VoidType.js.map +1 -1
- package/dist/types/VoidType.spec.js +3 -3
- package/dist/types/VoidType.spec.js.map +1 -1
- package/dist/types/helper.spec.d.ts +1 -0
- package/dist/types/helper.spec.js +144 -0
- package/dist/types/helper.spec.js.map +1 -0
- package/dist/types/helpers.d.ts +26 -0
- package/dist/types/helpers.js +191 -0
- package/dist/types/helpers.js.map +1 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/index.js +39 -0
- package/dist/types/index.js.map +1 -0
- package/dist/util.d.ts +218 -106
- package/dist/util.js +1310 -320
- package/dist/util.js.map +1 -1
- package/dist/validators/ClassValidator.d.ts +9 -15
- package/dist/validators/ClassValidator.js +81 -134
- package/dist/validators/ClassValidator.js.map +1 -1
- package/package.json +169 -138
- 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/Chunk.d.ts +0 -82
- package/dist/preprocessor/Chunk.js +0 -77
- package/dist/preprocessor/Chunk.js.map +0 -1
- package/dist/preprocessor/Preprocessor.d.ts +0 -60
- package/dist/preprocessor/Preprocessor.js +0 -156
- package/dist/preprocessor/Preprocessor.js.map +0 -1
- package/dist/preprocessor/Preprocessor.spec.js +0 -152
- package/dist/preprocessor/Preprocessor.spec.js.map +0 -1
- package/dist/preprocessor/PreprocessorParser.d.ts +0 -61
- package/dist/preprocessor/PreprocessorParser.js +0 -194
- package/dist/preprocessor/PreprocessorParser.js.map +0 -1
- package/dist/preprocessor/PreprocessorParser.spec.js +0 -116
- package/dist/preprocessor/PreprocessorParser.spec.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/CustomType.d.ts +0 -10
- package/dist/types/CustomType.js +0 -35
- package/dist/types/CustomType.js.map +0 -1
- package/dist/types/FunctionType.spec.js +0 -29
- package/dist/types/FunctionType.spec.js.map +0 -1
- package/dist/types/LazyType.d.ts +0 -15
- package/dist/types/LazyType.js +0 -32
- package/dist/types/LazyType.js.map +0 -1
- /package/dist/{preprocessor/Preprocessor.spec.d.ts → astUtils/Editor.spec.d.ts} +0 -0
- /package/dist/{preprocessor/PreprocessorParser.spec.d.ts → bscPlugin/completions/CompletionsProcessor.spec.d.ts} +0 -0
- /package/dist/{types/FunctionType.spec.d.ts → bscPlugin/definition/DefinitionProvider.spec.d.ts} +0 -0
|
@@ -1,64 +1,85 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NullCoalescingExpression = exports.TernaryExpression = exports.AnnotationExpression = exports.TaggedTemplateStringExpression = exports.TemplateStringExpression = exports.TemplateStringQuasiExpression = exports.CallfuncExpression = exports.NewExpression = exports.SourceLiteralExpression = exports.VariableExpression = exports.UnaryExpression = exports.AALiteralExpression = exports.AAMemberExpression = exports.ArrayLiteralExpression = exports.EscapedCharCodeLiteralExpression = exports.LiteralExpression = exports.GroupingExpression = exports.IndexedGetExpression = exports.XmlAttributeGetExpression = exports.DottedGetExpression = exports.
|
|
4
|
-
const
|
|
3
|
+
exports.TypedArrayExpression = exports.TypecastExpression = exports.TypeExpression = exports.RegexLiteralExpression = exports.NullCoalescingExpression = exports.TernaryExpression = exports.AnnotationExpression = exports.TaggedTemplateStringExpression = exports.TemplateStringExpression = exports.TemplateStringQuasiExpression = exports.CallfuncExpression = exports.NewExpression = exports.SourceLiteralExpression = exports.VariableExpression = exports.UnaryExpression = exports.AALiteralExpression = exports.AAMemberExpression = exports.ArrayLiteralExpression = exports.EscapedCharCodeLiteralExpression = exports.LiteralExpression = exports.GroupingExpression = exports.IndexedGetExpression = exports.XmlAttributeGetExpression = exports.DottedGetExpression = exports.FunctionParameterExpression = exports.FunctionExpression = exports.CallExpression = exports.BinaryExpression = void 0;
|
|
4
|
+
const TokenKind_1 = require("../lexer/TokenKind");
|
|
5
5
|
const util_1 = require("../util");
|
|
6
6
|
const Parser_1 = require("./Parser");
|
|
7
7
|
const fileUrl = require("file-url");
|
|
8
8
|
const visitors_1 = require("../astUtils/visitors");
|
|
9
|
+
const visitors_2 = require("../astUtils/visitors");
|
|
9
10
|
const reflection_1 = require("../astUtils/reflection");
|
|
11
|
+
const interfaces_1 = require("../interfaces");
|
|
10
12
|
const VoidType_1 = require("../types/VoidType");
|
|
11
13
|
const DynamicType_1 = require("../types/DynamicType");
|
|
14
|
+
const AstNode_1 = require("./AstNode");
|
|
12
15
|
const SymbolTable_1 = require("../SymbolTable");
|
|
16
|
+
const source_map_1 = require("source-map");
|
|
17
|
+
const StringType_1 = require("../types/StringType");
|
|
18
|
+
const ReferenceType_1 = require("../types/ReferenceType");
|
|
19
|
+
const UnionType_1 = require("../types/UnionType");
|
|
20
|
+
const ArrayType_1 = require("../types/ArrayType");
|
|
21
|
+
const AssociativeArrayType_1 = require("../types/AssociativeArrayType");
|
|
22
|
+
const creators_1 = require("../astUtils/creators");
|
|
23
|
+
const types_1 = require("../types");
|
|
13
24
|
const FunctionType_1 = require("../types/FunctionType");
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
constructor() {
|
|
17
|
-
/**
|
|
18
|
-
* When being considered by the walk visitor, this describes what type of element the current class is.
|
|
19
|
-
*/
|
|
20
|
-
this.visitMode = visitors_1.InternalWalkMode.visitExpressions;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
exports.Expression = Expression;
|
|
24
|
-
class BinaryExpression extends Expression {
|
|
25
|
-
constructor(left, operator, right) {
|
|
25
|
+
class BinaryExpression extends AstNode_1.Expression {
|
|
26
|
+
constructor(options) {
|
|
26
27
|
super();
|
|
27
|
-
this.
|
|
28
|
-
this.
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
this.kind = AstNode_1.AstNodeKind.BinaryExpression;
|
|
29
|
+
this.tokens = {
|
|
30
|
+
operator: options.operator
|
|
31
|
+
};
|
|
32
|
+
this.left = options.left;
|
|
33
|
+
this.right = options.right;
|
|
34
|
+
this.range = util_1.default.createBoundingRange(this.left, this.tokens.operator, this.right);
|
|
31
35
|
}
|
|
32
36
|
transpile(state) {
|
|
33
37
|
return [
|
|
34
38
|
state.sourceNode(this.left, this.left.transpile(state)),
|
|
35
39
|
' ',
|
|
36
|
-
state.transpileToken(this.operator),
|
|
40
|
+
state.transpileToken(this.tokens.operator),
|
|
37
41
|
' ',
|
|
38
42
|
state.sourceNode(this.right, this.right.transpile(state))
|
|
39
43
|
];
|
|
40
44
|
}
|
|
41
45
|
walk(visitor, options) {
|
|
42
|
-
if (options.walkMode &
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
|
|
47
|
+
(0, visitors_2.walk)(this, 'left', visitor, options);
|
|
48
|
+
(0, visitors_2.walk)(this, 'right', visitor, options);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
getType(options) {
|
|
52
|
+
const operatorKind = this.tokens.operator.kind;
|
|
53
|
+
if (options.flags & 2 /* SymbolTypeFlag.typetime */) {
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
55
|
+
switch (operatorKind) {
|
|
56
|
+
case TokenKind_1.TokenKind.Or:
|
|
57
|
+
return new UnionType_1.UnionType([this.left.getType(options), this.right.getType(options)]);
|
|
58
|
+
//TODO: Intersection Types?, eg. case TokenKind.And:
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else if (options.flags & 1 /* SymbolTypeFlag.runtime */) {
|
|
62
|
+
return util_1.default.binaryOperatorResultType(this.left.getType(options), this.tokens.operator, this.right.getType(options));
|
|
45
63
|
}
|
|
64
|
+
return DynamicType_1.DynamicType.instance;
|
|
65
|
+
}
|
|
66
|
+
getLeadingTrivia() {
|
|
67
|
+
return this.left.getLeadingTrivia();
|
|
46
68
|
}
|
|
47
69
|
}
|
|
48
70
|
exports.BinaryExpression = BinaryExpression;
|
|
49
|
-
class CallExpression extends Expression {
|
|
50
|
-
constructor(
|
|
51
|
-
|
|
52
|
-
* The namespace that currently wraps this call expression. This is NOT the namespace of the callee...that will be represented in the callee expression itself.
|
|
53
|
-
*/
|
|
54
|
-
namespaceName) {
|
|
71
|
+
class CallExpression extends AstNode_1.Expression {
|
|
72
|
+
constructor(options) {
|
|
73
|
+
var _a;
|
|
55
74
|
super();
|
|
56
|
-
this.
|
|
57
|
-
this.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
this.
|
|
75
|
+
this.kind = AstNode_1.AstNodeKind.CallExpression;
|
|
76
|
+
this.tokens = {
|
|
77
|
+
openingParen: options.openingParen,
|
|
78
|
+
closingParen: options.closingParen
|
|
79
|
+
};
|
|
80
|
+
this.callee = options.callee;
|
|
81
|
+
this.args = (_a = options.args) !== null && _a !== void 0 ? _a : [];
|
|
82
|
+
this.range = util_1.default.createBoundingRange(this.callee, this.tokens.openingParen, ...this.args, this.tokens.closingParen);
|
|
62
83
|
}
|
|
63
84
|
transpile(state, nameOverride) {
|
|
64
85
|
let result = [];
|
|
@@ -69,7 +90,7 @@ class CallExpression extends Expression {
|
|
|
69
90
|
else {
|
|
70
91
|
result.push(...this.callee.transpile(state));
|
|
71
92
|
}
|
|
72
|
-
result.push(state.transpileToken(this.openingParen));
|
|
93
|
+
result.push(state.transpileToken(this.tokens.openingParen, '('));
|
|
73
94
|
for (let i = 0; i < this.args.length; i++) {
|
|
74
95
|
//add comma between args
|
|
75
96
|
if (i > 0) {
|
|
@@ -78,80 +99,103 @@ class CallExpression extends Expression {
|
|
|
78
99
|
let arg = this.args[i];
|
|
79
100
|
result.push(...arg.transpile(state));
|
|
80
101
|
}
|
|
81
|
-
|
|
102
|
+
if (this.tokens.closingParen) {
|
|
103
|
+
result.push(state.transpileToken(this.tokens.closingParen));
|
|
104
|
+
}
|
|
82
105
|
return result;
|
|
83
106
|
}
|
|
84
107
|
walk(visitor, options) {
|
|
85
|
-
if (options.walkMode &
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
108
|
+
if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
|
|
109
|
+
(0, visitors_2.walk)(this, 'callee', visitor, options);
|
|
110
|
+
(0, visitors_2.walkArray)(this.args, visitor, options, this);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
getType(options) {
|
|
114
|
+
var _a, _b;
|
|
115
|
+
const calleeType = this.callee.getType(options);
|
|
116
|
+
if (options.ignoreCall) {
|
|
117
|
+
return calleeType;
|
|
118
|
+
}
|
|
119
|
+
if ((0, reflection_1.isNewExpression)(this.parent)) {
|
|
120
|
+
return calleeType;
|
|
121
|
+
}
|
|
122
|
+
const specialCaseReturnType = util_1.default.getSpecialCaseCallExpressionReturnType(this);
|
|
123
|
+
if (specialCaseReturnType) {
|
|
124
|
+
return specialCaseReturnType;
|
|
90
125
|
}
|
|
126
|
+
if ((0, reflection_1.isCallableType)(calleeType) && (!(0, reflection_1.isReferenceType)(calleeType.returnType) || ((_a = calleeType.returnType) === null || _a === void 0 ? void 0 : _a.isResolvable()))) {
|
|
127
|
+
return calleeType.returnType;
|
|
128
|
+
}
|
|
129
|
+
if (!(0, reflection_1.isReferenceType)(calleeType) && ((_b = calleeType === null || calleeType === void 0 ? void 0 : calleeType.returnType) === null || _b === void 0 ? void 0 : _b.isResolvable())) {
|
|
130
|
+
return calleeType.returnType;
|
|
131
|
+
}
|
|
132
|
+
return new ReferenceType_1.TypePropertyReferenceType(calleeType, 'returnType');
|
|
133
|
+
}
|
|
134
|
+
getLeadingTrivia() {
|
|
135
|
+
return this.callee.getLeadingTrivia();
|
|
91
136
|
}
|
|
92
137
|
}
|
|
93
138
|
exports.CallExpression = CallExpression;
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
139
|
+
/**
|
|
140
|
+
* Number of parameters that can be defined on a function
|
|
141
|
+
*
|
|
142
|
+
* Prior to Roku OS 11.5, this was 32
|
|
143
|
+
* As of Roku OS 11.5, this is 63
|
|
144
|
+
*/
|
|
145
|
+
CallExpression.MaximumArguments = 63;
|
|
146
|
+
class FunctionExpression extends AstNode_1.Expression {
|
|
147
|
+
constructor(options) {
|
|
148
|
+
var _a;
|
|
101
149
|
super();
|
|
102
|
-
this.
|
|
103
|
-
this.
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
this.
|
|
111
|
-
this.
|
|
112
|
-
this.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
this.childFunctionExpressions = [];
|
|
123
|
-
if (this.returnTypeToken) {
|
|
124
|
-
this.returnType = util_1.default.tokenToBscType(this.returnTypeToken);
|
|
125
|
-
}
|
|
126
|
-
else if (this.functionType.text.toLowerCase() === 'sub') {
|
|
127
|
-
this.returnType = new VoidType_1.VoidType();
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
this.returnType = new DynamicType_1.DynamicType();
|
|
131
|
-
}
|
|
132
|
-
this.symbolTable = new SymbolTable_1.SymbolTable(parentSymbolTable);
|
|
133
|
-
for (let param of parameters) {
|
|
134
|
-
this.symbolTable.addSymbol(param.name.text, param.name.range, param.type);
|
|
150
|
+
this.kind = AstNode_1.AstNodeKind.FunctionExpression;
|
|
151
|
+
this.tokens = {
|
|
152
|
+
functionType: options.functionType,
|
|
153
|
+
leftParen: options.leftParen,
|
|
154
|
+
rightParen: options.rightParen,
|
|
155
|
+
as: options.as,
|
|
156
|
+
endFunctionType: options.endFunctionType
|
|
157
|
+
};
|
|
158
|
+
this.parameters = (_a = options.parameters) !== null && _a !== void 0 ? _a : [];
|
|
159
|
+
this.body = options.body;
|
|
160
|
+
this.returnTypeExpression = options.returnTypeExpression;
|
|
161
|
+
//if there's a body, and it doesn't have a SymbolTable, assign one
|
|
162
|
+
if (this.body) {
|
|
163
|
+
if (!this.body.symbolTable) {
|
|
164
|
+
this.body.symbolTable = new SymbolTable_1.SymbolTable(`Block`, () => this.getSymbolTable());
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
this.body.symbolTable.pushParentProvider(() => this.getSymbolTable());
|
|
168
|
+
}
|
|
169
|
+
this.body.parent = this;
|
|
135
170
|
}
|
|
171
|
+
this.symbolTable = new SymbolTable_1.SymbolTable('FunctionExpression', () => { var _a; return (_a = this.parent) === null || _a === void 0 ? void 0 : _a.getSymbolTable(); });
|
|
172
|
+
}
|
|
173
|
+
getLeadingTrivia() {
|
|
174
|
+
var _a, _b;
|
|
175
|
+
return (_b = (_a = this.tokens.functionType) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
|
|
176
|
+
}
|
|
177
|
+
getEndTrivia() {
|
|
178
|
+
var _a, _b;
|
|
179
|
+
return (_b = (_a = this.tokens.endFunctionType) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
|
|
136
180
|
}
|
|
137
181
|
/**
|
|
138
182
|
* The range of the function, starting at the 'f' in function or 's' in sub (or the open paren if the keyword is missing),
|
|
139
183
|
* and ending with the last n' in 'end function' or 'b' in 'end sub'
|
|
140
184
|
*/
|
|
141
185
|
get range() {
|
|
142
|
-
|
|
143
|
-
return util_1.default.createRangeFromPositions(((_a = this.functionType) !== null && _a !== void 0 ? _a : this.leftParen).range.start, ((_e = (_d = (_c = (_b = this.end) !== null && _b !== void 0 ? _b : this.body) !== null && _c !== void 0 ? _c : this.returnTypeToken) !== null && _d !== void 0 ? _d : this.asToken) !== null && _e !== void 0 ? _e : this.rightParen).range.end);
|
|
186
|
+
return util_1.default.createBoundingRange(this.tokens.functionType, this.tokens.leftParen, ...this.parameters, this.tokens.rightParen, this.tokens.as, this.returnTypeExpression, this.tokens.endFunctionType);
|
|
144
187
|
}
|
|
145
188
|
transpile(state, name, includeBody = true) {
|
|
189
|
+
var _a, _b, _c;
|
|
146
190
|
let results = [];
|
|
147
191
|
//'function'|'sub'
|
|
148
|
-
results.push(state.transpileToken(this.functionType));
|
|
192
|
+
results.push(state.transpileToken(this.tokens.functionType, 'function'));
|
|
149
193
|
//functionName?
|
|
150
194
|
if (name) {
|
|
151
195
|
results.push(' ', state.transpileToken(name));
|
|
152
196
|
}
|
|
153
197
|
//leftParen
|
|
154
|
-
results.push(state.transpileToken(this.leftParen));
|
|
198
|
+
results.push(state.transpileToken(this.tokens.leftParen));
|
|
155
199
|
//parameters
|
|
156
200
|
for (let i = 0; i < this.parameters.length; i++) {
|
|
157
201
|
let param = this.parameters[i];
|
|
@@ -163,71 +207,130 @@ class FunctionExpression extends Expression {
|
|
|
163
207
|
results.push(param.transpile(state));
|
|
164
208
|
}
|
|
165
209
|
//right paren
|
|
166
|
-
results.push(state.transpileToken(this.rightParen));
|
|
210
|
+
results.push(state.transpileToken(this.tokens.rightParen));
|
|
167
211
|
//as [Type]
|
|
168
|
-
if (this.
|
|
212
|
+
if (!state.options.removeParameterTypes && this.returnTypeExpression) {
|
|
169
213
|
results.push(' ',
|
|
170
214
|
//as
|
|
171
|
-
state.transpileToken(this.
|
|
215
|
+
state.transpileToken(this.tokens.as, 'as'), ' ',
|
|
172
216
|
//return type
|
|
173
|
-
|
|
217
|
+
...this.returnTypeExpression.transpile(state));
|
|
174
218
|
}
|
|
219
|
+
let hasBody = false;
|
|
175
220
|
if (includeBody) {
|
|
176
221
|
state.lineage.unshift(this);
|
|
177
222
|
let body = this.body.transpile(state);
|
|
223
|
+
hasBody = body.length > 0;
|
|
178
224
|
state.lineage.shift();
|
|
179
225
|
results.push(...body);
|
|
180
226
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
results.push(state.indent(), state.transpileToken(this.end));
|
|
227
|
+
const lastLocatable = hasBody ? this.body : (_b = (_a = this.returnTypeExpression) !== null && _a !== void 0 ? _a : this.tokens.leftParen) !== null && _b !== void 0 ? _b : this.tokens.functionType;
|
|
228
|
+
results.push(...state.transpileEndBlockToken(lastLocatable, this.tokens.endFunctionType, `end ${(_c = this.tokens.functionType) !== null && _c !== void 0 ? _c : 'function'}`));
|
|
184
229
|
return results;
|
|
185
230
|
}
|
|
186
|
-
getTypedef(state
|
|
187
|
-
|
|
231
|
+
getTypedef(state) {
|
|
232
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
233
|
+
let results = [
|
|
234
|
+
new source_map_1.SourceNode(1, 0, null, [
|
|
235
|
+
//'function'|'sub'
|
|
236
|
+
(_b = (_a = this.tokens.functionType) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : 'function',
|
|
237
|
+
//functionName?
|
|
238
|
+
...((0, reflection_1.isFunctionStatement)(this.parent) || (0, reflection_1.isMethodStatement)(this.parent) ? [' ', (_d = (_c = this.parent.tokens.name) === null || _c === void 0 ? void 0 : _c.text) !== null && _d !== void 0 ? _d : ''] : []),
|
|
239
|
+
//leftParen
|
|
240
|
+
'(',
|
|
241
|
+
//parameters
|
|
242
|
+
...((_f = (_e = this.parameters) === null || _e === void 0 ? void 0 : _e.map((param, i) => ([
|
|
243
|
+
//separating comma
|
|
244
|
+
i > 0 ? ', ' : '',
|
|
245
|
+
...param.getTypedef(state)
|
|
246
|
+
]))) !== null && _f !== void 0 ? _f : []),
|
|
247
|
+
//right paren
|
|
248
|
+
')',
|
|
249
|
+
//as <ReturnType>
|
|
250
|
+
...(this.returnTypeExpression ? [
|
|
251
|
+
' ',
|
|
252
|
+
(_h = (_g = this.tokens.as) === null || _g === void 0 ? void 0 : _g.text) !== null && _h !== void 0 ? _h : 'as',
|
|
253
|
+
' ',
|
|
254
|
+
...this.returnTypeExpression.getTypedef(state)
|
|
255
|
+
] : []),
|
|
256
|
+
'\n',
|
|
257
|
+
state.indent(),
|
|
258
|
+
//'end sub'|'end function'
|
|
259
|
+
(_k = (_j = this.tokens.endFunctionType) === null || _j === void 0 ? void 0 : _j.text) !== null && _k !== void 0 ? _k : `end ${(_l = this.tokens.functionType) !== null && _l !== void 0 ? _l : 'function'}`
|
|
260
|
+
])
|
|
261
|
+
];
|
|
262
|
+
return results;
|
|
188
263
|
}
|
|
189
264
|
walk(visitor, options) {
|
|
190
|
-
if (options.walkMode &
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
265
|
+
if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
|
|
266
|
+
(0, visitors_2.walkArray)(this.parameters, visitor, options, this);
|
|
267
|
+
(0, visitors_2.walk)(this, 'returnTypeExpression', visitor, options);
|
|
194
268
|
//This is the core of full-program walking...it allows us to step into sub functions
|
|
195
|
-
if (options.walkMode &
|
|
196
|
-
|
|
269
|
+
if (options.walkMode & visitors_2.InternalWalkMode.recurseChildFunctions) {
|
|
270
|
+
(0, visitors_2.walk)(this, 'body', visitor, options);
|
|
197
271
|
}
|
|
198
272
|
}
|
|
199
273
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
274
|
+
getType(options) {
|
|
275
|
+
var _a, _b, _c, _d;
|
|
276
|
+
//if there's a defined return type, use that
|
|
277
|
+
let returnType = (_a = this.returnTypeExpression) === null || _a === void 0 ? void 0 : _a.getType(Object.assign(Object.assign({}, options), { typeChain: undefined }));
|
|
278
|
+
const isSub = ((_b = this.tokens.functionType) === null || _b === void 0 ? void 0 : _b.kind) === TokenKind_1.TokenKind.Sub;
|
|
279
|
+
//if we don't have a return type and this is a sub, set the return type to `void`. else use `dynamic`
|
|
280
|
+
if (!returnType) {
|
|
281
|
+
returnType = isSub ? VoidType_1.VoidType.instance : DynamicType_1.DynamicType.instance;
|
|
282
|
+
}
|
|
283
|
+
const resultType = new types_1.TypedFunctionType(returnType);
|
|
284
|
+
resultType.isSub = isSub;
|
|
203
285
|
for (let param of this.parameters) {
|
|
204
|
-
|
|
286
|
+
resultType.addParameter(param.tokens.name.text, param.getType(Object.assign(Object.assign({}, options), { typeChain: undefined })), !!param.defaultValue);
|
|
287
|
+
}
|
|
288
|
+
// Figure out this function's name if we can
|
|
289
|
+
let funcName = '';
|
|
290
|
+
if ((0, reflection_1.isMethodStatement)(this.parent) || (0, reflection_1.isInterfaceMethodStatement)(this.parent)) {
|
|
291
|
+
funcName = this.parent.getName(Parser_1.ParseMode.BrighterScript);
|
|
292
|
+
if (options.typeChain) {
|
|
293
|
+
// Get the typechain info from the parent class
|
|
294
|
+
(_c = this.parent.parent) === null || _c === void 0 ? void 0 : _c.getType(options);
|
|
295
|
+
}
|
|
205
296
|
}
|
|
206
|
-
|
|
297
|
+
else if ((0, reflection_1.isFunctionStatement)(this.parent)) {
|
|
298
|
+
funcName = this.parent.getName(Parser_1.ParseMode.BrighterScript);
|
|
299
|
+
}
|
|
300
|
+
if (funcName) {
|
|
301
|
+
resultType.setName(funcName);
|
|
302
|
+
}
|
|
303
|
+
(_d = options.typeChain) === null || _d === void 0 ? void 0 : _d.push(new interfaces_1.TypeChainEntry({ name: funcName, type: resultType, data: options.data, astNode: this }));
|
|
304
|
+
return resultType;
|
|
207
305
|
}
|
|
208
306
|
}
|
|
209
307
|
exports.FunctionExpression = FunctionExpression;
|
|
210
|
-
class FunctionParameterExpression extends Expression {
|
|
211
|
-
constructor(
|
|
308
|
+
class FunctionParameterExpression extends AstNode_1.Expression {
|
|
309
|
+
constructor(options) {
|
|
212
310
|
super();
|
|
213
|
-
this.
|
|
214
|
-
this.
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
this.
|
|
311
|
+
this.kind = AstNode_1.AstNodeKind.FunctionParameterExpression;
|
|
312
|
+
this.tokens = {
|
|
313
|
+
name: options.name,
|
|
314
|
+
equals: options.equals,
|
|
315
|
+
as: options.as
|
|
316
|
+
};
|
|
317
|
+
this.defaultValue = options.defaultValue;
|
|
318
|
+
this.typeExpression = options.typeExpression;
|
|
319
|
+
}
|
|
320
|
+
getType(options) {
|
|
321
|
+
var _a, _b, _c, _d, _e;
|
|
322
|
+
const paramType = (_d = (_b = (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.getType(Object.assign(Object.assign({}, options), { flags: 2 /* SymbolTypeFlag.typetime */, typeChain: undefined }))) !== null && _b !== void 0 ? _b : (_c = this.defaultValue) === null || _c === void 0 ? void 0 : _c.getType(Object.assign(Object.assign({}, options), { flags: 1 /* SymbolTypeFlag.runtime */, typeChain: undefined }))) !== null && _d !== void 0 ? _d : DynamicType_1.DynamicType.instance;
|
|
323
|
+
(_e = options.typeChain) === null || _e === void 0 ? void 0 : _e.push(new interfaces_1.TypeChainEntry({ name: this.tokens.name.text, type: paramType, data: options.data, astNode: this }));
|
|
324
|
+
return paramType;
|
|
220
325
|
}
|
|
221
326
|
get range() {
|
|
222
|
-
return
|
|
223
|
-
start: this.name.range.start,
|
|
224
|
-
end: this.typeToken ? this.typeToken.range.end : this.name.range.end
|
|
225
|
-
};
|
|
327
|
+
return util_1.default.createBoundingRange(this.tokens.name, this.tokens.as, this.typeExpression, this.tokens.equals, this.defaultValue);
|
|
226
328
|
}
|
|
227
329
|
transpile(state) {
|
|
330
|
+
var _a, _b;
|
|
228
331
|
let result = [
|
|
229
332
|
//name
|
|
230
|
-
state.transpileToken(this.name)
|
|
333
|
+
state.transpileToken(this.tokens.name)
|
|
231
334
|
];
|
|
232
335
|
//default value
|
|
233
336
|
if (this.defaultValue) {
|
|
@@ -235,211 +338,271 @@ class FunctionParameterExpression extends Expression {
|
|
|
235
338
|
result.push(this.defaultValue.transpile(state));
|
|
236
339
|
}
|
|
237
340
|
//type declaration
|
|
238
|
-
if (this.
|
|
341
|
+
if (this.typeExpression && !state.options.removeParameterTypes) {
|
|
239
342
|
result.push(' ');
|
|
240
|
-
result.push(state.transpileToken(this.
|
|
343
|
+
result.push(state.transpileToken(this.tokens.as, 'as'));
|
|
241
344
|
result.push(' ');
|
|
242
|
-
result.push(
|
|
345
|
+
result.push(...((_b = (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.transpile(state)) !== null && _b !== void 0 ? _b : []));
|
|
243
346
|
}
|
|
244
347
|
return result;
|
|
245
348
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
constructor(
|
|
259
|
-
//if this is a `DottedGetExpression`, it must be comprised only of `VariableExpression`s
|
|
260
|
-
expression) {
|
|
261
|
-
super();
|
|
262
|
-
this.expression = expression;
|
|
263
|
-
this.range = expression.range;
|
|
264
|
-
}
|
|
265
|
-
transpile(state) {
|
|
266
|
-
return [
|
|
267
|
-
state.sourceNode(this, this.getName(Parser_1.ParseMode.BrightScript))
|
|
268
|
-
];
|
|
269
|
-
}
|
|
270
|
-
getNameParts() {
|
|
271
|
-
let parts = [];
|
|
272
|
-
if (reflection_1.isVariableExpression(this.expression)) {
|
|
273
|
-
parts.push(this.expression.name.text);
|
|
274
|
-
}
|
|
275
|
-
else {
|
|
276
|
-
let expr = this.expression;
|
|
277
|
-
parts.push(expr.name.text);
|
|
278
|
-
while (reflection_1.isVariableExpression(expr) === false) {
|
|
279
|
-
expr = expr.obj;
|
|
280
|
-
parts.unshift(expr.name.text);
|
|
349
|
+
getTypedef(state) {
|
|
350
|
+
var _a, _b;
|
|
351
|
+
const results = [this.tokens.name.text];
|
|
352
|
+
if (this.defaultValue) {
|
|
353
|
+
results.push(' = ', ...this.defaultValue.transpile(state));
|
|
354
|
+
}
|
|
355
|
+
if (this.tokens.as) {
|
|
356
|
+
results.push(' as ');
|
|
357
|
+
// TODO: Is this conditional needed? Will typeToken always exist
|
|
358
|
+
// so long as `asToken` exists?
|
|
359
|
+
if (this.typeExpression) {
|
|
360
|
+
results.push(...((_b = (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.getTypedef(state)) !== null && _b !== void 0 ? _b : ['']));
|
|
281
361
|
}
|
|
282
362
|
}
|
|
283
|
-
return
|
|
284
|
-
}
|
|
285
|
-
getName(parseMode) {
|
|
286
|
-
if (parseMode === Parser_1.ParseMode.BrighterScript) {
|
|
287
|
-
return this.getNameParts().join('.');
|
|
288
|
-
}
|
|
289
|
-
else {
|
|
290
|
-
return this.getNameParts().join('_');
|
|
291
|
-
}
|
|
363
|
+
return results;
|
|
292
364
|
}
|
|
293
365
|
walk(visitor, options) {
|
|
294
|
-
|
|
295
|
-
|
|
366
|
+
// eslint-disable-next-line no-bitwise
|
|
367
|
+
if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
|
|
368
|
+
(0, visitors_2.walk)(this, 'defaultValue', visitor, options);
|
|
369
|
+
(0, visitors_2.walk)(this, 'typeExpression', visitor, options);
|
|
296
370
|
}
|
|
297
371
|
}
|
|
372
|
+
getLeadingTrivia() {
|
|
373
|
+
var _a;
|
|
374
|
+
return (_a = this.tokens.name.leadingTrivia) !== null && _a !== void 0 ? _a : [];
|
|
375
|
+
}
|
|
298
376
|
}
|
|
299
|
-
exports.
|
|
300
|
-
class DottedGetExpression extends Expression {
|
|
301
|
-
constructor(
|
|
377
|
+
exports.FunctionParameterExpression = FunctionParameterExpression;
|
|
378
|
+
class DottedGetExpression extends AstNode_1.Expression {
|
|
379
|
+
constructor(options) {
|
|
302
380
|
super();
|
|
303
|
-
this.
|
|
304
|
-
this.
|
|
305
|
-
|
|
306
|
-
|
|
381
|
+
this.kind = AstNode_1.AstNodeKind.DottedGetExpression;
|
|
382
|
+
this.tokens = {
|
|
383
|
+
name: options.name,
|
|
384
|
+
dot: options.dot
|
|
385
|
+
};
|
|
386
|
+
this.obj = options.obj;
|
|
387
|
+
this.range = util_1.default.createBoundingRange(this.obj, this.tokens.dot, this.tokens.name);
|
|
307
388
|
}
|
|
308
389
|
transpile(state) {
|
|
309
390
|
//if the callee starts with a namespace name, transpile the name
|
|
310
391
|
if (state.file.calleeStartsWithNamespace(this)) {
|
|
311
|
-
return
|
|
392
|
+
return [
|
|
393
|
+
state.sourceNode(this, this.getName(Parser_1.ParseMode.BrightScript))
|
|
394
|
+
];
|
|
312
395
|
}
|
|
313
396
|
else {
|
|
314
397
|
return [
|
|
315
398
|
...this.obj.transpile(state),
|
|
316
|
-
'.',
|
|
317
|
-
state.transpileToken(this.name)
|
|
399
|
+
state.transpileToken(this.tokens.dot, '.'),
|
|
400
|
+
state.transpileToken(this.tokens.name)
|
|
318
401
|
];
|
|
319
402
|
}
|
|
320
403
|
}
|
|
321
404
|
walk(visitor, options) {
|
|
322
|
-
if (options.walkMode &
|
|
323
|
-
|
|
324
|
-
}
|
|
405
|
+
if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
|
|
406
|
+
(0, visitors_2.walk)(this, 'obj', visitor, options);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
getType(options) {
|
|
410
|
+
var _a, _b, _c, _d, _e, _f;
|
|
411
|
+
const objType = (_a = this.obj) === null || _a === void 0 ? void 0 : _a.getType(options);
|
|
412
|
+
let result = objType === null || objType === void 0 ? void 0 : objType.getMemberType((_b = this.tokens.name) === null || _b === void 0 ? void 0 : _b.text, options);
|
|
413
|
+
if (util_1.default.isClassUsedAsFunction(result, this, options)) {
|
|
414
|
+
// treat this class constructor as a function
|
|
415
|
+
result = FunctionType_1.FunctionType.instance;
|
|
416
|
+
}
|
|
417
|
+
(_c = options.typeChain) === null || _c === void 0 ? void 0 : _c.push(new interfaces_1.TypeChainEntry({
|
|
418
|
+
name: (_d = this.tokens.name) === null || _d === void 0 ? void 0 : _d.text,
|
|
419
|
+
type: result,
|
|
420
|
+
data: options.data,
|
|
421
|
+
range: (_f = (_e = this.tokens.name) === null || _e === void 0 ? void 0 : _e.range) !== null && _f !== void 0 ? _f : this.range,
|
|
422
|
+
astNode: this
|
|
423
|
+
}));
|
|
424
|
+
if (result ||
|
|
425
|
+
options.flags & 2 /* SymbolTypeFlag.typetime */ ||
|
|
426
|
+
((0, reflection_1.isPrimitiveType)(objType) || (0, reflection_1.isCallableType)(objType))) {
|
|
427
|
+
// All types should be known at typeTime, or the obj is well known
|
|
428
|
+
return result;
|
|
429
|
+
}
|
|
430
|
+
// It is possible at runtime that a value has been added dynamically to an object, or something
|
|
431
|
+
// TODO: maybe have a strict flag on this?
|
|
432
|
+
return DynamicType_1.DynamicType.instance;
|
|
433
|
+
}
|
|
434
|
+
getName(parseMode) {
|
|
435
|
+
return util_1.default.getAllDottedGetPartsAsString(this, parseMode);
|
|
436
|
+
}
|
|
437
|
+
getLeadingTrivia() {
|
|
438
|
+
return this.obj.getLeadingTrivia();
|
|
325
439
|
}
|
|
326
440
|
}
|
|
327
441
|
exports.DottedGetExpression = DottedGetExpression;
|
|
328
|
-
class XmlAttributeGetExpression extends Expression {
|
|
329
|
-
constructor(
|
|
442
|
+
class XmlAttributeGetExpression extends AstNode_1.Expression {
|
|
443
|
+
constructor(options) {
|
|
330
444
|
super();
|
|
331
|
-
this.
|
|
332
|
-
this.
|
|
333
|
-
this.
|
|
334
|
-
this.range = util_1.default.
|
|
445
|
+
this.kind = AstNode_1.AstNodeKind.XmlAttributeGetExpression;
|
|
446
|
+
this.obj = options.obj;
|
|
447
|
+
this.tokens = { at: options.at, name: options.name };
|
|
448
|
+
this.range = util_1.default.createBoundingRange(this.obj, this.tokens.at, this.tokens.name);
|
|
335
449
|
}
|
|
336
450
|
transpile(state) {
|
|
337
451
|
return [
|
|
338
452
|
...this.obj.transpile(state),
|
|
339
|
-
'@',
|
|
340
|
-
state.transpileToken(this.name)
|
|
453
|
+
state.transpileToken(this.tokens.at, '@'),
|
|
454
|
+
state.transpileToken(this.tokens.name)
|
|
341
455
|
];
|
|
342
456
|
}
|
|
343
457
|
walk(visitor, options) {
|
|
344
|
-
if (options.walkMode &
|
|
345
|
-
|
|
458
|
+
if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
|
|
459
|
+
(0, visitors_2.walk)(this, 'obj', visitor, options);
|
|
346
460
|
}
|
|
347
461
|
}
|
|
462
|
+
getLeadingTrivia() {
|
|
463
|
+
return this.obj.getLeadingTrivia();
|
|
464
|
+
}
|
|
348
465
|
}
|
|
349
466
|
exports.XmlAttributeGetExpression = XmlAttributeGetExpression;
|
|
350
|
-
class IndexedGetExpression extends Expression {
|
|
351
|
-
constructor(
|
|
467
|
+
class IndexedGetExpression extends AstNode_1.Expression {
|
|
468
|
+
constructor(options) {
|
|
352
469
|
super();
|
|
353
|
-
this.
|
|
354
|
-
this.
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
470
|
+
this.kind = AstNode_1.AstNodeKind.IndexedGetExpression;
|
|
471
|
+
this.tokens = {
|
|
472
|
+
openingSquare: options.openingSquare,
|
|
473
|
+
closingSquare: options.closingSquare,
|
|
474
|
+
questionDot: options.questionDot
|
|
475
|
+
};
|
|
476
|
+
this.obj = options.obj;
|
|
477
|
+
this.indexes = options.indexes;
|
|
478
|
+
this.range = util_1.default.createBoundingRange(this.obj, this.tokens.openingSquare, this.tokens.questionDot, this.tokens.openingSquare, ...this.indexes, this.tokens.closingSquare);
|
|
358
479
|
}
|
|
359
480
|
transpile(state) {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
481
|
+
var _a;
|
|
482
|
+
const result = [];
|
|
483
|
+
result.push(...this.obj.transpile(state), this.tokens.questionDot ? state.transpileToken(this.tokens.questionDot) : '', state.transpileToken(this.tokens.openingSquare, '['));
|
|
484
|
+
for (let i = 0; i < this.indexes.length; i++) {
|
|
485
|
+
//add comma between indexes
|
|
486
|
+
if (i > 0) {
|
|
487
|
+
result.push(', ');
|
|
488
|
+
}
|
|
489
|
+
let index = this.indexes[i];
|
|
490
|
+
result.push(...((_a = index === null || index === void 0 ? void 0 : index.transpile(state)) !== null && _a !== void 0 ? _a : []));
|
|
491
|
+
}
|
|
492
|
+
result.push(state.transpileToken(this.tokens.closingSquare, ']'));
|
|
493
|
+
return result;
|
|
366
494
|
}
|
|
367
495
|
walk(visitor, options) {
|
|
368
|
-
if (options.walkMode &
|
|
369
|
-
|
|
370
|
-
|
|
496
|
+
if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
|
|
497
|
+
(0, visitors_2.walk)(this, 'obj', visitor, options);
|
|
498
|
+
(0, visitors_2.walkArray)(this.indexes, visitor, options, this);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
getType(options) {
|
|
502
|
+
const objType = this.obj.getType(options);
|
|
503
|
+
if ((0, reflection_1.isArrayType)(objType)) {
|
|
504
|
+
// This is used on an array. What is the default type of that array?
|
|
505
|
+
return objType.defaultType;
|
|
371
506
|
}
|
|
507
|
+
return super.getType(options);
|
|
508
|
+
}
|
|
509
|
+
getLeadingTrivia() {
|
|
510
|
+
return this.obj.getLeadingTrivia();
|
|
372
511
|
}
|
|
373
512
|
}
|
|
374
513
|
exports.IndexedGetExpression = IndexedGetExpression;
|
|
375
|
-
class GroupingExpression extends Expression {
|
|
376
|
-
constructor(
|
|
514
|
+
class GroupingExpression extends AstNode_1.Expression {
|
|
515
|
+
constructor(options) {
|
|
377
516
|
super();
|
|
378
|
-
this.
|
|
379
|
-
this.
|
|
380
|
-
|
|
517
|
+
this.kind = AstNode_1.AstNodeKind.GroupingExpression;
|
|
518
|
+
this.tokens = {
|
|
519
|
+
rightParen: options.rightParen,
|
|
520
|
+
leftParen: options.leftParen
|
|
521
|
+
};
|
|
522
|
+
this.expression = options.expression;
|
|
523
|
+
this.range = util_1.default.createBoundingRange(this.tokens.leftParen, this.expression, this.tokens.rightParen);
|
|
381
524
|
}
|
|
382
525
|
transpile(state) {
|
|
526
|
+
if ((0, reflection_1.isTypecastExpression)(this.expression)) {
|
|
527
|
+
return this.expression.transpile(state);
|
|
528
|
+
}
|
|
383
529
|
return [
|
|
384
|
-
state.transpileToken(this.tokens.
|
|
530
|
+
state.transpileToken(this.tokens.leftParen),
|
|
385
531
|
...this.expression.transpile(state),
|
|
386
|
-
state.transpileToken(this.tokens.
|
|
532
|
+
state.transpileToken(this.tokens.rightParen)
|
|
387
533
|
];
|
|
388
534
|
}
|
|
389
535
|
walk(visitor, options) {
|
|
390
|
-
if (options.walkMode &
|
|
391
|
-
|
|
536
|
+
if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
|
|
537
|
+
(0, visitors_2.walk)(this, 'expression', visitor, options);
|
|
392
538
|
}
|
|
393
539
|
}
|
|
540
|
+
getType(options) {
|
|
541
|
+
return this.expression.getType(options);
|
|
542
|
+
}
|
|
543
|
+
getLeadingTrivia() {
|
|
544
|
+
var _a, _b;
|
|
545
|
+
return (_b = (_a = this.tokens.leftParen) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
|
|
546
|
+
}
|
|
394
547
|
}
|
|
395
548
|
exports.GroupingExpression = GroupingExpression;
|
|
396
|
-
class LiteralExpression extends Expression {
|
|
397
|
-
constructor(
|
|
549
|
+
class LiteralExpression extends AstNode_1.Expression {
|
|
550
|
+
constructor(options) {
|
|
398
551
|
super();
|
|
399
|
-
this.
|
|
400
|
-
this.
|
|
552
|
+
this.kind = AstNode_1.AstNodeKind.LiteralExpression;
|
|
553
|
+
this.tokens = {
|
|
554
|
+
value: options.value
|
|
555
|
+
};
|
|
401
556
|
}
|
|
402
557
|
get range() {
|
|
403
|
-
return this.
|
|
558
|
+
return this.tokens.value.range;
|
|
559
|
+
}
|
|
560
|
+
getType(options) {
|
|
561
|
+
return util_1.default.tokenToBscType(this.tokens.value);
|
|
404
562
|
}
|
|
405
563
|
transpile(state) {
|
|
406
564
|
let text;
|
|
407
|
-
if (this.
|
|
565
|
+
if (this.tokens.value.kind === TokenKind_1.TokenKind.TemplateStringQuasi) {
|
|
408
566
|
//wrap quasis with quotes (and escape inner quotemarks)
|
|
409
|
-
text = `"${this.
|
|
567
|
+
text = `"${this.tokens.value.text.replace(/"/g, '""')}"`;
|
|
410
568
|
}
|
|
411
|
-
else if (
|
|
412
|
-
text = this.
|
|
569
|
+
else if (this.tokens.value.kind === TokenKind_1.TokenKind.StringLiteral) {
|
|
570
|
+
text = this.tokens.value.text;
|
|
413
571
|
//add trailing quotemark if it's missing. We will have already generated a diagnostic for this.
|
|
414
572
|
if (text.endsWith('"') === false) {
|
|
415
573
|
text += '"';
|
|
416
574
|
}
|
|
417
575
|
}
|
|
418
576
|
else {
|
|
419
|
-
text = this.
|
|
577
|
+
text = this.tokens.value.text;
|
|
420
578
|
}
|
|
421
579
|
return [
|
|
422
|
-
state.
|
|
580
|
+
state.transpileToken(Object.assign(Object.assign({}, this.tokens.value), { text: text }))
|
|
423
581
|
];
|
|
424
582
|
}
|
|
425
583
|
walk(visitor, options) {
|
|
426
584
|
//nothing to walk
|
|
427
585
|
}
|
|
586
|
+
getLeadingTrivia() {
|
|
587
|
+
var _a;
|
|
588
|
+
return (_a = this.tokens.value.leadingTrivia) !== null && _a !== void 0 ? _a : [];
|
|
589
|
+
}
|
|
428
590
|
}
|
|
429
591
|
exports.LiteralExpression = LiteralExpression;
|
|
430
592
|
/**
|
|
431
593
|
* This is a special expression only used within template strings. It exists so we can prevent producing lots of empty strings
|
|
432
594
|
* during template string transpile by identifying these expressions explicitly and skipping the bslib_toString around them
|
|
433
595
|
*/
|
|
434
|
-
class EscapedCharCodeLiteralExpression extends Expression {
|
|
435
|
-
constructor(
|
|
596
|
+
class EscapedCharCodeLiteralExpression extends AstNode_1.Expression {
|
|
597
|
+
constructor(options) {
|
|
436
598
|
super();
|
|
437
|
-
this.
|
|
438
|
-
this.
|
|
599
|
+
this.kind = AstNode_1.AstNodeKind.EscapedCharCodeLiteralExpression;
|
|
600
|
+
this.tokens = { value: options.value };
|
|
601
|
+
this.range = this.tokens.value.range;
|
|
439
602
|
}
|
|
440
603
|
transpile(state) {
|
|
441
604
|
return [
|
|
442
|
-
state.sourceNode(this, `chr(${this.
|
|
605
|
+
state.sourceNode(this, `chr(${this.tokens.value.charCode})`)
|
|
443
606
|
];
|
|
444
607
|
}
|
|
445
608
|
walk(visitor, options) {
|
|
@@ -447,101 +610,106 @@ class EscapedCharCodeLiteralExpression extends Expression {
|
|
|
447
610
|
}
|
|
448
611
|
}
|
|
449
612
|
exports.EscapedCharCodeLiteralExpression = EscapedCharCodeLiteralExpression;
|
|
450
|
-
class ArrayLiteralExpression extends Expression {
|
|
451
|
-
constructor(
|
|
613
|
+
class ArrayLiteralExpression extends AstNode_1.Expression {
|
|
614
|
+
constructor(options) {
|
|
452
615
|
super();
|
|
453
|
-
this.
|
|
454
|
-
this.
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
616
|
+
this.kind = AstNode_1.AstNodeKind.ArrayLiteralExpression;
|
|
617
|
+
this.tokens = {
|
|
618
|
+
open: options.open,
|
|
619
|
+
close: options.close
|
|
620
|
+
};
|
|
621
|
+
this.elements = options.elements;
|
|
622
|
+
this.range = util_1.default.createBoundingRange(this.tokens.open, ...this.elements, this.tokens.close);
|
|
458
623
|
}
|
|
459
624
|
transpile(state) {
|
|
625
|
+
var _a;
|
|
460
626
|
let result = [];
|
|
461
|
-
result.push(state.transpileToken(this.open));
|
|
627
|
+
result.push(state.transpileToken(this.tokens.open, '['));
|
|
462
628
|
let hasChildren = this.elements.length > 0;
|
|
463
629
|
state.blockDepth++;
|
|
464
630
|
for (let i = 0; i < this.elements.length; i++) {
|
|
465
631
|
let previousElement = this.elements[i - 1];
|
|
466
632
|
let element = this.elements[i];
|
|
467
|
-
if (
|
|
468
|
-
|
|
469
|
-
if (util_1.default.linesTouch(this.open, element) || util_1.default.linesTouch(previousElement, element)) {
|
|
470
|
-
result.push(' ');
|
|
471
|
-
}
|
|
472
|
-
else {
|
|
473
|
-
result.push('\n', state.indent());
|
|
474
|
-
}
|
|
475
|
-
state.lineage.unshift(this);
|
|
476
|
-
result.push(element.transpile(state));
|
|
477
|
-
state.lineage.shift();
|
|
633
|
+
if (util_1.default.isLeadingCommentOnSameLine(previousElement !== null && previousElement !== void 0 ? previousElement : this.tokens.open, element)) {
|
|
634
|
+
result.push(' ');
|
|
478
635
|
}
|
|
479
636
|
else {
|
|
480
|
-
result.push('\n');
|
|
481
|
-
result.push(state.indent(), ...element.transpile(state));
|
|
482
|
-
//add a comma if we know there will be another non-comment statement after this
|
|
483
|
-
for (let j = i + 1; j < this.elements.length; j++) {
|
|
484
|
-
let el = this.elements[j];
|
|
485
|
-
//add a comma if there will be another element after this
|
|
486
|
-
if (reflection_1.isCommentStatement(el) === false) {
|
|
487
|
-
result.push(',');
|
|
488
|
-
break;
|
|
489
|
-
}
|
|
490
|
-
}
|
|
637
|
+
result.push('\n', state.indent());
|
|
491
638
|
}
|
|
639
|
+
result.push(...element.transpile(state));
|
|
492
640
|
}
|
|
493
641
|
state.blockDepth--;
|
|
494
642
|
//add a newline between open and close if there are elements
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
result.push(state.indent());
|
|
498
|
-
}
|
|
499
|
-
result.push(state.transpileToken(this.close));
|
|
643
|
+
const lastLocatable = (_a = this.elements[this.elements.length - 1]) !== null && _a !== void 0 ? _a : this.tokens.open;
|
|
644
|
+
result.push(...state.transpileEndBlockToken(lastLocatable, this.tokens.close, ']', hasChildren));
|
|
500
645
|
return result;
|
|
501
646
|
}
|
|
502
647
|
walk(visitor, options) {
|
|
503
|
-
if (options.walkMode &
|
|
504
|
-
|
|
505
|
-
visitors_1.walk(this.elements, i, visitor, options, this);
|
|
506
|
-
}
|
|
648
|
+
if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
|
|
649
|
+
(0, visitors_2.walkArray)(this.elements, visitor, options, this);
|
|
507
650
|
}
|
|
508
651
|
}
|
|
652
|
+
getType(options) {
|
|
653
|
+
const innerTypes = this.elements.map(expr => expr.getType(options));
|
|
654
|
+
return new ArrayType_1.ArrayType(...innerTypes);
|
|
655
|
+
}
|
|
656
|
+
getLeadingTrivia() {
|
|
657
|
+
var _a, _b;
|
|
658
|
+
return (_b = (_a = this.tokens.open) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
|
|
659
|
+
}
|
|
660
|
+
getEndTrivia() {
|
|
661
|
+
var _a, _b;
|
|
662
|
+
return (_b = (_a = this.tokens.close) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
|
|
663
|
+
}
|
|
509
664
|
}
|
|
510
665
|
exports.ArrayLiteralExpression = ArrayLiteralExpression;
|
|
511
|
-
class AAMemberExpression extends Expression {
|
|
512
|
-
constructor(
|
|
513
|
-
/** The expression evaluated to determine the member's initial value. */
|
|
514
|
-
value) {
|
|
666
|
+
class AAMemberExpression extends AstNode_1.Expression {
|
|
667
|
+
constructor(options) {
|
|
515
668
|
super();
|
|
516
|
-
this.
|
|
517
|
-
this.
|
|
518
|
-
|
|
519
|
-
|
|
669
|
+
this.kind = AstNode_1.AstNodeKind.AAMemberExpression;
|
|
670
|
+
this.tokens = {
|
|
671
|
+
key: options.key,
|
|
672
|
+
colon: options.colon,
|
|
673
|
+
comma: options.comma
|
|
674
|
+
};
|
|
675
|
+
this.value = options.value;
|
|
676
|
+
this.range = util_1.default.createBoundingRange(this.tokens.key, this.tokens.colon, this.value);
|
|
520
677
|
}
|
|
521
678
|
transpile(state) {
|
|
522
679
|
//TODO move the logic from AALiteralExpression loop into this function
|
|
523
680
|
return [];
|
|
524
681
|
}
|
|
525
682
|
walk(visitor, options) {
|
|
526
|
-
|
|
683
|
+
(0, visitors_2.walk)(this, 'value', visitor, options);
|
|
684
|
+
}
|
|
685
|
+
getType(options) {
|
|
686
|
+
return this.value.getType(options);
|
|
687
|
+
}
|
|
688
|
+
getLeadingTrivia() {
|
|
689
|
+
var _a;
|
|
690
|
+
return (_a = this.tokens.key.leadingTrivia) !== null && _a !== void 0 ? _a : [];
|
|
527
691
|
}
|
|
528
692
|
}
|
|
529
693
|
exports.AAMemberExpression = AAMemberExpression;
|
|
530
|
-
class AALiteralExpression extends Expression {
|
|
531
|
-
constructor(
|
|
694
|
+
class AALiteralExpression extends AstNode_1.Expression {
|
|
695
|
+
constructor(options) {
|
|
532
696
|
super();
|
|
533
|
-
this.
|
|
534
|
-
this.
|
|
535
|
-
|
|
536
|
-
|
|
697
|
+
this.kind = AstNode_1.AstNodeKind.AALiteralExpression;
|
|
698
|
+
this.tokens = {
|
|
699
|
+
open: options.open,
|
|
700
|
+
close: options.close
|
|
701
|
+
};
|
|
702
|
+
this.elements = options.elements;
|
|
703
|
+
this.range = util_1.default.createBoundingRange(this.tokens.open, ...this.elements, this.tokens.close);
|
|
537
704
|
}
|
|
538
705
|
transpile(state) {
|
|
706
|
+
var _a;
|
|
539
707
|
let result = [];
|
|
540
708
|
//open curly
|
|
541
|
-
result.push(state.transpileToken(this.open));
|
|
709
|
+
result.push(state.transpileToken(this.tokens.open, '{'));
|
|
542
710
|
let hasChildren = this.elements.length > 0;
|
|
543
711
|
//add newline if the object has children and the first child isn't a comment starting on the same line as opening curly
|
|
544
|
-
if (hasChildren &&
|
|
712
|
+
if (hasChildren && !util_1.default.isLeadingCommentOnSameLine(this.tokens.open, this.elements[0])) {
|
|
545
713
|
result.push('\n');
|
|
546
714
|
}
|
|
547
715
|
state.blockDepth++;
|
|
@@ -550,170 +718,235 @@ class AALiteralExpression extends Expression {
|
|
|
550
718
|
let previousElement = this.elements[i - 1];
|
|
551
719
|
let nextElement = this.elements[i + 1];
|
|
552
720
|
//don't indent if comment is same-line
|
|
553
|
-
if (
|
|
554
|
-
|
|
721
|
+
if (util_1.default.isLeadingCommentOnSameLine(this.tokens.open, element) ||
|
|
722
|
+
util_1.default.isLeadingCommentOnSameLine(previousElement, element)) {
|
|
555
723
|
result.push(' ');
|
|
556
|
-
//indent line
|
|
557
724
|
}
|
|
558
725
|
else {
|
|
726
|
+
//indent line
|
|
559
727
|
result.push(state.indent());
|
|
560
728
|
}
|
|
561
|
-
//
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
result.push(state.transpileToken(element.keyToken));
|
|
568
|
-
//colon
|
|
569
|
-
result.push(state.transpileToken(element.colonToken), ' ');
|
|
570
|
-
//determine if comments are the only members left in the array
|
|
571
|
-
let onlyCommentsRemaining = true;
|
|
572
|
-
for (let j = i + 1; j < this.elements.length; j++) {
|
|
573
|
-
if (reflection_1.isCommentStatement(this.elements[j]) === false) {
|
|
574
|
-
onlyCommentsRemaining = false;
|
|
575
|
-
break;
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
//value
|
|
579
|
-
result.push(...element.value.transpile(state));
|
|
580
|
-
//add trailing comma if not final element (excluding comments)
|
|
581
|
-
if (i !== this.elements.length - 1 && onlyCommentsRemaining === false) {
|
|
582
|
-
result.push(',');
|
|
583
|
-
}
|
|
584
|
-
}
|
|
729
|
+
//key
|
|
730
|
+
result.push(state.transpileToken(element.tokens.key));
|
|
731
|
+
//colon
|
|
732
|
+
result.push(state.transpileToken(element.tokens.colon, ':'), ' ');
|
|
733
|
+
//value
|
|
734
|
+
result.push(...element.value.transpile(state));
|
|
585
735
|
//if next element is a same-line comment, skip the newline
|
|
586
|
-
if (nextElement &&
|
|
736
|
+
if (nextElement && !util_1.default.isLeadingCommentOnSameLine(element, nextElement)) {
|
|
587
737
|
//add a newline between statements
|
|
588
|
-
}
|
|
589
|
-
else {
|
|
590
738
|
result.push('\n');
|
|
591
739
|
}
|
|
592
740
|
}
|
|
593
741
|
state.blockDepth--;
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
result.push(state.indent());
|
|
597
|
-
}
|
|
598
|
-
//close curly
|
|
599
|
-
result.push(state.transpileToken(this.close));
|
|
742
|
+
const lastElement = (_a = this.elements[this.elements.length - 1]) !== null && _a !== void 0 ? _a : this.tokens.open;
|
|
743
|
+
result.push(...state.transpileEndBlockToken(lastElement, this.tokens.close, '}', hasChildren));
|
|
600
744
|
return result;
|
|
601
745
|
}
|
|
602
746
|
walk(visitor, options) {
|
|
603
|
-
if (options.walkMode &
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
747
|
+
if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
|
|
748
|
+
(0, visitors_2.walkArray)(this.elements, visitor, options, this);
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
getType(options) {
|
|
752
|
+
const resultType = new AssociativeArrayType_1.AssociativeArrayType();
|
|
753
|
+
resultType.addBuiltInInterfaces();
|
|
754
|
+
for (const element of this.elements) {
|
|
755
|
+
if ((0, reflection_1.isAAMemberExpression)(element)) {
|
|
756
|
+
resultType.addMember(element.tokens.key.text, { definingNode: element }, element.getType(options), 1 /* SymbolTypeFlag.runtime */);
|
|
611
757
|
}
|
|
612
758
|
}
|
|
759
|
+
return resultType;
|
|
760
|
+
}
|
|
761
|
+
getLeadingTrivia() {
|
|
762
|
+
var _a, _b;
|
|
763
|
+
return (_b = (_a = this.tokens.open) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
|
|
764
|
+
}
|
|
765
|
+
getEndTrivia() {
|
|
766
|
+
var _a, _b;
|
|
767
|
+
return (_b = (_a = this.tokens.close) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
|
|
613
768
|
}
|
|
614
769
|
}
|
|
615
770
|
exports.AALiteralExpression = AALiteralExpression;
|
|
616
|
-
class UnaryExpression extends Expression {
|
|
617
|
-
constructor(
|
|
771
|
+
class UnaryExpression extends AstNode_1.Expression {
|
|
772
|
+
constructor(options) {
|
|
618
773
|
super();
|
|
619
|
-
this.
|
|
620
|
-
this.
|
|
621
|
-
|
|
774
|
+
this.kind = AstNode_1.AstNodeKind.UnaryExpression;
|
|
775
|
+
this.tokens = {
|
|
776
|
+
operator: options.operator
|
|
777
|
+
};
|
|
778
|
+
this.right = options.right;
|
|
779
|
+
this.range = util_1.default.createBoundingRange(this.tokens.operator, this.right);
|
|
622
780
|
}
|
|
623
781
|
transpile(state) {
|
|
782
|
+
let separatingWhitespace;
|
|
783
|
+
if ((0, reflection_1.isVariableExpression)(this.right)) {
|
|
784
|
+
separatingWhitespace = this.right.tokens.name.leadingWhitespace;
|
|
785
|
+
}
|
|
786
|
+
else if ((0, reflection_1.isLiteralExpression)(this.right)) {
|
|
787
|
+
separatingWhitespace = this.right.tokens.value.leadingWhitespace;
|
|
788
|
+
}
|
|
789
|
+
else {
|
|
790
|
+
separatingWhitespace = ' ';
|
|
791
|
+
}
|
|
624
792
|
return [
|
|
625
|
-
state.transpileToken(this.operator),
|
|
626
|
-
|
|
793
|
+
state.transpileToken(this.tokens.operator),
|
|
794
|
+
separatingWhitespace,
|
|
627
795
|
...this.right.transpile(state)
|
|
628
796
|
];
|
|
629
797
|
}
|
|
630
798
|
walk(visitor, options) {
|
|
631
|
-
if (options.walkMode &
|
|
632
|
-
|
|
799
|
+
if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
|
|
800
|
+
(0, visitors_2.walk)(this, 'right', visitor, options);
|
|
633
801
|
}
|
|
634
802
|
}
|
|
803
|
+
getType(options) {
|
|
804
|
+
return util_1.default.unaryOperatorResultType(this.tokens.operator, this.right.getType(options));
|
|
805
|
+
}
|
|
806
|
+
getLeadingTrivia() {
|
|
807
|
+
var _a;
|
|
808
|
+
return (_a = this.tokens.operator.leadingTrivia) !== null && _a !== void 0 ? _a : [];
|
|
809
|
+
}
|
|
635
810
|
}
|
|
636
811
|
exports.UnaryExpression = UnaryExpression;
|
|
637
|
-
class VariableExpression extends Expression {
|
|
638
|
-
constructor(
|
|
812
|
+
class VariableExpression extends AstNode_1.Expression {
|
|
813
|
+
constructor(options) {
|
|
814
|
+
var _a;
|
|
639
815
|
super();
|
|
640
|
-
this.
|
|
641
|
-
this.
|
|
642
|
-
|
|
816
|
+
this.kind = AstNode_1.AstNodeKind.VariableExpression;
|
|
817
|
+
this.tokens = {
|
|
818
|
+
name: options.name
|
|
819
|
+
};
|
|
820
|
+
this.range = (_a = this.tokens.name) === null || _a === void 0 ? void 0 : _a.range;
|
|
643
821
|
}
|
|
644
822
|
getName(parseMode) {
|
|
645
|
-
return
|
|
823
|
+
return this.tokens.name.text;
|
|
646
824
|
}
|
|
647
825
|
transpile(state) {
|
|
648
|
-
var _a;
|
|
649
826
|
let result = [];
|
|
827
|
+
const namespace = this.findAncestor(reflection_1.isNamespaceStatement);
|
|
650
828
|
//if the callee is the name of a known namespace function
|
|
651
|
-
if (state.file.calleeIsKnownNamespaceFunction(this,
|
|
829
|
+
if (namespace && state.file.calleeIsKnownNamespaceFunction(this, namespace.getName(Parser_1.ParseMode.BrighterScript))) {
|
|
652
830
|
result.push(state.sourceNode(this, [
|
|
653
|
-
|
|
831
|
+
namespace.getName(Parser_1.ParseMode.BrightScript),
|
|
654
832
|
'_',
|
|
655
833
|
this.getName(Parser_1.ParseMode.BrightScript)
|
|
656
834
|
]));
|
|
657
835
|
//transpile normally
|
|
658
836
|
}
|
|
659
837
|
else {
|
|
660
|
-
result.push(state.transpileToken(this.name));
|
|
838
|
+
result.push(state.transpileToken(this.tokens.name));
|
|
661
839
|
}
|
|
662
840
|
return result;
|
|
663
841
|
}
|
|
664
842
|
walk(visitor, options) {
|
|
665
843
|
//nothing to walk
|
|
666
844
|
}
|
|
845
|
+
getType(options) {
|
|
846
|
+
var _a;
|
|
847
|
+
let resultType = util_1.default.tokenToBscType(this.tokens.name);
|
|
848
|
+
const nameKey = this.getName();
|
|
849
|
+
if (!resultType) {
|
|
850
|
+
const symbolTable = this.getSymbolTable();
|
|
851
|
+
resultType = symbolTable === null || symbolTable === void 0 ? void 0 : symbolTable.getSymbolType(nameKey, Object.assign(Object.assign({}, options), { fullName: nameKey, tableProvider: () => this.getSymbolTable() }));
|
|
852
|
+
if (util_1.default.isClassUsedAsFunction(resultType, this, options)) {
|
|
853
|
+
resultType = FunctionType_1.FunctionType.instance;
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
(_a = options === null || options === void 0 ? void 0 : options.typeChain) === null || _a === void 0 ? void 0 : _a.push(new interfaces_1.TypeChainEntry({ name: nameKey, type: resultType, data: options.data, astNode: this }));
|
|
857
|
+
return resultType;
|
|
858
|
+
}
|
|
859
|
+
getLeadingTrivia() {
|
|
860
|
+
var _a;
|
|
861
|
+
return (_a = this.tokens.name.leadingTrivia) !== null && _a !== void 0 ? _a : [];
|
|
862
|
+
}
|
|
667
863
|
}
|
|
668
864
|
exports.VariableExpression = VariableExpression;
|
|
669
|
-
class SourceLiteralExpression extends Expression {
|
|
670
|
-
constructor(
|
|
865
|
+
class SourceLiteralExpression extends AstNode_1.Expression {
|
|
866
|
+
constructor(options) {
|
|
867
|
+
var _a;
|
|
671
868
|
super();
|
|
672
|
-
this.
|
|
673
|
-
this.
|
|
869
|
+
this.kind = AstNode_1.AstNodeKind.SourceLiteralExpression;
|
|
870
|
+
this.tokens = {
|
|
871
|
+
value: options.value
|
|
872
|
+
};
|
|
873
|
+
this.range = (_a = this.tokens.value) === null || _a === void 0 ? void 0 : _a.range;
|
|
874
|
+
}
|
|
875
|
+
/**
|
|
876
|
+
* Find the index of the function in its parent
|
|
877
|
+
*/
|
|
878
|
+
findFunctionIndex(parentFunction, func) {
|
|
879
|
+
let index = -1;
|
|
880
|
+
parentFunction.findChild((node) => {
|
|
881
|
+
if ((0, reflection_1.isFunctionExpression)(node)) {
|
|
882
|
+
index++;
|
|
883
|
+
if (node === func) {
|
|
884
|
+
return true;
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
}, {
|
|
888
|
+
walkMode: visitors_1.WalkMode.visitAllRecursive
|
|
889
|
+
});
|
|
890
|
+
return index;
|
|
674
891
|
}
|
|
675
892
|
getFunctionName(state, parseMode) {
|
|
676
|
-
let
|
|
893
|
+
let func = this.findAncestor(reflection_1.isFunctionExpression);
|
|
677
894
|
let nameParts = [];
|
|
678
|
-
|
|
679
|
-
|
|
895
|
+
let parentFunction;
|
|
896
|
+
while ((parentFunction = func.findAncestor(reflection_1.isFunctionExpression))) {
|
|
897
|
+
let index = this.findFunctionIndex(parentFunction, func);
|
|
680
898
|
nameParts.unshift(`anon${index}`);
|
|
681
|
-
|
|
899
|
+
func = parentFunction;
|
|
682
900
|
}
|
|
683
901
|
//get the index of this function in its parent
|
|
684
|
-
nameParts.unshift(
|
|
902
|
+
nameParts.unshift(func.functionStatement.getName(parseMode));
|
|
685
903
|
return nameParts.join('$');
|
|
686
904
|
}
|
|
905
|
+
/**
|
|
906
|
+
* Get the line number from our token or from the closest ancestor that has a range
|
|
907
|
+
*/
|
|
908
|
+
getClosestLineNumber() {
|
|
909
|
+
let node = this;
|
|
910
|
+
while (node) {
|
|
911
|
+
if (node.range) {
|
|
912
|
+
return node.range.start.line + 1;
|
|
913
|
+
}
|
|
914
|
+
node = node.parent;
|
|
915
|
+
}
|
|
916
|
+
return -1;
|
|
917
|
+
}
|
|
687
918
|
transpile(state) {
|
|
688
919
|
let text;
|
|
689
|
-
switch (this.
|
|
690
|
-
case
|
|
920
|
+
switch (this.tokens.value.kind) {
|
|
921
|
+
case TokenKind_1.TokenKind.SourceFilePathLiteral:
|
|
691
922
|
const pathUrl = fileUrl(state.srcPath);
|
|
692
923
|
text = `"${pathUrl.substring(0, 4)}" + "${pathUrl.substring(4)}"`;
|
|
693
924
|
break;
|
|
694
|
-
case
|
|
695
|
-
|
|
925
|
+
case TokenKind_1.TokenKind.SourceLineNumLiteral:
|
|
926
|
+
//TODO find first parent that has range, or default to -1
|
|
927
|
+
text = `${this.getClosestLineNumber()}`;
|
|
696
928
|
break;
|
|
697
|
-
case
|
|
929
|
+
case TokenKind_1.TokenKind.FunctionNameLiteral:
|
|
698
930
|
text = `"${this.getFunctionName(state, Parser_1.ParseMode.BrightScript)}"`;
|
|
699
931
|
break;
|
|
700
|
-
case
|
|
932
|
+
case TokenKind_1.TokenKind.SourceFunctionNameLiteral:
|
|
701
933
|
text = `"${this.getFunctionName(state, Parser_1.ParseMode.BrighterScript)}"`;
|
|
702
934
|
break;
|
|
703
|
-
case
|
|
935
|
+
case TokenKind_1.TokenKind.SourceLocationLiteral:
|
|
704
936
|
const locationUrl = fileUrl(state.srcPath);
|
|
705
|
-
|
|
937
|
+
//TODO find first parent that has range, or default to -1
|
|
938
|
+
text = `"${locationUrl.substring(0, 4)}" + "${locationUrl.substring(4)}:${this.getClosestLineNumber()}"`;
|
|
706
939
|
break;
|
|
707
|
-
case
|
|
708
|
-
text = `"${state.file.pkgPath
|
|
940
|
+
case TokenKind_1.TokenKind.PkgPathLiteral:
|
|
941
|
+
text = `"${util_1.default.sanitizePkgPath(state.file.pkgPath)}"`;
|
|
709
942
|
break;
|
|
710
|
-
case
|
|
711
|
-
text = `"${state.file.pkgPath
|
|
943
|
+
case TokenKind_1.TokenKind.PkgLocationLiteral:
|
|
944
|
+
text = `"${util_1.default.sanitizePkgPath(state.file.pkgPath)}:" + str(LINE_NUM)`;
|
|
712
945
|
break;
|
|
713
|
-
case
|
|
946
|
+
case TokenKind_1.TokenKind.LineNumLiteral:
|
|
714
947
|
default:
|
|
715
948
|
//use the original text (because it looks like a variable)
|
|
716
|
-
text = this.
|
|
949
|
+
text = this.tokens.value.text;
|
|
717
950
|
break;
|
|
718
951
|
}
|
|
719
952
|
return [
|
|
@@ -723,6 +956,10 @@ class SourceLiteralExpression extends Expression {
|
|
|
723
956
|
walk(visitor, options) {
|
|
724
957
|
//nothing to walk
|
|
725
958
|
}
|
|
959
|
+
getLeadingTrivia() {
|
|
960
|
+
var _a;
|
|
961
|
+
return (_a = this.tokens.value.leadingTrivia) !== null && _a !== void 0 ? _a : [];
|
|
962
|
+
}
|
|
726
963
|
}
|
|
727
964
|
exports.SourceLiteralExpression = SourceLiteralExpression;
|
|
728
965
|
/**
|
|
@@ -730,61 +967,78 @@ exports.SourceLiteralExpression = SourceLiteralExpression;
|
|
|
730
967
|
* except we need to uniquely identify these statements so we can
|
|
731
968
|
* do more type checking.
|
|
732
969
|
*/
|
|
733
|
-
class NewExpression extends Expression {
|
|
734
|
-
constructor(
|
|
970
|
+
class NewExpression extends AstNode_1.Expression {
|
|
971
|
+
constructor(options) {
|
|
735
972
|
super();
|
|
736
|
-
this.
|
|
737
|
-
this.
|
|
738
|
-
|
|
973
|
+
this.kind = AstNode_1.AstNodeKind.NewExpression;
|
|
974
|
+
this.tokens = {
|
|
975
|
+
new: options.new
|
|
976
|
+
};
|
|
977
|
+
this.call = options.call;
|
|
978
|
+
this.range = util_1.default.createBoundingRange(this.tokens.new, this.call);
|
|
739
979
|
}
|
|
740
980
|
/**
|
|
741
981
|
* The name of the class to initialize (with optional namespace prefixed)
|
|
742
982
|
*/
|
|
743
983
|
get className() {
|
|
744
984
|
//the parser guarantees the callee of a new statement's call object will be
|
|
745
|
-
//a
|
|
985
|
+
//either a VariableExpression or a DottedGet
|
|
746
986
|
return this.call.callee;
|
|
747
987
|
}
|
|
748
|
-
get namespaceName() {
|
|
749
|
-
return this.call.namespaceName;
|
|
750
|
-
}
|
|
751
988
|
transpile(state) {
|
|
752
|
-
var _a
|
|
753
|
-
const
|
|
989
|
+
var _a;
|
|
990
|
+
const namespace = this.findAncestor(reflection_1.isNamespaceStatement);
|
|
991
|
+
const cls = (_a = state.file.getClassFileLink(this.className.getName(Parser_1.ParseMode.BrighterScript), namespace === null || namespace === void 0 ? void 0 : namespace.getName(Parser_1.ParseMode.BrighterScript))) === null || _a === void 0 ? void 0 : _a.item;
|
|
754
992
|
//new statements within a namespace block can omit the leading namespace if the class resides in that same namespace.
|
|
755
993
|
//So we need to figure out if this is a namespace-omitted class, or if this class exists without a namespace.
|
|
756
994
|
return this.call.transpile(state, cls === null || cls === void 0 ? void 0 : cls.getName(Parser_1.ParseMode.BrightScript));
|
|
757
995
|
}
|
|
758
996
|
walk(visitor, options) {
|
|
759
|
-
if (options.walkMode &
|
|
760
|
-
|
|
997
|
+
if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
|
|
998
|
+
(0, visitors_2.walk)(this, 'call', visitor, options);
|
|
761
999
|
}
|
|
762
1000
|
}
|
|
1001
|
+
getType(options) {
|
|
1002
|
+
const result = this.call.getType(options);
|
|
1003
|
+
if (options.typeChain) {
|
|
1004
|
+
// modify last typechain entry to show it is a new ...()
|
|
1005
|
+
const lastEntry = options.typeChain[options.typeChain.length - 1];
|
|
1006
|
+
if (lastEntry) {
|
|
1007
|
+
lastEntry.astNode = this;
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
return result;
|
|
1011
|
+
}
|
|
1012
|
+
getLeadingTrivia() {
|
|
1013
|
+
var _a;
|
|
1014
|
+
return (_a = this.tokens.new.leadingTrivia) !== null && _a !== void 0 ? _a : [];
|
|
1015
|
+
}
|
|
763
1016
|
}
|
|
764
1017
|
exports.NewExpression = NewExpression;
|
|
765
|
-
class CallfuncExpression extends Expression {
|
|
766
|
-
constructor(
|
|
767
|
-
var _a
|
|
1018
|
+
class CallfuncExpression extends AstNode_1.Expression {
|
|
1019
|
+
constructor(options) {
|
|
1020
|
+
var _a;
|
|
768
1021
|
super();
|
|
769
|
-
this.
|
|
770
|
-
this.
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
1022
|
+
this.kind = AstNode_1.AstNodeKind.CallfuncExpression;
|
|
1023
|
+
this.tokens = {
|
|
1024
|
+
operator: options.operator,
|
|
1025
|
+
methodName: options.methodName,
|
|
1026
|
+
openingParen: options.openingParen,
|
|
1027
|
+
closingParen: options.closingParen
|
|
1028
|
+
};
|
|
1029
|
+
this.callee = options.callee;
|
|
1030
|
+
this.args = (_a = options.args) !== null && _a !== void 0 ? _a : [];
|
|
1031
|
+
this.range = util_1.default.createBoundingRange(this.callee, this.tokens.operator, this.tokens.methodName, this.tokens.openingParen, ...this.args, this.tokens.closingParen);
|
|
776
1032
|
}
|
|
777
1033
|
transpile(state) {
|
|
1034
|
+
var _a;
|
|
778
1035
|
let result = [];
|
|
779
|
-
result.push(...this.callee.transpile(state), state.sourceNode(this.operator, '.callfunc'), state.transpileToken(this.openingParen),
|
|
1036
|
+
result.push(...this.callee.transpile(state), state.sourceNode(this.tokens.operator, '.callfunc'), state.transpileToken(this.tokens.openingParen, '('),
|
|
780
1037
|
//the name of the function
|
|
781
|
-
state.sourceNode(this.methodName, ['"', this.methodName.text, '"'])
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
result.push('invalid');
|
|
786
|
-
}
|
|
787
|
-
else {
|
|
1038
|
+
state.sourceNode(this.tokens.methodName, ['"', this.tokens.methodName.text, '"']));
|
|
1039
|
+
if (((_a = this.args) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
1040
|
+
result.push(', ');
|
|
1041
|
+
//transpile args
|
|
788
1042
|
for (let i = 0; i < this.args.length; i++) {
|
|
789
1043
|
//add comma between args
|
|
790
1044
|
if (i > 0) {
|
|
@@ -794,16 +1048,54 @@ class CallfuncExpression extends Expression {
|
|
|
794
1048
|
result.push(...arg.transpile(state));
|
|
795
1049
|
}
|
|
796
1050
|
}
|
|
797
|
-
|
|
1051
|
+
else if (state.options.legacyCallfuncHandling) {
|
|
1052
|
+
result.push(', ', 'invalid');
|
|
1053
|
+
}
|
|
1054
|
+
result.push(state.transpileToken(this.tokens.closingParen, ')'));
|
|
798
1055
|
return result;
|
|
799
1056
|
}
|
|
800
1057
|
walk(visitor, options) {
|
|
801
|
-
if (options.walkMode &
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
1058
|
+
if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
|
|
1059
|
+
(0, visitors_2.walk)(this, 'callee', visitor, options);
|
|
1060
|
+
(0, visitors_2.walkArray)(this.args, visitor, options, this);
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
getType(options) {
|
|
1064
|
+
var _a, _b, _c;
|
|
1065
|
+
let result = DynamicType_1.DynamicType.instance;
|
|
1066
|
+
// a little hacky here with checking options.ignoreCall because callFuncExpression has the method name
|
|
1067
|
+
// It's nicer for CallExpression, because it's a call on any expression.
|
|
1068
|
+
const calleeType = this.callee.getType(Object.assign(Object.assign({}, options), { flags: 1 /* SymbolTypeFlag.runtime */ }));
|
|
1069
|
+
if ((0, reflection_1.isComponentType)(calleeType) || (0, reflection_1.isReferenceType)(calleeType)) {
|
|
1070
|
+
const funcType = (_b = (_a = calleeType).getCallFuncType) === null || _b === void 0 ? void 0 : _b.call(_a, this.tokens.methodName.text, options);
|
|
1071
|
+
if (funcType) {
|
|
1072
|
+
(_c = options.typeChain) === null || _c === void 0 ? void 0 : _c.push(new interfaces_1.TypeChainEntry({
|
|
1073
|
+
name: this.tokens.methodName.text,
|
|
1074
|
+
type: funcType,
|
|
1075
|
+
data: options.data,
|
|
1076
|
+
range: this.tokens.methodName.range,
|
|
1077
|
+
separatorToken: (0, creators_1.createToken)(TokenKind_1.TokenKind.Callfunc),
|
|
1078
|
+
astNode: this
|
|
1079
|
+
}));
|
|
1080
|
+
if (options.ignoreCall) {
|
|
1081
|
+
result = funcType;
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
/* TODO:
|
|
1085
|
+
make callfunc return types work
|
|
1086
|
+
else if (isCallableType(funcType) && (!isReferenceType(funcType.returnType) || funcType.returnType.isResolvable())) {
|
|
1087
|
+
result = funcType.returnType;
|
|
1088
|
+
} else if (!isReferenceType(funcType) && (funcType as any)?.returnType?.isResolvable()) {
|
|
1089
|
+
result = (funcType as any).returnType;
|
|
1090
|
+
} else {
|
|
1091
|
+
return new TypePropertyReferenceType(funcType, 'returnType');
|
|
805
1092
|
}
|
|
1093
|
+
*/
|
|
806
1094
|
}
|
|
1095
|
+
return result;
|
|
1096
|
+
}
|
|
1097
|
+
getLeadingTrivia() {
|
|
1098
|
+
return this.callee.getLeadingTrivia();
|
|
807
1099
|
}
|
|
808
1100
|
}
|
|
809
1101
|
exports.CallfuncExpression = CallfuncExpression;
|
|
@@ -811,11 +1103,12 @@ exports.CallfuncExpression = CallfuncExpression;
|
|
|
811
1103
|
* Since template strings can contain newlines, we need to concatenate multiple strings together with chr() calls.
|
|
812
1104
|
* This is a single expression that represents the string contatenation of all parts of a single quasi.
|
|
813
1105
|
*/
|
|
814
|
-
class TemplateStringQuasiExpression extends Expression {
|
|
815
|
-
constructor(
|
|
1106
|
+
class TemplateStringQuasiExpression extends AstNode_1.Expression {
|
|
1107
|
+
constructor(options) {
|
|
816
1108
|
super();
|
|
817
|
-
this.
|
|
818
|
-
this.
|
|
1109
|
+
this.kind = AstNode_1.AstNodeKind.TemplateStringQuasiExpression;
|
|
1110
|
+
this.expressions = options.expressions;
|
|
1111
|
+
this.range = util_1.default.createBoundingRange(...this.expressions);
|
|
819
1112
|
}
|
|
820
1113
|
transpile(state, skipEmptyStrings = true) {
|
|
821
1114
|
let result = [];
|
|
@@ -823,7 +1116,7 @@ class TemplateStringQuasiExpression extends Expression {
|
|
|
823
1116
|
for (let expression of this.expressions) {
|
|
824
1117
|
//skip empty strings
|
|
825
1118
|
//TODO what does an empty string literal expression look like?
|
|
826
|
-
if (expression.
|
|
1119
|
+
if (expression.tokens.value.text === '' && skipEmptyStrings === true) {
|
|
827
1120
|
continue;
|
|
828
1121
|
}
|
|
829
1122
|
result.push(plus, ...expression.transpile(state));
|
|
@@ -832,28 +1125,32 @@ class TemplateStringQuasiExpression extends Expression {
|
|
|
832
1125
|
return result;
|
|
833
1126
|
}
|
|
834
1127
|
walk(visitor, options) {
|
|
835
|
-
if (options.walkMode &
|
|
836
|
-
|
|
837
|
-
visitors_1.walk(this.expressions, i, visitor, options, this);
|
|
838
|
-
}
|
|
1128
|
+
if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
|
|
1129
|
+
(0, visitors_2.walkArray)(this.expressions, visitor, options, this);
|
|
839
1130
|
}
|
|
840
1131
|
}
|
|
841
1132
|
}
|
|
842
1133
|
exports.TemplateStringQuasiExpression = TemplateStringQuasiExpression;
|
|
843
|
-
class TemplateStringExpression extends Expression {
|
|
844
|
-
constructor(
|
|
1134
|
+
class TemplateStringExpression extends AstNode_1.Expression {
|
|
1135
|
+
constructor(options) {
|
|
845
1136
|
super();
|
|
846
|
-
this.
|
|
847
|
-
this.
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
1137
|
+
this.kind = AstNode_1.AstNodeKind.TemplateStringExpression;
|
|
1138
|
+
this.tokens = {
|
|
1139
|
+
openingBacktick: options.openingBacktick,
|
|
1140
|
+
closingBacktick: options.closingBacktick
|
|
1141
|
+
};
|
|
1142
|
+
this.quasis = options.quasis;
|
|
1143
|
+
this.expressions = options.expressions;
|
|
1144
|
+
this.range = util_1.default.createBoundingRange(this.tokens.openingBacktick, this.quasis[0], this.quasis[this.quasis.length - 1], this.tokens.closingBacktick);
|
|
1145
|
+
}
|
|
1146
|
+
getType(options) {
|
|
1147
|
+
return StringType_1.StringType.instance;
|
|
851
1148
|
}
|
|
852
1149
|
transpile(state) {
|
|
853
1150
|
if (this.quasis.length === 1 && this.expressions.length === 0) {
|
|
854
1151
|
return this.quasis[0].transpile(state);
|
|
855
1152
|
}
|
|
856
|
-
let result = [];
|
|
1153
|
+
let result = ['('];
|
|
857
1154
|
let plus = '';
|
|
858
1155
|
//helper function to figure out when to include the plus
|
|
859
1156
|
function add(...items) {
|
|
@@ -871,8 +1168,8 @@ class TemplateStringExpression extends Expression {
|
|
|
871
1168
|
add(...quasi.transpile(state));
|
|
872
1169
|
if (expression) {
|
|
873
1170
|
//skip the toString wrapper around certain expressions
|
|
874
|
-
if (reflection_1.isEscapedCharCodeLiteralExpression(expression) ||
|
|
875
|
-
(reflection_1.isLiteralExpression(expression) && reflection_1.isStringType(expression.
|
|
1171
|
+
if ((0, reflection_1.isEscapedCharCodeLiteralExpression)(expression) ||
|
|
1172
|
+
((0, reflection_1.isLiteralExpression)(expression) && (0, reflection_1.isStringType)(expression.getType()))) {
|
|
876
1173
|
add(...expression.transpile(state));
|
|
877
1174
|
//wrap all other expressions with a bslib_toString call to prevent runtime type mismatch errors
|
|
878
1175
|
}
|
|
@@ -881,35 +1178,40 @@ class TemplateStringExpression extends Expression {
|
|
|
881
1178
|
}
|
|
882
1179
|
}
|
|
883
1180
|
}
|
|
1181
|
+
//the expression should be wrapped in parens so it can be used line a single expression at runtime
|
|
1182
|
+
result.push(')');
|
|
884
1183
|
return result;
|
|
885
1184
|
}
|
|
886
1185
|
walk(visitor, options) {
|
|
887
|
-
if (options.walkMode &
|
|
1186
|
+
if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
|
|
888
1187
|
//walk the quasis and expressions in left-to-right order
|
|
889
1188
|
for (let i = 0; i < this.quasis.length; i++) {
|
|
890
|
-
|
|
1189
|
+
(0, visitors_2.walk)(this.quasis, i, visitor, options, this);
|
|
891
1190
|
//this skips the final loop iteration since we'll always have one more quasi than expression
|
|
892
1191
|
if (this.expressions[i]) {
|
|
893
|
-
|
|
1192
|
+
(0, visitors_2.walk)(this.expressions, i, visitor, options, this);
|
|
894
1193
|
}
|
|
895
1194
|
}
|
|
896
1195
|
}
|
|
897
1196
|
}
|
|
898
1197
|
}
|
|
899
1198
|
exports.TemplateStringExpression = TemplateStringExpression;
|
|
900
|
-
class TaggedTemplateStringExpression extends Expression {
|
|
901
|
-
constructor(
|
|
1199
|
+
class TaggedTemplateStringExpression extends AstNode_1.Expression {
|
|
1200
|
+
constructor(options) {
|
|
902
1201
|
super();
|
|
903
|
-
this.
|
|
904
|
-
this.
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
1202
|
+
this.kind = AstNode_1.AstNodeKind.TaggedTemplateStringExpression;
|
|
1203
|
+
this.tokens = {
|
|
1204
|
+
tagName: options.tagName,
|
|
1205
|
+
openingBacktick: options.openingBacktick,
|
|
1206
|
+
closingBacktick: options.closingBacktick
|
|
1207
|
+
};
|
|
1208
|
+
this.quasis = options.quasis;
|
|
1209
|
+
this.expressions = options.expressions;
|
|
1210
|
+
this.range = util_1.default.createBoundingRange(this.tokens.tagName, this.tokens.openingBacktick, this.quasis[0], this.quasis[this.quasis.length - 1], this.tokens.closingBacktick);
|
|
909
1211
|
}
|
|
910
1212
|
transpile(state) {
|
|
911
1213
|
let result = [];
|
|
912
|
-
result.push(state.transpileToken(this.tagName), '([');
|
|
1214
|
+
result.push(state.transpileToken(this.tokens.tagName), '([');
|
|
913
1215
|
//add quasis as the first array
|
|
914
1216
|
for (let i = 0; i < this.quasis.length; i++) {
|
|
915
1217
|
let quasi = this.quasis[i];
|
|
@@ -928,30 +1230,36 @@ class TaggedTemplateStringExpression extends Expression {
|
|
|
928
1230
|
}
|
|
929
1231
|
result.push(...expression.transpile(state));
|
|
930
1232
|
}
|
|
931
|
-
result.push(state.sourceNode(this.closingBacktick, '])'));
|
|
1233
|
+
result.push(state.sourceNode(this.tokens.closingBacktick, '])'));
|
|
932
1234
|
return result;
|
|
933
1235
|
}
|
|
934
1236
|
walk(visitor, options) {
|
|
935
|
-
if (options.walkMode &
|
|
1237
|
+
if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
|
|
936
1238
|
//walk the quasis and expressions in left-to-right order
|
|
937
1239
|
for (let i = 0; i < this.quasis.length; i++) {
|
|
938
|
-
|
|
1240
|
+
(0, visitors_2.walk)(this.quasis, i, visitor, options, this);
|
|
939
1241
|
//this skips the final loop iteration since we'll always have one more quasi than expression
|
|
940
1242
|
if (this.expressions[i]) {
|
|
941
|
-
|
|
1243
|
+
(0, visitors_2.walk)(this.expressions, i, visitor, options, this);
|
|
942
1244
|
}
|
|
943
1245
|
}
|
|
944
1246
|
}
|
|
945
1247
|
}
|
|
946
1248
|
}
|
|
947
1249
|
exports.TaggedTemplateStringExpression = TaggedTemplateStringExpression;
|
|
948
|
-
class AnnotationExpression extends Expression {
|
|
949
|
-
constructor(
|
|
1250
|
+
class AnnotationExpression extends AstNode_1.Expression {
|
|
1251
|
+
constructor(options) {
|
|
950
1252
|
super();
|
|
951
|
-
this.
|
|
952
|
-
this.
|
|
953
|
-
|
|
954
|
-
|
|
1253
|
+
this.kind = AstNode_1.AstNodeKind.AnnotationExpression;
|
|
1254
|
+
this.tokens = {
|
|
1255
|
+
at: options.at,
|
|
1256
|
+
name: options.name
|
|
1257
|
+
};
|
|
1258
|
+
this.call = options.call;
|
|
1259
|
+
this.name = this.tokens.name.text;
|
|
1260
|
+
}
|
|
1261
|
+
get range() {
|
|
1262
|
+
return util_1.default.createBoundingRange(this.tokens.at, this.tokens.name, this.call);
|
|
955
1263
|
}
|
|
956
1264
|
/**
|
|
957
1265
|
* Convert annotation arguments to JavaScript types
|
|
@@ -963,6 +1271,10 @@ class AnnotationExpression extends Expression {
|
|
|
963
1271
|
}
|
|
964
1272
|
return this.call.args.map(e => expressionToValue(e, strict));
|
|
965
1273
|
}
|
|
1274
|
+
getLeadingTrivia() {
|
|
1275
|
+
var _a, _b;
|
|
1276
|
+
return (_b = (_a = this.tokens.at) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
|
|
1277
|
+
}
|
|
966
1278
|
transpile(state) {
|
|
967
1279
|
return [];
|
|
968
1280
|
}
|
|
@@ -979,22 +1291,25 @@ class AnnotationExpression extends Expression {
|
|
|
979
1291
|
}
|
|
980
1292
|
}
|
|
981
1293
|
exports.AnnotationExpression = AnnotationExpression;
|
|
982
|
-
class TernaryExpression extends Expression {
|
|
983
|
-
constructor(
|
|
984
|
-
var _a, _b, _c;
|
|
1294
|
+
class TernaryExpression extends AstNode_1.Expression {
|
|
1295
|
+
constructor(options) {
|
|
985
1296
|
super();
|
|
986
|
-
this.
|
|
987
|
-
this.
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
this.
|
|
1297
|
+
this.kind = AstNode_1.AstNodeKind.TernaryExpression;
|
|
1298
|
+
this.tokens = {
|
|
1299
|
+
questionMark: options.questionMark,
|
|
1300
|
+
colon: options.colon
|
|
1301
|
+
};
|
|
1302
|
+
this.test = options.test;
|
|
1303
|
+
this.consequent = options.consequent;
|
|
1304
|
+
this.alternate = options.alternate;
|
|
1305
|
+
this.range = util_1.default.createBoundingRange(this.test, this.tokens.questionMark, this.consequent, this.tokens.colon, this.alternate);
|
|
992
1306
|
}
|
|
993
1307
|
transpile(state) {
|
|
994
1308
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
995
1309
|
let result = [];
|
|
996
|
-
|
|
997
|
-
let
|
|
1310
|
+
const file = state.file;
|
|
1311
|
+
let consequentInfo = util_1.default.getExpressionInfo(this.consequent, file);
|
|
1312
|
+
let alternateInfo = util_1.default.getExpressionInfo(this.alternate, file);
|
|
998
1313
|
//get all unique variable names used in the consequent and alternate, and sort them alphabetically so the output is consistent
|
|
999
1314
|
let allUniqueVarNames = [...new Set([...consequentInfo.uniqueVarNames, ...alternateInfo.uniqueVarNames])].sort();
|
|
1000
1315
|
let mutatingExpressions = [
|
|
@@ -1002,12 +1317,12 @@ class TernaryExpression extends Expression {
|
|
|
1002
1317
|
...alternateInfo.expressions
|
|
1003
1318
|
].filter(e => e instanceof CallExpression || e instanceof CallfuncExpression || e instanceof DottedGetExpression);
|
|
1004
1319
|
if (mutatingExpressions.length > 0) {
|
|
1005
|
-
result.push(state.sourceNode(this.
|
|
1320
|
+
result.push(state.sourceNode(this.tokens.questionMark,
|
|
1006
1321
|
//write all the scope variables as parameters.
|
|
1007
1322
|
//TODO handle when there are more than 31 parameters
|
|
1008
|
-
`(function(__bsCondition,
|
|
1323
|
+
`(function(${['__bsCondition', ...allUniqueVarNames].join(', ')})`), state.newline,
|
|
1009
1324
|
//double indent so our `end function` line is still indented one at the end
|
|
1010
|
-
state.indent(2), state.sourceNode(this.test, `if __bsCondition then`), state.newline, state.indent(1), state.sourceNode((_a = this.consequent) !== null && _a !== void 0 ? _a : this.
|
|
1325
|
+
state.indent(2), state.sourceNode(this.test, `if __bsCondition then`), state.newline, state.indent(1), state.sourceNode((_a = this.consequent) !== null && _a !== void 0 ? _a : this.tokens.questionMark, 'return '), ...(_c = (_b = this.consequent) === null || _b === void 0 ? void 0 : _b.transpile(state)) !== null && _c !== void 0 ? _c : [state.sourceNode(this.tokens.questionMark, 'invalid')], state.newline, state.indent(-1), state.sourceNode((_d = this.consequent) !== null && _d !== void 0 ? _d : this.tokens.questionMark, 'else'), state.newline, state.indent(1), state.sourceNode((_e = this.consequent) !== null && _e !== void 0 ? _e : this.tokens.questionMark, 'return '), ...(_g = (_f = this.alternate) === null || _f === void 0 ? void 0 : _f.transpile(state)) !== null && _g !== void 0 ? _g : [state.sourceNode((_h = this.consequent) !== null && _h !== void 0 ? _h : this.tokens.questionMark, 'invalid')], state.newline, state.indent(-1), state.sourceNode(this.tokens.questionMark, 'end if'), state.newline, state.indent(-1), state.sourceNode(this.tokens.questionMark, 'end function)('), ...this.test.transpile(state), state.sourceNode(this.tokens.questionMark, `${['', ...allUniqueVarNames].join(', ')})`));
|
|
1011
1326
|
state.blockDepth--;
|
|
1012
1327
|
}
|
|
1013
1328
|
else {
|
|
@@ -1016,33 +1331,38 @@ class TernaryExpression extends Expression {
|
|
|
1016
1331
|
return result;
|
|
1017
1332
|
}
|
|
1018
1333
|
walk(visitor, options) {
|
|
1019
|
-
if (options.walkMode &
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1334
|
+
if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
|
|
1335
|
+
(0, visitors_2.walk)(this, 'test', visitor, options);
|
|
1336
|
+
(0, visitors_2.walk)(this, 'consequent', visitor, options);
|
|
1337
|
+
(0, visitors_2.walk)(this, 'alternate', visitor, options);
|
|
1023
1338
|
}
|
|
1024
1339
|
}
|
|
1340
|
+
getLeadingTrivia() {
|
|
1341
|
+
return this.test.getLeadingTrivia();
|
|
1342
|
+
}
|
|
1025
1343
|
}
|
|
1026
1344
|
exports.TernaryExpression = TernaryExpression;
|
|
1027
|
-
class NullCoalescingExpression extends Expression {
|
|
1028
|
-
constructor(
|
|
1029
|
-
var _a;
|
|
1345
|
+
class NullCoalescingExpression extends AstNode_1.Expression {
|
|
1346
|
+
constructor(options) {
|
|
1030
1347
|
super();
|
|
1031
|
-
this.
|
|
1032
|
-
this.
|
|
1033
|
-
|
|
1034
|
-
|
|
1348
|
+
this.kind = AstNode_1.AstNodeKind.NullCoalescingExpression;
|
|
1349
|
+
this.tokens = {
|
|
1350
|
+
questionQuestion: options.questionQuestion
|
|
1351
|
+
};
|
|
1352
|
+
this.consequent = options.consequent;
|
|
1353
|
+
this.alternate = options.alternate;
|
|
1354
|
+
this.range = util_1.default.createBoundingRange(this.consequent, this.tokens.questionQuestion, this.alternate);
|
|
1035
1355
|
}
|
|
1036
1356
|
transpile(state) {
|
|
1037
1357
|
let result = [];
|
|
1038
|
-
let consequentInfo = util_1.default.getExpressionInfo(this.consequent);
|
|
1039
|
-
let alternateInfo = util_1.default.getExpressionInfo(this.alternate);
|
|
1358
|
+
let consequentInfo = util_1.default.getExpressionInfo(this.consequent, state.file);
|
|
1359
|
+
let alternateInfo = util_1.default.getExpressionInfo(this.alternate, state.file);
|
|
1040
1360
|
//get all unique variable names used in the consequent and alternate, and sort them alphabetically so the output is consistent
|
|
1041
1361
|
let allUniqueVarNames = [...new Set([...consequentInfo.uniqueVarNames, ...alternateInfo.uniqueVarNames])].sort();
|
|
1042
1362
|
let hasMutatingExpression = [
|
|
1043
1363
|
...consequentInfo.expressions,
|
|
1044
1364
|
...alternateInfo.expressions
|
|
1045
|
-
].find(e => reflection_1.isCallExpression(e) || reflection_1.isCallfuncExpression(e) || reflection_1.isDottedGetExpression(e));
|
|
1365
|
+
].find(e => (0, reflection_1.isCallExpression)(e) || (0, reflection_1.isCallfuncExpression)(e) || (0, reflection_1.isDottedGetExpression)(e));
|
|
1046
1366
|
if (hasMutatingExpression) {
|
|
1047
1367
|
result.push(`(function(`,
|
|
1048
1368
|
//write all the scope variables as parameters.
|
|
@@ -1060,51 +1380,186 @@ class NullCoalescingExpression extends Expression {
|
|
|
1060
1380
|
return result;
|
|
1061
1381
|
}
|
|
1062
1382
|
walk(visitor, options) {
|
|
1063
|
-
if (options.walkMode &
|
|
1064
|
-
|
|
1065
|
-
|
|
1383
|
+
if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
|
|
1384
|
+
(0, visitors_2.walk)(this, 'consequent', visitor, options);
|
|
1385
|
+
(0, visitors_2.walk)(this, 'alternate', visitor, options);
|
|
1066
1386
|
}
|
|
1067
1387
|
}
|
|
1388
|
+
getLeadingTrivia() {
|
|
1389
|
+
return this.consequent.getLeadingTrivia();
|
|
1390
|
+
}
|
|
1068
1391
|
}
|
|
1069
1392
|
exports.NullCoalescingExpression = NullCoalescingExpression;
|
|
1393
|
+
class RegexLiteralExpression extends AstNode_1.Expression {
|
|
1394
|
+
constructor(options) {
|
|
1395
|
+
super();
|
|
1396
|
+
this.kind = AstNode_1.AstNodeKind.RegexLiteralExpression;
|
|
1397
|
+
this.tokens = {
|
|
1398
|
+
regexLiteral: options.regexLiteral
|
|
1399
|
+
};
|
|
1400
|
+
}
|
|
1401
|
+
get range() {
|
|
1402
|
+
var _a, _b;
|
|
1403
|
+
return (_b = (_a = this.tokens) === null || _a === void 0 ? void 0 : _a.regexLiteral) === null || _b === void 0 ? void 0 : _b.range;
|
|
1404
|
+
}
|
|
1405
|
+
transpile(state) {
|
|
1406
|
+
var _a, _b;
|
|
1407
|
+
let text = (_b = (_a = this.tokens.regexLiteral) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : '';
|
|
1408
|
+
let flags = '';
|
|
1409
|
+
//get any flags from the end
|
|
1410
|
+
const flagMatch = /\/([a-z]+)$/i.exec(text);
|
|
1411
|
+
if (flagMatch) {
|
|
1412
|
+
text = text.substring(0, flagMatch.index + 1);
|
|
1413
|
+
flags = flagMatch[1];
|
|
1414
|
+
}
|
|
1415
|
+
let pattern = text
|
|
1416
|
+
//remove leading and trailing slashes
|
|
1417
|
+
.substring(1, text.length - 1)
|
|
1418
|
+
//escape quotemarks
|
|
1419
|
+
.split('"').join('" + chr(34) + "');
|
|
1420
|
+
return [
|
|
1421
|
+
state.sourceNode(this.tokens.regexLiteral, [
|
|
1422
|
+
'CreateObject("roRegex", ',
|
|
1423
|
+
`"${pattern}", `,
|
|
1424
|
+
`"${flags}"`,
|
|
1425
|
+
')'
|
|
1426
|
+
])
|
|
1427
|
+
];
|
|
1428
|
+
}
|
|
1429
|
+
walk(visitor, options) {
|
|
1430
|
+
//nothing to walk
|
|
1431
|
+
}
|
|
1432
|
+
getLeadingTrivia() {
|
|
1433
|
+
var _a, _b;
|
|
1434
|
+
return (_b = (_a = this.tokens.regexLiteral) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
exports.RegexLiteralExpression = RegexLiteralExpression;
|
|
1070
1438
|
function expressionToValue(expr, strict) {
|
|
1071
1439
|
if (!expr) {
|
|
1072
1440
|
return null;
|
|
1073
1441
|
}
|
|
1074
|
-
if (reflection_1.isUnaryExpression(expr) && reflection_1.isLiteralNumber(expr.right)) {
|
|
1075
|
-
return numberExpressionToValue(expr.right, expr.operator.text);
|
|
1442
|
+
if ((0, reflection_1.isUnaryExpression)(expr) && (0, reflection_1.isLiteralNumber)(expr.right)) {
|
|
1443
|
+
return numberExpressionToValue(expr.right, expr.tokens.operator.text);
|
|
1076
1444
|
}
|
|
1077
|
-
if (reflection_1.isLiteralString(expr)) {
|
|
1445
|
+
if ((0, reflection_1.isLiteralString)(expr)) {
|
|
1078
1446
|
//remove leading and trailing quotes
|
|
1079
|
-
return expr.
|
|
1447
|
+
return expr.tokens.value.text.replace(/^"/, '').replace(/"$/, '');
|
|
1080
1448
|
}
|
|
1081
|
-
if (reflection_1.isLiteralNumber(expr)) {
|
|
1449
|
+
if ((0, reflection_1.isLiteralNumber)(expr)) {
|
|
1082
1450
|
return numberExpressionToValue(expr);
|
|
1083
1451
|
}
|
|
1084
|
-
if (reflection_1.isLiteralBoolean(expr)) {
|
|
1085
|
-
return expr.
|
|
1452
|
+
if ((0, reflection_1.isLiteralBoolean)(expr)) {
|
|
1453
|
+
return expr.tokens.value.text.toLowerCase() === 'true';
|
|
1086
1454
|
}
|
|
1087
|
-
if (reflection_1.isArrayLiteralExpression(expr)) {
|
|
1455
|
+
if ((0, reflection_1.isArrayLiteralExpression)(expr)) {
|
|
1088
1456
|
return expr.elements
|
|
1089
|
-
.filter(e => !reflection_1.isCommentStatement(e))
|
|
1090
1457
|
.map(e => expressionToValue(e, strict));
|
|
1091
1458
|
}
|
|
1092
|
-
if (reflection_1.isAALiteralExpression(expr)) {
|
|
1459
|
+
if ((0, reflection_1.isAALiteralExpression)(expr)) {
|
|
1093
1460
|
return expr.elements.reduce((acc, e) => {
|
|
1094
|
-
|
|
1095
|
-
acc[e.keyToken.text] = expressionToValue(e.value, strict);
|
|
1096
|
-
}
|
|
1461
|
+
acc[e.tokens.key.text] = expressionToValue(e.value, strict);
|
|
1097
1462
|
return acc;
|
|
1098
1463
|
}, {});
|
|
1099
1464
|
}
|
|
1100
1465
|
return strict ? null : expr;
|
|
1101
1466
|
}
|
|
1102
1467
|
function numberExpressionToValue(expr, operator = '') {
|
|
1103
|
-
if (reflection_1.isIntegerType(expr.
|
|
1104
|
-
return parseInt(operator + expr.
|
|
1468
|
+
if ((0, reflection_1.isIntegerType)(expr.getType()) || (0, reflection_1.isLongIntegerType)(expr.getType())) {
|
|
1469
|
+
return parseInt(operator + expr.tokens.value.text);
|
|
1105
1470
|
}
|
|
1106
1471
|
else {
|
|
1107
|
-
return parseFloat(operator + expr.
|
|
1472
|
+
return parseFloat(operator + expr.tokens.value.text);
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
class TypeExpression extends AstNode_1.Expression {
|
|
1476
|
+
constructor(options) {
|
|
1477
|
+
var _a;
|
|
1478
|
+
super();
|
|
1479
|
+
this.kind = AstNode_1.AstNodeKind.TypeExpression;
|
|
1480
|
+
this.expression = options.expression;
|
|
1481
|
+
this.range = (_a = this.expression) === null || _a === void 0 ? void 0 : _a.range;
|
|
1482
|
+
}
|
|
1483
|
+
transpile(state) {
|
|
1484
|
+
return [this.getType({ flags: 2 /* SymbolTypeFlag.typetime */ }).toTypeString()];
|
|
1485
|
+
}
|
|
1486
|
+
walk(visitor, options) {
|
|
1487
|
+
if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
|
|
1488
|
+
(0, visitors_2.walk)(this, 'expression', visitor, options);
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
getType(options) {
|
|
1492
|
+
return this.expression.getType(Object.assign(Object.assign({}, options), { flags: 2 /* SymbolTypeFlag.typetime */ }));
|
|
1493
|
+
}
|
|
1494
|
+
getTypedef(state) {
|
|
1495
|
+
// TypeDefs should pass through any valid type names
|
|
1496
|
+
return this.expression.transpile(state);
|
|
1497
|
+
}
|
|
1498
|
+
getName(parseMode = Parser_1.ParseMode.BrighterScript) {
|
|
1499
|
+
//TODO: this may not support Complex Types, eg. generics or Unions
|
|
1500
|
+
return util_1.default.getAllDottedGetPartsAsString(this.expression, parseMode);
|
|
1501
|
+
}
|
|
1502
|
+
getNameParts() {
|
|
1503
|
+
//TODO: really, this code is only used to get Namespaces. It could be more clear.
|
|
1504
|
+
return util_1.default.getAllDottedGetParts(this.expression).map(x => x.text);
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
exports.TypeExpression = TypeExpression;
|
|
1508
|
+
class TypecastExpression extends AstNode_1.Expression {
|
|
1509
|
+
constructor(options) {
|
|
1510
|
+
super();
|
|
1511
|
+
this.kind = AstNode_1.AstNodeKind.TypecastExpression;
|
|
1512
|
+
this.tokens = {
|
|
1513
|
+
as: options.as
|
|
1514
|
+
};
|
|
1515
|
+
this.obj = options.obj;
|
|
1516
|
+
this.typeExpression = options.typeExpression;
|
|
1517
|
+
this.range = util_1.default.createBoundingRange(this.obj, this.tokens.as, this.typeExpression);
|
|
1518
|
+
}
|
|
1519
|
+
transpile(state) {
|
|
1520
|
+
return this.obj.transpile(state);
|
|
1521
|
+
}
|
|
1522
|
+
walk(visitor, options) {
|
|
1523
|
+
if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
|
|
1524
|
+
(0, visitors_2.walk)(this, 'obj', visitor, options);
|
|
1525
|
+
(0, visitors_2.walk)(this, 'typeExpression', visitor, options);
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
getType(options) {
|
|
1529
|
+
const result = this.typeExpression.getType(options);
|
|
1530
|
+
if (options.typeChain) {
|
|
1531
|
+
// modify last typechain entry to show it is a typecast
|
|
1532
|
+
const lastEntry = options.typeChain[options.typeChain.length - 1];
|
|
1533
|
+
if (lastEntry) {
|
|
1534
|
+
lastEntry.astNode = this;
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
return result;
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
exports.TypecastExpression = TypecastExpression;
|
|
1541
|
+
class TypedArrayExpression extends AstNode_1.Expression {
|
|
1542
|
+
constructor(options) {
|
|
1543
|
+
super();
|
|
1544
|
+
this.kind = AstNode_1.AstNodeKind.TypedArrayExpression;
|
|
1545
|
+
this.tokens = {
|
|
1546
|
+
leftBracket: options.leftBracket,
|
|
1547
|
+
rightBracket: options.rightBracket
|
|
1548
|
+
};
|
|
1549
|
+
this.innerType = options.innerType;
|
|
1550
|
+
this.range = util_1.default.createBoundingRange(this.innerType, this.tokens.leftBracket, this.tokens.rightBracket);
|
|
1551
|
+
}
|
|
1552
|
+
transpile(state) {
|
|
1553
|
+
return [this.getType({ flags: 2 /* SymbolTypeFlag.typetime */ }).toTypeString()];
|
|
1554
|
+
}
|
|
1555
|
+
walk(visitor, options) {
|
|
1556
|
+
if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
|
|
1557
|
+
(0, visitors_2.walk)(this, 'innerType', visitor, options);
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
getType(options) {
|
|
1561
|
+
return new ArrayType_1.ArrayType(this.innerType.getType(options));
|
|
1108
1562
|
}
|
|
1109
1563
|
}
|
|
1564
|
+
exports.TypedArrayExpression = TypedArrayExpression;
|
|
1110
1565
|
//# sourceMappingURL=Expression.js.map
|