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
|
@@ -7,6 +7,7 @@ const testHelpers_spec_1 = require("../../testHelpers.spec");
|
|
|
7
7
|
const chai_1 = require("chai");
|
|
8
8
|
const IntegerType_1 = require("../../types/IntegerType");
|
|
9
9
|
const StringType_1 = require("../../types/StringType");
|
|
10
|
+
const types_1 = require("../../types");
|
|
10
11
|
describe('ScopeValidator', () => {
|
|
11
12
|
let sinon = sinonImport.createSandbox();
|
|
12
13
|
let rootDir = process.cwd();
|
|
@@ -130,6 +131,57 @@ describe('ScopeValidator', () => {
|
|
|
130
131
|
//should have no errors
|
|
131
132
|
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
132
133
|
});
|
|
134
|
+
it('checks for at least the number of non-optional args on variadic (callFunc) functions', () => {
|
|
135
|
+
program.setFile('components/Widget.xml', (0, testHelpers_spec_1.trim) `
|
|
136
|
+
<?xml version="1.0" encoding="utf-8" ?>
|
|
137
|
+
<component name="Widget" extends="Group">
|
|
138
|
+
<script uri="Widget.brs"/>
|
|
139
|
+
<interface>
|
|
140
|
+
<function name="someFunc" />
|
|
141
|
+
</interface>
|
|
142
|
+
</component>
|
|
143
|
+
`);
|
|
144
|
+
program.setFile('components/Widget.brs', `
|
|
145
|
+
sub someFunc(input as object)
|
|
146
|
+
print input
|
|
147
|
+
end sub
|
|
148
|
+
`);
|
|
149
|
+
program.setFile('source/util.brs', `
|
|
150
|
+
sub useCallFunc(input as roSGNodeWidget)
|
|
151
|
+
input.callFunc()
|
|
152
|
+
end sub
|
|
153
|
+
`);
|
|
154
|
+
program.validate();
|
|
155
|
+
//should have an error
|
|
156
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
157
|
+
DiagnosticMessages_1.DiagnosticMessages.mismatchArgumentCount('1-32', 0)
|
|
158
|
+
]);
|
|
159
|
+
});
|
|
160
|
+
it('any number number of args on variadic (callFunc) functions', () => {
|
|
161
|
+
program.setFile('components/Widget.xml', (0, testHelpers_spec_1.trim) `
|
|
162
|
+
<?xml version="1.0" encoding="utf-8" ?>
|
|
163
|
+
<component name="Widget" extends="Group">
|
|
164
|
+
<script uri="Widget.brs"/>
|
|
165
|
+
<interface>
|
|
166
|
+
<function name="someFunc" />
|
|
167
|
+
</interface>
|
|
168
|
+
</component>
|
|
169
|
+
`);
|
|
170
|
+
program.setFile('components/Widget.brs', `
|
|
171
|
+
sub someFunc(input as object)
|
|
172
|
+
print input
|
|
173
|
+
end sub
|
|
174
|
+
`);
|
|
175
|
+
program.setFile('source/util.brs', `
|
|
176
|
+
sub useCallFunc(input as roSGNodeWidget)
|
|
177
|
+
input.callFunc("someFunc", 1, 2, 3, {})
|
|
178
|
+
end sub
|
|
179
|
+
`);
|
|
180
|
+
program.validate();
|
|
181
|
+
//TODO: do a better job of handling callFunc() invocations!
|
|
182
|
+
//should have an error
|
|
183
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
184
|
+
});
|
|
133
185
|
});
|
|
134
186
|
describe('argumentTypeMismatch', () => {
|
|
135
187
|
it('param `as object` supports all known types', () => {
|
|
@@ -948,6 +1000,318 @@ describe('ScopeValidator', () => {
|
|
|
948
1000
|
(0, testHelpers_spec_1.expectTypeToBe)(data.fieldMismatches[0].expectedType, IntegerType_1.IntegerType);
|
|
949
1001
|
(0, testHelpers_spec_1.expectTypeToBe)(data.fieldMismatches[0].actualType, StringType_1.StringType);
|
|
950
1002
|
});
|
|
1003
|
+
it('allows interfaces that have a superset of properties', () => {
|
|
1004
|
+
program.setFile('source/util.bs', `
|
|
1005
|
+
sub doStuff()
|
|
1006
|
+
takesMyIface({alpha: true, beta: "hello", charlie: 1})
|
|
1007
|
+
end sub
|
|
1008
|
+
|
|
1009
|
+
sub takesMyIface(iFace as MyIFace)
|
|
1010
|
+
end sub
|
|
1011
|
+
|
|
1012
|
+
interface MyIFace
|
|
1013
|
+
beta as string
|
|
1014
|
+
charlie as integer
|
|
1015
|
+
end interface
|
|
1016
|
+
`);
|
|
1017
|
+
program.validate();
|
|
1018
|
+
//should have no errors
|
|
1019
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1020
|
+
});
|
|
1021
|
+
it('allows interfaces that have a superset of properties', () => {
|
|
1022
|
+
program.setFile('source/util.bs', `
|
|
1023
|
+
sub doStuff(otherFace as MyOtherFace)
|
|
1024
|
+
takesMyIface(otherFace)
|
|
1025
|
+
end sub
|
|
1026
|
+
|
|
1027
|
+
sub takesMyIface(iFace as MyIFace)
|
|
1028
|
+
end sub
|
|
1029
|
+
|
|
1030
|
+
interface MyIFace
|
|
1031
|
+
beta as string
|
|
1032
|
+
charlie as integer
|
|
1033
|
+
end interface
|
|
1034
|
+
|
|
1035
|
+
interface MyOtherFace
|
|
1036
|
+
alpha as boolean
|
|
1037
|
+
beta as string
|
|
1038
|
+
charlie as integer
|
|
1039
|
+
end interface
|
|
1040
|
+
`);
|
|
1041
|
+
program.validate();
|
|
1042
|
+
//should have no errors
|
|
1043
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1044
|
+
});
|
|
1045
|
+
it('includes data on missing fields', () => {
|
|
1046
|
+
program.setFile('source/util.bs', `
|
|
1047
|
+
sub doStuff()
|
|
1048
|
+
takesMyIface({charlie: "hello"})
|
|
1049
|
+
end sub
|
|
1050
|
+
|
|
1051
|
+
sub takesMyIface(iFace as MyIFace)
|
|
1052
|
+
end sub
|
|
1053
|
+
|
|
1054
|
+
interface MyIFace
|
|
1055
|
+
beta as string
|
|
1056
|
+
charlie as integer
|
|
1057
|
+
end interface
|
|
1058
|
+
`);
|
|
1059
|
+
program.validate();
|
|
1060
|
+
//should have error
|
|
1061
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1062
|
+
DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch('roAssociativeArray', 'MyIFace', {
|
|
1063
|
+
missingFields: [{ name: 'beta', expectedType: StringType_1.StringType.instance }],
|
|
1064
|
+
fieldMismatches: [{ name: 'charlie', expectedType: IntegerType_1.IntegerType.instance, actualType: StringType_1.StringType.instance }]
|
|
1065
|
+
}).message
|
|
1066
|
+
]);
|
|
1067
|
+
//The aa should have 'beta' and 'charlie' properties of type string and integer
|
|
1068
|
+
const diagnostics = program.getDiagnostics();
|
|
1069
|
+
(0, chai_1.expect)(diagnostics.length).to.eq(1);
|
|
1070
|
+
const data = diagnostics[0].data;
|
|
1071
|
+
(0, chai_1.expect)(data.missingFields.length).to.eq(1);
|
|
1072
|
+
(0, chai_1.expect)(data.missingFields[0].name).to.eq('beta');
|
|
1073
|
+
(0, testHelpers_spec_1.expectTypeToBe)(data.missingFields[0].expectedType, StringType_1.StringType);
|
|
1074
|
+
(0, chai_1.expect)(data.fieldMismatches.length).to.eq(1);
|
|
1075
|
+
(0, chai_1.expect)(data.fieldMismatches[0].name).to.eq('charlie');
|
|
1076
|
+
(0, testHelpers_spec_1.expectTypeToBe)(data.fieldMismatches[0].expectedType, IntegerType_1.IntegerType);
|
|
1077
|
+
(0, testHelpers_spec_1.expectTypeToBe)(data.fieldMismatches[0].actualType, StringType_1.StringType);
|
|
1078
|
+
});
|
|
1079
|
+
describe('array compatibility', () => {
|
|
1080
|
+
it('accepts dynamic when assigning to a roArray', () => {
|
|
1081
|
+
program.setFile('source/util.bs', `
|
|
1082
|
+
sub takesArray(arr as roArray)
|
|
1083
|
+
end sub
|
|
1084
|
+
|
|
1085
|
+
sub doStuff(someArray)
|
|
1086
|
+
takesArray(someArray)
|
|
1087
|
+
end sub
|
|
1088
|
+
`);
|
|
1089
|
+
program.validate();
|
|
1090
|
+
//should have no errors
|
|
1091
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1092
|
+
});
|
|
1093
|
+
it('accepts roArray when assigning to a roArray', () => {
|
|
1094
|
+
program.setFile('source/util.bs', `
|
|
1095
|
+
sub takesArray(arr as roArray)
|
|
1096
|
+
end sub
|
|
1097
|
+
|
|
1098
|
+
sub doStuff(someArray as roArray)
|
|
1099
|
+
takesArray(someArray)
|
|
1100
|
+
end sub
|
|
1101
|
+
`);
|
|
1102
|
+
program.validate();
|
|
1103
|
+
//should have no errors
|
|
1104
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1105
|
+
});
|
|
1106
|
+
it('accepts typed arrays when assigning to a roArray', () => {
|
|
1107
|
+
program.setFile('source/util.bs', `
|
|
1108
|
+
sub takesArray(arr as roArray)
|
|
1109
|
+
end sub
|
|
1110
|
+
|
|
1111
|
+
sub doStuff(someArray as dynamic[])
|
|
1112
|
+
takesArray(someArray)
|
|
1113
|
+
end sub
|
|
1114
|
+
`);
|
|
1115
|
+
program.validate();
|
|
1116
|
+
//should have no errors
|
|
1117
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1118
|
+
});
|
|
1119
|
+
it('accepts roArray when assigning to dynamic[]', () => {
|
|
1120
|
+
program.setFile('source/util.bs', `
|
|
1121
|
+
sub takesArray(arr as dynamic[])
|
|
1122
|
+
end sub
|
|
1123
|
+
|
|
1124
|
+
sub doStuff(someArray as roArray)
|
|
1125
|
+
takesArray(someArray)
|
|
1126
|
+
end sub
|
|
1127
|
+
`);
|
|
1128
|
+
program.validate();
|
|
1129
|
+
//should have no errors
|
|
1130
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1131
|
+
});
|
|
1132
|
+
it('accepts roArray when assigning to typed array', () => {
|
|
1133
|
+
program.setFile('source/util.bs', `
|
|
1134
|
+
sub takesArray(arr as string[])
|
|
1135
|
+
end sub
|
|
1136
|
+
|
|
1137
|
+
sub doStuff(someArray as roArray)
|
|
1138
|
+
takesArray(someArray)
|
|
1139
|
+
end sub
|
|
1140
|
+
`);
|
|
1141
|
+
program.validate();
|
|
1142
|
+
//should have no errors
|
|
1143
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1144
|
+
});
|
|
1145
|
+
it('validates when typed array types are incompatible', () => {
|
|
1146
|
+
program.setFile('source/util.bs', `
|
|
1147
|
+
sub takesArray(arr as string[])
|
|
1148
|
+
end sub
|
|
1149
|
+
|
|
1150
|
+
sub doStuff(someArray as integer[])
|
|
1151
|
+
takesArray(someArray)
|
|
1152
|
+
end sub
|
|
1153
|
+
`);
|
|
1154
|
+
program.validate();
|
|
1155
|
+
//should have errors
|
|
1156
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1157
|
+
DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch('Array<integer>', 'Array<string>').message
|
|
1158
|
+
]);
|
|
1159
|
+
});
|
|
1160
|
+
it('accepts when typed array types are compatible', () => {
|
|
1161
|
+
program.setFile('source/util.bs', `
|
|
1162
|
+
sub takesArray(arr as float[])
|
|
1163
|
+
end sub
|
|
1164
|
+
|
|
1165
|
+
sub doStuff(someArray as integer[])
|
|
1166
|
+
takesArray(someArray)
|
|
1167
|
+
end sub
|
|
1168
|
+
`);
|
|
1169
|
+
program.validate();
|
|
1170
|
+
//should have no errors
|
|
1171
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1172
|
+
});
|
|
1173
|
+
});
|
|
1174
|
+
describe('interface with optional properties', () => {
|
|
1175
|
+
it('allows using interfaces with optional props', () => {
|
|
1176
|
+
program.setFile('source/util.bs', `
|
|
1177
|
+
function takesIFace(iface as MyIFace) as string
|
|
1178
|
+
if invalid <> iface.name
|
|
1179
|
+
return iface.name
|
|
1180
|
+
else if invalid <> iface.data
|
|
1181
|
+
return FormatJson(iface.data)
|
|
1182
|
+
end if
|
|
1183
|
+
return "no"
|
|
1184
|
+
end function
|
|
1185
|
+
|
|
1186
|
+
sub doStuff(iface as MyIFace)
|
|
1187
|
+
print takesIFace(iface)
|
|
1188
|
+
end sub
|
|
1189
|
+
|
|
1190
|
+
interface MyIFace
|
|
1191
|
+
optional name as string
|
|
1192
|
+
optional data
|
|
1193
|
+
end interface
|
|
1194
|
+
`);
|
|
1195
|
+
program.validate();
|
|
1196
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1197
|
+
});
|
|
1198
|
+
it('allows using passing AAs with missing optional properties', () => {
|
|
1199
|
+
program.setFile('source/util.bs', `
|
|
1200
|
+
function takesIFace(iface as MyIFace) as string
|
|
1201
|
+
if invalid <> iface.name
|
|
1202
|
+
return iface.name
|
|
1203
|
+
else if invalid <> iface.data
|
|
1204
|
+
return FormatJson(iface.data)
|
|
1205
|
+
end if
|
|
1206
|
+
return "no"
|
|
1207
|
+
end function
|
|
1208
|
+
|
|
1209
|
+
sub doStuff(iface as MyIFace)
|
|
1210
|
+
print takesIFace({name: "Hello"})
|
|
1211
|
+
end sub
|
|
1212
|
+
|
|
1213
|
+
interface MyIFace
|
|
1214
|
+
optional name as string
|
|
1215
|
+
optional data
|
|
1216
|
+
end interface
|
|
1217
|
+
`);
|
|
1218
|
+
program.validate();
|
|
1219
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1220
|
+
});
|
|
1221
|
+
it('disallows using AAs with bad types for optional properties', () => {
|
|
1222
|
+
program.setFile('source/util.bs', `
|
|
1223
|
+
function takesIFace(iface as MyIFace) as string
|
|
1224
|
+
if invalid <> iface.name
|
|
1225
|
+
return iface.name
|
|
1226
|
+
else if invalid <> iface.data
|
|
1227
|
+
return FormatJson(iface.data)
|
|
1228
|
+
end if
|
|
1229
|
+
return "no"
|
|
1230
|
+
end function
|
|
1231
|
+
|
|
1232
|
+
sub doStuff(iface as MyIFace)
|
|
1233
|
+
print takesIFace({name: 3.14})
|
|
1234
|
+
end sub
|
|
1235
|
+
|
|
1236
|
+
interface MyIFace
|
|
1237
|
+
optional name as string
|
|
1238
|
+
optional data
|
|
1239
|
+
end interface
|
|
1240
|
+
`);
|
|
1241
|
+
program.validate();
|
|
1242
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1243
|
+
DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch('roAssociativeArray', 'MyIFace', {
|
|
1244
|
+
fieldMismatches: [{ name: 'name', expectedType: StringType_1.StringType.instance, actualType: types_1.FloatType.instance }]
|
|
1245
|
+
}).message
|
|
1246
|
+
]);
|
|
1247
|
+
});
|
|
1248
|
+
it('disallows passing classes with bad types for optional properties', () => {
|
|
1249
|
+
program.setFile('source/util.bs', `
|
|
1250
|
+
function takesIFace(iface as MyIFace) as string
|
|
1251
|
+
if invalid <> iface.name
|
|
1252
|
+
return iface.name
|
|
1253
|
+
else if invalid <> iface.data
|
|
1254
|
+
return FormatJson(iface.data)
|
|
1255
|
+
end if
|
|
1256
|
+
return "no"
|
|
1257
|
+
end function
|
|
1258
|
+
|
|
1259
|
+
sub doStuff(iface as MyIFace)
|
|
1260
|
+
k = new MyKlass()
|
|
1261
|
+
print takesIFace(k)
|
|
1262
|
+
end sub
|
|
1263
|
+
|
|
1264
|
+
interface MyIFace
|
|
1265
|
+
optional name as string
|
|
1266
|
+
optional data
|
|
1267
|
+
end interface
|
|
1268
|
+
|
|
1269
|
+
class MyKlass
|
|
1270
|
+
name as float
|
|
1271
|
+
end class
|
|
1272
|
+
`);
|
|
1273
|
+
program.validate();
|
|
1274
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1275
|
+
DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch('MyKlass', 'MyIFace', {
|
|
1276
|
+
fieldMismatches: [{ name: 'name', expectedType: StringType_1.StringType.instance, actualType: types_1.FloatType.instance }]
|
|
1277
|
+
}).message
|
|
1278
|
+
]);
|
|
1279
|
+
});
|
|
1280
|
+
it('allows passing classes as args for interfaces with optional properties', () => {
|
|
1281
|
+
program.setFile('source/util.bs', `
|
|
1282
|
+
function takesIFace(iface as MyIFace) as string
|
|
1283
|
+
if invalid <> iface.name
|
|
1284
|
+
return iface.name
|
|
1285
|
+
else if invalid <> iface.data
|
|
1286
|
+
return FormatJson(iface.data)
|
|
1287
|
+
end if
|
|
1288
|
+
return "no"
|
|
1289
|
+
end function
|
|
1290
|
+
|
|
1291
|
+
sub doStuff(iface as MyIFace)
|
|
1292
|
+
k = new MyKlass()
|
|
1293
|
+
k2 = new MyKlass2()
|
|
1294
|
+
print takesIFace(k)
|
|
1295
|
+
print takesIFace(k2)
|
|
1296
|
+
end sub
|
|
1297
|
+
|
|
1298
|
+
interface MyIFace
|
|
1299
|
+
optional name as string
|
|
1300
|
+
optional data
|
|
1301
|
+
end interface
|
|
1302
|
+
|
|
1303
|
+
class MyKlass
|
|
1304
|
+
data = {}
|
|
1305
|
+
end class
|
|
1306
|
+
|
|
1307
|
+
class MyKlass2
|
|
1308
|
+
data = "test"
|
|
1309
|
+
end class
|
|
1310
|
+
`);
|
|
1311
|
+
program.validate();
|
|
1312
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1313
|
+
});
|
|
1314
|
+
});
|
|
951
1315
|
});
|
|
952
1316
|
describe('cannotFindName', () => {
|
|
953
1317
|
it('finds variables from assignments from member functions of primitive types', () => {
|
|
@@ -973,6 +1337,21 @@ describe('ScopeValidator', () => {
|
|
|
973
1337
|
DiagnosticMessages_1.DiagnosticMessages.cannotFindName('expected').message
|
|
974
1338
|
]);
|
|
975
1339
|
});
|
|
1340
|
+
it('does not have a diagnostic for using a variable the result of an assignment with unresolved value', () => {
|
|
1341
|
+
program.setFile('source/util.bs', `
|
|
1342
|
+
sub doStuff()
|
|
1343
|
+
myValue = UndeclaredValue
|
|
1344
|
+
if myValue > 0
|
|
1345
|
+
print "hello"
|
|
1346
|
+
end if
|
|
1347
|
+
end sub
|
|
1348
|
+
`);
|
|
1349
|
+
program.validate();
|
|
1350
|
+
//should have only 1 error - cannot find "UndeclaredValue"
|
|
1351
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1352
|
+
DiagnosticMessages_1.DiagnosticMessages.cannotFindName('UndeclaredValue').message
|
|
1353
|
+
]);
|
|
1354
|
+
});
|
|
976
1355
|
});
|
|
977
1356
|
describe('returnTypeMismatch', () => {
|
|
978
1357
|
it('finds when a function returns a type that is not what was declared', () => {
|
|
@@ -1062,6 +1441,110 @@ describe('ScopeValidator', () => {
|
|
|
1062
1441
|
DiagnosticMessages_1.DiagnosticMessages.returnTypeMismatch('string', 'void').message
|
|
1063
1442
|
]);
|
|
1064
1443
|
});
|
|
1444
|
+
it('allows returning enums with the default type that matches the declared return type', () => {
|
|
1445
|
+
program.setFile('source/util.bs', `
|
|
1446
|
+
enum MyEnum
|
|
1447
|
+
val1
|
|
1448
|
+
val2
|
|
1449
|
+
end enum
|
|
1450
|
+
|
|
1451
|
+
function getInt() as integer
|
|
1452
|
+
return MyEnum.val1
|
|
1453
|
+
end function
|
|
1454
|
+
`);
|
|
1455
|
+
program.validate();
|
|
1456
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1457
|
+
});
|
|
1458
|
+
it('allows returning enums passed as a param with the default type that matches the declared return type', () => {
|
|
1459
|
+
program.setFile('source/util.bs', `
|
|
1460
|
+
enum MyEnum
|
|
1461
|
+
val1
|
|
1462
|
+
val2
|
|
1463
|
+
end enum
|
|
1464
|
+
|
|
1465
|
+
function getInt(enumVal as MyEnum) as integer
|
|
1466
|
+
return enumVal
|
|
1467
|
+
end function
|
|
1468
|
+
`);
|
|
1469
|
+
program.validate();
|
|
1470
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1471
|
+
});
|
|
1472
|
+
it('allows returning enums with the default type that matches the declared return type for string enums', () => {
|
|
1473
|
+
program.setFile('source/util.bs', `
|
|
1474
|
+
enum MyEnum
|
|
1475
|
+
val1 = "hello"
|
|
1476
|
+
val2 = "world"
|
|
1477
|
+
end enum
|
|
1478
|
+
|
|
1479
|
+
function getInt() as string
|
|
1480
|
+
return MyEnum.val1
|
|
1481
|
+
end function
|
|
1482
|
+
`);
|
|
1483
|
+
program.validate();
|
|
1484
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1485
|
+
});
|
|
1486
|
+
it('flags returning enums with the default type that does not matches the declared return type', () => {
|
|
1487
|
+
program.setFile('source/util.bs', `
|
|
1488
|
+
enum MyEnum
|
|
1489
|
+
val1 = "hello"
|
|
1490
|
+
val2 = "world"
|
|
1491
|
+
end enum
|
|
1492
|
+
|
|
1493
|
+
function getInt() as integer
|
|
1494
|
+
return MyEnum.val1
|
|
1495
|
+
end function
|
|
1496
|
+
`);
|
|
1497
|
+
program.validate();
|
|
1498
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1499
|
+
DiagnosticMessages_1.DiagnosticMessages.returnTypeMismatch('MyEnum', 'integer').message
|
|
1500
|
+
]);
|
|
1501
|
+
});
|
|
1502
|
+
it('flags returning enums passed as params with the default type that does not matches the declared return type', () => {
|
|
1503
|
+
program.setFile('source/util.bs', `
|
|
1504
|
+
enum MyEnum
|
|
1505
|
+
val1 = "hello"
|
|
1506
|
+
val2 = "world"
|
|
1507
|
+
end enum
|
|
1508
|
+
|
|
1509
|
+
function getInt(enumVal as MyEnum) as integer
|
|
1510
|
+
return enumVal
|
|
1511
|
+
end function
|
|
1512
|
+
`);
|
|
1513
|
+
program.validate();
|
|
1514
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1515
|
+
DiagnosticMessages_1.DiagnosticMessages.returnTypeMismatch('MyEnum', 'integer').message
|
|
1516
|
+
]);
|
|
1517
|
+
});
|
|
1518
|
+
it('flags returning enums type', () => {
|
|
1519
|
+
program.setFile('source/util.bs', `
|
|
1520
|
+
enum MyEnum
|
|
1521
|
+
val1 = "hello"
|
|
1522
|
+
val2 = "world"
|
|
1523
|
+
end enum
|
|
1524
|
+
|
|
1525
|
+
|
|
1526
|
+
function getInt() as integer
|
|
1527
|
+
return MyEnum
|
|
1528
|
+
end function
|
|
1529
|
+
`);
|
|
1530
|
+
program.validate();
|
|
1531
|
+
(0, chai_1.expect)(program.getDiagnostics().length).to.be.greaterThan(0);
|
|
1532
|
+
});
|
|
1533
|
+
it('allows returning an Enum', () => {
|
|
1534
|
+
program.setFile('source/util.bs', `
|
|
1535
|
+
enum MyEnum
|
|
1536
|
+
val1 = "hello"
|
|
1537
|
+
val2 = "world"
|
|
1538
|
+
end enum
|
|
1539
|
+
|
|
1540
|
+
|
|
1541
|
+
function getInt() as MyEnum
|
|
1542
|
+
return MyEnum.val1
|
|
1543
|
+
end function
|
|
1544
|
+
`);
|
|
1545
|
+
program.validate();
|
|
1546
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1547
|
+
});
|
|
1065
1548
|
});
|
|
1066
1549
|
describe('assignmentTypeMismatch', () => {
|
|
1067
1550
|
it('finds when the type of the lhs is not compatible with the expected type', () => {
|
|
@@ -1331,5 +1814,191 @@ describe('ScopeValidator', () => {
|
|
|
1331
1814
|
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1332
1815
|
});
|
|
1333
1816
|
});
|
|
1817
|
+
describe('revalidation', () => {
|
|
1818
|
+
it('revalidates when a enum defined in a different namespace changes', () => {
|
|
1819
|
+
program.setFile('source/file1.bs', `
|
|
1820
|
+
namespace Alpha
|
|
1821
|
+
function printEnum(enumVal as Alpha.Beta.Charlie.SomeEnum) as string
|
|
1822
|
+
return enumVal.toStr()
|
|
1823
|
+
end function
|
|
1824
|
+
end namespace
|
|
1825
|
+
`);
|
|
1826
|
+
program.setFile('source/file2.bs', `
|
|
1827
|
+
namespace Alpha.Beta.Charlie
|
|
1828
|
+
enum SomeEnum
|
|
1829
|
+
val1 = 1
|
|
1830
|
+
val2 = 2
|
|
1831
|
+
end enum
|
|
1832
|
+
end namespace
|
|
1833
|
+
`);
|
|
1834
|
+
program.validate();
|
|
1835
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1836
|
+
program.setFile('source/file2.bs', `
|
|
1837
|
+
namespace Alpha.Beta.Charlie
|
|
1838
|
+
enum ChangedEnum
|
|
1839
|
+
val1 = 1
|
|
1840
|
+
val2 = 2
|
|
1841
|
+
end enum
|
|
1842
|
+
end namespace
|
|
1843
|
+
`);
|
|
1844
|
+
program.validate();
|
|
1845
|
+
(0, testHelpers_spec_1.expectDiagnosticsIncludes)(program, [DiagnosticMessages_1.DiagnosticMessages.cannotFindName('SomeEnum').message]);
|
|
1846
|
+
});
|
|
1847
|
+
it('revalidates when a class defined in a different namespace changes', () => {
|
|
1848
|
+
program.setFile('source/file1.bs', `
|
|
1849
|
+
namespace Alpha
|
|
1850
|
+
function printEnum(myKlass as Alpha.Beta.Charlie.SomeClass) as string
|
|
1851
|
+
return myKlass.getValue()
|
|
1852
|
+
end function
|
|
1853
|
+
end namespace
|
|
1854
|
+
`);
|
|
1855
|
+
program.setFile('source/file2.bs', `
|
|
1856
|
+
namespace Alpha.Beta.Charlie
|
|
1857
|
+
class SomeClass
|
|
1858
|
+
private myValue as string
|
|
1859
|
+
function getValue() as string
|
|
1860
|
+
return m.myValue
|
|
1861
|
+
end function
|
|
1862
|
+
end class
|
|
1863
|
+
end namespace
|
|
1864
|
+
`);
|
|
1865
|
+
program.validate();
|
|
1866
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1867
|
+
program.setFile('source/file2.bs', `
|
|
1868
|
+
namespace Alpha.Beta.Charlie
|
|
1869
|
+
class SomeClass
|
|
1870
|
+
private myValue as string
|
|
1871
|
+
function getValue(lowerCase as boolean) as string
|
|
1872
|
+
if lowerCase
|
|
1873
|
+
return lcase(m.myValue)
|
|
1874
|
+
end if
|
|
1875
|
+
return m.myValue
|
|
1876
|
+
end function
|
|
1877
|
+
end class
|
|
1878
|
+
end namespace
|
|
1879
|
+
`);
|
|
1880
|
+
program.validate();
|
|
1881
|
+
(0, testHelpers_spec_1.expectDiagnosticsIncludes)(program, [DiagnosticMessages_1.DiagnosticMessages.mismatchArgumentCount(1, 0).message]);
|
|
1882
|
+
});
|
|
1883
|
+
it('validates only parts of files that need revalidation on scope validation', () => {
|
|
1884
|
+
function validateFile(file) {
|
|
1885
|
+
const validateFileEvent = {
|
|
1886
|
+
program: program,
|
|
1887
|
+
file: file
|
|
1888
|
+
};
|
|
1889
|
+
//emit an event to allow plugins to contribute to the file validation process
|
|
1890
|
+
program.plugins.emit('onFileValidate', validateFileEvent);
|
|
1891
|
+
}
|
|
1892
|
+
const commonContents = `
|
|
1893
|
+
sub noValidationForEachScope()
|
|
1894
|
+
k = new KlassInSameFile()
|
|
1895
|
+
print k.value
|
|
1896
|
+
end sub
|
|
1897
|
+
|
|
1898
|
+
class KlassInSameFile
|
|
1899
|
+
value = 1
|
|
1900
|
+
end class
|
|
1901
|
+
`;
|
|
1902
|
+
let commonBs = program.setFile('source/common.bs', commonContents);
|
|
1903
|
+
validateFile(commonBs);
|
|
1904
|
+
(0, chai_1.expect)(commonBs.validationSegmenter.segmentsForValidation.length).to.eq(2); // 1 func, 1 classField
|
|
1905
|
+
(0, chai_1.expect)(commonBs.validationSegmenter.unresolvedSegmentsSymbols.size).to.eq(0);
|
|
1906
|
+
commonBs.validationSegmenter.validatedSegments.forEach(x => (0, chai_1.expect)(x).to.be.false);
|
|
1907
|
+
(0, chai_1.expect)(commonBs.validationSegmenter.singleValidationSegments.size).to.eq(2); // no references needed to other files
|
|
1908
|
+
let common2Contents = `
|
|
1909
|
+
sub doesValidationForEachScope()
|
|
1910
|
+
k = new KlassInDiffFile()
|
|
1911
|
+
print k.value
|
|
1912
|
+
end sub
|
|
1913
|
+
|
|
1914
|
+
function alsoNoValidationForEachScope() as integer
|
|
1915
|
+
return 1
|
|
1916
|
+
end function
|
|
1917
|
+
`;
|
|
1918
|
+
let common2Bs = program.setFile('source/common2.bs', common2Contents);
|
|
1919
|
+
validateFile(common2Bs);
|
|
1920
|
+
(0, chai_1.expect)(common2Bs.validationSegmenter.segmentsForValidation.length).to.eq(2); // 2 func
|
|
1921
|
+
(0, chai_1.expect)(common2Bs.validationSegmenter.unresolvedSegmentsSymbols.size).to.eq(1);
|
|
1922
|
+
commonBs.validationSegmenter.validatedSegments.forEach(x => (0, chai_1.expect)(x).to.be.false);
|
|
1923
|
+
(0, chai_1.expect)(common2Bs.validationSegmenter.singleValidationSegments.size).to.eq(1); // alsoNoValidationForEachScope() does not reference other files
|
|
1924
|
+
let klassContents = `
|
|
1925
|
+
class KlassInDiffFile
|
|
1926
|
+
value = 2
|
|
1927
|
+
end class
|
|
1928
|
+
`;
|
|
1929
|
+
let klassBs = program.setFile('source/klass.bs', klassContents);
|
|
1930
|
+
validateFile(klassBs);
|
|
1931
|
+
(0, chai_1.expect)(klassBs.validationSegmenter.segmentsForValidation.length).to.eq(1); // 1 classField
|
|
1932
|
+
(0, chai_1.expect)(klassBs.validationSegmenter.unresolvedSegmentsSymbols.size).to.eq(0);
|
|
1933
|
+
klassBs.validationSegmenter.validatedSegments.forEach(x => (0, chai_1.expect)(x).to.be.false);
|
|
1934
|
+
(0, chai_1.expect)(klassBs.validationSegmenter.singleValidationSegments.size).to.eq(1); // does not reference other files
|
|
1935
|
+
const widgetFileContents = `
|
|
1936
|
+
sub init()
|
|
1937
|
+
noValidationForEachScope()
|
|
1938
|
+
doesValidationForEachScope()
|
|
1939
|
+
end sub
|
|
1940
|
+
|
|
1941
|
+
sub anotherFunction()
|
|
1942
|
+
print "hello"
|
|
1943
|
+
end sub
|
|
1944
|
+
`;
|
|
1945
|
+
let widgetBs = program.setFile('components/Widget.bs', widgetFileContents);
|
|
1946
|
+
validateFile(widgetBs);
|
|
1947
|
+
(0, chai_1.expect)(widgetBs.validationSegmenter.segmentsForValidation.length).to.eq(2); // 2 funcs
|
|
1948
|
+
(0, chai_1.expect)(widgetBs.validationSegmenter.unresolvedSegmentsSymbols.size).to.eq(1); // 1 func (init)
|
|
1949
|
+
widgetBs.validationSegmenter.validatedSegments.forEach(x => (0, chai_1.expect)(x).to.be.false);
|
|
1950
|
+
(0, chai_1.expect)(widgetBs.validationSegmenter.singleValidationSegments.size).to.eq(1); // 1 func (anotherFunction)
|
|
1951
|
+
const diffKlassContent = `
|
|
1952
|
+
class KlassInDiffFile
|
|
1953
|
+
value = 3
|
|
1954
|
+
end class
|
|
1955
|
+
`;
|
|
1956
|
+
let diffKlassBs = program.setFile('components/diffKlass.bs', diffKlassContent);
|
|
1957
|
+
validateFile(diffKlassBs);
|
|
1958
|
+
(0, chai_1.expect)(diffKlassBs.validationSegmenter.segmentsForValidation.length).to.eq(1); // 1 classField
|
|
1959
|
+
(0, chai_1.expect)(diffKlassBs.validationSegmenter.unresolvedSegmentsSymbols.size).to.eq(0);
|
|
1960
|
+
diffKlassBs.validationSegmenter.validatedSegments.forEach(x => (0, chai_1.expect)(x).to.be.false);
|
|
1961
|
+
(0, chai_1.expect)(diffKlassBs.validationSegmenter.singleValidationSegments.size).to.eq(1);
|
|
1962
|
+
program.setFile('components/Widget.xml', (0, testHelpers_spec_1.trim) `
|
|
1963
|
+
<?xml version="1.0" encoding="utf-8" ?>
|
|
1964
|
+
<component name="Widget" extends="Group">
|
|
1965
|
+
<script uri="Widget.bs"/>
|
|
1966
|
+
<script uri="pkg:/source/common.bs"/>
|
|
1967
|
+
<script uri="pkg:/source/common2.bs"/>
|
|
1968
|
+
<script uri="diffKlass.bs"/>
|
|
1969
|
+
</component>
|
|
1970
|
+
`);
|
|
1971
|
+
//reset files
|
|
1972
|
+
commonBs = program.setFile('source/common.bs', commonContents);
|
|
1973
|
+
common2Bs = program.setFile('source/common2.bs', common2Contents);
|
|
1974
|
+
klassBs = program.setFile('source/klass.bs', klassContents);
|
|
1975
|
+
widgetBs = program.setFile('components/Widget.bs', widgetFileContents);
|
|
1976
|
+
diffKlassBs = program.setFile('components/diffKlass.bs', diffKlassContent);
|
|
1977
|
+
program.validate();
|
|
1978
|
+
// all segments should be validated
|
|
1979
|
+
[commonBs, common2Bs, klassBs, widgetBs, diffKlassBs].forEach(file => {
|
|
1980
|
+
(0, chai_1.expect)(file.validationSegmenter.validatedSegments.size).to.gte(file.validationSegmenter.segmentsForValidation.length);
|
|
1981
|
+
file.validationSegmenter.validatedSegments.forEach(x => (0, chai_1.expect)(x).to.be.true);
|
|
1982
|
+
});
|
|
1983
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1984
|
+
program.setFile('components/Widget.bs', widgetFileContents);
|
|
1985
|
+
program.validate();
|
|
1986
|
+
// Widget.bs has changed. it needs to totally re-validated
|
|
1987
|
+
// and other files in the scope need to revalidate only the unresolved segments - should be source/common2.bs
|
|
1988
|
+
// TODO: how to test this?
|
|
1989
|
+
program.validate();
|
|
1990
|
+
program.setFile('components/diffKlass.bs', diffKlassContent);
|
|
1991
|
+
// diffKlass.bs has changed. it needs to totally re-validated
|
|
1992
|
+
// no other files in scope reference it .. no other files need revalidation
|
|
1993
|
+
// TODO: how to test this?
|
|
1994
|
+
program.validate();
|
|
1995
|
+
program.setFile('source/common.bs', commonContents);
|
|
1996
|
+
// common.bs has changed. it needs to totally re-validated
|
|
1997
|
+
// in source scope, common2.bs still has unresolves, it needs revalidation
|
|
1998
|
+
// in widget scope, widget.bs references it
|
|
1999
|
+
// TODO: how to test this?
|
|
2000
|
+
program.validate();
|
|
2001
|
+
});
|
|
2002
|
+
});
|
|
1334
2003
|
});
|
|
1335
2004
|
//# sourceMappingURL=ScopeValidator.spec.js.map
|