brighterscript 1.0.0-alpha.16 → 1.0.0-alpha.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +42 -1
- package/README.md +28 -9
- package/dist/Logger.js +5 -5
- package/dist/Logger.js.map +1 -1
- package/dist/Program.d.ts +2 -2
- package/dist/Program.js +3 -3
- package/dist/Program.js.map +1 -1
- package/dist/ProgramBuilder.js +1 -1
- package/dist/ProgramBuilder.js.map +1 -1
- package/dist/Scope.js +13 -9
- package/dist/Scope.js.map +1 -1
- package/dist/XmlScope.js +1 -1
- package/dist/XmlScope.js.map +1 -1
- package/dist/astUtils/creators.d.ts +3 -3
- package/dist/astUtils/creators.js +8 -8
- package/dist/astUtils/creators.js.map +1 -1
- package/dist/astUtils/creators.spec.js +10 -0
- package/dist/astUtils/creators.spec.js.map +1 -1
- package/dist/astUtils/reflection.d.ts +2 -1
- package/dist/astUtils/reflection.js +5 -1
- package/dist/astUtils/reflection.js.map +1 -1
- package/dist/astUtils/visitors.spec.js +2 -0
- package/dist/astUtils/visitors.spec.js.map +1 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +2 -2
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -1
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js +7 -3
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js.map +1 -1
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.d.ts +1 -0
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js +32 -0
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js.map +1 -0
- package/dist/examples/plugins/removePrint.js +12 -14
- package/dist/examples/plugins/removePrint.js.map +1 -1
- package/dist/files/BrsFile.Class.spec.js +1 -1
- package/dist/files/BrsFile.d.ts +1 -2
- package/dist/files/BrsFile.js +24 -20
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/BrsFile.spec.js +171 -64
- package/dist/files/BrsFile.spec.js.map +1 -1
- package/dist/parser/Expression.d.ts +68 -6
- package/dist/parser/Expression.js +133 -18
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Parser.Class.spec.js +1 -1
- package/dist/parser/Parser.Class.spec.js.map +1 -1
- package/dist/parser/Parser.d.ts +1 -1
- package/dist/parser/Parser.js +49 -46
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/Parser.spec.js +57 -2
- package/dist/parser/Parser.spec.js.map +1 -1
- package/dist/parser/Statement.d.ts +17 -13
- package/dist/parser/Statement.js +36 -26
- package/dist/parser/Statement.js.map +1 -1
- package/dist/types/BooleanType.d.ts +4 -2
- package/dist/types/BooleanType.js +5 -1
- package/dist/types/BooleanType.js.map +1 -1
- package/dist/types/DoubleType.d.ts +2 -0
- package/dist/types/DoubleType.js +5 -1
- package/dist/types/DoubleType.js.map +1 -1
- package/dist/types/DynamicType.d.ts +2 -0
- package/dist/types/DynamicType.js +5 -1
- package/dist/types/DynamicType.js.map +1 -1
- package/dist/types/FloatType.d.ts +3 -1
- package/dist/types/FloatType.js +5 -1
- package/dist/types/FloatType.js.map +1 -1
- package/dist/types/IntegerType.d.ts +3 -1
- package/dist/types/IntegerType.js +5 -1
- package/dist/types/IntegerType.js.map +1 -1
- package/dist/types/InvalidType.d.ts +4 -2
- package/dist/types/InvalidType.js +5 -1
- package/dist/types/InvalidType.js.map +1 -1
- package/dist/types/LongIntegerType.d.ts +3 -1
- package/dist/types/LongIntegerType.js +5 -1
- package/dist/types/LongIntegerType.js.map +1 -1
- package/dist/types/ObjectType.d.ts +2 -1
- package/dist/types/ObjectType.js +4 -2
- package/dist/types/ObjectType.js.map +1 -1
- package/dist/types/StringType.d.ts +4 -2
- package/dist/types/StringType.js +5 -1
- package/dist/types/StringType.js.map +1 -1
- package/dist/types/UninitializedType.js.map +1 -1
- package/dist/types/VoidType.d.ts +4 -2
- package/dist/types/VoidType.js +5 -1
- package/dist/types/VoidType.js.map +1 -1
- package/dist/util.d.ts +1 -1
- package/dist/util.js +22 -33
- package/dist/util.js.map +1 -1
- package/dist/validators/ClassValidator.js +3 -3
- package/dist/validators/ClassValidator.js.map +1 -1
- package/package.json +2 -2
package/dist/parser/Parser.js
CHANGED
|
@@ -246,13 +246,12 @@ class Parser {
|
|
|
246
246
|
interfaceFieldStatement() {
|
|
247
247
|
const name = this.identifier(...TokenKind_1.AllowedProperties);
|
|
248
248
|
let asToken = this.consumeToken(TokenKind_1.TokenKind.As);
|
|
249
|
-
let
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.functionParameterTypeIsInvalid(name.text, typeToken.text)), { range: typeToken.range }));
|
|
249
|
+
let typeExpr = this.typeExpression();
|
|
250
|
+
if (!typeExpr.isValidType()) {
|
|
251
|
+
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.functionParameterTypeIsInvalid(name.text, typeExpr.getText())), { range: typeExpr.range }));
|
|
253
252
|
throw this.lastDiagnosticAsError();
|
|
254
253
|
}
|
|
255
|
-
return new Statement_1.InterfaceFieldStatement(name, asToken,
|
|
254
|
+
return new Statement_1.InterfaceFieldStatement(name, asToken, typeExpr);
|
|
256
255
|
}
|
|
257
256
|
/**
|
|
258
257
|
* Create a new InterfaceMethodStatement. This should only be called from within `interfaceDeclaration()`
|
|
@@ -264,17 +263,16 @@ class Parser {
|
|
|
264
263
|
const params = [];
|
|
265
264
|
const rightParen = this.consumeToken(TokenKind_1.TokenKind.RightParen);
|
|
266
265
|
let asToken = null;
|
|
267
|
-
let
|
|
266
|
+
let returnTypeExpr;
|
|
268
267
|
if (this.check(TokenKind_1.TokenKind.As)) {
|
|
269
268
|
asToken = this.advance();
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.functionParameterTypeIsInvalid(name.text, returnTypeToken.text)), { range: returnTypeToken.range }));
|
|
269
|
+
returnTypeExpr = this.typeExpression();
|
|
270
|
+
if (!returnTypeExpr.isValidType(this.options.mode)) {
|
|
271
|
+
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.functionParameterTypeIsInvalid(name.text, returnTypeExpr.getText())), { range: returnTypeExpr.range }));
|
|
274
272
|
throw this.lastDiagnosticAsError();
|
|
275
273
|
}
|
|
276
274
|
}
|
|
277
|
-
return new Statement_1.InterfaceMethodStatement(functionType, name, leftParen, params, rightParen, asToken,
|
|
275
|
+
return new Statement_1.InterfaceMethodStatement(functionType, name, leftParen, params, rightParen, asToken, returnTypeExpr);
|
|
278
276
|
}
|
|
279
277
|
interfaceDeclaration() {
|
|
280
278
|
this.warnIfNotBrighterScriptMode('interface declarations');
|
|
@@ -476,13 +474,13 @@ class Parser {
|
|
|
476
474
|
classFieldDeclaration(accessModifier) {
|
|
477
475
|
let name = this.consume(DiagnosticMessages_1.DiagnosticMessages.expectedClassFieldIdentifier(), TokenKind_1.TokenKind.Identifier, ...TokenKind_1.AllowedProperties);
|
|
478
476
|
let asToken;
|
|
479
|
-
let
|
|
477
|
+
let fieldTypeExpr;
|
|
480
478
|
//look for `as SOME_TYPE`
|
|
481
479
|
if (this.check(TokenKind_1.TokenKind.As)) {
|
|
482
480
|
asToken = this.advance();
|
|
483
|
-
|
|
481
|
+
fieldTypeExpr = this.typeExpression();
|
|
484
482
|
//no field type specified
|
|
485
|
-
if (!
|
|
483
|
+
if (!fieldTypeExpr.isValidType(this.options.mode)) {
|
|
486
484
|
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.expectedValidTypeToFollowAsKeyword()), { range: this.peek().range }));
|
|
487
485
|
}
|
|
488
486
|
}
|
|
@@ -493,7 +491,7 @@ class Parser {
|
|
|
493
491
|
equal = this.advance();
|
|
494
492
|
initialValue = this.expression();
|
|
495
493
|
}
|
|
496
|
-
return new Statement_1.ClassFieldStatement(accessModifier, name, asToken,
|
|
494
|
+
return new Statement_1.ClassFieldStatement(accessModifier, name, asToken, fieldTypeExpr, equal, initialValue, this.currentNamespaceName);
|
|
497
495
|
}
|
|
498
496
|
functionDeclaration(isAnonymous, checkIdentifier = true, forClassMethod = false) {
|
|
499
497
|
var _a, _b, _c, _d;
|
|
@@ -543,7 +541,7 @@ class Parser {
|
|
|
543
541
|
}
|
|
544
542
|
let params = [];
|
|
545
543
|
let asToken;
|
|
546
|
-
let
|
|
544
|
+
let typeExpr;
|
|
547
545
|
if (!this.check(TokenKind_1.TokenKind.RightParen)) {
|
|
548
546
|
do {
|
|
549
547
|
if (params.length >= Expression_1.CallExpression.MaximumArguments) {
|
|
@@ -555,9 +553,9 @@ class Parser {
|
|
|
555
553
|
let rightParen = this.advance();
|
|
556
554
|
if (this.check(TokenKind_1.TokenKind.As)) {
|
|
557
555
|
asToken = this.advance();
|
|
558
|
-
|
|
559
|
-
if (!
|
|
560
|
-
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.invalidFunctionReturnType((_a =
|
|
556
|
+
typeExpr = this.typeExpression();
|
|
557
|
+
if (!typeExpr.isValidType(this.options.mode)) {
|
|
558
|
+
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.invalidFunctionReturnType((_a = typeExpr.getText()) !== null && _a !== void 0 ? _a : '')), { range: typeExpr.range }));
|
|
561
559
|
}
|
|
562
560
|
}
|
|
563
561
|
params.reduce((haveFoundOptional, param) => {
|
|
@@ -569,7 +567,7 @@ class Parser {
|
|
|
569
567
|
this.consumeStatementSeparators(true);
|
|
570
568
|
let func = new Expression_1.FunctionExpression(params, undefined, //body
|
|
571
569
|
functionType, undefined, //ending keyword
|
|
572
|
-
leftParen, rightParen, asToken,
|
|
570
|
+
leftParen, rightParen, asToken, typeExpr, //return type
|
|
573
571
|
this.currentFunctionExpression, this.currentNamespaceName, (_c = (_b = this.currentNamespace) === null || _b === void 0 ? void 0 : _b.symbolTable) !== null && _c !== void 0 ? _c : this.symbolTable);
|
|
574
572
|
//if there is a parent function, register this function with the parent
|
|
575
573
|
if (this.currentFunctionExpression) {
|
|
@@ -638,7 +636,7 @@ class Parser {
|
|
|
638
636
|
throw this.lastDiagnosticAsError();
|
|
639
637
|
}
|
|
640
638
|
const name = this.identifier(...TokenKind_1.AllowedLocalIdentifiers);
|
|
641
|
-
let
|
|
639
|
+
let typeExpr;
|
|
642
640
|
let defaultValue;
|
|
643
641
|
let equalsToken;
|
|
644
642
|
// parse argument default value
|
|
@@ -650,26 +648,26 @@ class Parser {
|
|
|
650
648
|
let asToken = null;
|
|
651
649
|
if (this.check(TokenKind_1.TokenKind.As)) {
|
|
652
650
|
asToken = this.advance();
|
|
653
|
-
|
|
654
|
-
if (!
|
|
655
|
-
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.functionParameterTypeIsInvalid(name.text,
|
|
651
|
+
typeExpr = this.typeExpression();
|
|
652
|
+
if (!typeExpr.isValidType(this.options.mode)) {
|
|
653
|
+
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.functionParameterTypeIsInvalid(name.text, typeExpr.getText())), { range: typeExpr.range }));
|
|
656
654
|
throw this.lastDiagnosticAsError();
|
|
657
655
|
}
|
|
658
656
|
}
|
|
659
|
-
let
|
|
660
|
-
if (
|
|
661
|
-
|
|
657
|
+
let typeInContext;
|
|
658
|
+
if (typeExpr) {
|
|
659
|
+
typeInContext = typeExpr.type;
|
|
662
660
|
}
|
|
663
661
|
else if (defaultValue) {
|
|
664
|
-
|
|
665
|
-
if ((0, reflection_1.isInvalidType)(
|
|
666
|
-
|
|
662
|
+
typeInContext = getBscTypeFromExpression(defaultValue, this.currentFunctionExpression);
|
|
663
|
+
if ((0, reflection_1.isInvalidType)(typeInContext)) {
|
|
664
|
+
typeInContext = new DynamicType_1.DynamicType();
|
|
667
665
|
}
|
|
668
666
|
}
|
|
669
667
|
else {
|
|
670
|
-
|
|
668
|
+
typeInContext = new DynamicType_1.DynamicType();
|
|
671
669
|
}
|
|
672
|
-
return new Expression_1.FunctionParameterExpression(name,
|
|
670
|
+
return new Expression_1.FunctionParameterExpression(name, typeInContext, equalsToken, defaultValue, asToken, typeExpr, this.currentNamespaceName);
|
|
673
671
|
}
|
|
674
672
|
assignment() {
|
|
675
673
|
let name = this.identifier(...this.allowedLocalIdentifiers);
|
|
@@ -863,6 +861,12 @@ class Parser {
|
|
|
863
861
|
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.expectedExpressionAfterForEachIn()), { range: this.peek().range }));
|
|
864
862
|
throw this.lastDiagnosticAsError();
|
|
865
863
|
}
|
|
864
|
+
let itemType = new DynamicType_1.DynamicType();
|
|
865
|
+
const targetType = getBscTypeFromExpression(target, this.currentFunctionExpression);
|
|
866
|
+
if ((0, reflection_1.isArrayType)(targetType)) {
|
|
867
|
+
itemType = targetType.getDefaultType();
|
|
868
|
+
}
|
|
869
|
+
this.currentSymbolTable.addSymbol(name.text, name.range, itemType);
|
|
866
870
|
this.consumeStatementSeparators();
|
|
867
871
|
let body = this.block(TokenKind_1.TokenKind.EndFor, TokenKind_1.TokenKind.Next);
|
|
868
872
|
if (!body) {
|
|
@@ -870,12 +874,6 @@ class Parser {
|
|
|
870
874
|
throw this.lastDiagnosticAsError();
|
|
871
875
|
}
|
|
872
876
|
let endFor = this.advance();
|
|
873
|
-
let itemType = new DynamicType_1.DynamicType();
|
|
874
|
-
const targetType = getBscTypeFromExpression(target, this.currentFunctionExpression);
|
|
875
|
-
if ((0, reflection_1.isArrayType)(targetType)) {
|
|
876
|
-
itemType = targetType.getDefaultType();
|
|
877
|
-
}
|
|
878
|
-
this.currentSymbolTable.addSymbol(name.text, name.range, itemType);
|
|
879
877
|
return new Statement_1.ForEachStatement(forEach, name, maybeIn, target, body, endFor);
|
|
880
878
|
}
|
|
881
879
|
exitFor() {
|
|
@@ -1784,7 +1782,7 @@ class Parser {
|
|
|
1784
1782
|
* Allows for built-in types (double, string, etc.) or namespaced custom types in Brighterscript mode
|
|
1785
1783
|
* Will return a token of whatever is next to be parsed (unless `advanceIfUnknown` is false, in which case undefined will be returned instead
|
|
1786
1784
|
*/
|
|
1787
|
-
|
|
1785
|
+
typeExpression() {
|
|
1788
1786
|
let typeToken;
|
|
1789
1787
|
if (this.checkAny(...TokenKind_1.DeclarableTypes)) {
|
|
1790
1788
|
// Token is a built in type
|
|
@@ -1805,18 +1803,23 @@ class Parser {
|
|
|
1805
1803
|
// just get whatever's next
|
|
1806
1804
|
typeToken = this.advance();
|
|
1807
1805
|
}
|
|
1808
|
-
|
|
1806
|
+
//TODO: to support InterfaceTypeLiterals - (eg. `{name as string; age as integer}`), check if "typeToken" is a curly bracket, and do something else
|
|
1807
|
+
let typeExpr = new Expression_1.TypeExpression({ type: typeToken }, this.currentNamespaceName);
|
|
1808
|
+
if (this.options.mode === ParseMode.BrighterScript) {
|
|
1809
1809
|
// Check if it is an array - that is, if it has `[]` after the type
|
|
1810
|
-
// eg. `string[]` or `SomeKlass[]`
|
|
1811
|
-
|
|
1812
|
-
this.advance();
|
|
1810
|
+
// eg. `string[]` or `SomeKlass[]` or `float[][][]`
|
|
1811
|
+
while (this.check(TokenKind_1.TokenKind.LeftSquareBracket)) {
|
|
1812
|
+
const leftBracket = this.advance();
|
|
1813
1813
|
if (this.check(TokenKind_1.TokenKind.RightSquareBracket)) {
|
|
1814
1814
|
const rightBracket = this.advance();
|
|
1815
|
-
|
|
1815
|
+
typeExpr = new Expression_1.ArrayTypeExpression([typeExpr], { leftBracket: leftBracket, rightBracket: rightBracket }, this.currentNamespaceName);
|
|
1816
|
+
}
|
|
1817
|
+
else {
|
|
1818
|
+
break;
|
|
1816
1819
|
}
|
|
1817
1820
|
}
|
|
1818
1821
|
}
|
|
1819
|
-
return
|
|
1822
|
+
return typeExpr;
|
|
1820
1823
|
}
|
|
1821
1824
|
primary() {
|
|
1822
1825
|
switch (true) {
|
|
@@ -2587,7 +2590,7 @@ function getBscTypeFromExpression(expression, functionExpression) {
|
|
|
2587
2590
|
//Associative array literal
|
|
2588
2591
|
}
|
|
2589
2592
|
else if ((0, reflection_1.isAALiteralExpression)(expression)) {
|
|
2590
|
-
return new ObjectType_1.ObjectType(expression.memberTable);
|
|
2593
|
+
return new ObjectType_1.ObjectType('object', expression.memberTable);
|
|
2591
2594
|
//Array literal
|
|
2592
2595
|
}
|
|
2593
2596
|
else if ((0, reflection_1.isArrayLiteralExpression)(expression)) {
|