brighterscript 0.70.3 → 0.71.0

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 (61) hide show
  1. package/README.md +3 -0
  2. package/dist/DiagnosticMessages.d.ts +21 -3
  3. package/dist/DiagnosticMessages.js +21 -3
  4. package/dist/DiagnosticMessages.js.map +1 -1
  5. package/dist/LanguageServer.d.ts +24 -0
  6. package/dist/LanguageServer.js +46 -2
  7. package/dist/LanguageServer.js.map +1 -1
  8. package/dist/Program.js +1 -1
  9. package/dist/Program.js.map +1 -1
  10. package/dist/ProgramBuilder.d.ts +1 -1
  11. package/dist/Scope.d.ts +14 -1
  12. package/dist/Scope.js +58 -6
  13. package/dist/Scope.js.map +1 -1
  14. package/dist/astUtils/reflection.d.ts +4 -2
  15. package/dist/astUtils/reflection.js +11 -2
  16. package/dist/astUtils/reflection.js.map +1 -1
  17. package/dist/astUtils/visitors.d.ts +4 -2
  18. package/dist/astUtils/visitors.js.map +1 -1
  19. package/dist/bscPlugin/codeActions/CodeActionsProcessor.d.ts +72 -6
  20. package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +392 -110
  21. package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
  22. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +575 -0
  23. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
  24. package/dist/bscPlugin/definition/DefinitionProvider.js +8 -0
  25. package/dist/bscPlugin/definition/DefinitionProvider.js.map +1 -1
  26. package/dist/bscPlugin/definition/DefinitionProvider.spec.js +84 -0
  27. package/dist/bscPlugin/definition/DefinitionProvider.spec.js.map +1 -1
  28. package/dist/bscPlugin/validation/BrsFileValidator.js +2 -1
  29. package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -1
  30. package/dist/bscPlugin/validation/ScopeValidator.d.ts +6 -0
  31. package/dist/bscPlugin/validation/ScopeValidator.js +70 -0
  32. package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -1
  33. package/dist/files/BrsFile.spec.js +251 -0
  34. package/dist/files/BrsFile.spec.js.map +1 -1
  35. package/dist/lexer/TokenKind.js +4 -2
  36. package/dist/lexer/TokenKind.js.map +1 -1
  37. package/dist/lsp/ProjectManager.d.ts +10 -0
  38. package/dist/lsp/ProjectManager.js +21 -4
  39. package/dist/lsp/ProjectManager.js.map +1 -1
  40. package/dist/lsp/ProjectManager.spec.js +30 -0
  41. package/dist/lsp/ProjectManager.spec.js.map +1 -1
  42. package/dist/parser/AstNode.spec.js +21 -0
  43. package/dist/parser/AstNode.spec.js.map +1 -1
  44. package/dist/parser/Expression.d.ts +26 -2
  45. package/dist/parser/Expression.js +47 -6
  46. package/dist/parser/Expression.js.map +1 -1
  47. package/dist/parser/Parser.d.ts +7 -1
  48. package/dist/parser/Parser.js +200 -20
  49. package/dist/parser/Parser.js.map +1 -1
  50. package/dist/parser/Parser.spec.js +418 -0
  51. package/dist/parser/Parser.spec.js.map +1 -1
  52. package/dist/parser/Statement.d.ts +20 -0
  53. package/dist/parser/Statement.js +51 -1
  54. package/dist/parser/Statement.js.map +1 -1
  55. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +70 -0
  56. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
  57. package/dist/parser/tests/statement/Enum.spec.js +318 -0
  58. package/dist/parser/tests/statement/Enum.spec.js.map +1 -1
  59. package/dist/validators/ClassValidator.js +1 -1
  60. package/dist/validators/ClassValidator.js.map +1 -1
  61. package/package.json +6 -13
@@ -71,6 +71,69 @@ describe('BrsFile', () => {
71
71
  (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
72
72
  });
73
73
  });
