jsweet icon indicating copy to clipboard operation
jsweet copied to clipboard

Error With BigDecimal Support

Open pbtura opened this issue 6 years ago • 9 comments

I'm trying to add support for java BigNumber types to my jsweet project. I followed the instructions here: extension examples. I added a dependency to the bigjs candy in my pom.xml and added a line "adapters": [ "org.jsweet.transpiler.extension.BigDecimalAdapter" ] to my jsweetconfig.js file. After running the maven command, all the files generated as expected and the BigDecimal fields in java were converted into 'Big' types in the resulting .ts

The problem is, the compiler doesn't seem to know about the 'Big' type. Every line that uses that type results in the error Cannot find name 'Big'. Looking again at the example it says This extension requires the big.js candy to be available in the JSweet classpath. I thought I had done that by adding the candy to the maven dependencies. Is there another step somewhere I'm missing?

pbtura avatar Feb 07 '18 17:02 pbtura

Yes, adding the Big.js candy should be enough. Could you turn on the verbose mode and provide the error trace?

renaudpawlak avatar Feb 11 '18 07:02 renaudpawlak

I have verbose mode on. There are no errors when I run the maven command. The issues show up when I actually try to compile my project with the generated files that jsweet creates. The compiler error is: error TS2304: Cannot find name 'Big'

pbtura avatar Feb 12 '18 15:02 pbtura

Well, then it means that you don't have the big.d.ts accessible for some reason. Not sure why. Are you compiling with TypeScript separately or is it JSweet that runs the TypeScript compilation? In any case, try to find the big.js definitions in your project and figure out why they are not seen by TypeScript.

renaudpawlak avatar Feb 12 '18 19:02 renaudpawlak

Full compilation trace may help :)

renaudpawlak avatar Feb 12 '18 19:02 renaudpawlak

Where should those definitions be ending up in my project if the maven command is working correctly?

Update: If it makes any difference, I looked in the .jsweet directory of my project and it looks like bigjs is there. Under the path .jsweet/candies/typings/META-INF/resources/bigjs/3.1.0-20170726/ there is a file named 'bundle.d.ts'.

pbtura avatar Feb 12 '18 19:02 pbtura

I finally made a bit of progress on this, but I'm still having issues. To get the compiler to see the definition for big you have to add the .jsweet path to the 'typeRoots' property of your tsconfig.json. Unfortunately, that leads to another obstacle. Typescript expects to find the .d.ts file directly under the folder for each lib (i.e. typings/bigjs/bundle.d.ts) but maven adds another directory in-between for the version number (i.e. typings/bigjs/2.0.0/bundle.d.ts) . In addition, typescript is only looking for 'index.d.ts' files. All the candies have the file name 'bundle.d.ts' instead. So even if the directory structure was right it STILL wouldn't pick them up thanks to the file names. Just to confirm that this was the issue, I went in and manually moved and renamed the .d.ts file and it did compile, but even then eclipse still doesn't see the definition and is still displaying errors.

Thoughts?

pbtura avatar Mar 07 '18 17:03 pbtura

Sorry, but you are not on the right track. Having the big.js candy in your Maven deps should make it work as is right away (I have just tried it on a demo project and it works). Trying to hack the jsweet configuration would probably make it worse or hide the root problem. I join the project that works for me...

bigjsExample.zip

renaudpawlak avatar Mar 10 '18 15:03 renaudpawlak

That example was a big help, but I'm still having issues. If run as-is, everything works great. I can even pull in java files from other projects and have them generate. The issue now is that for a real project, I would want the generated .ts files to be under my src directory so that they are visible to the rest of the project. As soon as I change the pom to make the <tsOut> point to a folder in the src directory, the issue with Big returns.

I thought it was something to do with the directory structure, but that also appears to be incorrect. Having the generated files outside the src directory worked at first. As soon as I added a reference to a generated file in my project though, the errors showed up again.

pbtura avatar Mar 12 '18 15:03 pbtura

I'm also having trouble with this. I downloaded bigjsExample.zip and ran maven.

The declarations file for bigjs lies under .jsweet\candies\typings\META-INF\resources\typings\bigjs\3.1.0-20170726 but not under target/js

Running node target/js/bundle.js produces ReferenceError: Big is not defined at Function.TestBigjs.main (...bigjsExample\target\js\bundle.js:9:21)

What is the correct way to run the JS code?

afimuc avatar Apr 04 '19 10:04 afimuc