Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/Program.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,27 @@ describe('Program', () => {
}
expect(error?.message).to.eql('Crash for test');
});

it('includes files added during beforeProgramValidate in validation', () => {
program.setFile('source/a.brs', `
sub a()
b()
end sub
`);

program.plugins.add({
name: 'add file in beforeProgramValidate',
beforeProgramValidate: () => {
program.setFile('source/b.brs', `
sub b()
end sub
`);
}
});

program.validate();
expectZeroDiagnostics(program);
});
});

describe('hasFile', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/Program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ export class Program {
this.plugins.emit('beforeProgramValidate', this);
beforeProgramValidateWasEmitted = true;
})
.forEach(Object.values(this.files), (file) => {
.forEach(() => Object.values(this.files), (file) => {
if (!file.isValidated) {
this.plugins.emit('beforeFileValidate', {
program: this,
Expand Down
26 changes: 19 additions & 7 deletions src/common/Sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,25 @@ export class Sequencer {
// eslint-disable-next-line @typescript-eslint/ban-types
private actions: Array<{ args: any[]; func: Function }> = [];

public forEach<T>(items: T[], func: (item: T) => any) {
for (const item of items) {
this.actions.push({
args: [item],
func: func
});
}
public forEach<T>(itemsOrFactory: Iterable<T> | (() => Iterable<T>), func: (item: T) => any) {
//register a single action for now, we will fetch the full list and register their actions later
const primaryAction = {
args: [],
func: (data) => {
const items = typeof itemsOrFactory === 'function' ? itemsOrFactory() : itemsOrFactory;
const actions: Sequencer['actions'] = [];
for (const item of items) {
actions.push({
args: [item],
func: func
});
}
let primaryActionIndex = this.actions.indexOf(primaryAction);
//insert all of these item actions immediately after this action
this.actions.splice(primaryActionIndex + 1, 0, ...actions);
}
};
this.actions.push(primaryAction);
return this;
}

Expand Down