74
+ it('does not show "missing function" diagnostic for `call().dottedGet` as a statement', () => {
75
+ program.setFile(`source/main.brs`, `
76
+ sub main()
77
+ test().disabled
78
+ end sub
79
+ sub test()
80
+ end sub
81
+ `);
82
+ program.validate();
83
+ (0, testHelpers_spec_1.expectDiagnostics)(program, [
84
+ {
85
+ range: util_1.default.createRange(2, 22, 2, 31),
86
+ message: DiagnosticMessages_1.DiagnosticMessages.propAccessNotPermittedAfterFunctionCallInExpressionStatement('Property').message
87
+ }
88
+ ]);
89
+ });
90
+ it('does not show "missing function" diagnostic for `call()["indexedGet"]` as a statement', () => {
91
+ program.setFile(`source/main.brs`, `
92
+ sub main()
93
+ test()["disabled"]
94
+ end sub
95
+ sub test()
96
+ end sub
97
+ `);
98
+ program.validate();
99
+ (0, testHelpers_spec_1.expectDiagnostics)(program, [
100
+ {
101
+ range: util_1.default.createRange(2, 22, 2, 34),
102
+ message: DiagnosticMessages_1.DiagnosticMessages.propAccessNotPermittedAfterFunctionCallInExpressionStatement('Index').message
103
+ }
104
+ ]);
105
+ });
106
+ it('does not show "missing function" diagnostic for `call()@xmlAttr` as a statement', () => {
107
+ program.setFile(`source/main.brs`, `
108
+ sub main()
109
+ test()@disabled
110
+ end sub
111
+ sub test()
112
+ end sub
113
+ `);
114
+ program.validate();
115
+ (0, testHelpers_spec_1.expectDiagnostics)(program, [
116
+ {
117
+ range: util_1.default.createRange(2, 22, 2, 31),
118
+ message: DiagnosticMessages_1.DiagnosticMessages.propAccessNotPermittedAfterFunctionCallInExpressionStatement('XML attribute').message
119
+ }
120
+ ]);
121
+ });
122
+ it('does not flag two chained calls together', () => {
123
+ program.setFile(`source/main.brs`, `
124
+ sub main()
125
+ test().test()
126
+ end sub
127
+ function test()
128
+ print "test"
129
+ return {
130
+ test: test
131
+ }
132
+ end function
133
+ `);
134
+ program.validate();
135
+ (0, testHelpers_spec_1.expectDiagnostics)(program, []);
136
+ });
74
137
  it('flags namespaces used as variables', () => {
75
138
  program.setFile('source/main.bs', `
76
139
  sub main()
@@ -1989,6 +2052,28 @@ describe('BrsFile', () => {
1989
2052
  //this test will throw an exception if something went wrong
1990
2053
  });
1991
2054
  describe('transpile', () => {
2055
+ it('namespaced functions default param values in d.bs files are transpiled correctly', () => {
2056
+ testGetTypedef(`
2057
+ namespace promises
2058
+ function onThen(promise as dynamic, callback = promises.internal.defaultThenCallback as function, context = "__INVALID__" as object) as dynamic
2059
+ return true
2060
+ end function
2061
+ end namespace
2062
+ namespace promises.internal
2063
+ function defaultThenCallback(value = invalid as dynamic, _ = invalid as dynamic) as dynamic
2064
+ end function
2065
+ end namespace
2066
+ `, `
2067
+ namespace promises
2068
+ function onThen(promise as dynamic, callback = promises.internal.defaultThenCallback as function, context = "__INVALID__" as object) as dynamic
2069
+ end function
2070
+ end namespace
2071
+ namespace promises.internal
2072
+ function defaultThenCallback(value = invalid as dynamic, _ = invalid as dynamic) as dynamic
2073
+ end function
2074
+ end namespace
2075
+ `);
2076
+ });
1992
2077
  it('namespaced functions default param values in d.bs files are transpiled correctly', () => {
1993
2078
  testGetTypedef(`
1994
2079
  namespace alpha
@@ -3864,6 +3949,97 @@ describe('BrsFile', () => {
3864
3949
  end sub
3865
3950
  `);
3866
3951
  });
3952
+ it('allows intersection types for primitives', () => {
3953
+ testTranspile(`
3954
+ sub main(x as string and float, y as object and float or string)
3955
+ end sub
3956
+ `, `
3957
+ sub main(x as dynamic, y as dynamic)
3958
+ end sub
3959
+ `);
3960
+ });
3961
+ it('allows intersection types for classes, interfaces', () => {
3962
+ testTranspile(`
3963
+ interface IFaceA
3964
+ name as string
3965
+ data as integer
3966
+ end interface
3967
+
3968
+ interface IFaceB
3969
+ name as string
3970
+ value as float
3971
+ end interface
3972
+
3973
+ sub main(x as IFaceA and IFaceB)
3974
+ end sub
3975
+ `, `
3976
+ sub main(x as dynamic)
3977
+ end sub
3978
+ `);
3979
+ });
3980
+ it('allows intersection types for classes, interfaces', () => {
3981
+ testTranspile(`
3982
+ namespace alpha.beta
3983
+ interface IFaceA
3984
+ name as string
3985
+ data as integer
3986
+ end interface
3987
+
3988
+ interface IFaceB
3989
+ name as string
3990
+ value as float
3991
+ end interface
3992
+ end namespace
3993
+
3994
+ sub main(x as alpha.beta.IFaceA and alpha.beta.IFaceB)
3995
+ end sub
3996
+ `, `
3997
+ sub main(x as dynamic)
3998
+ end sub
3999
+ `);
4000
+ });
4001
+ it('allows intersection types of arrays', () => {
4002
+ testTranspile(`
4003
+ namespace alpha.beta
4004
+ interface IFaceA
4005
+ name as string
4006
+ data as integer
4007
+ end interface
4008
+
4009
+ interface IFaceB
4010
+ name as string
4011
+ value as float
4012
+ end interface
4013
+ end namespace
4014
+
4015
+ sub main(x as alpha.beta.IFaceA[][] and alpha.beta.IFaceB[] and ifStringOps)
4016
+ end sub
4017
+ `, `
4018
+ sub main(x as dynamic)
4019
+ end sub
4020
+ `);
4021
+ });
4022
+ it('allows grouped expression in types types', () => {
4023
+ testTranspile(`
4024
+ namespace alpha.beta
4025
+ interface IFaceA
4026
+ name as string
4027
+ data as integer
4028
+ end interface
4029
+
4030
+ interface IFaceB
4031
+ name as string
4032
+ value as float
4033
+ end interface
4034
+ end namespace
4035
+
4036
+ sub main(x as (alpha.beta.IFace and alpha.beta.IFaceB)[] or ifStringOps)
4037
+ end sub
4038
+ `, `
4039
+ sub main(x as dynamic)
4040
+ end sub
4041
+ `);
4042
+ });
3867
4043
  it('allows built-in types for return values', () => {
3868
4044
  testTranspile(`
3869
4045
  function makeLabel(text as string) as roSGNodeLabel
@@ -3965,6 +4141,81 @@ describe('BrsFile', () => {
3965
4141
  end sub
3966
4142
  `);
3967
4143
  });
4144
+ describe('inline interfaces', () => {
4145
+ it('transpiles to "dynamic"', () => {
4146
+ testTranspile(`
4147
+ function foo(input as {name as string}) as {id as string}
4148
+ output as {id as string} = {id: input.name}
4149
+ return output
4150
+ end function
4151
+ `, `
4152
+ function foo(input as dynamic) as dynamic
4153
+ output = {
4154
+ id: input.name
4155
+ }
4156
+ return output
4157
+ end function
4158
+ `);
4159
+ });
4160
+ });
4161
+ describe('type statements interfaces', () => {
4162
+ it('transpiles statement to nothing', () => {
4163
+ testTranspile(`
4164
+ type number = integer or float
4165
+
4166
+ sub foo()
4167
+ print "hello"
4168
+ end sub
4169
+ `, `
4170
+ sub foo()
4171
+ print "hello"
4172
+ end sub
4173
+ `);
4174
+ });
4175
+ it('transpiles type statement to object', () => {
4176
+ testTranspile(`
4177
+ type number = integer or float
4178
+
4179
+ sub foo(node as number)
4180
+ print node[m.keyProp]
4181
+ end sub
4182
+ `, `
4183
+ sub foo(node as object)
4184
+ print node[m.keyProp]
4185
+ end sub
4186
+ `);
4187
+ });
4188
+ });
4189
+ describe('for each loop with types', () => {
4190
+ it('transpiles to untyped for each', () => {
4191
+ testTranspile(`
4192
+ sub foo(items as string[])
4193
+ for each item as string in items
4194
+ print item
4195
+ end for
4196
+ end sub
4197
+ `, `
4198
+ sub foo(items as dynamic)
4199
+ for each item in items
4200
+ print item
4201
+ end for
4202
+ end sub
4203
+ `);
4204
+ });
4205
+ });
4206
+ describe('typed functions in type expressions', () => {
4207
+ it('transpiles to function', () => {
4208
+ testTranspile(`
4209
+ function test(func as function(name as string, num as integer) as integer) as integer
4210
+ return func("hello", 123)
4211
+ end function
4212
+ `, `
4213
+ function test(func as Function) as integer
4214
+ return func("hello", 123)
4215
+ end function
4216
+ `);
4217
+ });
4218
+ });
3968
4219
  });
3969
4220
  it('allows up to 63 function params', () => {
3970
4221
  program.setFile('source/main.bs', `