Skip to content

Commit

Permalink
ensure consistent insertion of bslib.brs (#870)
Browse files Browse the repository at this point in the history
* ensure consistent insertion of bslib.brs

* Fix lint issues, add unit test

---------

Co-authored-by: Bronley Plumb <bronley@gmail.com>
  • Loading branch information
enthooz and TwitchBronBron committed Aug 5, 2023
1 parent 47229eb commit a307d8e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/Program.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1843,8 +1843,38 @@ describe('Program', () => {
});
});

describe('transpile', () => {
it('beforeProgramTranspile sends entries in alphabetical order', () => {
program.setFile('source/main.bs', trim`
sub main()
print "hello world"
end sub
`);

program.setFile('source/common.bs', trim`
sub getString()
return "test"
end sub
`);

//send the files out of order
const result = program['beforeProgramTranspile']([{
src: s`${rootDir}/source/main.bs`,
dest: 'source/main.bs'
}, {
src: s`${rootDir}/source/main.bs`,
dest: 'source/main.bs'
}], program.options.stagingDir);

//entries should now be in alphabetic order
expect(
result.entries.map(x => x.outputPath)
).to.eql([
s`${stagingDir}/source/common.brs`,
s`${stagingDir}/source/main.brs`
]);
});

describe('transpile', () => {
it('detects and transpiles files added between beforeProgramTranspile and afterProgramTranspile', async () => {
program.setFile('source/main.bs', trim`
sub main()
Expand Down
3 changes: 3 additions & 0 deletions src/Program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,9 @@ export class Program {
file: file,
outputPath: getOutputPath(file)
};
//sort the entries to make transpiling more deterministic
}).sort((a, b) => {
return a.file.srcPath < b.file.srcPath ? -1 : 1;
});

const astEditor = new AstEditor();
Expand Down

0 comments on commit a307d8e

Please sign in to comment.