feat(dart): Use ts2dart for transpilation in Karma Dart.
This commit is contained in:
		
							parent
							
								
									226cbc7db3
								
							
						
					
					
						commit
						17e8857efc
					
				| @ -58,25 +58,14 @@ module.exports = function(config) { | ||||
|     }, | ||||
| 
 | ||||
|     preprocessors: { | ||||
|       'modules/**/*.js': ['traceur'], | ||||
|       'tools/**/*.js': ['traceur'] | ||||
|       'modules/**/*.js': ['ts2dart'], | ||||
|       'tools/**/*.js': ['ts2dart'] | ||||
|     }, | ||||
| 
 | ||||
|     traceurPreprocessor: { | ||||
|       options: { | ||||
|         outputLanguage: 'dart', | ||||
|         sourceMaps: true, | ||||
|         script: false, | ||||
|         modules: 'register', | ||||
|         memberVariables: true, | ||||
|         types: true, | ||||
|         // typeAssertions: true,
 | ||||
|         // typeAssertionModule: 'assert',
 | ||||
|         annotations: true | ||||
|       }, | ||||
|     ts2dartPreprocessor: { | ||||
|       resolveModuleName: file2moduleName, | ||||
|       transformPath: function(fileName) { | ||||
|         return fileName.replace('.js', '.dart'); | ||||
|         return fileName.replace(/.js$/, '.dart'); | ||||
|       } | ||||
|     }, | ||||
| 
 | ||||
| @ -91,5 +80,5 @@ module.exports = function(config) { | ||||
|   }); | ||||
| 
 | ||||
| 
 | ||||
|   config.plugins.push(require('./tools/transpiler/karma-traceur-preprocessor')); | ||||
|   config.plugins.push(require('./tools/transpiler/karma-ts2dart-preprocessor')); | ||||
| }; | ||||
|  | ||||
| @ -96,6 +96,7 @@ | ||||
|     "ternary-stream": "^1.2.3", | ||||
|     "through2": "^0.6.1", | ||||
|     "typescript": "alexeagle/TypeScript#93dbbe2a2d0b42cefd02ac949e4bc8ab6b5b5823", | ||||
|     "ts2dart": "^0.2.0", | ||||
|     "vinyl": "^0.4.6", | ||||
|     "walk-sync": "^0.1.3", | ||||
|     "xtend": "^4.0.0", | ||||
|  | ||||
							
								
								
									
										35
									
								
								tools/transpiler/karma-ts2dart-preprocessor.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								tools/transpiler/karma-ts2dart-preprocessor.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,35 @@ | ||||
| // Transpiles JavaScript and TypeScript code to Dart using ts2dart.
 | ||||
| 
 | ||||
| var ts2dart = require('ts2dart'); | ||||
| var rundartpackage = require('../build/rundartpackage.js'); | ||||
| 
 | ||||
| module.exports = { | ||||
|   'preprocessor:ts2dart': ['factory', createTs2DartPreprocessor] | ||||
| }; | ||||
| 
 | ||||
| function createTs2DartPreprocessor(logger, basePath, config, emitter) { | ||||
|   var log = logger.create('ts2dart'); | ||||
|   return function(content, file, done) { | ||||
|     try { | ||||
|       var moduleName = config.resolveModuleName(file.originalPath); | ||||
|       file.path = config.transformPath(file.originalPath); | ||||
|       var transpiler = new ts2dart.Transpiler(); | ||||
|       var transpiledContent = transpiler.translateFile(file.originalPath, moduleName); | ||||
|       // TODO(martinprobst): Source maps.
 | ||||
|       done(null, transpiledContent); | ||||
|     } 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('ts2dart compile errors:\n' + errorString)); | ||||
|     } | ||||
|   }; | ||||
| } | ||||
| 
 | ||||
| createTs2DartPreprocessor | ||||
|     .$inject = ['logger', 'config.basePath', 'config.ts2dartPreprocessor', 'emitter']; | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user