New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More →

brightscript-language

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

brightscript-language - npm Package Compare versions

Comparing version

to
0.1.18

@@ -9,4 +9,11 @@ # Changelog

## [0.1.18] - 2019-03-08
### Fixed
- issue where only top-level variables were being found. Now all variables are found throughout the entire function scope.
- runtime error when getting hover result.
- issue with hover that would not find top-level function parameter types.
## [0.1.17] - 2019-03-08
## Fixed
### Fixed
- Upgraded to brs@0.13.0-nightly.20190307 which fixed assignment operator parse errors. ([see this issue](https://github.com/sjbarag/brs/issues/173)).

@@ -57,2 +64,3 @@

[0.1.18]: https://github.com/TwitchBronBron/brightscript-language/compare/v0.1.17...v0.1.18
[0.1.17]: https://github.com/TwitchBronBron/brightscript-language/compare/v0.1.16...v0.1.17

@@ -59,0 +67,0 @@ [0.1.16]: https://github.com/TwitchBronBron/brightscript-language/compare/v0.1.15...v0.1.16

@@ -69,2 +69,3 @@ "use strict";

var brs = require("brs");
var Lexeme = brs.lexer.Lexeme;
var path = require("path");

@@ -98,2 +99,3 @@ var vscode_languageserver_1 = require("vscode-languageserver");

this.functionScopes = [];
this.tokens = [];
this.scopesByFunc = new Map();

@@ -225,2 +227,3 @@ this.extension = path.extname(pathAbsolute).toLowerCase();

scope.bodyRange = util_1.default.getBodyRangeForFunc(func);
scope.range = vscode_languageserver_1.Range.create(func.keyword.location.start.line - 1, func.keyword.location.start.column, func.end.location.end.line - 1, func.end.location.end.column);
try {

@@ -232,6 +235,5 @@ //add every parameter

nameRange: util_1.default.locationToRange(param.name.location),
lineIndex: scope.bodyRange.start.line,
lineIndex: param.name.location.start.line - 1,
name: param.name.text,
//TODO which is it? `type` or `kind`?
type: util_1.default.valueKindToBrsType(param.type || param.kind)
type: util_1.default.valueKindToBrsType(param.type.kind)
});

@@ -247,25 +249,2 @@ }

}
try {
//add every variable assignment to the scope
for (var _f = __values(func.body.statements), _g = _f.next(); !_g.done; _g = _f.next()) {
var statement = _g.value;
//if this is a variable assignment
if (statement instanceof brs.parser.Stmt.Assignment) {
scope.variableDeclarations.push({
nameRange: util_1.default.locationToRange(statement.name.location),
lineIndex: statement.name.location.start.line - 1,
name: statement.name.text,
type: this.getBRSTypeFromAssignment(statement, scope)
});
}
//TODO support things inside of loops, conditionals, etc
}
}
catch (e_5_1) { e_5 = { error: e_5_1 }; }
finally {
try {
if (_g && !_g.done && (_c = _f.return)) _c.call(_f);
}
finally { if (e_5) throw e_5.error; }
}
this.scopesByFunc.set(func, scope);

@@ -283,2 +262,29 @@ //find every statement in the scope

}
//find every variable assignment in the whole file
var assignmentStatements = util_1.default.findAllDeep(this.ast, function (x) { return x instanceof brs.parser.Stmt.Assignment; });
try {
for (var assignmentStatements_1 = __values(assignmentStatements), assignmentStatements_1_1 = assignmentStatements_1.next(); !assignmentStatements_1_1.done; assignmentStatements_1_1 = assignmentStatements_1.next()) {
var kvp = assignmentStatements_1_1.value;
var statement = kvp.value;
var nameRange = util_1.default.locationToRange(statement.name.location);
//find this statement's function scope
var scope = this.getFunctionScopeAtPosition(nameRange.start);
//skip variable declarations that are outside of any scope
if (scope) {
scope.variableDeclarations.push({
nameRange: nameRange,
lineIndex: statement.name.location.start.line - 1,
name: statement.name.text,
type: this.getBRSTypeFromAssignment(statement, scope)
});
}
}
}
catch (e_5_1) { e_5 = { error: e_5_1 }; }
finally {
try {
if (assignmentStatements_1_1 && !assignmentStatements_1_1.done && (_c = assignmentStatements_1.return)) _c.call(assignmentStatements_1);
}
finally { if (e_5) throw e_5.error; }
}
};

