google/traceur-compiler — pull request #250 by usrbincc (2013-04-08 19:13:44+00:00)
Title: Implement 'inlineAndCompileSync'.

- Add 'loadSync' and 'loadTextFileSync' methods to InternalLoader.

----

With this current code, I was able to build traceur synchronously. Because of the self-hosting thing, it's slightly tricky, though:

```bash
sh <<"END_"

# build a traceur with sync functionality.
make boot

# modify to use 'inlineAndCompileSync'.
sed \
-e '/var inlineAndCompile/i\
// BEGIN_DELETE\
var inlineAndCompileSync =\
require("./inline-module.js").inlineAndCompileSync;\
// END_DELETE' \
-e '/inlineAndCompile(resolvedIncludes/i\
// BEGIN_DELETE\
return writeTreeToFile(\
inlineAndCompileSync(resolvedIncludes, {}, reporter),\
resolvedOutputFile, useSourceMaps);\
// END_DELETE' \
-i src/node/compiler.js

# build using inlineAndCompileSync
make force

# remove our test code.
sed '/BEGIN_DELETE/,/END_DELETE/d' -i src/node/compiler.js
END_
```

There are a few different ways I could have organized the code. For example, having sync loading functionality in an `SyncInternalLoader` (`InternalSyncLoader`? `InternalLoaderSync`?) subclass. In that case, I wouldn't have had to add the `*Sync` methods.

I haven't done any tests at all of `inlineAndCompileSync` with the synchronous xhr backend, but `loadTextFileSync` itself works from adhoc in-browser tests. I don't really use xhr much, so this code is probably suboptimal.

----

Is this sufficient to hook into `require`, or is there something else that needs to be synchronous?