brighterscript 0.62.0 → 0.64.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.
@@ -4,7 +4,6 @@ exports.ContinueStatement = exports.ConstStatement = exports.EnumMemberStatement
4
4
  const TokenKind_1 = require("../lexer/TokenKind");
5
5
  const Expression_1 = require("./Expression");
6
6
  const util_1 = require("../util");
7
- const vscode_languageserver_1 = require("vscode-languageserver");
8
7
  const Parser_1 = require("./Parser");
9
8
  const visitors_1 = require("../astUtils/visitors");
10
9
  const reflection_1 = require("../astUtils/reflection");
@@ -39,8 +38,9 @@ class Body extends AstNode_1.Statement {
39
38
  this.symbolTable = new SymbolTable_1.SymbolTable('Body', () => { var _a; return (_a = this.parent) === null || _a === void 0 ? void 0 : _a.getSymbolTable(); });
40
39
  }
41
40
  get range() {
42
- var _a, _b, _c, _d;
43
- return util_1.util.createRangeFromPositions((_b = (_a = this.statements[0]) === null || _a === void 0 ? void 0 : _a.range.start) !== null && _b !== void 0 ? _b : vscode_languageserver_1.Position.create(0, 0), (_d = (_c = this.statements[this.statements.length - 1]) === null || _c === void 0 ? void 0 : _c.range.end) !== null && _d !== void 0 ? _d : vscode_languageserver_1.Position.create(0, 0));
41
+ var _a;
42
+ //this needs to be a getter because the body has its statements pushed to it after being constructed
43
+ return util_1.util.createBoundingRange(...((_a = this.statements) !== null && _a !== void 0 ? _a : []));
44
44
  }