@@ -564,3 +570,3 @@ /**

var scope = functionScopes_1_1.value;
if (util_1.default.rangeContains(scope.bodyRange, position)) {
if (util_1.default.rangeContains(scope.range, position)) {
//see if any of that scope's children match the position also, and give them priority

@@ -617,4 +623,11 @@ var childScope = this.getFunctionScopeAtPosition(position, scope.childrenScopes);

var token = this.getTokenAt(position);
//if no token found or token does not look like an identifier, there's nothing to show
if (!token || /[\w\d_]+/gi.test(token.text) === false) {
var hoverTokenTypes = [
Lexeme.Identifier,
Lexeme.Function,
Lexeme.EndFunction,
Lexeme.Sub,
Lexeme.EndSub
];
//throw out invalid tokens and the wrong kind of tokens
if (!token || hoverTokenTypes.indexOf(token.kind) === -1) {
return null;

@@ -621,0 +634,0 @@ }

@@ -588,2 +588,13 @@ "use strict";

return __generator(this, function (_a) {
it('creates range properly', function () { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, file.parse("\n sub Main()\n name = 'bob\"\n end sub\n ")];
case 1:
_a.sent();
chai_1.expect(file.functionScopes[0].range).to.eql(vscode_languageserver_1.Range.create(1, 16, 3, 23));
return [2 /*return*/];
}
});
}); });
it('creates scopes for parent and child functions', function () { return __awaiter(_this, void 0, void 0, function () {

@@ -600,2 +611,17 @@ return __generator(this, function (_a) {

}); });
it('outer function does not capture inner statements', function () { return __awaiter(_this, void 0, void 0, function () {
var outerScope, innerScope;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, file.parse("\n sub Main()\n name = \"john\"\n sayHi = sub()\n age = 12\n end sub\n end sub\n ")];
case 1:
_a.sent();
outerScope = file.getFunctionScopeAtPosition(vscode_languageserver_1.Position.create(2, 25));
chai_1.expect(outerScope.variableDeclarations).to.be.lengthOf(2);
innerScope = file.getFunctionScopeAtPosition(vscode_languageserver_1.Position.create(4, 10));
chai_1.expect(innerScope.variableDeclarations).to.be.lengthOf(1);
return [2 /*return*/];
}
});
}); });
it('finds variables declared in function scopes', function () { return __awaiter(_this, void 0, void 0, function () {

@@ -629,2 +655,16 @@ return __generator(this, function (_a) {

}); });
it('finds variable declarations inside of if statements', function () { return __awaiter(_this, void 0, void 0, function () {
var scope;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, file.parse("\n sub Main()\n if true then\n theLength = 1\n end if\n end sub\n ")];
case 1:
_a.sent();
scope = file.getFunctionScopeAtPosition(vscode_languageserver_1.Position.create(3, 0));
chai_1.expect(scope.variableDeclarations[0]).to.exist;
chai_1.expect(scope.variableDeclarations[0].name).to.equal('theLength');
return [2 /*return*/];
}
});
}); });
it('finds value from global return', function () { return __awaiter(_this, void 0, void 0, function () {

@@ -730,2 +770,36 @@ return __generator(this, function (_a) {

describe('getHover', function () {
it('works for param types', function () { return __awaiter(_this, void 0, void 0, function () {
var file, hover;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, program.addOrReplaceFile(rootDir + "/source/main.brs", "\n sub DoSomething(name as string)\n name = 1\n sayMyName = function(name as string)\n end function\n end sub\n ")];
case 1:
file = _a.sent();
hover = file.getHover(vscode_languageserver_1.Position.create(2, 24));
chai_1.expect(hover).to.exist;
chai_1.expect(hover.range).to.eql(vscode_languageserver_1.Range.create(2, 20, 2, 24));
//hover over the `name` parameter declaration
hover = file.getHover(vscode_languageserver_1.Position.create(1, 34));
chai_1.expect(hover).to.exist;
chai_1.expect(hover.range).to.eql(vscode_languageserver_1.Range.create(1, 32, 1, 36));
return [2 /*return*/];
}
});
}); });
//ignore this for now...it's not a huge deal
it.skip('does not match on keywords or data types', function () { return __awaiter(_this, void 0, void 0, function () {
var file;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, program.addOrReplaceFile(rootDir + "/source/main.brs", "\n sub Main(name as string)\n end sub\n sub as()\n end sub\n ")];
case 1:
file = _a.sent();
//hover over the `as`
chai_1.expect(file.getHover(vscode_languageserver_1.Position.create(1, 31))).not.to.exist;
//hover over the `string`
chai_1.expect(file.getHover(vscode_languageserver_1.Position.create(1, 36))).not.to.exist;
return [2 /*return*/];
}
});
}); });
it('finds declared function', function () { return __awaiter(_this, void 0, void 0, function () {

@@ -732,0 +806,0 @@ var file, hover;

@@ -12,2 +12,7 @@ import * as brs from 'brs';

/**
* The full range of this function. Starts at the position of the `f` in function or `s` in sub,
* and ends after the final `n` in `end function` or `b` in end sub.
*/
range: Range;
/**
* The scopes that are children of this scope

@@ -14,0 +19,0 @@ */

@@ -139,89 +139,1 @@ import { Range } from 'vscode-languageserver';

}
export declare enum Lexeme {
LeftParen = 0,
RightParen = 1,
LeftSquare = 2,
RightSquare = 3,
LeftBrace = 4,
RightBrace = 5,
Caret = 6,
Minus = 7,
Plus = 8,
Star = 9,
Slash = 10,
Mod = 11,
Backslash = 12,
LeftShift = 13,
RightShift = 14,
Less = 15,
LessEqual = 16,
Greater = 17,
GreaterEqual = 18,
Equal = 19,
LessGreater = 20,
Identifier = 21,
String = 22,
Integer = 23,
Float = 24,
Double = 25,
LongInteger = 26,
Dot = 27,
Comma = 28,
Colon = 29,
Semicolon = 30,
HashIf = 31,
HashElseIf = 32,
HashElse = 33,
HashEndIf = 34,
HashConst = 35,
HashError = 36,
HashErrorMessage = 37,
And = 38,
Box = 39,
CreateObject = 40,
Dim = 41,
Else = 42,
ElseIf = 43,
End = 44,
EndFunction = 45,
EndFor = 46,
EndIf = 47,
EndSub = 48,
EndWhile = 49,
Eval = 50,
Exit = 51,
ExitFor = 52,
ExitWhile = 53,
False = 54,
For = 55,
ForEach = 56,
Function = 57,
GetGlobalAA = 58,
GetLastRunCompileError = 59,
GetLastRunRunTimeError = 60,
Goto = 61,
If = 62,
Invalid = 63,
Let = 64,
LineNum = 65,
Next = 66,
Not = 67,
ObjFun = 68,
Or = 69,
Pos = 70,
Print = 71,
Rem = 72,
Return = 73,
Run = 74,
Step = 75,
Stop = 76,
Sub = 77,
Tab = 78,
Then = 79,
To = 80,
True = 81,
Type = 82,
While = 83,
Newline = 84,
Eof = 85
}

@@ -19,91 +19,2 @@ "use strict";

})(ValueKind = exports.ValueKind || (exports.ValueKind = {}));
var Lexeme;
(function (Lexeme) {
Lexeme[Lexeme["LeftParen"] = 0] = "LeftParen";
Lexeme[Lexeme["RightParen"] = 1] = "RightParen";
Lexeme[Lexeme["LeftSquare"] = 2] = "LeftSquare";
Lexeme[Lexeme["RightSquare"] = 3] = "RightSquare";
Lexeme[Lexeme["LeftBrace"] = 4] = "LeftBrace";
Lexeme[Lexeme["RightBrace"] = 5] = "RightBrace";
Lexeme[Lexeme["Caret"] = 6] = "Caret";
Lexeme[Lexeme["Minus"] = 7] = "Minus";
Lexeme[Lexeme["Plus"] = 8] = "Plus";
Lexeme[Lexeme["Star"] = 9] = "Star";
Lexeme[Lexeme["Slash"] = 10] = "Slash";
Lexeme[Lexeme["Mod"] = 11] = "Mod";
Lexeme[Lexeme["Backslash"] = 12] = "Backslash";
Lexeme[Lexeme["LeftShift"] = 13] = "LeftShift";
Lexeme[Lexeme["RightShift"] = 14] = "RightShift";
Lexeme[Lexeme["Less"] = 15] = "Less";
Lexeme[Lexeme["LessEqual"] = 16] = "LessEqual";
Lexeme[Lexeme["Greater"] = 17] = "Greater";
Lexeme[Lexeme["GreaterEqual"] = 18] = "GreaterEqual";
Lexeme[Lexeme["Equal"] = 19] = "Equal";
Lexeme[Lexeme["LessGreater"] = 20] = "LessGreater";
Lexeme[Lexeme["Identifier"] = 21] = "Identifier";
Lexeme[Lexeme["String"] = 22] = "String";
Lexeme[Lexeme["Integer"] = 23] = "Integer";
Lexeme[Lexeme["Float"] = 24] = "Float";
Lexeme[Lexeme["Double"] = 25] = "Double";
Lexeme[Lexeme["LongInteger"] = 26] = "LongInteger";
Lexeme[Lexeme["Dot"] = 27] = "Dot";
Lexeme[Lexeme["Comma"] = 28] = "Comma";
Lexeme[Lexeme["Colon"] = 29] = "Colon";
Lexeme[Lexeme["Semicolon"] = 30] = "Semicolon";
Lexeme[Lexeme["HashIf"] = 31] = "HashIf";
Lexeme[Lexeme["HashElseIf"] = 32] = "HashElseIf";
Lexeme[Lexeme["HashElse"] = 33] = "HashElse";
Lexeme[Lexeme["HashEndIf"] = 34] = "HashEndIf";
Lexeme[Lexeme["HashConst"] = 35] = "HashConst";
Lexeme[Lexeme["HashError"] = 36] = "HashError";
Lexeme[Lexeme["HashErrorMessage"] = 37] = "HashErrorMessage";
Lexeme[Lexeme["And"] = 38] = "And";
Lexeme[Lexeme["Box"] = 39] = "Box";
Lexeme[Lexeme["CreateObject"] = 40] = "CreateObject";
Lexeme[Lexeme["Dim"] = 41] = "Dim";
Lexeme[Lexeme["Else"] = 42] = "Else";
Lexeme[Lexeme["ElseIf"] = 43] = "ElseIf";
Lexeme[Lexeme["End"] = 44] = "End";
Lexeme[Lexeme["EndFunction"] = 45] = "EndFunction";
Lexeme[Lexeme["EndFor"] = 46] = "EndFor";
Lexeme[Lexeme["EndIf"] = 47] = "EndIf";
Lexeme[Lexeme["EndSub"] = 48] = "EndSub";
Lexeme[Lexeme["EndWhile"] = 49] = "EndWhile";
Lexeme[Lexeme["Eval"] = 50] = "Eval";
Lexeme[Lexeme["Exit"] = 51] = "Exit";
Lexeme[Lexeme["ExitFor"] = 52] = "ExitFor";
Lexeme[Lexeme["ExitWhile"] = 53] = "ExitWhile";
Lexeme[Lexeme["False"] = 54] = "False";
Lexeme[Lexeme["For"] = 55] = "For";
Lexeme[Lexeme["ForEach"] = 56] = "ForEach";
Lexeme[Lexeme["Function"] = 57] = "Function";
Lexeme[Lexeme["GetGlobalAA"] = 58] = "GetGlobalAA";
Lexeme[Lexeme["GetLastRunCompileError"] = 59] = "GetLastRunCompileError";
Lexeme[Lexeme["GetLastRunRunTimeError"] = 60] = "GetLastRunRunTimeError";
Lexeme[Lexeme["Goto"] = 61] = "Goto";
Lexeme[Lexeme["If"] = 62] = "If";
Lexeme[Lexeme["Invalid"] = 63] = "Invalid";
Lexeme[Lexeme["Let"] = 64] = "Let";
Lexeme[Lexeme["LineNum"] = 65] = "LineNum";
Lexeme[Lexeme["Next"] = 66] = "Next";
Lexeme[Lexeme["Not"] = 67] = "Not";
Lexeme[Lexeme["ObjFun"] = 68] = "ObjFun";
Lexeme[Lexeme["Or"] = 69] = "Or";
Lexeme[Lexeme["Pos"] = 70] = "Pos";
Lexeme[Lexeme["Print"] = 71] = "Print";
Lexeme[Lexeme["Rem"] = 72] = "Rem";
Lexeme[Lexeme["Return"] = 73] = "Return";
Lexeme[Lexeme["Run"] = 74] = "Run";
Lexeme[Lexeme["Step"] = 75] = "Step";
Lexeme[Lexeme["Stop"] = 76] = "Stop";
Lexeme[Lexeme["Sub"] = 77] = "Sub";
Lexeme[Lexeme["Tab"] = 78] = "Tab";
Lexeme[Lexeme["Then"] = 79] = "Then";
Lexeme[Lexeme["To"] = 80] = "To";
Lexeme[Lexeme["True"] = 81] = "True";
Lexeme[Lexeme["Type"] = 82] = "Type";
Lexeme[Lexeme["While"] = 83] = "While";
Lexeme[Lexeme["Newline"] = 84] = "Newline";
Lexeme[Lexeme["Eof"] = 85] = "Eof";
})(Lexeme = exports.Lexeme || (exports.Lexeme = {}));
//# sourceMappingURL=interfaces.js.map
{
"name": "brightscript-language",
"version": "0.1.17",
"version": "0.1.18",
"description": "Suite of language tools for Roku's BrightScript language.",

@@ -85,3 +85,3 @@ "scripts": {

"dependencies": {
"brs": "0.13.0-nightly.20190307",
"brs": "0.13.0-nightly.20190308",
"chalk": "^2.4.2",

@@ -88,0 +88,0 @@ "chokidar": "^2.0.4",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet