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 needsReload = true;
|
||||||
var oldSystemGet = System.get;
|
var oldSystemGet = System.get;
|
||||||
|
var currentOptions;
|
||||||
|
|
||||||
exports.reloadSources = function() {
|
exports.reloadSources = function() {
|
||||||
needsReload = true;
|
needsReload = true;
|
||||||
|
@ -43,10 +44,12 @@ exports.compile = function compile(options, paths, source, reloadTraceur) {
|
||||||
var CompilerCls = System.get('transpiler/src/compiler').Compiler;
|
var CompilerCls = System.get('transpiler/src/compiler').Compiler;
|
||||||
|
|
||||||
var compiler = new CompilerCls(options, moduleName);
|
var compiler = new CompilerCls(options, moduleName);
|
||||||
|
currentOptions = options;
|
||||||
var result = {
|
var result = {
|
||||||
js: compiler.compile(source, inputPath, outputPath),
|
js: compiler.compile(source, inputPath, outputPath),
|
||||||
sourceMap: null
|
sourceMap: null
|
||||||
};
|
};
|
||||||
|
currentOptions = null;
|
||||||
|
|
||||||
var sourceMapString = compiler.getSourceMap();
|
var sourceMapString = compiler.getSourceMap();
|
||||||
if (sourceMapString) {
|
if (sourceMapString) {
|
||||||
|
@ -186,6 +189,7 @@ function useRttsAssertModuleForConvertingTypesToExpressions() {
|
||||||
for (var prop in patch.prototype) {
|
for (var prop in patch.prototype) {
|
||||||
original.prototype[prop] = patch.prototype[prop];
|
original.prototype[prop] = patch.prototype[prop];
|
||||||
}
|
}
|
||||||
|
original.prototype.getOptions = function() { return currentOptions; };
|
||||||
|
|
||||||
var TypeAssertionTransformer = System.get(traceurVersion+'/src/codegeneration/TypeAssertionTransformer').TypeAssertionTransformer;
|
var TypeAssertionTransformer = System.get(traceurVersion+'/src/codegeneration/TypeAssertionTransformer').TypeAssertionTransformer;
|
||||||
var createIdentifierExpression = System.get(traceurVersion+'/src/codegeneration/ParseTreeFactory').createIdentifierExpression;
|
var createIdentifierExpression = System.get(traceurVersion+'/src/codegeneration/ParseTreeFactory').createIdentifierExpression;
|
||||||
|
@ -197,7 +201,8 @@ function useRttsAssertModuleForConvertingTypesToExpressions() {
|
||||||
this.paramTypes_.atLeastOneParameterTyped = true;
|
this.paramTypes_.atLeastOneParameterTyped = true;
|
||||||
} else {
|
} else {
|
||||||
// PATCH start
|
// PATCH start
|
||||||
typeAnnotation = parseExpression(["assert.type.any"]);
|
var typeModule = currentOptions.outputLanguage === 'es6' ? 'assert' : '$traceurRuntime';
|
||||||
|
typeAnnotation = parseExpression([typeModule + ".type.any"]);
|
||||||
// PATCH end
|
// PATCH end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,13 @@ import {
|
||||||
} from 'traceur/src/codegeneration/PlaceholderParser.js';
|
} from 'traceur/src/codegeneration/PlaceholderParser.js';
|
||||||
|
|
||||||
export class TypeToExpressionTransformer extends ParseTreeTransformer {
|
export class TypeToExpressionTransformer extends ParseTreeTransformer {
|
||||||
|
// Not used. Just required to call super() by traceur.
|
||||||
constructor(idGenerator, reporter, options) {
|
constructor(idGenerator, reporter, options) {
|
||||||
super(idGenerator, reporter);
|
super(idGenerator, reporter);
|
||||||
this.options_ = options;
|
}
|
||||||
|
|
||||||
|
typeModule() {
|
||||||
|
return parseExpression([this.getOptions().outputLanguage === 'es6' ? 'assert' : '$traceurRuntime']);
|
||||||
}
|
}
|
||||||
|
|
||||||
transformTypeName(tree) {
|
transformTypeName(tree) {
|
||||||
|
@ -30,14 +34,14 @@ export class TypeToExpressionTransformer extends ParseTreeTransformer {
|
||||||
}
|
}
|
||||||
|
|
||||||
transformPredefinedType(tree) {
|
transformPredefinedType(tree) {
|
||||||
return parseExpression `assert.type.${tree.typeToken})`;
|
return parseExpression `${this.typeModule()}.type.${tree.typeToken})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
transformTypeReference(tree) {
|
transformTypeReference(tree) {
|
||||||
var typeName = this.transformAny(tree.typeName);
|
var typeName = this.transformAny(tree.typeName);
|
||||||
var args = this.transformAny(tree.args);
|
var args = this.transformAny(tree.args);
|
||||||
var argumentList = new ArgumentList(tree.location, [typeName, ...args]);
|
var argumentList = new ArgumentList(tree.location, [typeName, ...args]);
|
||||||
return parseExpression `assert.genericType(${argumentList})`;
|
return parseExpression `${this.typeModule()}.genericType(${argumentList})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
transformTypeArguments(tree) {
|
transformTypeArguments(tree) {
|
||||||
|
|
Loading…
Reference in New Issue