Skip to content

Commit

Permalink
add rhino compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed Dec 29, 2017
1 parent 2673840 commit 8e2edd2
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions processor/src/main/java/org/bsc/processor/TypescriptProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,20 @@ public class TypescriptProcessor extends AbstractProcessorEx {
* @param w
* @param t
*/
private void addDeclaration( java.io.Writer w, TSType t ) {
private void addDeclaration( java.io.Writer w, TSType t, boolean isRhinoCompatible ) {
if( !t.isExport() ) return;

Class<?> type = t.valueAsClass();

info( "export type [%s]", t.getValue() );

try {
w.append( String.format( "exports.%s\t=\tJava.type( \"%s\" );\n", type.getSimpleName(), type.getName()));
if( isRhinoCompatible ) {
w.append( String.format( "exports.%s\t\t=\t%s;\n", type.getSimpleName(), type.getName()));
}
else {
w.append( String.format( "exports.%s\t\t=\tJava.type( \"%s\" );\n", type.getSimpleName(), type.getName()));
}
} catch (IOException e) {
error( "error adding [%s]", t.getValue());
}
Expand All @@ -112,6 +117,8 @@ private void addDeclaration( java.io.Writer w, TSType t ) {
public boolean process( Context processingContext ) throws Exception {

final String targetDefinitionFile = processingContext.getOptionMap().getOrDefault("ts.outfile", "out");
final String compatibility = processingContext.getOptionMap().getOrDefault("compatibility", "nashorn");


final FileObject outD = super.getSourceOutputFile( Paths.get("ts"), Paths.get(targetDefinitionFile.concat(".d.ts")));
final FileObject outT = super.getSourceOutputFile( Paths.get("ts"), Paths.get(targetDefinitionFile.concat(".ts")));
Expand All @@ -131,7 +138,7 @@ public boolean process( Context processingContext ) throws Exception {


final List<Class<?>> classes = types.stream()
.peek( t -> addDeclaration(wT, t) )
.peek( t -> addDeclaration(wT, t, compatibility.equalsIgnoreCase("rhino")) )
.map( t -> t.valueAsClass() )
.collect( Collectors.toList());

Expand Down

0 comments on commit 8e2edd2

Please sign in to comment.