45
45
  transpile(state) {
46
46
  let result = [];
@@ -94,7 +94,7 @@ class AssignmentStatement extends AstNode_1.Statement {
94
94
  this.equals = equals;
95
95
  this.name = name;
96
96
  this.value = value;
97
- this.range = util_1.util.createRangeFromPositions(this.name.range.start, this.value.range.end);
97
+ this.range = util_1.util.createBoundingRange(name, equals, value);
98
98
  }
99
99
  /**
100
100
  * Get the name of the wrapping namespace (if it exists)
@@ -131,9 +131,7 @@ class Block extends AstNode_1.Statement {
131
131
  super();
132
132
  this.statements = statements;
133
133
  this.startingRange = startingRange;
134
- this.range = util_1.util.createRangeFromPositions(this.startingRange.start, this.statements.length
135
- ? this.statements[this.statements.length - 1].range.end
136
- : this.startingRange.start);
134
+ this.range = util_1.util.createBoundingRange({ range: this.startingRange }, ...(statements !== null && statements !== void 0 ? statements : []));
137
135
  }
138
136
  transpile(state) {
139
137
  state.blockDepth++;
@@ -189,7 +187,7 @@ class CommentStatement extends AstNode_1.Statement {
189
187
  this.comments = comments;
190
188
  this.visitMode = visitors_1.InternalWalkMode.visitStatements | visitors_1.InternalWalkMode.visitExpressions;
191
189
  if (((_a = this.comments) === null || _a === void 0 ? void 0 : _a.length) > 0) {
192
- this.range = util_1.util.createRangeFromPositions(this.comments[0].range.start, this.comments[this.comments.length - 1].range.end);
190
+ this.range = util_1.util.createBoundingRange(...this.comments);
193
191
  }
194
192
  }
195
193
  get text() {
@@ -303,14 +301,13 @@ class FunctionStatement extends AstNode_1.Statement {
303
301
  exports.FunctionStatement = FunctionStatement;
304
302
  class IfStatement extends AstNode_1.Statement {
305
303
  constructor(tokens, condition, thenBranch, elseBranch, isInline) {
306
- var _a, _b;
307
304
  super();
308
305
  this.tokens = tokens;
309
306
  this.condition = condition;
310
307
  this.thenBranch = thenBranch;
311
308
  this.elseBranch = elseBranch;
312
309
  this.isInline = isInline;
313
- this.range = util_1.util.createRangeFromPositions(this.tokens.if.range.start, ((_b = (_a = this.tokens.endIf) !== null && _a !== void 0 ? _a : this.elseBranch) !== null && _b !== void 0 ? _b : this.thenBranch).range.end);
310
+ this.range = util_1.util.createBoundingRange(tokens.if, condition, tokens.then, thenBranch, tokens.else, elseBranch, tokens.endIf);
314
311
  }
315
312
  transpile(state) {
316
313
  let results = [];
@@ -393,7 +390,7 @@ class IncrementStatement extends AstNode_1.Statement {
393
390
  super();
394
391
  this.value = value;
395
392
  this.operator = operator;
396
- this.range = util_1.util.createRangeFromPositions(this.value.range.start, this.operator.range.end);
393
+ this.range = util_1.util.createBoundingRange(value, operator);
397
394
  }
398
395
  transpile(state) {
399
396
  return [
@@ -422,9 +419,7 @@ class PrintStatement extends AstNode_1.Statement {
422
419
  super();
423
420
  this.tokens = tokens;
424
421
  this.expressions = expressions;
425
- this.range = util_1.util.createRangeFromPositions(this.tokens.print.range.start, this.expressions.length
426
- ? this.expressions[this.expressions.length - 1].range.end
427
- : this.tokens.print.range.end);
422
+ this.range = util_1.util.createBoundingRange(tokens.print, ...(expressions !== null && expressions !== void 0 ? expressions : []));
428
423
  }
429
424
  transpile(state) {
430
425
  var _a;
@@ -457,14 +452,13 @@ class PrintStatement extends AstNode_1.Statement {
457
452
  exports.PrintStatement = PrintStatement;
458
453
  class DimStatement extends AstNode_1.Statement {
459
454
  constructor(dimToken, identifier, openingSquare, dimensions, closingSquare) {
460
- var _a, _b, _c, _d;
461
455
  super();
462
456
  this.dimToken = dimToken;
463
457
  this.identifier = identifier;
464
458
  this.openingSquare = openingSquare;
465
459
  this.dimensions = dimensions;
466
460
  this.closingSquare = closingSquare;
467
- this.range = util_1.util.createRangeFromPositions(this.dimToken.range.start, ((_d = (_c = (_b = (_a = this.closingSquare) !== null && _a !== void 0 ? _a : this.dimensions[this.dimensions.length - 1]) !== null && _b !== void 0 ? _b : this.openingSquare) !== null && _c !== void 0 ? _c : this.identifier) !== null && _d !== void 0 ? _d : this.dimToken).range.end);
461
+ this.range = util_1.util.createBoundingRange(dimToken, identifier, openingSquare, ...(dimensions !== null && dimensions !== void 0 ? dimensions : []), closingSquare);
468
462
  }
469
463
  transpile(state) {
470
464
  let result = [
@@ -494,7 +488,7 @@ class GotoStatement extends AstNode_1.Statement {
494
488
  constructor(tokens) {
495
489
  super();
496
490
  this.tokens = tokens;
497
- this.range = util_1.util.createRangeFromPositions(this.tokens.goto.range.start, this.tokens.label.range.end);
491
+ this.range = util_1.util.createBoundingRange(tokens.goto, tokens.label);
498
492
  }
499
493
  transpile(state) {
500
494
  return [
@@ -512,7 +506,7 @@ class LabelStatement extends AstNode_1.Statement {
512
506
  constructor(tokens) {
513
507
  super();
514
508
  this.tokens = tokens;
515
- this.range = util_1.util.createRangeFromPositions(this.tokens.identifier.range.start, this.tokens.colon.range.end);
509
+ this.range = util_1.util.createBoundingRange(tokens.identifier, tokens.colon);
516
510
  }
517
511
  transpile(state) {
518
512
  return [
@@ -527,11 +521,10 @@ class LabelStatement extends AstNode_1.Statement {
527
521
  exports.LabelStatement = LabelStatement;
528
522
  class ReturnStatement extends AstNode_1.Statement {
529
523
  constructor(tokens, value) {
530
- var _a;
531
524
  super();
532
525
  this.tokens = tokens;
533
526
  this.value = value;
534
- this.range = util_1.util.createRangeFromPositions(this.tokens.return.range.start, ((_a = this.value) === null || _a === void 0 ? void 0 : _a.range.end) || this.tokens.return.range.end);
527
+ this.range = util_1.util.createBoundingRange(tokens.return, value);
535
528
  }
536
529
  transpile(state) {
537
530
  let result = [];
@@ -553,7 +546,7 @@ class EndStatement extends AstNode_1.Statement {
553
546
  constructor(tokens) {
554
547
  super();
555
548
  this.tokens = tokens;
556
- this.range = util_1.util.createRangeFromPositions(this.tokens.end.range.start, this.tokens.end.range.end);
549
+ this.range = tokens.end.range;
557
550
  }
558
551
  transpile(state) {
559
552
  return [
@@ -567,9 +560,10 @@ class EndStatement extends AstNode_1.Statement {
567
560
  exports.EndStatement = EndStatement;
568
561
  class StopStatement extends AstNode_1.Statement {
569
562
  constructor(tokens) {
563
+ var _a;
570
564
  super();
571
565
  this.tokens = tokens;
572
- this.range = util_1.util.createRangeFromPositions(this.tokens.stop.range.start, this.tokens.stop.range.end);
566
+ this.range = (_a = tokens === null || tokens === void 0 ? void 0 : tokens.stop) === null || _a === void 0 ? void 0 : _a.range;
573
567
  }
574
568
  transpile(state) {
575
569
  return [
@@ -583,7 +577,6 @@ class StopStatement extends AstNode_1.Statement {
583
577
  exports.StopStatement = StopStatement;
584
578
  class ForStatement extends AstNode_1.Statement {
585
579
  constructor(forToken, counterDeclaration, toToken, finalValue, body, endForToken, stepToken, increment) {
586
- var _a, _b;
587
580
  super();
588
581
  this.forToken = forToken;
589
582
  this.counterDeclaration = counterDeclaration;
@@ -593,8 +586,7 @@ class ForStatement extends AstNode_1.Statement {
593
586
  this.endForToken = endForToken;
594
587
  this.stepToken = stepToken;
595
588
  this.increment = increment;
596
- const lastRange = (_b = (_a = this.endForToken) === null || _a === void 0 ? void 0 : _a.range) !== null && _b !== void 0 ? _b : body.range;
597
- this.range = util_1.util.createRangeFromPositions(this.forToken.range.start, lastRange.end);
589
+ this.range = util_1.util.createBoundingRange(forToken, counterDeclaration, toToken, finalValue, stepToken, increment, body, endForToken);
598
590
  }
599
591
  transpile(state) {
600
592
  let result = [];
@@ -636,14 +628,12 @@ class ForStatement extends AstNode_1.Statement {
636
628
  exports.ForStatement = ForStatement;
637
629
  class ForEachStatement extends AstNode_1.Statement {
638
630
  constructor(tokens, item, target, body) {
639
- var _a, _b;
640
631
  super();
641
632
  this.tokens = tokens;
642
633
  this.item = item;
643
634
  this.target = target;
644
635
  this.body = body;
645
- const lastRange = (_b = (_a = this.tokens.endFor) === null || _a === void 0 ? void 0 : _a.range) !== null && _b !== void 0 ? _b : body.range;
646
- this.range = util_1.util.createRangeFromPositions(this.tokens.forEach.range.start, lastRange.end);
636
+ this.range = util_1.util.createBoundingRange(tokens.forEach, item, tokens.in, target, body, tokens.endFor);
647
637
  }
648
638
  transpile(state) {
649
639
  let result = [];
@@ -677,13 +667,11 @@ class ForEachStatement extends AstNode_1.Statement {
677
667
  exports.ForEachStatement = ForEachStatement;
678
668
  class WhileStatement extends AstNode_1.Statement {
679
669
  constructor(tokens, condition, body) {
680
- var _a, _b;
681
670
  super();
682
671
  this.tokens = tokens;
683
672
  this.condition = condition;
684
673
  this.body = body;
685
- const lastRange = (_b = (_a = this.tokens.endWhile) === null || _a === void 0 ? void 0 : _a.range) !== null && _b !== void 0 ? _b : body.range;
686
- this.range = util_1.util.createRangeFromPositions(this.tokens.while.range.start, lastRange.end);
674
+ this.range = util_1.util.createBoundingRange(tokens.while, condition, body, tokens.endWhile);
687
675
  }
688
676
  transpile(state) {
689
677
  let result = [];
@@ -718,7 +706,7 @@ class DottedSetStatement extends AstNode_1.Statement {
718
706
  this.name = name;
719
707
  this.value = value;
720
708
  this.dot = dot;
721
- this.range = util_1.util.createRangeFromPositions(this.obj.range.start, this.value.range.end);
709
+ this.range = util_1.util.createBoundingRange(obj, dot, name, value);
722
710
  }
723
711
  transpile(state) {
724
712
  var _a, _b;
@@ -755,7 +743,7 @@ class IndexedSetStatement extends AstNode_1.Statement {
755
743
  this.value = value;
756
744
  this.openingSquare = openingSquare;
757
745
  this.closingSquare = closingSquare;
758
- this.range = util_1.util.createRangeFromPositions(this.obj.range.start, this.value.range.end);
746
+ this.range = util_1.util.createBoundingRange(obj, openingSquare, index, closingSquare, value);
759
747
  }
760
748
  transpile(state) {
761
749
  var _a, _b;
@@ -793,7 +781,7 @@ class LibraryStatement extends AstNode_1.Statement {
793
781
  constructor(tokens) {
794
782
  super();
795
783
  this.tokens = tokens;
796
- this.range = util_1.util.createRangeFromPositions(this.tokens.library.range.start, this.tokens.filePath ? this.tokens.filePath.range.end : this.tokens.library.range.end);
784
+ this.range = util_1.util.createBoundingRange(this.tokens.library, this.tokens.filePath);
797
785
  }
798
786
  transpile(state) {
799
787
  let result = [];
@@ -874,7 +862,7 @@ class ImportStatement extends AstNode_1.Statement {
874
862
  super();
875
863
  this.importToken = importToken;
876
864
  this.filePathToken = filePathToken;
877
- this.range = util_1.util.createRangeFromPositions(importToken.range.start, (filePathToken !== null && filePathToken !== void 0 ? filePathToken : importToken).range.end);
865
+ this.range = util_1.util.createBoundingRange(importToken, filePathToken);
878
866
  if (this.filePathToken) {
879
867
  //remove quotes
880
868
  this.filePath = this.filePathToken.text.replace(/"/g, '');
@@ -1026,14 +1014,11 @@ class InterfaceFieldStatement extends AstNode_1.Statement {
1026
1014
  this.tokens.name = nameToken;
1027
1015
  this.tokens.as = asToken;
1028
1016
  this.tokens.type = typeToken;
1017
+ this.range = util_1.util.createBoundingRange(nameToken, asToken, typeToken);
1029
1018
  }
1030
1019
  transpile(state) {
1031
1020
  throw new Error('Method not implemented.');
1032
1021
  }
1033
- get range() {
1034
- var _a, _b;
1035
- return util_1.util.createRangeFromPositions(this.tokens.name.range.start, ((_b = (_a = this.tokens.type) !== null && _a !== void 0 ? _a : this.tokens.as) !== null && _b !== void 0 ? _b : this.tokens.name).range.end);
1036
- }
1037
1022
  get name() {
1038
1023
  return this.tokens.name.text;
1039
1024
  }
@@ -1071,8 +1056,8 @@ class InterfaceMethodStatement extends AstNode_1.Statement {
1071
1056
  throw new Error('Method not implemented.');
1072
1057
  }
1073
1058
  get range() {
1074
- var _a, _b, _c, _d, _e, _f, _g, _h;
1075
- return util_1.util.createRangeFromPositions(this.tokens.name.range.start, ((_h = (_g = (_f = (_c = (_b = (_a = this.tokens.returnType) !== null && _a !== void 0 ? _a : this.tokens.as) !== null && _b !== void 0 ? _b : this.tokens.rightParen) !== null && _c !== void 0 ? _c : (_d = this.params) === null || _d === void 0 ? void 0 : _d[((_e = this.params) === null || _e === void 0 ? void 0 : _e.length) - 1]) !== null && _f !== void 0 ? _f : this.tokens.leftParen) !== null && _g !== void 0 ? _g : this.tokens.name) !== null && _h !== void 0 ? _h : this.tokens.functionType).range.end);
1059
+ var _a;
1060
+ return util_1.util.createBoundingRange(this.tokens.functionType, this.tokens.name, this.tokens.leftParen, ...((_a = this.params) !== null && _a !== void 0 ? _a : []), this.tokens.rightParen, this.tokens.as, this.tokens.returnType);
1076
1061
  }
1077
1062
  walk(visitor, options) {
1078
1063
  //nothing to walk
@@ -1131,7 +1116,7 @@ class ClassStatement extends AstNode_1.Statement {
1131
1116
  this.memberMap[(_c = statement === null || statement === void 0 ? void 0 : statement.name) === null || _c === void 0 ? void 0 : _c.text.toLowerCase()] = statement;
1132
1117
  }
1133
1118
  }
1134
- this.range = util_1.util.createRangeFromPositions(this.classKeyword.range.start, this.end.range.end);
1119
+ this.range = util_1.util.createBoundingRange(classKeyword, name, extendsKeyword, parentClassName, ...(body !== null && body !== void 0 ? body : []), end);
1135
1120
  }
1136
1121
  /**
1137
1122
  * Get the name of the wrapping namespace (if it exists)
@@ -1406,7 +1391,6 @@ const accessModifiers = [
1406
1391
  ];
1407
1392
  class MethodStatement extends FunctionStatement {
1408
1393
  constructor(modifiers, name, func, override) {
1409
- var _a;
1410
1394
  super(name, func);
1411
1395
  this.override = override;
1412
1396
  this.modifiers = [];
@@ -1418,7 +1402,7 @@ class MethodStatement extends FunctionStatement {
1418
1402
  this.modifiers.push(modifiers);
1419
1403
  }
1420
1404
  }
1421
- this.range = util_1.util.createRangeFromPositions(((_a = this.accessModifier) !== null && _a !== void 0 ? _a : this.func).range.start, this.func.range.end);
1405
+ this.range = util_1.util.createBoundingRange(...(this.modifiers), override, func);
1422
1406
  }
1423
1407
  get accessModifier() {
1424
1408
  return this.modifiers.find(x => accessModifiers.includes(x.kind));
@@ -1551,7 +1535,6 @@ class ClassMethodStatement extends MethodStatement {
1551
1535
  exports.ClassMethodStatement = ClassMethodStatement;
1552
1536
  class FieldStatement extends AstNode_1.Statement {
1553
1537
  constructor(accessModifier, name, as, type, equal, initialValue) {
1554
- var _a, _b, _c, _d;
1555
1538
  super();
1556
1539
  this.accessModifier = accessModifier;
1557
1540
  this.name = name;
@@ -1559,7 +1542,7 @@ class FieldStatement extends AstNode_1.Statement {
1559
1542
  this.type = type;
1560
1543
  this.equal = equal;
1561
1544
  this.initialValue = initialValue;
1562
- this.range = util_1.util.createRangeFromPositions(((_a = this.accessModifier) !== null && _a !== void 0 ? _a : this.name).range.start, ((_d = (_c = (_b = this.initialValue) !== null && _b !== void 0 ? _b : this.type) !== null && _c !== void 0 ? _c : this.as) !== null && _d !== void 0 ? _d : this.name).range.end);
1545
+ this.range = util_1.util.createBoundingRange(accessModifier, name, as, type, equal, initialValue);
1563
1546
  }
1564
1547
  /**
1565
1548
  * Derive a ValueKind from the type token, or the initial value.
@@ -1613,10 +1596,7 @@ class TryCatchStatement extends AstNode_1.Statement {
1613
1596
  this.tokens = tokens;
1614
1597
  this.tryBranch = tryBranch;
1615
1598
  this.catchStatement = catchStatement;
1616
- }
1617
- get range() {
1618
- var _a, _b, _c;
1619
- return util_1.util.createRangeFromPositions(this.tokens.try.range.start, ((_c = (_b = (_a = this.tokens.endTry) !== null && _a !== void 0 ? _a : this.catchStatement) !== null && _b !== void 0 ? _b : this.tryBranch) !== null && _c !== void 0 ? _c : this.tokens.try).range.end);
1599
+ this.range = util_1.util.createBoundingRange(tokens.try, tryBranch, catchStatement, tokens.endTry);
1620
1600
  }
1621
1601
  transpile(state) {
1622
1602
  var _a, _b;
@@ -1645,10 +1625,7 @@ class CatchStatement extends AstNode_1.Statement {
1645
1625
  this.tokens = tokens;
1646
1626
  this.exceptionVariable = exceptionVariable;
1647
1627
  this.catchBranch = catchBranch;
1648
- }
1649
- get range() {
1650
- var _a, _b;
1651
- return util_1.util.createRangeFromPositions(this.tokens.catch.range.start, ((_b = (_a = this.catchBranch) !== null && _a !== void 0 ? _a : this.exceptionVariable) !== null && _b !== void 0 ? _b : this.tokens.catch).range.end);
1628
+ this.range = util_1.util.createBoundingRange(tokens.catch, exceptionVariable, catchBranch);
1652
1629
  }
1653
1630
  transpile(state) {
1654
1631
  var _a, _b, _c, _d;
@@ -1668,11 +1645,10 @@ class CatchStatement extends AstNode_1.Statement {
1668
1645
  exports.CatchStatement = CatchStatement;
1669
1646
  class ThrowStatement extends AstNode_1.Statement {
1670
1647
  constructor(throwToken, expression) {
1671
- var _a;
1672
1648
  super();
1673
1649
  this.throwToken = throwToken;
1674
1650
  this.expression = expression;
1675
- this.range = util_1.util.createRangeFromPositions(this.throwToken.range.start, ((_a = this.expression) !== null && _a !== void 0 ? _a : this.throwToken).range.end);
1651
+ this.range = util_1.util.createBoundingRange(throwToken, expression);
1676
1652
  }
1677
1653
  transpile(state) {
1678
1654
  const result = [
@@ -1705,8 +1681,7 @@ class EnumStatement extends AstNode_1.Statement {
1705
1681
  this.body = (_a = this.body) !== null && _a !== void 0 ? _a : [];
1706
1682
  }
1707
1683
  get range() {
1708
- var _a, _b, _c;
1709
- return util_1.util.createRangeFromPositions((_a = this.tokens.enum.range.start) !== null && _a !== void 0 ? _a : vscode_languageserver_1.Position.create(0, 0), ((_c = (_b = this.tokens.endEnum) !== null && _b !== void 0 ? _b : this.tokens.name) !== null && _c !== void 0 ? _c : this.tokens.enum).range.end);
1684
+ return util_1.util.createBoundingRange(this.tokens.enum, this.tokens.name, ...this.body, this.tokens.endEnum);
1710
1685
  }
1711
1686
  /**
1712
1687
  * Get the name of the wrapping namespace (if it exists)
@@ -1834,8 +1809,7 @@ class EnumMemberStatement extends AstNode_1.Statement {
1834
1809
  return this.tokens.name.text;
1835
1810
  }
1836
1811
  get range() {
1837
- var _a, _b, _c, _d, _e;
1838
- return util_1.util.createRangeFromPositions((_c = ((_b = (_a = this.tokens.name) !== null && _a !== void 0 ? _a : this.tokens.equal) !== null && _b !== void 0 ? _b : this.value).range.start) !== null && _c !== void 0 ? _c : vscode_languageserver_1.Position.create(0, 0), ((_e = (_d = this.value) !== null && _d !== void 0 ? _d : this.tokens.equal) !== null && _e !== void 0 ? _e : this.tokens.name).range.end);
1812
+ return util_1.util.createBoundingRange(this.tokens.name, this.tokens.equal, this.value);
1839
1813
  }
1840
1814
  transpile(state) {
1841
1815
  return [];
@@ -1916,9 +1890,7 @@ class ContinueStatement extends AstNode_1.Statement {
1916
1890
  constructor(tokens) {
1917
1891
  super();
1918
1892
  this.tokens = tokens;
1919
- }
1920
- get range() {
1921
- return this.tokens.continue.range;
1893
+ this.range = util_1.util.createBoundingRange(tokens.continue, tokens.loopType);
1922
1894
  }
1923
1895
  transpile(state) {
1924
1896
  var _a, _b, _c, _d, _e;