chore(ts): Patch traceur's type module only when targetting es6 output.

This commit is contained in:
Alex Eagle 2015-03-31 16:12:13 -07:00
parent 59c1299168
commit 91e0e9e1dd
2 changed files with 14 additions and 5 deletions

View File

@ -18,6 +18,7 @@ var SELF_COMPILE_OPTIONS = {
var needsReload = true;
var oldSystemGet = System.get;
var currentOptions;
exports.reloadSources = function() {
needsReload = true;
@ -43,10 +44,12 @@ exports.compile = function compile(options, paths, source, reloadTraceur) {
var CompilerCls = System.get('transpiler/src/compiler').Compiler;
var compiler = new CompilerCls(options, moduleName);
currentOptions = options;
var result = {
js: compiler.compile(source, inputPath, outputPath),
sourceMap: null
};
currentOptions = null;
var sourceMapString = compiler.getSourceMap();
if (sourceMapString) {
@ -186,6 +189,7 @@ function useRttsAssertModuleForConvertingTypesToExpressions() {
for (var prop in patch.prototype) {
original.prototype[prop] = patch.prototype[prop];
}
original.prototype.getOptions = function() { return currentOptions; };
var TypeAssertionTransformer = System.get(traceurVersion+'/src/codegeneration/TypeAssertionTransformer').TypeAssertionTransformer;
var createIdentifierExpression = System.get(traceurVersion+'/src/codegeneration/ParseTreeFactory').createIdentifierExpression;
@ -197,7 +201,8 @@ function useRttsAssertModuleForConvertingTypesToExpressions() {
this.paramTypes_.atLeastOneParameterTyped = true;
} else {
// PATCH start
typeAnnotation = parseExpression(["assert.type.any"]);
var typeModule = currentOptions.outputLanguage === 'es6' ? 'assert' : '$traceurRuntime';
typeAnnotation = parseExpression([typeModule + ".type.any"]);
// PATCH end
}

View File

@ -16,9 +16,13 @@ import {
} from 'traceur/src/codegeneration/PlaceholderParser.js';
export class TypeToExpressionTransformer extends ParseTreeTransformer {
// Not used. Just required to call super() by traceur.
constructor(idGenerator, reporter, options) {
super(idGenerator, reporter);
this.options_ = options;
}
typeModule() {
return parseExpression([this.getOptions().outputLanguage === 'es6' ? 'assert' : '$traceurRuntime']);
}
transformTypeName(tree) {
@ -30,18 +34,18 @@ export class TypeToExpressionTransformer extends ParseTreeTransformer {
}
transformPredefinedType(tree) {
return parseExpression `assert.type.${tree.typeToken})`;
return parseExpression `${this.typeModule()}.type.${tree.typeToken})`;
}
transformTypeReference(tree) {
var typeName = this.transformAny(tree.typeName);
var args = this.transformAny(tree.args);
var argumentList = new ArgumentList(tree.location, [typeName, ...args]);
return parseExpression `assert.genericType(${argumentList})`;
return parseExpression `${this.typeModule()}.genericType(${argumentList})`;
}
transformTypeArguments(tree) {
return this.transformList(tree.args);
}
}
}