* remove `wraps` syntax enhancements for imports
and support new `import * as module from ...` syntax
- default imports are the wrong construct for importing
everything from a module
* moved tests from transpiler to jasmine and karma
- transpiler tests are included when running karma in main project folder
- transpiler is reloaded after every test run in karma,
so no need to restart karma when the transpiler has been changed.
- removed own gulp build for transpiler and `postinstall.sh`
as they are no more needed.
- transpiler tests are now executed in Dart AND JavaScript (used to be executed
only in Dart), which allowed to catch some bugs (see the bug with the
import specification above).
* made tests work in dart as well by using the following hack:
- dependencies are loaded from the `build` folder, which makes
running `gulp build` necessary before running karma for dart
- for this to work,
the dependencies are included in main `pubspec.yaml` of project
- reason for the hack: `karma-dart` loads all `packages` urls
directly from disc (should rather use the karma file list)
* added explicit annotations `FIELD`, `ABSTRACT`, ... to `facade/lang.*`
- needed for now that we can run tests and don't get errors for undefined
annotations.
* added `README.md` with details about the build and tests
44 lines
1.4 KiB
JavaScript
44 lines
1.4 KiB
JavaScript
var transpiler = require('./index.js');
|
|
|
|
module.exports = {
|
|
'preprocessor:traceur': ['factory', createJs2DartPreprocessor]
|
|
};
|
|
|
|
function createJs2DartPreprocessor(logger, basePath, config, emitter) {
|
|
var log = logger.create('traceur');
|
|
// Reload the transpiler sources so we don't need to
|
|
// restart karma when we made changes to traceur.
|
|
// As there is no event that is called before any preprocessor runs,
|
|
// we listen for the end event in karma to reload the
|
|
// transpiler sources.
|
|
emitter.on('run_complete', function(filesPromise) {
|
|
transpiler.reloadSources();
|
|
});
|
|
return function(content, file, done) {
|
|
try {
|
|
var moduleName = config.resolveModuleName(file.originalPath);
|
|
if (config.transformPath) {
|
|
file.path = config.transformPath(file.originalPath);
|
|
}
|
|
done(null, transpiler.compile(config.options, {
|
|
inputPath: file.originalPath,
|
|
moduleName: moduleName
|
|
}, content));
|
|
} catch (errors) {
|
|
var errorString;
|
|
if (errors.forEach) {
|
|
errors.forEach(function(error) {
|
|
log.error(error);
|
|
});
|
|
errorString = errors.join('\n');
|
|
} else {
|
|
log.error(errors);
|
|
errorString = errors;
|
|
}
|
|
done(new Error('TRACEUR COMPILE ERRORS\n' + errorString));
|
|
}
|
|
};
|
|
}
|
|
|
|
createJs2DartPreprocessor.$inject = ['logger', 'config.basePath', 'config.traceurPreprocessor', 'emitter'];
|