brighterscript 1.0.0-alpha.13 → 1.0.0-alpha.16

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.
Files changed (229) hide show
  1. package/CHANGELOG.md +87 -2
  2. package/dist/Cache.d.ts +3 -8
  3. package/dist/Cache.js +9 -14
  4. package/dist/Cache.js.map +1 -1
  5. package/dist/DependencyGraph.js +5 -4
  6. package/dist/DependencyGraph.js.map +1 -1
  7. package/dist/DiagnosticMessages.d.ts +21 -1
  8. package/dist/DiagnosticMessages.js +21 -1
  9. package/dist/DiagnosticMessages.js.map +1 -1
  10. package/dist/LanguageServer.d.ts +1 -6
  11. package/dist/LanguageServer.js +0 -9
  12. package/dist/LanguageServer.js.map +1 -1
  13. package/dist/PluginInterface.d.ts +3 -3
  14. package/dist/PluginInterface.js +3 -0
  15. package/dist/PluginInterface.js.map +1 -1
  16. package/dist/Program.d.ts +30 -16
  17. package/dist/Program.js +108 -43
  18. package/dist/Program.js.map +1 -1
  19. package/dist/ProgramBuilder.js +3 -3
  20. package/dist/ProgramBuilder.js.map +1 -1
  21. package/dist/Scope.d.ts +29 -15
  22. package/dist/Scope.js +68 -28
  23. package/dist/Scope.js.map +1 -1
  24. package/dist/SymbolTable.d.ts +1 -1
  25. package/dist/XmlScope.d.ts +3 -3
  26. package/dist/astUtils/AstEditor.d.ts +6 -0
  27. package/dist/astUtils/AstEditor.js +10 -0
  28. package/dist/astUtils/AstEditor.js.map +1 -1
  29. package/dist/astUtils/AstEditor.spec.js +37 -0
  30. package/dist/astUtils/AstEditor.spec.js.map +1 -1
  31. package/dist/astUtils/creators.d.ts +8 -4
  32. package/dist/astUtils/creators.js +87 -6
  33. package/dist/astUtils/creators.js.map +1 -1
  34. package/dist/astUtils/reflection.d.ts +5 -1
  35. package/dist/astUtils/reflection.js +15 -3
  36. package/dist/astUtils/reflection.js.map +1 -1
  37. package/dist/astUtils/reflection.spec.js +11 -10
  38. package/dist/astUtils/reflection.spec.js.map +1 -1
  39. package/dist/astUtils/visitors.d.ts +3 -1
  40. package/dist/astUtils/visitors.js.map +1 -1
  41. package/dist/astUtils/visitors.spec.js +8 -8
  42. package/dist/astUtils/visitors.spec.js.map +1 -1
  43. package/dist/bscPlugin/BscPlugin.d.ts +4 -1
  44. package/dist/bscPlugin/BscPlugin.js +21 -2
  45. package/dist/bscPlugin/BscPlugin.js.map +1 -1
  46. package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +3 -3
  47. package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
  48. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
  49. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.d.ts +9 -0
  50. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +97 -0
  51. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -0
  52. package/dist/bscPlugin/semanticTokens/{SemanticTokensProcessor.spec.d.ts → BrsFileSemanticTokensProcessor.spec.d.ts} +0 -0
  53. package/dist/bscPlugin/semanticTokens/{SemanticTokensProcessor.spec.js → BrsFileSemanticTokensProcessor.spec.js} +30 -2
  54. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +1 -0
  55. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.d.ts +8 -0
  56. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js +36 -0
  57. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js.map +1 -0
  58. package/dist/bscPlugin/validation/BrsFileValidator.d.ts +9 -0
  59. package/dist/bscPlugin/validation/BrsFileValidator.js +66 -0
  60. package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -0
  61. package/dist/bscPlugin/validation/ScopeValidator.d.ts +11 -0
  62. package/dist/bscPlugin/validation/ScopeValidator.js +94 -0
  63. package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -0
  64. package/dist/diagnosticUtils.js +3 -3
  65. package/dist/diagnosticUtils.js.map +1 -1
  66. package/dist/files/BrsFile.Class.spec.js +382 -232
  67. package/dist/files/BrsFile.Class.spec.js.map +1 -1
  68. package/dist/files/BrsFile.d.ts +26 -12
  69. package/dist/files/BrsFile.js +268 -119
  70. package/dist/files/BrsFile.js.map +1 -1
  71. package/dist/files/BrsFile.spec.js +570 -168
  72. package/dist/files/BrsFile.spec.js.map +1 -1
  73. package/dist/files/XmlFile.d.ts +11 -10
  74. package/dist/files/XmlFile.js +16 -11
  75. package/dist/files/XmlFile.js.map +1 -1
  76. package/dist/files/XmlFile.spec.js +60 -58
  77. package/dist/files/XmlFile.spec.js.map +1 -1
  78. package/dist/files/tests/imports.spec.js +8 -6
  79. package/dist/files/tests/imports.spec.js.map +1 -1
  80. package/dist/index.d.ts +12 -3
  81. package/dist/index.js +21 -4
  82. package/dist/index.js.map +1 -1
  83. package/dist/interfaces.d.ts +63 -35
  84. package/dist/lexer/Lexer.js +1 -2
  85. package/dist/lexer/Lexer.js.map +1 -1
  86. package/dist/lexer/Lexer.spec.js +470 -462
  87. package/dist/lexer/Lexer.spec.js.map +1 -1
  88. package/dist/lexer/TokenKind.d.ts +2 -0
  89. package/dist/lexer/TokenKind.js +5 -0
  90. package/dist/lexer/TokenKind.js.map +1 -1
  91. package/dist/parser/Expression.d.ts +18 -16
  92. package/dist/parser/Expression.js +57 -48
  93. package/dist/parser/Expression.js.map +1 -1
  94. package/dist/parser/Parser.Class.spec.js +33 -32
  95. package/dist/parser/Parser.Class.spec.js.map +1 -1
  96. package/dist/parser/Parser.d.ts +28 -7
  97. package/dist/parser/Parser.js +508 -296
  98. package/dist/parser/Parser.js.map +1 -1
  99. package/dist/parser/Parser.spec.js +157 -35
  100. package/dist/parser/Parser.spec.js.map +1 -1
  101. package/dist/parser/SGTypes.spec.js +9 -9
  102. package/dist/parser/SGTypes.spec.js.map +1 -1
  103. package/dist/parser/Statement.d.ts +80 -20
  104. package/dist/parser/Statement.js +257 -92
  105. package/dist/parser/Statement.js.map +1 -1
  106. package/dist/parser/tests/Parser.spec.d.ts +3 -3
  107. package/dist/parser/tests/Parser.spec.js +4 -4
  108. package/dist/parser/tests/Parser.spec.js.map +1 -1
  109. package/dist/parser/tests/controlFlow/For.spec.js +40 -40
  110. package/dist/parser/tests/controlFlow/For.spec.js.map +1 -1
  111. package/dist/parser/tests/controlFlow/ForEach.spec.js +22 -21
  112. package/dist/parser/tests/controlFlow/ForEach.spec.js.map +1 -1
  113. package/dist/parser/tests/controlFlow/If.spec.js +100 -99
  114. package/dist/parser/tests/controlFlow/If.spec.js.map +1 -1
  115. package/dist/parser/tests/controlFlow/While.spec.js +25 -25
  116. package/dist/parser/tests/controlFlow/While.spec.js.map +1 -1
  117. package/dist/parser/tests/expression/Additive.spec.js +21 -21
  118. package/dist/parser/tests/expression/Additive.spec.js.map +1 -1
  119. package/dist/parser/tests/expression/ArrayLiterals.spec.js +91 -91
  120. package/dist/parser/tests/expression/ArrayLiterals.spec.js.map +1 -1
  121. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +102 -102
  122. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
  123. package/dist/parser/tests/expression/Boolean.spec.js +15 -15
  124. package/dist/parser/tests/expression/Boolean.spec.js.map +1 -1
  125. package/dist/parser/tests/expression/Call.spec.js +22 -21
  126. package/dist/parser/tests/expression/Call.spec.js.map +1 -1
  127. package/dist/parser/tests/expression/Exponential.spec.js +11 -11
  128. package/dist/parser/tests/expression/Exponential.spec.js.map +1 -1
  129. package/dist/parser/tests/expression/Function.spec.js +171 -171
  130. package/dist/parser/tests/expression/Function.spec.js.map +1 -1
  131. package/dist/parser/tests/expression/Indexing.spec.js +50 -50
  132. package/dist/parser/tests/expression/Indexing.spec.js.map +1 -1
  133. package/dist/parser/tests/expression/Multiplicative.spec.js +25 -25
  134. package/dist/parser/tests/expression/Multiplicative.spec.js.map +1 -1
  135. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +16 -16
  136. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
  137. package/dist/parser/tests/expression/PrefixUnary.spec.js +26 -26
  138. package/dist/parser/tests/expression/PrefixUnary.spec.js.map +1 -1
  139. package/dist/parser/tests/expression/Primary.spec.js +27 -27
  140. package/dist/parser/tests/expression/Primary.spec.js.map +1 -1
  141. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +3 -2
  142. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js.map +1 -1
  143. package/dist/parser/tests/expression/Relational.spec.js +25 -25
  144. package/dist/parser/tests/expression/Relational.spec.js.map +1 -1
  145. package/dist/parser/tests/expression/TemplateStringExpression.spec.js +7 -7
  146. package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +1 -1
  147. package/dist/parser/tests/expression/TernaryExpression.spec.js +6 -6
  148. package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
  149. package/dist/parser/tests/statement/AssignmentOperators.spec.js +15 -15
  150. package/dist/parser/tests/statement/AssignmentOperators.spec.js.map +1 -1
  151. package/dist/parser/tests/statement/Declaration.spec.js +20 -20
  152. package/dist/parser/tests/statement/Declaration.spec.js.map +1 -1
  153. package/dist/parser/tests/statement/Enum.spec.d.ts +1 -0
  154. package/dist/parser/tests/statement/Enum.spec.js +774 -0
  155. package/dist/parser/tests/statement/Enum.spec.js.map +1 -0
  156. package/dist/parser/tests/statement/For.spec.d.ts +1 -0
  157. package/dist/parser/tests/statement/For.spec.js +46 -0
  158. package/dist/parser/tests/statement/For.spec.js.map +1 -0
  159. package/dist/parser/tests/statement/ForEach.spec.d.ts +1 -0
  160. package/dist/parser/tests/statement/ForEach.spec.js +37 -0
  161. package/dist/parser/tests/statement/ForEach.spec.js.map +1 -0
  162. package/dist/parser/tests/statement/Function.spec.js +121 -120
  163. package/dist/parser/tests/statement/Function.spec.js.map +1 -1
  164. package/dist/parser/tests/statement/Goto.spec.js +9 -8
  165. package/dist/parser/tests/statement/Goto.spec.js.map +1 -1
  166. package/dist/parser/tests/statement/Increment.spec.js +22 -22
  167. package/dist/parser/tests/statement/Increment.spec.js.map +1 -1
  168. package/dist/parser/tests/statement/InterfaceStatement.spec.js +12 -0
  169. package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +1 -1
  170. package/dist/parser/tests/statement/LibraryStatement.spec.js +7 -7
  171. package/dist/parser/tests/statement/LibraryStatement.spec.js.map +1 -1
  172. package/dist/parser/tests/statement/Misc.spec.js +71 -70
  173. package/dist/parser/tests/statement/Misc.spec.js.map +1 -1
  174. package/dist/parser/tests/statement/PrintStatement.spec.js +17 -17
  175. package/dist/parser/tests/statement/PrintStatement.spec.js.map +1 -1
  176. package/dist/parser/tests/statement/ReturnStatement.spec.js +33 -33
  177. package/dist/parser/tests/statement/ReturnStatement.spec.js.map +1 -1
  178. package/dist/parser/tests/statement/Set.spec.js +53 -53
  179. package/dist/parser/tests/statement/Set.spec.js.map +1 -1
  180. package/dist/parser/tests/statement/Stop.spec.js +7 -6
  181. package/dist/parser/tests/statement/Stop.spec.js.map +1 -1
  182. package/dist/preprocessor/Chunk.d.ts +1 -1
  183. package/dist/preprocessor/Preprocessor.d.ts +1 -1
  184. package/dist/preprocessor/Preprocessor.js +7 -7
  185. package/dist/preprocessor/Preprocessor.js.map +1 -1
  186. package/dist/types/ArrayType.d.ts +8 -5
  187. package/dist/types/ArrayType.js +45 -9
  188. package/dist/types/ArrayType.js.map +1 -1
  189. package/dist/types/ArrayType.spec.js +62 -3
  190. package/dist/types/ArrayType.spec.js.map +1 -1
  191. package/dist/types/BscType.d.ts +1 -1
  192. package/dist/types/CustomType.d.ts +1 -1
  193. package/dist/types/CustomType.js +4 -2
  194. package/dist/types/CustomType.js.map +1 -1
  195. package/dist/types/FunctionType.d.ts +7 -6
  196. package/dist/types/FunctionType.js +21 -18
  197. package/dist/types/FunctionType.js.map +1 -1
  198. package/dist/types/FunctionType.spec.js +6 -0
  199. package/dist/types/FunctionType.spec.js.map +1 -1
  200. package/dist/types/LazyType.d.ts +1 -2
  201. package/dist/types/LazyType.js +1 -5
  202. package/dist/types/LazyType.js.map +1 -1
  203. package/dist/types/UniversalFunctionType.d.ts +9 -0
  204. package/dist/types/UniversalFunctionType.js +25 -0
  205. package/dist/types/UniversalFunctionType.js.map +1 -0
  206. package/dist/types/helpers.js +1 -1
  207. package/dist/types/helpers.js.map +1 -1
  208. package/dist/util.d.ts +26 -10
  209. package/dist/util.js +145 -61
  210. package/dist/util.js.map +1 -1
  211. package/dist/validators/ClassValidator.js +17 -24
  212. package/dist/validators/ClassValidator.js.map +1 -1
  213. package/package.json +3 -3
  214. package/dist/astUtils/index.d.ts +0 -7
  215. package/dist/astUtils/index.js +0 -26
  216. package/dist/astUtils/index.js.map +0 -1
  217. package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.d.ts +0 -7
  218. package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.js +0 -63
  219. package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.js.map +0 -1
  220. package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.spec.js.map +0 -1
  221. package/dist/lexer/index.d.ts +0 -3
  222. package/dist/lexer/index.js +0 -18
  223. package/dist/lexer/index.js.map +0 -1
  224. package/dist/parser/index.d.ts +0 -3
  225. package/dist/parser/index.js +0 -16
  226. package/dist/parser/index.js.map +0 -1
  227. package/dist/preprocessor/index.d.ts +0 -3
  228. package/dist/preprocessor/index.js +0 -16
  229. package/dist/preprocessor/index.js.map +0 -1
