Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to coffeescript 1.3.3 #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# JCoffeeScript

JCoffeeScript is a java library that compiles CoffeeScript 1.1.
JCoffeeScript is a java library that compiles CoffeeScript 1.3.3.

### Usage
from the command prompt:
> echo "a = 1" | java -jar jcoffeescript-1.1.jar
> echo "a = 1" | java -jar jcoffeescript-1.3.3.jar
<pre>
(function() {
var a;
Expand All @@ -13,7 +13,7 @@ from the command prompt:
</pre>

####Command Line (unix/windows):
> java -jar jcoffeescript-1.1.jar < foo.coffee > foo.js
> java -jar jcoffeescript-1.3.3.jar < foo.coffee > foo.js

####command line options:
> __--bare__ - compile the javascript without top-level function safety wrapper.
Expand Down
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<target name="build" depends="bootstrap, clean, functional-test"/>

<property name="artifact.name" value="jcoffeescript-1.1"/>
<property name="artifact.name" value="jcoffeescript-1.3.3"/>
<import file="${basedir}/conf/build/build-bootstrap.xml"/>
<import file="${basedir}/conf/build/build-clean.xml"/>
<import file="${basedir}/conf/build/build-compile.xml"/>
Expand Down
17 changes: 3 additions & 14 deletions src/main/java/org/jcoffeescript/JCoffeeScriptCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,12 @@
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.util.Collection;
import java.util.Collections;

public class JCoffeeScriptCompiler {

private final Scriptable globalScope;
private final Options options;

public JCoffeeScriptCompiler() {
this(Collections.<Option>emptyList());
}

public JCoffeeScriptCompiler(Collection<Option> options) {
public JCoffeeScriptCompiler() {
ClassLoader classLoader = getClass().getClassLoader();
InputStream inputStream = classLoader.getResourceAsStream("org/jcoffeescript/coffee-script.js");
try {
Expand All @@ -63,18 +56,16 @@ public JCoffeeScriptCompiler(Collection<Option> options) {
} catch (IOException e) {
throw new Error(e); // This should never happen
}

this.options = new Options(options);
}

public String compile (String coffeeScriptSource) throws JCoffeeScriptCompileException {
public String compile (String coffeeScriptSource, Boolean bare) throws JCoffeeScriptCompileException {
Context context = Context.enter();
try {
Scriptable compileScope = context.newObject(globalScope);
compileScope.setParentScope(globalScope);
compileScope.put("coffeeScriptSource", compileScope, coffeeScriptSource);
try {
return (String)context.evaluateString(compileScope, String.format("CoffeeScript.compile(coffeeScriptSource, %s);", options.toJavaScript()),
return (String)context.evaluateString(compileScope, String.format("CoffeeScript.compile(coffeeScriptSource, {bare: %b});", bare),
"JCoffeeScriptCompiler", 0, null);
} catch (JavaScriptException e) {
throw new JCoffeeScriptCompileException(e);
Expand All @@ -83,6 +74,4 @@ public String compile (String coffeeScriptSource) throws JCoffeeScriptCompileExc
Context.exit();
}
}


}
15 changes: 4 additions & 11 deletions src/main/java/org/jcoffeescript/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.Collection;
import java.util.LinkedList;

public class Main {
private static final int BUFFER_SIZE = 262144;
Expand All @@ -32,9 +30,9 @@ public static void main(String[] args) {
}

public void execute(String[] args, PrintStream out, InputStream in) {
final Collection<Option> options = readOptionsFrom(args);
final Boolean bare = readIsBareFrom(args);
try {
out.print(new JCoffeeScriptCompiler(options).compile(readSourceFrom(in)));
out.print(new JCoffeeScriptCompiler().compile(readSourceFrom(in), bare));
} catch (JCoffeeScriptCompileException e) {
System.err.println(e.getMessage());
}
Expand All @@ -60,12 +58,7 @@ private String readSourceFrom(InputStream inputStream) {
}
}

private Collection<Option> readOptionsFrom(String[] args) {
final Collection<Option> options = new LinkedList<Option>();

if (args.length == 1 && args[0].equals("--bare")) {
options.add(Option.BARE);
}
return options;
private boolean readIsBareFrom(String[] args) {
return args.length == 1 && args[0].equals("--bare");
}
}
21 changes: 0 additions & 21 deletions src/main/java/org/jcoffeescript/Option.java

This file was deleted.

31 changes: 0 additions & 31 deletions src/main/java/org/jcoffeescript/Options.java

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/resources/org/jcoffeescript/coffee-script.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/main/ruby/compile.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
require 'java'
puts org.jcoffeescript.JCoffeeScriptCompiler.new.compile(ARGV[0])
puts org.jcoffeescript.JCoffeeScriptCompiler.new.compile(ARGV[0], false)
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class CoffeeScriptCompilerTest {
@Test
public void shouldCompileWithDefaultOptions() throws JCoffeeScriptCompileException {
assertThat(compiling("a = 1"),
assertThat(compiling("a = 1", false),
allOf(
containsString("a = 1"),
containsFunctionWrapper()
Expand All @@ -37,14 +37,14 @@ public void shouldCompileWithDefaultOptions() throws JCoffeeScriptCompileExcepti

@Test
public void shouldCompileWithoutFunctionWrapper() throws JCoffeeScriptCompileException {
assertThat(compiling("a = 1", Option.BARE), not(containsFunctionWrapper()));
assertThat(compiling("a = 1", true), not(containsFunctionWrapper()));
}

private Matcher<String> containsFunctionWrapper() {
return allOf(startsWith("(function() {\n"), endsWith("\n}).call(this);\n"));
}

private String compiling(String coffeeScriptSource, Option... options) throws JCoffeeScriptCompileException {
return new JCoffeeScriptCompiler(Arrays.asList(options)).compile(coffeeScriptSource);
private String compiling(String coffeeScriptSource, Boolean bare) throws JCoffeeScriptCompileException {
return new JCoffeeScriptCompiler().compile(coffeeScriptSource, bare);
}
}