diff --git a/benchmarks/targets/validate.js b/benchmarks/targets/validate.js
index 982daa879..83af3139b 100644
--- a/benchmarks/targets/validate.js
+++ b/benchmarks/targets/validate.js
@@ -15,14 +15,18 @@ module.exports = async (suite, name, brighterscript, projectPath) => {
throw new Error('No files found in program');
}
- suite.add(name, async (deferred) => {
+ suite.add(name, (deferred) => {
const scopes = Object.values(builder.program.scopes);
//mark all scopes as invalid so they'll re-validate
for (let scope of scopes) {
scope.invalidate();
}
- await builder.program.validate();
- deferred.resolve();
+ let promise = builder.program.validate();
+ if (promise) {
+ promise.then(() => deferred.resolve());
+ } else {
+ deferred.resolve();
+ }
}, {
'defer': true
});
diff --git a/scripts/compile-doc-examples.ts b/scripts/compile-doc-examples.ts
index e7f7fcf21..e502182f5 100644
--- a/scripts/compile-doc-examples.ts
+++ b/scripts/compile-doc-examples.ts
@@ -8,46 +8,46 @@ class DocCompiler {
private docsFolder = path.resolve(path.join(__dirname, '..', 'docs'));
public async run() {
- var docs = glob.sync('**/*.md', {
+ let docs = glob.sync('**/*.md', {
cwd: this.docsFolder,
absolute: true
});
for (let docPath of docs) {
console.log('\n', docPath);
- await this.processDoc(docPath);
+ this.processDoc(docPath);
}
}
private lines: string[];
private index: number;
- public async processDoc(docPath: string) {
+ public processDoc(docPath: string) {
let contents = fsExtra.readFileSync(docPath).toString();
this.lines = util.splitIntoLines(contents);
this.index = 0;
while (this.index < this.lines.length) {
let line = this.lines[this.index];
if (line.includes('```')) {
- await this.processCodeBlock();
+ this.processCodeBlock();
}
this.index++;
}
- var result = this.lines.join('\n');
+ let result = this.lines.join('\n');
fsExtra.writeFileSync(docPath, result);
delete this.lines;
this.index = -1;
}
- public async processCodeBlock() {
- var sourceLines = [] as string[];
- var sourceStartIndex = this.index + 1;
- var sourceStopIndex: number;
+ public processCodeBlock() {
+ let sourceLines = [] as string[];
+ let sourceStartIndex = this.index + 1;
+ let sourceStopIndex: number;
//find the rest of the source code block
//+1 to step past the opening ```
- for (var i = this.index + 1; i < this.lines.length; i++) {
+ for (let i = this.index + 1; i < this.lines.length; i++) {
let line = this.lines[i];
if (line.includes('```')) {
sourceStopIndex = i - 1;
@@ -59,11 +59,11 @@ class DocCompiler {
let sourceCode = sourceLines.join('\n');
- var transpiledStartIndex: number;
- var transpiledStopIndex: number;
+ let transpiledStartIndex: number;
+ let transpiledStopIndex: number;
//find the transpiled code block (there must be one after every
//+2 to step past the last line of code, and the final ```
- outer: for (var i = sourceStopIndex + 2; i < this.lines.length; i++) {
+ outer: for (let i = sourceStopIndex + 2; i < this.lines.length; i++) {
let line = this.lines[i];
//the next code block MUST be a brightscript block. hard-fail if it isn't
if (line.includes('```')) {
@@ -88,9 +88,9 @@ class DocCompiler {
//now that we have the range for the transpiled code, we need to transpile the source code
if (transpiledStartIndex && transpiledStopIndex && sourceCode) {
console.log(`Transpiling code block at lines ${sourceStartIndex}-${sourceStopIndex}`);
- var transpiledCode = await this.transpile(sourceCode);
+ const transpiledCode = this.transpile(sourceCode);
let transpiledLines = transpiledCode.split('\n');
- let originalTranspiledLineCount = transpiledStopIndex - transpiledStartIndex
+ let originalTranspiledLineCount = transpiledStopIndex - transpiledStartIndex;
//replace the old transpiled lines with the new ones
this.lines.splice(
@@ -103,15 +103,15 @@ class DocCompiler {
}
}
- public async transpile(code: string) {
- var program = new Program({
+ public transpile(code: string) {
+ const program = new Program({
rootDir: `${__dirname}/rootDir`,
files: [
'source/main.brs'
]
});
- var file = await program.addOrReplaceFile({ src: `${__dirname}/rootDir/source/main.bs`, dest: 'source/main.bs' }, code)
- await program.validate();
+ const file = program.addOrReplaceFile({ src: `${__dirname}/rootDir/source/main.bs`, dest: 'source/main.bs' }, code);
+ program.validate();
let tranpileResult = file.transpile();
return tranpileResult.code;
}
diff --git a/src/FunctionScope.spec.ts b/src/FunctionScope.spec.ts
index ef1cebf1c..99f632d63 100644
--- a/src/FunctionScope.spec.ts
+++ b/src/FunctionScope.spec.ts
@@ -22,8 +22,8 @@ describe('FunctionScope', () => {
expect(variables).to.be.lengthOf(0);
});
- it('returns variables defined above the specified line number', async () => {
- let file = await program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
+ it('returns variables defined above the specified line number', () => {
+ let file = program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
sub main()
var1 = 1
var2 = 2
diff --git a/src/LanguageServer.spec.ts b/src/LanguageServer.spec.ts
index 0910526db..79f84d584 100644
--- a/src/LanguageServer.spec.ts
+++ b/src/LanguageServer.spec.ts
@@ -103,7 +103,7 @@ describe('LanguageServer', () => {
server.dispose();
});
- async function addXmlFile(name: string, additionalXmlContents = '') {
+ function addXmlFile(name: string, additionalXmlContents = '') {
const filePath = `components/${name}.xml`;
const contents = `
@@ -111,12 +111,12 @@ describe('LanguageServer', () => {
${additionalXmlContents}
`;
- await program.addOrReplaceFile(filePath, contents);
+ program.addOrReplaceFile(filePath, contents);
}
- async function addScriptFile(name: string, contents: string, extension = 'brs') {
+ function addScriptFile(name: string, contents: string, extension = 'brs') {
const filePath = s`components/${name}.${extension}`;
- await program.addOrReplaceFile(filePath, contents);
+ program.addOrReplaceFile(filePath, contents);
for (const key in program.files) {
if (key.includes(filePath)) {
const document = TextDocument.create(util.pathToUri(key), 'brightscript', 1, contents);
@@ -279,6 +279,7 @@ describe('LanguageServer', () => {
'source/**/*'
]
},
+ getFileContents: sinon.stub().callsFake(() => Promise.resolve('')) as any,
rootDir: rootDir,
program: {
addOrReplaceFile: addOrReplaceFileStub
@@ -294,7 +295,7 @@ describe('LanguageServer', () => {
pathAbsolute: mainPath
}]);
- expect(addOrReplaceFileStub.getCalls()[0].args[0]).to.eql({
+ expect(addOrReplaceFileStub.getCalls()[0]?.args[0]).to.eql({
src: mainPath,
dest: s`source/main.brs`
});
@@ -362,7 +363,7 @@ describe('LanguageServer', () => {
program = svr.workspaces[0].builder.program;
const name = `CallComponent`;
- callDocument = await addScriptFile(name, `
+ callDocument = addScriptFile(name, `
sub init()
shouldBuildAwesome = true
if shouldBuildAwesome then
@@ -372,14 +373,14 @@ describe('LanguageServer', () => {
end if
end sub
`);
- await addXmlFile(name, ``);
+ addXmlFile(name, ``);
});
it('should return the expected signature info when documentation is included', async () => {
const funcDescriptionComment = '@description Builds awesome for you';
const funcReturnComment = '@return {Integer} The key to everything';
- await addScriptFile(functionFileBaseName, `
+ addScriptFile(functionFileBaseName, `
' /**
' * ${funcDescriptionComment}
' * ${funcReturnComment}
@@ -403,7 +404,7 @@ describe('LanguageServer', () => {
});
it('should work if used on a property value', async () => {
- await addScriptFile(functionFileBaseName, `
+ addScriptFile(functionFileBaseName, `
${funcDefinitionLine}
return 42
end function
@@ -422,7 +423,7 @@ describe('LanguageServer', () => {
it('should give the correct signature for a class method', async () => {
const classMethodDefinitionLine = 'function buildAwesome(classVersion = true as Boolean)';
- await addScriptFile(functionFileBaseName, `
+ addScriptFile(functionFileBaseName, `
class ${functionFileBaseName}
${classMethodDefinitionLine}
return 42
@@ -453,7 +454,7 @@ describe('LanguageServer', () => {
program = svr.workspaces[0].builder.program;
const functionFileBaseName = 'buildAwesome';
- functionDocument = await addScriptFile(functionFileBaseName, `
+ functionDocument = addScriptFile(functionFileBaseName, `
function buildAwesome()
return 42
end function
@@ -461,7 +462,7 @@ describe('LanguageServer', () => {
for (let i = 0; i < 5; i++) {
let name = `CallComponent${i}`;
- const document = await addScriptFile(name, `
+ const document = addScriptFile(name, `
sub init()
shouldBuildAwesome = true
if shouldBuildAwesome then
@@ -470,7 +471,7 @@ describe('LanguageServer', () => {
end sub
`);
- await addXmlFile(name, ``);
+ addXmlFile(name, ``);
referenceFileUris.push(document.uri);
}
});
@@ -521,7 +522,7 @@ describe('LanguageServer', () => {
program = svr.workspaces[0].builder.program;
const functionFileBaseName = 'buildAwesome';
- functionDocument = await addScriptFile(functionFileBaseName, `
+ functionDocument = addScriptFile(functionFileBaseName, `
function pi()
return 3.141592653589793
end function
@@ -532,7 +533,7 @@ describe('LanguageServer', () => {
`);
const name = `CallComponent`;
- referenceDocument = await addScriptFile(name, `
+ referenceDocument = addScriptFile(name, `
sub init()
shouldBuildAwesome = true
if shouldBuildAwesome then
@@ -543,7 +544,7 @@ describe('LanguageServer', () => {
end sub
`);
- await addXmlFile(name, ``);
+ addXmlFile(name, ``);
});
it('should return the expected location if we entered on an identifier token', async () => {
@@ -605,7 +606,7 @@ describe('LanguageServer', () => {
it('should work for bs class functions as well', async () => {
const functionFileBaseName = 'Build';
- functionDocument = await addScriptFile(functionFileBaseName, `
+ functionDocument = addScriptFile(functionFileBaseName, `
class ${functionFileBaseName}
function awesome()
return 42
@@ -614,14 +615,14 @@ describe('LanguageServer', () => {
`, 'bs');
const name = `CallComponent`;
- referenceDocument = await addScriptFile(name, `
+ referenceDocument = addScriptFile(name, `
sub init()
build = new Build()
build.awesome()
end sub
`);
- await addXmlFile(name, ``);
+ addXmlFile(name, ``);
const locations = await svr.onDefinition({
textDocument: {
@@ -647,7 +648,7 @@ describe('LanguageServer', () => {
});
it('should return the expected symbols even if pulled from cache', async () => {
- const document = await addScriptFile('buildAwesome', `
+ const document = addScriptFile('buildAwesome', `
function pi()
return 3.141592653589793
end function
@@ -669,7 +670,7 @@ describe('LanguageServer', () => {
});
it('should work for brightscript classes as well', async () => {
- const document = await addScriptFile('MyFirstClass', `
+ const document = addScriptFile('MyFirstClass', `
class MyFirstClass
function pi()
return 3.141592653589793
@@ -698,7 +699,7 @@ describe('LanguageServer', () => {
});
it('should work for brightscript namespaces as well', async () => {
- const document = await addScriptFile('MyFirstNamespace', `
+ const document = addScriptFile('MyFirstNamespace', `
namespace MyFirstNamespace
function pi()
return 3.141592653589793
@@ -738,7 +739,7 @@ describe('LanguageServer', () => {
const className = 'MyFirstClass';
const namespaceName = 'MyFirstNamespace';
- await addScriptFile('buildAwesome', `
+ addScriptFile('buildAwesome', `
function pi()
return 3.141592653589793
end function
@@ -748,7 +749,7 @@ describe('LanguageServer', () => {
end function
`);
- await addScriptFile(className, `
+ addScriptFile(className, `
class ${className}
function ${className}pi()
return 3.141592653589793
@@ -761,7 +762,7 @@ describe('LanguageServer', () => {
`, 'bs');
- await addScriptFile(namespaceName, `
+ addScriptFile(namespaceName, `
namespace ${namespaceName}
function pi()
return 3.141592653589793
@@ -810,7 +811,7 @@ describe('LanguageServer', () => {
const nestedNamespace = 'containerNamespace';
const nestedClassName = 'nestedClass';
- await addScriptFile('nested', `
+ addScriptFile('nested', `
namespace ${nestedNamespace}
class ${nestedClassName}
function pi()
diff --git a/src/LanguageServer.ts b/src/LanguageServer.ts
index d59c40ab1..4923d8d30 100644
--- a/src/LanguageServer.ts
+++ b/src/LanguageServer.ts
@@ -335,7 +335,7 @@ export class LanguageServer {
//if there's a setting, we need to find the file or show error if it can't be found
if (config?.configFile) {
configFilePath = path.resolve(workspacePath, config.configFile);
- if (await util.fileExists(configFilePath)) {
+ if (await util.pathExists(configFilePath)) {
return configFilePath;
} else {
this.sendCriticalFailure(`Cannot find config file specified in user/workspace settings at '${configFilePath}'`);
@@ -344,13 +344,13 @@ export class LanguageServer {
//default to config file path found in the root of the workspace
configFilePath = path.resolve(workspacePath, 'bsconfig.json');
- if (await util.fileExists(configFilePath)) {
+ if (await util.pathExists(configFilePath)) {
return configFilePath;
}
//look for the deprecated `brsconfig.json` file
configFilePath = path.resolve(workspacePath, 'brsconfig.json');
- if (await util.fileExists(configFilePath)) {
+ if (await util.pathExists(configFilePath)) {
return configFilePath;
}
@@ -371,16 +371,14 @@ export class LanguageServer {
builder.allowConsoleClearing = false;
//look for files in our in-memory cache before going to the file system
- builder.addFileResolver((pathAbsolute) => {
- return this.documentFileResolver(pathAbsolute);
- });
+ builder.addFileResolver(this.documentFileResolver.bind(this));
let configFilePath = await this.getConfigFilePath(workspacePath);
let cwd = workspacePath;
//if the config file exists, use it and its folder as cwd
- if (configFilePath && await util.fileExists(configFilePath)) {
+ if (configFilePath && await util.pathExists(configFilePath)) {
cwd = path.dirname(configFilePath);
} else {
//config file doesn't exist...let `brighterscript` resolve the default way
@@ -442,9 +440,7 @@ export class LanguageServer {
builder.allowConsoleClearing = false;
//look for files in our in-memory cache before going to the file system
- builder.addFileResolver((pathAbsolute) => {
- return this.documentFileResolver(pathAbsolute);
- });
+ builder.addFileResolver(this.documentFileResolver.bind(this));
//get the path to the directory where this file resides
let cwd = path.dirname(filePathAbsolute);
@@ -521,23 +517,9 @@ export class LanguageServer {
//wait until the file has settled
await this.keyedThrottler.onIdleOnce(filePath, true);
- let workspaceCompletionPromises = [] as Array>;
- let workspaces = this.getWorkspaces();
- //get completions from every workspace
- for (let workspace of workspaces) {
- //if this workspace has the file in question, get its completions
- if (workspace.builder.program.hasFile(filePath)) {
- workspaceCompletionPromises.push(
- workspace.builder.program.getCompletions(filePath, position)
- );
- }
- }
-
- let completions = ([] as CompletionItem[])
- //wait for all promises to resolve, and then flatten them into a single array
- .concat(...await Promise.all(workspaceCompletionPromises))
- //throw out falsey values
- .filter(x => !!x);
+ let completions = this
+ .getWorkspaces()
+ .flatMap(workspace => workspace.builder.program.getCompletions(filePath, position));
for (let completion of completions) {
completion.commitCharacters = ['.'];
@@ -804,10 +786,13 @@ export class LanguageServer {
//if we got a dest path, then the program wants this file
if (destPath) {
- await program.addOrReplaceFile({
- src: change.pathAbsolute,
- dest: rokuDeploy.getDestPath(change.pathAbsolute, options.files, rootDir)
- });
+ program.addOrReplaceFile(
+ {
+ src: change.pathAbsolute,
+ dest: rokuDeploy.getDestPath(change.pathAbsolute, options.files, rootDir)
+ },
+ await workspace.builder.getFileContents(change.pathAbsolute)
+ );
} else {
//no dest path means the program doesn't want this file
}
@@ -816,11 +801,14 @@ export class LanguageServer {
} else if (program.hasFile(change.pathAbsolute)) {
//sometimes "changed" events are emitted on files that were actually deleted,
//so determine file existance and act accordingly
- if (await util.fileExists(change.pathAbsolute)) {
- await program.addOrReplaceFile({
- src: change.pathAbsolute,
- dest: rokuDeploy.getDestPath(change.pathAbsolute, options.files, rootDir)
- });
+ if (await util.pathExists(change.pathAbsolute)) {
+ program.addOrReplaceFile(
+ {
+ src: change.pathAbsolute,
+ dest: rokuDeploy.getDestPath(change.pathAbsolute, options.files, rootDir)
+ },
+ await workspace.builder.getFileContents(change.pathAbsolute)
+ );
} else {
program.removeFile(change.pathAbsolute);
}
@@ -875,26 +863,23 @@ export class LanguageServer {
try {
//throttle file processing. first call is run immediately, and then the last call is processed.
- await this.keyedThrottler.run(filePath, async () => {
+ await this.keyedThrottler.run(filePath, () => {
this.connection.sendNotification('build-status', 'building');
let documentText = textDocument.getText();
- let workspaces = this.getWorkspaces();
- await Promise.all(
- workspaces.map(async (x) => {
- //only add or replace existing files. All of the files in the project should
- //have already been loaded by other means
- if (x.builder.program.hasFile(filePath)) {
- let rootDir = x.builder.program.options.rootDir ?? x.builder.program.options.cwd;
- let dest = rokuDeploy.getDestPath(filePath, x.builder.program.options.files, rootDir);
- await x.builder.program.addOrReplaceFile({
- src: filePath,
- dest: dest
- }, documentText);
- }
- })
- );
+ for (const workspace of this.getWorkspaces()) {
+ //only add or replace existing files. All of the files in the project should
+ //have already been loaded by other means
+ if (workspace.builder.program.hasFile(filePath)) {
+ let rootDir = workspace.builder.program.options.rootDir ?? workspace.builder.program.options.cwd;
+ let dest = rokuDeploy.getDestPath(filePath, workspace.builder.program.options.files, rootDir);
+ workspace.builder.program.addOrReplaceFile({
+ src: filePath,
+ dest: dest
+ }, documentText);
+ }
+ }
});
// validate all workspaces
await this.validateAllThrottled();
diff --git a/src/Program.spec.ts b/src/Program.spec.ts
index ec81b0b84..1dbdc7b89 100644
--- a/src/Program.spec.ts
+++ b/src/Program.spec.ts
@@ -48,81 +48,41 @@ describe('Program', () => {
});
describe('addFile', () => {
- it('adds various files to `pkgMap`', async () => {
- await program.addOrReplaceFile('source/main.brs', '');
+ it('adds various files to `pkgMap`', () => {
+ program.addOrReplaceFile('source/main.brs', '');
expect(program['pkgMap']).to.have.property(s`source/main.brs`);
- await program.addOrReplaceFile('source/main.bs', '');
+ program.addOrReplaceFile('source/main.bs', '');
expect(program['pkgMap']).to.have.property(s`source/main.bs`);
- await program.addOrReplaceFile('components/comp1.xml', '');
+ program.addOrReplaceFile('components/comp1.xml', '');
expect(program['pkgMap']).to.have.property(s`components/comp1.xml`);
});
- it('does not crash when given a totally bogus file', async () => {
- await program.addOrReplaceFile({
+ it('does not crash when given a totally bogus file', () => {
+ program.addOrReplaceFile({
src: `${rootDir}/source/main.brs`,
dest: 'source/main.brs'
}, `class Animalpublic name as stringpublic function walk()end functionend class`);
//if the program didn't get stuck in an infinite loop, this test passes
});
- describe('fileResolvers', () => {
- it('loads brs file contents from disk when necessary', async () => {
- let stub = sinon.stub(util, 'getFileContents').returns(Promise.resolve(''));
- expect(stub.called).to.be.false;
-
- //resolve lib.brs from memory instead of going to disk
- program.fileResolvers.push((pathAbsolute) => {
- if (
- pathAbsolute === s`${rootDir}/source/lib.brs` ||
- pathAbsolute === s`${rootDir}/source/lib.d.bs`
- ) {
- return `'comment`;
- }
- });
- await program.addOrReplaceFile({ src: `${rootDir}/source/lib.brs`, dest: 'source/lib.brs' });
-
- expect(stub.called).to.be.false;
-
- //load main.brs from disk
- await program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' });
- expect(stub.called).to.be.true;
- });
-
- it('loads xml file contents from disk when necessary', async () => {
- let stub = sinon.stub(util, 'getFileContents').returns(Promise.resolve(''));
- expect(stub.called).to.be.false;
-
- program.fileResolvers.push((pathAbsolute) => {
- if (pathAbsolute === s`${rootDir}/components/A.xml`) {
- return ``;
- }
- });
- await program.addOrReplaceFile({ src: `${rootDir}/components/A.xml`, dest: 'components/A.xml' });
- expect(stub.called).to.be.false;
-
- await program.addOrReplaceFile({ src: `${rootDir}/components/B.brs`, dest: 'components/B.brs' });
- expect(stub.called).to.be.true;
-
- });
- });
- it('only parses xml files as components when file is found within the "components" folder', async () => {
+ it('only parses xml files as components when file is found within the "components" folder', () => {
expect(Object.keys(program.files).length).to.equal(0);
- await program.addOrReplaceFile({
+ program.addOrReplaceFile({
src: s`${rootDir}/components/comp1.xml`,
dest: util.pathSepNormalize(`components/comp1.xml`)
}, '');
expect(Object.keys(program.files).length).to.equal(1);
- await program.addOrReplaceFile({
+ program.addOrReplaceFile({
src: s`${rootDir}/notComponents/comp1.xml`,
dest: util.pathSepNormalize(`notComponents/comp1.xml`)
}, '');
expect(Object.keys(program.files).length).to.equal(1);
- await program.addOrReplaceFile({
+ program.addOrReplaceFile({
src: s`${rootDir}/componentsExtra/comp1.xml`,
dest: util.pathSepNormalize(`componentsExtra/comp1.xml`)
}, '');
@@ -130,7 +90,7 @@ describe('Program', () => {
});
it('supports empty statements for transpile', async () => {
- const file = await program.addOrReplaceFile('source/main.bs', `
+ const file = program.addOrReplaceFile('source/main.bs', `
sub main()
m.logError()
'some comment
@@ -140,37 +100,37 @@ describe('Program', () => {
await program.transpile([{ src: file.pathAbsolute, dest: file.pkgPath }], tmpPath);
});
- it('works with different cwd', async () => {
+ it('works with different cwd', () => {
let projectDir = s`${tmpPath}/project2`;
fsExtra.ensureDirSync(projectDir);
program = new Program({ cwd: projectDir });
- await program.addOrReplaceFile({ src: 'source/lib.brs', dest: 'source/lib.brs' }, 'function main()\n print "hello world"\nend function');
+ program.addOrReplaceFile({ src: 'source/lib.brs', dest: 'source/lib.brs' }, 'function main()\n print "hello world"\nend function');
// await program.reloadFile('source/lib.brs', `'this is a comment`);
//if we made it to here, nothing exploded, so the test passes
});
- it(`adds files in the source folder to the 'source' scope`, async () => {
+ it(`adds files in the source folder to the 'source' scope`, () => {
expect(program.getScopeByName('source')).to.exist;
//no files in source scope
expect(program.getScopeByName('source').getOwnFiles().length).to.equal(0);
let mainPath = s`${rootDir}/source/main.brs`;
//add a new source file
- await program.addOrReplaceFile({ src: mainPath, dest: 'source/main.brs' }, '');
+ program.addOrReplaceFile({ src: mainPath, dest: 'source/main.brs' }, '');
//file should be in source scope now
expect(program.getScopeByName('source').getFile(mainPath)).to.exist;
//add an unreferenced file from the components folder
- await program.addOrReplaceFile({ src: `${rootDir}/components/component1/component1.brs`, dest: 'components/component1/component1.brs' }, '');
+ program.addOrReplaceFile({ src: `${rootDir}/components/component1/component1.brs`, dest: 'components/component1/component1.brs' }, '');
//source scope should have the same number of files
expect(program.getScopeByName('source').getFile(mainPath)).to.exist;
expect(program.getScopeByName('source').getFile(`${rootDir}/components/component1/component1.brs`)).not.to.exist;
});
- it('normalizes file paths', async () => {
+ it('normalizes file paths', () => {
let filePath = `${rootDir}/source\\main.brs`;
- await program.addOrReplaceFile({ src: filePath, dest: 'source/main.brs' }, '');
+ program.addOrReplaceFile({ src: filePath, dest: 'source/main.brs' }, '');
expect(program.getScopeByName('source').getFile(filePath)).to.exist;
@@ -188,7 +148,7 @@ describe('Program', () => {
// await program.loadOrReloadFile('components', '')
});
- it(`emits events for scope and file creation`, async () => {
+ it(`emits events for scope and file creation`, () => {
const beforeProgramValidate = sinon.spy();
const afterProgramValidate = sinon.spy();
const afterScopeCreate = sinon.spy();
@@ -211,14 +171,14 @@ describe('Program', () => {
let mainPath = s`${rootDir}/source/main.brs`;
//add a new source file
- await program.addOrReplaceFile({ src: mainPath, dest: 'source/main.brs' }, '');
+ program.addOrReplaceFile({ src: mainPath, dest: 'source/main.brs' }, '');
//add a component file
- await program.addOrReplaceFile({ src: `${rootDir}/components/component1.xml`, dest: 'components/component1.xml' }, trim`
+ program.addOrReplaceFile({ src: `${rootDir}/components/component1.xml`, dest: 'components/component1.xml' }, trim`
`);
- await program.validate();
+ program.validate();
//program events
expect(beforeProgramValidate.callCount).to.equal(1);
@@ -236,19 +196,19 @@ describe('Program', () => {
});
describe('validate', () => {
- it('catches duplicate XML component names', async () => {
+ it('catches duplicate XML component names', () => {
//add 2 components which both reference the same errored file
- await program.addOrReplaceFile({ src: `${rootDir}/components/component1.xml`, dest: 'components/component1.xml' }, trim`
+ program.addOrReplaceFile({ src: `${rootDir}/components/component1.xml`, dest: 'components/component1.xml' }, trim`
`);
- await program.addOrReplaceFile({ src: `${rootDir}/components/component2.xml`, dest: 'components/component2.xml' }, trim`
+ program.addOrReplaceFile({ src: `${rootDir}/components/component2.xml`, dest: 'components/component2.xml' }, trim`
`);
- await program.validate();
+ program.validate();
expect(program.getDiagnostics()).to.be.lengthOf(2);
expect(program.getDiagnostics().map(x => {
delete x.file;
@@ -287,9 +247,9 @@ describe('Program', () => {
expect(actual).to.deep.equal(expected);
});
- it('does not produce duplicate parse errors for different component scopes', async () => {
+ it('does not produce duplicate parse errors for different component scopes', () => {
//add a file with a parse error
- await program.addOrReplaceFile({ src: `${rootDir}/components/lib.brs`, dest: 'components/lib.brs' }, `
+ program.addOrReplaceFile({ src: `${rootDir}/components/lib.brs`, dest: 'components/lib.brs' }, `
sub DoSomething()
'random out-of-place open paren, definitely causes parse error
(
@@ -297,173 +257,173 @@ describe('Program', () => {
`);
//add 2 components which both reference the same errored file
- await program.addOrReplaceFile({ src: `${rootDir}/components/component1.xml`, dest: 'components/component1.xml' }, trim`
+ program.addOrReplaceFile({ src: `${rootDir}/components/component1.xml`, dest: 'components/component1.xml' }, trim`
`);
- await program.addOrReplaceFile({ src: `${rootDir}/components/component2.xml`, dest: 'components/component2.xml' }, trim`
+ program.addOrReplaceFile({ src: `${rootDir}/components/component2.xml`, dest: 'components/component2.xml' }, trim`
`);
- await program.validate();
+ program.validate();
let diagnostics = program.getDiagnostics();
expect(diagnostics).to.be.lengthOf(1);
});
- it('detects scripts not loaded by any file', async () => {
+ it('detects scripts not loaded by any file', () => {
//add a main file for sanity check
- await program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, '');
- await program.validate();
+ program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, '');
+ program.validate();
expect(program.getDiagnostics()).to.be.lengthOf(0);
//add the orphaned file
- await program.addOrReplaceFile({ src: `${rootDir}/components/lib.brs`, dest: 'components/lib.brs' }, '');
- await program.validate();
+ program.addOrReplaceFile({ src: `${rootDir}/components/lib.brs`, dest: 'components/lib.brs' }, '');
+ program.validate();
let diagnostics = program.getDiagnostics();
expect(diagnostics).to.be.lengthOf(1);
expect(diagnostics[0].code).to.equal(DiagnosticMessages.fileNotReferencedByAnyOtherFile().code);
});
- it('does not throw errors on shadowed init functions in components', async () => {
- await program.addOrReplaceFile({ src: `${rootDir}/lib.brs`, dest: 'lib.brs' }, `
+ it('does not throw errors on shadowed init functions in components', () => {
+ program.addOrReplaceFile({ src: `${rootDir}/lib.brs`, dest: 'lib.brs' }, `
function DoSomething()
return true
end function
`);
- await program.addOrReplaceFile({ src: `${rootDir}/components/Parent.xml`, dest: 'components/Parent.xml' }, trim`
+ program.addOrReplaceFile({ src: `${rootDir}/components/Parent.xml`, dest: 'components/Parent.xml' }, trim`
`);
- await program.addOrReplaceFile({ src: `${rootDir}/components/Child.xml`, dest: 'components/Child.xml' }, trim`
+ program.addOrReplaceFile({ src: `${rootDir}/components/Child.xml`, dest: 'components/Child.xml' }, trim`
`);
- await program.validate();
+ program.validate();
expect(program.getDiagnostics()).to.be.lengthOf(0);
});
- it('recognizes global function calls', async () => {
+ it('recognizes global function calls', () => {
expect(program.getDiagnostics().length).to.equal(0);
- await program.addOrReplaceFile({ src: `${rootDir}/source/file.brs`, dest: 'source/file.brs' }, `
+ program.addOrReplaceFile({ src: `${rootDir}/source/file.brs`, dest: 'source/file.brs' }, `
function DoB()
sleep(100)
end function
`);
//validate the scope
- await program.validate();
+ program.validate();
let diagnostics = program.getDiagnostics();
//shouldn't have any errors
expect(diagnostics).to.be.lengthOf(0);
});
- it('shows warning when a child component imports the same script as its parent', async () => {
- await program.addOrReplaceFile({ src: `${rootDir}/components/parent.xml`, dest: 'components/parent.xml' }, trim`
+ it('shows warning when a child component imports the same script as its parent', () => {
+ program.addOrReplaceFile({ src: `${rootDir}/components/parent.xml`, dest: 'components/parent.xml' }, trim`
`);
- await program.addOrReplaceFile({ src: `${rootDir}/components/child.xml`, dest: 'components/child.xml' }, trim`
+ program.addOrReplaceFile({ src: `${rootDir}/components/child.xml`, dest: 'components/child.xml' }, trim`
`);
- await program.addOrReplaceFile({ src: `${rootDir}/lib.brs`, dest: 'lib.brs' }, `'comment`);
- await program.validate();
+ program.addOrReplaceFile({ src: `${rootDir}/lib.brs`, dest: 'lib.brs' }, `'comment`);
+ program.validate();
let diagnostics = program.getDiagnostics();
expect(diagnostics).to.be.lengthOf(1);
expect(diagnostics[0].code).to.equal(DiagnosticMessages.unnecessaryScriptImportInChildFromParent('').code);
expect(diagnostics[0].severity).to.equal(DiagnosticSeverity.Warning);
});
- it('adds info diag when child component method shadows parent component method', async () => {
- await program.addOrReplaceFile({ src: `${rootDir}/components/parent.xml`, dest: 'components/parent.xml' }, trim`
+ it('adds info diag when child component method shadows parent component method', () => {
+ program.addOrReplaceFile({ src: `${rootDir}/components/parent.xml`, dest: 'components/parent.xml' }, trim`
`);
- await program.addOrReplaceFile({ src: `${rootDir}/components/child.xml`, dest: 'components/child.xml' }, trim`
+ program.addOrReplaceFile({ src: `${rootDir}/components/child.xml`, dest: 'components/child.xml' }, trim`
`);
- await program.addOrReplaceFile({ src: `${rootDir}/parent.brs`, dest: 'parent.brs' }, `sub DoSomething()\nend sub`);
- await program.addOrReplaceFile({ src: `${rootDir}/child.brs`, dest: 'child.brs' }, `sub DoSomething()\nend sub`);
- await program.validate();
+ program.addOrReplaceFile({ src: `${rootDir}/parent.brs`, dest: 'parent.brs' }, `sub DoSomething()\nend sub`);
+ program.addOrReplaceFile({ src: `${rootDir}/child.brs`, dest: 'child.brs' }, `sub DoSomething()\nend sub`);
+ program.validate();
let diagnostics = program.getDiagnostics();
expect(diagnostics).to.be.lengthOf(1);
expect(diagnostics[0].code).to.equal(DiagnosticMessages.overridesAncestorFunction('', '', '', '').code);
});
- it('does not add info diagnostic on shadowed "init" functions', async () => {
- await program.addOrReplaceFile('components/parent.xml', trim`
+ it('does not add info diagnostic on shadowed "init" functions', () => {
+ program.addOrReplaceFile('components/parent.xml', trim`
`);
- await program.addOrReplaceFile(`components/parent.brs`, `sub Init()\nend sub`);
- await program.addOrReplaceFile(`components/child.brs`, `sub Init()\nend sub`);
+ program.addOrReplaceFile(`components/parent.brs`, `sub Init()\nend sub`);
+ program.addOrReplaceFile(`components/child.brs`, `sub Init()\nend sub`);
- await program.addOrReplaceFile('components/child.xml', trim`
+ program.addOrReplaceFile('components/child.xml', trim`
`);
//run this validate separately so we can have an easier time debugging just the child component
- await program.validate();
+ program.validate();
let diagnostics = program.getDiagnostics();
expect(diagnostics.map(x => x.message)).to.eql([]);
});
- it('catches duplicate methods in single file', async () => {
- await program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
+ it('catches duplicate methods in single file', () => {
+ program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
sub DoSomething()
end sub
sub DoSomething()
end sub
`);
- await program.validate();
+ program.validate();
expect(program.getDiagnostics().length).to.equal(2);
expect(program.getDiagnostics()[0].message.indexOf('Duplicate sub declaration'));
});
- it('catches duplicate methods across multiple files', async () => {
- await program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
+ it('catches duplicate methods across multiple files', () => {
+ program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
sub DoSomething()
end sub
`);
- await program.addOrReplaceFile({ src: `${rootDir}/source/lib.brs`, dest: 'source/lib.brs' }, `
+ program.addOrReplaceFile({ src: `${rootDir}/source/lib.brs`, dest: 'source/lib.brs' }, `
sub DoSomething()
end sub
`);
- await program.validate();
+ program.validate();
expect(program.getDiagnostics().length).to.equal(2);
expect(program.getDiagnostics()[0].message.indexOf('Duplicate sub declaration'));
});
- it('maintains correct callables list', async () => {
+ it('maintains correct callables list', () => {
let initialCallableCount = program.getScopeByName('source').getAllCallables().length;
- await program.addOrReplaceFile('source/main.brs', `
+ program.addOrReplaceFile('source/main.brs', `
sub DoSomething()
end sub
sub DoSomething()
@@ -471,7 +431,7 @@ describe('Program', () => {
`);
expect(program.getScopeByName('source').getAllCallables().length).equals(initialCallableCount + 2);
//set the file contents again (resetting the wasProcessed flag)
- await program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
+ program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
sub DoSomething()
end sub
sub DoSomething()
@@ -482,82 +442,82 @@ describe('Program', () => {
expect(program.getScopeByName('source').getAllCallables().length).equals(initialCallableCount);
});
- it('resets errors on revalidate', async () => {
- await program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
+ it('resets errors on revalidate', () => {
+ program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
sub DoSomething()
end sub
sub DoSomething()
end sub
`);
- await program.validate();
+ program.validate();
expect(program.getDiagnostics().length).to.equal(2);
//set the file contents again (resetting the wasProcessed flag)
- await program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
+ program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
sub DoSomething()
end sub
sub DoSomething()
end sub
`);
- await program.validate();
+ program.validate();
expect(program.getDiagnostics().length).to.equal(2);
//load in a valid file, the errors should go to zero
- await program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
+ program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
sub DoSomething()
end sub
`);
- await program.validate();
+ program.validate();
expect(program.getDiagnostics().length).to.equal(0);
});
- it('identifies invocation of unknown function', async () => {
+ it('identifies invocation of unknown function', () => {
//call a function that doesn't exist
- await program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
+ program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
sub Main()
name = "Hello"
DoSomething(name)
end sub
`);
- await program.validate();
+ program.validate();
expect(program.getDiagnostics().length).to.equal(1);
expect(program.getDiagnostics()[0].code).to.equal(DiagnosticMessages.callToUnknownFunction('', '').code);
});
- it('detects methods from another file in a subdirectory', async () => {
- await program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
+ it('detects methods from another file in a subdirectory', () => {
+ program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
sub Main()
DoSomething()
end sub
`);
- await program.addOrReplaceFile({ src: `${rootDir}/source/ui/lib.brs`, dest: 'source/ui/lib.brs' }, `
+ program.addOrReplaceFile({ src: `${rootDir}/source/ui/lib.brs`, dest: 'source/ui/lib.brs' }, `
function DoSomething()
print "hello world"
end function
`);
- await program.validate();
+ program.validate();
expect(program.getDiagnostics().length).to.equal(0);
});
});
describe('hasFile', () => {
- it('recognizes when it has a file loaded', async () => {
+ it('recognizes when it has a file loaded', () => {
expect(program.hasFile('file1.brs')).to.be.false;
- await program.addOrReplaceFile({ src: 'file1.brs', dest: 'file1.brs' }, `'comment`);
+ program.addOrReplaceFile({ src: 'file1.brs', dest: 'file1.brs' }, `'comment`);
expect(program.hasFile('file1.brs')).to.be.true;
});
});
describe('addOrReplaceFile', () => {
- it('links xml scopes based on xml parent-child relationships', async () => {
- await program.addOrReplaceFile({ src: s`${rootDir}/components/ParentScene.xml`, dest: 'components/ParentScene.xml' }, trim`
+ it('links xml scopes based on xml parent-child relationships', () => {
+ program.addOrReplaceFile({ src: s`${rootDir}/components/ParentScene.xml`, dest: 'components/ParentScene.xml' }, trim`
`);
//create child component
- await program.addOrReplaceFile({ src: s`${rootDir}/components/ChildScene.xml`, dest: 'components/ChildScene.xml' }, trim`
+ program.addOrReplaceFile({ src: s`${rootDir}/components/ChildScene.xml`, dest: 'components/ChildScene.xml' }, trim`
@@ -566,7 +526,7 @@ describe('Program', () => {
expect(program.getScopeByName('components/ChildScene.xml').getParentScope().name).to.equal(s`components/ParentScene.xml`);
//change the parent's name.
- await program.addOrReplaceFile({ src: s`${rootDir}/components/ParentScene.xml`, dest: 'components/ParentScene.xml' }, trim`
+ program.addOrReplaceFile({ src: s`${rootDir}/components/ParentScene.xml`, dest: 'components/ParentScene.xml' }, trim`
@@ -576,48 +536,48 @@ describe('Program', () => {
expect(program.getScopeByName('components/ChildScene.xml').getParentScope().name).to.equal('global');
});
- it('creates a new scope for every added component xml', async () => {
+ it('creates a new scope for every added component xml', () => {
//we have global callables, so get that initial number
- await program.addOrReplaceFile({ src: `${rootDir}/components/component1.xml`, dest: 'components/component1.xml' }, '');
+ program.addOrReplaceFile({ src: `${rootDir}/components/component1.xml`, dest: 'components/component1.xml' }, '');
expect(program.getScopeByName(`components/component1.xml`)).to.exist;
- await program.addOrReplaceFile({ src: `${rootDir}/components/component1.xml`, dest: 'components/component1.xml' }, '');
- await program.addOrReplaceFile({ src: `${rootDir}/components/component2.xml`, dest: 'components/component2.xml' }, '');
+ program.addOrReplaceFile({ src: `${rootDir}/components/component1.xml`, dest: 'components/component1.xml' }, '');
+ program.addOrReplaceFile({ src: `${rootDir}/components/component2.xml`, dest: 'components/component2.xml' }, '');
expect(program.getScopeByName(`components/component1.xml`)).to.exist;
expect(program.getScopeByName(`components/component2.xml`)).to.exist;
});
- it('includes referenced files in xml scopes', async () => {
+ it('includes referenced files in xml scopes', () => {
let xmlPath = s`${rootDir}/components/component1.xml`;
- await program.addOrReplaceFile({ src: xmlPath, dest: 'components/component1.xml' }, trim`
+ program.addOrReplaceFile({ src: xmlPath, dest: 'components/component1.xml' }, trim`
`);
let brsPath = s`${rootDir}/components/component1.brs`;
- await program.addOrReplaceFile({ src: brsPath, dest: 'components/component1.brs' }, '');
+ program.addOrReplaceFile({ src: brsPath, dest: 'components/component1.brs' }, '');
let scope = program.getScopeByName(`components/component1.xml`);
expect(scope.getFile(xmlPath).pkgPath).to.equal(s`components/component1.xml`);
expect(scope.getFile(brsPath).pkgPath).to.equal(s`components/component1.brs`);
});
- it('adds xml file to files map', async () => {
+ it('adds xml file to files map', () => {
let xmlPath = `${rootDir}/components/component1.xml`;
- await program.addOrReplaceFile({ src: xmlPath, dest: 'components/component1.xml' }, '');
+ program.addOrReplaceFile({ src: xmlPath, dest: 'components/component1.xml' }, '');
expect(program.getFileByPathAbsolute(xmlPath)).to.exist;
});
- it('detects missing script reference', async () => {
+ it('detects missing script reference', () => {
let xmlPath = `${rootDir}/components/component1.xml`;
- await program.addOrReplaceFile({ src: xmlPath, dest: 'components/component1.xml' }, trim`
+ program.addOrReplaceFile({ src: xmlPath, dest: 'components/component1.xml' }, trim`
`);
- await program.validate();
+ program.validate();
let diagnostics = program.getDiagnostics();
expect(diagnostics.length).to.equal(1);
expect(diagnostics[0]).to.deep.include({
@@ -627,17 +587,17 @@ describe('Program', () => {
});
});
- it('adds warning instead of error on mismatched upper/lower case script import', async () => {
- await program.addOrReplaceFile('components/component1.xml', trim`
+ it('adds warning instead of error on mismatched upper/lower case script import', () => {
+ program.addOrReplaceFile('components/component1.xml', trim`
`);
- await program.addOrReplaceFile('components/COMPONENT1.brs', '');
+ program.addOrReplaceFile('components/COMPONENT1.brs', '');
//validate
- await program.validate();
+ program.validate();
let diagnostics = program.getDiagnostics();
expect(diagnostics.map(x => x.message)).to.eql([
DiagnosticMessages.scriptImportCaseMismatch(s`components\\COMPONENT1.brs`).message
@@ -646,73 +606,73 @@ describe('Program', () => {
});
describe('reloadFile', () => {
- it('picks up new files in a scope when an xml file is loaded', async () => {
+ it('picks up new files in a scope when an xml file is loaded', () => {
program.options.ignoreErrorCodes.push(1013);
let xmlPath = s`${rootDir}/components/component1.xml`;
- await program.addOrReplaceFile({ src: xmlPath, dest: 'components/comonent1.xml' }, trim`
+ program.addOrReplaceFile({ src: xmlPath, dest: 'components/comonent1.xml' }, trim`
`);
- await program.validate();
+ program.validate();
expect(program.getDiagnostics()[0]).to.deep.include({
message: DiagnosticMessages.referencedFileDoesNotExist().message
});
//add the file, the error should go away
let brsPath = s`${rootDir}/components/component1.brs`;
- await program.addOrReplaceFile({ src: brsPath, dest: 'components/component1.brs' }, '');
- await program.validate();
+ program.addOrReplaceFile({ src: brsPath, dest: 'components/component1.brs' }, '');
+ program.validate();
expect(program.getDiagnostics()).to.be.empty;
//add the xml file back in, but change the component brs file name. Should have an error again
- await program.addOrReplaceFile({ src: xmlPath, dest: 'components/component1.xml' }, trim`
+ program.addOrReplaceFile({ src: xmlPath, dest: 'components/component1.xml' }, trim`
`);
- await program.validate();
+ program.validate();
expect(program.getDiagnostics()[0]).to.deep.include({
message: DiagnosticMessages.referencedFileDoesNotExist().message
});
});
- it('handles when the brs file is added before the component', async () => {
+ it('handles when the brs file is added before the component', () => {
let brsPath = s`${rootDir}/components/component1.brs`;
- await program.addOrReplaceFile({ src: brsPath, dest: 'components/component1.brs' }, '');
+ program.addOrReplaceFile({ src: brsPath, dest: 'components/component1.brs' }, '');
let xmlPath = s`${rootDir}/components/component1.xml`;
- let xmlFile = await program.addOrReplaceFile({ src: xmlPath, dest: 'components/component1.xml' }, trim`
+ let xmlFile = program.addOrReplaceFile({ src: xmlPath, dest: 'components/component1.xml' }, trim`
`);
- await program.validate();
+ program.validate();
expect(program.getDiagnostics()).to.be.empty;
expect(program.getScopeByName(xmlFile.pkgPath).getFile(brsPath)).to.exist;
});
- it('reloads referenced fles when xml file changes', async () => {
+ it('reloads referenced fles when xml file changes', () => {
program.options.ignoreErrorCodes.push(1013);
let brsPath = s`${rootDir}/components/component1.brs`;
- await program.addOrReplaceFile({ src: brsPath, dest: 'components/component1.brs' }, '');
+ program.addOrReplaceFile({ src: brsPath, dest: 'components/component1.brs' }, '');
let xmlPath = s`${rootDir}/components/component1.xml`;
- let xmlFile = await program.addOrReplaceFile({ src: xmlPath, dest: 'components/component1.xml' }, trim`
+ let xmlFile = program.addOrReplaceFile({ src: xmlPath, dest: 'components/component1.xml' }, trim`
`);
- await program.validate();
+ program.validate();
expect(program.getDiagnostics()).to.be.empty;
expect(program.getScopeByName(xmlFile.pkgPath).getFile(brsPath)).not.to.exist;
//reload the xml file contents, adding a new script reference.
- xmlFile = await program.addOrReplaceFile({ src: xmlPath, dest: 'components/component1.xml' }, trim`
+ xmlFile = program.addOrReplaceFile({ src: xmlPath, dest: 'components/component1.xml' }, trim`
@@ -725,8 +685,8 @@ describe('Program', () => {
});
describe('getCompletions', () => {
- it('should include first-level namespace names for brighterscript files', async () => {
- await program.addOrReplaceFile('source/main.bs', `
+ it('should include first-level namespace names for brighterscript files', () => {
+ program.addOrReplaceFile('source/main.bs', `
namespace NameA.NameB.NameC
sub DoSomething()
end sub
@@ -735,7 +695,7 @@ describe('Program', () => {
end sub
`);
- let completions = (await program.getCompletions(`${rootDir}/source/main.bs`, Position.create(6, 23))).map(x => x.label);
+ let completions = program.getCompletions(`${rootDir}/source/main.bs`, Position.create(6, 23)).map(x => x.label);
expect(completions).to.include('NameA');
expect(completions).not.to.include('NameB');
expect(completions).not.to.include('NameA.NameB');
@@ -743,8 +703,8 @@ describe('Program', () => {
expect(completions).not.to.include('NameA.NameB.NameC.DoSomething');
});
- it('resolves completions for namespaces with next namespace part for brighterscript file', async () => {
- await program.addOrReplaceFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.brs' }, `
+ it('resolves completions for namespaces with next namespace part for brighterscript file', () => {
+ program.addOrReplaceFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.brs' }, `
namespace NameA.NameB.NameC
sub DoSomething()
end sub
@@ -753,7 +713,7 @@ describe('Program', () => {
NameA.
end sub
`);
- let completions = (await program.getCompletions(`${rootDir}/source/main.bs`, Position.create(6, 26))).map(x => x.label);
+ let completions = program.getCompletions(`${rootDir}/source/main.bs`, Position.create(6, 26)).map(x => x.label);
expect(completions).to.include('NameB');
expect(completions).not.to.include('NameA');
expect(completions).not.to.include('NameA.NameB');
@@ -761,8 +721,8 @@ describe('Program', () => {
expect(completions).not.to.include('NameA.NameB.NameC.DoSomething');
});
- it('finds namespace members for brighterscript file', async () => {
- await program.addOrReplaceFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.brs' }, `
+ it('finds namespace members for brighterscript file', () => {
+ program.addOrReplaceFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.brs' }, `
sub main()
NameA.
NameA.NameB.
@@ -786,20 +746,20 @@ describe('Program', () => {
end namespace
`);
expect(
- (await program.getCompletions(`${rootDir}/source/main.bs`, Position.create(2, 26))).map(x => x.label).sort()
+ program.getCompletions(`${rootDir}/source/main.bs`, Position.create(2, 26)).map(x => x.label).sort()
).to.eql(['NameB', 'alertA', 'info']);
expect(
- (await program.getCompletions(`${rootDir}/source/main.bs`, Position.create(3, 32))).map(x => x.label).sort()
+ program.getCompletions(`${rootDir}/source/main.bs`, Position.create(3, 32)).map(x => x.label).sort()
).to.eql(['NameC', 'alertB']);
expect(
- (await program.getCompletions(`${rootDir}/source/main.bs`, Position.create(4, 38))).map(x => x.label).sort()
+ program.getCompletions(`${rootDir}/source/main.bs`, Position.create(4, 38)).map(x => x.label).sort()
).to.eql(['alertC']);
});
- it('finds namespace members for classes', async () => {
- await program.addOrReplaceFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.brs' }, `
+ it('finds namespace members for classes', () => {
+ program.addOrReplaceFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.brs' }, `
sub main()
NameA.
NameA.NameB.
@@ -827,20 +787,20 @@ describe('Program', () => {
end namespace
`);
expect(
- (await program.getCompletions(`${rootDir}/source/main.bs`, Position.create(2, 26))).map(x => x.label).sort()
+ program.getCompletions(`${rootDir}/source/main.bs`, Position.create(2, 26)).map(x => x.label).sort()
).to.eql(['MyClassA', 'NameB', 'alertA', 'info']);
expect(
- (await program.getCompletions(`${rootDir}/source/main.bs`, Position.create(3, 32))).map(x => x.label).sort()
+ program.getCompletions(`${rootDir}/source/main.bs`, Position.create(3, 32)).map(x => x.label).sort()
).to.eql(['MyClassB', 'NameC', 'alertB']);
expect(
- (await program.getCompletions(`${rootDir}/source/main.bs`, Position.create(4, 38))).map(x => x.label).sort()
+ program.getCompletions(`${rootDir}/source/main.bs`, Position.create(4, 38)).map(x => x.label).sort()
).to.eql(['alertC']);
});
- it('finds only namespaces that have classes, when new keyword is used', async () => {
- await program.addOrReplaceFile('source/main.bs', `
+ it('finds only namespaces that have classes, when new keyword is used', () => {
+ program.addOrReplaceFile('source/main.bs', `
sub main()
a = new NameA.
b = new NameA.NameB.
@@ -875,57 +835,57 @@ describe('Program', () => {
end namespace
`);
expect(
- (await program.getCompletions(`${rootDir}/source/main.bs`, Position.create(2, 34))).map(x => x.label).sort()
+ program.getCompletions(`${rootDir}/source/main.bs`, Position.create(2, 34)).map(x => x.label).sort()
).to.eql(['MyClassA', 'NameB']);
expect(
- (await program.getCompletions(`${rootDir}/source/main.bs`, Position.create(3, 40))).map(x => x.label).sort()
+ program.getCompletions(`${rootDir}/source/main.bs`, Position.create(3, 40)).map(x => x.label).sort()
).to.eql(['MyClassB']);
expect(
- (await program.getCompletions(`${rootDir}/source/main.bs`, Position.create(4, 46))).map(x => x.label).sort()
+ program.getCompletions(`${rootDir}/source/main.bs`, Position.create(4, 46)).map(x => x.label).sort()
).to.be.empty;
});
//Bron.. pain to get this working.. do we realy need this? seems moot with ropm..
- it.skip('should include translated namespace function names for brightscript files', async () => {
- await program.addOrReplaceFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
+ it.skip('should include translated namespace function names for brightscript files', () => {
+ program.addOrReplaceFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
namespace NameA.NameB.NameC
sub DoSomething()
end sub
end namespace
`);
- await program.addOrReplaceFile({ src: `${rootDir}/source/lib.brs`, dest: 'source/lib.brs' }, `
+ program.addOrReplaceFile({ src: `${rootDir}/source/lib.brs`, dest: 'source/lib.brs' }, `
sub test()
end sub
`);
- let completions = await program.getCompletions(`${rootDir}/source/lib.brs`, Position.create(2, 23));
+ let completions = program.getCompletions(`${rootDir}/source/lib.brs`, Position.create(2, 23));
expect(completions.map(x => x.label)).to.include('NameA_NameB_NameC_DoSomething');
});
- it('inlcudes global completions for file with no scope', async () => {
- await program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'main.brs' }, `
+ it('inlcudes global completions for file with no scope', () => {
+ program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'main.brs' }, `
function Main()
age = 1
end function
`);
- let completions = await program.getCompletions(`${rootDir}/source/main.brs`, Position.create(2, 10));
+ let completions = program.getCompletions(`${rootDir}/source/main.brs`, Position.create(2, 10));
expect(completions.filter(x => x.label.toLowerCase() === 'abs')).to.be.lengthOf(1);
});
- it('filters out text results for top-level function statements', async () => {
- await program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
+ it('filters out text results for top-level function statements', () => {
+ program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
function Main()
age = 1
end function
`);
- let completions = await program.getCompletions(`${rootDir}/source/main.brs`, Position.create(2, 10));
+ let completions = program.getCompletions(`${rootDir}/source/main.brs`, Position.create(2, 10));
expect(completions.filter(x => x.label === 'Main')).to.be.lengthOf(1);
});
- it('does not filter text results for object properties used in conditional statements', async () => {
- await program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
+ it('does not filter text results for object properties used in conditional statements', () => {
+ program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
sub Main()
p.
end sub
@@ -936,12 +896,12 @@ describe('Program', () => {
end if
end sub
`);
- let completions = await program.getCompletions(`${rootDir}/source/main.brs`, Position.create(2, 22));
+ let completions = program.getCompletions(`${rootDir}/source/main.brs`, Position.create(2, 22));
expect(completions.filter(x => x.label === 'isAlive')).to.be.lengthOf(1);
});
- it('does not filter text results for object properties used in assignments', async () => {
- await program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
+ it('does not filter text results for object properties used in assignments', () => {
+ program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
sub Main()
p.
end sub
@@ -950,12 +910,12 @@ describe('Program', () => {
localVar = person.name
end sub
`);
- let completions = await program.getCompletions(`${rootDir}/source/main.brs`, Position.create(2, 22));
+ let completions = program.getCompletions(`${rootDir}/source/main.brs`, Position.create(2, 22));
expect(completions.filter(x => x.label === 'name')).to.be.lengthOf(1);
});
- it('does not filter text results for object properties', async () => {
- await program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
+ it('does not filter text results for object properties', () => {
+ program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
sub Main()
p.
end sub
@@ -964,12 +924,12 @@ describe('Program', () => {
person.name = "bob"
end sub
`);
- let completions = await program.getCompletions(`${rootDir}/source/main.brs`, Position.create(2, 22));
+ let completions = program.getCompletions(`${rootDir}/source/main.brs`, Position.create(2, 22));
expect(completions.filter(x => x.label === 'name')).to.be.lengthOf(1);
});
- it('filters out text results for local vars used in conditional statements', async () => {
- await program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
+ it('filters out text results for local vars used in conditional statements', () => {
+ program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
sub Main()
end sub
@@ -980,12 +940,12 @@ describe('Program', () => {
end if
end sub
`);
- let completions = await program.getCompletions(`${rootDir}/source/main.brs`, Position.create(2, 10));
+ let completions = program.getCompletions(`${rootDir}/source/main.brs`, Position.create(2, 10));
expect(completions.filter(x => x.label === 'isTrue')).to.be.lengthOf(0);
});
- it('filters out text results for local variable assignments', async () => {
- await program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
+ it('filters out text results for local variable assignments', () => {
+ program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
sub Main()
end sub
@@ -993,12 +953,12 @@ describe('Program', () => {
message = "Hello"
end sub
`);
- let completions = await program.getCompletions(`${rootDir}/source/main.brs`, Position.create(2, 10));
+ let completions = program.getCompletions(`${rootDir}/source/main.brs`, Position.create(2, 10));
expect(completions.filter(x => x.label === 'message')).to.be.lengthOf(0);
});
- it('filters out text results for local variables used in assignments', async () => {
- await program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
+ it('filters out text results for local variables used in assignments', () => {
+ program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
sub Main()
end sub
@@ -1007,32 +967,32 @@ describe('Program', () => {
otherVar = message
end sub
`);
- let completions = await program.getCompletions(`${rootDir}/source/main.brs`, Position.create(2, 10));
+ let completions = program.getCompletions(`${rootDir}/source/main.brs`, Position.create(2, 10));
expect(completions.filter(x => x.label === 'message')).to.be.lengthOf(0);
});
- it('does not suggest local variables when initiated to the right of a period', async () => {
- await program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
+ it('does not suggest local variables when initiated to the right of a period', () => {
+ program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
function Main()
helloMessage = "jack"
person.hello
end function
`);
- let completions = await program.getCompletions(`${rootDir}/source/main.brs`, Position.create(3, 32));
+ let completions = program.getCompletions(`${rootDir}/source/main.brs`, Position.create(3, 32));
expect(completions.filter(x => x.kind === CompletionItemKind.Variable).map(x => x.label)).not.to.contain('helloMessage');
});
- it('finds all file paths when initiated on xml uri', async () => {
+ it('finds all file paths when initiated on xml uri', () => {
let xmlPath = s`${rootDir}/components/component1.xml`;
- await program.addOrReplaceFile({ src: xmlPath, dest: 'components/component1.xml' }, trim`
+ program.addOrReplaceFile({ src: xmlPath, dest: 'components/component1.xml' }, trim`
`);
let brsPath = s`${rootDir}/components/component1.brs`;
- await program.addOrReplaceFile({ src: brsPath, dest: 'components/component1.brs' }, '');
- let completions = await program.getCompletions(xmlPath, Position.create(2, 42));
+ program.addOrReplaceFile({ src: brsPath, dest: 'components/component1.brs' }, '');
+ let completions = program.getCompletions(xmlPath, Position.create(2, 42));
expect(completions[0]).to.include({
kind: CompletionItemKind.File,
label: 'component1.brs'
@@ -1045,8 +1005,8 @@ describe('Program', () => {
expect(completions).to.be.lengthOf(2);
});
- it('get all functions and properties in scope when doing any dotted get on non m ', async () => {
- await program.addOrReplaceFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.brs' }, `
+ it('get all functions and properties in scope when doing any dotted get on non m ', () => {
+ program.addOrReplaceFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.brs' }, `
sub main()
thing.anonPropA = "foo"
thing.anonPropB = "bar"
@@ -1085,12 +1045,12 @@ describe('Program', () => {
`);
//note - we let the vscode extension do the filtering, so we still return everything; otherwise it exhibits strange behaviour in the IDE
expect(
- (await program.getCompletions(`${rootDir}/source/main.bs`, Position.create(4, 32))).map(x => x.label).sort()
+ (program.getCompletions(`${rootDir}/source/main.bs`, Position.create(4, 32))).map(x => x.label).sort()
).to.eql(['anonPropA', 'anonPropB', 'person', 'personAMethodA', 'personAMethodB', 'personAMethodC', 'personAName', 'personBMethodA', 'personBMethodB', 'personBName', 'personName']);
});
- it('get all functions and properties relevant for m ', async () => {
- await program.addOrReplaceFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.brs' }, `
+ it('get all functions and properties relevant for m ', () => {
+ program.addOrReplaceFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.brs' }, `
class MyClassA
function new()
m.
@@ -1128,17 +1088,17 @@ describe('Program', () => {
end sub
`);
expect(
- (await program.getCompletions(`${rootDir}/source/main.bs`, Position.create(3, 26))).map(x => x.label).sort()
+ (program.getCompletions(`${rootDir}/source/main.bs`, Position.create(3, 26))).map(x => x.label).sort()
).to.eql(['personAMethodA', 'personAMethodB', 'personAName', 'personName']);
expect(
- (await program.getCompletions(`${rootDir}/source/main.bs`, Position.create(24, 26))).map(x => x.label).sort()
+ (program.getCompletions(`${rootDir}/source/main.bs`, Position.create(24, 26))).map(x => x.label).sort()
).to.eql(['personAMethodA', 'personAMethodB', 'personAName', 'personCMethodA', 'personCMethodB', 'personCMethodC', 'personCName', 'personName']);
});
});
- it('include non-namespaced classes in the list of general output', async () => {
- await program.addOrReplaceFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.brs' }, `
+ it('include non-namespaced classes in the list of general output', () => {
+ program.addOrReplaceFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.brs' }, `
function regularFunc()
MyClass
end function
@@ -1152,12 +1112,12 @@ describe('Program', () => {
end class
`);
expect(
- (await program.getCompletions(`${rootDir}/source/main.bs`, Position.create(3, 26))).map(x => x.label).sort()
+ (program.getCompletions(`${rootDir}/source/main.bs`, Position.create(3, 26))).map(x => x.label).sort()
).to.include.members(['MyClassA', 'MyClassB', 'MyClassC']);
});
- it('only include classes when using new keyword', async () => {
- await program.addOrReplaceFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.brs' }, `
+ it('only include classes when using new keyword', () => {
+ program.addOrReplaceFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.brs' }, `
class MyClassA
end class
class MyClassB
@@ -1171,21 +1131,21 @@ describe('Program', () => {
end sub
`);
expect(
- (await program.getCompletions(`${rootDir}/source/main.bs`, Position.create(8, 29))).map(x => x.label).sort()
+ (program.getCompletions(`${rootDir}/source/main.bs`, Position.create(8, 29))).map(x => x.label).sort()
).to.eql(['MyClassA', 'MyClassB', 'MyClassC']);
});
- it('gets completions when using callfunc inovation', async () => {
- await program.addOrReplaceFile('source/main.bs', `
+ it('gets completions when using callfunc inovation', () => {
+ program.addOrReplaceFile('source/main.bs', `
function main()
myNode@.sayHello(arg1)
end function
`);
- await program.addOrReplaceFile('components/MyNode.bs', `
+ program.addOrReplaceFile('components/MyNode.bs', `
function sayHello(text, text2)
end function
`);
- await program.addOrReplaceFile('components/MyNode.xml',
+ program.addOrReplaceFile('components/MyNode.xml',
trim`
@@ -1193,26 +1153,26 @@ describe('Program', () => {
`);
- await program.validate();
+ program.validate();
expect(
- (await program.getCompletions(`${rootDir}/source/main.bs`, Position.create(2, 30))).map(x => x.label).sort()
+ (program.getCompletions(`${rootDir}/source/main.bs`, Position.create(2, 30))).map(x => x.label).sort()
).to.eql(['sayHello']);
});
- it('gets completions for callfunc invocation with multiple nodes', async () => {
- await program.addOrReplaceFile('source/main.bs', `
+ it('gets completions for callfunc invocation with multiple nodes', () => {
+ program.addOrReplaceFile('source/main.bs', `
function main()
myNode@.sayHello(arg1)
end function
`);
- await program.addOrReplaceFile('components/MyNode.bs', `
+ program.addOrReplaceFile('components/MyNode.bs', `
function sayHello(text, text2)
end function
function sayHello2(text, text2)
end function
`);
- await program.addOrReplaceFile('components/MyNode.xml',
+ program.addOrReplaceFile('components/MyNode.xml',
trim`
@@ -1221,13 +1181,13 @@ describe('Program', () => {
`);
- await program.addOrReplaceFile('components/MyNode2.bs', `
+ program.addOrReplaceFile('components/MyNode2.bs', `
function sayHello3(text, text2)
end function
function sayHello4(text, text2)
end function
`);
- await program.addOrReplaceFile('components/MyNode2.xml',
+ program.addOrReplaceFile('components/MyNode2.xml',
trim`
@@ -1236,26 +1196,26 @@ describe('Program', () => {
`);
- await program.validate();
+ program.validate();
expect(
- (await program.getCompletions(`${rootDir}/source/main.bs`, Position.create(2, 30))).map(x => x.label).sort()
+ (program.getCompletions(`${rootDir}/source/main.bs`, Position.create(2, 30))).map(x => x.label).sort()
).to.eql(['sayHello', 'sayHello2', 'sayHello3', 'sayHello4']);
});
- it('gets completions for extended nodes with callfunc invocation - ensure overridden methods included', async () => {
- await program.addOrReplaceFile('source/main.bs', `
+ it('gets completions for extended nodes with callfunc invocation - ensure overridden methods included', () => {
+ program.addOrReplaceFile('source/main.bs', `
function main()
myNode@.sayHello(arg1)
end function
`);
- await program.addOrReplaceFile('components/MyNode.bs', `
+ program.addOrReplaceFile('components/MyNode.bs', `
function sayHello(text, text2)
end function
function sayHello2(text, text2)
end function
`);
- await program.addOrReplaceFile('components/MyNode.xml',
+ program.addOrReplaceFile('components/MyNode.xml',
trim`
@@ -1264,7 +1224,7 @@ describe('Program', () => {
`);
- await program.addOrReplaceFile('components/MyNode2.bs', `
+ program.addOrReplaceFile('components/MyNode2.bs', `
function sayHello3(text, text2)
end function
function sayHello2(text, text2)
@@ -1272,7 +1232,7 @@ describe('Program', () => {
function sayHello4(text, text2)
end function
`);
- await program.addOrReplaceFile('components/MyNode2.xml',
+ program.addOrReplaceFile('components/MyNode2.xml',
trim`
@@ -1281,24 +1241,24 @@ describe('Program', () => {
`);
- await program.validate();
+ program.validate();
expect(
- (await program.getCompletions(`${rootDir}/source/main.bs`, Position.create(2, 30))).map(x => x.label).sort()
+ (program.getCompletions(`${rootDir}/source/main.bs`, Position.create(2, 30))).map(x => x.label).sort()
).to.eql(['sayHello', 'sayHello2', 'sayHello2', 'sayHello3', 'sayHello4']);
});
describe('xml inheritance', () => {
- it('handles parent-child attach and detach', async () => {
+ it('handles parent-child attach and detach', () => {
//create parent component
- let parentFile = await program.addOrReplaceFile({ src: s`${rootDir}/components/ParentScene.xml`, dest: 'components/ParentScene.xml' }, trim`
+ let parentFile = program.addOrReplaceFile({ src: s`${rootDir}/components/ParentScene.xml`, dest: 'components/ParentScene.xml' }, trim`
`);
//create child component
- let childFile = await program.addOrReplaceFile({ src: s`${rootDir}/components/ChildScene.xml`, dest: 'components/ChildScene.xml' }, trim`
+ let childFile = program.addOrReplaceFile({ src: s`${rootDir}/components/ChildScene.xml`, dest: 'components/ChildScene.xml' }, trim`
@@ -1308,7 +1268,7 @@ describe('Program', () => {
expect((childFile as XmlFile).parentComponent).to.equal(parentFile);
//change the name of the parent
- parentFile = await program.addOrReplaceFile({ src: s`${rootDir}/components/ParentScene.xml`, dest: 'components/ParentScene.xml' }, trim`
+ parentFile = program.addOrReplaceFile({ src: s`${rootDir}/components/ParentScene.xml`, dest: 'components/ParentScene.xml' }, trim`
@@ -1318,28 +1278,28 @@ describe('Program', () => {
expect((childFile as XmlFile).parentComponent).not.to.exist;
});
- it('provides child components with parent functions', async () => {
+ it('provides child components with parent functions', () => {
//create parent component
- await program.addOrReplaceFile({ src: s`${rootDir}/components/ParentScene.xml`, dest: 'components/ParentScene.xml' }, trim`
+ program.addOrReplaceFile({ src: s`${rootDir}/components/ParentScene.xml`, dest: 'components/ParentScene.xml' }, trim`
`);
//create child component
- await program.addOrReplaceFile({ src: s`${rootDir}/components/ChildScene.xml`, dest: 'components/ChildScene.xml' }, trim`
+ program.addOrReplaceFile({ src: s`${rootDir}/components/ChildScene.xml`, dest: 'components/ChildScene.xml' }, trim`
`);
- await program.addOrReplaceFile({ src: `${rootDir}/components/ChildScene.brs`, dest: 'components/ChildScene.brs' }, `
+ program.addOrReplaceFile({ src: `${rootDir}/components/ChildScene.brs`, dest: 'components/ChildScene.brs' }, `
sub Init()
DoParentThing()
end sub
`);
- await program.validate();
+ program.validate();
//there should be an error when calling DoParentThing, since it doesn't exist on child or parent
expect(program.getDiagnostics()).to.be.lengthOf(1);
@@ -1348,34 +1308,34 @@ describe('Program', () => {
});
//add the script into the parent
- await program.addOrReplaceFile({ src: s`${rootDir}/components/ParentScene.xml`, dest: 'components/ParentScene.xml' }, trim`
+ program.addOrReplaceFile({ src: s`${rootDir}/components/ParentScene.xml`, dest: 'components/ParentScene.xml' }, trim`
`);
- await program.addOrReplaceFile({ src: `${rootDir}/components/ParentScene.brs`, dest: 'components/ParentScene.brs' }, `
+ program.addOrReplaceFile({ src: `${rootDir}/components/ParentScene.brs`, dest: 'components/ParentScene.brs' }, `
sub DoParentThing()
end sub
`);
- await program.validate();
+ program.validate();
//the error should be gone because the child now has access to the parent script
expect(program.getDiagnostics()).to.be.empty;
});
});
describe('xml scope', () => {
- it('does not fail on base components with many children', async () => {
- await program.addOrReplaceFile({ src: `${rootDir}/source/lib.brs`, dest: 'source/lib.brs' }, `
+ it('does not fail on base components with many children', () => {
+ program.addOrReplaceFile({ src: `${rootDir}/source/lib.brs`, dest: 'source/lib.brs' }, `
sub DoSomething()
end sub
`);
//add a brs file with invalid syntax
- await program.addOrReplaceFile({ src: `${rootDir}/components/base.xml`, dest: 'components/base.xml' }, trim`
+ program.addOrReplaceFile({ src: `${rootDir}/components/base.xml`, dest: 'components/base.xml' }, trim`
@@ -1384,14 +1344,14 @@ describe('Program', () => {
let childCount = 20;
//add many children, we should never encounter an error
for (let i = 0; i < childCount; i++) {
- await program.addOrReplaceFile({ src: `${rootDir}/components/child${i}.xml`, dest: `components/child${i}.xml` }, trim`
+ program.addOrReplaceFile({ src: `${rootDir}/components/child${i}.xml`, dest: `components/child${i}.xml` }, trim`
`);
}
- await program.validate();
+ program.validate();
let diagnostics = program.getDiagnostics();
//the children shouldn't have diagnostics about shadowing their parent lib.brs file.
@@ -1403,9 +1363,9 @@ describe('Program', () => {
expect(importDiagnositcs).to.be.lengthOf(childCount);
});
- it('detects script import changes', async () => {
+ it('detects script import changes', () => {
//create the xml file without script imports
- let xmlFile = await program.addOrReplaceFile({ src: `${rootDir}/components/component.xml`, dest: 'components/component.xml' }, trim`
+ let xmlFile = program.addOrReplaceFile({ src: `${rootDir}/components/component.xml`, dest: 'components/component.xml' }, trim`
@@ -1415,10 +1375,10 @@ describe('Program', () => {
expect(program.getScopeByName(xmlFile.pkgPath).getOwnFiles().length).to.equal(1);
//create the lib file
- let libFile = await program.addOrReplaceFile({ src: `${rootDir}/source/lib.brs`, dest: 'source/lib.brs' }, `'comment`);
+ let libFile = program.addOrReplaceFile({ src: `${rootDir}/source/lib.brs`, dest: 'source/lib.brs' }, `'comment`);
//change the xml file to have a script import
- xmlFile = await program.addOrReplaceFile({ src: `${rootDir}/components/component.xml`, dest: 'components/component.xml' }, trim`
+ xmlFile = program.addOrReplaceFile({ src: `${rootDir}/components/component.xml`, dest: 'components/component.xml' }, trim`
@@ -1431,7 +1391,7 @@ describe('Program', () => {
expect(ctx.getFile(libFile.pathAbsolute)).to.exist;
//reload the xml file again, removing the script import.
- xmlFile = await program.addOrReplaceFile({ src: `${rootDir}/components/component.xml`, dest: 'components/component.xml' }, trim`
+ xmlFile = program.addOrReplaceFile({ src: `${rootDir}/components/component.xml`, dest: 'components/component.xml' }, trim`
@@ -1444,49 +1404,29 @@ describe('Program', () => {
});
describe('getFileByPkgPath', () => {
- it('finds file in source folder', async () => {
+ it('finds file in source folder', () => {
expect(program.getFileByPkgPath(s`source/main.brs`)).not.to.exist;
expect(program.getFileByPkgPath(s`source/main2.brs`)).not.to.exist;
- await program.addOrReplaceFile({ src: `${rootDir}/source/main2.brs`, dest: 'source/main2.brs' }, '');
- await program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, '');
+ program.addOrReplaceFile({ src: `${rootDir}/source/main2.brs`, dest: 'source/main2.brs' }, '');
+ program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, '');
expect(program.getFileByPkgPath(s`source/main.brs`)).to.exist;
expect(program.getFileByPkgPath(s`source/main2.brs`)).to.exist;
});
});
describe('removeFiles', () => {
- it('removes files by absolute paths', async () => {
- await program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, '');
+ it('removes files by absolute paths', () => {
+ program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, '');
expect(program.getFileByPkgPath(s`source/main.brs`)).to.exist;
program.removeFiles([`${rootDir}/source/main.brs`]);
expect(program.getFileByPkgPath(s`source/main.brs`)).not.to.exist;
});
});
- describe('addOrReplaceFiles', () => {
- it('adds multiple files', async () => {
- expect(Object.keys(program.files).length).to.equal(0);
- let brsFilePath = s`${rootDir}/components/comp1.brs`.toLowerCase();
- let xmlFilePath = s`${rootDir}/components/comp1.xml`.toLowerCase();
- program.fileResolvers.push((filePath) => {
- if (filePath.toLowerCase() === s`${brsFilePath}`) {
- return `'${filePath}`;
- } else if (filePath.toLowerCase() === s`${xmlFilePath}`) {
- return ``)).to.be.true;
});
- it('AST-based source mapping includes sourcemap reference', async () => {
- let file = await program.addOrReplaceFile(
+ it('AST-based source mapping includes sourcemap reference', () => {
+ let file = program.addOrReplaceFile(
{ src: s`${rootDir}/components/SimpleScene.xml`, dest: 'components/SimpleScene.xml' },
trim`
@@ -750,7 +750,7 @@ describe('XmlFile', () => {
});
});
- it('plugin diagnostics work for xml files', async () => {
+ it('plugin diagnostics work for xml files', () => {
program.plugins.add({
name: 'Xml diagnostic test',
afterFileParse: (file) => {
@@ -765,12 +765,12 @@ describe('XmlFile', () => {
}
});
- await program.addOrReplaceFile('components/comp.xml', trim`
+ program.addOrReplaceFile('components/comp.xml', trim`
`);
- await program.validate();
+ program.validate();
expect(program.getDiagnostics().map(x => ({ message: x.message, code: x.code }))).to.eql([{
message: 'Test diagnostic',
code: 9999
@@ -778,50 +778,50 @@ describe('XmlFile', () => {
});
describe('typedef', () => {
- it('loads d.bs files from parent scope', async () => {
- await program.addOrReplaceFile('components/ParentComponent.xml', trim`
+ it('loads d.bs files from parent scope', () => {
+ program.addOrReplaceFile('components/ParentComponent.xml', trim`
`);
- await program.addOrReplaceFile('components/ParentComponent.d.bs', `
+ program.addOrReplaceFile('components/ParentComponent.d.bs', `
import "Lib.brs"
namespace Parent
sub log()
end sub
end namespace
`);
- await program.addOrReplaceFile('components/ParentComponent.brs', `
+ program.addOrReplaceFile('components/ParentComponent.brs', `
sub Parent_log()
end sub
`);
- await program.addOrReplaceFile('components/Lib.d.bs', `
+ program.addOrReplaceFile('components/Lib.d.bs', `
namespace Lib
sub log()
end sub
end namespace
`);
- await program.addOrReplaceFile('components/Lib.brs', `
+ program.addOrReplaceFile('components/Lib.brs', `
sub Lib_log()
end sub
`);
- await program.addOrReplaceFile('components/ChildComponent.xml', trim`
+ program.addOrReplaceFile('components/ChildComponent.xml', trim`
`);
- await program.addOrReplaceFile('components/ChildComponent.bs', `
+ program.addOrReplaceFile('components/ChildComponent.bs', `
sub init()
Parent.log()
Lib.log()
end sub
`);
- await program.validate();
+ program.validate();
expect(program.getDiagnostics()[0]?.message).not.to.exist;
const scope = program.getComponentScope('ChildComponent');
expect(Object.keys(scope.namespaceLookup).sort()).to.eql([
@@ -830,14 +830,14 @@ describe('XmlFile', () => {
]);
});
- it('loads `d.bs` files into scope', async () => {
- const xmlFile = await program.addOrReplaceFile('components/Component1.xml', trim`
+ it('loads `d.bs` files into scope', () => {
+ const xmlFile = program.addOrReplaceFile('components/Component1.xml', trim`
`);
- await program.addOrReplaceFile('components/Component1.d.bs', `
+ program.addOrReplaceFile('components/Component1.d.bs', `
sub logInfo()
end sub
`);
@@ -845,21 +845,21 @@ describe('XmlFile', () => {
expect(program.getScopesForFile(xmlFile)[0].getAllCallables().map(x => x.callable.name)).to.include('logInfo');
});
- it('does not include `d.bs` script during transpile', async () => {
- await program.addOrReplaceFile('source/logger.d.bs', `
+ it('does not include `d.bs` script during transpile', () => {
+ program.addOrReplaceFile('source/logger.d.bs', `
sub logInfo()
end sub
`);
- await program.addOrReplaceFile('source/logger.brs', `
+ program.addOrReplaceFile('source/logger.brs', `
sub logInfo()
end sub
`);
- await program.addOrReplaceFile('components/Component1.bs', `
+ program.addOrReplaceFile('components/Component1.bs', `
import "pkg:/source/logger.brs"
sub logInfo()
end sub
`);
- await testTranspile(trim`
+ testTranspile(trim`
@@ -874,8 +874,8 @@ describe('XmlFile', () => {
`, 'none', 'components/Component1.xml');
});
- it('does not load .brs information into scope if related d.bs is in scope', async () => {
- const xmlFile = await program.addOrReplaceFile('components/Component1.xml', trim`
+ it('does not load .brs information into scope if related d.bs is in scope', () => {
+ const xmlFile = program.addOrReplaceFile('components/Component1.xml', trim`
@@ -884,7 +884,7 @@ describe('XmlFile', () => {
const scope = program.getScopesForFile(xmlFile)[0];
//load brs file
- await program.addOrReplaceFile('components/Component1.brs', `
+ program.addOrReplaceFile('components/Component1.brs', `
sub logInfo()
end sub
sub logWarning()
@@ -896,7 +896,7 @@ describe('XmlFile', () => {
expect(functionNames).to.include('logWarning');
//load d.bs file, which should shadow out the .brs file
- await program.addOrReplaceFile('components/Component1.d.bs', `
+ program.addOrReplaceFile('components/Component1.d.bs', `
sub logError()
end sub
`);
@@ -907,8 +907,8 @@ describe('XmlFile', () => {
expect(functionNames).not.to.include('logWarning');
});
- it('updates xml scope when typedef disappears', async () => {
- const xmlFile = await program.addOrReplaceFile('components/Component1.xml', trim`
+ it('updates xml scope when typedef disappears', () => {
+ const xmlFile = program.addOrReplaceFile('components/Component1.xml', trim`
@@ -917,16 +917,16 @@ describe('XmlFile', () => {
const scope = program.getScopesForFile(xmlFile)[0];
//load brs file
- await program.addOrReplaceFile('components/Component1.brs', `
+ program.addOrReplaceFile('components/Component1.brs', `
sub logBrs()
end sub
`);
//load d.bs file, which should shadow out the .brs file
- const typedef = await program.addOrReplaceFile('components/Component1.d.bs', `
+ const typedef = program.addOrReplaceFile('components/Component1.d.bs', `
sub logTypedef()
end sub
`);
- await program.validate();
+ program.validate();
let functionNames = scope.getOwnCallables().map(x => x.callable.name);
expect(functionNames).to.include('logTypedef');
expect(functionNames).not.to.include('logBrs');
@@ -934,15 +934,15 @@ describe('XmlFile', () => {
//remove the typdef file
program.removeFile(typedef.pathAbsolute);
- await program.validate();
+ program.validate();
functionNames = scope.getOwnCallables().map(x => x.callable.name);
expect(functionNames).not.to.include('logTypedef');
expect(functionNames).to.include('logBrs');
});
});
- it('finds script imports for single-quoted script tags', async () => {
- const file = await program.addOrReplaceFile('components/file.xml', trim`
+ it('finds script imports for single-quoted script tags', () => {
+ const file = program.addOrReplaceFile('components/file.xml', trim`
diff --git a/src/files/tests/imports.spec.ts b/src/files/tests/imports.spec.ts
index b62848d78..23446b84c 100644
--- a/src/files/tests/imports.spec.ts
+++ b/src/files/tests/imports.spec.ts
@@ -34,14 +34,14 @@ describe('import statements', () => {
});
it('still transpiles import statements if found at bottom of file', async () => {
- await program.addOrReplaceFile('components/ChildScene.xml', trim`
+ program.addOrReplaceFile('components/ChildScene.xml', trim`
`);
- await program.addOrReplaceFile('source/lib.bs', `
+ program.addOrReplaceFile('source/lib.bs', `
function toLower(strVal as string)
return StringToLower(strVal)
end function
@@ -49,7 +49,7 @@ describe('import statements', () => {
import "stringOps.bs"
`);
- await program.addOrReplaceFile('source/stringOps.bs', `
+ program.addOrReplaceFile('source/stringOps.bs', `
function StringToLower(strVal as string)
return true
end function
@@ -73,32 +73,32 @@ describe('import statements', () => {
`);
});
- it('finds function loaded in by import multiple levels deep', async () => {
+ it('finds function loaded in by import multiple levels deep', () => {
//create child component
- let component = await program.addOrReplaceFile('components/ChildScene.xml', trim`
+ let component = program.addOrReplaceFile('components/ChildScene.xml', trim`
`);
- await program.addOrReplaceFile('source/lib.bs', `
+ program.addOrReplaceFile('source/lib.bs', `
import "stringOps.bs"
function toLower(strVal as string)
return StringToLower(strVal)
end function
`);
- await program.addOrReplaceFile('source/stringOps.bs', `
+ program.addOrReplaceFile('source/stringOps.bs', `
import "intOps.bs"
function StringToLower(strVal as string)
return isInt(strVal)
end function
`);
- await program.addOrReplaceFile('source/intOps.bs', `
+ program.addOrReplaceFile('source/intOps.bs', `
function isInt(strVal as dynamic)
return true
end function
`);
- await program.validate();
+ program.validate();
expect(program.getDiagnostics().map(x => x.message)[0]).to.not.exist;
expect(
(component as XmlFile).getAvailableScriptImports().sort()
@@ -109,26 +109,26 @@ describe('import statements', () => {
]);
});
- it('supports importing brs files', async () => {
+ it('supports importing brs files', () => {
//create child component
- let component = await program.addOrReplaceFile('components/ChildScene.xml', trim`
+ let component = program.addOrReplaceFile('components/ChildScene.xml', trim`
`);
- await program.addOrReplaceFile('source/lib.bs', `
+ program.addOrReplaceFile('source/lib.bs', `
import "stringOps.brs"
function toLower(strVal as string)
return StringToLower(strVal)
end function
`);
- await program.addOrReplaceFile('source/stringOps.brs', `
+ program.addOrReplaceFile('source/stringOps.brs', `
function StringToLower(strVal as string)
return lcase(strVal)
end function
`);
- await program.validate();
+ program.validate();
expect(program.getDiagnostics().map(x => x.message)[0]).to.not.exist;
expect(
(component as XmlFile).getAvailableScriptImports()
@@ -138,65 +138,65 @@ describe('import statements', () => {
]);
});
- it('detects when dependency contents have changed', async () => {
+ it('detects when dependency contents have changed', () => {
//create child component
- await program.addOrReplaceFile('components/ChildScene.xml', trim`
+ program.addOrReplaceFile('components/ChildScene.xml', trim`
`);
- await program.addOrReplaceFile('components/lib.bs', `
+ program.addOrReplaceFile('components/lib.bs', `
import "animalActions.bs"
function init1(strVal as string)
Waddle()
end function
`);
//add the empty dependency
- await program.addOrReplaceFile('components/animalActions.bs', ``);
+ program.addOrReplaceFile('components/animalActions.bs', ``);
//there should be an error because that function doesn't exist
- await program.validate();
+ program.validate();
expect(program.getDiagnostics().map(x => x.message)).to.eql([
DiagnosticMessages.callToUnknownFunction('Waddle', s`components/ChildScene.xml`).message
]);
//change the dependency to now contain the file. the scope should re-validate
- await program.addOrReplaceFile('components/animalActions.bs', `
+ program.addOrReplaceFile('components/animalActions.bs', `
sub Waddle()
print "Waddling"
end sub
`);
//validate again
- await program.validate();
+ program.validate();
//the error should be gone
expect(program.getDiagnostics()).to.be.empty;
});
- it('adds brs imports to xml file during transpile', async () => {
+ it('adds brs imports to xml file during transpile', () => {
//create child component
- let component = await program.addOrReplaceFile({ src: s`${rootDir}/components/ChildScene.xml`, dest: 'components/ChildScene.xml' }, trim`
+ let component = program.addOrReplaceFile({ src: s`${rootDir}/components/ChildScene.xml`, dest: 'components/ChildScene.xml' }, trim`
`);
- await program.addOrReplaceFile({ src: s`${rootDir}/source/lib.bs`, dest: 'source/lib.bs' }, `
+ program.addOrReplaceFile({ src: s`${rootDir}/source/lib.bs`, dest: 'source/lib.bs' }, `
import "stringOps.brs"
function toLower(strVal as string)
return StringToLower(strVal)
end function
`);
- await program.addOrReplaceFile({ src: s`${rootDir}/source/stringOps.brs`, dest: 'source/stringOps.brs' }, `
+ program.addOrReplaceFile({ src: s`${rootDir}/source/stringOps.brs`, dest: 'source/stringOps.brs' }, `
function StringToLower(strVal as string)
return isInt(strVal)
end function
`);
- await program.validate();
+ program.validate();
expect(trimMap(component.transpile().code)).to.equal(trim`
@@ -207,36 +207,36 @@ describe('import statements', () => {
`);
});
- it('shows diagnostic for missing file in import', async () => {
+ it('shows diagnostic for missing file in import', () => {
//create child component
- await program.addOrReplaceFile('components/ChildScene.xml', trim`
+ program.addOrReplaceFile('components/ChildScene.xml', trim`
`);
- await program.addOrReplaceFile('components/ChildScene.bs', `
+ program.addOrReplaceFile('components/ChildScene.bs', `
import "stringOps.bs"
sub init()
end sub
`);
- await program.validate();
+ program.validate();
expect(program.getDiagnostics().map(x => x.message)[0]).to.eql(DiagnosticMessages.referencedFileDoesNotExist().message);
});
- it('complicated import graph adds correct script tags', async () => {
- await program.addOrReplaceFile('source/maestro/ioc/IOCMixin.bs', `
+ it('complicated import graph adds correct script tags', () => {
+ program.addOrReplaceFile('source/maestro/ioc/IOCMixin.bs', `
sub DoIocThings()
end sub
`);
- await program.addOrReplaceFile('source/BaseClass.bs', `
+ program.addOrReplaceFile('source/BaseClass.bs', `
import "pkg:/source/maestro/ioc/IOCMixin.bs"
`);
- await program.addOrReplaceFile('components/AuthManager.bs', `
+ program.addOrReplaceFile('components/AuthManager.bs', `
import "pkg:/source/BaseClass.bs"
`);
- await testTranspile(trim`
+ testTranspile(trim`
@@ -252,9 +252,9 @@ describe('import statements', () => {
`, null, 'components/AuthenticationService.xml');
});
- it('handles malformed imports', async () => {
+ it('handles malformed imports', () => {
//shouldn't crash
- const brsFile = await program.addOrReplaceFile('source/SomeFile.bs', `
+ const brsFile = program.addOrReplaceFile('source/SomeFile.bs', `
import ""
import ":"
import ":/"
diff --git a/src/globalCallables.spec.ts b/src/globalCallables.spec.ts
index 3fc4f8e86..094cacb55 100644
--- a/src/globalCallables.spec.ts
+++ b/src/globalCallables.spec.ts
@@ -19,45 +19,45 @@ describe('globalCallables', () => {
});
describe('val', () => {
- it('allows single parameter', async () => {
- await program.addOrReplaceFile('source/main.brs', `
+ it('allows single parameter', () => {
+ program.addOrReplaceFile('source/main.brs', `
sub main()
print val("1001")
end sub
`);
- await program.validate();
+ program.validate();
expect(program.getDiagnostics()[0]?.message).not.to.exist;
});
- it('allows both parameters', async () => {
- await program.addOrReplaceFile('source/main.brs', `
+ it('allows both parameters', () => {
+ program.addOrReplaceFile('source/main.brs', `
sub main()
print val("1001", 10)
end sub
`);
- await program.validate();
+ program.validate();
expect(program.getDiagnostics()[0]?.message).not.to.exist;
});
});
describe('StrI', () => {
- it('allows single parameter', async () => {
- await program.addOrReplaceFile('source/main.brs', `
+ it('allows single parameter', () => {
+ program.addOrReplaceFile('source/main.brs', `
sub main()
print StrI(2)
end sub
`);
- await program.validate();
+ program.validate();
expect(program.getDiagnostics()[0]?.message).not.to.exist;
});
- it('allows both parameters', async () => {
- await program.addOrReplaceFile('source/main.brs', `
+ it('allows both parameters', () => {
+ program.addOrReplaceFile('source/main.brs', `
sub main()
print StrI(2, 10)
end sub
`);
- await program.validate();
+ program.validate();
expect(program.getDiagnostics()[0]?.message).not.to.exist;
});
});
diff --git a/src/interfaces.ts b/src/interfaces.ts
index 53470d79a..5d828d6c7 100644
--- a/src/interfaces.ts
+++ b/src/interfaces.ts
@@ -194,3 +194,5 @@ export interface TypedefProvider {
}
export type TranspileResult = Array<(string | SourceNode)>;
+
+export type FileResolver = (pathAbsolute: string) => string | undefined | Thenable | void;
diff --git a/src/parser/Statement.spec.ts b/src/parser/Statement.spec.ts
index cd0c81859..ab74065bd 100644
--- a/src/parser/Statement.spec.ts
+++ b/src/parser/Statement.spec.ts
@@ -92,8 +92,8 @@ describe('Statement', () => {
describe('ImportStatement', () => {
describe('getTypedef', () => {
- it('changes .bs file extensions to .brs', async () => {
- const file = await program.addOrReplaceFile('source/main.bs', `
+ it('changes .bs file extensions to .brs', () => {
+ const file = program.addOrReplaceFile('source/main.bs', `
import "lib1.bs"
import "pkg:/source/lib2.bs"
`);
diff --git a/src/parser/tests/expression/SourceLiteralExpression.spec.ts b/src/parser/tests/expression/SourceLiteralExpression.spec.ts
index 5d905ea0f..a159a55d6 100644
--- a/src/parser/tests/expression/SourceLiteralExpression.spec.ts
+++ b/src/parser/tests/expression/SourceLiteralExpression.spec.ts
@@ -17,8 +17,8 @@ describe('SourceLiteralExpression', () => {
describe('transpile', () => {
- it('allows bs source literals local vars in brs mode', async () => {
- await testTranspile(`
+ it('allows bs source literals local vars in brs mode', () => {
+ testTranspile(`
sub main()
source_file_path = true
source_line_num = true
@@ -40,8 +40,8 @@ describe('SourceLiteralExpression', () => {
`, undefined, 'none', 'main.brs');
});
- it('computes SOURCE_FILE_PATH', async () => {
- await testTranspile(`
+ it('computes SOURCE_FILE_PATH', () => {
+ testTranspile(`
sub main()
print SOURCE_FILE_PATH
end sub
@@ -52,8 +52,8 @@ describe('SourceLiteralExpression', () => {
`, undefined, 'source/main.bs');
});
- it('computes SOURCE_LINE_NUM', async () => {
- await testTranspile(`
+ it('computes SOURCE_LINE_NUM', () => {
+ testTranspile(`
sub main()
print SOURCE_LINE_NUM
print "hello world"
@@ -68,8 +68,8 @@ describe('SourceLiteralExpression', () => {
`);
});
- it('computes FUNCTION_NAME', async () => {
- await testTranspile(`
+ it('computes FUNCTION_NAME', () => {
+ testTranspile(`
sub main1()
print FUNCTION_NAME
end sub
@@ -88,8 +88,8 @@ describe('SourceLiteralExpression', () => {
`);
});
- it('computes SOURCE_FUNCTION_NAME', async () => {
- await testTranspile(`
+ it('computes SOURCE_FUNCTION_NAME', () => {
+ testTranspile(`
sub main1()
print SOURCE_FUNCTION_NAME
end sub
@@ -108,8 +108,8 @@ describe('SourceLiteralExpression', () => {
`);
});
- it('SOURCE_FUNCTION_NAME computes nested anon', async () => {
- await testTranspile(`
+ it('SOURCE_FUNCTION_NAME computes nested anon', () => {
+ testTranspile(`
namespace NameA
sub main()
speak = sub()
@@ -132,8 +132,8 @@ describe('SourceLiteralExpression', () => {
`);
});
- it('computes SOURCE_LOCATION', async () => {
- await testTranspile(`
+ it('computes SOURCE_LOCATION', () => {
+ testTranspile(`
sub main()
print SOURCE_LOCATION
end sub
@@ -144,8 +144,8 @@ describe('SourceLiteralExpression', () => {
`, undefined, 'source/main.bs');
});
- it('computes PKG_PATH', async () => {
- await testTranspile(`
+ it('computes PKG_PATH', () => {
+ testTranspile(`
sub main()
print PKG_PATH
end sub
@@ -156,8 +156,8 @@ describe('SourceLiteralExpression', () => {
`, undefined, 'source/main.bs');
});
- it('computes PKG_LOCATION', async () => {
- await testTranspile(`
+ it('computes PKG_LOCATION', () => {
+ testTranspile(`
sub main()
print PKG_LOCATION
end sub
@@ -168,21 +168,21 @@ describe('SourceLiteralExpression', () => {
`, undefined, 'source/main.bs');
});
- it('retains LINE_NUM', async () => {
- await testTranspile(`
+ it('retains LINE_NUM', () => {
+ testTranspile(`
sub main()
print LINE_NUM
end sub
`);
});
- it('accounts for sourceRoot in SOURCE_FILE_PATH', async () => {
+ it('accounts for sourceRoot in SOURCE_FILE_PATH', () => {
let sourceRoot = s`${process.cwd()} / sourceRoot`;
program = new Program({
rootDir: rootDir,
sourceRoot: sourceRoot
});
- await testTranspile(`
+ testTranspile(`
sub main()
print SOURCE_FILE_PATH
end sub
@@ -193,13 +193,13 @@ describe('SourceLiteralExpression', () => {
`, undefined, 'source/main.bs');
});
- it('accounts for sourceRoot in SOURCE_LOCATION', async () => {
+ it('accounts for sourceRoot in SOURCE_LOCATION', () => {
let sourceRoot = s`${process.cwd()} / sourceRoot`;
program = new Program({
rootDir: rootDir,
sourceRoot: sourceRoot
});
- await testTranspile(`
+ testTranspile(`
sub main()
print SOURCE_LOCATION
end sub
diff --git a/src/parser/tests/expression/TemplateStringExpression.spec.ts b/src/parser/tests/expression/TemplateStringExpression.spec.ts
index ade84332a..380e17db1 100644
--- a/src/parser/tests/expression/TemplateStringExpression.spec.ts
+++ b/src/parser/tests/expression/TemplateStringExpression.spec.ts
@@ -74,64 +74,64 @@ describe('TemplateStringExpression', () => {
program.dispose();
});
- it('properly transpiles simple template string', async () => {
- await testTranspile(
+ it('properly transpiles simple template string', () => {
+ testTranspile(
'a = `hello world`',
'a = "hello world"'
);
});
- it('properly transpiles one line template string with expressions', async () => {
- await testTranspile(
+ it('properly transpiles one line template string with expressions', () => {
+ testTranspile(
'a = `hello ${a.text} world ${"template" + m.getChars()} test`',
`a = "hello " + bslib_toString(a.text) + " world " + bslib_toString("template" + m.getChars()) + " test"`
);
});
- it('handles escaped characters', async () => {
- await testTranspile(
+ it('handles escaped characters', () => {
+ testTranspile(
'a = `\\r\\n\\`\\$`',
`a = chr(13) + chr(10) + chr(96) + chr(36)`
);
});
- it('handles escaped unicode char codes', async () => {
- await testTranspile(
+ it('handles escaped unicode char codes', () => {
+ testTranspile(
'a = `\\c2\\c987`',
`a = chr(2) + chr(987)`
);
});
- it('properly transpiles simple multiline template string', async () => {
- await testTranspile(
+ it('properly transpiles simple multiline template string', () => {
+ testTranspile(
'a = `hello world\nI am multiline`',
'a = "hello world" + chr(10) + "I am multiline"'
);
});
- it('properly handles newlines', async () => {
- await testTranspile(
+ it('properly handles newlines', () => {
+ testTranspile(
'a = `\n`',
'a = chr(10)'
);
});
- it('properly handles clrf', async () => {
- await testTranspile(
+ it('properly handles clrf', () => {
+ testTranspile(
'a = `\r\n`',
'a = chr(13) + chr(10)'
);
});
- it('properly transpiles more complex multiline template string', async () => {
- await testTranspile(
+ it('properly transpiles more complex multiline template string', () => {
+ testTranspile(
'a = `I am multiline\n${a.isRunning()}\nmore`',
'a = "I am multiline" + chr(10) + bslib_toString(a.isRunning()) + chr(10) + "more"'
);
});
- it('properly transpiles complex multiline template string in array def', async () => {
- await testTranspile(
+ it('properly transpiles complex multiline template string in array def', () => {
+ testTranspile(
`a = [
"one",
"two",
@@ -150,8 +150,8 @@ describe('TemplateStringExpression', () => {
`);
});
- it('properly transpiles complex multiline template string in array def, with nested template', async () => {
- await testTranspile(`
+ it('properly transpiles complex multiline template string in array def, with nested template', () => {
+ testTranspile(`
a = [
"one",
"two",
@@ -176,8 +176,8 @@ describe('TemplateStringExpression', () => {
`);
});
- it('skips calling toString on strings', async () => {
- await testTranspile(`
+ it('skips calling toString on strings', () => {
+ testTranspile(`
text = \`Hello \${"world"}\`
`, `
text = "Hello " + "world"
@@ -185,8 +185,8 @@ describe('TemplateStringExpression', () => {
});
describe('tagged template strings', () => {
- it('properly transpiles with escaped characters and quasis', async () => {
- await testTranspile(`
+ it('properly transpiles with escaped characters and quasis', () => {
+ testTranspile(`
function zombify(strings, values)
end function
sub main()
@@ -202,8 +202,8 @@ describe('TemplateStringExpression', () => {
`);
});
- it('handles multiple embedded expressions', async () => {
- await testTranspile(`
+ it('handles multiple embedded expressions', () => {
+ testTranspile(`
function zombify(strings, values)
end function
sub main()
diff --git a/src/preprocessor/Manifest.spec.ts b/src/preprocessor/Manifest.spec.ts
index 553598100..f127fb95d 100644
--- a/src/preprocessor/Manifest.spec.ts
+++ b/src/preprocessor/Manifest.spec.ts
@@ -13,7 +13,7 @@
// });
// describe('manifest parser', () => {
-// it.only('returns an empty map if manifest not found', async () => {
+// it('returns an empty map if manifest not found', async () => {
// // sinon.stub(fsExtra, 'readFile').returns(
// // Promise.reject(
// // new Error('File not found')
diff --git a/src/util.spec.ts b/src/util.spec.ts
index b0465fd26..7eb25d425 100644
--- a/src/util.spec.ts
+++ b/src/util.spec.ts
@@ -26,7 +26,7 @@ describe('util', () => {
describe('fileExists', () => {
it('returns false when no value is passed', async () => {
- expect(await util.fileExists(undefined)).to.be.false;
+ expect(await util.pathExists(undefined)).to.be.false;
});
});
diff --git a/src/util.ts b/src/util.ts
index 518826159..317ebadcb 100644
--- a/src/util.ts
+++ b/src/util.ts
@@ -9,7 +9,7 @@ import { URI } from 'vscode-uri';
import * as xml2js from 'xml2js';
import type { BsConfig } from './BsConfig';
import { DiagnosticMessages } from './DiagnosticMessages';
-import type { CallableContainer, BsDiagnostic, FileReference, CallableContainerMap, CompilerPluginFactory } from './interfaces';
+import type { CallableContainer, BsDiagnostic, FileReference, CallableContainerMap, CompilerPluginFactory, CompilerPlugin } from './interfaces';
import { BooleanType } from './types/BooleanType';
import { DoubleType } from './types/DoubleType';
import { DynamicType } from './types/DynamicType';
@@ -26,12 +26,10 @@ import type { DottedGetExpression, VariableExpression } from './parser/Expressio
import { Logger, LogLevel } from './Logger';
import type { Token } from './lexer';
import { TokenKind } from './lexer';
-import type { CompilerPlugin } from '.';
import { isBrsFile, isDottedGetExpression, isVariableExpression } from './astUtils';
import { CustomType } from './types/CustomType';
export class Util {
-
public clearConsole() {
// process.stdout.write('\x1Bc');
}
@@ -40,7 +38,7 @@ export class Util {
* Determine if the file exists
* @param filePath
*/
- public async fileExists(filePath: string | undefined) {
+ public async pathExists(filePath: string | undefined) {
if (!filePath) {
return false;
} else {
@@ -49,20 +47,22 @@ export class Util {
}
/**
- * Determine if this path is a directory
+ * Determine if the file exists
+ * @param filePath
*/
- public isDirectorySync(dirPath: string | undefined) {
- return fs.existsSync(dirPath) && fs.lstatSync(dirPath).isDirectory();
+ public pathExistsSync(filePath: string | undefined) {
+ if (!filePath) {
+ return false;
+ } else {
+ return fsExtra.pathExistsSync(filePath);
+ }
}
/**
- * Load a file from disc into a string
- * @param filePath
+ * Determine if this path is a directory
*/
- public async getFileContents(filePath: string) {
- let file = await fsExtra.readFile(filePath);
- let fileContents = file.toString();
- return fileContents;
+ public isDirectorySync(dirPath: string | undefined) {
+ return fs.existsSync(dirPath) && fs.lstatSync(dirPath).isDirectory();
}
/**
@@ -95,7 +95,7 @@ export class Util {
let configPath = path.join(cwd, 'bsconfig.json');
//find the nearest config file path
for (let i = 0; i < 100; i++) {
- if (await this.fileExists(configPath)) {
+ if (await this.pathExists(configPath)) {
return configPath;
} else {
let parentDirPath = path.dirname(path.dirname(configPath));
@@ -149,7 +149,7 @@ export class Util {
throw new Error('Circular dependency detected: "' + parentProjectPaths.join('" => ') + '"');
}
//load the project file
- let projectFileContents = await this.getFileContents(configFilePath);
+ let projectFileContents = (await fsExtra.readFile(configFilePath)).toString();
let parseErrors = [] as ParseError[];
let projectConfig = parseJsonc(projectFileContents, parseErrors) as BsConfig;
if (parseErrors.length > 0) {
@@ -752,9 +752,9 @@ export class Util {
let bsPath = path.join(currentPath, 'bsconfig.json');
let brsPath = path.join(currentPath, 'brsconfig.json');
- if (await this.fileExists(bsPath)) {
+ if (await this.pathExists(bsPath)) {
return bsPath;
- } else if (await this.fileExists(brsPath)) {
+ } else if (await this.pathExists(brsPath)) {
return brsPath;
} else {
//walk upwards one directory
@@ -1130,6 +1130,5 @@ export function standardizePath(stringParts, ...expressions: any[]) {
);
}
-
export let util = new Util();
export default util;