Permalink
Browse files

last 0.2.2 tests, some fix, gradle config clean

  • Loading branch information...
1 parent 935fcb2 commit 62b753579ab66639ce0e4b1e0cb7845e683272b9 @chiquitinxx committed Feb 23, 2013
View
@@ -1,39 +1,16 @@
GrooScript 0.2.2
================
-Converts your Groovy code to JavaScript(Groovy 2.0 to Javascript ECMAScript 5).
+Converts your Groovy code to JavaScript(Groovy 2.x to Javascript ECMAScript 5).
Not a full groovy to javascript conversion. Better groovy support means lost pretty print in javascript conversion.
Converted code, needs grooscript.js to run. grooscript.js inside the jar in META-INF/resources for servlet 3.0 support.
-No dependencies, Gradle as build system. In sonar maven repository:
-
-https://oss.sonatype.org/content/groups/public/
-
-org.grooscript:grooscript:0.2.2
+Only GPars 1.0 dependencies in the project, Gradle as build system.
Please all feedback welcome, thanks!
-Missing some Groovy / Java stuff:
----------------------------------
-
-Basic inheritance, can do super() only in constructors.
-
-Types not supported, can't casting, missing lot of java types.
-
-Only can access class names and instanceof of created classes with a conversion option.
-
-Not allowed same number of parameters in methods / constructors.
-
-Can add methods and properties with metaclass, but some problems with primitive types as String and Number.
-
-No delegate. No ExpandoMetaClass. No libraries out of groovy-core.
-
-Groovy ast transformations as @Cannonical, @ToString, ... not supported.
-
-Variable assignment not allowed inside boolean expressions as ternary (?:).
-
---
Twitter: @jfrancoleza
View
@@ -3,7 +3,6 @@ apply plugin: 'groovy'
apply plugin: 'maven'
apply plugin: 'signing'
-//name = 'grooscript'
group = 'org.grooscript'
version = '0.2.2'
@@ -14,22 +13,12 @@ sourceCompatibility = 1.7
def appName = 'GrooScript'
def webDir = '../grooscript_web'
def webDirJar = "$webDir/lib"
-def webDirExamples = "$webDir/scripts/examples/"
def webDirJs = "$webDir/web-app/js/"
def demoDir = '../monkfish'
def demoDirJar = "$demoDir/lib"
def demoDirJs = "$demoDir/web-app/js/"
-def examplesDir = 'src/test/resources/'
-def webExamples = [:]
-webExamples.putAt 'MysticTable',"${examplesDir}advanced/MysticTable.groovy"
-webExamples.putAt 'ExpandoTree',"${examplesDir}advanced/Tree.groovy"
-webExamples.putAt 'Random',"${examplesDir}advanced/RandomWorld.groovy"
-webExamples.putAt 'MethodMissing',"${examplesDir}advanced/MethodMissing.groovy"
-webExamples.putAt 'SortingLists',"${examplesDir}advanced/Sorting.groovy"
-webExamples.putAt 'Strings',"${examplesDir}advanced/StringSecrets.groovy"
-
repositories {
mavenCentral()
//maven {
@@ -38,15 +27,13 @@ repositories {
}
dependencies {
- compile group: 'org.codehaus.groovy', name: 'groovy', version: '2.0.7'
+ compile group: 'org.codehaus.groovy', name: 'groovy', version: '2.1.1'
compile group: 'org.codehaus.gpars', name: 'gpars', version: '1.0.0'
- //groovy group: 'org.codehaus.groovy', name: 'groovy', version: '2.0.6'
testCompile 'org.spockframework:spock-core:0.7-groovy-2.0'
- //testCompile fileTree(dir: 'lib', include: '*.jar')
}
//Sonar repository stuff
-
+/*
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from 'build/docs/javadoc'
@@ -106,6 +93,7 @@ uploadArchives {
}
}
}
+*/
//End Sonar
//Copy jar, js file, and examples to web directory, defined at start
@@ -129,16 +117,6 @@ task copyToGscriptWeb(dependsOn: build) << {
}
- println "Copying $appName examples to $webDirExamples ..."
- webExamples.each { key, value ->
- copy {
- into "$webDirExamples"
- from "$value"
- rename {
- return "${key}.groovy"
- }
- }
- }
}
//Copy jar and js file to Demo
@@ -159,5 +137,4 @@ task copyToDemo(dependsOn: build) << {
from "src/main/resources/META-INF/resources"
include "grooscript.js"
}
-
}
@@ -994,11 +994,29 @@ class GsConverter {
addScript(')')
}
+ def private handExpressionInBoolean(expression) {
+ if (expression instanceof VariableExpression || expression instanceof PropertyExpression ||
+ (expression instanceof NotExpression &&
+ expression.expression &&
+ (expression.expression instanceof VariableExpression || expression.expression instanceof PropertyExpression))) {
+ if (expression instanceof NotExpression) {
+ addScript('!gSbool(')
+ "process${expression.expression.class.simpleName}"(expression.expression)
+ } else {
+ addScript('gSbool(')
+ "process${expression.class.simpleName}"(expression)
+ }
+ addScript(')')
+ } else {
+ "process${expression.class.simpleName}"(expression)
+ }
+ }
+
def private processBooleanExpression(BooleanExpression expression) {
//println 'BooleanExpression->'+expression
//println 'BooleanExpression Inside->'+expression.expression
- //Groovy truth is a bit different, empty collections return false, we fix that here
+ /*
if (expression.expression instanceof VariableExpression || expression.expression instanceof PropertyExpression ||
(expression.expression instanceof NotExpression &&
expression.expression.expression &&
@@ -1013,7 +1031,10 @@ class GsConverter {
addScript(')')
} else {
"process${expression.expression.class.simpleName}"(expression.expression)
- }
+ }*/
+
+ //Groovy truth is a bit different, empty collections return false, we fix that here
+ handExpressionInBoolean(expression.expression)
}
def private processExpressionStatement(ExpressionStatement statement) {
@@ -1245,14 +1266,28 @@ class GsConverter {
!variableScopingContains(expression.leftExpression.name)) {
addToActualScope(expression.leftExpression.name)
}
+
+ //If is a boolean operation, we have to apply groovyTruth
//Left
- upgradedExpresion(expression.leftExpression)
+ if (expression.operation.text in ['&&','||']) {
+ addScript '('
+ handExpressionInBoolean(expression.leftExpression)
+ addScript ')'
+ } else {
+ upgradedExpresion(expression.leftExpression)
+ }
//Operator
//println 'Operator->'+expression.operation.text
addScript(' '+expression.operation.text+' ')
//Right
//println 'Right->'+expression.rightExpression
- upgradedExpresion(expression.rightExpression)
+ if (expression.operation.text in ['&&','||']) {
+ addScript '('
+ handExpressionInBoolean(expression.rightExpression)
+ addScript ')'
+ } else {
+ upgradedExpresion(expression.rightExpression)
+ }
if (expression.operation.text=='[') {
addScript(']')
}
@@ -85,7 +85,7 @@ class ConversionDaemon {
final def exit = new DataflowVariable()
def listConverteds = []
- final op = operator(inputs: [works], outputs: [exit], maxForks: 4) { absolutePath ->
+ final op = operator(inputs: [works], outputs: [exit], maxForks: 3) { absolutePath ->
try {
convertFile(absolutePath)
@@ -2083,44 +2083,49 @@ function gSmethodCall(item,methodName,values) {
return item();
} else {
- if (item['methodMissing']) {
- return item['methodMissing'](methodName,values);
- } else {
- //Lets check if in any category we have the static method
- if (gScategories.length > 0) {
- var whereExecutes = gScategorySearching(methodName);
- if (whereExecutes!=null) {
- return whereExecutes[methodName].apply(item,gSjoinParameters(item,values));
- }
+ //Lets check if in any category we have the static method
+ if (gScategories.length > 0) {
+ var whereExecutes = gScategorySearching(methodName);
+ if (whereExecutes!=null) {
+ return whereExecutes[methodName].apply(item,gSjoinParameters(item,values));
}
- //Lets check in mixins classes
- if (gSmixins.length>0) {
- var whereExecutes = gSmixinSearching(item,methodName);
- if (whereExecutes!=null) {
- //console.log('Where!'+whereExecutes[methodName]+' - '+item);
- return whereExecutes[methodName].apply(item,gSjoinParameters(item,values));
- }
+ }
+ //Lets check in mixins classes
+ if (gSmixins.length>0) {
+ var whereExecutes = gSmixinSearching(item,methodName);
+ if (whereExecutes!=null) {
+ //console.log('Where!'+whereExecutes[methodName]+' - '+item);
+ return whereExecutes[methodName].apply(item,gSjoinParameters(item,values));
}
- //Lets check in mixins objects
- if (gSmixinsObjects.length>0) {
- var whereExecutes = gSmixinObjectsSearching(item,methodName);
- if (whereExecutes!=null) {
- //console.log('Where!'+whereExecutes[methodName]+' - '+item);
- return whereExecutes[methodName].apply(item,gSjoinParameters(item,values));
- }
+ }
+ //Lets check in mixins objects
+ if (gSmixinsObjects.length>0) {
+ var whereExecutes = gSmixinObjectsSearching(item,methodName);
+ if (whereExecutes!=null) {
+ //console.log('Where!'+whereExecutes[methodName]+' - '+item);
+ return whereExecutes[methodName].apply(item,gSjoinParameters(item,values));
}
+ }
+
+ //Lets check in delegate
+ if (gSactualDelegate!=null && gSactualDelegate[methodName]!=undefined) {
+ return gSactualDelegate[methodName].apply(item,values);
+ }
+ if (gSactualDelegate!=null && item['methodMissing']==undefined
+ && gSactualDelegate['methodMissing']!=undefined) {
+ return gSmethodCall(gSactualDelegate,methodName,values);
+ }
+
+ if (item['methodMissing']) {
+
+ return item['methodMissing'](methodName,values);
+
+ } else {
//Maybe there is a function in the script with the name of the method
//In Node.js 'this.xxFunction()' in the main context fails
- /*
if (typeof eval(methodName)==='function') {
return eval(methodName).apply(this,values);
- }*/
-
- //Lets check in delegate
- if (gSactualDelegate!=null &&
- (gSactualDelegate[methodName]!=undefined || gSactualDelegate['methodMissing']!=undefined)) {
- return gSmethodCall(gSactualDelegate,methodName,values);
}
//Not exist the method, throw exception
@@ -292,4 +292,14 @@ class TestAdvanced extends Specification {
}
+ def 'multiple conditions'() {
+ when:
+ def result = readAndConvert('advanced/MultipleConditions',false)
+
+ then:
+ //println 'Console->'+result.gSconsole
+ !result.assertFails
+
+ }
+
}
@@ -47,6 +47,12 @@ def result = Tests.doTest()
assert result.size() == 2
assert result.findAll { it.fail == true}.size() == 1
+class Components {
+ def static salute(String who) {
+ return "Hello ${who}!"
+ }
+}
+
class LittleDsl {
@@ -65,7 +71,7 @@ class LittleDsl {
def methodMissing(String name,args) {
text << "<${name}>"
- if (args.last() instanceof Closure) {
+ if (args && args.last() instanceof Closure) {
def clo = args.last()
//clo.delegate = this
clo()
@@ -84,9 +90,16 @@ def text = LittleDsl.build {
li { add "(${i++}) Name: ${item.name} Fail:${item.fail}"}
}
}
+ use (Components) {
+ p { add "Jorge".salute()}
+ }
}
}
-assert text == '<ul><li>(0) Name: failTest Fail:true</li><li>(1) Name: okTest Fail:false</li></ul>'
+assert text == '<ul><li>(0) Name: failTest Fail:true</li><li>(1) Name: okTest Fail:false</li></ul><p>Hello Jorge!</p>'
+
+def name = "Groovy"
+name.metaClass.mixin Components
+assert name.salute() == "Hello Groovy!"
@@ -0,0 +1,15 @@
+package advanced
+
+/**
+ * User: jorgefrancoleza
+ * Date: 22/02/13
+ */
+
+def list = []
+def doIt = false
+
+if (list && !doIt && 5==5) {
+ doIt = true
+}
+
+assert !doIt

0 comments on commit 62b7535

Please sign in to comment.