Skip to content

Commit cad6866

Browse files
committed
Fixes for release v0.66.0-alpha1
1 parent 53f8f9c commit cad6866

File tree

14 files changed

+1838
-220
lines changed

14 files changed

+1838
-220
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"@types/node": "^14.6.0",
4848
"@typescript-eslint/eslint-plugin": "^3.10.1",
4949
"@typescript-eslint/parser": "^3.10.1",
50-
"brighterscript": "../brighterscript",
50+
"brighterscript": "0.66.0-alpha.1",
5151
"chai": "^4.3.6",
5252
"coveralls": "^3.1.1",
5353
"eslint": "^7.7.0",

src/plugins/checkUsage/index.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from 'chai';
2-
import { BsDiagnostic, Program } from 'brighterscript';
2+
import { AfterProgramCreateEvent, BsDiagnostic } from 'brighterscript';
33
import Linter from '../../Linter';
44
import { createContext, PluginWrapperContext } from '../../util';
55
import CheckUsage from './index';
@@ -26,7 +26,8 @@ describe('checkUsage', () => {
2626
linter = new Linter();
2727
linter.builder.plugins.add({
2828
name: 'test',
29-
afterProgramCreate: (program: Program) => {
29+
afterProgramCreate: (event: AfterProgramCreateEvent) => {
30+
const { program } = event;
3031
lintContext = createContext(program);
3132
const checkUsage = new CheckUsage(lintContext);
3233
program.plugins.add(checkUsage);

src/plugins/checkUsage/index.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BscFile, CallableContainerMap, createVisitor, DiagnosticSeverity, isBrsFile, isXmlFile, Program, Range, Scope, TokenKind, WalkMode, XmlFile } from 'brighterscript';
1+
import { AfterFileValidateEvent, AfterProgramValidateEvent, AfterScopeValidateEvent, BscFile, CompilerPlugin, createVisitor, DiagnosticSeverity, isBrsFile, isXmlFile, Range, TokenKind, WalkMode, XmlFile } from 'brighterscript';
22
import { SGNode } from 'brighterscript/dist/parser/SGTypes';
33
import { PluginContext } from '../../util';
44

@@ -9,7 +9,7 @@ export enum UnusedCode {
99
UnusedScript = 'LINT4002'
1010
}
1111

12-
export default class CheckUsage {
12+
export default class CheckUsage implements CompilerPlugin {
1313

1414
name = 'checkUsage';
1515

@@ -39,16 +39,16 @@ export default class CheckUsage {
3939

4040
private walkChildren(v: Vertice, children: SGNode[], file: BscFile) {
4141
children.forEach(node => {
42-
const name = node.tag?.text;
42+
const name = node.tagName;
4343
if (name) {
44-
v.edges.push(createComponentEdge(name, node.tag.range, file));
44+
v.edges.push(createComponentEdge(name, node.tokens.startTagName.range, file));
4545
}
4646
const itemComponentName = node.getAttribute('itemcomponentname');
4747
if (itemComponentName) {
48-
v.edges.push(createComponentEdge(itemComponentName.value.text, itemComponentName.value.range, file));
48+
v.edges.push(createComponentEdge(itemComponentName.value, itemComponentName.range, file));
4949
}
50-
if (node.children) {
51-
this.walkChildren(v, node.children, file);
50+
if (node.elements) {
51+
this.walkChildren(v, node.elements, file);
5252
}
5353
});
5454
}
@@ -69,7 +69,8 @@ export default class CheckUsage {
6969
});
7070
}
7171

72-
afterFileValidate(file: BscFile) {
72+
afterFileValidate(event: AfterFileValidateEvent) {
73+
const { file } = event;
7374
// collect all XML components
7475
if (isXmlFile(file)) {
7576
if (!file.componentName) {
@@ -100,14 +101,16 @@ export default class CheckUsage {
100101
v.edges.push(createComponentEdge(text, range, file));
101102
}
102103

103-
const children = file.ast.component?.children;
104+
const children = file.ast.componentElement?.childrenElement;
104105
if (children) {
105-
this.walkChildren(v, children.children, file);
106+
this.walkChildren(v, children.elements, file);
106107
}
107108
}
108109
}
109110

110-
afterScopeValidate(scope: Scope, files: BscFile[], _: CallableContainerMap) {
111+
afterScopeValidate(event: AfterScopeValidateEvent) {
112+
const { scope } = event;
113+
const files = scope.getAllFiles();
111114
const pkgPath = scope.name.toLowerCase();
112115
let v: Vertice;
113116
if (scope.name === 'global') {
@@ -180,7 +183,7 @@ export default class CheckUsage {
180183
});
181184
}
182185

183-
afterProgramValidate(_: Program) {
186+
afterProgramValidate(_: AfterProgramValidateEvent) {
184187
if (!this.main) {
185188
throw new Error('No `main.brs`');
186189
}

src/plugins/codeStyle/index.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as fs from 'fs';
22
import { expect } from 'chai';
3-
import { AALiteralExpression, AssignmentStatement, BsDiagnostic, ParseMode, Parser, Program, util } from 'brighterscript';
3+
import { AALiteralExpression, AfterProgramCreateEvent, AssignmentStatement, BsDiagnostic, ParseMode, Parser, util } from 'brighterscript';
44
import Linter from '../../Linter';
55
import CodeStyle, { collectWrappingAAMembersIndexes } from './index';
66
import { createContext, PluginWrapperContext } from '../../util';
@@ -28,7 +28,8 @@ describe('codeStyle', () => {
2828
linter = new Linter();
2929
linter.builder.plugins.add({
3030
name: 'test',
31-
afterProgramCreate: (program: Program) => {
31+
afterProgramCreate: (event: AfterProgramCreateEvent) => {
32+
const { program } = event;
3233
lintContext = createContext(program);
3334
const codeStyle = new CodeStyle(lintContext);
3435
program.plugins.add(codeStyle);

src/plugins/codeStyle/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { BscFile, BsDiagnostic, createVisitor, FunctionExpression, isBrsFile, isGroupingExpression, TokenKind, WalkMode, CancellationTokenSource, DiagnosticSeverity, OnGetCodeActionsEvent, isCommentStatement, AALiteralExpression, AAMemberExpression, SymbolTypeFlags, isVoidType } from 'brighterscript';
1+
import { BsDiagnostic, createVisitor, FunctionExpression, isBrsFile, isGroupingExpression, TokenKind, WalkMode, CancellationTokenSource, DiagnosticSeverity, OnGetCodeActionsEvent, isCommentStatement, AALiteralExpression, AAMemberExpression, SymbolTypeFlag, isVoidType, CompilerPlugin, AfterFileValidateEvent } from 'brighterscript';
22
import { RuleAAComma } from '../..';
33
import { addFixesToEvent } from '../../textEdit';
44
import { PluginContext } from '../../util';
55
import { messages } from './diagnosticMessages';
66
import { extractFixes } from './styleFixes';
77

8-
export default class CodeStyle {
8+
export default class CodeStyle implements CompilerPlugin {
99

1010
name: 'codeStyle';
1111

@@ -17,7 +17,8 @@ export default class CodeStyle {
1717
extractFixes(addFixes, event.diagnostics);
1818
}
1919

20-
afterFileValidate(file: BscFile) {
20+
afterFileValidate(event: AfterFileValidateEvent) {
21+
const { file } = event;
2122
if (!isBrsFile(file) || this.lintContext.ignores(file)) {
2223
return;
2324
}
@@ -241,7 +242,7 @@ export default class CodeStyle {
241242
getFunctionReturns(fun: FunctionExpression) {
242243
let hasReturnedValue = false;
243244
if (fun.returnTypeExpression) {
244-
hasReturnedValue = !isVoidType(fun.returnTypeExpression.getType({ flags: SymbolTypeFlags.typetime }));
245+
hasReturnedValue = !isVoidType(fun.returnTypeExpression.getType({ flags: SymbolTypeFlag.typetime }));
245246
} else {
246247
const cancel = new CancellationTokenSource();
247248
fun.body.walk(createVisitor({

src/plugins/codeStyle/styleFixes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BscFile, BsDiagnostic, FunctionExpression, GroupingExpression, IfStatement, isIfStatement, isVoidType, Position, Range, SymbolTypeFlags, VoidType, WhileStatement } from 'brighterscript';
1+
import { BscFile, BsDiagnostic, FunctionExpression, GroupingExpression, IfStatement, isIfStatement, isVoidType, Position, Range, SymbolTypeFlag, VoidType, WhileStatement } from 'brighterscript';
22
import { ChangeEntry, comparePos, insertText, replaceText } from '../../textEdit';
33
import { CodeStyleError } from './diagnosticMessages';
44
import { platform } from 'process';
@@ -136,7 +136,7 @@ function replaceFunctionTokens(diagnostic: BsDiagnostic, token: string) {
136136
replaceText(fun.end?.range, `end${space}${token}`)
137137
];
138138
// remove `as void` in case of `sub`
139-
const returnType = fun.returnTypeExpression?.getType({ flags: SymbolTypeFlags.typetime }) ?? VoidType.instance;
139+
const returnType = fun.returnTypeExpression?.getType({ flags: SymbolTypeFlag.typetime }) ?? VoidType.instance;
140140
const returnChanges = token === 'sub' && fun.returnTypeExpression && isVoidType(returnType) ? [
141141
replaceText(Range.create(fun.rightParen.range.end, fun.returnTypeExpression.range.end), '')
142142
] : [];

src/plugins/trackCodeFlow/index.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as fs from 'fs';
22
import { expect } from 'chai';
3-
import { BsDiagnostic, Program } from 'brighterscript';
3+
import { AfterProgramCreateEvent, BsDiagnostic } from 'brighterscript';
44
import Linter from '../../Linter';
55
import TrackCodeFlow from './index';
66
import { createContext, PluginWrapperContext } from '../../util';
@@ -27,7 +27,8 @@ describe('trackCodeFlow', () => {
2727
linter = new Linter();
2828
linter.builder.plugins.add({
2929
name: 'test',
30-
afterProgramCreate: (program: Program) => {
30+
afterProgramCreate: (event: AfterProgramCreateEvent) => {
31+
const { program } = event;
3132
lintContext = createContext(program);
3233
const trackCodeFlow = new TrackCodeFlow(lintContext);
3334
program.plugins.add(trackCodeFlow);

src/plugins/trackCodeFlow/index.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BscFile, Scope, BsDiagnostic, CallableContainerMap, BrsFile, OnGetCodeActionsEvent, Statement, EmptyStatement, FunctionExpression, isForEachStatement, isForStatement, isIfStatement, isWhileStatement, Range, createStackedVisitor, isBrsFile, isStatement, isExpression, WalkMode, isTryCatchStatement, isCatchStatement } from 'brighterscript';
1+
import { BsDiagnostic, BrsFile, OnGetCodeActionsEvent, Statement, EmptyStatement, FunctionExpression, isForEachStatement, isForStatement, isIfStatement, isWhileStatement, Range, createStackedVisitor, isBrsFile, isStatement, isExpression, WalkMode, isTryCatchStatement, isCatchStatement, CompilerPlugin, AfterScopeValidateEvent, AfterFileValidateEvent, util } from 'brighterscript';
22
import { PluginContext } from '../../util';
33
import { createReturnLinter } from './returnTracking';
44
import { createVarLinter, resetVarContext, runDeferredValidation } from './varTracking';
@@ -50,7 +50,7 @@ export interface LintState {
5050
branch?: StatementInfo;
5151
}
5252

53-
export default class TrackCodeFlow {
53+
export default class TrackCodeFlow implements CompilerPlugin {
5454

5555
name: 'trackCodeFlow';
5656

@@ -62,12 +62,15 @@ export default class TrackCodeFlow {
6262
extractFixes(addFixes, event.diagnostics);
6363
}
6464

65-
afterScopeValidate(scope: Scope, files: BscFile[], callables: CallableContainerMap) {
66-
const diagnostics = runDeferredValidation(this.lintContext, scope, files, callables);
65+
afterScopeValidate(event: AfterScopeValidateEvent) {
66+
const { scope } = event;
67+
const callablesMap = util.getCallableContainersByLowerName(scope.getAllCallables());
68+
const diagnostics = runDeferredValidation(this.lintContext, scope, scope.getAllFiles(), callablesMap);
6769
scope.addDiagnostics(diagnostics);
6870
}
6971

70-
afterFileValidate(file: BscFile) {
72+
afterFileValidate(event: AfterFileValidateEvent) {
73+
const { file } = event;
7174
if (!isBrsFile(file) || this.lintContext.ignores(file)) {
7275
return;
7376
}

src/plugins/trackCodeFlow/returnTracking.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BscFile, FunctionExpression, BsDiagnostic, isCommentStatement, DiagnosticTag, isReturnStatement, isIfStatement, isThrowStatement, TokenKind, util, ReturnStatement, ThrowStatement, isTryCatchStatement, isCatchStatement, isVoidType, SymbolTypeFlags } from 'brighterscript';
1+
import { BscFile, FunctionExpression, BsDiagnostic, isCommentStatement, DiagnosticTag, isReturnStatement, isIfStatement, isThrowStatement, TokenKind, util, ReturnStatement, ThrowStatement, isTryCatchStatement, isCatchStatement, isVoidType, SymbolTypeFlag } from 'brighterscript';
22
import { LintState, StatementInfo } from '.';
33
import { PluginContext } from '../../util';
44

@@ -98,7 +98,7 @@ export function createReturnLinter(
9898
const funRange = util.createRangeFromPositions(funRangeStart, funRangeEnd);
9999

100100
// Explicit `as void` or `sub` without return type should never return a value
101-
const returnType = fun.returnTypeExpression?.getType({ flags: SymbolTypeFlags.typetime });
101+
const returnType = fun.returnTypeExpression?.getType({ flags: SymbolTypeFlag.typetime });
102102

103103
if (
104104
isVoidType(returnType) ||

0 commit comments

Comments
 (0)