brighterscript 0.66.0-alpha.6 → 0.66.0-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +88 -10
- package/README.md +16 -0
- package/bsconfig.schema.json +15 -0
- package/dist/ActionPipeline.d.ts +10 -0
- package/dist/ActionPipeline.js +40 -0
- package/dist/ActionPipeline.js.map +1 -0
- package/dist/AstValidationSegmenter.d.ts +25 -0
- package/dist/AstValidationSegmenter.js +150 -0
- package/dist/AstValidationSegmenter.js.map +1 -0
- package/dist/BsConfig.d.ts +15 -1
- package/dist/CommentFlagProcessor.d.ts +4 -3
- package/dist/CommentFlagProcessor.js.map +1 -1
- package/dist/DiagnosticMessages.d.ts +8 -1
- package/dist/DiagnosticMessages.js +30 -13
- package/dist/DiagnosticMessages.js.map +1 -1
- package/dist/LanguageServer.js +7 -1
- package/dist/LanguageServer.js.map +1 -1
- package/dist/PluginInterface.d.ts +11 -2
- package/dist/PluginInterface.js +69 -10
- package/dist/PluginInterface.js.map +1 -1
- package/dist/Program.d.ts +107 -38
- package/dist/Program.js +502 -270
- package/dist/Program.js.map +1 -1
- package/dist/ProgramBuilder.d.ts +10 -4
- package/dist/ProgramBuilder.js +44 -54
- package/dist/ProgramBuilder.js.map +1 -1
- package/dist/Scope.d.ts +26 -38
- package/dist/Scope.js +153 -174
- package/dist/Scope.js.map +1 -1
- package/dist/SymbolTable.d.ts +4 -1
- package/dist/SymbolTable.js +19 -7
- package/dist/SymbolTable.js.map +1 -1
- package/dist/XmlScope.d.ts +5 -4
- package/dist/XmlScope.js +16 -14
- package/dist/XmlScope.js.map +1 -1
- package/dist/astUtils/{AstEditor.d.ts → Editor.d.ts} +6 -1
- package/dist/astUtils/{AstEditor.js → Editor.js} +9 -3
- package/dist/astUtils/Editor.js.map +1 -0
- package/dist/astUtils/{AstEditor.spec.js → Editor.spec.js} +10 -6
- package/dist/astUtils/Editor.spec.js.map +1 -0
- package/dist/astUtils/reflection.d.ts +9 -4
- package/dist/astUtils/reflection.js +23 -7
- package/dist/astUtils/reflection.js.map +1 -1
- package/dist/astUtils/reflection.spec.js +2 -2
- package/dist/astUtils/reflection.spec.js.map +1 -1
- package/dist/astUtils/visitors.d.ts +14 -3
- package/dist/astUtils/visitors.js +22 -2
- package/dist/astUtils/visitors.js.map +1 -1
- package/dist/astUtils/visitors.spec.js +58 -7
- package/dist/astUtils/visitors.spec.js.map +1 -1
- package/dist/bscPlugin/BscPlugin.d.ts +10 -2
- package/dist/bscPlugin/BscPlugin.js +24 -4
- package/dist/bscPlugin/BscPlugin.js.map +1 -1
- package/dist/bscPlugin/FileWriter.d.ts +6 -0
- package/dist/bscPlugin/FileWriter.js +24 -0
- package/dist/bscPlugin/FileWriter.js.map +1 -0
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +8 -8
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/completions/CompletionsProcessor.d.ts +7 -2
- package/dist/bscPlugin/completions/CompletionsProcessor.js +112 -44
- package/dist/bscPlugin/completions/CompletionsProcessor.js.map +1 -1
- package/dist/bscPlugin/completions/CompletionsProcessor.spec.js +212 -6
- package/dist/bscPlugin/completions/CompletionsProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/fileProviders/FileProvider.d.ts +9 -0
- package/dist/bscPlugin/fileProviders/FileProvider.js +51 -0
- package/dist/bscPlugin/fileProviders/FileProvider.js.map +1 -0
- package/dist/bscPlugin/hover/HoverProcessor.d.ts +1 -7
- package/dist/bscPlugin/hover/HoverProcessor.js +10 -8
- package/dist/bscPlugin/hover/HoverProcessor.js.map +1 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.d.ts +1 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +43 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js +22 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/serialize/BslibInjector.spec.js +19 -0
- package/dist/bscPlugin/serialize/BslibInjector.spec.js.map +1 -0
- package/dist/bscPlugin/serialize/BslibManager.d.ts +9 -0
- package/dist/bscPlugin/serialize/BslibManager.js +40 -0
- package/dist/bscPlugin/serialize/BslibManager.js.map +1 -0
- package/dist/bscPlugin/serialize/FileSerializer.d.ts +9 -0
- package/dist/bscPlugin/serialize/FileSerializer.js +72 -0
- package/dist/bscPlugin/serialize/FileSerializer.js.map +1 -0
- package/dist/bscPlugin/transpile/{BrsFilePreTranspileProcessor.d.ts → BrsFileTranspileProcessor.d.ts} +4 -2
- package/dist/bscPlugin/transpile/{BrsFilePreTranspileProcessor.js → BrsFileTranspileProcessor.js} +29 -5
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js.map +1 -0
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.d.ts +1 -0
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.js +41 -0
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.js.map +1 -0
- package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.d.ts +2 -2
- package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.js.map +1 -1
- package/dist/bscPlugin/validation/BrsFileValidator.js +8 -3
- package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -1
- package/dist/bscPlugin/validation/BrsFileValidator.spec.js +1 -1
- package/dist/bscPlugin/validation/BrsFileValidator.spec.js.map +1 -1
- package/dist/bscPlugin/validation/ScopeValidator.d.ts +5 -9
- package/dist/bscPlugin/validation/ScopeValidator.js +214 -222
- package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -1
- package/dist/bscPlugin/validation/ScopeValidator.spec.js +669 -0
- package/dist/bscPlugin/validation/ScopeValidator.spec.js.map +1 -1
- package/dist/bscPlugin/validation/XmlFileValidator.js +2 -2
- package/dist/bscPlugin/validation/XmlFileValidator.js.map +1 -1
- package/dist/cli.js +1 -0
- package/dist/cli.js.map +1 -1
- package/dist/deferred.d.ts +2 -2
- package/dist/deferred.js.map +1 -1
- package/dist/diagnosticUtils.d.ts +1 -0
- package/dist/diagnosticUtils.js +4 -3
- package/dist/diagnosticUtils.js.map +1 -1
- package/dist/examples/plugins/removePrint.js +1 -1
- package/dist/examples/plugins/removePrint.js.map +1 -1
- package/dist/files/AssetFile.d.ts +26 -0
- package/dist/files/AssetFile.js +26 -0
- package/dist/files/AssetFile.js.map +1 -0
- package/dist/files/BrsFile.Class.spec.js +241 -40
- package/dist/files/BrsFile.Class.spec.js.map +1 -1
- package/dist/files/BrsFile.d.ts +66 -16
- package/dist/files/BrsFile.js +330 -80
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/BrsFile.spec.js +1134 -167
- package/dist/files/BrsFile.spec.js.map +1 -1
- package/dist/files/Factory.d.ts +25 -0
- package/dist/files/Factory.js +22 -0
- package/dist/files/Factory.js.map +1 -0
- package/dist/files/File.d.ts +106 -0
- package/dist/files/File.js +16 -0
- package/dist/files/File.js.map +1 -0
- package/dist/files/LazyFileData.d.ts +20 -0
- package/dist/files/LazyFileData.js +54 -0
- package/dist/files/LazyFileData.js.map +1 -0
- package/dist/files/LazyFileData.spec.d.ts +1 -0
- package/dist/files/LazyFileData.spec.js +27 -0
- package/dist/files/LazyFileData.spec.js.map +1 -0
- package/dist/files/XmlFile.d.ts +55 -17
- package/dist/files/XmlFile.js +88 -47
- package/dist/files/XmlFile.js.map +1 -1
- package/dist/files/XmlFile.spec.js +64 -57
- package/dist/files/XmlFile.spec.js.map +1 -1
- package/dist/files/tests/imports.spec.js +21 -8
- package/dist/files/tests/imports.spec.js.map +1 -1
- package/dist/files/tests/optionalChaning.spec.js +14 -14
- package/dist/files/tests/optionalChaning.spec.js.map +1 -1
- package/dist/globalCallables.js +1 -1
- package/dist/globalCallables.js.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +357 -89
- package/dist/interfaces.js +10 -2
- package/dist/interfaces.js.map +1 -1
- package/dist/lexer/Lexer.js +1 -1
- package/dist/lexer/TokenKind.d.ts +1 -0
- package/dist/lexer/TokenKind.js +4 -1
- package/dist/lexer/TokenKind.js.map +1 -1
- package/dist/parser/AstNode.d.ts +2 -2
- package/dist/parser/AstNode.js +1 -1
- package/dist/parser/AstNode.js.map +1 -1
- package/dist/parser/BrsTranspileState.d.ts +3 -2
- package/dist/parser/BrsTranspileState.js +3 -2
- package/dist/parser/BrsTranspileState.js.map +1 -1
- package/dist/parser/Expression.d.ts +2 -2
- package/dist/parser/Expression.js +23 -19
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Parser.Class.spec.js +103 -0
- package/dist/parser/Parser.Class.spec.js.map +1 -1
- package/dist/parser/Parser.js +61 -13
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/Parser.spec.js +227 -1
- package/dist/parser/Parser.spec.js.map +1 -1
- package/dist/parser/SGParser.d.ts +2 -2
- package/dist/parser/SGParser.js +3 -3
- package/dist/parser/SGParser.js.map +1 -1
- package/dist/parser/SGParser.spec.js +2 -2
- package/dist/parser/SGParser.spec.js.map +1 -1
- package/dist/parser/SGTypes.d.ts +1 -1
- package/dist/parser/Statement.d.ts +12 -5
- package/dist/parser/Statement.js +56 -26
- package/dist/parser/Statement.js.map +1 -1
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +16 -16
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +10 -10
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.js +24 -24
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js +64 -36
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TernaryExpression.spec.js +34 -34
- package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/UnaryExpression.spec.d.ts +1 -0
- package/dist/parser/tests/expression/UnaryExpression.spec.js +52 -0
- package/dist/parser/tests/expression/UnaryExpression.spec.js.map +1 -0
- package/dist/parser/tests/statement/ConstStatement.spec.js +90 -16
- package/dist/parser/tests/statement/ConstStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Continue.spec.js +2 -2
- package/dist/parser/tests/statement/Continue.spec.js.map +1 -1
- package/dist/parser/tests/statement/Enum.spec.js +35 -26
- package/dist/parser/tests/statement/Enum.spec.js.map +1 -1
- package/dist/parser/tests/statement/For.spec.js +6 -6
- package/dist/parser/tests/statement/For.spec.js.map +1 -1
- package/dist/parser/tests/statement/ForEach.spec.js +4 -4
- package/dist/parser/tests/statement/ForEach.spec.js.map +1 -1
- package/dist/parser/tests/statement/InterfaceStatement.spec.js +20 -12
- package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/PrintStatement.spec.js +10 -10
- package/dist/parser/tests/statement/PrintStatement.spec.js.map +1 -1
- package/dist/preprocessor/Manifest.d.ts +1 -1
- package/dist/preprocessor/Manifest.js +2 -2
- package/dist/preprocessor/Manifest.js.map +1 -1
- package/dist/roku-types/data.json +98 -193
- package/dist/roku-types/index.d.ts +15 -11
- package/dist/types/ArrayType.d.ts +1 -1
- package/dist/types/ArrayType.js +4 -0
- package/dist/types/ArrayType.js.map +1 -1
- package/dist/types/ArrayType.spec.js +1 -1
- package/dist/types/ArrayType.spec.js.map +1 -1
- package/dist/types/AssociativeArrayType.d.ts +1 -1
- package/dist/types/AssociativeArrayType.js +1 -1
- package/dist/types/AssociativeArrayType.js.map +1 -1
- package/dist/types/BooleanType.d.ts +1 -1
- package/dist/types/BooleanType.js +2 -1
- package/dist/types/BooleanType.js.map +1 -1
- package/dist/types/BscType.d.ts +2 -2
- package/dist/types/BscType.js +30 -9
- package/dist/types/BscType.js.map +1 -1
- package/dist/types/BuiltInInterfaceAdder.d.ts +3 -0
- package/dist/types/BuiltInInterfaceAdder.js +37 -16
- package/dist/types/BuiltInInterfaceAdder.js.map +1 -1
- package/dist/types/BuiltInInterfaceAdder.spec.js +7 -0
- package/dist/types/BuiltInInterfaceAdder.spec.js.map +1 -1
- package/dist/types/ClassType.d.ts +4 -3
- package/dist/types/ClassType.js +6 -3
- package/dist/types/ClassType.js.map +1 -1
- package/dist/types/ClassType.spec.js +5 -3
- package/dist/types/ClassType.spec.js.map +1 -1
- package/dist/types/ComponentType.d.ts +1 -1
- package/dist/types/ComponentType.js +3 -0
- package/dist/types/ComponentType.js.map +1 -1
- package/dist/types/DoubleType.js +3 -1
- package/dist/types/DoubleType.js.map +1 -1
- package/dist/types/EnumType.d.ts +1 -1
- package/dist/types/EnumType.js +7 -2
- package/dist/types/EnumType.js.map +1 -1
- package/dist/types/FloatType.js +3 -1
- package/dist/types/FloatType.js.map +1 -1
- package/dist/types/InheritableType.d.ts +7 -4
- package/dist/types/InheritableType.js +67 -3
- package/dist/types/InheritableType.js.map +1 -1
- package/dist/types/IntegerType.js +3 -1
- package/dist/types/IntegerType.js.map +1 -1
- package/dist/types/InterfaceType.d.ts +5 -4
- package/dist/types/InterfaceType.js +5 -12
- package/dist/types/InterfaceType.js.map +1 -1
- package/dist/types/InterfaceType.spec.js +23 -0
- package/dist/types/InterfaceType.spec.js.map +1 -1
- package/dist/types/LongIntegerType.js +3 -1
- package/dist/types/LongIntegerType.js.map +1 -1
- package/dist/types/NamespaceType.d.ts +2 -1
- package/dist/types/NamespaceType.js +3 -0
- package/dist/types/NamespaceType.js.map +1 -1
- package/dist/types/ObjectType.d.ts +1 -1
- package/dist/types/ReferenceType.js +40 -6
- package/dist/types/ReferenceType.js.map +1 -1
- package/dist/types/StringType.js +2 -2
- package/dist/types/StringType.js.map +1 -1
- package/dist/types/TypedFunctionType.d.ts +6 -1
- package/dist/types/TypedFunctionType.js +46 -16
- package/dist/types/TypedFunctionType.js.map +1 -1
- package/dist/types/TypedFunctionType.spec.js +99 -0
- package/dist/types/TypedFunctionType.spec.js.map +1 -1
- package/dist/types/UnionType.js +8 -0
- package/dist/types/UnionType.js.map +1 -1
- package/dist/types/helper.spec.js +15 -0
- package/dist/types/helper.spec.js.map +1 -1
- package/dist/types/helpers.d.ts +3 -0
- package/dist/types/helpers.js +33 -1
- package/dist/types/helpers.js.map +1 -1
- package/dist/util.d.ts +25 -9
- package/dist/util.js +165 -72
- package/dist/util.js.map +1 -1
- package/dist/validators/ClassValidator.js.map +1 -1
- package/package.json +2 -2
- package/dist/astUtils/AstEditor.js.map +0 -1
- package/dist/astUtils/AstEditor.spec.js.map +0 -1
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js.map +0 -1
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js +0 -31
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js.map +0 -1
- /package/dist/astUtils/{AstEditor.spec.d.ts → Editor.spec.d.ts} +0 -0
- /package/dist/bscPlugin/{transpile/BrsFilePreTranspileProcessor.spec.d.ts → serialize/BslibInjector.spec.d.ts} +0 -0
|
@@ -15,16 +15,16 @@ const Lexer_1 = require("../lexer/Lexer");
|
|
|
15
15
|
const TokenKind_1 = require("../lexer/TokenKind");
|
|
16
16
|
const DiagnosticMessages_1 = require("../DiagnosticMessages");
|
|
17
17
|
const util_1 = require("../util");
|
|
18
|
-
const PluginInterface_1 = require("../PluginInterface");
|
|
19
18
|
const testHelpers_spec_1 = require("../testHelpers.spec");
|
|
20
19
|
const Parser_1 = require("../parser/Parser");
|
|
21
|
-
const Logger_1 = require("../Logger");
|
|
22
20
|
const Statement_1 = require("../parser/Statement");
|
|
23
21
|
const creators_1 = require("../astUtils/creators");
|
|
24
22
|
const fsExtra = require("fs-extra");
|
|
25
23
|
const vscode_uri_1 = require("vscode-uri");
|
|
26
24
|
const undent_1 = require("undent");
|
|
27
25
|
const testHelpers_spec_2 = require("../testHelpers.spec");
|
|
26
|
+
const SymbolTable_1 = require("../SymbolTable");
|
|
27
|
+
const types_1 = require("../types");
|
|
28
28
|
let sinon = sinonImport.createSandbox();
|
|
29
29
|
describe('BrsFile', () => {
|
|
30
30
|
let program;
|
|
@@ -36,12 +36,41 @@ describe('BrsFile', () => {
|
|
|
36
36
|
beforeEach(() => {
|
|
37
37
|
fsExtra.emptyDirSync(testHelpers_spec_2.tempDir);
|
|
38
38
|
program = new Program_1.Program({ rootDir: testHelpers_spec_2.rootDir, sourceMap: true });
|
|
39
|
-
file = new BrsFile_1.BrsFile(
|
|
39
|
+
file = new BrsFile_1.BrsFile({
|
|
40
|
+
srcPath: srcPath,
|
|
41
|
+
destPath: destPath,
|
|
42
|
+
program: program
|
|
43
|
+
});
|
|
40
44
|
});
|
|
41
45
|
afterEach(() => {
|
|
42
46
|
sinon.restore();
|
|
43
47
|
program.dispose();
|
|
44
48
|
});
|
|
49
|
+
describe('constructor', () => {
|
|
50
|
+
it('calculates correct paths when no pkgPath specified', () => {
|
|
51
|
+
(0, chai_config_spec_1.expect)(new BrsFile_1.BrsFile({
|
|
52
|
+
srcPath: (0, util_1.standardizePath) `${testHelpers_spec_2.rootDir}/source/main.bs`,
|
|
53
|
+
destPath: (0, util_1.standardizePath) `source/main.bs`,
|
|
54
|
+
program: program
|
|
55
|
+
})).to.include({
|
|
56
|
+
srcPath: (0, util_1.standardizePath) `${testHelpers_spec_2.rootDir}/source/main.bs`,
|
|
57
|
+
destPath: (0, util_1.standardizePath) `source/main.bs`,
|
|
58
|
+
pkgPath: (0, util_1.standardizePath) `source/main.brs`
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
it('uses supplied pkgPath', () => {
|
|
62
|
+
(0, chai_config_spec_1.expect)(new BrsFile_1.BrsFile({
|
|
63
|
+
srcPath: (0, util_1.standardizePath) `${testHelpers_spec_2.rootDir}/source/main.bs`,
|
|
64
|
+
destPath: (0, util_1.standardizePath) `source/main.bs`,
|
|
65
|
+
pkgPath: (0, util_1.standardizePath) `source/main.transpiled.brs`,
|
|
66
|
+
program: program
|
|
67
|
+
})).to.include({
|
|
68
|
+
srcPath: (0, util_1.standardizePath) `${testHelpers_spec_2.rootDir}/source/main.bs`,
|
|
69
|
+
destPath: (0, util_1.standardizePath) `source/main.bs`,
|
|
70
|
+
pkgPath: (0, util_1.standardizePath) `source/main.transpiled.brs`
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
|
45
74
|
describe('allowBrighterScriptInBrightScript', () => {
|
|
46
75
|
it('is false by default', () => {
|
|
47
76
|
program.setFile('source/main.brs', `
|
|
@@ -82,6 +111,22 @@ describe('BrsFile', () => {
|
|
|
82
111
|
program.validate();
|
|
83
112
|
(0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.itemCannotBeUsedAsVariable('namespace')), { range: util_1.default.createRange(3, 22, 3, 27) }), Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.itemCannotBeUsedAsVariable('namespace')), { range: util_1.default.createRange(4, 22, 4, 32) }), Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.itemCannotBeUsedAsVariable('namespace')), { range: util_1.default.createRange(5, 22, 5, 40) })]);
|
|
84
113
|
});
|
|
114
|
+
it('allows namespaces with the name `optional`', () => {
|
|
115
|
+
program.setFile('source/main.bs', `
|
|
116
|
+
namespace optional
|
|
117
|
+
namespace optional
|
|
118
|
+
end namespace
|
|
119
|
+
end namespace
|
|
120
|
+
namespace alpha
|
|
121
|
+
namespace optional
|
|
122
|
+
end namespace
|
|
123
|
+
end namespace
|
|
124
|
+
namespace alpha.beta.optional
|
|
125
|
+
end namespace
|
|
126
|
+
`);
|
|
127
|
+
program.validate();
|
|
128
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
129
|
+
});
|
|
85
130
|
it('flags enums used as variables', () => {
|
|
86
131
|
program.setFile('source/main.bs', `
|
|
87
132
|
enum Foo
|
|
@@ -125,9 +170,17 @@ describe('BrsFile', () => {
|
|
|
125
170
|
});
|
|
126
171
|
it('sets needsTranspiled to true for .bs files', () => {
|
|
127
172
|
//BrightScript
|
|
128
|
-
(0, chai_config_spec_1.expect)(new BrsFile_1.BrsFile(
|
|
173
|
+
(0, chai_config_spec_1.expect)(new BrsFile_1.BrsFile({
|
|
174
|
+
srcPath: `${testHelpers_spec_2.rootDir}/source/main.brs`,
|
|
175
|
+
destPath: 'source/main.brs',
|
|
176
|
+
program: program
|
|
177
|
+
})['needsTranspiled']).to.be.false;
|
|
129
178
|
//BrighterScript
|
|
130
|
-
(0, chai_config_spec_1.expect)(new BrsFile_1.BrsFile(
|
|
179
|
+
(0, chai_config_spec_1.expect)(new BrsFile_1.BrsFile({
|
|
180
|
+
srcPath: `${testHelpers_spec_2.rootDir}/source/main.bs`,
|
|
181
|
+
destPath: 'source/main.bs',
|
|
182
|
+
program: program
|
|
183
|
+
})['needsTranspiled']).to.be.true;
|
|
131
184
|
});
|
|
132
185
|
it('computes new import statements after clearing parser references', () => {
|
|
133
186
|
const file = program.setFile('source/main.bs', ``);
|
|
@@ -235,12 +288,12 @@ describe('BrsFile', () => {
|
|
|
235
288
|
something = true 'bs:disable-line: LINT1005
|
|
236
289
|
end sub
|
|
237
290
|
`);
|
|
238
|
-
file.
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
291
|
+
file.diagnostics.push({
|
|
292
|
+
code: 'LINT1005',
|
|
293
|
+
file: file,
|
|
294
|
+
message: 'Something is not right',
|
|
295
|
+
range: util_1.default.createRange(2, 16, 2, 26)
|
|
296
|
+
});
|
|
244
297
|
const scope = program.getScopesForFile(file)[0];
|
|
245
298
|
(0, testHelpers_spec_1.expectZeroDiagnostics)(scope);
|
|
246
299
|
});
|
|
@@ -925,7 +978,11 @@ describe('BrsFile', () => {
|
|
|
925
978
|
`);
|
|
926
979
|
});
|
|
927
980
|
it('finds line and column numbers for functions', () => {
|
|
928
|
-
let file = new BrsFile_1.BrsFile(
|
|
981
|
+
let file = new BrsFile_1.BrsFile({
|
|
982
|
+
srcPath: 'absolute_path/file.brs',
|
|
983
|
+
destPath: 'relative_path/file.brs',
|
|
984
|
+
program: program
|
|
985
|
+
});
|
|
929
986
|
file.parse(`
|
|
930
987
|
function DoA()
|
|
931
988
|
print "A"
|
|
@@ -941,7 +998,11 @@ describe('BrsFile', () => {
|
|
|
941
998
|
(0, chai_config_spec_1.expect)(file.callables[1].nameRange).to.eql(vscode_languageserver_1.Range.create(5, 26, 5, 29));
|
|
942
999
|
});
|
|
943
1000
|
it('throws an error if the file has already been parsed', () => {
|
|
944
|
-
let file = new BrsFile_1.BrsFile(
|
|
1001
|
+
let file = new BrsFile_1.BrsFile({
|
|
1002
|
+
srcPath: 'abspath',
|
|
1003
|
+
destPath: 'relpath',
|
|
1004
|
+
program: program
|
|
1005
|
+
});
|
|
945
1006
|
file.parse(`'a comment`);
|
|
946
1007
|
try {
|
|
947
1008
|
file.parse(`'a new comment`);
|
|
@@ -952,7 +1013,11 @@ describe('BrsFile', () => {
|
|
|
952
1013
|
}
|
|
953
1014
|
});
|
|
954
1015
|
it('finds and registers duplicate callables', () => {
|
|
955
|
-
let file = new BrsFile_1.BrsFile(
|
|
1016
|
+
let file = new BrsFile_1.BrsFile({
|
|
1017
|
+
srcPath: 'absolute_path/file.brs',
|
|
1018
|
+
destPath: 'relative_path/file.brs',
|
|
1019
|
+
program: program
|
|
1020
|
+
});
|
|
956
1021
|
file.parse(`
|
|
957
1022
|
function DoA()
|
|
958
1023
|
print "A"
|
|
@@ -969,7 +1034,11 @@ describe('BrsFile', () => {
|
|
|
969
1034
|
(0, chai_config_spec_1.expect)(file.callables[1].nameRange.start.line).to.equal(5);
|
|
970
1035
|
});
|
|
971
1036
|
it('finds function call line and column numbers', () => {
|
|
972
|
-
let file = new BrsFile_1.BrsFile(
|
|
1037
|
+
let file = new BrsFile_1.BrsFile({
|
|
1038
|
+
srcPath: 'absolute_path/file.brs',
|
|
1039
|
+
destPath: 'relative_path/file.brs',
|
|
1040
|
+
program: program
|
|
1041
|
+
});
|
|
973
1042
|
file.parse(`
|
|
974
1043
|
function DoA()
|
|
975
1044
|
DoB("a")
|
|
@@ -985,7 +1054,11 @@ describe('BrsFile', () => {
|
|
|
985
1054
|
(0, chai_config_spec_1.expect)(file.functionCalls[1].nameRange).to.eql(vscode_languageserver_1.Range.create(5, 20, 5, 23));
|
|
986
1055
|
});
|
|
987
1056
|
it('finds function calls that are unfinished', () => {
|
|
988
|
-
let file = new BrsFile_1.BrsFile(
|
|
1057
|
+
let file = new BrsFile_1.BrsFile({
|
|
1058
|
+
srcPath: 'absolute_path/file.brs',
|
|
1059
|
+
destPath: 'relative_path/file.brs',
|
|
1060
|
+
program: program
|
|
1061
|
+
});
|
|
989
1062
|
file.parse(`
|
|
990
1063
|
function DoA()
|
|
991
1064
|
DoB("a"
|
|
@@ -1008,7 +1081,11 @@ describe('BrsFile', () => {
|
|
|
1008
1081
|
(0, chai_config_spec_1.expect)(file.functionCalls[1].nameRange).to.eql(vscode_languageserver_1.Range.create(5, 20, 5, 23));
|
|
1009
1082
|
});
|
|
1010
1083
|
it('sanitizes brs errors', () => {
|
|
1011
|
-
let file = new BrsFile_1.BrsFile(
|
|
1084
|
+
let file = new BrsFile_1.BrsFile({
|
|
1085
|
+
srcPath: 'absolute_path/file.brs',
|
|
1086
|
+
destPath: 'relative_path/file.brs',
|
|
1087
|
+
program: program
|
|
1088
|
+
});
|
|
1012
1089
|
file.parse(`
|
|
1013
1090
|
function DoSomething
|
|
1014
1091
|
end function
|
|
@@ -1018,7 +1095,11 @@ describe('BrsFile', () => {
|
|
|
1018
1095
|
(0, chai_config_spec_1.expect)(file.getDiagnostics()[0].range.start.line).to.equal(1);
|
|
1019
1096
|
});
|
|
1020
1097
|
it('supports using the `next` keyword in a for loop', () => {
|
|
1021
|
-
let file = new BrsFile_1.BrsFile(
|
|
1098
|
+
let file = new BrsFile_1.BrsFile({
|
|
1099
|
+
srcPath: 'absolute_path/file.brs',
|
|
1100
|
+
destPath: 'relative_path/file.brs',
|
|
1101
|
+
program: program
|
|
1102
|
+
});
|
|
1022
1103
|
file.parse(`
|
|
1023
1104
|
sub countit()
|
|
1024
1105
|
for each num in [1,2,3]
|
|
@@ -1030,7 +1111,11 @@ describe('BrsFile', () => {
|
|
|
1030
1111
|
});
|
|
1031
1112
|
//test is not working yet, but will be enabled when brs supports this syntax
|
|
1032
1113
|
it('supports assigning functions to objects', () => {
|
|
1033
|
-
let file = new BrsFile_1.BrsFile(
|
|
1114
|
+
let file = new BrsFile_1.BrsFile({
|
|
1115
|
+
srcPath: 'absolute_path/file.brs',
|
|
1116
|
+
destPath: 'relative_path/file.brs',
|
|
1117
|
+
program: program
|
|
1118
|
+
});
|
|
1034
1119
|
file.parse(`
|
|
1035
1120
|
function main()
|
|
1036
1121
|
o = CreateObject("roAssociativeArray")
|
|
@@ -1058,7 +1143,11 @@ describe('BrsFile', () => {
|
|
|
1058
1143
|
});
|
|
1059
1144
|
describe('findCallables', () => {
|
|
1060
1145
|
it('finds range', () => {
|
|
1061
|
-
let file = new BrsFile_1.BrsFile(
|
|
1146
|
+
let file = new BrsFile_1.BrsFile({
|
|
1147
|
+
srcPath: 'absolute_path/file.brs',
|
|
1148
|
+
destPath: 'relative_path/file.brs',
|
|
1149
|
+
program: program
|
|
1150
|
+
});
|
|
1062
1151
|
file.parse(`
|
|
1063
1152
|
sub Sum()
|
|
1064
1153
|
print "hello world"
|
|
@@ -1068,7 +1157,11 @@ describe('BrsFile', () => {
|
|
|
1068
1157
|
(0, chai_config_spec_1.expect)(callable.range).to.eql(vscode_languageserver_1.Range.create(1, 16, 3, 23));
|
|
1069
1158
|
});
|
|
1070
1159
|
it('finds correct body range even with inner function', () => {
|
|
1071
|
-
let file = new BrsFile_1.BrsFile(
|
|
1160
|
+
let file = new BrsFile_1.BrsFile({
|
|
1161
|
+
srcPath: 'absolute_path/file.brs',
|
|
1162
|
+
destPath: 'relative_path/file.brs',
|
|
1163
|
+
program: program
|
|
1164
|
+
});
|
|
1072
1165
|
file.parse(`
|
|
1073
1166
|
sub Sum()
|
|
1074
1167
|
sayHi = sub()
|
|
@@ -1081,7 +1174,11 @@ describe('BrsFile', () => {
|
|
|
1081
1174
|
(0, chai_config_spec_1.expect)(callable.range).to.eql(vscode_languageserver_1.Range.create(1, 16, 6, 23));
|
|
1082
1175
|
});
|
|
1083
1176
|
it('finds callable parameters', () => {
|
|
1084
|
-
let file = new BrsFile_1.BrsFile(
|
|
1177
|
+
let file = new BrsFile_1.BrsFile({
|
|
1178
|
+
srcPath: 'absolute_path/file.brs',
|
|
1179
|
+
destPath: 'relative_path/file.brs',
|
|
1180
|
+
program: program
|
|
1181
|
+
});
|
|
1085
1182
|
file.parse(`
|
|
1086
1183
|
function Sum(a, b, c)
|
|
1087
1184
|
|
|
@@ -1108,7 +1205,11 @@ describe('BrsFile', () => {
|
|
|
1108
1205
|
(0, chai_config_spec_1.expect)(callable.params[2].type).instanceof(DynamicType_1.DynamicType);
|
|
1109
1206
|
});
|
|
1110
1207
|
it('finds optional parameters', () => {
|
|
1111
|
-
let file = new BrsFile_1.BrsFile(
|
|
1208
|
+
let file = new BrsFile_1.BrsFile({
|
|
1209
|
+
srcPath: 'absolute_path/file.brs',
|
|
1210
|
+
destPath: 'relative_path/file.brs',
|
|
1211
|
+
program: program
|
|
1212
|
+
});
|
|
1112
1213
|
file.parse(`
|
|
1113
1214
|
function Sum(a=2)
|
|
1114
1215
|
|
|
@@ -1123,7 +1224,11 @@ describe('BrsFile', () => {
|
|
|
1123
1224
|
(0, chai_config_spec_1.expect)(callable.params[0].type).instanceof(IntegerType_1.IntegerType);
|
|
1124
1225
|
});
|
|
1125
1226
|
it('finds parameter types', () => {
|
|
1126
|
-
let file = new BrsFile_1.BrsFile(
|
|
1227
|
+
let file = new BrsFile_1.BrsFile({
|
|
1228
|
+
srcPath: 'absolute_path/file.brs',
|
|
1229
|
+
destPath: 'relative_path/file.brs',
|
|
1230
|
+
program: program
|
|
1231
|
+
});
|
|
1127
1232
|
file.parse(`
|
|
1128
1233
|
function Sum(a, b as integer, c as string)
|
|
1129
1234
|
|
|
@@ -1152,7 +1257,11 @@ describe('BrsFile', () => {
|
|
|
1152
1257
|
});
|
|
1153
1258
|
describe('findCallableInvocations', () => {
|
|
1154
1259
|
it('finds arguments with literal values', () => {
|
|
1155
|
-
let file = new BrsFile_1.BrsFile(
|
|
1260
|
+
let file = new BrsFile_1.BrsFile({
|
|
1261
|
+
srcPath: 'absolute_path/file.brs',
|
|
1262
|
+
destPath: 'relative_path/file.brs',
|
|
1263
|
+
program: program
|
|
1264
|
+
});
|
|
1156
1265
|
file.parse(`
|
|
1157
1266
|
function Sum()
|
|
1158
1267
|
DoSomething("name", 12, true)
|
|
@@ -1191,7 +1300,11 @@ describe('BrsFile', () => {
|
|
|
1191
1300
|
]);
|
|
1192
1301
|
});
|
|
1193
1302
|
it('finds arguments with variable values', () => {
|
|
1194
|
-
let file = new BrsFile_1.BrsFile(
|
|
1303
|
+
let file = new BrsFile_1.BrsFile({
|
|
1304
|
+
srcPath: 'absolute_path/file.brs',
|
|
1305
|
+
destPath: 'relative_path/file.brs',
|
|
1306
|
+
program: program
|
|
1307
|
+
});
|
|
1195
1308
|
file.parse(`
|
|
1196
1309
|
function Sum()
|
|
1197
1310
|
count = 1
|
|
@@ -1218,7 +1331,11 @@ describe('BrsFile', () => {
|
|
|
1218
1331
|
describe('findCallables', () => {
|
|
1219
1332
|
//this test is to help with code coverage
|
|
1220
1333
|
it('skips top-level statements', () => {
|
|
1221
|
-
let file = new BrsFile_1.BrsFile(
|
|
1334
|
+
let file = new BrsFile_1.BrsFile({
|
|
1335
|
+
srcPath: 'absolute',
|
|
1336
|
+
destPath: 'relative',
|
|
1337
|
+
program: program
|
|
1338
|
+
});
|
|
1222
1339
|
file.parse('name = "Bob"');
|
|
1223
1340
|
(0, chai_config_spec_1.expect)(file.callables.length).to.equal(0);
|
|
1224
1341
|
});
|
|
@@ -1373,7 +1490,7 @@ describe('BrsFile', () => {
|
|
|
1373
1490
|
end if
|
|
1374
1491
|
end sub
|
|
1375
1492
|
`);
|
|
1376
|
-
(0,
|
|
1493
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(mainFile);
|
|
1377
1494
|
mainFile = program.setFile('source/main.brs', `
|
|
1378
1495
|
sub Main()
|
|
1379
1496
|
if true Then
|
|
@@ -1381,7 +1498,7 @@ describe('BrsFile', () => {
|
|
|
1381
1498
|
end if
|
|
1382
1499
|
end sub
|
|
1383
1500
|
`);
|
|
1384
|
-
(0,
|
|
1501
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(mainFile);
|
|
1385
1502
|
mainFile = program.setFile('source/main.brs', `
|
|
1386
1503
|
sub Main()
|
|
1387
1504
|
if true THEN
|
|
@@ -1389,7 +1506,7 @@ describe('BrsFile', () => {
|
|
|
1389
1506
|
end if
|
|
1390
1507
|
end sub
|
|
1391
1508
|
`);
|
|
1392
|
-
(0,
|
|
1509
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(mainFile);
|
|
1393
1510
|
});
|
|
1394
1511
|
it('does not throw when encountering incomplete import statement', () => {
|
|
1395
1512
|
program.setFile('source/main.brs', `
|
|
@@ -1401,8 +1518,8 @@ describe('BrsFile', () => {
|
|
|
1401
1518
|
//this test will throw an exception if something went wrong
|
|
1402
1519
|
});
|
|
1403
1520
|
describe('transpile', () => {
|
|
1404
|
-
it('excludes trailing commas in array literals', () => {
|
|
1405
|
-
testTranspile(`
|
|
1521
|
+
it('excludes trailing commas in array literals', async () => {
|
|
1522
|
+
await testTranspile(`
|
|
1406
1523
|
sub main()
|
|
1407
1524
|
arr = [
|
|
1408
1525
|
1,
|
|
@@ -1430,7 +1547,7 @@ describe('BrsFile', () => {
|
|
|
1430
1547
|
end sub
|
|
1431
1548
|
`);
|
|
1432
1549
|
});
|
|
1433
|
-
it('transpiles if statement keywords as provided', () => {
|
|
1550
|
+
it('transpiles if statement keywords as provided', async () => {
|
|
1434
1551
|
const code = `
|
|
1435
1552
|
sub main()
|
|
1436
1553
|
If True Then
|
|
@@ -1444,12 +1561,12 @@ describe('BrsFile', () => {
|
|
|
1444
1561
|
End If
|
|
1445
1562
|
end sub
|
|
1446
1563
|
`;
|
|
1447
|
-
testTranspile(code);
|
|
1448
|
-
testTranspile(code.toLowerCase());
|
|
1449
|
-
testTranspile(code.toUpperCase());
|
|
1564
|
+
await testTranspile(code);
|
|
1565
|
+
await testTranspile(code.toLowerCase());
|
|
1566
|
+
await testTranspile(code.toUpperCase());
|
|
1450
1567
|
});
|
|
1451
|
-
it('does not transpile `then` tokens', () => {
|
|
1452
|
-
testTranspile(`
|
|
1568
|
+
it('does not transpile `then` tokens', async () => {
|
|
1569
|
+
await testTranspile(`
|
|
1453
1570
|
sub main()
|
|
1454
1571
|
if true
|
|
1455
1572
|
print true
|
|
@@ -1459,8 +1576,8 @@ describe('BrsFile', () => {
|
|
|
1459
1576
|
end sub
|
|
1460
1577
|
`);
|
|
1461
1578
|
});
|
|
1462
|
-
it('honors spacing between multi-word tokens', () => {
|
|
1463
|
-
testTranspile(`
|
|
1579
|
+
it('honors spacing between multi-word tokens', async () => {
|
|
1580
|
+
await testTranspile(`
|
|
1464
1581
|
sub main()
|
|
1465
1582
|
if true
|
|
1466
1583
|
print true
|
|
@@ -1470,8 +1587,8 @@ describe('BrsFile', () => {
|
|
|
1470
1587
|
end sub
|
|
1471
1588
|
`);
|
|
1472
1589
|
});
|
|
1473
|
-
it('handles when only some of the statements have `then`', () => {
|
|
1474
|
-
testTranspile(`
|
|
1590
|
+
it('handles when only some of the statements have `then`', async () => {
|
|
1591
|
+
await testTranspile(`
|
|
1475
1592
|
sub main()
|
|
1476
1593
|
if true
|
|
1477
1594
|
else if true then
|
|
@@ -1484,25 +1601,25 @@ describe('BrsFile', () => {
|
|
|
1484
1601
|
end sub
|
|
1485
1602
|
`);
|
|
1486
1603
|
});
|
|
1487
|
-
it('retains casing of parameter types', () => {
|
|
1488
|
-
function test(type) {
|
|
1489
|
-
testTranspile(`
|
|
1604
|
+
it('retains casing of parameter types', async () => {
|
|
1605
|
+
async function test(type) {
|
|
1606
|
+
await testTranspile(`
|
|
1490
1607
|
sub one(a as ${type}, b as ${type.toUpperCase()}, c as ${type.toLowerCase()})
|
|
1491
1608
|
end sub
|
|
1492
1609
|
`);
|
|
1493
1610
|
}
|
|
1494
|
-
test('Boolean');
|
|
1495
|
-
test('Double');
|
|
1496
|
-
test('Dynamic');
|
|
1497
|
-
test('Float');
|
|
1498
|
-
test('Integer');
|
|
1499
|
-
test('LongInteger');
|
|
1500
|
-
test('Object');
|
|
1501
|
-
test('String');
|
|
1502
|
-
});
|
|
1503
|
-
it('retains casing of return types', () => {
|
|
1504
|
-
function test(type) {
|
|
1505
|
-
testTranspile(`
|
|
1611
|
+
await test('Boolean');
|
|
1612
|
+
await test('Double');
|
|
1613
|
+
await test('Dynamic');
|
|
1614
|
+
await test('Float');
|
|
1615
|
+
await test('Integer');
|
|
1616
|
+
await test('LongInteger');
|
|
1617
|
+
await test('Object');
|
|
1618
|
+
await test('String');
|
|
1619
|
+
});
|
|
1620
|
+
it('retains casing of return types', async () => {
|
|
1621
|
+
async function test(type) {
|
|
1622
|
+
await testTranspile(`
|
|
1506
1623
|
sub one() as ${type}
|
|
1507
1624
|
end sub
|
|
1508
1625
|
|
|
@@ -1513,19 +1630,19 @@ describe('BrsFile', () => {
|
|
|
1513
1630
|
end sub
|
|
1514
1631
|
`);
|
|
1515
1632
|
}
|
|
1516
|
-
test('Boolean');
|
|
1517
|
-
test('Double');
|
|
1518
|
-
test('Dynamic');
|
|
1519
|
-
test('Float');
|
|
1520
|
-
test('Integer');
|
|
1521
|
-
test('LongInteger');
|
|
1522
|
-
test('Object');
|
|
1523
|
-
test('String');
|
|
1524
|
-
test('Void');
|
|
1525
|
-
});
|
|
1526
|
-
it('retains casing of literal types', () => {
|
|
1527
|
-
function test(type) {
|
|
1528
|
-
testTranspile(`
|
|
1633
|
+
await test('Boolean');
|
|
1634
|
+
await test('Double');
|
|
1635
|
+
await test('Dynamic');
|
|
1636
|
+
await test('Float');
|
|
1637
|
+
await test('Integer');
|
|
1638
|
+
await test('LongInteger');
|
|
1639
|
+
await test('Object');
|
|
1640
|
+
await test('String');
|
|
1641
|
+
await test('Void');
|
|
1642
|
+
});
|
|
1643
|
+
it('retains casing of literal types', async () => {
|
|
1644
|
+
async function test(type) {
|
|
1645
|
+
await testTranspile(`
|
|
1529
1646
|
sub main()
|
|
1530
1647
|
thing = ${type}
|
|
1531
1648
|
thing = ${type.toLowerCase()}
|
|
@@ -1533,13 +1650,13 @@ describe('BrsFile', () => {
|
|
|
1533
1650
|
end sub
|
|
1534
1651
|
`);
|
|
1535
1652
|
}
|
|
1536
|
-
test('Invalid');
|
|
1537
|
-
test('True');
|
|
1538
|
-
test('False');
|
|
1653
|
+
await test('Invalid');
|
|
1654
|
+
await test('True');
|
|
1655
|
+
await test('False');
|
|
1539
1656
|
});
|
|
1540
1657
|
describe('throwStatement', () => {
|
|
1541
|
-
it('transpiles properly', () => {
|
|
1542
|
-
testTranspile(`
|
|
1658
|
+
it('transpiles properly', async () => {
|
|
1659
|
+
await testTranspile(`
|
|
1543
1660
|
sub main()
|
|
1544
1661
|
try
|
|
1545
1662
|
throw "some message"
|
|
@@ -1550,8 +1667,8 @@ describe('BrsFile', () => {
|
|
|
1550
1667
|
});
|
|
1551
1668
|
});
|
|
1552
1669
|
describe('try/catch', () => {
|
|
1553
|
-
it('transpiles properly', () => {
|
|
1554
|
-
testTranspile(`
|
|
1670
|
+
it('transpiles properly', async () => {
|
|
1671
|
+
await testTranspile(`
|
|
1555
1672
|
sub main()
|
|
1556
1673
|
try
|
|
1557
1674
|
print m.b.c
|
|
@@ -1563,8 +1680,8 @@ describe('BrsFile', () => {
|
|
|
1563
1680
|
});
|
|
1564
1681
|
});
|
|
1565
1682
|
describe('namespaces', () => {
|
|
1566
|
-
it('properly transpiles namespace functions for assignments', () => {
|
|
1567
|
-
testTranspile(`
|
|
1683
|
+
it('properly transpiles namespace functions for assignments', async () => {
|
|
1684
|
+
await testTranspile(`
|
|
1568
1685
|
namespace NameA.NameB
|
|
1569
1686
|
sub Speak()
|
|
1570
1687
|
end sub
|
|
@@ -1585,8 +1702,8 @@ describe('BrsFile', () => {
|
|
|
1585
1702
|
end sub
|
|
1586
1703
|
`);
|
|
1587
1704
|
});
|
|
1588
|
-
it('properly transpiles inferred namespace function for assignment', () => {
|
|
1589
|
-
testTranspile(`
|
|
1705
|
+
it('properly transpiles inferred namespace function for assignment', async () => {
|
|
1706
|
+
await testTranspile(`
|
|
1590
1707
|
namespace NameA.NameB
|
|
1591
1708
|
sub Speak()
|
|
1592
1709
|
end sub
|
|
@@ -1606,26 +1723,26 @@ describe('BrsFile', () => {
|
|
|
1606
1723
|
`);
|
|
1607
1724
|
});
|
|
1608
1725
|
});
|
|
1609
|
-
it('includes all text to end of line for a non-terminated string', () => {
|
|
1610
|
-
testTranspile('sub main()\n name = "john \nend sub', 'sub main()\n name = "john "\nend sub', null, 'source/main.bs', false);
|
|
1726
|
+
it('includes all text to end of line for a non-terminated string', async () => {
|
|
1727
|
+
await testTranspile('sub main()\n name = "john \nend sub', 'sub main()\n name = "john "\nend sub', null, 'source/main.bs', false);
|
|
1611
1728
|
});
|
|
1612
|
-
it('escapes quotes in string literals', () => {
|
|
1613
|
-
testTranspile(`
|
|
1729
|
+
it('escapes quotes in string literals', async () => {
|
|
1730
|
+
await testTranspile(`
|
|
1614
1731
|
sub main()
|
|
1615
1732
|
expected = "Hello"
|
|
1616
1733
|
expected += chr(10) + " version=""2.0"""
|
|
1617
1734
|
end sub
|
|
1618
1735
|
`);
|
|
1619
1736
|
});
|
|
1620
|
-
it('keeps function parameter types in proper order', () => {
|
|
1621
|
-
testTranspile(`
|
|
1737
|
+
it('keeps function parameter types in proper order', async () => {
|
|
1738
|
+
await testTranspile(`
|
|
1622
1739
|
function CreateTestStatistic(name as string, result = "Success" as string, time = 0 as integer, errorCode = 0 as integer, errorMessage = "" as string) as object
|
|
1623
1740
|
end function
|
|
1624
1741
|
`);
|
|
1625
1742
|
});
|
|
1626
|
-
it('discard parameter types when removeParameterTypes is true', () => {
|
|
1743
|
+
it('discard parameter types when removeParameterTypes is true', async () => {
|
|
1627
1744
|
program.options.removeParameterTypes = true;
|
|
1628
|
-
testTranspile(`
|
|
1745
|
+
await testTranspile(`
|
|
1629
1746
|
sub one(a as integer, b = "" as string, c = invalid as dynamic)
|
|
1630
1747
|
end sub
|
|
1631
1748
|
`, `
|
|
@@ -1633,9 +1750,9 @@ describe('BrsFile', () => {
|
|
|
1633
1750
|
end sub
|
|
1634
1751
|
`);
|
|
1635
1752
|
});
|
|
1636
|
-
it('discard return type when removeParameterTypes is true', () => {
|
|
1753
|
+
it('discard return type when removeParameterTypes is true', async () => {
|
|
1637
1754
|
program.options.removeParameterTypes = true;
|
|
1638
|
-
testTranspile(`
|
|
1755
|
+
await testTranspile(`
|
|
1639
1756
|
function one() as string
|
|
1640
1757
|
return ""
|
|
1641
1758
|
end function
|
|
@@ -1645,8 +1762,8 @@ describe('BrsFile', () => {
|
|
|
1645
1762
|
end function
|
|
1646
1763
|
`);
|
|
1647
1764
|
});
|
|
1648
|
-
it('transpiles local var assignment operators', () => {
|
|
1649
|
-
testTranspile(`
|
|
1765
|
+
it('transpiles local var assignment operators', async () => {
|
|
1766
|
+
await testTranspile(`
|
|
1650
1767
|
sub main()
|
|
1651
1768
|
count = 0
|
|
1652
1769
|
count += 1
|
|
@@ -1659,8 +1776,8 @@ describe('BrsFile', () => {
|
|
|
1659
1776
|
end sub
|
|
1660
1777
|
`);
|
|
1661
1778
|
});
|
|
1662
|
-
it('transpiles AA property assignment operators', () => {
|
|
1663
|
-
testTranspile(`
|
|
1779
|
+
it('transpiles AA property assignment operators', async () => {
|
|
1780
|
+
await testTranspile(`
|
|
1664
1781
|
sub main()
|
|
1665
1782
|
person = {
|
|
1666
1783
|
count: 0
|
|
@@ -1669,8 +1786,8 @@ describe('BrsFile', () => {
|
|
|
1669
1786
|
end sub
|
|
1670
1787
|
`);
|
|
1671
1788
|
});
|
|
1672
|
-
it('transpiles AA indexed assignment operators', () => {
|
|
1673
|
-
testTranspile(`
|
|
1789
|
+
it('transpiles AA indexed assignment operators', async () => {
|
|
1790
|
+
await testTranspile(`
|
|
1674
1791
|
sub main()
|
|
1675
1792
|
person = {
|
|
1676
1793
|
count: 0
|
|
@@ -1679,8 +1796,8 @@ describe('BrsFile', () => {
|
|
|
1679
1796
|
end sub
|
|
1680
1797
|
`);
|
|
1681
1798
|
});
|
|
1682
|
-
it('relative-referenced namespaced functions get prefixed', () => {
|
|
1683
|
-
testTranspile(`
|
|
1799
|
+
it('relative-referenced namespaced functions get prefixed', async () => {
|
|
1800
|
+
await testTranspile(`
|
|
1684
1801
|
namespace Vertibrates.Birds
|
|
1685
1802
|
function GetAllBirds()
|
|
1686
1803
|
return [
|
|
@@ -1710,8 +1827,8 @@ describe('BrsFile', () => {
|
|
|
1710
1827
|
end function
|
|
1711
1828
|
`, 'trim', 'source/main.bs');
|
|
1712
1829
|
});
|
|
1713
|
-
it('transpiles namespaced functions', () => {
|
|
1714
|
-
testTranspile(`
|
|
1830
|
+
it('transpiles namespaced functions', async () => {
|
|
1831
|
+
await testTranspile(`
|
|
1715
1832
|
namespace NameA
|
|
1716
1833
|
sub alert()
|
|
1717
1834
|
end sub
|
|
@@ -1727,9 +1844,9 @@ describe('BrsFile', () => {
|
|
|
1727
1844
|
end sub
|
|
1728
1845
|
`, 'trim', 'source/main.bs');
|
|
1729
1846
|
});
|
|
1730
|
-
it('transpiles dim', () => {
|
|
1731
|
-
function doTest(code) {
|
|
1732
|
-
testTranspile(`
|
|
1847
|
+
it('transpiles dim', async () => {
|
|
1848
|
+
async function doTest(code) {
|
|
1849
|
+
await testTranspile(`
|
|
1733
1850
|
sub main()
|
|
1734
1851
|
requestList = []
|
|
1735
1852
|
${code}
|
|
@@ -1741,20 +1858,20 @@ describe('BrsFile', () => {
|
|
|
1741
1858
|
end sub
|
|
1742
1859
|
`);
|
|
1743
1860
|
}
|
|
1744
|
-
doTest(`Dim c[5]`);
|
|
1745
|
-
doTest(`Dim c[5, 4]`);
|
|
1746
|
-
doTest(`Dim c[5, 4, 6]`);
|
|
1747
|
-
doTest(`Dim requestData[requestList.count()]`);
|
|
1748
|
-
doTest(`Dim requestData[1, requestList.count()]`);
|
|
1749
|
-
doTest(`Dim requestData[1, requestList.count(), 2]`);
|
|
1750
|
-
doTest(`Dim requestData[requestList[2]]`);
|
|
1751
|
-
doTest(`Dim requestData[1, requestList[2]]`);
|
|
1752
|
-
doTest(`Dim requestData[1, requestList[2], 2]`);
|
|
1753
|
-
doTest(`Dim requestData[requestList["2"]]`);
|
|
1754
|
-
doTest(`Dim requestData[1, requestList["2"]]`);
|
|
1755
|
-
doTest(`Dim requestData[1, requestList["2"], 2]`);
|
|
1756
|
-
doTest(`Dim requestData[1, StrToI("1"), 2]`);
|
|
1757
|
-
testTranspile(`
|
|
1861
|
+
await doTest(`Dim c[5]`);
|
|
1862
|
+
await doTest(`Dim c[5, 4]`);
|
|
1863
|
+
await doTest(`Dim c[5, 4, 6]`);
|
|
1864
|
+
await doTest(`Dim requestData[requestList.count()]`);
|
|
1865
|
+
await doTest(`Dim requestData[1, requestList.count()]`);
|
|
1866
|
+
await doTest(`Dim requestData[1, requestList.count(), 2]`);
|
|
1867
|
+
await doTest(`Dim requestData[requestList[2]]`);
|
|
1868
|
+
await doTest(`Dim requestData[1, requestList[2]]`);
|
|
1869
|
+
await doTest(`Dim requestData[1, requestList[2], 2]`);
|
|
1870
|
+
await doTest(`Dim requestData[requestList["2"]]`);
|
|
1871
|
+
await doTest(`Dim requestData[1, requestList["2"]]`);
|
|
1872
|
+
await doTest(`Dim requestData[1, requestList["2"], 2]`);
|
|
1873
|
+
await doTest(`Dim requestData[1, StrToI("1"), 2]`);
|
|
1874
|
+
await testTranspile(`
|
|
1758
1875
|
function getValue(param1)
|
|
1759
1876
|
end function
|
|
1760
1877
|
|
|
@@ -1766,8 +1883,8 @@ describe('BrsFile', () => {
|
|
|
1766
1883
|
end sub
|
|
1767
1884
|
`);
|
|
1768
1885
|
});
|
|
1769
|
-
it('transpiles calls to fully-qualified namespaced functions', () => {
|
|
1770
|
-
testTranspile(`
|
|
1886
|
+
it('transpiles calls to fully-qualified namespaced functions', async () => {
|
|
1887
|
+
await testTranspile(`
|
|
1771
1888
|
namespace NameA
|
|
1772
1889
|
sub alert()
|
|
1773
1890
|
end sub
|
|
@@ -1792,15 +1909,15 @@ describe('BrsFile', () => {
|
|
|
1792
1909
|
end sub
|
|
1793
1910
|
`, 'trim', 'source/main.bs');
|
|
1794
1911
|
});
|
|
1795
|
-
it('keeps end-of-line comments with their line', () => {
|
|
1796
|
-
testTranspile(`
|
|
1912
|
+
it('keeps end-of-line comments with their line', async () => {
|
|
1913
|
+
await testTranspile(`
|
|
1797
1914
|
function DoSomething() 'comment 1
|
|
1798
1915
|
name = "bob" 'comment 2
|
|
1799
1916
|
end function 'comment 3
|
|
1800
1917
|
`);
|
|
1801
1918
|
});
|
|
1802
|
-
it('works for functions', () => {
|
|
1803
|
-
testTranspile(`
|
|
1919
|
+
it('works for functions', async () => {
|
|
1920
|
+
await testTranspile(`
|
|
1804
1921
|
function DoSomething()
|
|
1805
1922
|
'lots of empty white space
|
|
1806
1923
|
'that will be removed during transpile
|
|
@@ -1815,16 +1932,16 @@ describe('BrsFile', () => {
|
|
|
1815
1932
|
end function
|
|
1816
1933
|
`);
|
|
1817
1934
|
});
|
|
1818
|
-
it('keeps empty AAs and arrays on same line', () => {
|
|
1819
|
-
testTranspile(`
|
|
1935
|
+
it('keeps empty AAs and arrays on same line', async () => {
|
|
1936
|
+
await testTranspile(`
|
|
1820
1937
|
sub a()
|
|
1821
1938
|
person = {}
|
|
1822
1939
|
stuff = []
|
|
1823
1940
|
end sub
|
|
1824
1941
|
`, null, 'trim');
|
|
1825
1942
|
});
|
|
1826
|
-
it('does not add leading or trailing newlines', () => {
|
|
1827
|
-
testTranspile(`function abc()\nend function`, undefined, 'none');
|
|
1943
|
+
it('does not add leading or trailing newlines', async () => {
|
|
1944
|
+
await testTranspile(`function abc()\nend function`, undefined, 'none');
|
|
1828
1945
|
});
|
|
1829
1946
|
it('handles sourcemap edge case', async () => {
|
|
1830
1947
|
let source = 'sub main()\n' +
|
|
@@ -1833,9 +1950,9 @@ describe('BrsFile', () => {
|
|
|
1833
1950
|
'\n' +
|
|
1834
1951
|
'end sub';
|
|
1835
1952
|
program.options.sourceMap = true;
|
|
1836
|
-
let result = testTranspile(source, `sub main()\n print 1\nend sub`, 'none', 'source/main.bs');
|
|
1953
|
+
let result = await testTranspile(source, `sub main()\n print 1\nend sub`, 'none', 'source/main.bs');
|
|
1837
1954
|
//load the source map
|
|
1838
|
-
let location = await source_map_1.SourceMapConsumer.with(result.map
|
|
1955
|
+
let location = await source_map_1.SourceMapConsumer.with(result.map, null, (consumer) => {
|
|
1839
1956
|
return consumer.generatedPositionFor({
|
|
1840
1957
|
line: 3,
|
|
1841
1958
|
column: 0,
|
|
@@ -1852,7 +1969,7 @@ describe('BrsFile', () => {
|
|
|
1852
1969
|
//remove newlines and EOF
|
|
1853
1970
|
.filter(x => x.kind !== TokenKind_1.TokenKind.Eof && x.kind !== TokenKind_1.TokenKind.Newline);
|
|
1854
1971
|
program.options.sourceMap = true;
|
|
1855
|
-
let result = testTranspile(source, source, 'none');
|
|
1972
|
+
let result = await testTranspile(source, source, 'none');
|
|
1856
1973
|
//load the source map
|
|
1857
1974
|
await source_map_1.SourceMapConsumer.with(result.map.toString(), null, (consumer) => {
|
|
1858
1975
|
let tokenResult = tokens.map(token => ({
|
|
@@ -1875,8 +1992,8 @@ describe('BrsFile', () => {
|
|
|
1875
1992
|
(0, chai_config_spec_1.expect)(sourcemapResult).to.eql(tokenResult);
|
|
1876
1993
|
});
|
|
1877
1994
|
});
|
|
1878
|
-
it('handles empty if block', () => {
|
|
1879
|
-
testTranspile(`
|
|
1995
|
+
it('handles empty if block', async () => {
|
|
1996
|
+
await testTranspile(`
|
|
1880
1997
|
sub main()
|
|
1881
1998
|
if true then
|
|
1882
1999
|
end if
|
|
@@ -1897,8 +2014,8 @@ describe('BrsFile', () => {
|
|
|
1897
2014
|
end sub
|
|
1898
2015
|
`);
|
|
1899
2016
|
});
|
|
1900
|
-
it('handles empty elseif block', () => {
|
|
1901
|
-
testTranspile(`
|
|
2017
|
+
it('handles empty elseif block', async () => {
|
|
2018
|
+
await testTranspile(`
|
|
1902
2019
|
sub main()
|
|
1903
2020
|
if true then
|
|
1904
2021
|
print "if"
|
|
@@ -1912,8 +2029,8 @@ describe('BrsFile', () => {
|
|
|
1912
2029
|
end sub
|
|
1913
2030
|
`);
|
|
1914
2031
|
});
|
|
1915
|
-
it('handles empty else block', () => {
|
|
1916
|
-
testTranspile(`
|
|
2032
|
+
it('handles empty else block', async () => {
|
|
2033
|
+
await testTranspile(`
|
|
1917
2034
|
sub main()
|
|
1918
2035
|
if true then
|
|
1919
2036
|
print "if"
|
|
@@ -1928,8 +2045,8 @@ describe('BrsFile', () => {
|
|
|
1928
2045
|
end sub
|
|
1929
2046
|
`);
|
|
1930
2047
|
});
|
|
1931
|
-
it('handles else block with a leading comment', () => {
|
|
1932
|
-
testTranspile(`
|
|
2048
|
+
it('handles else block with a leading comment', async () => {
|
|
2049
|
+
await testTranspile(`
|
|
1933
2050
|
sub main()
|
|
1934
2051
|
if true then
|
|
1935
2052
|
print "if"
|
|
@@ -1940,8 +2057,8 @@ describe('BrsFile', () => {
|
|
|
1940
2057
|
end sub
|
|
1941
2058
|
`);
|
|
1942
2059
|
});
|
|
1943
|
-
it('works for function parameters', () => {
|
|
1944
|
-
testTranspile(`
|
|
2060
|
+
it('works for function parameters', async () => {
|
|
2061
|
+
await testTranspile(`
|
|
1945
2062
|
function DoSomething(name, age as integer, text as string)
|
|
1946
2063
|
end function
|
|
1947
2064
|
`, `
|
|
@@ -1949,8 +2066,8 @@ describe('BrsFile', () => {
|
|
|
1949
2066
|
end function
|
|
1950
2067
|
`);
|
|
1951
2068
|
});
|
|
1952
|
-
it('adds newlines between top-level statements', () => {
|
|
1953
|
-
testTranspile(`
|
|
2069
|
+
it('adds newlines between top-level statements', async () => {
|
|
2070
|
+
await testTranspile(`
|
|
1954
2071
|
function a()
|
|
1955
2072
|
end function
|
|
1956
2073
|
|
|
@@ -1958,8 +2075,8 @@ describe('BrsFile', () => {
|
|
|
1958
2075
|
end function
|
|
1959
2076
|
`);
|
|
1960
2077
|
});
|
|
1961
|
-
it('properly indents nested AA literals', () => {
|
|
1962
|
-
testTranspile(`
|
|
2078
|
+
it('properly indents nested AA literals', async () => {
|
|
2079
|
+
await testTranspile(`
|
|
1963
2080
|
sub doSomething()
|
|
1964
2081
|
grandparent = {
|
|
1965
2082
|
parent: {
|
|
@@ -1973,8 +2090,8 @@ describe('BrsFile', () => {
|
|
|
1973
2090
|
end sub
|
|
1974
2091
|
`);
|
|
1975
2092
|
});
|
|
1976
|
-
it('does not add comma after final object property even when comments are present', () => {
|
|
1977
|
-
testTranspile(`
|
|
2093
|
+
it('does not add comma after final object property even when comments are present', async () => {
|
|
2094
|
+
await testTranspile(`
|
|
1978
2095
|
sub doSomething()
|
|
1979
2096
|
person = {
|
|
1980
2097
|
age: 12 'comment
|
|
@@ -1997,8 +2114,8 @@ describe('BrsFile', () => {
|
|
|
1997
2114
|
end sub
|
|
1998
2115
|
`);
|
|
1999
2116
|
});
|
|
2000
|
-
it('works for a complex function with comments all over the place', () => {
|
|
2001
|
-
testTranspile(`
|
|
2117
|
+
it('works for a complex function with comments all over the place', async () => {
|
|
2118
|
+
await testTranspile(`
|
|
2002
2119
|
'import some library
|
|
2003
2120
|
library "v30/bslCore.brs" 'comment
|
|
2004
2121
|
|
|
@@ -2088,7 +2205,7 @@ describe('BrsFile', () => {
|
|
|
2088
2205
|
sub logInfo()
|
|
2089
2206
|
end sub
|
|
2090
2207
|
`);
|
|
2091
|
-
file
|
|
2208
|
+
file['needsTranspiled'] = false;
|
|
2092
2209
|
const { code } = file.transpile();
|
|
2093
2210
|
(0, chai_config_spec_1.expect)(code.endsWith(`'//# sourceMappingURL=./logger.brs.map`)).to.be.true;
|
|
2094
2211
|
});
|
|
@@ -2097,16 +2214,16 @@ describe('BrsFile', () => {
|
|
|
2097
2214
|
sub logInfo()
|
|
2098
2215
|
end sub
|
|
2099
2216
|
`);
|
|
2100
|
-
file
|
|
2217
|
+
file['needsTranspiled'] = true;
|
|
2101
2218
|
const { code } = file.transpile();
|
|
2102
2219
|
(0, chai_config_spec_1.expect)(code.endsWith(`'//# sourceMappingURL=./logger.brs.map`)).to.be.true;
|
|
2103
2220
|
});
|
|
2104
|
-
it('replaces custom types in parameter types and return types', () => {
|
|
2221
|
+
it('replaces custom types in parameter types and return types', async () => {
|
|
2105
2222
|
program.setFile('source/SomeKlass.bs', `
|
|
2106
2223
|
class SomeKlass
|
|
2107
2224
|
end class
|
|
2108
2225
|
`);
|
|
2109
|
-
testTranspile(`
|
|
2226
|
+
await testTranspile(`
|
|
2110
2227
|
function foo() as SomeKlass
|
|
2111
2228
|
return new SomeKlass()
|
|
2112
2229
|
end function
|
|
@@ -2135,8 +2252,8 @@ describe('BrsFile', () => {
|
|
|
2135
2252
|
program.validate();
|
|
2136
2253
|
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
2137
2254
|
});
|
|
2138
|
-
it('sets invalid on empty callfunc', () => {
|
|
2139
|
-
testTranspile(`
|
|
2255
|
+
it('sets invalid on empty callfunc', async () => {
|
|
2256
|
+
await testTranspile(`
|
|
2140
2257
|
sub main()
|
|
2141
2258
|
node = invalid
|
|
2142
2259
|
node@.doSomething()
|
|
@@ -2152,8 +2269,8 @@ describe('BrsFile', () => {
|
|
|
2152
2269
|
end sub
|
|
2153
2270
|
`);
|
|
2154
2271
|
});
|
|
2155
|
-
it('includes original arguments', () => {
|
|
2156
|
-
testTranspile(`
|
|
2272
|
+
it('includes original arguments', async () => {
|
|
2273
|
+
await testTranspile(`
|
|
2157
2274
|
sub main()
|
|
2158
2275
|
node = invalid
|
|
2159
2276
|
node@.doSomething(1, true, m.top.someVal)
|
|
@@ -2255,8 +2372,8 @@ describe('BrsFile', () => {
|
|
|
2255
2372
|
});
|
|
2256
2373
|
});
|
|
2257
2374
|
describe('typedef', () => {
|
|
2258
|
-
it('includes enum and interface types', () => {
|
|
2259
|
-
testGetTypedef(`
|
|
2375
|
+
it('includes enum and interface types', async () => {
|
|
2376
|
+
await testGetTypedef(`
|
|
2260
2377
|
interface Foo
|
|
2261
2378
|
field as string
|
|
2262
2379
|
end interface
|
|
@@ -2632,8 +2749,8 @@ describe('BrsFile', () => {
|
|
|
2632
2749
|
function plugin() {
|
|
2633
2750
|
return {
|
|
2634
2751
|
name: 'lower-file-name',
|
|
2635
|
-
|
|
2636
|
-
evt.
|
|
2752
|
+
afterProvideFile: (evt) => {
|
|
2753
|
+
evt.files[0]._customProp = true;
|
|
2637
2754
|
}
|
|
2638
2755
|
};
|
|
2639
2756
|
}
|
|
@@ -2641,16 +2758,16 @@ describe('BrsFile', () => {
|
|
|
2641
2758
|
`);
|
|
2642
2759
|
});
|
|
2643
2760
|
it('can load an absolute plugin which receives callbacks', () => {
|
|
2644
|
-
|
|
2645
|
-
(
|
|
2646
|
-
|
|
2761
|
+
for (const plugin of util_1.default.loadPlugins(testHelpers_spec_2.tempDir, [(0, util_1.standardizePath) `${testHelpers_spec_2.tempDir}/plugins/${pluginFileName}`])) {
|
|
2762
|
+
program.plugins.add(plugin);
|
|
2763
|
+
}
|
|
2647
2764
|
const file = program.setFile('source/MAIN.brs', '');
|
|
2648
2765
|
(0, chai_config_spec_1.expect)(file._customProp).to.exist;
|
|
2649
2766
|
});
|
|
2650
2767
|
it('can load a relative plugin which receives callbacks', () => {
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2768
|
+
for (const plugin of util_1.default.loadPlugins(testHelpers_spec_2.tempDir, [`./plugins/${pluginFileName}`])) {
|
|
2769
|
+
program.plugins.add(plugin);
|
|
2770
|
+
}
|
|
2654
2771
|
const file = program.setFile('source/MAIN.brs', '');
|
|
2655
2772
|
(0, chai_config_spec_1.expect)(file._customProp).to.exist;
|
|
2656
2773
|
});
|
|
@@ -2690,6 +2807,74 @@ describe('BrsFile', () => {
|
|
|
2690
2807
|
range: util_1.default.createRange(5, 25, 5, 31)
|
|
2691
2808
|
}]);
|
|
2692
2809
|
});
|
|
2810
|
+
it('returns interface location', () => {
|
|
2811
|
+
const file = program.setFile('source/main.bs', `
|
|
2812
|
+
sub test(selectedMovie as Movie)
|
|
2813
|
+
print selectedMovie
|
|
2814
|
+
end sub
|
|
2815
|
+
interface Movie
|
|
2816
|
+
url as string
|
|
2817
|
+
end interface
|
|
2818
|
+
`);
|
|
2819
|
+
program.validate();
|
|
2820
|
+
// sub test(selectedMovie as Mo|vie)
|
|
2821
|
+
(0, chai_config_spec_1.expect)(program.getDefinition(file.srcPath, vscode_languageserver_1.Position.create(1, 44))).to.eql([{
|
|
2822
|
+
uri: vscode_uri_1.URI.file(file.srcPath).toString(),
|
|
2823
|
+
range: util_1.default.createRange(4, 26, 4, 31)
|
|
2824
|
+
}]);
|
|
2825
|
+
});
|
|
2826
|
+
it('returns namespaced interface location', () => {
|
|
2827
|
+
const file = program.setFile('source/main.bs', `
|
|
2828
|
+
sub test(selectedMovie as interfaces.Movie)
|
|
2829
|
+
print selectedMovie
|
|
2830
|
+
end sub
|
|
2831
|
+
namespace interfaces
|
|
2832
|
+
interface Movie
|
|
2833
|
+
url as string
|
|
2834
|
+
end interface
|
|
2835
|
+
end namespace
|
|
2836
|
+
`);
|
|
2837
|
+
program.validate();
|
|
2838
|
+
//sub test(selectedMovie as interfaces.Mo|vie)
|
|
2839
|
+
(0, chai_config_spec_1.expect)(program.getDefinition(file.srcPath, vscode_languageserver_1.Position.create(1, 55))).to.eql([{
|
|
2840
|
+
uri: vscode_uri_1.URI.file(file.srcPath).toString(),
|
|
2841
|
+
range: util_1.default.createRange(5, 30, 5, 35)
|
|
2842
|
+
}]);
|
|
2843
|
+
});
|
|
2844
|
+
it('returns class location', () => {
|
|
2845
|
+
const file = program.setFile('source/main.bs', `
|
|
2846
|
+
sub test(selectedMovie as Movie)
|
|
2847
|
+
print selectedMovie
|
|
2848
|
+
end sub
|
|
2849
|
+
class Movie
|
|
2850
|
+
url as string
|
|
2851
|
+
end class
|
|
2852
|
+
`);
|
|
2853
|
+
program.validate();
|
|
2854
|
+
//sub test(selectedMovie as Mo|vie)
|
|
2855
|
+
(0, chai_config_spec_1.expect)(program.getDefinition(file.srcPath, vscode_languageserver_1.Position.create(1, 44))).to.eql([{
|
|
2856
|
+
uri: vscode_uri_1.URI.file(file.srcPath).toString(),
|
|
2857
|
+
range: util_1.default.createRange(4, 22, 4, 27)
|
|
2858
|
+
}]);
|
|
2859
|
+
});
|
|
2860
|
+
it('returns namespaced class location', () => {
|
|
2861
|
+
const file = program.setFile('source/main.bs', `
|
|
2862
|
+
sub test(selectedMovie as classes.Movie)
|
|
2863
|
+
print selectedMovie
|
|
2864
|
+
end sub
|
|
2865
|
+
namespace classes
|
|
2866
|
+
class Movie
|
|
2867
|
+
url as string
|
|
2868
|
+
end class
|
|
2869
|
+
end namespace
|
|
2870
|
+
`);
|
|
2871
|
+
program.validate();
|
|
2872
|
+
//sub test(selectedMovie as classes.Mo|vie)
|
|
2873
|
+
(0, chai_config_spec_1.expect)(program.getDefinition(file.srcPath, vscode_languageserver_1.Position.create(1, 52))).to.eql([{
|
|
2874
|
+
uri: vscode_uri_1.URI.file(file.srcPath).toString(),
|
|
2875
|
+
range: util_1.default.createRange(5, 26, 5, 31)
|
|
2876
|
+
}]);
|
|
2877
|
+
});
|
|
2693
2878
|
it('does not crash on nulls', () => {
|
|
2694
2879
|
const file = program.setFile('source/main.bs', `
|
|
2695
2880
|
sub main()
|
|
@@ -2730,5 +2915,787 @@ describe('BrsFile', () => {
|
|
|
2730
2915
|
program.validate();
|
|
2731
2916
|
(0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.mismatchedEndCallableKeyword('function', 'sub')), { range: util_1.default.createRange(2, 12, 2, 19) }), Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.mismatchedEndCallableKeyword('sub', 'function')), { range: util_1.default.createRange(4, 12, 4, 24) })]);
|
|
2732
2917
|
});
|
|
2918
|
+
describe('requiredSymbols', () => {
|
|
2919
|
+
it('should be empty for a simple file', () => {
|
|
2920
|
+
const mainFile = program.setFile('source/main.bs', `
|
|
2921
|
+
function someFunc() as integer
|
|
2922
|
+
return 1
|
|
2923
|
+
end function
|
|
2924
|
+
`);
|
|
2925
|
+
const validateFileEvent = {
|
|
2926
|
+
program: program,
|
|
2927
|
+
file: mainFile
|
|
2928
|
+
};
|
|
2929
|
+
program.plugins.emit('onFileValidate', validateFileEvent);
|
|
2930
|
+
(0, chai_config_spec_1.expect)(mainFile.requiredSymbols.length).to.eq(0);
|
|
2931
|
+
});
|
|
2932
|
+
it('should be empty if the file needs no external symbols', () => {
|
|
2933
|
+
const mainFile = program.setFile('source/main.bs', `
|
|
2934
|
+
function someFunc() as integer
|
|
2935
|
+
return 1
|
|
2936
|
+
end function
|
|
2937
|
+
|
|
2938
|
+
sub useKlass()
|
|
2939
|
+
k = new Klass()
|
|
2940
|
+
k.addTwo()
|
|
2941
|
+
end sub
|
|
2942
|
+
|
|
2943
|
+
class Klass
|
|
2944
|
+
sub addTwo()
|
|
2945
|
+
print someFunc() + someFunc()
|
|
2946
|
+
end sub
|
|
2947
|
+
end class
|
|
2948
|
+
`);
|
|
2949
|
+
const validateFileEvent = {
|
|
2950
|
+
program: program,
|
|
2951
|
+
file: mainFile
|
|
2952
|
+
};
|
|
2953
|
+
program.plugins.emit('onFileValidate', validateFileEvent);
|
|
2954
|
+
(0, chai_config_spec_1.expect)(mainFile.requiredSymbols.length).to.eq(0);
|
|
2955
|
+
});
|
|
2956
|
+
it('should not include global callables or types', () => {
|
|
2957
|
+
const mainFile = program.setFile('source/main.bs', `
|
|
2958
|
+
function printLower(s as string) as integer
|
|
2959
|
+
print lcase(s.trim())
|
|
2960
|
+
end function
|
|
2961
|
+
|
|
2962
|
+
sub setLabelText( label as roSGNodeLabel, text as string)
|
|
2963
|
+
label.text = text
|
|
2964
|
+
end sub
|
|
2965
|
+
`);
|
|
2966
|
+
const validateFileEvent = {
|
|
2967
|
+
program: program,
|
|
2968
|
+
file: mainFile
|
|
2969
|
+
};
|
|
2970
|
+
program.plugins.emit('onFileValidate', validateFileEvent);
|
|
2971
|
+
(0, chai_config_spec_1.expect)(mainFile.requiredSymbols.length).to.eq(0);
|
|
2972
|
+
});
|
|
2973
|
+
it('should include unknown param and return types', () => {
|
|
2974
|
+
const mainFile = program.setFile('source/main.bs', `
|
|
2975
|
+
function someFunc(arg as OneType) as TwoType
|
|
2976
|
+
return arg.getTwo()
|
|
2977
|
+
end function
|
|
2978
|
+
`);
|
|
2979
|
+
const validateFileEvent = {
|
|
2980
|
+
program: program,
|
|
2981
|
+
file: mainFile
|
|
2982
|
+
};
|
|
2983
|
+
program.plugins.emit('onFileValidate', validateFileEvent);
|
|
2984
|
+
(0, chai_config_spec_1.expect)(mainFile.requiredSymbols.length).to.eq(2);
|
|
2985
|
+
(0, chai_config_spec_1.expect)(mainFile.requiredSymbols.map(x => x.typeChain[0].name)).to.have.same.members([
|
|
2986
|
+
'TwoType', 'OneType'
|
|
2987
|
+
]);
|
|
2988
|
+
});
|
|
2989
|
+
it('should include unknown param and return types on class methods', () => {
|
|
2990
|
+
const mainFile = program.setFile('source/main.bs', `
|
|
2991
|
+
class Klass
|
|
2992
|
+
function someFunc(arg as OneType) as TwoType
|
|
2993
|
+
return arg.getTwo()
|
|
2994
|
+
end function
|
|
2995
|
+
end class
|
|
2996
|
+
`);
|
|
2997
|
+
const validateFileEvent = {
|
|
2998
|
+
program: program,
|
|
2999
|
+
file: mainFile
|
|
3000
|
+
};
|
|
3001
|
+
program.plugins.emit('onFileValidate', validateFileEvent);
|
|
3002
|
+
(0, chai_config_spec_1.expect)(mainFile.requiredSymbols.length).to.eq(2);
|
|
3003
|
+
(0, chai_config_spec_1.expect)(mainFile.requiredSymbols.map(x => x.typeChain[0].name)).to.have.same.members([
|
|
3004
|
+
'TwoType', 'OneType'
|
|
3005
|
+
]);
|
|
3006
|
+
});
|
|
3007
|
+
it('should not include assigned symbols', () => {
|
|
3008
|
+
const mainFile = program.setFile('source/main.bs', `
|
|
3009
|
+
sub someFunc(arg as SomeOtherType)
|
|
3010
|
+
x = arg.member
|
|
3011
|
+
print x+1
|
|
3012
|
+
end sub
|
|
3013
|
+
`);
|
|
3014
|
+
const validateFileEvent = {
|
|
3015
|
+
program: program,
|
|
3016
|
+
file: mainFile
|
|
3017
|
+
};
|
|
3018
|
+
program.plugins.emit('onFileValidate', validateFileEvent);
|
|
3019
|
+
(0, chai_config_spec_1.expect)(mainFile.requiredSymbols.length).to.eq(1);
|
|
3020
|
+
// x and arg are assigned.. they are not included in the required symbols
|
|
3021
|
+
(0, chai_config_spec_1.expect)(mainFile.requiredSymbols[0].typeChain[0].name).to.equal('SomeOtherType');
|
|
3022
|
+
});
|
|
3023
|
+
it('should include functions called that are not in the file', () => {
|
|
3024
|
+
const mainFile = program.setFile('source/main.bs', `
|
|
3025
|
+
sub someFunc()
|
|
3026
|
+
x = otherFileFunc1()
|
|
3027
|
+
print x+1
|
|
3028
|
+
end sub
|
|
3029
|
+
|
|
3030
|
+
function deepFunctionCall(i as integer)
|
|
3031
|
+
x = 2*i and otherFileFunc2()
|
|
3032
|
+
y = sin(x+fix(78.2)*log(otherFileFunc3()))
|
|
3033
|
+
' this is a comment otherFileFunc5()
|
|
3034
|
+
return y-otherFileFunc4()
|
|
3035
|
+
end function
|
|
3036
|
+
`);
|
|
3037
|
+
const validateFileEvent = {
|
|
3038
|
+
program: program,
|
|
3039
|
+
file: mainFile
|
|
3040
|
+
};
|
|
3041
|
+
program.plugins.emit('onFileValidate', validateFileEvent);
|
|
3042
|
+
(0, chai_config_spec_1.expect)(mainFile.requiredSymbols.length).to.eq(4);
|
|
3043
|
+
(0, chai_config_spec_1.expect)(mainFile.requiredSymbols.map(x => x.typeChain[0].name)).to.have.same.members([
|
|
3044
|
+
'otherFileFunc1', 'otherFileFunc2', 'otherFileFunc3', 'otherFileFunc4'
|
|
3045
|
+
]);
|
|
3046
|
+
});
|
|
3047
|
+
it('should include classes called that are not in the file', () => {
|
|
3048
|
+
const mainFile = program.setFile('source/main.bs', `
|
|
3049
|
+
function someFunc(other as OtherKlass) as NS1.Thing
|
|
3050
|
+
x = new AnotherClass()
|
|
3051
|
+
return other.getThing(x)
|
|
3052
|
+
end function
|
|
3053
|
+
`);
|
|
3054
|
+
const validateFileEvent = {
|
|
3055
|
+
program: program,
|
|
3056
|
+
file: mainFile
|
|
3057
|
+
};
|
|
3058
|
+
program.plugins.emit('onFileValidate', validateFileEvent);
|
|
3059
|
+
(0, chai_config_spec_1.expect)(mainFile.requiredSymbols.length).to.eq(3);
|
|
3060
|
+
const requiredTypeChains = mainFile.requiredSymbols.map(x => x.typeChain.map(tc => tc.name).join('.'));
|
|
3061
|
+
(0, chai_config_spec_1.expect)(requiredTypeChains).to.have.same.members([
|
|
3062
|
+
'OtherKlass', 'NS1.Thing', 'AnotherClass'
|
|
3063
|
+
]);
|
|
3064
|
+
const requiredSymbolsFlags = mainFile.requiredSymbols.map(x => x.flags);
|
|
3065
|
+
(0, chai_config_spec_1.expect)(requiredSymbolsFlags).to.have.same.members([
|
|
3066
|
+
SymbolTable_1.SymbolTypeFlag.typetime, SymbolTable_1.SymbolTypeFlag.typetime, SymbolTable_1.SymbolTypeFlag.runtime
|
|
3067
|
+
]);
|
|
3068
|
+
});
|
|
3069
|
+
it('should include enums and consts that are not in the file', () => {
|
|
3070
|
+
const mainFile = program.setFile('source/main.bs', `
|
|
3071
|
+
sub someFunc(myEnum as SomeEnum)
|
|
3072
|
+
if myEnum = SomeEnum.value1
|
|
3073
|
+
print 1
|
|
3074
|
+
else if myEnum = SomeEnum.value2
|
|
3075
|
+
print 2
|
|
3076
|
+
else if myEnum = SomeConstValue
|
|
3077
|
+
print 3
|
|
3078
|
+
end if
|
|
3079
|
+
end sub
|
|
3080
|
+
`);
|
|
3081
|
+
const validateFileEvent = {
|
|
3082
|
+
program: program,
|
|
3083
|
+
file: mainFile
|
|
3084
|
+
};
|
|
3085
|
+
program.plugins.emit('onFileValidate', validateFileEvent);
|
|
3086
|
+
(0, chai_config_spec_1.expect)(mainFile.requiredSymbols.length).to.eq(4);
|
|
3087
|
+
const requiredTypeChains = mainFile.requiredSymbols.map(x => x.typeChain.map(tc => tc.name).join('.'));
|
|
3088
|
+
(0, chai_config_spec_1.expect)(requiredTypeChains).to.have.same.members([
|
|
3089
|
+
'SomeEnum', 'SomeEnum.value1', 'SomeEnum.value2', 'SomeConstValue'
|
|
3090
|
+
]);
|
|
3091
|
+
const requiredSymbolsFlags = mainFile.requiredSymbols.map(x => x.flags);
|
|
3092
|
+
(0, chai_config_spec_1.expect)(requiredSymbolsFlags).to.have.same.members([
|
|
3093
|
+
SymbolTable_1.SymbolTypeFlag.typetime, SymbolTable_1.SymbolTypeFlag.runtime, SymbolTable_1.SymbolTypeFlag.runtime, SymbolTable_1.SymbolTypeFlag.runtime
|
|
3094
|
+
]);
|
|
3095
|
+
});
|
|
3096
|
+
it('should include types not defined in the file', () => {
|
|
3097
|
+
const mainFile = program.setFile('source/main.bs', `
|
|
3098
|
+
interface Data
|
|
3099
|
+
kind as DataKind
|
|
3100
|
+
getObj as DataObject
|
|
3101
|
+
subData as SubData
|
|
3102
|
+
end interface
|
|
3103
|
+
|
|
3104
|
+
class DataObject extends BaseData
|
|
3105
|
+
kind as DataKind
|
|
3106
|
+
function process(dataProcess as DataProcessor) as ProcessedData
|
|
3107
|
+
return dataProcess.work(m)
|
|
3108
|
+
end function
|
|
3109
|
+
end class
|
|
3110
|
+
`);
|
|
3111
|
+
const validateFileEvent = {
|
|
3112
|
+
program: program,
|
|
3113
|
+
file: mainFile
|
|
3114
|
+
};
|
|
3115
|
+
program.plugins.emit('onFileValidate', validateFileEvent);
|
|
3116
|
+
(0, chai_config_spec_1.expect)(mainFile.requiredSymbols.length).to.eq(5);
|
|
3117
|
+
const requiredTypeChains = mainFile.requiredSymbols.map(x => x.typeChain.map(tc => tc.name).join('.'));
|
|
3118
|
+
(0, chai_config_spec_1.expect)(requiredTypeChains).to.have.same.members([
|
|
3119
|
+
'DataKind', 'SubData', 'BaseData', 'DataProcessor', 'ProcessedData'
|
|
3120
|
+
]);
|
|
3121
|
+
const requiredSymbolsFlags = mainFile.requiredSymbols.map(x => x.flags);
|
|
3122
|
+
(0, chai_config_spec_1.expect)(requiredSymbolsFlags).to.have.same.members([
|
|
3123
|
+
SymbolTable_1.SymbolTypeFlag.typetime, SymbolTable_1.SymbolTypeFlag.typetime, SymbolTable_1.SymbolTypeFlag.typetime, SymbolTable_1.SymbolTypeFlag.typetime, SymbolTable_1.SymbolTypeFlag.typetime
|
|
3124
|
+
]);
|
|
3125
|
+
});
|
|
3126
|
+
it('includes namespace details', () => {
|
|
3127
|
+
const mainFile = program.setFile('source/main.bs', `
|
|
3128
|
+
namespace Alpha.Beta
|
|
3129
|
+
sub printConstVal()
|
|
3130
|
+
print CONST_VALUE
|
|
3131
|
+
end sub
|
|
3132
|
+
end namespace
|
|
3133
|
+
|
|
3134
|
+
namespace Delta
|
|
3135
|
+
namespace Gamma
|
|
3136
|
+
namespace Eta
|
|
3137
|
+
sub doStuff(x as OtherType)
|
|
3138
|
+
x.something()
|
|
3139
|
+
end sub
|
|
3140
|
+
end namespace
|
|
3141
|
+
end namespace
|
|
3142
|
+
end namespace
|
|
3143
|
+
`);
|
|
3144
|
+
const validateFileEvent = {
|
|
3145
|
+
program: program,
|
|
3146
|
+
file: mainFile
|
|
3147
|
+
};
|
|
3148
|
+
program.plugins.emit('onFileValidate', validateFileEvent);
|
|
3149
|
+
(0, chai_config_spec_1.expect)(mainFile.requiredSymbols.length).to.eq(2);
|
|
3150
|
+
const requiredTypeChains = mainFile.requiredSymbols.map(x => x.typeChain.map(tc => tc.name).join('.'));
|
|
3151
|
+
(0, chai_config_spec_1.expect)(requiredTypeChains).to.have.same.members([
|
|
3152
|
+
'CONST_VALUE', 'OtherType'
|
|
3153
|
+
]);
|
|
3154
|
+
(0, chai_config_spec_1.expect)(mainFile.requiredSymbols[0].containingNamespaces).to.have.same.members(['Alpha', 'Beta']);
|
|
3155
|
+
(0, chai_config_spec_1.expect)(mainFile.requiredSymbols[1].containingNamespaces).to.have.same.members(['Delta', 'Gamma', 'Eta']);
|
|
3156
|
+
});
|
|
3157
|
+
it('does not include namespaces that are defined in the file', () => {
|
|
3158
|
+
const mainFile = program.setFile('source/main.bs', `
|
|
3159
|
+
namespace name1
|
|
3160
|
+
const PI = 3.14
|
|
3161
|
+
|
|
3162
|
+
namespace name2
|
|
3163
|
+
function getPi() as float
|
|
3164
|
+
return name1.PI
|
|
3165
|
+
end function
|
|
3166
|
+
end namespace
|
|
3167
|
+
end namespace
|
|
3168
|
+
`);
|
|
3169
|
+
program.plugins.emit('onFileValidate', { program: program, file: mainFile });
|
|
3170
|
+
(0, chai_config_spec_1.expect)(mainFile.requiredSymbols.length).to.eq(0);
|
|
3171
|
+
});
|
|
3172
|
+
it('should put types from typecasts as typetime required', () => {
|
|
3173
|
+
const mainFile = program.setFile('source/main.bs', `
|
|
3174
|
+
function takesIface(z) as string
|
|
3175
|
+
return (z as MyInterface).name
|
|
3176
|
+
end function
|
|
3177
|
+
`);
|
|
3178
|
+
program.plugins.emit('onFileValidate', { program: program, file: mainFile });
|
|
3179
|
+
(0, chai_config_spec_1.expect)(mainFile.requiredSymbols.length).to.eq(1);
|
|
3180
|
+
(0, chai_config_spec_1.expect)(mainFile.requiredSymbols[0].flags).to.eq(SymbolTable_1.SymbolTypeFlag.typetime);
|
|
3181
|
+
});
|
|
3182
|
+
});
|
|
3183
|
+
describe('providedSymbols', () => {
|
|
3184
|
+
it('includes functions defined in the file', () => {
|
|
3185
|
+
const mainFile = program.setFile('source/main.bs', `
|
|
3186
|
+
function someFunc() as integer
|
|
3187
|
+
return 1
|
|
3188
|
+
end function
|
|
3189
|
+
|
|
3190
|
+
function someFunc2() as float
|
|
3191
|
+
return 2.3
|
|
3192
|
+
end function
|
|
3193
|
+
`);
|
|
3194
|
+
const validateFileEvent = {
|
|
3195
|
+
program: program,
|
|
3196
|
+
file: mainFile
|
|
3197
|
+
};
|
|
3198
|
+
program.plugins.emit('onFileValidate', validateFileEvent);
|
|
3199
|
+
const runtimeSymbols = mainFile.providedSymbols.symbolMap.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3200
|
+
(0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(2);
|
|
3201
|
+
const someFuncType = runtimeSymbols.get('somefunc').type;
|
|
3202
|
+
(0, testHelpers_spec_1.expectTypeToBe)(someFuncType, TypedFunctionType_1.TypedFunctionType);
|
|
3203
|
+
const someFunc2Type = runtimeSymbols.get('somefunc2').type;
|
|
3204
|
+
(0, testHelpers_spec_1.expectTypeToBe)(someFunc2Type, TypedFunctionType_1.TypedFunctionType);
|
|
3205
|
+
});
|
|
3206
|
+
it('includes functions with unresolved params/return types', () => {
|
|
3207
|
+
const mainFile = program.setFile('source/main.bs', `
|
|
3208
|
+
function someFunc() as OtherFileType
|
|
3209
|
+
return new OtherFileType()
|
|
3210
|
+
end function
|
|
3211
|
+
`);
|
|
3212
|
+
const validateFileEvent = {
|
|
3213
|
+
program: program,
|
|
3214
|
+
file: mainFile
|
|
3215
|
+
};
|
|
3216
|
+
program.plugins.emit('onFileValidate', validateFileEvent);
|
|
3217
|
+
const runtimeSymbols = mainFile.providedSymbols.symbolMap.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3218
|
+
(0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(1);
|
|
3219
|
+
const someFuncType = runtimeSymbols.get('somefunc').type;
|
|
3220
|
+
(0, testHelpers_spec_1.expectTypeToBe)(someFuncType, TypedFunctionType_1.TypedFunctionType);
|
|
3221
|
+
const requiredSymbols = mainFile.requiredSymbols.map(x => x.typeChain[0].name);
|
|
3222
|
+
(0, chai_config_spec_1.expect)(requiredSymbols).to.have.same.members(['OtherFileType', 'OtherFileType']);
|
|
3223
|
+
const requiredSymbolTypes = mainFile.requiredSymbols.map(x => x.flags);
|
|
3224
|
+
(0, chai_config_spec_1.expect)(requiredSymbolTypes).to.have.same.members([SymbolTable_1.SymbolTypeFlag.runtime, SymbolTable_1.SymbolTypeFlag.typetime]);
|
|
3225
|
+
});
|
|
3226
|
+
it('includes classes defined in the file', () => {
|
|
3227
|
+
const mainFile = program.setFile('source/main.bs', `
|
|
3228
|
+
class Klass
|
|
3229
|
+
name as string
|
|
3230
|
+
end class
|
|
3231
|
+
|
|
3232
|
+
class Klass2 extends Klass
|
|
3233
|
+
age as integer
|
|
3234
|
+
|
|
3235
|
+
function getId() as string
|
|
3236
|
+
return m.name + " " + m.age.toStr()
|
|
3237
|
+
end function
|
|
3238
|
+
end class
|
|
3239
|
+
|
|
3240
|
+
class Klass3
|
|
3241
|
+
propClass = new Klass2()
|
|
3242
|
+
end class
|
|
3243
|
+
`);
|
|
3244
|
+
const validateFileEvent = {
|
|
3245
|
+
program: program,
|
|
3246
|
+
file: mainFile
|
|
3247
|
+
};
|
|
3248
|
+
program.plugins.emit('onFileValidate', validateFileEvent);
|
|
3249
|
+
const runtimeSymbols = mainFile.providedSymbols.symbolMap.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3250
|
+
(0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(3);
|
|
3251
|
+
(0, testHelpers_spec_1.expectTypeToBe)(runtimeSymbols.get('klass').type, types_1.ClassType);
|
|
3252
|
+
(0, testHelpers_spec_1.expectTypeToBe)(runtimeSymbols.get('klass2').type, types_1.ClassType);
|
|
3253
|
+
(0, testHelpers_spec_1.expectTypeToBe)(runtimeSymbols.get('klass3').type, types_1.ClassType);
|
|
3254
|
+
const typetimeSymbols = mainFile.providedSymbols.symbolMap.get(SymbolTable_1.SymbolTypeFlag.typetime);
|
|
3255
|
+
(0, chai_config_spec_1.expect)(typetimeSymbols.size).to.eq(3);
|
|
3256
|
+
(0, testHelpers_spec_1.expectTypeToBe)(runtimeSymbols.get('klass').type, types_1.ClassType);
|
|
3257
|
+
(0, testHelpers_spec_1.expectTypeToBe)(runtimeSymbols.get('klass2').type, types_1.ClassType);
|
|
3258
|
+
(0, testHelpers_spec_1.expectTypeToBe)(runtimeSymbols.get('klass3').type, types_1.ClassType);
|
|
3259
|
+
});
|
|
3260
|
+
it('includes other types defined in the file', () => {
|
|
3261
|
+
const mainFile = program.setFile('source/main.bs', `
|
|
3262
|
+
interface MyInterface
|
|
3263
|
+
name as string
|
|
3264
|
+
end interface
|
|
3265
|
+
|
|
3266
|
+
enum MyEnum
|
|
3267
|
+
val1
|
|
3268
|
+
val2
|
|
3269
|
+
end enum
|
|
3270
|
+
|
|
3271
|
+
namespace MyNamespace
|
|
3272
|
+
const MyConst = 3.14
|
|
3273
|
+
end namespace
|
|
3274
|
+
`);
|
|
3275
|
+
const validateFileEvent = {
|
|
3276
|
+
program: program,
|
|
3277
|
+
file: mainFile
|
|
3278
|
+
};
|
|
3279
|
+
program.plugins.emit('onFileValidate', validateFileEvent);
|
|
3280
|
+
const runtimeSymbols = mainFile.providedSymbols.symbolMap.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3281
|
+
(0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(2);
|
|
3282
|
+
(0, testHelpers_spec_1.expectTypeToBe)(runtimeSymbols.get('myenum').type, types_1.EnumType);
|
|
3283
|
+
(0, testHelpers_spec_1.expectTypeToBe)(runtimeSymbols.get('mynamespace.myconst').type, types_1.FloatType);
|
|
3284
|
+
const typetimeSymbols = mainFile.providedSymbols.symbolMap.get(SymbolTable_1.SymbolTypeFlag.typetime);
|
|
3285
|
+
(0, chai_config_spec_1.expect)(typetimeSymbols.size).to.eq(2);
|
|
3286
|
+
(0, testHelpers_spec_1.expectTypeToBe)(typetimeSymbols.get('myinterface').type, types_1.InterfaceType);
|
|
3287
|
+
(0, testHelpers_spec_1.expectTypeToBe)(runtimeSymbols.get('myenum').type, types_1.EnumType);
|
|
3288
|
+
});
|
|
3289
|
+
describe('changes', () => {
|
|
3290
|
+
it('new symbols are added to the changes set', () => {
|
|
3291
|
+
let mainFile = program.setFile('source/main.bs', `
|
|
3292
|
+
sub someFunc()
|
|
3293
|
+
print 1
|
|
3294
|
+
end sub
|
|
3295
|
+
`);
|
|
3296
|
+
program.plugins.emit('onFileValidate', { program: program, file: mainFile });
|
|
3297
|
+
let runtimeSymbols = mainFile.providedSymbols.symbolMap.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3298
|
+
(0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(1);
|
|
3299
|
+
mainFile = program.setFile('source/main.bs', `
|
|
3300
|
+
sub someFunc()
|
|
3301
|
+
print 1
|
|
3302
|
+
end sub
|
|
3303
|
+
|
|
3304
|
+
sub someFunc2()
|
|
3305
|
+
print 2
|
|
3306
|
+
end sub
|
|
3307
|
+
`);
|
|
3308
|
+
program.plugins.emit('onFileValidate', { program: program, file: mainFile });
|
|
3309
|
+
runtimeSymbols = mainFile.providedSymbols.symbolMap.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3310
|
+
(0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(2);
|
|
3311
|
+
let runtimeChanges = mainFile.providedSymbols.changes.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3312
|
+
(0, chai_config_spec_1.expect)(runtimeChanges.size).to.eq(1);
|
|
3313
|
+
(0, chai_config_spec_1.expect)(runtimeChanges.has('somefunc2')).to.be.true;
|
|
3314
|
+
});
|
|
3315
|
+
it('removed symbols are added to the changes set', () => {
|
|
3316
|
+
let mainFile = program.setFile('source/main.bs', `
|
|
3317
|
+
sub someFunc()
|
|
3318
|
+
print 1
|
|
3319
|
+
end sub
|
|
3320
|
+
|
|
3321
|
+
sub someFunc2()
|
|
3322
|
+
print 2
|
|
3323
|
+
end sub
|
|
3324
|
+
`);
|
|
3325
|
+
program.plugins.emit('onFileValidate', { program: program, file: mainFile });
|
|
3326
|
+
let runtimeSymbols = mainFile.providedSymbols.symbolMap.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3327
|
+
(0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(2);
|
|
3328
|
+
mainFile = program.setFile('source/main.bs', `
|
|
3329
|
+
sub someFunc()
|
|
3330
|
+
print 1
|
|
3331
|
+
end sub
|
|
3332
|
+
`);
|
|
3333
|
+
program.plugins.emit('onFileValidate', { program: program, file: mainFile });
|
|
3334
|
+
runtimeSymbols = mainFile.providedSymbols.symbolMap.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3335
|
+
(0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(1);
|
|
3336
|
+
let runtimeChanges = mainFile.providedSymbols.changes.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3337
|
+
(0, chai_config_spec_1.expect)(runtimeChanges.size).to.eq(1);
|
|
3338
|
+
(0, chai_config_spec_1.expect)(runtimeChanges.has('somefunc2')).to.be.true;
|
|
3339
|
+
});
|
|
3340
|
+
it('new symbols in a namespace are added to the changes set', () => {
|
|
3341
|
+
let mainFile = program.setFile('source/main.bs', `
|
|
3342
|
+
namespace Alpha
|
|
3343
|
+
end namespace
|
|
3344
|
+
`);
|
|
3345
|
+
program.plugins.emit('onFileValidate', { program: program, file: mainFile });
|
|
3346
|
+
let runtimeSymbols = mainFile.providedSymbols.symbolMap.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3347
|
+
(0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(0);
|
|
3348
|
+
mainFile = program.setFile('source/main.bs', `
|
|
3349
|
+
namespace Alpha
|
|
3350
|
+
const ABC = "abc"
|
|
3351
|
+
end namespace
|
|
3352
|
+
`);
|
|
3353
|
+
program.plugins.emit('onFileValidate', { program: program, file: mainFile });
|
|
3354
|
+
runtimeSymbols = mainFile.providedSymbols.symbolMap.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3355
|
+
(0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(1);
|
|
3356
|
+
let runtimeChanges = mainFile.providedSymbols.changes.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3357
|
+
(0, chai_config_spec_1.expect)(runtimeChanges.size).to.eq(1);
|
|
3358
|
+
(0, chai_config_spec_1.expect)(runtimeChanges.has('alpha.abc')).to.be.true;
|
|
3359
|
+
});
|
|
3360
|
+
it('should be empty if no changes in actual provided symbols', () => {
|
|
3361
|
+
let mainFile = program.setFile('source/main.bs', `
|
|
3362
|
+
sub printSomething()
|
|
3363
|
+
print "Something"
|
|
3364
|
+
end sub
|
|
3365
|
+
|
|
3366
|
+
namespace alpha.beta
|
|
3367
|
+
const PI = 3.14
|
|
3368
|
+
end namespace
|
|
3369
|
+
`);
|
|
3370
|
+
program.plugins.emit('onFileValidate', { program: program, file: mainFile });
|
|
3371
|
+
let runtimeSymbols = mainFile.providedSymbols.symbolMap.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3372
|
+
(0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(2);
|
|
3373
|
+
mainFile = program.setFile('source/main.bs', `
|
|
3374
|
+
sub printSomething()
|
|
3375
|
+
print "Something Else"
|
|
3376
|
+
end sub
|
|
3377
|
+
|
|
3378
|
+
namespace alpha.beta
|
|
3379
|
+
const PI = 3.14159
|
|
3380
|
+
end namespace
|
|
3381
|
+
`);
|
|
3382
|
+
program.plugins.emit('onFileValidate', { program: program, file: mainFile });
|
|
3383
|
+
runtimeSymbols = mainFile.providedSymbols.symbolMap.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3384
|
+
(0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(2);
|
|
3385
|
+
let runtimeChanges = mainFile.providedSymbols.changes.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3386
|
+
(0, chai_config_spec_1.expect)(runtimeChanges.size).to.eq(0);
|
|
3387
|
+
});
|
|
3388
|
+
it('should include changes in function signatures', () => {
|
|
3389
|
+
let mainFile = program.setFile('source/main.bs', `
|
|
3390
|
+
function someFunc(x)
|
|
3391
|
+
return x
|
|
3392
|
+
end function
|
|
3393
|
+
`);
|
|
3394
|
+
program.plugins.emit('onFileValidate', { program: program, file: mainFile });
|
|
3395
|
+
let runtimeSymbols = mainFile.providedSymbols.symbolMap.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3396
|
+
(0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(1);
|
|
3397
|
+
mainFile = program.setFile('source/main.bs', `
|
|
3398
|
+
function someFunc(x, y)
|
|
3399
|
+
return x+y
|
|
3400
|
+
end function
|
|
3401
|
+
`);
|
|
3402
|
+
program.plugins.emit('onFileValidate', { program: program, file: mainFile });
|
|
3403
|
+
runtimeSymbols = mainFile.providedSymbols.symbolMap.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3404
|
+
(0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(1);
|
|
3405
|
+
let runtimeChanges = mainFile.providedSymbols.changes.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3406
|
+
(0, chai_config_spec_1.expect)(runtimeChanges.size).to.eq(1);
|
|
3407
|
+
(0, chai_config_spec_1.expect)(runtimeChanges.has('somefunc'));
|
|
3408
|
+
});
|
|
3409
|
+
it('should include changes in classes', () => {
|
|
3410
|
+
let mainFile = program.setFile('source/main.bs', `
|
|
3411
|
+
class MyKlass
|
|
3412
|
+
name as string
|
|
3413
|
+
function getValue() as float
|
|
3414
|
+
return 3.14
|
|
3415
|
+
end function
|
|
3416
|
+
end class
|
|
3417
|
+
`);
|
|
3418
|
+
program.plugins.emit('onFileValidate', { program: program, file: mainFile });
|
|
3419
|
+
let runtimeSymbols = mainFile.providedSymbols.symbolMap.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3420
|
+
(0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(1);
|
|
3421
|
+
mainFile = program.setFile('source/main.bs', `
|
|
3422
|
+
class MyKlass
|
|
3423
|
+
name as string
|
|
3424
|
+
function getValue() as string
|
|
3425
|
+
return "hello"
|
|
3426
|
+
end function
|
|
3427
|
+
end class
|
|
3428
|
+
`);
|
|
3429
|
+
program.plugins.emit('onFileValidate', { program: program, file: mainFile });
|
|
3430
|
+
runtimeSymbols = mainFile.providedSymbols.symbolMap.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3431
|
+
(0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(1);
|
|
3432
|
+
let runtimeChanges = mainFile.providedSymbols.changes.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3433
|
+
(0, chai_config_spec_1.expect)(runtimeChanges.size).to.eq(1);
|
|
3434
|
+
(0, chai_config_spec_1.expect)(runtimeChanges.has('myklass'));
|
|
3435
|
+
let typeTimeChanges = mainFile.providedSymbols.changes.get(SymbolTable_1.SymbolTypeFlag.typetime);
|
|
3436
|
+
(0, chai_config_spec_1.expect)(typeTimeChanges.size).to.eq(1);
|
|
3437
|
+
(0, chai_config_spec_1.expect)(typeTimeChanges.has('myklass'));
|
|
3438
|
+
});
|
|
3439
|
+
it('should include changes in interfaces', () => {
|
|
3440
|
+
let mainFile = program.setFile('source/main.bs', `
|
|
3441
|
+
interface Iface1
|
|
3442
|
+
name as string
|
|
3443
|
+
function doStuff() as float
|
|
3444
|
+
end interface
|
|
3445
|
+
`);
|
|
3446
|
+
program.plugins.emit('onFileValidate', { program: program, file: mainFile });
|
|
3447
|
+
let typetimeSymbols = mainFile.providedSymbols.symbolMap.get(SymbolTable_1.SymbolTypeFlag.typetime);
|
|
3448
|
+
(0, chai_config_spec_1.expect)(typetimeSymbols.size).to.eq(1);
|
|
3449
|
+
let runtimeSymbols = mainFile.providedSymbols.symbolMap.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3450
|
+
(0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(0);
|
|
3451
|
+
mainFile = program.setFile('source/main.bs', `
|
|
3452
|
+
interface Iface1
|
|
3453
|
+
name as string
|
|
3454
|
+
age as integer
|
|
3455
|
+
function doStuff() as float
|
|
3456
|
+
end interface
|
|
3457
|
+
`);
|
|
3458
|
+
program.plugins.emit('onFileValidate', { program: program, file: mainFile });
|
|
3459
|
+
typetimeSymbols = mainFile.providedSymbols.symbolMap.get(SymbolTable_1.SymbolTypeFlag.typetime);
|
|
3460
|
+
(0, chai_config_spec_1.expect)(typetimeSymbols.size).to.eq(1);
|
|
3461
|
+
let typeTimeChanges = mainFile.providedSymbols.changes.get(SymbolTable_1.SymbolTypeFlag.typetime);
|
|
3462
|
+
(0, chai_config_spec_1.expect)(typeTimeChanges.size).to.eq(1);
|
|
3463
|
+
(0, chai_config_spec_1.expect)(typeTimeChanges.has('iface1'));
|
|
3464
|
+
let runtimeChanges = mainFile.providedSymbols.changes.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3465
|
+
(0, chai_config_spec_1.expect)(runtimeChanges.size).to.eq(0);
|
|
3466
|
+
});
|
|
3467
|
+
it('should not include changes in enum values, if inner type is the same', () => {
|
|
3468
|
+
let mainFile = program.setFile('source/main.bs', `
|
|
3469
|
+
enum MyEnum
|
|
3470
|
+
north = 4
|
|
3471
|
+
east = 3
|
|
3472
|
+
south = 2
|
|
3473
|
+
west = 1
|
|
3474
|
+
end enum
|
|
3475
|
+
`);
|
|
3476
|
+
program.plugins.emit('onFileValidate', { program: program, file: mainFile });
|
|
3477
|
+
let runtimeSymbols = mainFile.providedSymbols.symbolMap.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3478
|
+
(0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(1);
|
|
3479
|
+
mainFile = program.setFile('source/main.bs', `
|
|
3480
|
+
enum MyEnum
|
|
3481
|
+
north = 1
|
|
3482
|
+
east = 2
|
|
3483
|
+
south = 3
|
|
3484
|
+
west = 4
|
|
3485
|
+
end enum
|
|
3486
|
+
`);
|
|
3487
|
+
program.plugins.emit('onFileValidate', { program: program, file: mainFile });
|
|
3488
|
+
runtimeSymbols = mainFile.providedSymbols.symbolMap.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3489
|
+
(0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(1);
|
|
3490
|
+
let runtimeChanges = mainFile.providedSymbols.changes.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3491
|
+
(0, chai_config_spec_1.expect)(runtimeChanges.size).to.eq(0);
|
|
3492
|
+
let typetimeSymbols = mainFile.providedSymbols.symbolMap.get(SymbolTable_1.SymbolTypeFlag.typetime);
|
|
3493
|
+
(0, chai_config_spec_1.expect)(typetimeSymbols.size).to.eq(1);
|
|
3494
|
+
let typetimeChanges = mainFile.providedSymbols.changes.get(SymbolTable_1.SymbolTypeFlag.typetime);
|
|
3495
|
+
(0, chai_config_spec_1.expect)(typetimeChanges.size).to.eq(0);
|
|
3496
|
+
});
|
|
3497
|
+
it('should include changes in enum, if different number of members', () => {
|
|
3498
|
+
let mainFile = program.setFile('source/main.bs', `
|
|
3499
|
+
enum Direction
|
|
3500
|
+
north = 1
|
|
3501
|
+
east = 2
|
|
3502
|
+
south = 3
|
|
3503
|
+
west = 4
|
|
3504
|
+
end enum
|
|
3505
|
+
|
|
3506
|
+
enum Weather
|
|
3507
|
+
rainy
|
|
3508
|
+
sunny
|
|
3509
|
+
end enum
|
|
3510
|
+
|
|
3511
|
+
enum Colors
|
|
3512
|
+
blue
|
|
3513
|
+
red
|
|
3514
|
+
green
|
|
3515
|
+
purple
|
|
3516
|
+
end enum
|
|
3517
|
+
`);
|
|
3518
|
+
program.plugins.emit('onFileValidate', { program: program, file: mainFile });
|
|
3519
|
+
let runtimeSymbols = mainFile.providedSymbols.symbolMap.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3520
|
+
(0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(3);
|
|
3521
|
+
mainFile = program.setFile('source/main.bs', `
|
|
3522
|
+
enum Direction ' same
|
|
3523
|
+
north = 1
|
|
3524
|
+
east = 2
|
|
3525
|
+
south = 3
|
|
3526
|
+
west = 4
|
|
3527
|
+
end enum
|
|
3528
|
+
|
|
3529
|
+
enum Weather 'added member
|
|
3530
|
+
rainy
|
|
3531
|
+
sunny
|
|
3532
|
+
snowy
|
|
3533
|
+
end enum
|
|
3534
|
+
|
|
3535
|
+
enum Colors 'removed member
|
|
3536
|
+
blue
|
|
3537
|
+
red
|
|
3538
|
+
green
|
|
3539
|
+
end enum
|
|
3540
|
+
`);
|
|
3541
|
+
program.plugins.emit('onFileValidate', { program: program, file: mainFile });
|
|
3542
|
+
runtimeSymbols = mainFile.providedSymbols.symbolMap.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3543
|
+
(0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(3);
|
|
3544
|
+
let runtimeChanges = mainFile.providedSymbols.changes.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3545
|
+
(0, chai_config_spec_1.expect)(runtimeChanges.size).to.eq(2);
|
|
3546
|
+
(0, chai_config_spec_1.expect)(runtimeChanges.has('weather'));
|
|
3547
|
+
(0, chai_config_spec_1.expect)(runtimeChanges.has('colors'));
|
|
3548
|
+
});
|
|
3549
|
+
it('should include changes in enum, if different underlying type', () => {
|
|
3550
|
+
let mainFile = program.setFile('source/main.bs', `
|
|
3551
|
+
enum Direction
|
|
3552
|
+
north = 1
|
|
3553
|
+
east = 2
|
|
3554
|
+
south = 3
|
|
3555
|
+
west = 4
|
|
3556
|
+
end enum
|
|
3557
|
+
`);
|
|
3558
|
+
program.plugins.emit('onFileValidate', { program: program, file: mainFile });
|
|
3559
|
+
let runtimeSymbols = mainFile.providedSymbols.symbolMap.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3560
|
+
(0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(1);
|
|
3561
|
+
mainFile = program.setFile('source/main.bs', `
|
|
3562
|
+
enum Direction ' now is a string
|
|
3563
|
+
north = "N"
|
|
3564
|
+
east = "E"
|
|
3565
|
+
south = "S"
|
|
3566
|
+
west = "W"
|
|
3567
|
+
end enum
|
|
3568
|
+
`);
|
|
3569
|
+
program.plugins.emit('onFileValidate', { program: program, file: mainFile });
|
|
3570
|
+
runtimeSymbols = mainFile.providedSymbols.symbolMap.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3571
|
+
(0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(1);
|
|
3572
|
+
let runtimeChanges = mainFile.providedSymbols.changes.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3573
|
+
(0, chai_config_spec_1.expect)(runtimeChanges.size).to.eq(1);
|
|
3574
|
+
(0, chai_config_spec_1.expect)(runtimeChanges.has('direction'));
|
|
3575
|
+
});
|
|
3576
|
+
it('should include changes in const, if different underlying type', () => {
|
|
3577
|
+
let mainFile = program.setFile('source/main.bs', `
|
|
3578
|
+
namespace alpha.beta
|
|
3579
|
+
const PI = 3.14
|
|
3580
|
+
end namespace
|
|
3581
|
+
`);
|
|
3582
|
+
program.plugins.emit('onFileValidate', { program: program, file: mainFile });
|
|
3583
|
+
let runtimeSymbols = mainFile.providedSymbols.symbolMap.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3584
|
+
(0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(1);
|
|
3585
|
+
mainFile = program.setFile('source/main.bs', `
|
|
3586
|
+
namespace alpha.beta
|
|
3587
|
+
const PI = "lemon chiffon"
|
|
3588
|
+
end namespace
|
|
3589
|
+
`);
|
|
3590
|
+
program.plugins.emit('onFileValidate', { program: program, file: mainFile });
|
|
3591
|
+
runtimeSymbols = mainFile.providedSymbols.symbolMap.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3592
|
+
(0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(1);
|
|
3593
|
+
let runtimeChanges = mainFile.providedSymbols.changes.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3594
|
+
(0, chai_config_spec_1.expect)(runtimeChanges.size).to.eq(1);
|
|
3595
|
+
(0, chai_config_spec_1.expect)(runtimeChanges.has('alpha.beta.pi'));
|
|
3596
|
+
});
|
|
3597
|
+
it('should not include changes inside a function if the param types are known', () => {
|
|
3598
|
+
let mainFile = program.setFile('source/main.bs', `
|
|
3599
|
+
function func1(p as string) as integer
|
|
3600
|
+
return len(p)
|
|
3601
|
+
end function
|
|
3602
|
+
|
|
3603
|
+
sub displayModelTypeInLabel(myLabel as roSgNodeLabel)
|
|
3604
|
+
print myLabel.text
|
|
3605
|
+
di = createObject("roDeviceInfo")' as roDeviceInfo
|
|
3606
|
+
myLabel.text = di.GetFriendlyName()
|
|
3607
|
+
print myLabel.getChildren(0, -1)
|
|
3608
|
+
end sub
|
|
3609
|
+
`);
|
|
3610
|
+
program.plugins.emit('onFileValidate', { program: program, file: mainFile });
|
|
3611
|
+
let runtimeSymbols = mainFile.providedSymbols.symbolMap.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3612
|
+
(0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(2);
|
|
3613
|
+
mainFile = program.setFile('source/main.bs', `
|
|
3614
|
+
function func1(p as string) as integer
|
|
3615
|
+
return len(p)+1
|
|
3616
|
+
end function
|
|
3617
|
+
|
|
3618
|
+
sub displayModelTypeInLabel(myLabel as roSgNodeLabel)
|
|
3619
|
+
print myLabel.text
|
|
3620
|
+
di = createObject("roDeviceInfo") as roDeviceInfo
|
|
3621
|
+
myLabel.text = di.GetFriendlyName()
|
|
3622
|
+
print myLabel.getChildren(0, -1)
|
|
3623
|
+
end sub
|
|
3624
|
+
`);
|
|
3625
|
+
program.plugins.emit('onFileValidate', { program: program, file: mainFile });
|
|
3626
|
+
runtimeSymbols = mainFile.providedSymbols.symbolMap.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3627
|
+
(0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(2);
|
|
3628
|
+
let runtimeChanges = mainFile.providedSymbols.changes.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3629
|
+
(0, chai_config_spec_1.expect)(runtimeChanges.size).to.eq(0);
|
|
3630
|
+
});
|
|
3631
|
+
it('classes that override AA built-in methods show change properly', () => {
|
|
3632
|
+
const classFileContent = `
|
|
3633
|
+
class AAOverRide
|
|
3634
|
+
sub count(num as integer) as void
|
|
3635
|
+
print num
|
|
3636
|
+
end sub
|
|
3637
|
+
end class
|
|
3638
|
+
`;
|
|
3639
|
+
let mainFile = program.setFile('source/class.bs', classFileContent);
|
|
3640
|
+
program.plugins.emit('onFileValidate', { program: program, file: mainFile });
|
|
3641
|
+
// No changes!
|
|
3642
|
+
mainFile = program.setFile('source/class.bs', classFileContent);
|
|
3643
|
+
program.plugins.emit('onFileValidate', { program: program, file: mainFile });
|
|
3644
|
+
let runtimeChanges = mainFile.providedSymbols.changes.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3645
|
+
(0, chai_config_spec_1.expect)(runtimeChanges.size).to.eq(0);
|
|
3646
|
+
});
|
|
3647
|
+
it('functions in a namespace that return classes show change properly', () => {
|
|
3648
|
+
const fileContent = `
|
|
3649
|
+
namespace Alpha.Beta
|
|
3650
|
+
|
|
3651
|
+
class SomeKlass
|
|
3652
|
+
name as string
|
|
3653
|
+
function combineName(klass as SomeKlass)
|
|
3654
|
+
m.name = m.name+klass.name
|
|
3655
|
+
end function
|
|
3656
|
+
end class
|
|
3657
|
+
|
|
3658
|
+
function getSomeKlass(name as string) as SomeKlass
|
|
3659
|
+
k = new SomeKlass()
|
|
3660
|
+
k.name = name
|
|
3661
|
+
return k
|
|
3662
|
+
end function
|
|
3663
|
+
end namespace
|
|
3664
|
+
`;
|
|
3665
|
+
let mainFile = program.setFile('source/class.bs', fileContent);
|
|
3666
|
+
program.plugins.emit('onFileValidate', { program: program, file: mainFile });
|
|
3667
|
+
// No changes!
|
|
3668
|
+
mainFile = program.setFile('source/class.bs', fileContent);
|
|
3669
|
+
program.plugins.emit('onFileValidate', { program: program, file: mainFile });
|
|
3670
|
+
let runtimeChanges = mainFile.providedSymbols.changes.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3671
|
+
(0, chai_config_spec_1.expect)(runtimeChanges.size).to.eq(0);
|
|
3672
|
+
});
|
|
3673
|
+
it('functions in a namespace that have class params show change properly', () => {
|
|
3674
|
+
const fileContent = `
|
|
3675
|
+
namespace Alpha.Beta
|
|
3676
|
+
|
|
3677
|
+
class SomeKlass
|
|
3678
|
+
name as string
|
|
3679
|
+
function combineName(klass as SomeKlass)
|
|
3680
|
+
m.name = m.name+klass.name
|
|
3681
|
+
end function
|
|
3682
|
+
end class
|
|
3683
|
+
|
|
3684
|
+
function combineKlass(klass1 as SomeKlass, klass2 as SomeKlass) as SomeKlass
|
|
3685
|
+
klass1.combineName(klass2)
|
|
3686
|
+
return klass1
|
|
3687
|
+
end function
|
|
3688
|
+
end namespace
|
|
3689
|
+
`;
|
|
3690
|
+
let mainFile = program.setFile('source/class.bs', fileContent);
|
|
3691
|
+
program.plugins.emit('onFileValidate', { program: program, file: mainFile });
|
|
3692
|
+
// No changes!
|
|
3693
|
+
mainFile = program.setFile('source/class.bs', fileContent);
|
|
3694
|
+
program.plugins.emit('onFileValidate', { program: program, file: mainFile });
|
|
3695
|
+
let runtimeChanges = mainFile.providedSymbols.changes.get(SymbolTable_1.SymbolTypeFlag.runtime);
|
|
3696
|
+
(0, chai_config_spec_1.expect)(runtimeChanges.size).to.eq(0);
|
|
3697
|
+
});
|
|
3698
|
+
});
|
|
3699
|
+
});
|
|
2733
3700
|
});
|
|
2734
3701
|
//# sourceMappingURL=BrsFile.spec.js.map
|