From a307d8e76fb899fff6a6167f122136a9c3f73ad5 Mon Sep 17 00:00:00 2001 From: Andrew Ashbacher Date: Sat, 5 Aug 2023 06:50:51 -0700 Subject: [PATCH] ensure consistent insertion of bslib.brs (#870) * ensure consistent insertion of bslib.brs * Fix lint issues, add unit test --------- Co-authored-by: Bronley Plumb --- src/Program.spec.ts | 32 +++++++++++++++++++++++++++++++- src/Program.ts | 3 +++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/Program.spec.ts b/src/Program.spec.ts index c8f231171..4f1c54848 100644 --- a/src/Program.spec.ts +++ b/src/Program.spec.ts @@ -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() diff --git a/src/Program.ts b/src/Program.ts index aed961fd4..6cad08a06 100644 --- a/src/Program.ts +++ b/src/Program.ts @@ -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();