Skip to content

Commit 04f98a9

Browse files
upgrade to brighterscript@1.0.0-alpha.26
1 parent 26dd9a7 commit 04f98a9

File tree

9 files changed

+54
-325
lines changed

9 files changed

+54
-325
lines changed

package-lock.json

Lines changed: 17 additions & 288 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"url": "https://github.com/rokucommunity/bslint.git"
3535
},
3636
"dependencies": {
37+
"coveralls-next": "^4.2.0",
3738
"fs-extra": "^10.0.0",
3839
"jsonc-parser": "^2.3.0",
3940
"minimatch": "^3.0.4",
@@ -48,9 +49,8 @@
4849
"@types/node": "^14.6.0",
4950
"@typescript-eslint/eslint-plugin": "^3.10.1",
5051
"@typescript-eslint/parser": "^3.10.1",
51-
"brighterscript": "^1.0.0-alpha.25",
52+
"brighterscript": "^1.0.0-alpha.26",
5253
"chai": "^4.3.6",
53-
"coveralls": "^3.1.1",
5454
"eslint": "^7.7.0",
5555
"mocha": "^9.2.2",
5656
"nyc": "^15.1.0",

src/plugins/checkUsage/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,15 @@ export default class CheckUsage implements CompilerPlugin {
176176
for (const func of functionExpressions) {
177177
func.body.walk(createVisitor({
178178
LiteralExpression: (e) => {
179-
const { kind } = e.token;
179+
const { kind } = e.tokens.value;
180180
if (kind === TokenKind.StringLiteral) {
181-
const { text } = e.token;
181+
const { text } = e.tokens.value;
182182
if (text !== '""') {
183183
const name = text.toLowerCase();
184184
if (map.has(name)) {
185185
fv.edges.push({
186186
name,
187-
range: e.token.range,
187+
range: e.tokens.value.range,
188188
file
189189
});
190190
}

src/plugins/codeStyle/diagnosticMessages.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ export const messages = {
9090
code: CodeStyleError.SubKeywordExpected,
9191
source: 'bslint',
9292
message: `${CS} expected 'sub' keyword ${reason}`,
93-
range: fun.functionType.range,
93+
range: fun.tokens.functionType.range,
9494
data: fun
9595
}),
9696
expectedFunctionKeyword: (fun: FunctionExpression, reason: string) => ({
9797
severity: DiagnosticSeverity.Error,
9898
code: CodeStyleError.FunctionKeywordExpected,
9999
source: 'bslint',
100100
message: `${CS} expected 'function' keyword ${reason}`,
101-
range: fun.functionType.range,
101+
range: fun.tokens.functionType.range,
102102
data: fun
103103
}),
104104
expectedReturnTypeAnnotation: (range: Range) => ({

src/plugins/codeStyle/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,14 @@ export default class CodeStyle implements CompilerPlugin {
133133
}
134134
},
135135
LiteralExpression: e => {
136-
if (validateColorStyle && e.token.kind === TokenKind.StringLiteral) {
137-
validateColorStyle(e.token.text, e.token.range, diagnostics);
136+
if (validateColorStyle && e.tokens.value.kind === TokenKind.StringLiteral) {
137+
validateColorStyle(e.tokens.value.text, e.tokens.value.range, diagnostics);
138138
}
139139
},
140140
TemplateStringExpression: e => {
141141
// only validate template strings that look like regular strings (i.e. `0xAABBCC`)
142142
if (validateColorStyle && e.quasis.length === 1 && e.quasis[0].expressions.length === 1) {
143-
validateColorStyle(e.quasis[0].expressions[0].token.text, e.quasis[0].expressions[0].token.range, diagnostics);
143+
validateColorStyle(e.quasis[0].expressions[0].tokens.value.text, e.quasis[0].expressions[0].tokens.value.range, diagnostics);
144144
}
145145
},
146146
AALiteralExpression: e => {
@@ -181,15 +181,15 @@ export default class CodeStyle implements CompilerPlugin {
181181
const indexes = collectWrappingAAMembersIndexes(aa);
182182
const last = indexes.length - 1;
183183
const isSingleLine = (aa: AALiteralExpression): boolean => {
184-
return aa.open.range.start.line === aa.close.range.end.line;
184+
return aa.tokens.open.range.start.line === aa.tokens.close.range.end.line;
185185
};
186186

187187
indexes.forEach((index, i) => {
188188
const member = aa.elements[index] as AAMemberExpression;
189-
const hasComma = !!member.commaToken;
189+
const hasComma = !!member.tokens.comma;
190190
if (aaCommaStyle === 'never' || (i === last && ((aaCommaStyle === 'no-dangling') || isSingleLine(aa)))) {
191191
if (hasComma) {
192-
diagnostics.push(messages.removeAAComma(member.commaToken.range));
192+
diagnostics.push(messages.removeAAComma(member.tokens.comma.range));
193193
}
194194
} else if (!hasComma) {
195195
diagnostics.push(messages.addAAComma(member.value.range));
@@ -201,7 +201,7 @@ export default class CodeStyle implements CompilerPlugin {
201201
const { severity } = this.lintContext;
202202
const { namedFunctionStyle, anonFunctionStyle, typeAnnotations } = severity;
203203
const style = fun.functionStatement ? namedFunctionStyle : anonFunctionStyle;
204-
const kind = fun.functionType.kind;
204+
const kind = fun.tokens.functionType.kind;
205205
const hasReturnedValue = style === 'auto' || typeAnnotations !== 'off' ? this.getFunctionReturns(fun) : false;
206206

207207
// type annotations
@@ -210,7 +210,7 @@ export default class CodeStyle implements CompilerPlugin {
210210
if (hasReturnedValue && !fun.returnTypeExpression) {
211211
diagnostics.push(messages.expectedReturnTypeAnnotation(
212212
// add the error to the function keyword (or just highlight the whole function if that's somehow missing)
213-
fun.functionType?.range ?? fun.range
213+
fun.tokens.functionType?.range ?? fun.range
214214
));
215215
}
216216
}

src/plugins/codeStyle/styleFixes.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ function addConditionGroup(diagnostic: BsDiagnostic) {
8080

8181
function removeConditionGroup(diagnostic: BsDiagnostic) {
8282
const stat: (IfStatement | WhileStatement) & { condition: GroupingExpression } = diagnostic.data;
83-
const { left, right } = stat.condition.tokens;
84-
const spaceBefore = left.leadingWhitespace?.length > 0 ? '' : ' ';
83+
const { leftParen, rightParen } = stat.condition.tokens;
84+
const spaceBefore = leftParen.leadingWhitespace?.length > 0 ? '' : ' ';
8585
let spaceAfter = '';
8686
if (isIfStatement(stat)) {
8787
spaceAfter = stat.isInline ? ' ' : '';
@@ -92,8 +92,8 @@ function removeConditionGroup(diagnostic: BsDiagnostic) {
9292
return {
9393
diagnostic,
9494
changes: [
95-
replaceText(left.range, spaceBefore),
96-
replaceText(right.range, spaceAfter)
95+
replaceText(leftParen.range, spaceBefore),
96+
replaceText(rightParen.range, spaceAfter)
9797
]
9898
};
9999
}
@@ -129,16 +129,16 @@ function removeThenToken(diagnostic: BsDiagnostic) {
129129

130130
function replaceFunctionTokens(diagnostic: BsDiagnostic, token: string) {
131131
const fun: FunctionExpression = diagnostic.data;
132-
const space = fun.end?.text.indexOf(' ') > 0 ? ' ' : '';
132+
const space = fun.tokens.endFunctionType?.text.indexOf(' ') > 0 ? ' ' : '';
133133
// sub/function keyword
134134
const keywordChanges = [
135-
replaceText(fun.functionType.range, token),
136-
replaceText(fun.end?.range, `end${space}${token}`)
135+
replaceText(fun.tokens.functionType.range, token),
136+
replaceText(fun.tokens.endFunctionType?.range, `end${space}${token}`)
137137
];
138138
// remove `as void` in case of `sub`
139139
const returnType = fun.returnTypeExpression?.getType({ flags: SymbolTypeFlag.typetime }) ?? VoidType.instance;
140140
const returnChanges = token === 'sub' && fun.returnTypeExpression && isVoidType(returnType) ? [
141-
replaceText(Range.create(fun.rightParen.range.end, fun.returnTypeExpression.range.end), '')
141+
replaceText(Range.create(fun.tokens.rightParen.range.end, fun.returnTypeExpression.range.end), '')
142142
] : [];
143143
return {
144144
diagnostic,

src/plugins/trackCodeFlow/returnTracking.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ export function createReturnLinter(
8989

9090
function finalize(last: StatementInfo) {
9191
const { consistentReturn } = severity;
92-
const kind = fun.functionType?.kind === TokenKind.Sub ? 'Sub' : 'Function';
92+
const kind = fun.tokens.functionType?.kind === TokenKind.Sub ? 'Sub' : 'Function';
9393
const returnedValues = returns.filter((r) => r.hasValue);
9494
const hasReturnedValue = returnedValues.length > 0;
9595
// Function range only includes the function signature
96-
const funRangeStart = (fun.functionType ?? fun.leftParen).range.start;
97-
const funRangeEnd = (fun.returnTypeExpression ?? fun.rightParen).range.end;
96+
const funRangeStart = (fun.tokens.functionType ?? fun.tokens.leftParen).range.start;
97+
const funRangeEnd = (fun.returnTypeExpression ?? fun.tokens.rightParen).range.end;
9898
const funRange = util.createRangeFromPositions(funRangeStart, funRangeEnd);
9999

100100
// Explicit `as void` or `sub` without return type should never return a value

src/plugins/trackCodeFlow/varTracking.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ export function createVarLinter(
4848
const args: Map<string, VarInfo> = new Map();
4949
args.set('m', { name: 'm', range: Range.create(0, 0, 0, 0), isParam: true, isUnsafe: false, isUsed: true });
5050
fun.parameters.forEach((p) => {
51-
const name = p.name.text;
52-
args.set(name.toLowerCase(), { name: name, range: p.name.range, isParam: true, isUnsafe: false, isUsed: false });
51+
const name = p.tokens.name.text;
52+
args.set(name.toLowerCase(), { name: name, range: p.tokens.name.range, isParam: true, isUnsafe: false, isUsed: false });
5353
});
5454

5555
if (isMethodStatement(fun.functionStatement)) {
@@ -154,7 +154,7 @@ export function createVarLinter(
154154
// for iterator will be declared by the next assignement statement
155155
} else if (isForEachStatement(stat)) {
156156
// declare `for each` iterator variable
157-
setLocal(block, stat.item, VarRestriction.Iterator);
157+
setLocal(block, stat.tokens.item, VarRestriction.Iterator);
158158
} else if (state.parent?.narrows) {
159159
narrowBlock(block);
160160
}
@@ -186,9 +186,9 @@ export function createVarLinter(
186186
const { stat } = curr;
187187
if (isAssignmentStatement(stat) && state.parent) {
188188
// value = stat.value;
189-
setLocal(state.parent, stat.name, isForStatement(state.parent.stat) ? VarRestriction.Iterator : undefined);
189+
setLocal(state.parent, stat.tokens.name, isForStatement(state.parent.stat) ? VarRestriction.Iterator : undefined);
190190
} else if (isCatchStatement(stat) && state.parent) {
191-
setLocal(curr, stat.exceptionVariable, VarRestriction.CatchedError);
191+
setLocal(curr, stat.tokens.exceptionVariable, VarRestriction.CatchedError);
192192
} else if (isLabelStatement(stat) && !foundLabelAt) {
193193
foundLabelAt = stat.range.start.line;
194194
} else if (foundLabelAt && isGotoStatement(stat) && state.parent) {
@@ -280,7 +280,7 @@ export function createVarLinter(
280280

281281
function visitExpression(expr: Expression, parent: Expression, curr: StatementInfo) {
282282
if (isVariableExpression(expr)) {
283-
const name = expr.name.text;
283+
const name = expr.tokens.name.text;
284284
if (name === 'm') {
285285
return;
286286
}
@@ -296,7 +296,7 @@ export function createVarLinter(
296296
return;
297297
} else {
298298
local.isUsed = true;
299-
verifyVarCasing(local, expr.name);
299+
verifyVarCasing(local, expr.tokens.name);
300300
}
301301

302302
if (local.isUnsafe && !findSafeLocal(name)) {
@@ -334,7 +334,7 @@ export function createVarLinter(
334334
// e.g. 2nd condition in: if x <> invalid and x.y = z
335335
return curr.narrows?.some(narrow => narrow.text === local.name);
336336
}
337-
const operator = parent.operator.kind;
337+
const operator = parent.tokens.operator.kind;
338338
if (operator !== TokenKind.Equal && operator !== TokenKind.LessGreater) {
339339
return false;
340340
}
@@ -402,7 +402,7 @@ function buildTopLevelVars(scope: Scope, globals: string[]) {
402402
toplevel.add(getRootNamespaceName(namespace).toLowerCase()); // keep root of namespace
403403
}
404404
for (const [, cls] of scope.getClassMap()) {
405-
toplevel.add(cls.item.name.text.toLowerCase());
405+
toplevel.add(cls.item.tokens.name.text.toLowerCase());
406406
}
407407
for (const [, enm] of scope.getEnumMap()) {
408408
toplevel.add(enm.item.name.toLowerCase());
@@ -465,7 +465,7 @@ export function getRootNamespaceName(namespace: NamespaceStatement) {
465465
break;
466466
}
467467
}
468-
const result = util.getDottedGetPath(namespace.nameExpression)[0]?.name?.text;
468+
const result = util.getDottedGetPath(namespace.nameExpression)[0]?.tokens.name?.text;
469469
// const name = namespace.getName(ParseMode.BrighterScript).toLowerCase();
470470
// if (name.includes('imigx')) {
471471
// console.log([name, result]);

src/textEdit.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from 'chai';
2-
import { Range } from 'vscode-languageserver';
2+
import { Range } from 'brighterscript';
33
import { applyEdits, compareRanges, getLineOffsets } from './textEdit';
44

55
describe('sortByRange', () => {

0 commit comments

Comments
 (0)