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

Question: How to transpile classes in project? #18

Closed
rquast opened this issue Jun 26, 2018 · 3 comments
Closed

Question: How to transpile classes in project? #18

rquast opened this issue Jun 26, 2018 · 3 comments
Labels
question Further information is requested

Comments

@rquast
Copy link

rquast commented Jun 26, 2018

I've managed to get the Java imports working great, but now I'm trying to import a class and it won't work. It appears it needs to be transpiled.

What doesn't work:

In my index.js I have import {Licensee} from './src/routes/licensee'; and licensee.js is just:

export class Licensee {
    test() {
        return 'IT WORKS';
    }
}

What does work:
index.js:

const Licensee = require('./src/routes/licensee');

licensee.js:

exports.test = function() {
        return 'IT WORKS';
};

Any tips on how to get it to transpile with the class? Very much appreciated! :)

@rquast
Copy link
Author

rquast commented Jun 27, 2018

Oh I think you might be just transpiling "import" only in your own code.

private static String adaptImport(final String exports, final String module) {

I thought it was running through typescript or something. Makes sense now.

So it's up to me to implement my own typescript transpilation then I guess? :)

@pmlopes
Copy link
Contributor

pmlopes commented Jun 27, 2018

@rquast this project doesn't do any special transpilation, you can see what ES6 level is supported by your runtime in the kangax table:

The only "trick" this project does is what you've just spotted, allow ES6 import syntax to be converted to commonjs require statements, mostly because IDEs such as vscode when using this format will pull the right type definition files giving you type hinting and proper code completion.

If you need more advanced features then you should rely on a ES6 transpiler such as babel, buble, traceur, etc... but this is not included in this project.

The reason is that the same runtime will run on GraalVM which is already ES6 ready (GraalVM support is still very experimental and has not been production tested, so currently it is just a development feature).

@pmlopes pmlopes added the question Further information is requested label Jun 27, 2018
@rquast
Copy link
Author

rquast commented Jun 27, 2018

Awesome! Thanks for the quick and detailed response Paulo!

@rquast rquast closed this as completed Jun 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants