But otherwise I don't get the syntax highlighting on my editor if I put it is a string. In addition, I am staying away from setfenv - It's deprecated
You can either do this correctly and have it work, or have syntax highlighting. There are a couple of solutions to this.
I didn't use loadfile this time - It was a function called getfile. But I wanted to wrap import because I need to be able to change the class table later on with a different one, and I don't want to pass the string between multiple function calls
Both of the following solutions do not require you to pass a string between multiple function calls, all they require is a extra variable or file.
Solution 1
Create a local string variable in your program something like importString and change the "import = load(string.dump(import), OSName..":Importer", "t", menv)" to "import = load(importString, OSName..":Importer", "t", menv)" you would also want to define import as a local variable whenever you define importString.
Solution 2
Copy the function into a another file and read all of the files contents in and treat what you read in as importString from solution 1.
Either way string.dump is not intended to be used how you are using it, and deciding that you won't do it the correct way because you want syntax highlighting is just bad practice.