brighterscript 0.57.2 → 0.58.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 (85) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +2 -0
  3. package/dist/Program.d.ts +7 -1
  4. package/dist/Program.js +49 -18
  5. package/dist/Program.js.map +1 -1
  6. package/dist/Scope.d.ts +2 -1
  7. package/dist/Scope.js +8 -8
  8. package/dist/Scope.js.map +1 -1
  9. package/dist/astUtils/AstEditor.d.ts +2 -3
  10. package/dist/astUtils/AstEditor.js.map +1 -1
  11. package/dist/astUtils/creators.d.ts +4 -4
  12. package/dist/astUtils/creators.js +6 -6
  13. package/dist/astUtils/creators.js.map +1 -1
  14. package/dist/astUtils/reflection.d.ts +65 -64
  15. package/dist/astUtils/reflection.js.map +1 -1
  16. package/dist/astUtils/reflection.spec.js +3 -3
  17. package/dist/astUtils/reflection.spec.js.map +1 -1
  18. package/dist/astUtils/visitors.d.ts +32 -31
  19. package/dist/astUtils/visitors.js.map +1 -1
  20. package/dist/astUtils/visitors.spec.js.map +1 -1
  21. package/dist/bscPlugin/BscPlugin.js +4 -0
  22. package/dist/bscPlugin/BscPlugin.js.map +1 -1
  23. package/dist/bscPlugin/hover/HoverProcessor.spec.js +6 -0
  24. package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +1 -1
  25. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +2 -2
  26. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -1
  27. package/dist/bscPlugin/validation/BrsFileValidator.d.ts +1 -0
  28. package/dist/bscPlugin/validation/BrsFileValidator.js +118 -6
  29. package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -1
  30. package/dist/bscPlugin/validation/ScopeValidator.d.ts +21 -19
  31. package/dist/bscPlugin/validation/ScopeValidator.js +164 -179
  32. package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -1
  33. package/dist/bscPlugin/validation/XmlFileValidator.d.ts +8 -0
  34. package/dist/bscPlugin/validation/XmlFileValidator.js +44 -0
  35. package/dist/bscPlugin/validation/XmlFileValidator.js.map +1 -0
  36. package/dist/files/BrsFile.Class.spec.js.map +1 -1
  37. package/dist/files/BrsFile.d.ts +11 -5
  38. package/dist/files/BrsFile.js +15 -47
  39. package/dist/files/BrsFile.js.map +1 -1
  40. package/dist/files/BrsFile.spec.js +29 -0
  41. package/dist/files/BrsFile.spec.js.map +1 -1
  42. package/dist/files/XmlFile.d.ts +9 -4
  43. package/dist/files/XmlFile.js +6 -30
  44. package/dist/files/XmlFile.js.map +1 -1
  45. package/dist/files/tests/optionalChaning.spec.js +2 -1
  46. package/dist/files/tests/optionalChaning.spec.js.map +1 -1
  47. package/dist/index.d.ts +1 -0
  48. package/dist/index.js +1 -0
  49. package/dist/index.js.map +1 -1
  50. package/dist/interfaces.d.ts +2 -3
  51. package/dist/parser/AstNode.d.ts +65 -0
  52. package/dist/parser/AstNode.js +93 -0
  53. package/dist/parser/AstNode.js.map +1 -0
  54. package/dist/parser/AstNode.spec.d.ts +1 -0
  55. package/dist/parser/AstNode.spec.js +44 -0
  56. package/dist/parser/AstNode.spec.js.map +1 -0
  57. package/dist/parser/Expression.d.ts +6 -43
  58. package/dist/parser/Expression.js +53 -81
  59. package/dist/parser/Expression.js.map +1 -1
  60. package/dist/parser/Parser.d.ts +11 -12
  61. package/dist/parser/Parser.js +118 -117
  62. package/dist/parser/Parser.js.map +1 -1
  63. package/dist/parser/Parser.spec.d.ts +1 -1
  64. package/dist/parser/Parser.spec.js.map +1 -1
  65. package/dist/parser/Statement.d.ts +15 -44
  66. package/dist/parser/Statement.js +91 -102
  67. package/dist/parser/Statement.js.map +1 -1
  68. package/dist/parser/Statement.spec.js +14 -7
  69. package/dist/parser/Statement.spec.js.map +1 -1
  70. package/dist/parser/tests/expression/ArrayLiterals.spec.js +37 -0
  71. package/dist/parser/tests/expression/ArrayLiterals.spec.js.map +1 -1
  72. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +41 -0
  73. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
  74. package/dist/parser/tests/expression/Call.spec.js +109 -1
  75. package/dist/parser/tests/expression/Call.spec.js.map +1 -1
  76. package/dist/parser/tests/expression/Indexing.spec.js +49 -4
  77. package/dist/parser/tests/expression/Indexing.spec.js.map +1 -1
  78. package/dist/parser/tests/statement/Enum.spec.js +7 -4
  79. package/dist/parser/tests/statement/Enum.spec.js.map +1 -1
  80. package/dist/util.d.ts +11 -5
  81. package/dist/util.js +50 -0
  82. package/dist/util.js.map +1 -1
  83. package/dist/validators/ClassValidator.js +22 -19
  84. package/dist/validators/ClassValidator.js.map +1 -1
  85. package/package.json +2 -2