@@ -51,7 +51,6 @@ describe('BrsFile BrighterScript classes', () => {
51
51
  //if no exception was thrown, this test passes
52
52
  });
53
53
  it('catches child class missing super call in constructor', () => {
54
- var _a;
55
54
  program.setFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
56
55
  class Person
57
56
  sub new()
@@ -63,10 +62,11 @@ describe('BrsFile BrighterScript classes', () => {
63
62
  end class
64
63
  `);
65
64
  program.validate();
66
- (0, chai_1.expect)((_a = program.getDiagnostics()[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.classConstructorMissingSuperCall().message);
65
+ (0, testHelpers_spec_1.expectDiagnostics)(program, [
66
+ DiagnosticMessages_1.DiagnosticMessages.classConstructorMissingSuperCall()
67
+ ]);
67
68
  });
68
69
  it('access modifier is option for override', () => {
69
- var _a;
70
70
  let file = program.setFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
71
71
  class Animal
72
72
  sub move()
@@ -79,13 +79,12 @@ describe('BrsFile BrighterScript classes', () => {
79
79
  end class
80
80
  `);
81
81
  program.validate();
82
- (0, chai_1.expect)((_a = program.getDiagnostics()[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
82
+ (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
83
83
  let duckClass = file.parser.references.classStatements.find(x => x.name.text.toLowerCase() === 'duck');
84
84
  (0, chai_1.expect)(duckClass).to.exist;
85
85
  (0, chai_1.expect)(duckClass.memberMap['move']).to.exist;
86
86
  });
87
87
  it('supports various namespace configurations', () => {
88
- var _a;
89
88
  program.setFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
90
89
  class Animal
91
90
  sub new()
@@ -106,11 +105,10 @@ describe('BrsFile BrighterScript classes', () => {
106
105
  end namespace
107
106
  `);
108
107
  program.validate();
109
- (0, chai_1.expect)((_a = program.getDiagnostics()[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
108
+ (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
110
109
  });
111
110
  describe('super', () => {
112
111
  it('always requires super call in child constructor', () => {
113
- var _a;
114
112
  program.setFile('source/main.bs', `
115
113
  class Bird
116
114
  end class
@@ -120,10 +118,11 @@ describe('BrsFile BrighterScript classes', () => {
120
118
  end class
121
119
  `);
122
120
  program.validate();
123
- (0, chai_1.expect)((_a = program.getDiagnostics()[0]) === null || _a === void 0 ? void 0 : _a.message).to.eql(DiagnosticMessages_1.DiagnosticMessages.classConstructorMissingSuperCall().message);
121
+ (0, testHelpers_spec_1.expectDiagnostics)(program, [
122
+ DiagnosticMessages_1.DiagnosticMessages.classConstructorMissingSuperCall()
123
+ ]);
124
124
  });
125
125
  it('requires super call in child when parent has own `new` method', () => {
126
- var _a;
127
126
  program.setFile('source/main.bs', `
128
127
  class Bird
129
128
  sub new()
@@ -135,10 +134,11 @@ describe('BrsFile BrighterScript classes', () => {
135
134
  end class
136
135
  `);
137
136
  program.validate();
138
- (0, chai_1.expect)((_a = program.getDiagnostics()[0]) === null || _a === void 0 ? void 0 : _a.message).to.eql(DiagnosticMessages_1.DiagnosticMessages.classConstructorMissingSuperCall().message);
137
+ (0, testHelpers_spec_1.expectDiagnostics)(program, [
138
+ DiagnosticMessages_1.DiagnosticMessages.classConstructorMissingSuperCall()
139
+ ]);
139
140
  });
140
141
  it('allows non-`m` expressions and statements before the super call', () => {
141
- var _a;
142
142
  program.setFile('source/main.bs', `
143
143
  class Bird
144
144
  sub new(name)
@@ -154,7 +154,7 @@ describe('BrsFile BrighterScript classes', () => {
154
154
  end class
155
155
  `);
156
156
  program.validate();
157
- (0, chai_1.expect)((_a = program.getDiagnostics()[0]) === null || _a === void 0 ? void 0 : _a.message).to.be.undefined;
157
+ (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
158
158
  });
159
159
  it('allows non-`m` expressions and statements before the super call', () => {
160
160
  program.setFile('source/main.bs', `
@@ -170,13 +170,7 @@ describe('BrsFile BrighterScript classes', () => {
170
170
  end class
171
171
  `);
172
172
  program.validate();
173
- (0, chai_1.expect)(program.getDiagnostics().map(x => ({ message: x.message, range: x.range }))).to.eql([{
174
- message: DiagnosticMessages_1.DiagnosticMessages.classConstructorIllegalUseOfMBeforeSuperCall().message,
175
- range: vscode_languageserver_1.Range.create(7, 24, 7, 25)
176
- }, {
177
- message: DiagnosticMessages_1.DiagnosticMessages.classConstructorIllegalUseOfMBeforeSuperCall().message,
178
- range: vscode_languageserver_1.Range.create(7, 33, 7, 34)
179
- }]);
173
+ (0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.classConstructorIllegalUseOfMBeforeSuperCall()), { range: vscode_languageserver_1.Range.create(7, 24, 7, 25) }), Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.classConstructorIllegalUseOfMBeforeSuperCall()), { range: vscode_languageserver_1.Range.create(7, 33, 7, 34) })]);
180
174
  });
181
175
  });
182
176
  describe('transpile', () => {
@@ -666,8 +660,7 @@ describe('BrsFile BrighterScript classes', () => {
666
660
  });
667
661
  });
668
662
  it('detects using `new` keyword on non-classes', () => {
669
- var _a;
670
- program.setFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
663
+ program.setFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.brs' }, `
671
664
  sub quack()
672
665
  end sub
673
666
  sub main()
@@ -675,37 +668,41 @@ describe('BrsFile BrighterScript classes', () => {
675
668
  end sub
676
669
  `);
677
670
  program.validate();
678
- (0, chai_1.expect)((_a = program.getDiagnostics()[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.expressionIsNotConstructable('sub').message);
671
+ (0, testHelpers_spec_1.expectDiagnostics)(program, [
672
+ DiagnosticMessages_1.DiagnosticMessages.expressionIsNotConstructable('sub')
673
+ ]);
679
674
  });
680
675
  it('detects missing call to super', () => {
681
- var _a;
682
- program.setFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
676
+ program.setFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.brs' }, `
683
677
  class Animal
684
- sub new()
678
+ sub new ()
685
679
  end sub
686
680
  end class
687
681
  class Duck extends Animal
688
- sub new()
682
+ sub new ()
689
683
  end sub
690
684
  end class
691
685
  `);
692
686
  program.validate();
693
- (0, chai_1.expect)((_a = program.getDiagnostics()[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.classConstructorMissingSuperCall().message);
687
+ (0, testHelpers_spec_1.expectDiagnostics)(program, [
688
+ DiagnosticMessages_1.DiagnosticMessages.classConstructorMissingSuperCall()
689
+ ]);
694
690
  });
695
691
  it.skip('detects calls to unknown m methods', () => {
696
- var _a;
697
- program.setFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
692
+ program.setFile('source/main.brs', `
698
693
  class Animal
699
- sub new()
694
+ sub new ()
700
695
  m.methodThatDoesNotExist()
701
696
  end sub
702
697
  end class
703
698
  `);
704
699
  program.validate();
705
- (0, chai_1.expect)((_a = program.getDiagnostics()[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.methodDoesNotExistOnType('methodThatDoesNotExist', 'Animal'));
700
+ (0, testHelpers_spec_1.expectDiagnostics)(program, [
701
+ DiagnosticMessages_1.DiagnosticMessages.methodDoesNotExistOnType('methodThatDoesNotExist', 'Animal')
702
+ ]);
706
703
  });
707
704
  it('detects duplicate member names', () => {
708
- program.setFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
705
+ program.setFile('source/main.bs', `
709
706
  class Animal
710
707
  public name
711
708
  public name
@@ -719,32 +716,26 @@ describe('BrsFile BrighterScript classes', () => {
719
716
  end class
720
717
  `);
721
718
  program.validate();
722
- let diagnostics = program.getDiagnostics().map(x => {
723
- return {
724
- code: x.code,
725
- message: x.message,
726
- range: x.range,
727
- severity: vscode_languageserver_1.DiagnosticSeverity.Error
728
- };
729
- });
730
- (0, chai_1.expect)(diagnostics).to.eql([Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.duplicateIdentifier('name')), { range: vscode_languageserver_1.Range.create(3, 23, 3, 27) }), Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.duplicateIdentifier('name')), { range: vscode_languageserver_1.Range.create(4, 27, 4, 31) }), Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.duplicateIdentifier('age')), { range: vscode_languageserver_1.Range.create(8, 27, 8, 30) }), Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.duplicateIdentifier('age')), { range: vscode_languageserver_1.Range.create(10, 23, 10, 26) })]);
719
+ (0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.duplicateIdentifier('name')), { range: vscode_languageserver_1.Range.create(3, 23, 3, 27) }), Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.duplicateIdentifier('name')), { range: vscode_languageserver_1.Range.create(4, 27, 4, 31) }), Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.duplicateIdentifier('age')), { range: vscode_languageserver_1.Range.create(8, 27, 8, 30) }), Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.duplicateIdentifier('age')), { range: vscode_languageserver_1.Range.create(10, 23, 10, 26) })]);
731
720
  });
732
721
  it('detects mismatched member type in child class', () => {
733
- program.setFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
722
+ program.setFile('source/main.bs', `
734
723
  class Animal
735
724
  public name
736
725
  end class
737
726
  class Duck extends Animal
738
- public function name()
727
+ public override function name()
739
728
  return "Donald"
740
729
  end function
741
730
  end class
742
731
  `);
743
732
  program.validate();
744
- (0, chai_1.expect)(program.getDiagnostics().map(x => x.message).sort()[0]).to.eql(DiagnosticMessages_1.DiagnosticMessages.classChildMemberDifferentMemberTypeThanAncestor('method', 'field', 'Animal').message);
733
+ (0, testHelpers_spec_1.expectDiagnostics)(program, [
734
+ DiagnosticMessages_1.DiagnosticMessages.classChildMemberDifferentMemberTypeThanAncestor('method', 'field', 'Animal')
735
+ ]);
745
736
  });
746
737
  it('allows untyped overridden field in child class', () => {
747
- program.setFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
738
+ program.setFile('source/main.bs', `
748
739
  class Animal
749
740
  public name
750
741
  end class
@@ -781,15 +772,15 @@ describe('BrsFile BrighterScript classes', () => {
781
772
  end class
782
773
  `);
783
774
  program.validate();
784
- (0, chai_1.expect)(program.getDiagnostics().map(x => x.message).sort()).to.eql([
785
- DiagnosticMessages_1.DiagnosticMessages.cannotFindType('Person').message,
786
- DiagnosticMessages_1.DiagnosticMessages.childFieldTypeNotAssignableToBaseProperty('Duck', 'Bird', 'age', 'float', 'integer').message,
787
- DiagnosticMessages_1.DiagnosticMessages.childFieldTypeNotAssignableToBaseProperty('Duck', 'Bird', 'name', 'integer', 'string').message,
788
- DiagnosticMessages_1.DiagnosticMessages.childFieldTypeNotAssignableToBaseProperty('Duck', 'Bird', 'owner', 'string', 'Person').message
775
+ (0, testHelpers_spec_1.expectDiagnostics)(program, [
776
+ DiagnosticMessages_1.DiagnosticMessages.cannotFindType('Person'),
777
+ DiagnosticMessages_1.DiagnosticMessages.childFieldTypeNotAssignableToBaseProperty('Duck', 'Bird', 'age', 'float', 'integer'),
778
+ DiagnosticMessages_1.DiagnosticMessages.childFieldTypeNotAssignableToBaseProperty('Duck', 'Bird', 'name', 'integer', 'string'),
779
+ DiagnosticMessages_1.DiagnosticMessages.childFieldTypeNotAssignableToBaseProperty('Duck', 'Bird', 'owner', 'string', 'Person')
789
780
  ]);
790
781
  });
791
782
  it('detects overridden methods without override keyword', () => {
792
- program.setFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
783
+ program.setFile('source/main.bs', `
793
784
  class Animal
794
785
  sub speak()
795
786
  end sub
@@ -800,10 +791,12 @@ describe('BrsFile BrighterScript classes', () => {
800
791
  end class
801
792
  `);
802
793
  program.validate();
803
- (0, chai_1.expect)(program.getDiagnostics()[0]).to.exist.and.to.include(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.missingOverrideKeyword('Animal')));
794
+ (0, testHelpers_spec_1.expectDiagnostics)(program, [
795
+ DiagnosticMessages_1.DiagnosticMessages.missingOverrideKeyword('Animal')
796
+ ]);
804
797
  });
805
798
  it('detects overridden methods with different visibility', () => {
806
- program.setFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
799
+ program.setFile('source/main.bs', `
807
800
  class Animal
808
801
  sub speakInPublic()
809
802
  end sub
@@ -822,12 +815,14 @@ describe('BrsFile BrighterScript classes', () => {
822
815
  end class
823
816
  `);
824
817
  program.validate();
825
- (0, chai_1.expect)(program.getDiagnostics()[0]).to.exist.and.to.include(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.mismatchedOverriddenMemberVisibility('Duck', 'speakInPublic', 'private', 'public', 'Animal')));
826
- (0, chai_1.expect)(program.getDiagnostics()[1]).to.exist.and.to.include(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.mismatchedOverriddenMemberVisibility('Duck', 'speakWithFriends', 'public', 'protected', 'Animal')));
827
- (0, chai_1.expect)(program.getDiagnostics()[2]).to.exist.and.to.include(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.mismatchedOverriddenMemberVisibility('Duck', 'speakWithFamily', 'public', 'private', 'Animal')));
818
+ (0, testHelpers_spec_1.expectDiagnostics)(program, [
819
+ DiagnosticMessages_1.DiagnosticMessages.mismatchedOverriddenMemberVisibility('Duck', 'speakInPublic', 'private', 'public', 'Animal'),
820
+ DiagnosticMessages_1.DiagnosticMessages.mismatchedOverriddenMemberVisibility('Duck', 'speakWithFriends', 'public', 'protected', 'Animal'),
821
+ DiagnosticMessages_1.DiagnosticMessages.mismatchedOverriddenMemberVisibility('Duck', 'speakWithFamily', 'public', 'private', 'Animal')
822
+ ]);
828
823
  });
829
824
  it('allows overridden methods with matching visibility', () => {
830
- program.setFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
825
+ program.setFile('source/main.bs', `
831
826
  class Animal
832
827
  sub speakInPublic()
833
828
  end sub
@@ -846,50 +841,123 @@ describe('BrsFile BrighterScript classes', () => {
846
841
  end class
847
842
  `);
848
843
  program.validate();
849
- (0, chai_1.expect)(program.getDiagnostics()).to.be.empty;
844
+ (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
850
845
  });
851
- it('detects extending unknown parent class', () => {
852
- program.setFile('source/main.brs', `
853
- class Duck extends Animal
854
- sub speak()
855
- end sub
856
- end class
857
- `);
858
- program.validate();
859
- (0, chai_1.expect)(program.getDiagnostics()[0]).to.exist.and.to.deep.include(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.classCouldNotBeFound('Animal', 'source')), { range: vscode_languageserver_1.Range.create(1, 31, 1, 37) }));
846
+ describe('detects unknown parent class', () => {
847
+ it('non-namespaced parent from outside namespace', () => {
848
+ program.setFile('source/main.bs', `
849
+ class Duck extends Animal
850
+ sub speak()
851
+ end sub
852
+ end class
853
+
854
+ namespace Vertibrates
855
+ class Animal
856
+ end class
857
+ end namespace
858
+ `);
859
+ program.validate();
860
+ (0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.classCouldNotBeFound('Animal', 'source')), { range: vscode_languageserver_1.Range.create(1, 35, 1, 41) })]);
861
+ });
862
+ it('non-namespaced parent from within namespace', () => {
863
+ program.setFile('source/main.bs', `
864
+ namespace Vertibrates
865
+ class Duck extends Animal
866
+ sub speak()
867
+ end sub
868
+ end class
869
+ end namespace
870
+ `);
871
+ program.validate();
872
+ (0, testHelpers_spec_1.expectDiagnostics)(program, [
873
+ DiagnosticMessages_1.DiagnosticMessages.classCouldNotBeFound('Animal', 'source')
874
+ ]);
875
+ });
876
+ it('non-namespaced name from outside namespace alongside existing namespace', () => {
877
+ program.setFile('source/main.bs', `
878
+ namespace Vertibrates
879
+ class Animal
880
+ end class
881
+ end namespace
882
+
883
+ class Duck extends Animal
884
+ sub speak()
885
+ end sub
886
+ end class
887
+ `);
888
+ program.validate();
889
+ (0, testHelpers_spec_1.expectDiagnostics)(program, [
890
+ DiagnosticMessages_1.DiagnosticMessages.classCouldNotBeFound('Animal', 'source')
891
+ ]);
892
+ });
893
+ it('namespaced parent class from outside namespace', () => {
894
+ program.setFile('source/vertibrates.bs', `
895
+ namespace Vertibrates
896
+ class Bird
897
+ end class
898
+ end namespace
899
+ `);
900
+ program.setFile('source/Duck.bs', `
901
+ class Duck extends Vertibrates.GroundedBird
902
+ sub speak()
903
+ end sub
904
+ end class
905
+ `);
906
+ program.validate();
907
+ //TODO replace this with `expectDiagnostics` once we fix the duplicate diagnostic one-per-file for missing base classes issue
908
+ (0, chai_1.expect)(program.getDiagnostics()[0].message).to.eql(DiagnosticMessages_1.DiagnosticMessages.classCouldNotBeFound('Vertibrates.GroundedBird', 'source').message);
909
+ });
910
+ it('namespaced parent class from inside namespace', () => {
911
+ program.setFile('source/vertibrates.bs', `
912
+ namespace Vertibrates
913
+ class Bird
914
+ end class
915
+ end namespace
916
+ `);
917
+ program.setFile('source/Duck.bs', `
918
+ namespace Birdies
919
+ class Duck extends Vertibrates.GroundedBird
920
+ sub speak()
921
+ end sub
922
+ end class
923
+ end namespace
924
+ `);
925
+ program.validate();
926
+ //TODO replace this with `expectDiagnostics` once we fix the duplicate diagnostic one-per-file for missing base classes issue
927
+ (0, chai_1.expect)(program.getDiagnostics()[0].message).to.eql(DiagnosticMessages_1.DiagnosticMessages.classCouldNotBeFound('Vertibrates.GroundedBird', 'source').message);
928
+ });
860
929
  });
861
930
  it('catches newable class without namespace name', () => {
862
- var _a;
863
931
  program.setFile('source/main.bs', `
864
932
  namespace NameA.NameB
865
933
  class Duck
866
934
  end class
867
- end namespace
935
+ end namespace
868
936
  sub main()
869
937
  ' this should be an error because the proper name is NameA.NameB.Duck"
870
938
  d = new Duck()
871
939
  end sub
872
- `);
940
+ `);
873
941
  program.validate();
874
- (0, chai_1.expect)((_a = program.getDiagnostics()[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.classCouldNotBeFound('Duck', 'source').message);
942
+ (0, testHelpers_spec_1.expectDiagnostics)(program, [
943
+ DiagnosticMessages_1.DiagnosticMessages.classCouldNotBeFound('Duck', 'source')
944
+ ]);
875
945
  });
876
946
  it('supports newable class namespace inference', () => {
877
- var _a;
878
- program.setFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
947
+ program.setFile('source/main.bs', `
879
948
  namespace NameA.NameB
880
949
  class Duck
881
950
  end class
882
- sub main()
951
+ sub main()
883
952
  d = new Duck()
884
953
  end sub
885
954
  end namespace
886
- `);
955
+ `);
887
956
  program.validate();
888
- (0, chai_1.expect)((_a = program.getDiagnostics()[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
957
+ (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
889
958
  });
890
959
  it('catches extending unknown namespaced class', () => {
891
- var _a;
892
- program.setFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
960
+ program.setFile('source/main.bs', `
893
961
  namespace NameA.NameB
894
962
  class Animal
895
963
  end class
@@ -898,89 +966,98 @@ describe('BrsFile BrighterScript classes', () => {
898
966
  end namespace
899
967
  `);
900
968
  program.validate();
901
- (0, chai_1.expect)((_a = program.getDiagnostics()[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.classCouldNotBeFound('NameA.NameB.Animal1', 'source').message);
969
+ (0, testHelpers_spec_1.expectDiagnostics)(program, [
970
+ DiagnosticMessages_1.DiagnosticMessages.classCouldNotBeFound('NameA.NameB.Animal1', 'source')
971
+ ]);
902
972
  });
903
973
  it('supports omitting namespace prefix for items in same namespace', () => {
904
- var _a;
905
- program.setFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
974
+ program.setFile('source/main.bs', `
906
975
  namespace NameA.NameB
907
976
  class Animal
908
977
  end class
909
978
  class Duck extends Animal
910
979
  end class
911
- end namespace
912
- `);
980
+ end namespace
981
+ `);
913
982
  program.validate();
914
- (0, chai_1.expect)((_a = program.getDiagnostics()[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
983
+ (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
915
984
  });
916
985
  it('catches duplicate root-level class declarations', () => {
917
- var _a;
918
- program.setFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
986
+ program.setFile('source/main.bs', `
919
987
  class Animal
920
988
  end class
921
989
  class Animal
990
+ end class
922
991
  `);
923
992
  program.validate();
924
- (0, chai_1.expect)((_a = program.getDiagnostics()[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.duplicateClassDeclaration('source', 'Animal').message);
993
+ (0, testHelpers_spec_1.expectDiagnostics)(program, [
994
+ DiagnosticMessages_1.DiagnosticMessages.duplicateClassDeclaration('source', 'Animal')
995
+ ]);
925
996
  });
926
997
  it('catches duplicate namespace-level class declarations', () => {
927
- var _a;
928
- program.setFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
998
+ program.setFile('source/main.bs', `
929
999
  namespace NameA.NameB
930
1000
  class Animal
931
1001
  end class
932
1002
  class Animal
1003
+ end class
933
1004
  end namespace
934
1005
  `);
935
1006
  program.validate();
936
- (0, chai_1.expect)((_a = program.getDiagnostics()[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.duplicateClassDeclaration('source', 'NameA.NameB.Animal').message);
1007
+ (0, testHelpers_spec_1.expectDiagnostics)(program, [
1008
+ DiagnosticMessages_1.DiagnosticMessages.duplicateClassDeclaration('source', 'NameA.NameB.Animal')
1009
+ ]);
937
1010
  });
938
1011
  it('catches namespaced class name which is the same as a global class', () => {
939
- var _a;
940
- program.setFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
1012
+ program.setFile('source/main.bs', `
941
1013
  namespace NameA.NameB
942
1014
  class Animal
943
1015
  end class
944
- end namespace
1016
+ end namespace
945
1017
  class Animal
946
1018
  end class
947
1019
  `);
948
1020
  program.validate();
949
- (0, chai_1.expect)((_a = program.getDiagnostics()[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.namespacedClassCannotShareNamewithNonNamespacedClass('Animal').message);
1021
+ (0, testHelpers_spec_1.expectDiagnostics)(program, [
1022
+ DiagnosticMessages_1.DiagnosticMessages.namespacedClassCannotShareNamewithNonNamespacedClass('Animal').message
1023
+ ]);
950
1024
  });
951
1025
  it('catches class with same name as function', () => {
952
- var _a;
953
1026
  program.setFile('source/main.bs', `
954
1027
  class Animal
955
1028
  end class
956
- sub Animal()
1029
+ sub Animal()
957
1030
  end sub
958
- `);
1031
+ `);
959
1032
  program.validate();
960
- (0, chai_1.expect)((_a = program.getDiagnostics()[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.functionCannotHaveSameNameAsClass('Animal').message);
1033
+ (0, testHelpers_spec_1.expectDiagnostics)(program, [
1034
+ DiagnosticMessages_1.DiagnosticMessages.functionCannotHaveSameNameAsClass('Animal').message
1035
+ ]);
961
1036
  });
962
1037
  it('catches class with same name (but different case) as function', () => {
963
- var _a;
964
1038
  program.setFile('source/main.bs', `
965
1039
  class ANIMAL
966
1040
  end class
967
- sub animal()
1041
+ sub animal()
968
1042
  end sub
969
- `);
1043
+ `);
970
1044
  program.validate();
971
- (0, chai_1.expect)((_a = program.getDiagnostics()[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.functionCannotHaveSameNameAsClass('animal').message);
1045
+ (0, testHelpers_spec_1.expectDiagnostics)(program, [
1046
+ DiagnosticMessages_1.DiagnosticMessages.functionCannotHaveSameNameAsClass('animal').message
1047
+ ]);
972
1048
  });
973
1049
  it('catches variable with same name as class', () => {
974
- var _a;
975
1050
  program.setFile('source/main.bs', `
976
1051
  class Animal
977
1052
  end class
978
- sub main()
1053
+ sub main()
979
1054
  animal = new Animal()
980
1055
  end sub
981
- `);
1056
+ `);
982
1057
  program.validate();
983
- (0, chai_1.expect)((_a = program.getDiagnostics()[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.localVarSameNameAsClass('Animal').message);
1058
+ (0, testHelpers_spec_1.expectDiagnostics)(program, [
1059
+ DiagnosticMessages_1.DiagnosticMessages.localVarSameNameAsClass('Animal').message
1060
+ ]);
984
1061
  });
985
1062
  it('allows extending classes with more than one dot in the filename', () => {
986
1063
  program.setFile('source/testclass.bs', `
@@ -988,21 +1065,21 @@ describe('BrsFile BrighterScript classes', () => {
988
1065
  end class
989
1066
 
990
1067
  class Bar extends Foo
991
- sub new()
1068
+ sub new ()
992
1069
  super()
993
1070
  end sub
994
1071
  end class
995
1072
  `);
996
1073
  program.setFile('source/testclass_no_testdot.bs', `
997
1074
  class BarNoDot extends Foo
998
- sub new()
1075
+ sub new ()
999
1076
  super()
1000
1077
  end sub
1001
1078
  end class
1002
1079
  `);
1003
1080
  program.setFile('source/testclass.dot.bs', `
1004
1081
  class BarDot extends Foo
1005
- sub new()
1082
+ sub new ()
1006
1083
  super()
1007
1084
  end sub
1008
1085
  end class
@@ -1027,7 +1104,7 @@ describe('BrsFile BrighterScript classes', () => {
1027
1104
  testTranspile(`
1028
1105
  namespace App
1029
1106
  class ClassC extends ClassB
1030
- sub new()
1107
+ sub new ()
1031
1108
  super()
1032
1109
  end sub
1033
1110
  end class
@@ -1058,7 +1135,7 @@ describe('BrsFile BrighterScript classes', () => {
1058
1135
  class ClassB extends ClassA
1059
1136
  end class
1060
1137
  end namespace
1061
- `, `
1138
+ `, `
1062
1139
  function __App_ClassB_builder()
1063
1140
  instance = __ClassA_builder()
1064
1141
  instance.super0_new = instance.new
@@ -1085,112 +1162,142 @@ describe('BrsFile BrighterScript classes', () => {
1085
1162
  });
1086
1163
  describe('getHover', () => {
1087
1164
  const animalClassCode = `
1088
- class Animal
1089
- kind as string
1090
- isHungry as boolean
1165
+ class Animal
1166
+ kind as string
1167
+ isHungry as boolean
1091
1168
 
1092
- sub new(kind as string)
1093
- m.kind = kind
1094
- m.isHungry = true ' born hungry
1095
- end sub
1169
+ sub new (kind as string)
1170
+ m.kind = kind
1171
+ m.isHungry = true ' born hungry
1172
+ end sub
1096
1173
 
1097
- sub eat(foodAmount as integer)
1098
- if foodAmount > 100
1099
- m.isHungry = false
1100
- end if
1101
- end sub
1174
+ sub eat(foodAmount as integer)
1175
+ if foodAmount > 100
1176
+ m.isHungry = false
1177
+ end if
1178
+ end sub
1102
1179
 
1103
- sub sleep()
1104
- m.isHungry = false
1105
- end sub
1180
+ sub sleep()
1181
+ m.isHungry = false
1182
+ end sub
1106
1183
 
1107
- end class
1184
+ end class
1108
1185
 
1109
- class Dog extends Animal
1110
- breed as string
1111
- sub new(breed as string)
1112
- super("Dog")
1113
- m.breed = breed
1114
- end sub
1186
+ class Dog extends Animal
1187
+ breed as string
1188
+ sub new (breed as string)
1189
+ super("Dog")
1190
+ m.breed = breed
1191
+ end sub
1115
1192
 
1116
- sub snooze()
1117
- m.sleep()
1118
- end sub
1119
- end class
1193
+ sub snooze()
1194
+ m.sleep()
1195
+ end sub
1196
+ end class
1120
1197
 
1121
- class DogHouse
1122
- puppy as Dog
1123
- sub new(pup as Dog)
1124
- m.puppy = pup
1125
- end sub
1126
- end class
1198
+ class DogHouse
1199
+ puppy as Dog
1200
+ sub new (pup as Dog)
1201
+ m.puppy = pup
1202
+ end sub
1203
+ end class
1127
1204
 
1128
- sub main()
1129
- snoopy = new Dog("Beagle")
1130
- biplane = new DogHouse(snoopy)
1131
- print snoopy.kind ' Dog
1132
- print snoopy.breed ' Beagle
1133
- print snoopy.isHungry ' true
1134
- feedAnimal(biplane.puppy)
1135
- print snoopy.isHungry ' false
1136
- end sub
1205
+ sub main()
1206
+ snoopy = new Dog("Beagle")
1207
+ biplane = new DogHouse(snoopy)
1208
+ print snoopy.kind ' Dog
1209
+ print snoopy.breed ' Beagle
1210
+ print snoopy.isHungry ' true
1211
+ feedAnimal(biplane.puppy)
1212
+ print snoopy.isHungry ' false
1213
+ end sub
1137
1214
 
1138
- sub feedAnimal(beast as Animal)
1139
- beast.eat(100)
1140
- end sub
1215
+ sub feedAnimal(beast as Animal)
1216
+ beast.eat(100)
1217
+ end sub
1141
1218
  `;
1142
1219
  it('correctly parses the file', () => {
1143
1220
  program.setFile('source/animal.bs', animalClassCode);
1144
1221
  program.validate();
1145
- (0, chai_1.expect)(program.getDiagnostics().length).to.equal(0);
1222
+ (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1146
1223
  });
1147
1224
  it('gets the correct text for m', () => {
1148
1225
  let animalCode = program.setFile('source/animal.bs', animalClassCode);
1149
1226
  program.validate();
1150
- let hover = animalCode.getHover(vscode_languageserver_1.Position.create(6, 17));
1151
- (0, chai_1.expect)(hover).to.exist;
1152
- (0, chai_1.expect)(hover.contents).to.equal('m as Animal');
1153
- hover = animalCode.getHover(vscode_languageserver_1.Position.create(26, 17));
1154
- (0, chai_1.expect)(hover).to.exist;
1155
- (0, chai_1.expect)(hover.contents).to.equal('m as Dog');
1227
+ let hover = animalCode.getHover(vscode_languageserver_1.Position.create(6, 21));
1228
+ (0, chai_1.expect)(hover === null || hover === void 0 ? void 0 : hover.contents).to.equal([
1229
+ '```brightscript',
1230
+ 'm as Animal',
1231
+ '```'
1232
+ ].join('\n'));
1233
+ hover = animalCode.getHover(vscode_languageserver_1.Position.create(26, 20));
1234
+ (0, chai_1.expect)(hover === null || hover === void 0 ? void 0 : hover.contents).to.equal([
1235
+ '```brightscript',
1236
+ 'm as Dog',
1237
+ '```'
1238
+ ].join('\n'));
1156
1239
  });
1157
1240
  it('gets the correct text for m.field', () => {
1158
1241
  let animalCode = program.setFile('source/animal.bs', animalClassCode);
1159
1242
  program.validate();
1160
- let hover = animalCode.getHover(vscode_languageserver_1.Position.create(6, 19));
1161
- (0, chai_1.expect)(hover).to.exist;
1162
- (0, chai_1.expect)(hover.contents).to.equal('Animal.kind as string');
1163
- hover = animalCode.getHover(vscode_languageserver_1.Position.create(26, 19));
1164
- (0, chai_1.expect)(hover).to.exist;
1165
- (0, chai_1.expect)(hover.contents).to.equal('Dog.breed as string');
1243
+ let hover = animalCode.getHover(vscode_languageserver_1.Position.create(6, 26));
1244
+ (0, chai_1.expect)(hover === null || hover === void 0 ? void 0 : hover.contents).to.equal([
1245
+ '```brightscript',
1246
+ 'Animal.kind as string',
1247
+ '```'
1248
+ ].join('\n'));
1249
+ hover = animalCode.getHover(vscode_languageserver_1.Position.create(26, 25));
1250
+ (0, chai_1.expect)(hover === null || hover === void 0 ? void 0 : hover.contents).to.equal([
1251
+ '```brightscript',
1252
+ 'Dog.breed as string',
1253
+ '```'
1254
+ ].join('\n'));
1166
1255
  });
1167
1256
  it('gets the correct text for m.method', () => {
1168
1257
  let animalCode = program.setFile('source/animal.bs', animalClassCode);
1169
1258
  program.validate();
1170
- let hover = animalCode.getHover(vscode_languageserver_1.Position.create(30, 21));
1171
- (0, chai_1.expect)(hover).to.exist;
1172
- (0, chai_1.expect)(hover.contents).to.equal('sub Animal.sleep() as void');
1259
+ let hover = animalCode.getHover(vscode_languageserver_1.Position.create(30, 25));
1260
+ (0, chai_1.expect)(hover === null || hover === void 0 ? void 0 : hover.contents).to.equal([
1261
+ '```brightscript',
1262
+ 'sub Animal.sleep() as void',
1263
+ '```'
1264
+ ].join('\n'));
1173
1265
  });
1174
1266
  it('gets the correct text for obj.field', () => {
1175
1267
  let animalCode = program.setFile('source/animal.brs', animalClassCode);
1176
1268
  program.validate();
1177
- let hover = animalCode.getHover(vscode_languageserver_1.Position.create(46, 29));
1269
+ let hover = animalCode.getHover(vscode_languageserver_1.Position.create(46, 33));
1178
1270
  (0, chai_1.expect)(hover).to.exist;
1179
1271
  //TODO TYPES: This should probably say 'Animal.isHungry ...' because that field is defined in Animal
1180
- (0, chai_1.expect)(hover.contents).to.equal('Dog.isHungry as boolean');
1272
+ (0, chai_1.expect)(hover === null || hover === void 0 ? void 0 : hover.contents).to.equal([
1273
+ '```brightscript',
1274
+ 'Dog.isHungry as boolean',
1275
+ '```'
1276
+ ].join('\n'));
1181
1277
  });
1182
1278
  it('gets the correct text for obj.method', () => {
1183
- let animalCode = program.setFile('source/animal.bs', animalClassCode);
1279
+ let animalCode = program.setFile('source/animal.bs', `
1280
+ sub feedAnimal(beast as Animal)
1281
+ beast.eat(100)
1282
+ end sub
1283
+ class Animal
1284
+ sub eat(foodAmount as integer)
1285
+ end sub
1286
+ end class
1287
+ `);
1184
1288
  program.validate();
1185
- let hover = animalCode.getHover(vscode_languageserver_1.Position.create(52, 21));
1186
- (0, chai_1.expect)(hover).to.exist;
1187
- (0, chai_1.expect)(hover.contents).to.equal('sub Animal.eat(foodAmount as integer) as void');
1289
+ let hover = animalCode.getHover(vscode_languageserver_1.Position.create(2, 29));
1290
+ (0, chai_1.expect)(hover === null || hover === void 0 ? void 0 : hover.contents).to.equal([
1291
+ '```brightscript',
1292
+ 'sub Animal.eat(foodAmount as integer) as void',
1293
+ '```'
1294
+ ].join('\n'));
1188
1295
  });
1189
1296
  });
1190
1297
  describe('getHover class members', () => {
1191
1298
  const testCode = `
1192
1299
  class Foo
1193
- sub new(name as string)
1300
+ sub new (name as string)
1194
1301
  end sub
1195
1302
  end class
1196
1303
 
@@ -1202,17 +1309,17 @@ describe('BrsFile BrighterScript classes', () => {
1202
1309
  function getInt() as integer
1203
1310
  return 1
1204
1311
  end function
1205
- end class
1312
+ end class
1206
1313
 
1207
1314
  class Buz
1208
1315
  myInt as integer
1209
- sub new(i as integer)
1210
- myInt = i
1316
+ sub new (i as integer)
1317
+ myInt = i
1211
1318
  end sub
1212
1319
  end class
1213
1320
 
1214
1321
  class Bee extends Buz
1215
- sub new(i as integer)
1322
+ sub new (i as integer)
1216
1323
  super(i)
1217
1324
  end sub
1218
1325
 
@@ -1230,90 +1337,110 @@ describe('BrsFile BrighterScript classes', () => {
1230
1337
  let file = program.setFile('source/fooBar.bs', testCode);
1231
1338
  program.validate();
1232
1339
  let hover = file.getHover(vscode_languageserver_1.Position.create(8, 34)); // new Foo("hello")
1233
- (0, chai_1.expect)(hover).to.exist;
1234
- (0, chai_1.expect)(hover.contents).to.equal('new Foo(name as string)');
1340
+ (0, chai_1.expect)(hover === null || hover === void 0 ? void 0 : hover.contents).to.equal([
1341
+ '```brightscript',
1342
+ 'new Foo(name as string)',
1343
+ '```'
1344
+ ].join('\n'));
1235
1345
  });
1236
1346
  it('gets the correct text for created object', () => {
1237
1347
  let file = program.setFile('source/fooBar.bs', testCode);
1238
1348
  program.validate();
1239
1349
  let hover = file.getHover(vscode_languageserver_1.Position.create(8, 23)); // myFoo
1240
- (0, chai_1.expect)(hover).to.exist;
1241
- (0, chai_1.expect)(hover.contents).to.equal('myFoo as Foo');
1350
+ (0, chai_1.expect)(hover === null || hover === void 0 ? void 0 : hover.contents).to.equal([
1351
+ '```brightscript',
1352
+ 'myFoo as Foo',
1353
+ '```'
1354
+ ].join('\n'));
1242
1355
  });
1243
1356
  it('gets the correct text for class declaration', () => {
1244
1357
  let file = program.setFile('source/fooBar.bs', testCode);
1245
1358
  program.validate();
1246
1359
  let hover = file.getHover(vscode_languageserver_1.Position.create(6, 21)); // class Bar
1247
- (0, chai_1.expect)(hover).to.exist;
1248
- (0, chai_1.expect)(hover.contents).to.equal('class Bar');
1360
+ (0, chai_1.expect)(hover === null || hover === void 0 ? void 0 : hover.contents).to.equal([
1361
+ '```brightscript',
1362
+ 'class Bar',
1363
+ '```'
1364
+ ].join('\n'));
1249
1365
  });
1250
1366
  it('gets the correct text for class method declaration', () => {
1251
1367
  let file = program.setFile('source/fooBar.bs', testCode);
1252
1368
  program.validate();
1253
1369
  let hover = file.getHover(vscode_languageserver_1.Position.create(11, 29)); // getInt
1254
- (0, chai_1.expect)(hover).to.exist;
1255
- (0, chai_1.expect)(hover.contents).to.equal('function Bar.getInt() as integer');
1370
+ (0, chai_1.expect)(hover === null || hover === void 0 ? void 0 : hover.contents).to.equal([
1371
+ '```brightscript',
1372
+ 'function Bar.getInt() as integer',
1373
+ '```'
1374
+ ].join('\n'));
1256
1375
  });
1257
1376
  it('gets the correct text for class field declaration', () => {
1258
1377
  let file = program.setFile('source/fooBar.bs', testCode);
1259
1378
  program.validate();
1260
1379
  let hover = file.getHover(vscode_languageserver_1.Position.create(17, 20)); // myInt
1261
- (0, chai_1.expect)(hover).to.exist;
1262
- (0, chai_1.expect)(hover.contents).to.equal('Buz.myInt as integer');
1380
+ (0, chai_1.expect)(hover === null || hover === void 0 ? void 0 : hover.contents).to.equal([
1381
+ '```brightscript',
1382
+ 'Buz.myInt as integer',
1383
+ '```'
1384
+ ].join('\n'));
1263
1385
  });
1264
1386
  it('gets the correct text for super() call', () => {
1265
1387
  let file = program.setFile('source/fooBar.bs', testCode);
1266
1388
  program.validate();
1267
1389
  let hover = file.getHover(vscode_languageserver_1.Position.create(25, 23)); // super() in Bee.new
1268
- (0, chai_1.expect)(hover).to.exist;
1269
- (0, chai_1.expect)(hover.contents).to.equal('new Buz(i as integer)');
1390
+ (0, chai_1.expect)(hover === null || hover === void 0 ? void 0 : hover.contents).to.equal([
1391
+ '```brightscript',
1392
+ 'new Buz(i as integer)',
1393
+ '```'
1394
+ ].join('\n'));
1270
1395
  });
1271
1396
  it('gets the correct text for variable with same name as a member', () => {
1272
1397
  let file = program.setFile('source/fooBar.bs', testCode);
1273
1398
  program.validate();
1274
1399
  let hover = file.getHover(vscode_languageserver_1.Position.create(29, 23)); // myInt in Bee.varSameNameAsMember
1275
- (0, chai_1.expect)(hover).to.exist;
1276
- (0, chai_1.expect)(hover.contents).to.equal('myInt as integer');
1400
+ (0, chai_1.expect)(hover === null || hover === void 0 ? void 0 : hover.contents).to.equal([
1401
+ '```brightscript',
1402
+ 'myInt as integer',
1403
+ '```'
1404
+ ].join('\n'));
1277
1405
  });
1278
1406
  });
1279
1407
  describe('getSymbolTypeFromToken', () => {
1280
1408
  const testClassCode = `
1281
- class KlassA
1282
- function getInt() as integer
1283
- return 1
1284
- end function
1285
-
1286
- sub printInt(i as integer)
1287
- print i
1409
+ sub main()
1410
+ c = new KlassC()
1411
+ a = c.b.getA()
1412
+ num = c.b.getA().getInt()
1413
+ c.b.getA().printInt(num)
1288
1414
  end sub
1289
- end class
1415
+ class KlassA
1416
+ function getInt() as integer
1417
+ return 1
1418
+ end function
1290
1419
 
1291
- class KlassB
1420
+ sub printInt(i as integer)
1421
+ print i
1422
+ end sub
1423
+ end class
1292
1424
 
1293
- function getA() as KlassA
1294
- return new KlassA()
1295
- end function
1296
- end class
1425
+ class KlassB
1297
1426
 
1298
- class KlassC
1299
- public b as KlassB
1427
+ function getA() as KlassA
1428
+ return new KlassA()
1429
+ end function
1430
+ end class
1300
1431
 
1301
- sub new()
1302
- m.b = new KlassB()
1303
- end sub
1304
- end class
1432
+ class KlassC
1433
+ public b as KlassB
1305
1434
 
1306
- sub main()
1307
- c = new KlassC()
1308
- a = c.b.getA()
1309
- num = c.b.getA().getInt()
1310
- c.b.getA().printInt(num)
1311
- end sub
1435
+ sub new ()
1436
+ m.b = new KlassB()
1437
+ end sub
1438
+ end class
1312
1439
  `;
1313
1440
  it('correctly parses the file', () => {
1314
1441
  program.setFile('source/klassTest.bs', testClassCode);
1315
1442
  program.validate();
1316
- (0, chai_1.expect)(program.getDiagnostics().length).to.equal(0);
1443
+ (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1317
1444
  });
1318
1445
  describe('finding tokens', () => {
1319
1446
  let klassCode;
@@ -1330,7 +1457,7 @@ describe('BrsFile BrighterScript classes', () => {
1330
1457
  });
1331
1458
  it('gets correct class for m', () => {
1332
1459
  var _a;
1333
- const position = vscode_languageserver_1.Position.create(22, 17); // 'm' from m.b = new KlassB()
1460
+ const position = vscode_languageserver_1.Position.create(28, 20); // 'm' from m.b = new KlassB()
1334
1461
  const token = klassCode.parser.getTokenAt(position);
1335
1462
  (0, chai_1.expect)(token.text).to.equal('m');
1336
1463
  const func = klassCode.getFunctionExpressionAtPosition(position);
@@ -1340,7 +1467,7 @@ describe('BrsFile BrighterScript classes', () => {
1340
1467
  });
1341
1468
  it('gets correct class for fieldMember', () => {
1342
1469
  var _a;
1343
- const position = vscode_languageserver_1.Position.create(22, 19); // 'b' from m.b = new KlassB()
1470
+ const position = vscode_languageserver_1.Position.create(28, 23); // 'b' from m.b = new KlassB()
1344
1471
  const token = klassCode.parser.getTokenAt(position);
1345
1472
  (0, chai_1.expect)(token.text).to.equal('b');
1346
1473
  const func = klassCode.getFunctionExpressionAtPosition(position);
@@ -1350,7 +1477,7 @@ describe('BrsFile BrighterScript classes', () => {
1350
1477
  });
1351
1478
  it('gets correct class for variable', () => {
1352
1479
  var _a;
1353
- const position = vscode_languageserver_1.Position.create(28, 17); // 'c' from c.b.getA().getInt()
1480
+ const position = vscode_languageserver_1.Position.create(4, 22); // 'c' from c.b.getA().getInt()
1354
1481
  const token = klassCode.parser.getTokenAt(position);
1355
1482
  (0, chai_1.expect)(token.text).to.equal('c');
1356
1483
  const func = klassCode.getFunctionExpressionAtPosition(position);
@@ -1360,7 +1487,7 @@ describe('BrsFile BrighterScript classes', () => {
1360
1487
  });
1361
1488
  it('gets correct class for variable field', () => {
1362
1489
  var _a;
1363
- const position = vscode_languageserver_1.Position.create(28, 19); // 'b' from c.b.getA()
1490
+ const position = vscode_languageserver_1.Position.create(3, 23); // 'b' from c.b.getA()
1364
1491
  const token = klassCode.parser.getTokenAt(position);
1365
1492
  (0, chai_1.expect)(token.text).to.equal('b');
1366
1493
  const func = klassCode.getFunctionExpressionAtPosition(position);
@@ -1369,19 +1496,17 @@ describe('BrsFile BrighterScript classes', () => {
1369
1496
  (0, chai_1.expect)(klass.getName(Parser_1.ParseMode.BrighterScript)).to.equal('KlassB');
1370
1497
  });
1371
1498
  it('gets type and return class for variable function field', () => {
1372
- const position = vscode_languageserver_1.Position.create(28, 23); // 'getA' from c.b.getA()
1499
+ const position = vscode_languageserver_1.Position.create(3, 28); // 'getA' from c.b.getA()
1373
1500
  const token = klassCode.parser.getTokenAt(position);
1374
1501
  (0, chai_1.expect)(token.text).to.equal('getA');
1375
1502
  const func = klassCode.getFunctionExpressionAtPosition(position);
1376
1503
  let { type, symbolContainer } = klassCode.getSymbolTypeFromToken(token, func, mainScope);
1377
- (0, chai_1.expect)(type).to.exist;
1378
1504
  (0, chai_1.expect)((0, reflection_1.isFunctionType)(type)).to.be.true;
1379
- (0, chai_1.expect)(symbolContainer).to.exist;
1380
1505
  (0, chai_1.expect)((0, reflection_1.isCustomType)(symbolContainer)).to.be.true;
1381
1506
  (0, chai_1.expect)(symbolContainer.name).to.equal('KlassA');
1382
1507
  });
1383
1508
  it('gets type and class for field from return value of function', () => {
1384
- const position = vscode_languageserver_1.Position.create(29, 30); // 'getInt' from c.b.getA().getInt()
1509
+ const position = vscode_languageserver_1.Position.create(4, 37); // 'getInt' from c.b.getA().getInt()
1385
1510
  const token = klassCode.parser.getTokenAt(position);
1386
1511
  (0, chai_1.expect)(token.text).to.equal('getInt');
1387
1512
  const func = klassCode.getFunctionExpressionAtPosition(position);
@@ -1397,7 +1522,7 @@ describe('BrsFile BrighterScript classes', () => {
1397
1522
  class Parent
1398
1523
  public function helloWorld()
1399
1524
  end function
1400
- end class
1525
+ end class
1401
1526
  class Child extends Parent
1402
1527
  public helloWorld as string
1403
1528
  end class
@@ -1412,9 +1537,34 @@ describe('BrsFile BrighterScript classes', () => {
1412
1537
  class Child extends Parent
1413
1538
  public function helloWorld()
1414
1539
  end function
1415
- end class
1540
+ end class
1416
1541
  `);
1417
1542
  program.validate();
1418
1543
  });
1544
+ it.skip('detects calling class constructors with too many parameters', () => {
1545
+ program.setFile('source/main.bs', `
1546
+ class Parameterless
1547
+ sub new ()
1548
+ end sub
1549
+ end class
1550
+
1551
+ class OneParam
1552
+ sub new (param1)
1553
+ end sub
1554
+ end class
1555
+
1556
+ sub main()
1557
+ c1 = new Parameterless(1)
1558
+ c2 = new OneParam(1, 2)
1559
+ c2 = new OneParam()
1560
+ end sub
1561
+ `);
1562
+ program.validate();
1563
+ (0, testHelpers_spec_1.expectDiagnostics)(program, [
1564
+ DiagnosticMessages_1.DiagnosticMessages.mismatchArgumentCount(0, 1),
1565
+ DiagnosticMessages_1.DiagnosticMessages.mismatchArgumentCount(1, 2),
1566
+ DiagnosticMessages_1.DiagnosticMessages.mismatchArgumentCount(1, 0)
1567
+ ]);
1568
+ });
1419
1569
  });
1420
1570
  //# sourceMappingURL=BrsFile.Class.spec.js.map