brighterscript 0.72.0 → 0.72.2
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/bsconfig.schema.json +62 -0
- package/dist/BsConfig.d.ts +56 -1
- package/dist/CommentFlagProcessor.d.ts +16 -12
- package/dist/CommentFlagProcessor.js +141 -59
- package/dist/CommentFlagProcessor.js.map +1 -1
- package/dist/DiagnosticMessages.d.ts +27 -1
- package/dist/DiagnosticMessages.js +32 -2
- package/dist/DiagnosticMessages.js.map +1 -1
- package/dist/Program.d.ts +4 -0
- package/dist/Program.js +2 -0
- package/dist/Program.js.map +1 -1
- package/dist/ProgramBuilder.d.ts +1 -8
- package/dist/ProgramBuilder.js +31 -11
- package/dist/ProgramBuilder.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.d.ts +38 -0
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +257 -14
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
- package/dist/bscPlugin/validation/BrsFileValidator.js +13 -0
- package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -1
- package/dist/cli.js +13 -0
- package/dist/cli.js.map +1 -1
- package/dist/diagnosticUtils.d.ts +51 -1
- package/dist/diagnosticUtils.js +222 -1
- package/dist/diagnosticUtils.js.map +1 -1
- package/dist/files/BrsFile.js +4 -2
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/XmlFile.js +2 -1
- package/dist/files/XmlFile.js.map +1 -1
- package/dist/interfaces.d.ts +15 -1
- package/dist/lexer/TokenKind.d.ts +8 -0
- package/dist/lexer/TokenKind.js +21 -1
- package/dist/lexer/TokenKind.js.map +1 -1
- package/dist/lsp/LspProject.d.ts +19 -0
- package/dist/lsp/Project.d.ts +14 -0
- package/dist/lsp/Project.js +9 -1
- package/dist/lsp/Project.js.map +1 -1
- package/dist/lsp/ProjectManager.js +15 -1
- package/dist/lsp/ProjectManager.js.map +1 -1
- package/dist/lsp/worker/WorkerThreadProject.d.ts +14 -0
- package/dist/lsp/worker/WorkerThreadProject.js +7 -0
- package/dist/lsp/worker/WorkerThreadProject.js.map +1 -1
- package/dist/parser/Parser.d.ts +13 -1
- package/dist/parser/Parser.js +40 -14
- package/dist/parser/Parser.js.map +1 -1
- package/dist/util.js +20 -9
- package/dist/util.js.map +1 -1
- package/package.json +17 -14
- package/dist/astUtils/AstEditor.spec.d.ts +0 -1
- package/dist/astUtils/AstEditor.spec.js +0 -254
- package/dist/astUtils/AstEditor.spec.js.map +0 -1
- package/dist/astUtils/creators.spec.d.ts +0 -1
- package/dist/astUtils/creators.spec.js +0 -21
- package/dist/astUtils/creators.spec.js.map +0 -1
- package/dist/astUtils/reflection.spec.d.ts +0 -1
- package/dist/astUtils/reflection.spec.js +0 -308
- package/dist/astUtils/reflection.spec.js.map +0 -1
- package/dist/astUtils/stackedVisitor.spec.d.ts +0 -1
- package/dist/astUtils/stackedVisitor.spec.js +0 -79
- package/dist/astUtils/stackedVisitor.spec.js.map +0 -1
- package/dist/astUtils/visitors.spec.d.ts +0 -1
- package/dist/astUtils/visitors.spec.js +0 -1197
- package/dist/astUtils/visitors.spec.js.map +0 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.d.ts +0 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +0 -887
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +0 -1
- package/dist/bscPlugin/definition/DefinitionProvider.spec.d.ts +0 -1
- package/dist/bscPlugin/definition/DefinitionProvider.spec.js +0 -171
- package/dist/bscPlugin/definition/DefinitionProvider.spec.js.map +0 -1
- package/dist/bscPlugin/hover/HoverProcessor.spec.d.ts +0 -1
- package/dist/bscPlugin/hover/HoverProcessor.spec.js +0 -201
- package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +0 -1
- package/dist/bscPlugin/references/ReferencesProvider.spec.d.ts +0 -1
- package/dist/bscPlugin/references/ReferencesProvider.spec.js +0 -51
- package/dist/bscPlugin/references/ReferencesProvider.spec.js.map +0 -1
- package/dist/bscPlugin/selectionRanges/SelectionRangesProcessor.spec.d.ts +0 -1
- package/dist/bscPlugin/selectionRanges/SelectionRangesProcessor.spec.js +0 -298
- package/dist/bscPlugin/selectionRanges/SelectionRangesProcessor.spec.js.map +0 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.d.ts +0 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js +0 -399
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +0 -1
- package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.d.ts +0 -1
- package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.js +0 -290
- package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.js.map +0 -1
- package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.d.ts +0 -1
- package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.js +0 -245
- package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.js.map +0 -1
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.d.ts +0 -1
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js +0 -46
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js.map +0 -1
- package/dist/bscPlugin/validation/BrsFileValidator.spec.d.ts +0 -1
- package/dist/bscPlugin/validation/BrsFileValidator.spec.js +0 -487
- package/dist/bscPlugin/validation/BrsFileValidator.spec.js.map +0 -1
- package/dist/common/Sequencer.spec.d.ts +0 -1
- package/dist/common/Sequencer.spec.js +0 -75
- package/dist/common/Sequencer.spec.js.map +0 -1
- package/dist/files/BrsFile.Class.spec.d.ts +0 -1
- package/dist/files/BrsFile.Class.spec.js +0 -1805
- package/dist/files/BrsFile.Class.spec.js.map +0 -1
- package/dist/files/BrsFile.spec.d.ts +0 -1
- package/dist/files/BrsFile.spec.js +0 -4420
- package/dist/files/BrsFile.spec.js.map +0 -1
- package/dist/files/XmlFile.spec.d.ts +0 -1
- package/dist/files/XmlFile.spec.js +0 -1169
- package/dist/files/XmlFile.spec.js.map +0 -1
- package/dist/files/tests/imports.spec.d.ts +0 -1
- package/dist/files/tests/imports.spec.js +0 -241
- package/dist/files/tests/imports.spec.js.map +0 -1
- package/dist/files/tests/optionalChaning.spec.d.ts +0 -1
- package/dist/files/tests/optionalChaning.spec.js +0 -152
- package/dist/files/tests/optionalChaning.spec.js.map +0 -1
- package/dist/lexer/Character.spec.d.ts +0 -1
- package/dist/lexer/Character.spec.js +0 -27
- package/dist/lexer/Character.spec.js.map +0 -1
- package/dist/lexer/Lexer.spec.d.ts +0 -1
- package/dist/lexer/Lexer.spec.js +0 -1300
- package/dist/lexer/Lexer.spec.js.map +0 -1
- package/dist/lsp/ActionQueue.spec.d.ts +0 -1
- package/dist/lsp/ActionQueue.spec.js +0 -80
- package/dist/lsp/ActionQueue.spec.js.map +0 -1
- package/dist/lsp/DocumentManager.spec.d.ts +0 -1
- package/dist/lsp/DocumentManager.spec.js +0 -103
- package/dist/lsp/DocumentManager.spec.js.map +0 -1
- package/dist/lsp/PathFilterer.spec.d.ts +0 -1
- package/dist/lsp/PathFilterer.spec.js +0 -182
- package/dist/lsp/PathFilterer.spec.js.map +0 -1
- package/dist/lsp/Project.spec.d.ts +0 -1
- package/dist/lsp/Project.spec.js +0 -400
- package/dist/lsp/Project.spec.js.map +0 -1
- package/dist/lsp/ProjectManager.spec.d.ts +0 -1
- package/dist/lsp/ProjectManager.spec.js +0 -1147
- package/dist/lsp/ProjectManager.spec.js.map +0 -1
- package/dist/lsp/worker/MessageHandler.spec.d.ts +0 -1
- package/dist/lsp/worker/MessageHandler.spec.js +0 -64
- package/dist/lsp/worker/MessageHandler.spec.js.map +0 -1
- package/dist/lsp/worker/WorkerPool.spec.d.ts +0 -1
- package/dist/lsp/worker/WorkerPool.spec.js +0 -59
- package/dist/lsp/worker/WorkerPool.spec.js.map +0 -1
- package/dist/lsp/worker/WorkerThreadProject.spec.d.ts +0 -2
- package/dist/lsp/worker/WorkerThreadProject.spec.js +0 -72
- package/dist/lsp/worker/WorkerThreadProject.spec.js.map +0 -1
- package/dist/parser/AstNode.spec.d.ts +0 -1
- package/dist/parser/AstNode.spec.js +0 -1452
- package/dist/parser/AstNode.spec.js.map +0 -1
- package/dist/parser/Expression.spec.d.ts +0 -1
- package/dist/parser/Expression.spec.js +0 -40
- package/dist/parser/Expression.spec.js.map +0 -1
- package/dist/parser/Parser.Class.spec.d.ts +0 -1
- package/dist/parser/Parser.Class.spec.js +0 -495
- package/dist/parser/Parser.Class.spec.js.map +0 -1
- package/dist/parser/Parser.spec.d.ts +0 -4
- package/dist/parser/Parser.spec.js +0 -1857
- package/dist/parser/Parser.spec.js.map +0 -1
- package/dist/parser/SGParser.spec.d.ts +0 -1
- package/dist/parser/SGParser.spec.js +0 -131
- package/dist/parser/SGParser.spec.js.map +0 -1
- package/dist/parser/Statement.spec.d.ts +0 -1
- package/dist/parser/Statement.spec.js +0 -118
- package/dist/parser/Statement.spec.js.map +0 -1
- package/dist/parser/tests/Parser.spec.d.ts +0 -19
- package/dist/parser/tests/Parser.spec.js +0 -38
- package/dist/parser/tests/Parser.spec.js.map +0 -1
- package/dist/parser/tests/controlFlow/For.spec.d.ts +0 -1
- package/dist/parser/tests/controlFlow/For.spec.js +0 -161
- package/dist/parser/tests/controlFlow/For.spec.js.map +0 -1
- package/dist/parser/tests/controlFlow/ForEach.spec.d.ts +0 -1
- package/dist/parser/tests/controlFlow/ForEach.spec.js +0 -106
- package/dist/parser/tests/controlFlow/ForEach.spec.js.map +0 -1
- package/dist/parser/tests/controlFlow/If.spec.d.ts +0 -1
- package/dist/parser/tests/controlFlow/If.spec.js +0 -570
- package/dist/parser/tests/controlFlow/If.spec.js.map +0 -1
- package/dist/parser/tests/controlFlow/While.spec.d.ts +0 -1
- package/dist/parser/tests/controlFlow/While.spec.js +0 -107
- package/dist/parser/tests/controlFlow/While.spec.js.map +0 -1
- package/dist/parser/tests/expression/Additive.spec.d.ts +0 -1
- package/dist/parser/tests/expression/Additive.spec.js +0 -99
- package/dist/parser/tests/expression/Additive.spec.js.map +0 -1
- package/dist/parser/tests/expression/ArrayLiterals.spec.d.ts +0 -1
- package/dist/parser/tests/expression/ArrayLiterals.spec.js +0 -291
- package/dist/parser/tests/expression/ArrayLiterals.spec.js.map +0 -1
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.d.ts +0 -1
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +0 -401
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +0 -1
- package/dist/parser/tests/expression/Boolean.spec.d.ts +0 -1
- package/dist/parser/tests/expression/Boolean.spec.js +0 -83
- package/dist/parser/tests/expression/Boolean.spec.js.map +0 -1
- package/dist/parser/tests/expression/Call.spec.d.ts +0 -1
- package/dist/parser/tests/expression/Call.spec.js +0 -242
- package/dist/parser/tests/expression/Call.spec.js.map +0 -1
- package/dist/parser/tests/expression/Exponential.spec.d.ts +0 -1
- package/dist/parser/tests/expression/Exponential.spec.js +0 -37
- package/dist/parser/tests/expression/Exponential.spec.js.map +0 -1
- package/dist/parser/tests/expression/Function.spec.d.ts +0 -1
- package/dist/parser/tests/expression/Function.spec.js +0 -403
- package/dist/parser/tests/expression/Function.spec.js.map +0 -1
- package/dist/parser/tests/expression/Indexing.spec.d.ts +0 -1
- package/dist/parser/tests/expression/Indexing.spec.js +0 -289
- package/dist/parser/tests/expression/Indexing.spec.js.map +0 -1
- package/dist/parser/tests/expression/Multiplicative.spec.d.ts +0 -1
- package/dist/parser/tests/expression/Multiplicative.spec.js +0 -67
- package/dist/parser/tests/expression/Multiplicative.spec.js.map +0 -1
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.d.ts +0 -1
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +0 -346
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +0 -1
- package/dist/parser/tests/expression/PrefixUnary.spec.d.ts +0 -1
- package/dist/parser/tests/expression/PrefixUnary.spec.js +0 -105
- package/dist/parser/tests/expression/PrefixUnary.spec.js.map +0 -1
- package/dist/parser/tests/expression/Primary.spec.d.ts +0 -1
- package/dist/parser/tests/expression/Primary.spec.js +0 -149
- package/dist/parser/tests/expression/Primary.spec.js.map +0 -1
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.d.ts +0 -1
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +0 -171
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.js.map +0 -1
- package/dist/parser/tests/expression/Relational.spec.d.ts +0 -1
- package/dist/parser/tests/expression/Relational.spec.js +0 -83
- package/dist/parser/tests/expression/Relational.spec.js.map +0 -1
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.d.ts +0 -1
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.js +0 -201
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.js.map +0 -1
- package/dist/parser/tests/expression/TemplateStringExpression.spec.d.ts +0 -1
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js +0 -389
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +0 -1
- package/dist/parser/tests/expression/TernaryExpression.spec.d.ts +0 -1
- package/dist/parser/tests/expression/TernaryExpression.spec.js +0 -876
- package/dist/parser/tests/expression/TernaryExpression.spec.js.map +0 -1
- package/dist/parser/tests/expression/UnaryExpression.spec.d.ts +0 -1
- package/dist/parser/tests/expression/UnaryExpression.spec.js +0 -52
- package/dist/parser/tests/expression/UnaryExpression.spec.js.map +0 -1
- package/dist/parser/tests/statement/AssignmentOperators.spec.d.ts +0 -1
- package/dist/parser/tests/statement/AssignmentOperators.spec.js +0 -79
- package/dist/parser/tests/statement/AssignmentOperators.spec.js.map +0 -1
- package/dist/parser/tests/statement/ConstStatement.spec.d.ts +0 -1
- package/dist/parser/tests/statement/ConstStatement.spec.js +0 -708
- package/dist/parser/tests/statement/ConstStatement.spec.js.map +0 -1
- package/dist/parser/tests/statement/Continue.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Continue.spec.js +0 -119
- package/dist/parser/tests/statement/Continue.spec.js.map +0 -1
- package/dist/parser/tests/statement/Declaration.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Declaration.spec.js +0 -108
- package/dist/parser/tests/statement/Declaration.spec.js.map +0 -1
- package/dist/parser/tests/statement/Dim.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Dim.spec.js +0 -73
- package/dist/parser/tests/statement/Dim.spec.js.map +0 -1
- package/dist/parser/tests/statement/Enum.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Enum.spec.js +0 -1307
- package/dist/parser/tests/statement/Enum.spec.js.map +0 -1
- package/dist/parser/tests/statement/For.spec.d.ts +0 -1
- package/dist/parser/tests/statement/For.spec.js +0 -45
- package/dist/parser/tests/statement/For.spec.js.map +0 -1
- package/dist/parser/tests/statement/ForEach.spec.d.ts +0 -1
- package/dist/parser/tests/statement/ForEach.spec.js +0 -36
- package/dist/parser/tests/statement/ForEach.spec.js.map +0 -1
- package/dist/parser/tests/statement/Function.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Function.spec.js +0 -342
- package/dist/parser/tests/statement/Function.spec.js.map +0 -1
- package/dist/parser/tests/statement/Goto.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Goto.spec.js +0 -51
- package/dist/parser/tests/statement/Goto.spec.js.map +0 -1
- package/dist/parser/tests/statement/Increment.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Increment.spec.js +0 -117
- package/dist/parser/tests/statement/Increment.spec.js.map +0 -1
- package/dist/parser/tests/statement/InterfaceStatement.spec.d.ts +0 -1
- package/dist/parser/tests/statement/InterfaceStatement.spec.js +0 -102
- package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +0 -1
- package/dist/parser/tests/statement/LibraryStatement.spec.d.ts +0 -1
- package/dist/parser/tests/statement/LibraryStatement.spec.js +0 -74
- package/dist/parser/tests/statement/LibraryStatement.spec.js.map +0 -1
- package/dist/parser/tests/statement/Misc.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Misc.spec.js +0 -335
- package/dist/parser/tests/statement/Misc.spec.js.map +0 -1
- package/dist/parser/tests/statement/PrintStatement.spec.d.ts +0 -1
- package/dist/parser/tests/statement/PrintStatement.spec.js +0 -195
- package/dist/parser/tests/statement/PrintStatement.spec.js.map +0 -1
- package/dist/parser/tests/statement/ReturnStatement.spec.d.ts +0 -1
- package/dist/parser/tests/statement/ReturnStatement.spec.js +0 -94
- package/dist/parser/tests/statement/ReturnStatement.spec.js.map +0 -1
- package/dist/parser/tests/statement/Set.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Set.spec.js +0 -218
- package/dist/parser/tests/statement/Set.spec.js.map +0 -1
- package/dist/parser/tests/statement/Stop.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Stop.spec.js +0 -38
- package/dist/parser/tests/statement/Stop.spec.js.map +0 -1
- package/dist/parser/tests/statement/Throw.spec.d.ts +0 -1
- package/dist/parser/tests/statement/Throw.spec.js +0 -35
- package/dist/parser/tests/statement/Throw.spec.js.map +0 -1
- package/dist/parser/tests/statement/TryCatch.spec.d.ts +0 -1
- package/dist/parser/tests/statement/TryCatch.spec.js +0 -142
- package/dist/parser/tests/statement/TryCatch.spec.js.map +0 -1
- package/dist/preprocessor/Manifest.spec.d.ts +0 -1
- package/dist/preprocessor/Manifest.spec.js +0 -80
- package/dist/preprocessor/Manifest.spec.js.map +0 -1
- package/dist/preprocessor/Preprocessor.spec.d.ts +0 -1
- package/dist/preprocessor/Preprocessor.spec.js +0 -152
- package/dist/preprocessor/Preprocessor.spec.js.map +0 -1
- package/dist/preprocessor/PreprocessorParser.spec.d.ts +0 -1
- package/dist/preprocessor/PreprocessorParser.spec.js +0 -116
- package/dist/preprocessor/PreprocessorParser.spec.js.map +0 -1
- package/dist/types/ArrayType.spec.d.ts +0 -1
- package/dist/types/ArrayType.spec.js +0 -30
- package/dist/types/ArrayType.spec.js.map +0 -1
- package/dist/types/BooleanType.spec.d.ts +0 -1
- package/dist/types/BooleanType.spec.js +0 -12
- package/dist/types/BooleanType.spec.js.map +0 -1
- package/dist/types/DoubleType.spec.d.ts +0 -1
- package/dist/types/DoubleType.spec.js +0 -12
- package/dist/types/DoubleType.spec.js.map +0 -1
- package/dist/types/DynamicType.spec.d.ts +0 -1
- package/dist/types/DynamicType.spec.js +0 -12
- package/dist/types/DynamicType.spec.js.map +0 -1
- package/dist/types/FloatType.spec.d.ts +0 -1
- package/dist/types/FloatType.spec.js +0 -12
- package/dist/types/FloatType.spec.js.map +0 -1
- package/dist/types/FunctionType.spec.d.ts +0 -1
- package/dist/types/FunctionType.spec.js +0 -23
- package/dist/types/FunctionType.spec.js.map +0 -1
- package/dist/types/IntegerType.spec.d.ts +0 -1
- package/dist/types/IntegerType.spec.js +0 -12
- package/dist/types/IntegerType.spec.js.map +0 -1
- package/dist/types/InterfaceType.spec.d.ts +0 -1
- package/dist/types/InterfaceType.spec.js +0 -175
- package/dist/types/InterfaceType.spec.js.map +0 -1
- package/dist/types/InvalidType.spec.d.ts +0 -1
- package/dist/types/InvalidType.spec.js +0 -12
- package/dist/types/InvalidType.spec.js.map +0 -1
- package/dist/types/LongIntegerType.spec.d.ts +0 -1
- package/dist/types/LongIntegerType.spec.js +0 -12
- package/dist/types/LongIntegerType.spec.js.map +0 -1
- package/dist/types/ObjectType.spec.d.ts +0 -1
- package/dist/types/ObjectType.spec.js +0 -12
- package/dist/types/ObjectType.spec.js.map +0 -1
- package/dist/types/StringType.spec.d.ts +0 -1
- package/dist/types/StringType.spec.js +0 -12
- package/dist/types/StringType.spec.js.map +0 -1
- package/dist/types/VoidType.spec.d.ts +0 -1
- package/dist/types/VoidType.spec.js +0 -12
- package/dist/types/VoidType.spec.js.map +0 -1
|
@@ -1,1857 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.failStatementType = exports.rangeToArray = void 0;
|
|
4
|
-
const chai_config_spec_1 = require("../chai-config.spec");
|
|
5
|
-
const Lexer_1 = require("../lexer/Lexer");
|
|
6
|
-
const TokenKind_1 = require("../lexer/TokenKind");
|
|
7
|
-
const Expression_1 = require("./Expression");
|
|
8
|
-
const Parser_1 = require("./Parser");
|
|
9
|
-
const Statement_1 = require("./Statement");
|
|
10
|
-
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
11
|
-
const DiagnosticMessages_1 = require("../DiagnosticMessages");
|
|
12
|
-
const reflection_1 = require("../astUtils/reflection");
|
|
13
|
-
const testHelpers_spec_1 = require("../testHelpers.spec");
|
|
14
|
-
const BrsTranspileState_1 = require("./BrsTranspileState");
|
|
15
|
-
const source_map_1 = require("source-map");
|
|
16
|
-
const BrsFile_1 = require("../files/BrsFile");
|
|
17
|
-
const Program_1 = require("../Program");
|
|
18
|
-
const visitors_1 = require("../astUtils/visitors");
|
|
19
|
-
describe('parser', () => {
|
|
20
|
-
it('emits empty object when empty token list is provided', () => {
|
|
21
|
-
(0, chai_config_spec_1.expect)(Parser_1.Parser.parse([])).to.deep.include({
|
|
22
|
-
statements: [],
|
|
23
|
-
diagnostics: []
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
describe('findReferences', () => {
|
|
27
|
-
it('gets called if references are missing', () => {
|
|
28
|
-
const parser = Parser_1.Parser.parse(`
|
|
29
|
-
sub main()
|
|
30
|
-
end sub
|
|
31
|
-
|
|
32
|
-
sub UnusedFunction()
|
|
33
|
-
end sub
|
|
34
|
-
`);
|
|
35
|
-
(0, chai_config_spec_1.expect)(parser.references.functionStatements.map(x => x.name.text)).to.eql([
|
|
36
|
-
'main',
|
|
37
|
-
'UnusedFunction'
|
|
38
|
-
]);
|
|
39
|
-
//simulate a tree-shaking plugin by removing the `UnusedFunction`
|
|
40
|
-
parser.ast.statements.splice(1);
|
|
41
|
-
//tell the parser we modified the AST and need to regenerate references
|
|
42
|
-
parser.invalidateReferences();
|
|
43
|
-
(0, chai_config_spec_1.expect)(parser['_references']).not.to.exist;
|
|
44
|
-
//calling `references` automatically regenerates the references
|
|
45
|
-
(0, chai_config_spec_1.expect)(parser.references.functionStatements.map(x => x.name.text)).to.eql([
|
|
46
|
-
'main'
|
|
47
|
-
]);
|
|
48
|
-
});
|
|
49
|
-
function expressionsToStrings(expressions) {
|
|
50
|
-
return [...expressions.values()].map(x => {
|
|
51
|
-
const file = new BrsFile_1.BrsFile('', '', new Program_1.Program({}));
|
|
52
|
-
const state = new BrsTranspileState_1.BrsTranspileState(file);
|
|
53
|
-
return new source_map_1.SourceNode(null, null, null, x.transpile(state)).toString();
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
it('works for references.expressions', () => {
|
|
57
|
-
const parser = Parser_1.Parser.parse(`
|
|
58
|
-
b += "plus-equal"
|
|
59
|
-
a += 1 + 2
|
|
60
|
-
b += getValue1() + getValue2()
|
|
61
|
-
increment++
|
|
62
|
-
decrement--
|
|
63
|
-
some.node@.doCallfunc()
|
|
64
|
-
bravo(3 + 4).jump(callMe())
|
|
65
|
-
obj = {
|
|
66
|
-
val1: someValue
|
|
67
|
-
}
|
|
68
|
-
arr = [
|
|
69
|
-
one
|
|
70
|
-
]
|
|
71
|
-
thing = alpha.bravo
|
|
72
|
-
alpha.charlie()
|
|
73
|
-
delta(alpha.delta)
|
|
74
|
-
call1().a.b.call2()
|
|
75
|
-
class Person
|
|
76
|
-
name as string = "bob"
|
|
77
|
-
end class
|
|
78
|
-
function thing(p1 = name.space.getSomething())
|
|
79
|
-
|
|
80
|
-
end function
|
|
81
|
-
`);
|
|
82
|
-
const expected = [
|
|
83
|
-
'"plus-equal"',
|
|
84
|
-
'b',
|
|
85
|
-
'b += "plus-equal"',
|
|
86
|
-
'1',
|
|
87
|
-
'2',
|
|
88
|
-
'a',
|
|
89
|
-
'a += 1 + 2',
|
|
90
|
-
'getValue1()',
|
|
91
|
-
'getValue2()',
|
|
92
|
-
'b',
|
|
93
|
-
'b += getValue1() + getValue2()',
|
|
94
|
-
'increment++',
|
|
95
|
-
'decrement--',
|
|
96
|
-
//currently the "toString" does a transpile, so that's why this is different.
|
|
97
|
-
'some.node.callfunc("doCallfunc", invalid)',
|
|
98
|
-
'3',
|
|
99
|
-
'4',
|
|
100
|
-
'3 + 4',
|
|
101
|
-
'callMe()',
|
|
102
|
-
'bravo(3 + 4).jump(callMe())',
|
|
103
|
-
'someValue',
|
|
104
|
-
'{\n val1: someValue\n}',
|
|
105
|
-
'one',
|
|
106
|
-
'[\n one\n]',
|
|
107
|
-
'alpha.bravo',
|
|
108
|
-
'alpha.charlie()',
|
|
109
|
-
'alpha.delta',
|
|
110
|
-
'delta(alpha.delta)',
|
|
111
|
-
'call1().a.b.call2()',
|
|
112
|
-
'"bob"',
|
|
113
|
-
'name.space.getSomething()'
|
|
114
|
-
];
|
|
115
|
-
(0, chai_config_spec_1.expect)(expressionsToStrings(parser.references.expressions)).to.eql(expected);
|
|
116
|
-
//tell the parser we modified the AST and need to regenerate references
|
|
117
|
-
parser.invalidateReferences();
|
|
118
|
-
(0, chai_config_spec_1.expect)(expressionsToStrings(parser.references.expressions).sort()).to.eql(expected.sort());
|
|
119
|
-
});
|
|
120
|
-
it('works for references.expressions', () => {
|
|
121
|
-
const parser = Parser_1.Parser.parse(`
|
|
122
|
-
value = true or type(true) = "something" or Enums.A.Value = "value" and Enum1.Value = Name.Space.Enum2.Value
|
|
123
|
-
`);
|
|
124
|
-
const expected = [
|
|
125
|
-
'true',
|
|
126
|
-
'type(true)',
|
|
127
|
-
'"something"',
|
|
128
|
-
'true',
|
|
129
|
-
'Enums.A.Value',
|
|
130
|
-
'"value"',
|
|
131
|
-
'Enum1.Value',
|
|
132
|
-
'Name.Space.Enum2.Value',
|
|
133
|
-
'true or type(true) = "something" or Enums.A.Value = "value" and Enum1.Value = Name.Space.Enum2.Value'
|
|
134
|
-
];
|
|
135
|
-
(0, chai_config_spec_1.expect)(expressionsToStrings(parser.references.expressions)).to.eql(expected);
|
|
136
|
-
//tell the parser we modified the AST and need to regenerate references
|
|
137
|
-
parser.invalidateReferences();
|
|
138
|
-
(0, chai_config_spec_1.expect)(expressionsToStrings(parser.references.expressions).sort()).to.eql(expected.sort());
|
|
139
|
-
});
|
|
140
|
-
it('works for logical expression', () => {
|
|
141
|
-
const parser = Parser_1.Parser.parse(`
|
|
142
|
-
value = Enums.A.Value = "value"
|
|
143
|
-
`);
|
|
144
|
-
const expected = [
|
|
145
|
-
'Enums.A.Value',
|
|
146
|
-
'"value"',
|
|
147
|
-
'Enums.A.Value = "value"'
|
|
148
|
-
];
|
|
149
|
-
(0, chai_config_spec_1.expect)(expressionsToStrings(parser.references.expressions)).to.eql(expected);
|
|
150
|
-
//tell the parser we modified the AST and need to regenerate references
|
|
151
|
-
parser.invalidateReferences();
|
|
152
|
-
(0, chai_config_spec_1.expect)(expressionsToStrings(parser.references.expressions).sort()).to.eql(expected.sort());
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
describe('callfunc operator', () => {
|
|
156
|
-
it('is not allowed in brightscript mode', () => {
|
|
157
|
-
var _a;
|
|
158
|
-
let parser = parse(`
|
|
159
|
-
sub main(node as dynamic)
|
|
160
|
-
node@.doSomething(1, 2)
|
|
161
|
-
end sub
|
|
162
|
-
`, Parser_1.ParseMode.BrightScript);
|
|
163
|
-
(0, chai_config_spec_1.expect)((_a = parser.diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.bsFeatureNotSupportedInBrsFiles('callfunc operator').message);
|
|
164
|
-
});
|
|
165
|
-
it('does not cause parse errors', () => {
|
|
166
|
-
var _a, _b, _c, _d, _e;
|
|
167
|
-
let parser = parse(`
|
|
168
|
-
sub main(node as dynamic)
|
|
169
|
-
node@.doSomething(1, 2)
|
|
170
|
-
end sub
|
|
171
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
172
|
-
(0, chai_config_spec_1.expect)((_a = parser.diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
173
|
-
(0, chai_config_spec_1.expect)((_e = (_d = (_c = (_b = parser.statements[0]) === null || _b === void 0 ? void 0 : _b.func) === null || _c === void 0 ? void 0 : _c.body) === null || _d === void 0 ? void 0 : _d.statements[0]) === null || _e === void 0 ? void 0 : _e.expression).to.be.instanceof(Expression_1.CallfuncExpression);
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
describe('optional chaining operator', () => {
|
|
177
|
-
function getExpression(text, options) {
|
|
178
|
-
const parser = parse(text, options === null || options === void 0 ? void 0 : options.parseMode);
|
|
179
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser);
|
|
180
|
-
const expressions = [...parser.references.expressions];
|
|
181
|
-
if (options === null || options === void 0 ? void 0 : options.matcher) {
|
|
182
|
-
return expressions.find(options.matcher);
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
return expressions[0];
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
it('works for ?.', () => {
|
|
189
|
-
const expression = getExpression(`value = person?.name`);
|
|
190
|
-
(0, chai_config_spec_1.expect)(expression).to.be.instanceOf(Expression_1.DottedGetExpression);
|
|
191
|
-
(0, chai_config_spec_1.expect)(expression.dot.kind).to.eql(TokenKind_1.TokenKind.QuestionDot);
|
|
192
|
-
});
|
|
193
|
-
it('works for ?[', () => {
|
|
194
|
-
const expression = getExpression(`value = person?["name"]`, { matcher: reflection_1.isIndexedGetExpression });
|
|
195
|
-
(0, chai_config_spec_1.expect)(expression).to.be.instanceOf(Expression_1.IndexedGetExpression);
|
|
196
|
-
(0, chai_config_spec_1.expect)(expression.openingSquare.kind).to.eql(TokenKind_1.TokenKind.QuestionLeftSquare);
|
|
197
|
-
(0, chai_config_spec_1.expect)(expression.questionDotToken).not.to.exist;
|
|
198
|
-
});
|
|
199
|
-
it('works for ?.[', () => {
|
|
200
|
-
var _a;
|
|
201
|
-
const expression = getExpression(`value = person?.["name"]`, { matcher: reflection_1.isIndexedGetExpression });
|
|
202
|
-
(0, chai_config_spec_1.expect)(expression).to.be.instanceOf(Expression_1.IndexedGetExpression);
|
|
203
|
-
(0, chai_config_spec_1.expect)(expression.openingSquare.kind).to.eql(TokenKind_1.TokenKind.LeftSquareBracket);
|
|
204
|
-
(0, chai_config_spec_1.expect)((_a = expression.questionDotToken) === null || _a === void 0 ? void 0 : _a.kind).to.eql(TokenKind_1.TokenKind.QuestionDot);
|
|
205
|
-
});
|
|
206
|
-
it('works for ?@', () => {
|
|
207
|
-
const expression = getExpression(`value = someXml?@someAttr`);
|
|
208
|
-
(0, chai_config_spec_1.expect)(expression).to.be.instanceOf(Expression_1.XmlAttributeGetExpression);
|
|
209
|
-
(0, chai_config_spec_1.expect)(expression.at.kind).to.eql(TokenKind_1.TokenKind.QuestionAt);
|
|
210
|
-
});
|
|
211
|
-
it('works for ?(', () => {
|
|
212
|
-
const expression = getExpression(`value = person.getName?()`);
|
|
213
|
-
(0, chai_config_spec_1.expect)(expression).to.be.instanceOf(Expression_1.CallExpression);
|
|
214
|
-
(0, chai_config_spec_1.expect)(expression.openingParen.kind).to.eql(TokenKind_1.TokenKind.QuestionLeftParen);
|
|
215
|
-
});
|
|
216
|
-
it('works for print statements using question mark', () => {
|
|
217
|
-
const { statements } = parse(`
|
|
218
|
-
?[1]
|
|
219
|
-
?(1+1)
|
|
220
|
-
`);
|
|
221
|
-
(0, chai_config_spec_1.expect)(statements[0]).to.be.instanceOf(Statement_1.PrintStatement);
|
|
222
|
-
(0, chai_config_spec_1.expect)(statements[1]).to.be.instanceOf(Statement_1.PrintStatement);
|
|
223
|
-
});
|
|
224
|
-
//TODO enable this once we properly parse IIFEs
|
|
225
|
-
it.skip('works for ?( in anonymous function', () => {
|
|
226
|
-
const expression = getExpression(`thing = (function() : end function)?()`);
|
|
227
|
-
(0, chai_config_spec_1.expect)(expression).to.be.instanceOf(Expression_1.CallExpression);
|
|
228
|
-
(0, chai_config_spec_1.expect)(expression.openingParen.kind).to.eql(TokenKind_1.TokenKind.QuestionLeftParen);
|
|
229
|
-
});
|
|
230
|
-
it('works for ?( in new call', () => {
|
|
231
|
-
const expression = getExpression(`thing = new Person?()`, { parseMode: Parser_1.ParseMode.BrighterScript });
|
|
232
|
-
(0, chai_config_spec_1.expect)(expression).to.be.instanceOf(Expression_1.NewExpression);
|
|
233
|
-
(0, chai_config_spec_1.expect)(expression.call.openingParen.kind).to.eql(TokenKind_1.TokenKind.QuestionLeftParen);
|
|
234
|
-
});
|
|
235
|
-
it('distinguishes between optional chaining and ternary expression', () => {
|
|
236
|
-
const parser = parse(`
|
|
237
|
-
sub main()
|
|
238
|
-
name = person?["name"]
|
|
239
|
-
isTrue = true
|
|
240
|
-
key = isTrue ? ["name"] : ["age"]
|
|
241
|
-
end sub
|
|
242
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
243
|
-
(0, chai_config_spec_1.expect)(parser.references.assignmentStatements[0].value).is.instanceof(Expression_1.IndexedGetExpression);
|
|
244
|
-
(0, chai_config_spec_1.expect)(parser.references.assignmentStatements[2].value).is.instanceof(Expression_1.TernaryExpression);
|
|
245
|
-
});
|
|
246
|
-
it('distinguishes between optional chaining and ternary expression', () => {
|
|
247
|
-
const parser = parse(`
|
|
248
|
-
sub main()
|
|
249
|
-
'optional chain. the lack of whitespace between ? and [ matters
|
|
250
|
-
key = isTrue ?["name"] : getDefault()
|
|
251
|
-
'ternary
|
|
252
|
-
key = isTrue ? ["name"] : getDefault()
|
|
253
|
-
end sub
|
|
254
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
255
|
-
(0, chai_config_spec_1.expect)(parser.references.assignmentStatements[0].value).is.instanceof(Expression_1.IndexedGetExpression);
|
|
256
|
-
(0, chai_config_spec_1.expect)(parser.references.assignmentStatements[1].value).is.instanceof(Expression_1.TernaryExpression);
|
|
257
|
-
});
|
|
258
|
-
});
|
|
259
|
-
describe('diagnostic locations', () => {
|
|
260
|
-
it('tracks basic diagnostic locations', () => {
|
|
261
|
-
(0, chai_config_spec_1.expect)(parse(`
|
|
262
|
-
sub main()
|
|
263
|
-
call()a
|
|
264
|
-
end sub
|
|
265
|
-
`).diagnostics.map(x => rangeToArray(x.range))).to.eql([
|
|
266
|
-
[2, 26, 2, 27],
|
|
267
|
-
[2, 27, 2, 28]
|
|
268
|
-
]);
|
|
269
|
-
});
|
|
270
|
-
it.skip('handles edge cases', () => {
|
|
271
|
-
var _a, _b;
|
|
272
|
-
let diagnostics = parse(`
|
|
273
|
-
function BuildCommit()
|
|
274
|
-
return "6c5cdf1"
|
|
275
|
-
end functionasdf
|
|
276
|
-
`).diagnostics;
|
|
277
|
-
(0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.exist.and.to.eql(DiagnosticMessages_1.DiagnosticMessages.expectedStatementOrFunctionCallButReceivedExpression().message);
|
|
278
|
-
(0, chai_config_spec_1.expect)((_b = diagnostics[0]) === null || _b === void 0 ? void 0 : _b.range).to.eql(vscode_languageserver_1.Range.create(3, 20, 3, 32));
|
|
279
|
-
});
|
|
280
|
-
});
|
|
281
|
-
describe('parse', () => {
|
|
282
|
-
it('supports ungrouped iife in assignment', () => {
|
|
283
|
-
const parser = parse(`
|
|
284
|
-
sub main()
|
|
285
|
-
result = sub()
|
|
286
|
-
end sub()
|
|
287
|
-
result = function()
|
|
288
|
-
end function()
|
|
289
|
-
end sub
|
|
290
|
-
`);
|
|
291
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser);
|
|
292
|
-
});
|
|
293
|
-
it('supports grouped iife in assignment', () => {
|
|
294
|
-
const parser = parse(`
|
|
295
|
-
sub main()
|
|
296
|
-
result = (sub()
|
|
297
|
-
end sub)()
|
|
298
|
-
result = (function()
|
|
299
|
-
end function)()
|
|
300
|
-
end sub
|
|
301
|
-
`);
|
|
302
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser);
|
|
303
|
-
});
|
|
304
|
-
it('supports returning iife call', () => {
|
|
305
|
-
const parser = parse(`
|
|
306
|
-
sub main()
|
|
307
|
-
return (sub()
|
|
308
|
-
end sub)()
|
|
309
|
-
end sub
|
|
310
|
-
`);
|
|
311
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser);
|
|
312
|
-
});
|
|
313
|
-
it('supports using "interface" as parameter name', () => {
|
|
314
|
-
var _a;
|
|
315
|
-
(0, chai_config_spec_1.expect)((_a = parse(`
|
|
316
|
-
sub main(interface as object)
|
|
317
|
-
end sub
|
|
318
|
-
`, Parser_1.ParseMode.BrighterScript).diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
319
|
-
});
|
|
320
|
-
it('does not scrap the entire function when encountering unknown parameter type', () => {
|
|
321
|
-
const parser = parse(`
|
|
322
|
-
sub test(param1 as unknownType)
|
|
323
|
-
end sub
|
|
324
|
-
`);
|
|
325
|
-
(0, testHelpers_spec_1.expectDiagnostics)(parser, [Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.functionParameterTypeIsInvalid('param1', 'unknownType'))]);
|
|
326
|
-
(0, chai_config_spec_1.expect)((0, reflection_1.isFunctionStatement)(parser.ast.statements[0])).to.be.true;
|
|
327
|
-
});
|
|
328
|
-
describe('namespace', () => {
|
|
329
|
-
it('allows namespaces declared inside other namespaces', () => {
|
|
330
|
-
const parser = parse(`
|
|
331
|
-
namespace Level1
|
|
332
|
-
namespace Level2.Level3
|
|
333
|
-
sub main()
|
|
334
|
-
end sub
|
|
335
|
-
end namespace
|
|
336
|
-
end namespace
|
|
337
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
338
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser);
|
|
339
|
-
// We expect these names to be "as given" in this context, because we aren't evaluating a full program.
|
|
340
|
-
(0, chai_config_spec_1.expect)(parser.references.namespaceStatements.map(statement => statement.getName(Parser_1.ParseMode.BrighterScript))).to.deep.equal([
|
|
341
|
-
'Level1.Level2.Level3',
|
|
342
|
-
'Level1'
|
|
343
|
-
]);
|
|
344
|
-
});
|
|
345
|
-
it('parses empty namespace', () => {
|
|
346
|
-
var _a;
|
|
347
|
-
let { statements, diagnostics } = parse(`
|
|
348
|
-
namespace Name.Space
|
|
349
|
-
end namespace
|
|
350
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
351
|
-
(0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
352
|
-
(0, chai_config_spec_1.expect)(statements[0]).to.be.instanceof(Statement_1.NamespaceStatement);
|
|
353
|
-
});
|
|
354
|
-
it('includes body', () => {
|
|
355
|
-
var _a;
|
|
356
|
-
let { statements, diagnostics } = parse(`
|
|
357
|
-
namespace Name.Space
|
|
358
|
-
sub main()
|
|
359
|
-
end sub
|
|
360
|
-
end namespace
|
|
361
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
362
|
-
(0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
363
|
-
(0, chai_config_spec_1.expect)(statements[0]).to.be.instanceof(Statement_1.NamespaceStatement);
|
|
364
|
-
(0, chai_config_spec_1.expect)(statements[0].body.statements[0]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
365
|
-
});
|
|
366
|
-
it('supports comments and newlines', () => {
|
|
367
|
-
var _a;
|
|
368
|
-
let { diagnostics } = parse(`
|
|
369
|
-
namespace Name.Space 'comment
|
|
370
|
-
|
|
371
|
-
'comment
|
|
372
|
-
|
|
373
|
-
sub main() 'comment
|
|
374
|
-
end sub 'comment
|
|
375
|
-
'comment
|
|
376
|
-
|
|
377
|
-
'comment
|
|
378
|
-
end namespace 'comment
|
|
379
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
380
|
-
(0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
381
|
-
});
|
|
382
|
-
it('catches missing name', () => {
|
|
383
|
-
var _a;
|
|
384
|
-
let { diagnostics } = parse(`
|
|
385
|
-
namespace
|
|
386
|
-
end namespace
|
|
387
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
388
|
-
(0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.expectedIdentifierAfterKeyword('namespace').message);
|
|
389
|
-
});
|
|
390
|
-
it('recovers after missing `end namespace`', () => {
|
|
391
|
-
var _a, _b, _c;
|
|
392
|
-
let parser = parse(`
|
|
393
|
-
namespace Name.Space
|
|
394
|
-
sub main()
|
|
395
|
-
end sub
|
|
396
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
397
|
-
(0, chai_config_spec_1.expect)(parser.ast.statements[0]).to.be.instanceof(Statement_1.NamespaceStatement);
|
|
398
|
-
(0, chai_config_spec_1.expect)((_a = parser.diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.couldNotFindMatchingEndKeyword('namespace').message);
|
|
399
|
-
(0, chai_config_spec_1.expect)((_c = (_b = parser.ast.statements[0]) === null || _b === void 0 ? void 0 : _b.body) === null || _c === void 0 ? void 0 : _c.statements[0]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
400
|
-
});
|
|
401
|
-
it('adds diagnostic when encountering namespace in brightscript mode', () => {
|
|
402
|
-
var _a;
|
|
403
|
-
let parser = Parser_1.Parser.parse(`
|
|
404
|
-
namespace Name.Space
|
|
405
|
-
end namespace
|
|
406
|
-
`);
|
|
407
|
-
(0, chai_config_spec_1.expect)((_a = parser.diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.bsFeatureNotSupportedInBrsFiles('namespace').message);
|
|
408
|
-
});
|
|
409
|
-
});
|
|
410
|
-
it('supports << operator', () => {
|
|
411
|
-
var _a;
|
|
412
|
-
(0, chai_config_spec_1.expect)((_a = parse(`
|
|
413
|
-
sub main()
|
|
414
|
-
print ((r << 24) + (g << 16) + (b << 8) + a)
|
|
415
|
-
end sub
|
|
416
|
-
`).diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
417
|
-
});
|
|
418
|
-
it('supports >> operator', () => {
|
|
419
|
-
var _a;
|
|
420
|
-
(0, chai_config_spec_1.expect)((_a = parse(`
|
|
421
|
-
sub main()
|
|
422
|
-
print ((r >> 24) + (g >> 16) + (b >> 8) + a)
|
|
423
|
-
end sub
|
|
424
|
-
`).diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
425
|
-
});
|
|
426
|
-
it('allows global function names with same as token to be called', () => {
|
|
427
|
-
var _a;
|
|
428
|
-
(0, chai_config_spec_1.expect)((_a = parse(`
|
|
429
|
-
sub main()
|
|
430
|
-
print string(123)
|
|
431
|
-
end sub
|
|
432
|
-
`).diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
433
|
-
});
|
|
434
|
-
it('supports @ symbol between names', () => {
|
|
435
|
-
var _a;
|
|
436
|
-
let parser = parse(`
|
|
437
|
-
sub main()
|
|
438
|
-
firstName = personXml@firstName
|
|
439
|
-
age = personXml.firstChild@age
|
|
440
|
-
end sub
|
|
441
|
-
`);
|
|
442
|
-
(0, chai_config_spec_1.expect)((_a = parser.diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.not.exist;
|
|
443
|
-
let statements = parser.statements[0].func.body.statements;
|
|
444
|
-
let first = statements[0].value;
|
|
445
|
-
(0, chai_config_spec_1.expect)(first).to.be.instanceof(Expression_1.XmlAttributeGetExpression);
|
|
446
|
-
(0, chai_config_spec_1.expect)(first.name.text).to.equal('firstName');
|
|
447
|
-
(0, chai_config_spec_1.expect)(first.at.text).to.equal('@');
|
|
448
|
-
(0, chai_config_spec_1.expect)(first.obj.name.text).to.equal('personXml');
|
|
449
|
-
let second = statements[1].value;
|
|
450
|
-
(0, chai_config_spec_1.expect)(second).to.be.instanceof(Expression_1.XmlAttributeGetExpression);
|
|
451
|
-
(0, chai_config_spec_1.expect)(second.name.text).to.equal('age');
|
|
452
|
-
(0, chai_config_spec_1.expect)(second.at.text).to.equal('@');
|
|
453
|
-
(0, chai_config_spec_1.expect)(second.obj.name.text).to.equal('firstChild');
|
|
454
|
-
});
|
|
455
|
-
it('does not allow chaining of @ symbols', () => {
|
|
456
|
-
let parser = parse(`
|
|
457
|
-
sub main()
|
|
458
|
-
personXml = invalid
|
|
459
|
-
name = personXml@name@age@shoeSize
|
|
460
|
-
end sub
|
|
461
|
-
`);
|
|
462
|
-
(0, chai_config_spec_1.expect)(parser.diagnostics).not.to.be.empty;
|
|
463
|
-
});
|
|
464
|
-
it('unknown function type does not invalidate rest of function', () => {
|
|
465
|
-
let { statements, diagnostics } = parse(`
|
|
466
|
-
function log() as UNKNOWN_TYPE
|
|
467
|
-
end function
|
|
468
|
-
`, Parser_1.ParseMode.BrightScript);
|
|
469
|
-
(0, chai_config_spec_1.expect)(diagnostics.length).to.be.greaterThan(0);
|
|
470
|
-
(0, chai_config_spec_1.expect)(statements[0]).to.exist;
|
|
471
|
-
});
|
|
472
|
-
it('unknown function type is not a problem in Brighterscript mode', () => {
|
|
473
|
-
let { statements, diagnostics } = parse(`
|
|
474
|
-
function log() as UNKNOWN_TYPE
|
|
475
|
-
end function
|
|
476
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
477
|
-
(0, chai_config_spec_1.expect)(diagnostics.length).to.equal(0);
|
|
478
|
-
(0, chai_config_spec_1.expect)(statements[0]).to.exist;
|
|
479
|
-
});
|
|
480
|
-
it('allows namespaced function type in Brighterscript mode', () => {
|
|
481
|
-
let { statements, diagnostics } = parse(`
|
|
482
|
-
function log() as SOME_NAMESPACE.UNKNOWN_TYPE
|
|
483
|
-
end function
|
|
484
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
485
|
-
(0, chai_config_spec_1.expect)(diagnostics.length).to.equal(0);
|
|
486
|
-
(0, chai_config_spec_1.expect)(statements[0]).to.exist;
|
|
487
|
-
});
|
|
488
|
-
it('allows custom parameter types in BrighterscriptMode', () => {
|
|
489
|
-
let { statements, diagnostics } = parse(`
|
|
490
|
-
sub foo(value as UNKNOWN_TYPE)
|
|
491
|
-
end sub
|
|
492
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
493
|
-
(0, chai_config_spec_1.expect)(diagnostics.length).to.equal(0);
|
|
494
|
-
(0, chai_config_spec_1.expect)(statements[0]).to.exist;
|
|
495
|
-
});
|
|
496
|
-
it('does not allow custom parameter types in Brightscript Mode', () => {
|
|
497
|
-
let { diagnostics } = parse(`
|
|
498
|
-
sub foo(value as UNKNOWN_TYPE)
|
|
499
|
-
end sub
|
|
500
|
-
`, Parser_1.ParseMode.BrightScript);
|
|
501
|
-
(0, chai_config_spec_1.expect)(diagnostics.length).not.to.equal(0);
|
|
502
|
-
});
|
|
503
|
-
it('allows custom namespaced parameter types in BrighterscriptMode', () => {
|
|
504
|
-
let { statements, diagnostics } = parse(`
|
|
505
|
-
sub foo(value as SOME_NAMESPACE.UNKNOWN_TYPE)
|
|
506
|
-
end sub
|
|
507
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
508
|
-
(0, chai_config_spec_1.expect)(diagnostics.length).to.equal(0);
|
|
509
|
-
(0, chai_config_spec_1.expect)(statements[0]).to.exist;
|
|
510
|
-
});
|
|
511
|
-
it('works with conditionals', () => {
|
|
512
|
-
var _a;
|
|
513
|
-
(0, chai_config_spec_1.expect)((_a = parse(`
|
|
514
|
-
function printNumber()
|
|
515
|
-
if true then
|
|
516
|
-
print 1
|
|
517
|
-
else if true
|
|
518
|
-
return false
|
|
519
|
-
end if
|
|
520
|
-
end function
|
|
521
|
-
`).diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
522
|
-
});
|
|
523
|
-
it('supports single-line if statements', () => {
|
|
524
|
-
var _a;
|
|
525
|
-
(0, chai_config_spec_1.expect)((_a = parse(`If true Then print "error" : Stop`).diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.not.exist;
|
|
526
|
-
});
|
|
527
|
-
it('works with excess newlines', () => {
|
|
528
|
-
var _a;
|
|
529
|
-
let { tokens } = Lexer_1.Lexer.scan('function boolToNumber() as string\n\n' +
|
|
530
|
-
' if true then\n\n' +
|
|
531
|
-
' print 1\n\n' +
|
|
532
|
-
' elseif true then\n\n' +
|
|
533
|
-
' print 0\n\n' +
|
|
534
|
-
' else\n\n' +
|
|
535
|
-
' print 1\n\n' +
|
|
536
|
-
' end if\n\n' +
|
|
537
|
-
'end function\n\n');
|
|
538
|
-
(0, chai_config_spec_1.expect)((_a = Parser_1.Parser.parse(tokens).diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.not.exist;
|
|
539
|
-
});
|
|
540
|
-
it('does not invalidate entire file when line ends with a period', () => {
|
|
541
|
-
let { tokens } = Lexer_1.Lexer.scan(`
|
|
542
|
-
sub main()
|
|
543
|
-
person.a
|
|
544
|
-
end sub
|
|
545
|
-
|
|
546
|
-
`);
|
|
547
|
-
let { diagnostics } = Parser_1.Parser.parse(tokens);
|
|
548
|
-
(0, chai_config_spec_1.expect)(diagnostics).to.be.lengthOf(1, 'Error count should be 0');
|
|
549
|
-
});
|
|
550
|
-
it.skip('allows printing object with trailing period', () => {
|
|
551
|
-
let { tokens } = Lexer_1.Lexer.scan(`print a.`);
|
|
552
|
-
let { statements, diagnostics } = Parser_1.Parser.parse(tokens);
|
|
553
|
-
let printStatement = statements[0];
|
|
554
|
-
(0, chai_config_spec_1.expect)(diagnostics).to.be.empty;
|
|
555
|
-
(0, chai_config_spec_1.expect)(printStatement).to.be.instanceof(Statement_1.PrintStatement);
|
|
556
|
-
(0, chai_config_spec_1.expect)(printStatement.expressions[0]).to.be.instanceof(Expression_1.DottedGetExpression);
|
|
557
|
-
});
|
|
558
|
-
describe('comments', () => {
|
|
559
|
-
it('combines multi-line comments', () => {
|
|
560
|
-
let { tokens } = Lexer_1.Lexer.scan(`
|
|
561
|
-
'line 1
|
|
562
|
-
'line 2
|
|
563
|
-
'line 3
|
|
564
|
-
`);
|
|
565
|
-
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
566
|
-
(0, chai_config_spec_1.expect)(diagnostics).to.be.lengthOf(0, 'Error count should be 0');
|
|
567
|
-
(0, chai_config_spec_1.expect)(statements[0].text).to.equal(`'line 1\n'line 2\n'line 3`);
|
|
568
|
-
});
|
|
569
|
-
it('does not combile comments separated by newlines', () => {
|
|
570
|
-
let { tokens } = Lexer_1.Lexer.scan(`
|
|
571
|
-
'line 1
|
|
572
|
-
|
|
573
|
-
'line 2
|
|
574
|
-
|
|
575
|
-
'line 3
|
|
576
|
-
`);
|
|
577
|
-
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
578
|
-
(0, chai_config_spec_1.expect)(diagnostics).to.be.lengthOf(0, 'Error count should be 0');
|
|
579
|
-
(0, chai_config_spec_1.expect)(statements).to.be.lengthOf(3);
|
|
580
|
-
(0, chai_config_spec_1.expect)(statements[0].text).to.equal(`'line 1`);
|
|
581
|
-
(0, chai_config_spec_1.expect)(statements[1].text).to.equal(`'line 2`);
|
|
582
|
-
(0, chai_config_spec_1.expect)(statements[2].text).to.equal(`'line 3`);
|
|
583
|
-
});
|
|
584
|
-
it('works after print statement', () => {
|
|
585
|
-
let { tokens } = Lexer_1.Lexer.scan(`
|
|
586
|
-
sub main()
|
|
587
|
-
print "hi" 'comment 1
|
|
588
|
-
end sub
|
|
589
|
-
`);
|
|
590
|
-
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
591
|
-
(0, chai_config_spec_1.expect)(diagnostics).to.be.lengthOf(0, 'Error count should be 0');
|
|
592
|
-
(0, chai_config_spec_1.expect)(statements[0].func.body.statements[1].text).to.equal(`'comment 1`);
|
|
593
|
-
});
|
|
594
|
-
it('declaration-level', () => {
|
|
595
|
-
let { tokens } = Lexer_1.Lexer.scan(`
|
|
596
|
-
'comment 1
|
|
597
|
-
function a()
|
|
598
|
-
end function
|
|
599
|
-
'comment 2
|
|
600
|
-
`);
|
|
601
|
-
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
602
|
-
(0, chai_config_spec_1.expect)(diagnostics).to.be.lengthOf(0, 'Error count should be 0');
|
|
603
|
-
(0, chai_config_spec_1.expect)(statements[0].text).to.equal(`'comment 1`);
|
|
604
|
-
(0, chai_config_spec_1.expect)(statements[2].text).to.equal(`'comment 2`);
|
|
605
|
-
});
|
|
606
|
-
it('works in aa literal as its own statement', () => {
|
|
607
|
-
let { tokens } = Lexer_1.Lexer.scan(`
|
|
608
|
-
obj = {
|
|
609
|
-
"name": true,
|
|
610
|
-
'comment
|
|
611
|
-
}
|
|
612
|
-
`);
|
|
613
|
-
let { diagnostics } = Parser_1.Parser.parse(tokens);
|
|
614
|
-
(0, chai_config_spec_1.expect)(diagnostics).to.be.lengthOf(0, 'Error count should be 0');
|
|
615
|
-
});
|
|
616
|
-
it('parses after function call', () => {
|
|
617
|
-
let { tokens } = Lexer_1.Lexer.scan(`
|
|
618
|
-
sub Main()
|
|
619
|
-
name = "Hello"
|
|
620
|
-
DoSomething(name) 'comment 1
|
|
621
|
-
end sub
|
|
622
|
-
`);
|
|
623
|
-
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
624
|
-
(0, chai_config_spec_1.expect)(diagnostics).to.be.lengthOf(0, 'Should have zero diagnostics');
|
|
625
|
-
(0, chai_config_spec_1.expect)(statements[0].func.body.statements[2].text).to.equal(`'comment 1`);
|
|
626
|
-
});
|
|
627
|
-
it('function', () => {
|
|
628
|
-
let { tokens } = Lexer_1.Lexer.scan(`
|
|
629
|
-
function a() 'comment 1
|
|
630
|
-
'comment 2
|
|
631
|
-
num = 1
|
|
632
|
-
'comment 3
|
|
633
|
-
end function 'comment 4
|
|
634
|
-
`);
|
|
635
|
-
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
636
|
-
(0, chai_config_spec_1.expect)(diagnostics).to.be.lengthOf(0, 'Should have zero diagnostics');
|
|
637
|
-
(0, chai_config_spec_1.expect)(statements[0].func.body.statements[0].text).to.equal(`'comment 1`);
|
|
638
|
-
(0, chai_config_spec_1.expect)(statements[0].func.body.statements[1].text).to.equal(`'comment 2`);
|
|
639
|
-
(0, chai_config_spec_1.expect)(statements[0].func.body.statements[3].text).to.equal(`'comment 3`);
|
|
640
|
-
(0, chai_config_spec_1.expect)(statements[1].text).to.equal(`'comment 4`);
|
|
641
|
-
});
|
|
642
|
-
it('if statement`', () => {
|
|
643
|
-
let { tokens } = Lexer_1.Lexer.scan(`
|
|
644
|
-
function a()
|
|
645
|
-
if true then 'comment 1
|
|
646
|
-
'comment 2
|
|
647
|
-
print "hello"
|
|
648
|
-
'comment 3
|
|
649
|
-
else if true then 'comment 4
|
|
650
|
-
'comment 5
|
|
651
|
-
print "hello"
|
|
652
|
-
'comment 6
|
|
653
|
-
else 'comment 7
|
|
654
|
-
'comment 8
|
|
655
|
-
print "hello"
|
|
656
|
-
'comment 9
|
|
657
|
-
end if 'comment 10
|
|
658
|
-
end function
|
|
659
|
-
`);
|
|
660
|
-
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
661
|
-
(0, chai_config_spec_1.expect)(diagnostics).to.be.lengthOf(0, 'Should have zero diagnostics');
|
|
662
|
-
let fnSmt = statements[0];
|
|
663
|
-
if ((0, reflection_1.isFunctionStatement)(fnSmt)) {
|
|
664
|
-
let ifStmt = fnSmt.func.body.statements[0];
|
|
665
|
-
if ((0, reflection_1.isIfStatement)(ifStmt)) {
|
|
666
|
-
expectCommentWithText(ifStmt.thenBranch.statements[0], `'comment 1`);
|
|
667
|
-
expectCommentWithText(ifStmt.thenBranch.statements[1], `'comment 2`);
|
|
668
|
-
expectCommentWithText(ifStmt.thenBranch.statements[3], `'comment 3`);
|
|
669
|
-
let elseIfBranch = ifStmt.elseBranch;
|
|
670
|
-
if ((0, reflection_1.isIfStatement)(elseIfBranch)) {
|
|
671
|
-
expectCommentWithText(elseIfBranch.thenBranch.statements[0], `'comment 4`);
|
|
672
|
-
expectCommentWithText(elseIfBranch.thenBranch.statements[1], `'comment 5`);
|
|
673
|
-
expectCommentWithText(elseIfBranch.thenBranch.statements[3], `'comment 6`);
|
|
674
|
-
let elseBranch = elseIfBranch.elseBranch;
|
|
675
|
-
if ((0, reflection_1.isBlock)(elseBranch)) {
|
|
676
|
-
expectCommentWithText(elseBranch.statements[0], `'comment 7`);
|
|
677
|
-
expectCommentWithText(elseBranch.statements[1], `'comment 8`);
|
|
678
|
-
expectCommentWithText(elseBranch.statements[3], `'comment 9`);
|
|
679
|
-
}
|
|
680
|
-
else {
|
|
681
|
-
failStatementType(elseBranch, 'Block');
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
else {
|
|
685
|
-
failStatementType(elseIfBranch, 'If');
|
|
686
|
-
}
|
|
687
|
-
expectCommentWithText(fnSmt.func.body.statements[1], `'comment 10`);
|
|
688
|
-
}
|
|
689
|
-
else {
|
|
690
|
-
failStatementType(ifStmt, 'If');
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
else {
|
|
694
|
-
failStatementType(fnSmt, 'Function');
|
|
695
|
-
}
|
|
696
|
-
});
|
|
697
|
-
it('while', () => {
|
|
698
|
-
let { tokens } = Lexer_1.Lexer.scan(`
|
|
699
|
-
function a()
|
|
700
|
-
while true 'comment 1
|
|
701
|
-
'comment 2
|
|
702
|
-
print "true"
|
|
703
|
-
'comment 3
|
|
704
|
-
end while 'comment 4
|
|
705
|
-
end function
|
|
706
|
-
`);
|
|
707
|
-
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
708
|
-
(0, chai_config_spec_1.expect)(diagnostics).to.be.lengthOf(0, 'Error count should be zero');
|
|
709
|
-
let stmt = statements[0].func.body.statements[0];
|
|
710
|
-
(0, chai_config_spec_1.expect)(stmt.body.statements[0].text).to.equal(`'comment 1`);
|
|
711
|
-
(0, chai_config_spec_1.expect)(stmt.body.statements[1].text).to.equal(`'comment 2`);
|
|
712
|
-
(0, chai_config_spec_1.expect)(stmt.body.statements[3].text).to.equal(`'comment 3`);
|
|
713
|
-
(0, chai_config_spec_1.expect)(statements[0].func.body.statements[1].text).to.equal(`'comment 4`);
|
|
714
|
-
});
|
|
715
|
-
it('for', () => {
|
|
716
|
-
let { tokens } = Lexer_1.Lexer.scan(`
|
|
717
|
-
function a()
|
|
718
|
-
for i = 0 to 10 step 1 'comment 1
|
|
719
|
-
'comment 2
|
|
720
|
-
print 1
|
|
721
|
-
'comment 3
|
|
722
|
-
end for 'comment 4
|
|
723
|
-
end function
|
|
724
|
-
`);
|
|
725
|
-
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
726
|
-
(0, chai_config_spec_1.expect)(diagnostics).to.be.lengthOf(0, 'Error count should be zero');
|
|
727
|
-
let stmt = statements[0].func.body.statements[0];
|
|
728
|
-
(0, chai_config_spec_1.expect)(stmt.body.statements[0].text).to.equal(`'comment 1`);
|
|
729
|
-
(0, chai_config_spec_1.expect)(stmt.body.statements[1].text).to.equal(`'comment 2`);
|
|
730
|
-
(0, chai_config_spec_1.expect)(stmt.body.statements[3].text).to.equal(`'comment 3`);
|
|
731
|
-
(0, chai_config_spec_1.expect)(statements[0].func.body.statements[1].text).to.equal(`'comment 4`);
|
|
732
|
-
});
|
|
733
|
-
it('for each', () => {
|
|
734
|
-
let { tokens } = Lexer_1.Lexer.scan(`
|
|
735
|
-
function a()
|
|
736
|
-
for each val in [1,2,3] 'comment 1
|
|
737
|
-
'comment 2
|
|
738
|
-
print 1
|
|
739
|
-
'comment 3
|
|
740
|
-
end for 'comment 4
|
|
741
|
-
end function
|
|
742
|
-
`);
|
|
743
|
-
let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
|
|
744
|
-
(0, chai_config_spec_1.expect)(diagnostics).to.be.lengthOf(0, 'Error count should be zero');
|
|
745
|
-
let stmt = statements[0].func.body.statements[0];
|
|
746
|
-
(0, chai_config_spec_1.expect)(stmt.body.statements[0].text).to.equal(`'comment 1`);
|
|
747
|
-
(0, chai_config_spec_1.expect)(stmt.body.statements[1].text).to.equal(`'comment 2`);
|
|
748
|
-
(0, chai_config_spec_1.expect)(stmt.body.statements[3].text).to.equal(`'comment 3`);
|
|
749
|
-
(0, chai_config_spec_1.expect)(statements[0].func.body.statements[1].text).to.equal(`'comment 4`);
|
|
750
|
-
});
|
|
751
|
-
});
|
|
752
|
-
});
|
|
753
|
-
describe('reservedWords', () => {
|
|
754
|
-
describe('`then`', () => {
|
|
755
|
-
it('is not allowed as a local identifier', () => {
|
|
756
|
-
let { diagnostics } = parse(`
|
|
757
|
-
sub main()
|
|
758
|
-
then = true
|
|
759
|
-
end sub
|
|
760
|
-
`);
|
|
761
|
-
(0, chai_config_spec_1.expect)(diagnostics).to.be.lengthOf(1);
|
|
762
|
-
});
|
|
763
|
-
it('is allowed as an AA property name', () => {
|
|
764
|
-
var _a;
|
|
765
|
-
let { diagnostics } = parse(`
|
|
766
|
-
sub main()
|
|
767
|
-
person = {
|
|
768
|
-
then: true
|
|
769
|
-
}
|
|
770
|
-
person.then = false
|
|
771
|
-
print person.then
|
|
772
|
-
end sub
|
|
773
|
-
`);
|
|
774
|
-
(0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
775
|
-
});
|
|
776
|
-
it('allows `mod` as an AA literal property', () => {
|
|
777
|
-
const parser = parse(`
|
|
778
|
-
sub main()
|
|
779
|
-
person = {
|
|
780
|
-
mod: true
|
|
781
|
-
}
|
|
782
|
-
person.mod = false
|
|
783
|
-
print person.mod
|
|
784
|
-
end sub
|
|
785
|
-
`);
|
|
786
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser);
|
|
787
|
-
});
|
|
788
|
-
it('converts aa literal property TokenKind to Identifier', () => {
|
|
789
|
-
const parser = parse(`
|
|
790
|
-
sub main()
|
|
791
|
-
person = {
|
|
792
|
-
mod: true
|
|
793
|
-
and: true
|
|
794
|
-
}
|
|
795
|
-
end sub
|
|
796
|
-
`);
|
|
797
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(parser);
|
|
798
|
-
const elements = [];
|
|
799
|
-
parser.ast.walk((0, visitors_1.createVisitor)({
|
|
800
|
-
AAMemberExpression: (node) => {
|
|
801
|
-
elements.push(node);
|
|
802
|
-
}
|
|
803
|
-
}), {
|
|
804
|
-
walkMode: visitors_1.WalkMode.visitAllRecursive
|
|
805
|
-
});
|
|
806
|
-
(0, chai_config_spec_1.expect)(elements.map(x => x.keyToken.kind)).to.eql([TokenKind_1.TokenKind.Identifier, TokenKind_1.TokenKind.Identifier]);
|
|
807
|
-
});
|
|
808
|
-
});
|
|
809
|
-
it('"end" is not allowed as a local identifier', () => {
|
|
810
|
-
let { diagnostics } = parse(`
|
|
811
|
-
sub main()
|
|
812
|
-
end = true
|
|
813
|
-
end sub
|
|
814
|
-
`);
|
|
815
|
-
(0, chai_config_spec_1.expect)(diagnostics).to.be.length.greaterThan(0);
|
|
816
|
-
});
|
|
817
|
-
it('none of them can be used as local variables', () => {
|
|
818
|
-
let reservedWords = new Set(TokenKind_1.ReservedWords);
|
|
819
|
-
//remove the rem keyword because it's a comment...won't cause error
|
|
820
|
-
reservedWords.delete('rem');
|
|
821
|
-
for (let reservedWord of reservedWords) {
|
|
822
|
-
let { tokens } = Lexer_1.Lexer.scan(`
|
|
823
|
-
sub main()
|
|
824
|
-
${reservedWord} = true
|
|
825
|
-
end sub
|
|
826
|
-
`);
|
|
827
|
-
let { diagnostics } = Parser_1.Parser.parse(tokens);
|
|
828
|
-
(0, chai_config_spec_1.expect)(diagnostics, `assigning to reserved word "${reservedWord}" should have been an error`).to.be.length.greaterThan(0);
|
|
829
|
-
}
|
|
830
|
-
});
|
|
831
|
-
});
|
|
832
|
-
describe('import keyword', () => {
|
|
833
|
-
it('parses without errors', () => {
|
|
834
|
-
var _a;
|
|
835
|
-
let { statements, diagnostics } = parse(`
|
|
836
|
-
import "somePath"
|
|
837
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
838
|
-
(0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
839
|
-
(0, chai_config_spec_1.expect)(statements[0]).to.be.instanceof(Statement_1.ImportStatement);
|
|
840
|
-
});
|
|
841
|
-
it('catches import statements used in brightscript files', () => {
|
|
842
|
-
var _a;
|
|
843
|
-
let { statements, diagnostics } = parse(`
|
|
844
|
-
import "somePath"
|
|
845
|
-
`, Parser_1.ParseMode.BrightScript);
|
|
846
|
-
(0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.eql(DiagnosticMessages_1.DiagnosticMessages.bsFeatureNotSupportedInBrsFiles('import statements').message);
|
|
847
|
-
(0, chai_config_spec_1.expect)(statements[0]).to.be.instanceof(Statement_1.ImportStatement);
|
|
848
|
-
});
|
|
849
|
-
it('catchs missing file path', () => {
|
|
850
|
-
var _a;
|
|
851
|
-
let { statements, diagnostics } = parse(`
|
|
852
|
-
import
|
|
853
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
854
|
-
(0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.expectedStringLiteralAfterKeyword('import').message);
|
|
855
|
-
(0, chai_config_spec_1.expect)(statements[0]).to.be.instanceof(Statement_1.ImportStatement);
|
|
856
|
-
});
|
|
857
|
-
});
|
|
858
|
-
describe('Annotations', () => {
|
|
859
|
-
it('parses with error if malformed', () => {
|
|
860
|
-
var _a;
|
|
861
|
-
let { diagnostics } = parse(`
|
|
862
|
-
@
|
|
863
|
-
sub main()
|
|
864
|
-
end sub
|
|
865
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
866
|
-
(0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.unexpectedToken('@').message);
|
|
867
|
-
});
|
|
868
|
-
it('properly handles empty annotation above class method', () => {
|
|
869
|
-
var _a;
|
|
870
|
-
//this code used to cause an infinite loop, so the fact that the test passes/fails on its own is a success!
|
|
871
|
-
let { diagnostics } = parse(`
|
|
872
|
-
class Person
|
|
873
|
-
@
|
|
874
|
-
sub new()
|
|
875
|
-
end sub
|
|
876
|
-
end class
|
|
877
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
878
|
-
(0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.expectedIdentifier().message);
|
|
879
|
-
});
|
|
880
|
-
it('parses with error if annotation is not followed by a statement', () => {
|
|
881
|
-
var _a, _b, _c, _d;
|
|
882
|
-
let { diagnostics } = parse(`
|
|
883
|
-
sub main()
|
|
884
|
-
@meta2
|
|
885
|
-
end sub
|
|
886
|
-
class MyClass
|
|
887
|
-
@meta3
|
|
888
|
-
@meta4
|
|
889
|
-
end class
|
|
890
|
-
@meta1
|
|
891
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
892
|
-
(0, chai_config_spec_1.expect)(diagnostics.length).to.equal(4);
|
|
893
|
-
(0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.unusedAnnotation().message);
|
|
894
|
-
(0, chai_config_spec_1.expect)((_b = diagnostics[1]) === null || _b === void 0 ? void 0 : _b.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.unusedAnnotation().message);
|
|
895
|
-
(0, chai_config_spec_1.expect)((_c = diagnostics[2]) === null || _c === void 0 ? void 0 : _c.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.unusedAnnotation().message);
|
|
896
|
-
(0, chai_config_spec_1.expect)((_d = diagnostics[3]) === null || _d === void 0 ? void 0 : _d.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.unusedAnnotation().message);
|
|
897
|
-
});
|
|
898
|
-
it('attaches an annotation to next statement', () => {
|
|
899
|
-
var _a;
|
|
900
|
-
let { statements, diagnostics } = parse(`
|
|
901
|
-
@meta1
|
|
902
|
-
function main()
|
|
903
|
-
end function
|
|
904
|
-
|
|
905
|
-
@meta2 sub init()
|
|
906
|
-
end sub
|
|
907
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
908
|
-
(0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
909
|
-
(0, chai_config_spec_1.expect)(statements[0]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
910
|
-
let fn = statements[0];
|
|
911
|
-
(0, chai_config_spec_1.expect)(fn.annotations).to.exist;
|
|
912
|
-
(0, chai_config_spec_1.expect)(fn.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
913
|
-
(0, chai_config_spec_1.expect)(fn.annotations[0].nameToken.text).to.equal('meta1');
|
|
914
|
-
(0, chai_config_spec_1.expect)(fn.annotations[0].name).to.equal('meta1');
|
|
915
|
-
(0, chai_config_spec_1.expect)(statements[1]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
916
|
-
fn = statements[1];
|
|
917
|
-
(0, chai_config_spec_1.expect)(fn.annotations).to.exist;
|
|
918
|
-
(0, chai_config_spec_1.expect)(fn.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
919
|
-
(0, chai_config_spec_1.expect)(fn.annotations[0].nameToken.text).to.equal('meta2');
|
|
920
|
-
});
|
|
921
|
-
it('attaches annotations inside a function body', () => {
|
|
922
|
-
var _a, _b;
|
|
923
|
-
let { statements, diagnostics } = parse(`
|
|
924
|
-
function main()
|
|
925
|
-
@meta1
|
|
926
|
-
print "hello"
|
|
927
|
-
end function
|
|
928
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
929
|
-
(0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
930
|
-
let fn = statements[0];
|
|
931
|
-
let fnStatements = fn.func.body.statements;
|
|
932
|
-
let stat = fnStatements[0];
|
|
933
|
-
(0, chai_config_spec_1.expect)(stat).to.exist;
|
|
934
|
-
(0, chai_config_spec_1.expect)((_b = stat.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
935
|
-
(0, chai_config_spec_1.expect)(stat.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
936
|
-
});
|
|
937
|
-
it('attaches multiple annotations to next statement', () => {
|
|
938
|
-
var _a;
|
|
939
|
-
let { statements, diagnostics } = parse(`
|
|
940
|
-
@meta1
|
|
941
|
-
@meta2 @meta3
|
|
942
|
-
function main()
|
|
943
|
-
end function
|
|
944
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
945
|
-
(0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
946
|
-
(0, chai_config_spec_1.expect)(statements[0]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
947
|
-
let fn = statements[0];
|
|
948
|
-
(0, chai_config_spec_1.expect)(fn.annotations).to.exist;
|
|
949
|
-
(0, chai_config_spec_1.expect)(fn.annotations.length).to.equal(3);
|
|
950
|
-
(0, chai_config_spec_1.expect)(fn.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
951
|
-
(0, chai_config_spec_1.expect)(fn.annotations[1]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
952
|
-
(0, chai_config_spec_1.expect)(fn.annotations[2]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
953
|
-
});
|
|
954
|
-
it('allows annotations with parameters', () => {
|
|
955
|
-
var _a;
|
|
956
|
-
let { statements, diagnostics } = parse(`
|
|
957
|
-
@meta1("arg", 2, true, { prop: "value" })
|
|
958
|
-
function main()
|
|
959
|
-
end function
|
|
960
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
961
|
-
(0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
962
|
-
let fn = statements[0];
|
|
963
|
-
(0, chai_config_spec_1.expect)(fn.annotations).to.exist;
|
|
964
|
-
(0, chai_config_spec_1.expect)(fn.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
965
|
-
(0, chai_config_spec_1.expect)(fn.annotations[0].nameToken.text).to.equal('meta1');
|
|
966
|
-
(0, chai_config_spec_1.expect)(fn.annotations[0].call).to.be.instanceof(Expression_1.CallExpression);
|
|
967
|
-
});
|
|
968
|
-
it('attaches annotations to a class', () => {
|
|
969
|
-
var _a, _b;
|
|
970
|
-
let { statements, diagnostics } = parse(`
|
|
971
|
-
@meta1
|
|
972
|
-
class MyClass
|
|
973
|
-
function main()
|
|
974
|
-
print "hello"
|
|
975
|
-
end function
|
|
976
|
-
end class
|
|
977
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
978
|
-
(0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
979
|
-
let cs = statements[0];
|
|
980
|
-
(0, chai_config_spec_1.expect)((_b = cs.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
981
|
-
(0, chai_config_spec_1.expect)(cs.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
982
|
-
});
|
|
983
|
-
it('attaches annotations to multiple clases', () => {
|
|
984
|
-
var _a, _b, _c;
|
|
985
|
-
let { statements, diagnostics } = parse(`
|
|
986
|
-
@meta1
|
|
987
|
-
class MyClass
|
|
988
|
-
function main()
|
|
989
|
-
print "hello"
|
|
990
|
-
end function
|
|
991
|
-
end class
|
|
992
|
-
@meta2
|
|
993
|
-
class MyClass2
|
|
994
|
-
function main()
|
|
995
|
-
print "hello"
|
|
996
|
-
end function
|
|
997
|
-
end class
|
|
998
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
999
|
-
(0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
1000
|
-
let cs = statements[0];
|
|
1001
|
-
(0, chai_config_spec_1.expect)((_b = cs.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
1002
|
-
(0, chai_config_spec_1.expect)(cs.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
1003
|
-
(0, chai_config_spec_1.expect)(cs.annotations[0].name).to.equal('meta1');
|
|
1004
|
-
let cs2 = statements[1];
|
|
1005
|
-
(0, chai_config_spec_1.expect)((_c = cs2.annotations) === null || _c === void 0 ? void 0 : _c.length).to.equal(1);
|
|
1006
|
-
(0, chai_config_spec_1.expect)(cs2.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
1007
|
-
(0, chai_config_spec_1.expect)(cs2.annotations[0].name).to.equal('meta2');
|
|
1008
|
-
});
|
|
1009
|
-
it('attaches annotations to a namespaced class', () => {
|
|
1010
|
-
var _a, _b;
|
|
1011
|
-
let { statements, diagnostics } = parse(`
|
|
1012
|
-
namespace ns
|
|
1013
|
-
@meta1
|
|
1014
|
-
class MyClass
|
|
1015
|
-
function main()
|
|
1016
|
-
print "hello"
|
|
1017
|
-
end function
|
|
1018
|
-
end class
|
|
1019
|
-
end namespace
|
|
1020
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1021
|
-
(0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
1022
|
-
let ns = statements[0];
|
|
1023
|
-
let cs = ns.body.statements[0];
|
|
1024
|
-
(0, chai_config_spec_1.expect)((_b = cs.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
1025
|
-
(0, chai_config_spec_1.expect)(cs.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
1026
|
-
});
|
|
1027
|
-
it('attaches annotations to a namespaced class - multiple', () => {
|
|
1028
|
-
var _a, _b, _c;
|
|
1029
|
-
let { statements, diagnostics } = parse(`
|
|
1030
|
-
namespace ns
|
|
1031
|
-
@meta1
|
|
1032
|
-
class MyClass
|
|
1033
|
-
function main()
|
|
1034
|
-
print "hello"
|
|
1035
|
-
end function
|
|
1036
|
-
end class
|
|
1037
|
-
@meta2
|
|
1038
|
-
class MyClass2
|
|
1039
|
-
function main()
|
|
1040
|
-
print "hello"
|
|
1041
|
-
end function
|
|
1042
|
-
end class
|
|
1043
|
-
end namespace
|
|
1044
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1045
|
-
(0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
1046
|
-
let ns = statements[0];
|
|
1047
|
-
let cs = ns.body.statements[0];
|
|
1048
|
-
(0, chai_config_spec_1.expect)((_b = cs.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
1049
|
-
(0, chai_config_spec_1.expect)(cs.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
1050
|
-
(0, chai_config_spec_1.expect)(cs.annotations[0].name).to.equal('meta1');
|
|
1051
|
-
let cs2 = ns.body.statements[1];
|
|
1052
|
-
(0, chai_config_spec_1.expect)((_c = cs2.annotations) === null || _c === void 0 ? void 0 : _c.length).to.equal(1);
|
|
1053
|
-
(0, chai_config_spec_1.expect)(cs2.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
1054
|
-
(0, chai_config_spec_1.expect)(cs2.annotations[0].name).to.equal('meta2');
|
|
1055
|
-
});
|
|
1056
|
-
it('attaches annotations to a class constructor', () => {
|
|
1057
|
-
var _a, _b;
|
|
1058
|
-
let { statements, diagnostics } = parse(`
|
|
1059
|
-
class MyClass
|
|
1060
|
-
@meta1
|
|
1061
|
-
function new()
|
|
1062
|
-
print "hello"
|
|
1063
|
-
end function
|
|
1064
|
-
function methodA()
|
|
1065
|
-
print "hello"
|
|
1066
|
-
end function
|
|
1067
|
-
end class
|
|
1068
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1069
|
-
(0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
1070
|
-
let cs = statements[0];
|
|
1071
|
-
let stat = cs.body[0];
|
|
1072
|
-
(0, chai_config_spec_1.expect)((_b = stat.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
1073
|
-
(0, chai_config_spec_1.expect)(stat.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
1074
|
-
});
|
|
1075
|
-
it('attaches annotations to a class methods', () => {
|
|
1076
|
-
var _a, _b;
|
|
1077
|
-
let { statements, diagnostics } = parse(`
|
|
1078
|
-
class MyClass
|
|
1079
|
-
function new()
|
|
1080
|
-
print "hello"
|
|
1081
|
-
end function
|
|
1082
|
-
@meta1
|
|
1083
|
-
function methodA()
|
|
1084
|
-
print "hello"
|
|
1085
|
-
end function
|
|
1086
|
-
end class
|
|
1087
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1088
|
-
(0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
1089
|
-
let cs = statements[0];
|
|
1090
|
-
let stat = cs.body[1];
|
|
1091
|
-
(0, chai_config_spec_1.expect)((_b = stat.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
1092
|
-
(0, chai_config_spec_1.expect)(stat.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
1093
|
-
});
|
|
1094
|
-
it('attaches annotations to a class methods, fields and constructor', () => {
|
|
1095
|
-
var _a, _b, _c, _d, _e;
|
|
1096
|
-
let { statements, diagnostics } = parse(`
|
|
1097
|
-
@meta2
|
|
1098
|
-
@meta1
|
|
1099
|
-
class MyClass
|
|
1100
|
-
@meta3
|
|
1101
|
-
@meta4
|
|
1102
|
-
function new()
|
|
1103
|
-
print "hello"
|
|
1104
|
-
end function
|
|
1105
|
-
@meta5
|
|
1106
|
-
@meta6
|
|
1107
|
-
function methodA()
|
|
1108
|
-
print "hello"
|
|
1109
|
-
end function
|
|
1110
|
-
|
|
1111
|
-
@meta5
|
|
1112
|
-
@meta6
|
|
1113
|
-
public foo="bar"
|
|
1114
|
-
end class
|
|
1115
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1116
|
-
(0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
1117
|
-
let cs = statements[0];
|
|
1118
|
-
(0, chai_config_spec_1.expect)((_b = cs.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(2);
|
|
1119
|
-
(0, chai_config_spec_1.expect)(cs.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
1120
|
-
let stat1 = cs.body[0];
|
|
1121
|
-
let stat2 = cs.body[1];
|
|
1122
|
-
let f1 = cs.body[2];
|
|
1123
|
-
(0, chai_config_spec_1.expect)((_c = stat1.annotations) === null || _c === void 0 ? void 0 : _c.length).to.equal(2);
|
|
1124
|
-
(0, chai_config_spec_1.expect)(stat1.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
1125
|
-
(0, chai_config_spec_1.expect)((_d = stat2.annotations) === null || _d === void 0 ? void 0 : _d.length).to.equal(2);
|
|
1126
|
-
(0, chai_config_spec_1.expect)(stat2.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
1127
|
-
(0, chai_config_spec_1.expect)((_e = f1.annotations) === null || _e === void 0 ? void 0 : _e.length).to.equal(2);
|
|
1128
|
-
(0, chai_config_spec_1.expect)(f1.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
1129
|
-
});
|
|
1130
|
-
it('ignores annotations on commented out lines', () => {
|
|
1131
|
-
var _a;
|
|
1132
|
-
let { statements, diagnostics } = parse(`
|
|
1133
|
-
'@meta1
|
|
1134
|
-
' @meta1
|
|
1135
|
-
function new()
|
|
1136
|
-
print "hello"
|
|
1137
|
-
end function
|
|
1138
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1139
|
-
(0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
1140
|
-
let cs = statements[0];
|
|
1141
|
-
(0, chai_config_spec_1.expect)(cs.annotations).to.be.undefined;
|
|
1142
|
-
});
|
|
1143
|
-
it('can convert argument of an annotation to JS types', () => {
|
|
1144
|
-
var _a;
|
|
1145
|
-
let { statements, diagnostics } = parse(`
|
|
1146
|
-
@meta1
|
|
1147
|
-
function main()
|
|
1148
|
-
end function
|
|
1149
|
-
|
|
1150
|
-
@meta2(
|
|
1151
|
-
"arg", 2, true,
|
|
1152
|
-
{ prop: "value" }, [1, 2],
|
|
1153
|
-
sub()
|
|
1154
|
-
end sub
|
|
1155
|
-
)
|
|
1156
|
-
sub init()
|
|
1157
|
-
end sub
|
|
1158
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1159
|
-
(0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
1160
|
-
(0, chai_config_spec_1.expect)(statements[0]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
1161
|
-
let fn = statements[0];
|
|
1162
|
-
(0, chai_config_spec_1.expect)(fn.annotations).to.exist;
|
|
1163
|
-
(0, chai_config_spec_1.expect)(fn.annotations[0].getArguments()).to.deep.equal([]);
|
|
1164
|
-
(0, chai_config_spec_1.expect)(statements[1]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
1165
|
-
fn = statements[1];
|
|
1166
|
-
(0, chai_config_spec_1.expect)(fn.annotations).to.exist;
|
|
1167
|
-
(0, chai_config_spec_1.expect)(fn.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
|
|
1168
|
-
(0, chai_config_spec_1.expect)(fn.annotations[0].getArguments()).to.deep.equal([
|
|
1169
|
-
'arg', 2, true,
|
|
1170
|
-
{ prop: 'value' }, [1, 2],
|
|
1171
|
-
null
|
|
1172
|
-
]);
|
|
1173
|
-
let allArgs = fn.annotations[0].getArguments(false);
|
|
1174
|
-
(0, chai_config_spec_1.expect)(allArgs.pop()).to.be.instanceOf(Expression_1.FunctionExpression);
|
|
1175
|
-
});
|
|
1176
|
-
it('can handle negative numbers', () => {
|
|
1177
|
-
var _a;
|
|
1178
|
-
let { statements, diagnostics } = parse(`
|
|
1179
|
-
@meta(-100)
|
|
1180
|
-
function main()
|
|
1181
|
-
end function
|
|
1182
|
-
|
|
1183
|
-
sub init()
|
|
1184
|
-
end sub
|
|
1185
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1186
|
-
(0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
|
|
1187
|
-
(0, chai_config_spec_1.expect)(statements[0]).to.be.instanceof(Statement_1.FunctionStatement);
|
|
1188
|
-
let fn = statements[0];
|
|
1189
|
-
(0, chai_config_spec_1.expect)(fn.annotations).to.exist;
|
|
1190
|
-
(0, chai_config_spec_1.expect)(fn.annotations[0].getArguments()).to.deep.equal([-100]);
|
|
1191
|
-
});
|
|
1192
|
-
});
|
|
1193
|
-
describe('grouped type expressions', () => {
|
|
1194
|
-
it('is not allowed in brightscript mode', () => {
|
|
1195
|
-
let parser = parse(`
|
|
1196
|
-
sub main(param as (string or integer))
|
|
1197
|
-
print param
|
|
1198
|
-
end sub
|
|
1199
|
-
`, Parser_1.ParseMode.BrightScript);
|
|
1200
|
-
(0, testHelpers_spec_1.expectDiagnosticsIncludes)(parser.diagnostics, [DiagnosticMessages_1.DiagnosticMessages.functionParameterTypeIsInvalid('param', '(')]);
|
|
1201
|
-
});
|
|
1202
|
-
it('allows group type expressions in parameters', () => {
|
|
1203
|
-
let { diagnostics } = parse(`
|
|
1204
|
-
sub main(param as (string or integer))
|
|
1205
|
-
print param
|
|
1206
|
-
end sub
|
|
1207
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1208
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1209
|
-
});
|
|
1210
|
-
it('allows group type expressions in type casts', () => {
|
|
1211
|
-
let { diagnostics } = parse(`
|
|
1212
|
-
sub main(val)
|
|
1213
|
-
printThing(val as (string or integer))
|
|
1214
|
-
end sub
|
|
1215
|
-
sub printThing(thing as (string or integer))
|
|
1216
|
-
print thing
|
|
1217
|
-
end sub
|
|
1218
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1219
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1220
|
-
});
|
|
1221
|
-
it('allows union of grouped type expressions', () => {
|
|
1222
|
-
let { diagnostics } = parse(`
|
|
1223
|
-
sub main(param as (string or integer) or (float or dynamic))
|
|
1224
|
-
print param
|
|
1225
|
-
end sub
|
|
1226
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1227
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1228
|
-
});
|
|
1229
|
-
it('allows nested grouped type expressions', () => {
|
|
1230
|
-
let { diagnostics } = parse(`
|
|
1231
|
-
sub main(param as ((string or integer) or (float or dynamic)))
|
|
1232
|
-
print param
|
|
1233
|
-
end sub
|
|
1234
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1235
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1236
|
-
});
|
|
1237
|
-
it('allows complicated grouped type expression', () => {
|
|
1238
|
-
let { diagnostics } = parse(`
|
|
1239
|
-
sub main(param as (({name as string} and {age as integer}) or (string and SomeInterface) or Klass and roAssociativeArray) )
|
|
1240
|
-
print param
|
|
1241
|
-
end sub
|
|
1242
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1243
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1244
|
-
});
|
|
1245
|
-
});
|
|
1246
|
-
describe('union types', () => {
|
|
1247
|
-
it('is not allowed in brightscript mode', () => {
|
|
1248
|
-
let parser = parse(`
|
|
1249
|
-
sub main(param as string or integer)
|
|
1250
|
-
print param
|
|
1251
|
-
end sub
|
|
1252
|
-
`, Parser_1.ParseMode.BrightScript);
|
|
1253
|
-
(0, testHelpers_spec_1.expectDiagnosticsIncludes)(parser.diagnostics, [DiagnosticMessages_1.DiagnosticMessages.expectedStatementOrFunctionCallButReceivedExpression()]);
|
|
1254
|
-
});
|
|
1255
|
-
it('allows union types in parameters', () => {
|
|
1256
|
-
let { diagnostics } = parse(`
|
|
1257
|
-
sub main(param as string or integer)
|
|
1258
|
-
print param
|
|
1259
|
-
end sub
|
|
1260
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1261
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1262
|
-
});
|
|
1263
|
-
it('allows union types in type casts', () => {
|
|
1264
|
-
let { diagnostics } = parse(`
|
|
1265
|
-
sub main(val)
|
|
1266
|
-
printThing(val as string or integer)
|
|
1267
|
-
end sub
|
|
1268
|
-
sub printThing(thing as string or integer)
|
|
1269
|
-
print thing
|
|
1270
|
-
end sub
|
|
1271
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1272
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1273
|
-
});
|
|
1274
|
-
});
|
|
1275
|
-
describe('intersection types', () => {
|
|
1276
|
-
it('is not allowed in brightscript mode', () => {
|
|
1277
|
-
let parser = parse(`
|
|
1278
|
-
sub main(param as string and integer)
|
|
1279
|
-
print param
|
|
1280
|
-
end sub
|
|
1281
|
-
`, Parser_1.ParseMode.BrightScript);
|
|
1282
|
-
(0, testHelpers_spec_1.expectDiagnosticsIncludes)(parser.diagnostics, [DiagnosticMessages_1.DiagnosticMessages.expectedStatementOrFunctionCallButReceivedExpression()]);
|
|
1283
|
-
});
|
|
1284
|
-
it('allows intersection types in parameters', () => {
|
|
1285
|
-
let { diagnostics } = parse(`
|
|
1286
|
-
sub main(param as string and integer)
|
|
1287
|
-
print param
|
|
1288
|
-
end sub
|
|
1289
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1290
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1291
|
-
});
|
|
1292
|
-
it('allows intersection types in type casts', () => {
|
|
1293
|
-
let { diagnostics } = parse(`
|
|
1294
|
-
sub main(val)
|
|
1295
|
-
printThing(val as string and integer)
|
|
1296
|
-
end sub
|
|
1297
|
-
sub printThing(thing as string and integer)
|
|
1298
|
-
print thing
|
|
1299
|
-
end sub
|
|
1300
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1301
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1302
|
-
});
|
|
1303
|
-
describe('invalid syntax', () => {
|
|
1304
|
-
it('flags union type with missing sides', () => {
|
|
1305
|
-
let { diagnostics } = parse(`
|
|
1306
|
-
sub main(param as Thing or )
|
|
1307
|
-
print param
|
|
1308
|
-
end sub
|
|
1309
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1310
|
-
(0, testHelpers_spec_1.expectDiagnostics)(diagnostics, [DiagnosticMessages_1.DiagnosticMessages.expectedIdentifierAfterKeyword('or').message]);
|
|
1311
|
-
});
|
|
1312
|
-
it('flags missing type inside binary type', () => {
|
|
1313
|
-
var _a;
|
|
1314
|
-
let { diagnostics } = parse(`
|
|
1315
|
-
sub main(param as string or and float)
|
|
1316
|
-
print param
|
|
1317
|
-
end sub
|
|
1318
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1319
|
-
(0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.exist;
|
|
1320
|
-
});
|
|
1321
|
-
});
|
|
1322
|
-
});
|
|
1323
|
-
describe('typecast statement', () => {
|
|
1324
|
-
it('allows typecast statement ', () => {
|
|
1325
|
-
let { ast, diagnostics } = parse(`
|
|
1326
|
-
typeCAST m AS roAssociativeArray
|
|
1327
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1328
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1329
|
-
(0, chai_config_spec_1.expect)((0, reflection_1.isTypecastStatement)(ast.statements[0])).to.be.true;
|
|
1330
|
-
const stmt = ast.statements[0];
|
|
1331
|
-
(0, chai_config_spec_1.expect)(stmt.tokens.typecast.text).to.eq('typeCAST');
|
|
1332
|
-
(0, chai_config_spec_1.expect)(stmt.tokens.typecast).to.exist;
|
|
1333
|
-
});
|
|
1334
|
-
it('is disallowed in brightscript mode', () => {
|
|
1335
|
-
let { diagnostics } = parse(`
|
|
1336
|
-
typecast m AS roAssociativeArray
|
|
1337
|
-
`, Parser_1.ParseMode.BrightScript);
|
|
1338
|
-
(0, testHelpers_spec_1.expectDiagnostics)(diagnostics, [
|
|
1339
|
-
DiagnosticMessages_1.DiagnosticMessages.bsFeatureNotSupportedInBrsFiles('typecast statements')
|
|
1340
|
-
]);
|
|
1341
|
-
});
|
|
1342
|
-
it('allows `typecast` for function name', () => {
|
|
1343
|
-
let { ast, diagnostics } = parse(`
|
|
1344
|
-
function typecast() as integer
|
|
1345
|
-
return 1
|
|
1346
|
-
end function
|
|
1347
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1348
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1349
|
-
(0, chai_config_spec_1.expect)(ast.statements[0].name.text).to.eq('typecast');
|
|
1350
|
-
});
|
|
1351
|
-
it('allows `typecast` for variable name', () => {
|
|
1352
|
-
let { ast, diagnostics } = parse(`
|
|
1353
|
-
function foo() as integer
|
|
1354
|
-
typecast = 1
|
|
1355
|
-
return typecast
|
|
1356
|
-
end function
|
|
1357
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1358
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1359
|
-
(0, chai_config_spec_1.expect)(ast.statements[0].func.body.statements[0].name.text).to.eq('typecast');
|
|
1360
|
-
});
|
|
1361
|
-
it('is allowed in function', () => {
|
|
1362
|
-
let { diagnostics } = parse(`
|
|
1363
|
-
function foo() as integer
|
|
1364
|
-
typecast m as MyObject
|
|
1365
|
-
return m.getNum()
|
|
1366
|
-
end function
|
|
1367
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1368
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1369
|
-
});
|
|
1370
|
-
it('is allowed in function literal', () => {
|
|
1371
|
-
let { diagnostics } = parse(`
|
|
1372
|
-
interface PiGetter
|
|
1373
|
-
pi as float
|
|
1374
|
-
function getPi() as float
|
|
1375
|
-
end interface
|
|
1376
|
-
|
|
1377
|
-
function makePiGetter() as object
|
|
1378
|
-
x = {
|
|
1379
|
-
pi: 3.14,
|
|
1380
|
-
getPi: function() as float
|
|
1381
|
-
typecast m as PiGetter
|
|
1382
|
-
return m.pi
|
|
1383
|
-
end function
|
|
1384
|
-
}
|
|
1385
|
-
return x
|
|
1386
|
-
end function
|
|
1387
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1388
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1389
|
-
});
|
|
1390
|
-
});
|
|
1391
|
-
describe('alias statement', () => {
|
|
1392
|
-
it('allows alias statement ', () => {
|
|
1393
|
-
let { ast, diagnostics } = parse(`
|
|
1394
|
-
ALIAS x = lcase
|
|
1395
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1396
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1397
|
-
(0, chai_config_spec_1.expect)((0, reflection_1.isAliasStatement)(ast.statements[0])).to.be.true;
|
|
1398
|
-
const stmt = ast.statements[0];
|
|
1399
|
-
(0, chai_config_spec_1.expect)(stmt.tokens.alias.text).to.eq('ALIAS');
|
|
1400
|
-
(0, chai_config_spec_1.expect)(stmt.tokens.value).to.exist;
|
|
1401
|
-
});
|
|
1402
|
-
it('is disallowed in brightscript mode', () => {
|
|
1403
|
-
let { diagnostics } = parse(`
|
|
1404
|
-
alias x = lcase
|
|
1405
|
-
`, Parser_1.ParseMode.BrightScript);
|
|
1406
|
-
(0, testHelpers_spec_1.expectDiagnostics)(diagnostics, [
|
|
1407
|
-
DiagnosticMessages_1.DiagnosticMessages.bsFeatureNotSupportedInBrsFiles('alias statements')
|
|
1408
|
-
]);
|
|
1409
|
-
});
|
|
1410
|
-
it('allows `alias` for function name', () => {
|
|
1411
|
-
let { ast, diagnostics } = parse(`
|
|
1412
|
-
function alias() as integer
|
|
1413
|
-
return 1
|
|
1414
|
-
end function
|
|
1415
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1416
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1417
|
-
(0, chai_config_spec_1.expect)(ast.statements[0].name.text).to.eq('alias');
|
|
1418
|
-
});
|
|
1419
|
-
it('allows `alias` for variable name', () => {
|
|
1420
|
-
let { ast, diagnostics } = parse(`
|
|
1421
|
-
function foo() as integer
|
|
1422
|
-
alias = 1
|
|
1423
|
-
return alias
|
|
1424
|
-
end function
|
|
1425
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1426
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1427
|
-
(0, chai_config_spec_1.expect)(ast.statements[0].func.body.statements[0].name.text).to.eq('alias');
|
|
1428
|
-
});
|
|
1429
|
-
});
|
|
1430
|
-
describe('type statement', () => {
|
|
1431
|
-
it('allows type statement ', () => {
|
|
1432
|
-
let { ast, diagnostics } = parse(`
|
|
1433
|
-
TYPE x = string
|
|
1434
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1435
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1436
|
-
(0, chai_config_spec_1.expect)((0, reflection_1.isTypeStatement)(ast.statements[0])).to.be.true;
|
|
1437
|
-
const stmt = ast.statements[0];
|
|
1438
|
-
(0, chai_config_spec_1.expect)(stmt.tokens.type.text).to.eq('TYPE');
|
|
1439
|
-
(0, chai_config_spec_1.expect)(stmt.tokens.value).to.exist;
|
|
1440
|
-
});
|
|
1441
|
-
it('is disallowed in brightscript mode', () => {
|
|
1442
|
-
let { diagnostics } = parse(`
|
|
1443
|
-
type x = string
|
|
1444
|
-
`, Parser_1.ParseMode.BrightScript);
|
|
1445
|
-
(0, testHelpers_spec_1.expectDiagnosticsIncludes)(diagnostics, [
|
|
1446
|
-
DiagnosticMessages_1.DiagnosticMessages.bsFeatureNotSupportedInBrsFiles('type statements')
|
|
1447
|
-
]);
|
|
1448
|
-
});
|
|
1449
|
-
it('disallows `type` for function name', () => {
|
|
1450
|
-
let { diagnostics } = parse(`
|
|
1451
|
-
function type() as integer
|
|
1452
|
-
return 1
|
|
1453
|
-
end function
|
|
1454
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1455
|
-
(0, testHelpers_spec_1.expectDiagnostics)(diagnostics, [
|
|
1456
|
-
DiagnosticMessages_1.DiagnosticMessages.cannotUseReservedWordAsIdentifier('type').message
|
|
1457
|
-
]);
|
|
1458
|
-
});
|
|
1459
|
-
it('disallows `type` for variable name', () => {
|
|
1460
|
-
let { diagnostics } = parse(`
|
|
1461
|
-
function foo() as integer
|
|
1462
|
-
type = 1
|
|
1463
|
-
return type
|
|
1464
|
-
end function
|
|
1465
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1466
|
-
(0, testHelpers_spec_1.expectDiagnostics)(diagnostics, [
|
|
1467
|
-
DiagnosticMessages_1.DiagnosticMessages.cannotUseReservedWordAsIdentifier('type').message
|
|
1468
|
-
]);
|
|
1469
|
-
});
|
|
1470
|
-
it('has error when rhs is not a type', () => {
|
|
1471
|
-
let { diagnostics } = parse(`
|
|
1472
|
-
type x = 123
|
|
1473
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1474
|
-
(0, testHelpers_spec_1.expectDiagnostics)(diagnostics, [
|
|
1475
|
-
DiagnosticMessages_1.DiagnosticMessages.expectedIdentifierAfterKeyword('=').message
|
|
1476
|
-
]);
|
|
1477
|
-
});
|
|
1478
|
-
it('allows type statement with complicated type', () => {
|
|
1479
|
-
let { ast, diagnostics } = parse(`
|
|
1480
|
-
type x = string or CustomKlass or roAssociativeArray
|
|
1481
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1482
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1483
|
-
(0, chai_config_spec_1.expect)((0, reflection_1.isTypeStatement)(ast.statements[0])).to.be.true;
|
|
1484
|
-
const stmt = ast.statements[0];
|
|
1485
|
-
(0, chai_config_spec_1.expect)(stmt.tokens.type.text).to.eq('type');
|
|
1486
|
-
(0, chai_config_spec_1.expect)(stmt.tokens.value).to.exist;
|
|
1487
|
-
});
|
|
1488
|
-
});
|
|
1489
|
-
describe('inline interfaces', () => {
|
|
1490
|
-
it('inline interface param types disallowed in brightscript mode', () => {
|
|
1491
|
-
let { diagnostics } = parse(`
|
|
1492
|
-
sub test(foo as {x as string})
|
|
1493
|
-
print foo.x
|
|
1494
|
-
end sub
|
|
1495
|
-
`, Parser_1.ParseMode.BrightScript);
|
|
1496
|
-
(0, testHelpers_spec_1.expectDiagnosticsIncludes)(diagnostics, [
|
|
1497
|
-
DiagnosticMessages_1.DiagnosticMessages.functionParameterTypeIsInvalid('foo', '{').message
|
|
1498
|
-
]);
|
|
1499
|
-
});
|
|
1500
|
-
it('inline interface return types disallowed in brightscript mode', () => {
|
|
1501
|
-
let { diagnostics } = parse(`
|
|
1502
|
-
function test() as {x as string}
|
|
1503
|
-
print {x: "hello"}
|
|
1504
|
-
end function
|
|
1505
|
-
`, Parser_1.ParseMode.BrightScript);
|
|
1506
|
-
(0, testHelpers_spec_1.expectDiagnosticsIncludes)(diagnostics, [
|
|
1507
|
-
DiagnosticMessages_1.DiagnosticMessages.invalidFunctionReturnType('{').message
|
|
1508
|
-
]);
|
|
1509
|
-
});
|
|
1510
|
-
it('inline interface as param type', () => {
|
|
1511
|
-
let { ast, diagnostics } = parse(`
|
|
1512
|
-
sub test(foo as {x as string})
|
|
1513
|
-
print foo.x
|
|
1514
|
-
end sub
|
|
1515
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1516
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1517
|
-
(0, chai_config_spec_1.expect)(ast.statements.length).to.eq(1);
|
|
1518
|
-
});
|
|
1519
|
-
it('inline interface as return type', () => {
|
|
1520
|
-
let { ast, diagnostics } = parse(`
|
|
1521
|
-
function test() as {x as string}
|
|
1522
|
-
print {x: "hello"}
|
|
1523
|
-
end function
|
|
1524
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1525
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1526
|
-
(0, chai_config_spec_1.expect)(ast.statements.length).to.eq(1);
|
|
1527
|
-
});
|
|
1528
|
-
it('parses a big inline interface as param type', () => {
|
|
1529
|
-
let { ast, diagnostics } = parse(`
|
|
1530
|
-
sub test(foo as {
|
|
1531
|
-
x as string,
|
|
1532
|
-
y as {a as integer}
|
|
1533
|
-
z})
|
|
1534
|
-
print foo.x + y.a.toStr()
|
|
1535
|
-
end sub
|
|
1536
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1537
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1538
|
-
(0, chai_config_spec_1.expect)(ast.statements.length).to.eq(1);
|
|
1539
|
-
});
|
|
1540
|
-
it('allows optional members', () => {
|
|
1541
|
-
let { ast, diagnostics } = parse(`
|
|
1542
|
-
sub test(p as {x as string, optional y})
|
|
1543
|
-
end sub
|
|
1544
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1545
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1546
|
-
(0, chai_config_spec_1.expect)(ast.statements.length).to.eq(1);
|
|
1547
|
-
});
|
|
1548
|
-
it('is allowed as typecast', () => {
|
|
1549
|
-
let { diagnostics } = parse(`
|
|
1550
|
-
sub test(p)
|
|
1551
|
-
print (p as {name as string}).name
|
|
1552
|
-
end sub
|
|
1553
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1554
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1555
|
-
});
|
|
1556
|
-
it('is allowed as class and interface field', () => {
|
|
1557
|
-
let { diagnostics } = parse(`
|
|
1558
|
-
class Klass
|
|
1559
|
-
x as {name as string}
|
|
1560
|
-
end class
|
|
1561
|
-
interface Iface
|
|
1562
|
-
y as {age as integer}
|
|
1563
|
-
end interface
|
|
1564
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1565
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1566
|
-
});
|
|
1567
|
-
it('can have custom type as member type', () => {
|
|
1568
|
-
let { diagnostics } = parse(`
|
|
1569
|
-
interface IFace
|
|
1570
|
-
name as string
|
|
1571
|
-
end interface
|
|
1572
|
-
function test(z as {foo as IFace})
|
|
1573
|
-
return z.foo.name
|
|
1574
|
-
end function
|
|
1575
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1576
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1577
|
-
});
|
|
1578
|
-
it('can have per-member doc comment', () => {
|
|
1579
|
-
let { diagnostics } = parse(`
|
|
1580
|
-
interface IFace
|
|
1581
|
-
inline as {
|
|
1582
|
-
' comment 1
|
|
1583
|
-
name as string
|
|
1584
|
-
' comment 2
|
|
1585
|
-
age as integer
|
|
1586
|
-
}
|
|
1587
|
-
end interface
|
|
1588
|
-
function test(z as {foo as IFace})
|
|
1589
|
-
return z.foo.inline.name
|
|
1590
|
-
end function
|
|
1591
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1592
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1593
|
-
});
|
|
1594
|
-
it('can have string literals as members', () => {
|
|
1595
|
-
let { diagnostics } = parse(`
|
|
1596
|
-
function test(z as {"this is a stringliteral" as string})
|
|
1597
|
-
return z["this is a stringliteral"]
|
|
1598
|
-
end function
|
|
1599
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1600
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1601
|
-
});
|
|
1602
|
-
});
|
|
1603
|
-
describe('for each with types', () => {
|
|
1604
|
-
it('parses without errors', () => {
|
|
1605
|
-
let { diagnostics } = parse(`
|
|
1606
|
-
function main()
|
|
1607
|
-
for each item as string in ["a", "b", "c"]
|
|
1608
|
-
print item
|
|
1609
|
-
end for
|
|
1610
|
-
end function
|
|
1611
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1612
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1613
|
-
});
|
|
1614
|
-
it('allows complicated expressions', () => {
|
|
1615
|
-
let { diagnostics } = parse(`
|
|
1616
|
-
function main(data)
|
|
1617
|
-
for each item as {a as integer or boolean, b as SomeInterface[], c as {id as string} } or string in data
|
|
1618
|
-
print item
|
|
1619
|
-
end for
|
|
1620
|
-
end function
|
|
1621
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1622
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1623
|
-
});
|
|
1624
|
-
});
|
|
1625
|
-
describe('line continuation', () => {
|
|
1626
|
-
describe('binary operator continuation', () => {
|
|
1627
|
-
it('is allowed after arithmetic operators in BrighterScript mode', () => {
|
|
1628
|
-
let { diagnostics } = parse(`
|
|
1629
|
-
sub main()
|
|
1630
|
-
a = x +
|
|
1631
|
-
y
|
|
1632
|
-
b = x -
|
|
1633
|
-
y
|
|
1634
|
-
c = x *
|
|
1635
|
-
y
|
|
1636
|
-
d = x /
|
|
1637
|
-
y
|
|
1638
|
-
e = x \\
|
|
1639
|
-
y
|
|
1640
|
-
f = x mod
|
|
1641
|
-
y
|
|
1642
|
-
g = x ^
|
|
1643
|
-
y
|
|
1644
|
-
end sub
|
|
1645
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1646
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1647
|
-
});
|
|
1648
|
-
it('is allowed after boolean operators in BrighterScript mode', () => {
|
|
1649
|
-
let { diagnostics } = parse(`
|
|
1650
|
-
sub main()
|
|
1651
|
-
a = isValid and
|
|
1652
|
-
isEnabled
|
|
1653
|
-
b = isValid or
|
|
1654
|
-
isEnabled
|
|
1655
|
-
end sub
|
|
1656
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1657
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1658
|
-
});
|
|
1659
|
-
it('is allowed after relational operators in BrighterScript mode', () => {
|
|
1660
|
-
let { diagnostics } = parse(`
|
|
1661
|
-
sub main()
|
|
1662
|
-
a = x =
|
|
1663
|
-
y
|
|
1664
|
-
b = x <>
|
|
1665
|
-
y
|
|
1666
|
-
c = x >
|
|
1667
|
-
y
|
|
1668
|
-
d = x >=
|
|
1669
|
-
y
|
|
1670
|
-
e = x <
|
|
1671
|
-
y
|
|
1672
|
-
f = x <=
|
|
1673
|
-
y
|
|
1674
|
-
end sub
|
|
1675
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1676
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1677
|
-
});
|
|
1678
|
-
it('is not allowed in BrightScript mode', () => {
|
|
1679
|
-
let { diagnostics } = parse(`
|
|
1680
|
-
sub main()
|
|
1681
|
-
result = value1 +
|
|
1682
|
-
value2
|
|
1683
|
-
end sub
|
|
1684
|
-
`, Parser_1.ParseMode.BrightScript);
|
|
1685
|
-
(0, testHelpers_spec_1.expectDiagnosticsIncludes)(diagnostics, [
|
|
1686
|
-
DiagnosticMessages_1.DiagnosticMessages.unexpectedToken('\n'),
|
|
1687
|
-
DiagnosticMessages_1.DiagnosticMessages.expectedStatementOrFunctionCallButReceivedExpression()
|
|
1688
|
-
]);
|
|
1689
|
-
});
|
|
1690
|
-
});
|
|
1691
|
-
describe('function call argument continuation', () => {
|
|
1692
|
-
it('is not allowed in BrightScript mode', () => {
|
|
1693
|
-
let { diagnostics } = parse(`
|
|
1694
|
-
sub main()
|
|
1695
|
-
result = foo(
|
|
1696
|
-
arg1,
|
|
1697
|
-
arg2
|
|
1698
|
-
)
|
|
1699
|
-
end sub
|
|
1700
|
-
sub foo(a, b)
|
|
1701
|
-
end sub
|
|
1702
|
-
`, Parser_1.ParseMode.BrightScript);
|
|
1703
|
-
(0, testHelpers_spec_1.expectDiagnosticsIncludes)(diagnostics, [
|
|
1704
|
-
DiagnosticMessages_1.DiagnosticMessages.unexpectedToken('\n'),
|
|
1705
|
-
DiagnosticMessages_1.DiagnosticMessages.expectedRightParenAfterFunctionCallArguments(),
|
|
1706
|
-
DiagnosticMessages_1.DiagnosticMessages.expectedStatementOrFunctionCallButReceivedExpression()
|
|
1707
|
-
]);
|
|
1708
|
-
});
|
|
1709
|
-
it('is allowed in BrighterScript mode', () => {
|
|
1710
|
-
let { diagnostics } = parse(`
|
|
1711
|
-
sub main()
|
|
1712
|
-
result = foo(
|
|
1713
|
-
arg1,
|
|
1714
|
-
arg2
|
|
1715
|
-
)
|
|
1716
|
-
end sub
|
|
1717
|
-
sub foo(a, b)
|
|
1718
|
-
end sub
|
|
1719
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1720
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1721
|
-
});
|
|
1722
|
-
it('does not affect inline objects passed as arguments in BrightScript mode', () => {
|
|
1723
|
-
let { diagnostics } = parse(`
|
|
1724
|
-
sub main()
|
|
1725
|
-
foo({
|
|
1726
|
-
key: "value"
|
|
1727
|
-
})
|
|
1728
|
-
end sub
|
|
1729
|
-
sub foo(a)
|
|
1730
|
-
end sub
|
|
1731
|
-
`, Parser_1.ParseMode.BrightScript);
|
|
1732
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1733
|
-
});
|
|
1734
|
-
});
|
|
1735
|
-
});
|
|
1736
|
-
describe('typed functions as types', () => {
|
|
1737
|
-
it('disallowed in brightscript mode', () => {
|
|
1738
|
-
let { diagnostics } = parse(`
|
|
1739
|
-
function test(func as function())
|
|
1740
|
-
return func()
|
|
1741
|
-
end function
|
|
1742
|
-
`, Parser_1.ParseMode.BrightScript);
|
|
1743
|
-
(0, testHelpers_spec_1.expectDiagnosticsIncludes)(diagnostics, [
|
|
1744
|
-
DiagnosticMessages_1.DiagnosticMessages.unexpectedToken(')')
|
|
1745
|
-
]);
|
|
1746
|
-
});
|
|
1747
|
-
it('can be passed as param types', () => {
|
|
1748
|
-
let { diagnostics } = parse(`
|
|
1749
|
-
function test(func as function())
|
|
1750
|
-
return func()
|
|
1751
|
-
end function
|
|
1752
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1753
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1754
|
-
});
|
|
1755
|
-
it('can have a return type', () => {
|
|
1756
|
-
let { diagnostics } = parse(`
|
|
1757
|
-
function test(func as sub() as integer) as integer
|
|
1758
|
-
return func()
|
|
1759
|
-
end function
|
|
1760
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1761
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1762
|
-
});
|
|
1763
|
-
it('can use sub or function', () => {
|
|
1764
|
-
let { diagnostics } = parse(`
|
|
1765
|
-
function test(func as sub() as integer) as integer
|
|
1766
|
-
return func()
|
|
1767
|
-
end function
|
|
1768
|
-
|
|
1769
|
-
function test2(func as function() as integer) as integer
|
|
1770
|
-
return func()
|
|
1771
|
-
end function
|
|
1772
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1773
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1774
|
-
});
|
|
1775
|
-
it('can have primitive parameters', () => {
|
|
1776
|
-
let { diagnostics } = parse(`
|
|
1777
|
-
function test(func as function(name as string, num as integer) as integer) as integer
|
|
1778
|
-
return func("hello", 123)
|
|
1779
|
-
end function
|
|
1780
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1781
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1782
|
-
});
|
|
1783
|
-
it('can have complex parameters', () => {
|
|
1784
|
-
let { diagnostics } = parse(`
|
|
1785
|
-
interface IFace
|
|
1786
|
-
name as string
|
|
1787
|
-
end interface
|
|
1788
|
-
|
|
1789
|
-
function test(func as function(thing as IFace) as integer) as integer
|
|
1790
|
-
return func({name: "hello"})
|
|
1791
|
-
end function
|
|
1792
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1793
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1794
|
-
});
|
|
1795
|
-
it('can have compound parameters', () => {
|
|
1796
|
-
let { diagnostics } = parse(`
|
|
1797
|
-
interface IFace
|
|
1798
|
-
name as string
|
|
1799
|
-
end interface
|
|
1800
|
-
|
|
1801
|
-
function test(func as function(arg1 as string or integer, arg2 as IFace) as integer) as integer
|
|
1802
|
-
return func("hello", {name: "hello"})
|
|
1803
|
-
end function
|
|
1804
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1805
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1806
|
-
});
|
|
1807
|
-
it('can be used as return types', () => {
|
|
1808
|
-
let { diagnostics } = parse(`
|
|
1809
|
-
function test() as function() as integer
|
|
1810
|
-
return function() as integer
|
|
1811
|
-
return 123
|
|
1812
|
-
end function
|
|
1813
|
-
end function
|
|
1814
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1815
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1816
|
-
});
|
|
1817
|
-
it('can have a union as return type', () => {
|
|
1818
|
-
let { diagnostics } = parse(`
|
|
1819
|
-
type foo = function() as integer or string
|
|
1820
|
-
function test() as foo
|
|
1821
|
-
return function() as integer
|
|
1822
|
-
return 123
|
|
1823
|
-
end function
|
|
1824
|
-
end function
|
|
1825
|
-
`, Parser_1.ParseMode.BrighterScript);
|
|
1826
|
-
(0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
|
|
1827
|
-
});
|
|
1828
|
-
});
|
|
1829
|
-
});
|
|
1830
|
-
function parse(text, mode) {
|
|
1831
|
-
let { tokens } = Lexer_1.Lexer.scan(text);
|
|
1832
|
-
return Parser_1.Parser.parse(tokens, {
|
|
1833
|
-
mode: mode
|
|
1834
|
-
});
|
|
1835
|
-
}
|
|
1836
|
-
function rangeToArray(range) {
|
|
1837
|
-
return [
|
|
1838
|
-
range.start.line,
|
|
1839
|
-
range.start.character,
|
|
1840
|
-
range.end.line,
|
|
1841
|
-
range.end.character
|
|
1842
|
-
];
|
|
1843
|
-
}
|
|
1844
|
-
exports.rangeToArray = rangeToArray;
|
|
1845
|
-
function expectCommentWithText(stat, text) {
|
|
1846
|
-
if ((0, reflection_1.isCommentStatement)(stat)) {
|
|
1847
|
-
(0, chai_config_spec_1.expect)(stat.text).to.equal(text);
|
|
1848
|
-
}
|
|
1849
|
-
else {
|
|
1850
|
-
failStatementType(stat, 'Comment');
|
|
1851
|
-
}
|
|
1852
|
-
}
|
|
1853
|
-
function failStatementType(stat, type) {
|
|
1854
|
-
chai_config_spec_1.assert.fail(`Statement ${stat.constructor.name} line ${stat.range.start.line} is not a ${type}`);
|
|
1855
|
-
}
|
|
1856
|
-
exports.failStatementType = failStatementType;
|
|
1857
|
-
//# sourceMappingURL=Parser.spec.js.map
|