@@ -13,8 +13,6 @@ const reflection_1 = require("../astUtils/reflection");
13
13
  const visitors_1 = require("../astUtils/visitors");
14
14
  const creators_1 = require("../astUtils/creators");
15
15
  const Cache_1 = require("../Cache");
16
- const SymbolTable_1 = require("../SymbolTable");
17
- const DynamicType_1 = require("../types/DynamicType");
18
16
  class Parser {
19
17
  constructor() {
20
18
  /**
@@ -25,10 +23,6 @@ class Parser {
25
23
  * The list of statements for the parsed file
26
24
  */
27
25
  this.ast = new Statement_1.Body([]);
28
- /**
29
- * The top-level symbol table for this file. Things like top-level namespaces, non-namespaced classes, enums, interfaces, and functions beling here.
30
- */
31
- this.symbolTable = new SymbolTable_1.SymbolTable();
32
26
  this._references = new References();
33
27
  this.globalTerminators = [];
34
28
  /**
@@ -39,9 +33,11 @@ class Parser {
39
33
  get statements() {
40
34
  return this.ast.statements;
41
35
  }
42
- get currentSymbolTable() {
43
- var _a, _b, _c, _d;
44
- return (_d = (_b = (_a = this.currentFunctionExpression) === null || _a === void 0 ? void 0 : _a.symbolTable) !== null && _b !== void 0 ? _b : (_c = this.currentNamespace) === null || _c === void 0 ? void 0 : _c.symbolTable) !== null && _d !== void 0 ? _d : this.symbolTable;
36
+ /**
37
+ * The top-level symbol table for the body of this file.
38
+ */
39
+ get symbolTable() {
40
+ return this.ast.symbolTable;
45
41
  }
46
42
  /**
47
43
  * References for significant statements/expressions in the parser.
@@ -78,10 +74,6 @@ class Parser {
78
74
  }
79
75
  }
80
76
  }
81
- get currentNamespaceName() {
82
- var _a;
83
- return (_a = this.currentNamespace) === null || _a === void 0 ? void 0 : _a.nameExpression;
84
- }
85
77
  /**
86
78
  * Get the currently active global terminators
87
79
  */
@@ -126,7 +118,7 @@ class Parser {
126
118
  }
127
119
  body() {
128
120
  const parentAnnotations = this.enterAnnotationBlock();
129
- let body = new Statement_1.Body([], this.symbolTable);
121
+ let body = new Statement_1.Body([]);
130
122
  if (this.tokens.length > 0) {
131
123
  this.consumeStatementSeparators(true);
132
124
  try {
@@ -333,13 +325,13 @@ class Parser {
333
325
  }
334
326
  //consume the final `end interface` token
335
327
  const endInterfaceToken = this.consumeToken(TokenKind_1.TokenKind.EndInterface);
336
- const statement = new Statement_1.InterfaceStatement(interfaceToken, nameToken, extendsToken, parentInterfaceName, body, endInterfaceToken, this.currentNamespaceName);
328
+ const statement = new Statement_1.InterfaceStatement(interfaceToken, nameToken, extendsToken, parentInterfaceName, body, endInterfaceToken);
337
329
  this._references.interfaceStatements.push(statement);
338
330
  this.exitAnnotationBlock(parentAnnotations);
339
331
  return statement;
340
332
  }
341
333
  enumDeclaration() {
342
- const result = new Statement_1.EnumStatement({}, [], this.currentNamespaceName);
334
+ const result = new Statement_1.EnumStatement({}, []);
343
335
  this.warnIfNotBrighterScriptMode('enum declarations');
344
336
  const parentAnnotations = this.enterAnnotationBlock();
345
337
  result.tokens.enum = this.consume(DiagnosticMessages_1.DiagnosticMessages.expectedKeyword(TokenKind_1.TokenKind.Enum), TokenKind_1.TokenKind.Enum);
@@ -383,9 +375,6 @@ class Parser {
383
375
  }
384
376
  //consume the final `end interface` token
385
377
  result.tokens.endEnum = this.consumeToken(TokenKind_1.TokenKind.EndEnum);
386
- if (result.name) {
387
- this.currentSymbolTable.addSymbol(result.tokens.name.text, result.tokens.name.range, DynamicType_1.DynamicType.instance);
388
- }
389
378
  this._references.enumStatements.push(result);
390
379
  this.exitAnnotationBlock(parentAnnotations);
391
380
  return result;
@@ -437,8 +426,6 @@ class Parser {
437
426
  decl = new Statement_1.MethodStatement(accessModifier, funcDeclaration.name, funcDeclaration.func, overrideKeyword);
438
427
  //refer to this statement as parent of the expression
439
428
  functionStatement.func.functionStatement = decl;
440
- //add the `super` symbol to class methods
441
- funcDeclaration.func.symbolTable.addSymbol('super', undefined, DynamicType_1.DynamicType.instance);
442
429
  //fields
443
430
  }
444
431
  else if (this.checkAny(TokenKind_1.TokenKind.Identifier, ...TokenKind_1.AllowedProperties)) {
@@ -468,10 +455,7 @@ class Parser {
468
455
  if (endingKeyword.kind !== TokenKind_1.TokenKind.EndClass) {
469
456
  this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.couldNotFindMatchingEndKeyword('class')), { range: endingKeyword.range }));
470
457
  }
471
- const result = new Statement_1.ClassStatement(classKeyword, className, body, endingKeyword, extendsKeyword, parentClassName, this.currentNamespaceName);
472
- if (className) {
473
- this.currentSymbolTable.addSymbol(className.text, className.range, DynamicType_1.DynamicType.instance);
474
- }
458
+ const result = new Statement_1.ClassStatement(classKeyword, className, body, endingKeyword, extendsKeyword, parentClassName);
475
459
  this._references.classStatements.push(result);
476
460
  this.exitAnnotationBlock(parentAnnotations);
477
461
  return result;
@@ -572,10 +556,7 @@ class Parser {
572
556
  this.consumeStatementSeparators(true);
573
557
  let func = new Expression_1.FunctionExpression(params, undefined, //body
574
558
  functionType, undefined, //ending keyword
575
- leftParen, rightParen, asToken, typeToken, this.currentFunctionExpression, this.currentNamespaceName, this.currentSymbolTable);
576
- if (!func.symbolTable.hasSymbol('m')) {
577
- func.symbolTable.addSymbol('m', undefined, DynamicType_1.DynamicType.instance);
578
- }
559
+ leftParen, rightParen, asToken, typeToken, this.currentFunctionExpression);
579
560
  //if there is a parent function, register this function with the parent
580
561
  if (this.currentFunctionExpression) {
581
562
  this.currentFunctionExpression.childFunctionExpressions.push(func);
@@ -584,8 +565,6 @@ class Parser {
584
565
  if (!onlyCallableAsMember && name) {
585
566
  const funcType = func.getFunctionType();
586
567
  funcType.setName(name.text);
587
- // add the function as declared to the current symbol table
588
- this.currentSymbolTable.addSymbol(name.text, name.range, funcType);
589
568
  }
590
569
  this._references.functionExpressions.push(func);
591
570
  let previousFunctionExpression = this.currentFunctionExpression;
@@ -615,18 +594,9 @@ class Parser {
615
594
  return func;
616
595
  }
617
596
  else {
618
- let result = new Statement_1.FunctionStatement(name, func, this.currentNamespaceName);
597
+ let result = new Statement_1.FunctionStatement(name, func);
619
598
  func.functionStatement = result;
620
599
  this._references.functionStatements.push(result);
621
- // Add the transpiled name for namespace functions
622
- // to consider an edge case when defining namespaces in .bs files
623
- // and using them in .brs files.
624
- if (func.namespaceName) {
625
- const transpiledNamespaceFunctionName = result.getName(ParseMode.BrightScript);
626
- const funcType = func.getFunctionType();
627
- funcType.setName(transpiledNamespaceFunctionName);
628
- this.symbolTable.addSymbol(transpiledNamespaceFunctionName, name.range, funcType);
629
- }
630
600
  return result;
631
601
  }
632
602
  }
@@ -660,7 +630,7 @@ class Parser {
660
630
  throw this.lastDiagnosticAsError();
661
631
  }
662
632
  }
663
- return new Expression_1.FunctionParameterExpression(name, typeToken, defaultValue, asToken, this.currentNamespaceName);
633
+ return new Expression_1.FunctionParameterExpression(name, typeToken, defaultValue, asToken);
664
634
  }
665
635
  assignment() {
666
636
  let name = this.advance();
@@ -675,7 +645,7 @@ class Parser {
675
645
  result = new Statement_1.AssignmentStatement(operator, name, value, this.currentFunctionExpression);
676
646
  }
677
647
  else {
678
- const nameExpression = new Expression_1.VariableExpression(name, this.currentNamespaceName);
648
+ const nameExpression = new Expression_1.VariableExpression(name);
679
649
  result = new Statement_1.AssignmentStatement(operator, name, new Expression_1.BinaryExpression(nameExpression, operator, value), this.currentFunctionExpression);
680
650
  this.addExpressionsToReferences(nameExpression);
681
651
  if ((0, reflection_1.isBinaryExpression)(value)) {
@@ -684,7 +654,6 @@ class Parser {
684
654
  }
685
655
  this._references.expressions.add(result);
686
656
  }
687
- this.currentSymbolTable.addSymbol(name.text, name.range, DynamicType_1.DynamicType.instance);
688
657
  this._references.assignmentStatements.push(result);
689
658
  return result;
690
659
  }
@@ -857,7 +826,6 @@ class Parser {
857
826
  this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.expectedExpressionAfterForEachIn()), { range: this.peek().range }));
858
827
  throw this.lastDiagnosticAsError();
859
828
  }
860
- this.currentSymbolTable.addSymbol(name.text, name.range, DynamicType_1.DynamicType.instance);
861
829
  this.consumeStatementSeparators();
862
830
  let body = this.block(TokenKind_1.TokenKind.EndFor, TokenKind_1.TokenKind.Next);
863
831
  if (!body) {
@@ -900,13 +868,10 @@ class Parser {
900
868
  this.namespaceAndFunctionDepth++;
901
869
  let name = this.getNamespacedVariableNameExpression();
902
870
  //set the current namespace name
903
- let result = new Statement_1.NamespaceStatement(keyword, name, null, null, this.currentSymbolTable);
904
- this.currentNamespace = result;
871
+ let result = new Statement_1.NamespaceStatement(keyword, name, null, null);
905
872
  this.globalTerminators.push([TokenKind_1.TokenKind.EndNamespace]);
906
873
  let body = this.body();
907
874
  this.globalTerminators.pop();
908
- //unset the current namespace name
909
- this.currentNamespace = undefined;
910
875
  let endKeyword;
911
876
  if (this.check(TokenKind_1.TokenKind.EndNamespace)) {
912
877
  endKeyword = this.advance();
@@ -921,9 +886,6 @@ class Parser {
921
886
  this._references.namespaceStatements.push(result);
922
887
  //cache the range property so that plugins can't affect it
923
888
  result.cacheRange();
924
- if (result.name) {
925
- this.symbolTable.addSymbol(result.name.split('.')[0], result.nameExpression.range, DynamicType_1.DynamicType.instance);
926
- }
927
889
  return result;
928
890
  }
929
891
  /**
@@ -935,7 +897,7 @@ class Parser {
935
897
  if (firstIdentifier) {
936
898
  // force it into an identifier so the AST makes some sense
937
899
  firstIdentifier.kind = TokenKind_1.TokenKind.Identifier;
938
- const varExpr = new Expression_1.VariableExpression(firstIdentifier, null);
900
+ const varExpr = new Expression_1.VariableExpression(firstIdentifier);
939
901
  expr = varExpr;
940
902
  //consume multiple dot identifiers (i.e. `Name.Space.Can.Have.Many.Parts`)
941
903
  while (this.check(TokenKind_1.TokenKind.Dot)) {
@@ -986,10 +948,7 @@ class Parser {
986
948
  const: constToken,
987
949
  name: nameToken,
988
950
  equals: equalToken
989
- }, expression, this.currentNamespaceName);
990
- if (nameToken) {
991
- this.currentSymbolTable.addSymbol(nameToken.text, nameToken.range, DynamicType_1.DynamicType.instance);
992
- }
951
+ }, expression);
993
952
  this._references.constStatements.push(statement);
994
953
  return statement;
995
954
  }
@@ -1161,9 +1120,6 @@ class Parser {
1161
1120
  else {
1162
1121
  statement.tokens.endTry = this.advance();
1163
1122
  }
1164
- if (exceptionVarToken) {
1165
- this.currentSymbolTable.addSymbol(exceptionVarToken.text, exceptionVarToken.range, DynamicType_1.DynamicType.instance);
1166
- }
1167
1123
  return statement;
1168
1124
  }
1169
1125
  throwStatement() {
@@ -1206,9 +1162,6 @@ class Parser {
1206
1162
  this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.missingExpressionsInDimStatement()), { range: this.peek().range }));
1207
1163
  }
1208
1164
  let rightSquareBracket = this.tryConsume(DiagnosticMessages_1.DiagnosticMessages.missingRightSquareBracketAfterDimIdentifier(), TokenKind_1.TokenKind.RightSquareBracket);
1209
- if (identifier) {
1210
- this.currentSymbolTable.addSymbol(identifier.text, identifier.range, DynamicType_1.DynamicType.instance);
1211
- }
1212
1165
  return new Statement_1.DimStatement(dim, identifier, leftSquareBracket, expressions, rightSquareBracket);
1213
1166
  }
1214
1167
  ifStatement() {
@@ -1700,10 +1653,17 @@ class Parser {
1700
1653
  indexedGet(expr) {
1701
1654
  let openingSquare = this.previous();
1702
1655
  let questionDotToken = this.getMatchingTokenAtOffset(-2, TokenKind_1.TokenKind.QuestionDot);
1656
+ let index;
1657
+ let closingSquare;
1703
1658
  while (this.match(TokenKind_1.TokenKind.Newline)) { }
1704
- let index = this.expression();
1659
+ try {
1660
+ index = this.expression();
1661
+ }
1662
+ catch (error) {
1663
+ this.rethrowNonDiagnosticError(error);
1664
+ }
1705
1665
  while (this.match(TokenKind_1.TokenKind.Newline)) { }
1706
- let closingSquare = this.consume(DiagnosticMessages_1.DiagnosticMessages.expectedRightSquareBraceAfterArrayOrObjectIndex(), TokenKind_1.TokenKind.RightSquareBracket);
1666
+ closingSquare = this.tryConsume(DiagnosticMessages_1.DiagnosticMessages.expectedRightSquareBraceAfterArrayOrObjectIndex(), TokenKind_1.TokenKind.RightSquareBracket);
1707
1667
  return new Expression_1.IndexedGetExpression(expr, index, openingSquare, closingSquare, questionDotToken);
1708
1668
  }
1709
1669
  newExpression() {
@@ -1758,7 +1718,10 @@ class Parser {
1758
1718
  }
1759
1719
  else {
1760
1720
  let dot = this.previous();
1761
- let name = this.consume(DiagnosticMessages_1.DiagnosticMessages.expectedPropertyNameAfterPeriod(), TokenKind_1.TokenKind.Identifier, ...TokenKind_1.AllowedProperties);
1721
+ let name = this.tryConsume(DiagnosticMessages_1.DiagnosticMessages.expectedPropertyNameAfterPeriod(), TokenKind_1.TokenKind.Identifier, ...TokenKind_1.AllowedProperties);
1722
+ if (!name) {
1723
+ break;
1724
+ }
1762
1725
  // force it into an identifier so the AST makes some sense
1763
1726
  name.kind = TokenKind_1.TokenKind.Identifier;
1764
1727
  expr = new Expression_1.DottedGetExpression(expr, name, dot);
@@ -1767,9 +1730,12 @@ class Parser {
1767
1730
  }
1768
1731
  else if (this.checkAny(TokenKind_1.TokenKind.At, TokenKind_1.TokenKind.QuestionAt)) {
1769
1732
  let dot = this.advance();
1770
- let name = this.consume(DiagnosticMessages_1.DiagnosticMessages.expectedAttributeNameAfterAtSymbol(), TokenKind_1.TokenKind.Identifier, ...TokenKind_1.AllowedProperties);
1733
+ let name = this.tryConsume(DiagnosticMessages_1.DiagnosticMessages.expectedAttributeNameAfterAtSymbol(), TokenKind_1.TokenKind.Identifier, ...TokenKind_1.AllowedProperties);
1771
1734
  // force it into an identifier so the AST makes some sense
1772
1735
  name.kind = TokenKind_1.TokenKind.Identifier;
1736
+ if (!name) {
1737
+ break;
1738
+ }
1773
1739
  expr = new Expression_1.XmlAttributeGetExpression(expr, name, dot);
1774
1740
  //only allow a single `@` expression
1775
1741
  break;
@@ -1794,12 +1760,19 @@ class Parser {
1794
1760
  this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.tooManyCallableArguments(args.length, Expression_1.CallExpression.MaximumArguments)), { range: this.peek().range }));
1795
1761
  throw this.lastDiagnosticAsError();
1796
1762
  }
1797
- args.push(this.expression());
1763
+ try {
1764
+ args.push(this.expression());
1765
+ }
1766
+ catch (error) {
1767
+ this.rethrowNonDiagnosticError(error);
1768
+ // we were unable to get an expression, so don't continue
1769
+ break;
1770
+ }
1798
1771
  } while (this.match(TokenKind_1.TokenKind.Comma));
1799
1772
  }
1800
1773
  while (this.match(TokenKind_1.TokenKind.Newline)) { }
1801
- const closingParen = this.consume(DiagnosticMessages_1.DiagnosticMessages.expectedRightParenAfterFunctionCallArguments(), TokenKind_1.TokenKind.RightParen);
1802
- let expression = new Expression_1.CallExpression(callee, openingParen, closingParen, args, this.currentNamespaceName);
1774
+ const closingParen = this.tryConsume(DiagnosticMessages_1.DiagnosticMessages.expectedRightParenAfterFunctionCallArguments(), TokenKind_1.TokenKind.RightParen);
1775
+ let expression = new Expression_1.CallExpression(callee, openingParen, closingParen, args);
1803
1776
  if (addToCallExpressionList) {
1804
1777
  this.callExpressions.push(expression);
1805
1778
  }
@@ -1847,7 +1820,7 @@ class Parser {
1847
1820
  case this.checkAny(TokenKind_1.TokenKind.Identifier, ...TokenKind_1.AllowedLocalIdentifiers) && this.checkNext(TokenKind_1.TokenKind.BackTick):
1848
1821
  return this.templateString(true);
1849
1822
  case this.matchAny(TokenKind_1.TokenKind.Identifier, ...this.allowedLocalIdentifiers):
1850
- return new Expression_1.VariableExpression(this.previous(), this.currentNamespaceName);
1823
+ return new Expression_1.VariableExpression(this.previous());
1851
1824
  case this.match(TokenKind_1.TokenKind.LeftParen):
1852
1825
  let left = this.previous();
1853
1826
  let expr = this.expression();
@@ -1861,7 +1834,7 @@ class Parser {
1861
1834
  let token = Object.assign(this.previous(), {
1862
1835
  kind: TokenKind_1.TokenKind.Identifier
1863
1836
  });
1864
- return new Expression_1.VariableExpression(token, this.currentNamespaceName);
1837
+ return new Expression_1.VariableExpression(token);
1865
1838
  case this.checkAny(TokenKind_1.TokenKind.Function, TokenKind_1.TokenKind.Sub):
1866
1839
  return this.anonymousFunction();
1867
1840
  case this.check(TokenKind_1.TokenKind.RegexLiteral):
@@ -1889,23 +1862,31 @@ class Parser {
1889
1862
  }
1890
1863
  while (this.match(TokenKind_1.TokenKind.Newline)) {
1891
1864
  }
1865
+ let closingSquare;
1892
1866
  if (!this.match(TokenKind_1.TokenKind.RightSquareBracket)) {
1893
- elements.push(this.expression());
1894
- while (this.matchAny(TokenKind_1.TokenKind.Comma, TokenKind_1.TokenKind.Newline, TokenKind_1.TokenKind.Comment)) {
1895
- if (this.checkPrevious(TokenKind_1.TokenKind.Comment) || this.check(TokenKind_1.TokenKind.Comment)) {
1896
- let comment = this.check(TokenKind_1.TokenKind.Comment) ? this.advance() : this.previous();
1897
- elements.push(new Statement_1.CommentStatement([comment]));
1898
- }
1899
- while (this.match(TokenKind_1.TokenKind.Newline)) {
1900
- }
1901
- if (this.check(TokenKind_1.TokenKind.RightSquareBracket)) {
1902
- break;
1903
- }
1867
+ try {
1904
1868
  elements.push(this.expression());
1869
+ while (this.matchAny(TokenKind_1.TokenKind.Comma, TokenKind_1.TokenKind.Newline, TokenKind_1.TokenKind.Comment)) {
1870
+ if (this.checkPrevious(TokenKind_1.TokenKind.Comment) || this.check(TokenKind_1.TokenKind.Comment)) {
1871
+ let comment = this.check(TokenKind_1.TokenKind.Comment) ? this.advance() : this.previous();
1872
+ elements.push(new Statement_1.CommentStatement([comment]));
1873
+ }
1874
+ while (this.match(TokenKind_1.TokenKind.Newline)) {
1875
+ }
1876
+ if (this.check(TokenKind_1.TokenKind.RightSquareBracket)) {
1877
+ break;
1878
+ }
1879
+ elements.push(this.expression());
1880
+ }
1881
+ }
1882
+ catch (error) {
1883
+ this.rethrowNonDiagnosticError(error);
1905
1884
  }
1906
- this.consume(DiagnosticMessages_1.DiagnosticMessages.unmatchedLeftSquareBraceAfterArrayLiteral(), TokenKind_1.TokenKind.RightSquareBracket);
1885
+ closingSquare = this.tryConsume(DiagnosticMessages_1.DiagnosticMessages.unmatchedLeftSquareBraceAfterArrayLiteral(), TokenKind_1.TokenKind.RightSquareBracket);
1886
+ }
1887
+ else {
1888
+ closingSquare = this.previous();
1907
1889
  }
1908
- let closingSquare = this.previous();
1909
1890
  //this.consume("Expected newline or ':' after array literal", TokenKind.Newline, TokenKind.Colon, TokenKind.Eof);
1910
1891
  return new Expression_1.ArrayLiteralExpression(elements, openingSquare, closingSquare);
1911
1892
  }
@@ -1933,49 +1914,57 @@ class Parser {
1933
1914
  return result;
1934
1915
  };
1935
1916
  while (this.match(TokenKind_1.TokenKind.Newline)) { }
1917
+ let closingBrace;
1936
1918
  if (!this.match(TokenKind_1.TokenKind.RightCurlyBrace)) {
1937
1919
  let lastAAMember;
1938
- if (this.check(TokenKind_1.TokenKind.Comment)) {
1939
- lastAAMember = null;
1940
- members.push(new Statement_1.CommentStatement([this.advance()]));
1941
- }
1942
- else {
1943
- let k = key();
1944
- let expr = this.expression();
1945
- lastAAMember = new Expression_1.AAMemberExpression(k.keyToken, k.colonToken, expr);
1946
- members.push(lastAAMember);
1947
- }
1948
- while (this.matchAny(TokenKind_1.TokenKind.Comma, TokenKind_1.TokenKind.Newline, TokenKind_1.TokenKind.Colon, TokenKind_1.TokenKind.Comment)) {
1949
- // collect comma at end of expression
1950
- if (lastAAMember && this.checkPrevious(TokenKind_1.TokenKind.Comma)) {
1951
- lastAAMember.commaToken = this.previous();
1952
- }
1953
- //check for comment at the end of the current line
1954
- if (this.check(TokenKind_1.TokenKind.Comment) || this.checkPrevious(TokenKind_1.TokenKind.Comment)) {
1955
- let token = this.checkPrevious(TokenKind_1.TokenKind.Comment) ? this.previous() : this.advance();
1956
- members.push(new Statement_1.CommentStatement([token]));
1920
+ try {
1921
+ if (this.check(TokenKind_1.TokenKind.Comment)) {
1922
+ lastAAMember = null;
1923
+ members.push(new Statement_1.CommentStatement([this.advance()]));
1957
1924
  }
1958
1925
  else {
1959
- this.consumeStatementSeparators(true);
1960
- //check for a comment on its own line
1926
+ let k = key();
1927
+ let expr = this.expression();
1928
+ lastAAMember = new Expression_1.AAMemberExpression(k.keyToken, k.colonToken, expr);
1929
+ members.push(lastAAMember);
1930
+ }
1931
+ while (this.matchAny(TokenKind_1.TokenKind.Comma, TokenKind_1.TokenKind.Newline, TokenKind_1.TokenKind.Colon, TokenKind_1.TokenKind.Comment)) {
1932
+ // collect comma at end of expression
1933
+ if (lastAAMember && this.checkPrevious(TokenKind_1.TokenKind.Comma)) {
1934
+ lastAAMember.commaToken = this.previous();
1935
+ }
1936
+ //check for comment at the end of the current line
1961
1937
  if (this.check(TokenKind_1.TokenKind.Comment) || this.checkPrevious(TokenKind_1.TokenKind.Comment)) {
1962
1938
  let token = this.checkPrevious(TokenKind_1.TokenKind.Comment) ? this.previous() : this.advance();
1963
- lastAAMember = null;
1964
1939
  members.push(new Statement_1.CommentStatement([token]));
1965
- continue;
1966
1940
  }
1967
- if (this.check(TokenKind_1.TokenKind.RightCurlyBrace)) {
1968
- break;
1941
+ else {
1942
+ this.consumeStatementSeparators(true);
1943
+ //check for a comment on its own line
1944
+ if (this.check(TokenKind_1.TokenKind.Comment) || this.checkPrevious(TokenKind_1.TokenKind.Comment)) {
1945
+ let token = this.checkPrevious(TokenKind_1.TokenKind.Comment) ? this.previous() : this.advance();
1946
+ lastAAMember = null;
1947
+ members.push(new Statement_1.CommentStatement([token]));
1948
+ continue;
1949
+ }
1950
+ if (this.check(TokenKind_1.TokenKind.RightCurlyBrace)) {
1951
+ break;
1952
+ }
1953
+ let k = key();
1954
+ let expr = this.expression();
1955
+ lastAAMember = new Expression_1.AAMemberExpression(k.keyToken, k.colonToken, expr);
1956
+ members.push(lastAAMember);
1969
1957
  }
1970
- let k = key();
1971
- let expr = this.expression();
1972
- lastAAMember = new Expression_1.AAMemberExpression(k.keyToken, k.colonToken, expr);
1973
- members.push(lastAAMember);
1974
1958
  }
1975
1959
  }
1976
- this.consume(DiagnosticMessages_1.DiagnosticMessages.unmatchedLeftCurlyAfterAALiteral(), TokenKind_1.TokenKind.RightCurlyBrace);
1960
+ catch (error) {
1961
+ this.rethrowNonDiagnosticError(error);
1962
+ }
1963
+ closingBrace = this.tryConsume(DiagnosticMessages_1.DiagnosticMessages.unmatchedLeftCurlyAfterAALiteral(), TokenKind_1.TokenKind.RightCurlyBrace);
1964
+ }
1965
+ else {
1966
+ closingBrace = this.previous();
1977
1967
  }
1978
- let closingBrace = this.previous();
1979
1968
  const aaExpr = new Expression_1.AALiteralExpression(members, openingBrace, closingBrace);
1980
1969
  this.addPropertyHints(aaExpr);
1981
1970
  return aaExpr;
@@ -2120,6 +2109,18 @@ class Parser {
2120
2109
  previous() {
2121
2110
  return this.tokens[this.current - 1];
2122
2111
  }
2112
+ /**
2113
+ * Sometimes we catch an error that is a diagnostic.
2114
+ * If that's the case, we want to continue parsing.
2115
+ * Otherwise, re-throw the error
2116
+ *
2117
+ * @param error error caught in a try/catch
2118
+ */
2119
+ rethrowNonDiagnosticError(error) {
2120
+ if (!error.isDiagnostic) {
2121
+ throw error;
2122
+ }
2123
+ }
2123
2124
  /**
2124
2125
  * Get the token that is {offset} indexes away from {this.current}
2125
2126
  * @param offset the number of index steps away from current index to fetch
@@ -2229,7 +2230,7 @@ class Parser {
2229
2230
  this._references.libraryStatements.push(s);
2230
2231
  },
2231
2232
  FunctionExpression: (expression, parent) => {
2232
- if (!(0, reflection_1.isClassMethodStatement)(parent)) {
2233
+ if (!(0, reflection_1.isMethodStatement)(parent)) {
2233
2234
  this._references.functionExpressions.push(expression);
2234
2235
  }
2235
2236
  },