Danny Tuppeny Danny Tuppeny - 1 year ago 107
Dart Question

How can I generate code to export functions for node in Dart?

(I failed at getting this working in dart2js so I'm trying in dart dev compiler; but I'd happily take an answer for dart2j!).

If I have


void activate() {

and run
dartdevc --modules node -o test.js test.dart
the output is:

(function() {
'use strict';
const dart_sdk = require('dart_sdk');
const core = dart_sdk.core;
const dart = dart_sdk.dart;
const dartx = dart_sdk.dartx;
const __test = Object.create(null);
let VoidTovoid = () => (VoidTovoid = dart.constFn(dart.definiteFunctionType(dart.void, [])))();
__test.activate = function() {
dart.fn(__test.activate, VoidTovoid());
// Exports:
exports.__test = __test;

This means my function is exported as
but what I need is for it just to be

How can I control this? The JS I'm aiming for the equivilent of this:

exports.activate = function() { core.print("activating"); }

Answer Source

This isn't currently possible but I worked around it with a wrapper:

var extension = require('./dartvsjs/extension.js');

exports.activate = extension.__lib__extension.activate;
exports.deactivate = extension.__lib__extension.deactivate;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download