Skip to content

Commit

Permalink
1072 -> 879
Browse files Browse the repository at this point in the history
  • Loading branch information
josephjunker committed Dec 23, 2023
1 parent 4a5ac2e commit 54d4acb
Show file tree
Hide file tree
Showing 39 changed files with 261 additions and 193 deletions.
8 changes: 4 additions & 4 deletions src/LanguageServer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ describe('LanguageServer', () => {
it('sends diagnostics that were triggered by the program instead of vscode', async () => {
server['connection'] = server['createConnection']();
await server['createProject'](workspacePath);
let stub: SinonStub;
let stub: SinonStub | undefined;
const promise = new Promise((resolve) => {
stub = sinon.stub(connection, 'sendDiagnostics').callsFake(resolve as any);
});
Expand All @@ -240,7 +240,7 @@ describe('LanguageServer', () => {
`);
program.validate();
await promise;
expect(stub.called).to.be.true;
expect(stub!.called).to.be.true;
});
});

Expand Down Expand Up @@ -836,7 +836,7 @@ describe('LanguageServer', () => {
expect(symbols.length).to.equal(1);
const classSymbol = symbols[0];
expect(classSymbol.name).to.equal('MyFirstClass');
const classChildrenSymbols = classSymbol.children;
const classChildrenSymbols = classSymbol.children!;
expect(classChildrenSymbols.length).to.equal(2);
expect(classChildrenSymbols[0].name).to.equal('pi');
expect(classChildrenSymbols[1].name).to.equal('buildAwesome');
Expand Down Expand Up @@ -866,7 +866,7 @@ describe('LanguageServer', () => {
expect(symbols.length).to.equal(1);
const namespaceSymbol = symbols[0];
expect(namespaceSymbol.name).to.equal('MyFirstNamespace');
const classChildrenSymbols = namespaceSymbol.children;
const classChildrenSymbols = namespaceSymbol.children!;
expect(classChildrenSymbols.length).to.equal(2);
expect(classChildrenSymbols[0].name).to.equal('MyFirstNamespace.pi');
expect(classChildrenSymbols[1].name).to.equal('MyFirstNamespace.buildAwesome');
Expand Down
7 changes: 7 additions & 0 deletions src/PluginInterface.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/prefer-ts-expect-error */
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { expect } from './chai-config.spec';
import * as sinon from 'sinon';
import { Logger } from './Logger';
Expand All @@ -16,8 +18,10 @@ describe('PluginInterface', () => {
name: 'allows adding a plugin',
beforePublish: beforePublish
};
//@ts-ignore the current definition of `emit` doesn't like this third argument
pluginInterface.emit('beforePublish', undefined, []);
pluginInterface.add(plugin);
//@ts-ignore the current definition of `emit` doesn't like this third argument
pluginInterface.emit('beforePublish', undefined, []);
expect(beforePublish.callCount).to.equal(1);
});
Expand All @@ -39,6 +43,7 @@ describe('PluginInterface', () => {
};
pluginInterface.add(plugin);
pluginInterface.add(plugin);
//@ts-ignore the current definition of `emit` doesn't like this third argument
pluginInterface.emit('beforePublish', undefined, []);
expect(beforePublish.callCount).to.equal(1);
pluginInterface.remove(plugin);
Expand All @@ -52,9 +57,11 @@ describe('PluginInterface', () => {
beforePublish: beforePublish
};
pluginInterface.add(plugin);
//@ts-ignore the current definition of `emit` doesn't like this third argument
pluginInterface.emit('beforePublish', undefined, []);
expect(beforePublish.callCount).to.equal(1);
pluginInterface.remove(plugin);
//@ts-ignore the current definition of `emit` doesn't like this third argument
pluginInterface.emit('beforePublish', undefined, []);
expect(beforePublish.callCount).to.equal(1);
});
Expand Down
45 changes: 24 additions & 21 deletions src/Program.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { assert, expect } from './chai-config.spec';
import * as pick from 'object.pick';
import * as sinonImport from 'sinon';
Expand All @@ -21,6 +23,7 @@ import { isBrsFile } from './astUtils/reflection';
import type { LiteralExpression } from './parser/Expression';
import type { AstEditor } from './astUtils/AstEditor';
import { tempDir, rootDir, stagingDir } from './testHelpers.spec';
import type { BsDiagnostic } from './interfaces';

let sinon = sinonImport.createSandbox();

Expand Down Expand Up @@ -263,11 +266,11 @@ describe('Program', () => {
});

it('allows adding diagnostics', () => {
const expected = [{
const expected: BsDiagnostic[] = [{
message: 'message',
file: undefined,
range: undefined
}];
}] as any;
program.addDiagnostics(expected);
const actual = (program as any).diagnostics;
expect(actual).to.deep.equal(expected);
Expand Down Expand Up @@ -720,7 +723,7 @@ describe('Program', () => {

describe('reloadFile', () => {
it('picks up new files in a scope when an xml file is loaded', () => {
program.options.ignoreErrorCodes.push(1013);
program.options.ignoreErrorCodes!.push(1013);
program.setFile('components/component1.xml', trim`
<?xml version="1.0" encoding="utf-8" ?>
<component name="HeroScene" extends="Scene">
Expand Down Expand Up @@ -766,7 +769,7 @@ describe('Program', () => {
});

it('reloads referenced fles when xml file changes', () => {
program.options.ignoreErrorCodes.push(1013);
program.options.ignoreErrorCodes!.push(1013);
program.setFile('components/component1.brs', '');

let xmlFile = program.setFile('components/component1.xml', trim`
Expand Down Expand Up @@ -1735,19 +1738,19 @@ describe('Program', () => {
});

it('does not create map by default', async () => {
fsExtra.ensureDirSync(program.options.stagingDir);
fsExtra.ensureDirSync(program.options.stagingDir!);
program.setFile('source/main.brs', `
sub main()
end sub
`);
program.validate();
await program.transpile([], program.options.stagingDir);
await program.transpile([], program.options.stagingDir!);
expect(fsExtra.pathExistsSync(s`${stagingDir}/source/main.brs`)).is.true;
expect(fsExtra.pathExistsSync(s`${stagingDir}/source/main.brs.map`)).is.false;
});

it('creates sourcemap for brs and xml files', async () => {
fsExtra.ensureDirSync(program.options.stagingDir);
fsExtra.ensureDirSync(program.options.stagingDir!);
program.setFile('source/main.brs', `
sub main()
end sub
Expand All @@ -1770,27 +1773,27 @@ describe('Program', () => {
dest: s`components/comp1.xml`
}];
program.options.sourceMap = true;
await program.transpile(filePaths, program.options.stagingDir);
await program.transpile(filePaths, program.options.stagingDir!);

expect(fsExtra.pathExistsSync(s`${stagingDir}/source/main.brs.map`)).is.true;
expect(fsExtra.pathExistsSync(s`${stagingDir}/components/comp1.xml.map`)).is.true;
});

it('copies the bslib.brs file', async () => {
fsExtra.ensureDirSync(program.options.stagingDir);
fsExtra.ensureDirSync(program.options.stagingDir!);
program.validate();

await program.transpile([], program.options.stagingDir);
await program.transpile([], program.options.stagingDir!);

expect(fsExtra.pathExistsSync(s`${stagingDir}/source/bslib.brs`)).is.true;
});

it('copies the bslib.brs file to optionally specified directory', async () => {
fsExtra.ensureDirSync(program.options.stagingDir);
fsExtra.ensureDirSync(program.options.stagingDir!);
program.options.bslibDestinationDir = 'source/opt';
program.validate();

await program.transpile([], program.options.stagingDir);
await program.transpile([], program.options.stagingDir!);

expect(fsExtra.pathExistsSync(s`${stagingDir}/source/opt/bslib.brs`)).is.true;
});
Expand Down Expand Up @@ -1873,7 +1876,7 @@ describe('Program', () => {
}, {
src: s`${rootDir}/source/main.bs`,
dest: 'source/main.bs'
}], program.options.stagingDir);
}], program.options.stagingDir!);

//entries should now be in alphabetic order
expect(
Expand Down Expand Up @@ -1960,7 +1963,7 @@ describe('Program', () => {
print "hello world"
end sub
`);
let literalExpression: LiteralExpression;
let literalExpression: LiteralExpression | undefined;
//replace all strings with "goodbye world"
program.plugins.add({
name: 'TestPlugin',
Expand Down Expand Up @@ -1989,7 +1992,7 @@ describe('Program', () => {
);

//our literalExpression should have been restored to its original value
expect(literalExpression.token.text).to.eql('"hello world"');
expect(literalExpression!.token.text).to.eql('"hello world"');
});

it('handles AstEditor for beforeProgramTranspile', async () => {
Expand All @@ -1998,7 +2001,7 @@ describe('Program', () => {
print "hello world"
end sub
`);
let literalExpression: LiteralExpression;
let literalExpression: LiteralExpression | undefined;
//replace all strings with "goodbye world"
program.plugins.add({
name: 'TestPlugin',
Expand All @@ -2025,7 +2028,7 @@ describe('Program', () => {
);

//our literalExpression should have been restored to its original value
expect(literalExpression.token.text).to.eql('"hello world"');
expect(literalExpression!.token.text).to.eql('"hello world"');
});

it('copies bslib.brs when no ropm version was found', async () => {
Expand All @@ -2046,7 +2049,7 @@ describe('Program', () => {
print SOURCE_LINE_NUM
end sub
`);
await program.transpile([], program.options.stagingDir);
await program.transpile([], program.options.stagingDir!);
expect(trimMap(
fsExtra.readFileSync(s`${stagingDir}/source/logger.brs`).toString()
)).to.eql(trim`
Expand All @@ -2062,7 +2065,7 @@ describe('Program', () => {
print "logInfo"
end sub
`);
await program.transpile([], program.options.stagingDir);
await program.transpile([], program.options.stagingDir!);
expect(trimMap(
fsExtra.readFileSync(s`${stagingDir}/source/logger.brs`).toString()
)).to.eql(trim`
Expand All @@ -2078,7 +2081,7 @@ describe('Program', () => {
<component name="Component1" extends="Scene">
</component>
`);
await program.transpile([], program.options.stagingDir);
await program.transpile([], program.options.stagingDir!);
expect(trimMap(
fsExtra.readFileSync(s`${stagingDir}/components/Component1.xml`).toString()
)).to.eql(trim`
Expand All @@ -2096,7 +2099,7 @@ describe('Program', () => {
<component name="Component1" extends="Scene">
</component>
`);
await program.transpile([], program.options.stagingDir);
await program.transpile([], program.options.stagingDir!);
expect(trimMap(
fsExtra.readFileSync(s`${stagingDir}/components/Component1.xml`).toString()
)).to.eql(trim`
Expand Down
8 changes: 4 additions & 4 deletions src/ProgramBuilder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ describe('ProgramBuilder', () => {

let diagnostics = createBsDiagnostic('p1', ['m1']);
let f1 = diagnostics[0].file as BrsFile;
f1.fileContents = null;
(f1.fileContents as any) = null;
sinon.stub(builder, 'getDiagnostics').returns(diagnostics);

sinon.stub(builder.program, 'getFile').returns(f1);
Expand All @@ -292,7 +292,7 @@ describe('ProgramBuilder', () => {
let diagnostics = createBsDiagnostic('p1', ['m1']);
sinon.stub(builder, 'getDiagnostics').returns(diagnostics);

sinon.stub(builder.program, 'getFile').returns(null);
sinon.stub(builder.program, 'getFile').returns(null as any);

let printStub = sinon.stub(diagnosticUtils, 'printDiagnostic');

Expand Down Expand Up @@ -351,8 +351,8 @@ describe('ProgramBuilder', () => {
});

function createBsDiagnostic(filePath: string, messages: string[]): BsDiagnostic[] {
let file = new BrsFile(filePath, filePath, null);
let diagnostics = [];
let file = new BrsFile(filePath, filePath, null as any);
let diagnostics: BsDiagnostic[] = [];
for (let message of messages) {
let d = createDiagnostic(file, 1, message);
d.file = file;
Expand Down
9 changes: 5 additions & 4 deletions src/Scope.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { expect } from './chai-config.spec';
import * as sinonImport from 'sinon';
import { Position, Range } from 'vscode-languageserver';
Expand All @@ -9,7 +10,7 @@ import PluginInterface from './PluginInterface';
import { expectDiagnostics, expectZeroDiagnostics, trim } from './testHelpers.spec';
import { Logger } from './Logger';
import type { BrsFile } from './files/BrsFile';
import type { FunctionStatement, NamespaceStatement } from './parser/Statement';
import type { NamespaceStatement } from './parser/Statement';
import type { OnScopeValidateEvent } from './interfaces';

describe('Scope', () => {
Expand All @@ -30,7 +31,7 @@ describe('Scope', () => {
it('getEnumMemberFileLink does not crash on undefined name', () => {
program.setFile('source/main.bs', ``);
const scope = program.getScopesForFile('source/main.bs')[0];
scope.getEnumMemberFileLink(null);
scope.getEnumMemberFileLink(null as any);
//test passes if this doesn't explode
});

Expand Down Expand Up @@ -1481,7 +1482,7 @@ describe('Scope', () => {
`);
program.setFile(s`components/child.brs`, ``);
program.validate();
let childScope = program.getComponentScope('child');
let childScope = program.getComponentScope('child')!;
expect(childScope.getAllCallables().map(x => x.callable.name)).not.to.include('parentSub');

program.setFile('components/parent.xml', trim`
Expand Down Expand Up @@ -1542,7 +1543,7 @@ describe('Scope', () => {
end function
end namespace
`);
delete ((file.ast.statements[0] as NamespaceStatement).body.statements[0] as FunctionStatement).name;
delete ((file.ast.statements[0] as NamespaceStatement).body.statements[0] as any).name;
program.validate();
program['scopes']['source'].buildNamespaceLookup();
});
Expand Down
4 changes: 2 additions & 2 deletions src/Scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -917,8 +917,8 @@ export class Scope {
}

private validateClasses() {
let validator = new BsClassValidator();
validator.validate(this);
let validator = new BsClassValidator(this);
validator.validate();
this.diagnostics.push(...validator.diagnostics);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Stopwatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class Stopwatch {
/**
* The number of milliseconds when the stopwatch was started.
*/
private startTime: number;
private startTime: number | undefined;
start() {
this.startTime = performance.now();
}
Expand All @@ -17,7 +17,7 @@ export class Stopwatch {
this.startTime = undefined;
}
reset() {
this.totalMilliseconds = undefined;
this.totalMilliseconds = 0;
this.startTime = undefined;
}
getDurationText() {
Expand Down
Loading

0 comments on commit 54d4acb

Please sign in to comment.