chore(ts): Patch traceur's type module only when targetting es6 output.
This commit is contained in:
parent
59c1299168
commit
91e0e9e1dd
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue