Search code examples
ceylon

How to use ceylon js (also with google closure compiler)


  1. Calling a file resulting from the concatenation (bash: cat ... >> app.js) of the following three files:

/usr/share/ceylon/1.2.0/repo/ceylon/language/1.2.0/ceylon.language-1.2.0.js

modules/com/example/helloworld/1.0.0/com.example.helloworld-1.0.0-model.js

modules/com/example/helloworld/1.0.0/com.example.helloworld-1.0.0.js

with the command nodejs app.js does nothing. The same when used in a web page. How do have I to call that javascript program so that it runs without using require.js ?

Please give the rules how ceylon modules and the run function and other functions contained within translate to javascript and are to be called.

How can I get one javascript file from compilation of several ceylon modules without concatenating them manually or with require.js?

The above is without using google closure compiler.

Given the size of 1.6 MB of the language module, it makes no sense to run ceylon-js without using google closure compiler.

  1. Compiling "ceylon.language-1.2.0.js" alone with google closure compiler results in a lot of warnings.

java -jar compiler.jar --compilation_level ADVANCED_OPTIMIZATIONS --js /usr/share/ceylon/1.2.0/repo/ceylon/language/1.2.0/ceylon.language-1.2.0.js --js_output_file lib-compiled.js

How can I get rid of those warnings?

  1. In what order do I have to chain together files resulting from ceylon-js with the model file and the language file to compile them in advanced mode with google closure compiler for dead code elimination.

Solution

  • These are 3 questions, really.

    A Ceylon module is compiled to a CommonJS module. Concatenating the resulting files won't work because each file is on CommonJS format, which is a big function that returns an object with the exported declarations.

    You can compile the modules with the --no-module option to get just the generated code, without it being wrapped in CommonJS format. For the language module, you can copy the file and just delete the first line and the last 5 lines.

    I do not yet know how to get rid of the warnings you mention in the second question.

    And as for the third question, I would recommend putting the language module first, then the rest of the files. If you have any toplevel declarations with the same name in different modules, you'll have conflicts (only the last declaration will remain), even if they're not shared, since they're all in the same module/unit.