use of com.github.anba.es6draft.compiler.CompiledFunction in project es6draft by anba.
the class NodeModuleRecord method ParseModule.
/**
* ParseModule ( sourceText )
*
* @param scriptLoader
* the script loader
* @param identifier
* the source code identifier
* @param moduleSource
* the module source code
* @return the parsed module record
* @throws IOException
* if there was any I/O error
* @throws ParserException
* if the module source contains any syntax errors
* @throws CompilationException
* if the parsed module source cannot be compiled
*/
public static NodeModuleRecord ParseModule(ScriptLoader scriptLoader, SourceIdentifier identifier, ModuleSource moduleSource) throws IOException, ParserException, CompilationException {
Source source = moduleSource.toSource();
String sourceCode = moduleSource.sourceCode();
if (identifier.toUri().toString().endsWith(".json")) {
String jsonScript = JSONParser.parse(sourceCode, new ScriptJSONBuilder());
sourceCode = String.format("module.exports = %s", jsonScript);
}
String parameters = "exports, require, module, __filename, __dirname";
CompiledFunction function = scriptLoader.function(source, parameters, sourceCode);
return new NodeModuleRecord(identifier, source, function);
}
Aggregations