Skip to content

Commit 17e8857

Browse files
committed
feat(dart): Use ts2dart for transpilation in Karma Dart.
1 parent 226cbc7 commit 17e8857

File tree

3 files changed

+41
-16
lines changed

3 files changed

+41
-16
lines changed

karma-dart.conf.js

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,14 @@ module.exports = function(config) {
5858
},
5959

6060
preprocessors: {
61-
'modules/**/*.js': ['traceur'],
62-
'tools/**/*.js': ['traceur']
61+
'modules/**/*.js': ['ts2dart'],
62+
'tools/**/*.js': ['ts2dart']
6363
},
6464

65-
traceurPreprocessor: {
66-
options: {
67-
outputLanguage: 'dart',
68-
sourceMaps: true,
69-
script: false,
70-
modules: 'register',
71-
memberVariables: true,
72-
types: true,
73-
// typeAssertions: true,
74-
// typeAssertionModule: 'assert',
75-
annotations: true
76-
},
65+
ts2dartPreprocessor: {
7766
resolveModuleName: file2moduleName,
7867
transformPath: function(fileName) {
79-
return fileName.replace('.js', '.dart');
68+
return fileName.replace(/.js$/, '.dart');
8069
}
8170
},
8271

@@ -91,5 +80,5 @@ module.exports = function(config) {
9180
});
9281

9382

94-
config.plugins.push(require('./tools/transpiler/karma-traceur-preprocessor'));
83+
config.plugins.push(require('./tools/transpiler/karma-ts2dart-preprocessor'));
9584
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
"ternary-stream": "^1.2.3",
9797
"through2": "^0.6.1",
9898
"typescript": "alexeagle/TypeScript#93dbbe2a2d0b42cefd02ac949e4bc8ab6b5b5823",
99+
"ts2dart": "^0.2.0",
99100
"vinyl": "^0.4.6",
100101
"walk-sync": "^0.1.3",
101102
"xtend": "^4.0.0",
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Transpiles JavaScript and TypeScript code to Dart using ts2dart.
2+
3+
var ts2dart = require('ts2dart');
4+
var rundartpackage = require('../build/rundartpackage.js');
5+
6+
module.exports = {
7+
'preprocessor:ts2dart': ['factory', createTs2DartPreprocessor]
8+
};
9+
10+
function createTs2DartPreprocessor(logger, basePath, config, emitter) {
11+
var log = logger.create('ts2dart');
12+
return function(content, file, done) {
13+
try {
14+
var moduleName = config.resolveModuleName(file.originalPath);
15+
file.path = config.transformPath(file.originalPath);
16+
var transpiler = new ts2dart.Transpiler();
17+
var transpiledContent = transpiler.translateFile(file.originalPath, moduleName);
18+
// TODO(martinprobst): Source maps.
19+
done(null, transpiledContent);
20+
} catch (errors) {
21+
var errorString;
22+
if (errors.forEach) {
23+
errors.forEach(function(error) { log.error(error); });
24+
errorString = errors.join('\n');
25+
} else {
26+
log.error(errors);
27+
errorString = errors;
28+
}
29+
done(new Error('ts2dart compile errors:\n' + errorString));
30+
}
31+
};
32+
}
33+
34+
createTs2DartPreprocessor
35+
.$inject = ['logger', 'config.basePath', 'config.ts2dartPreprocessor', 'emitter'];

0 commit comments

Comments
 (0)