Comparing version
@@ -20,3 +20,3 @@ import * as ts from 'typescript'; | ||
*/ | ||
private symbolToString(sym); | ||
symbolToString(sym: ts.Symbol): string; | ||
/** | ||
@@ -23,0 +23,0 @@ * @param notNull When true, insert a ! before any type references. This |
@@ -9,2 +9,3 @@ "use strict"; | ||
var rewriter_1 = require('./rewriter'); | ||
var type_translator_1 = require('./type-translator'); | ||
// ClassRewriter rewrites a single "class Foo {...}" declaration. | ||
@@ -64,3 +65,3 @@ // It's its own object because we collect decorators on the class and the ctor | ||
if (sym && (sym.flags & ts.SymbolFlags.Value)) { | ||
paramCtor = sym.name; | ||
paramCtor = new type_translator_1.TypeTranslator(this.typeChecker, param.type).symbolToString(sym); | ||
} | ||
@@ -67,0 +68,0 @@ } |
{ | ||
"name": "tsickle", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Transpile TypeScript code to JavaScript with Closure annotations.", | ||
@@ -5,0 +5,0 @@ "main": "build/src/tsickle.js", |
import * as ts from 'typescript'; | ||
import {Rewriter} from './rewriter'; | ||
import {TypeTranslator} from './type-translator'; | ||
@@ -61,3 +62,3 @@ // ClassRewriter rewrites a single "class Foo {...}" declaration. | ||
if (sym && (sym.flags & ts.SymbolFlags.Value)) { | ||
paramCtor = sym.name; | ||
paramCtor = new TypeTranslator(this.typeChecker, param.type).symbolToString(sym); | ||
} | ||
@@ -64,0 +65,0 @@ } |
@@ -77,3 +77,3 @@ import * as ts from 'typescript'; | ||
*/ | ||
private symbolToString(sym: ts.Symbol): string { | ||
public symbolToString(sym: ts.Symbol): string { | ||
// This follows getSingleLineStringWriter in the TypeScript compiler. | ||
@@ -80,0 +80,0 @@ let str = ''; |
@@ -17,8 +17,12 @@ import {convertDecorators} from '../src/decorator-annotator'; | ||
function sources(sourceText: string): {[fileName: string]: string} { | ||
return { | ||
[testCaseFileName]: sourceText, | ||
'bar.d.ts': 'declare module "bar" { export class BarService {} }' | ||
}; | ||
} | ||
function verifyCompiles(sourceText: string) { | ||
let sources: {[fileName: string]: string} = { | ||
[testCaseFileName]: testSupportCode + sourceText, | ||
}; | ||
// This throws an exception on error. | ||
test_support.createProgram(sources); | ||
test_support.createProgram(sources(testSupportCode + sourceText)); | ||
} | ||
@@ -29,6 +33,3 @@ | ||
function translate(sourceText: string, allowErrors = false) { | ||
let sources: {[fileName: string]: string} = { | ||
[testCaseFileName]: sourceText, | ||
}; | ||
let program = test_support.createProgram(sources); | ||
let program = test_support.createProgram(sources(sourceText)); | ||
let {output, diagnostics} = | ||
@@ -146,3 +147,3 @@ convertDecorators(program.getTypeChecker(), program.getSourceFile(testCaseFileName)); | ||
expect(translate(` | ||
class BarService {}; | ||
import {BarService} from 'bar'; | ||
class Foo { | ||
@@ -152,3 +153,3 @@ constructor(bar: BarService, num: number) { | ||
}`).output).to.equal(` | ||
class BarService {}; | ||
import {BarService} from 'bar'; | ||
class Foo { | ||
@@ -183,4 +184,4 @@ constructor(bar: BarService, num: number) { | ||
expect(translate(` | ||
import {BarService} from 'bar'; | ||
let Test1: Function; | ||
class BarService {} | ||
@Test1() | ||
@@ -191,4 +192,4 @@ class Foo { | ||
}`).output).to.equal(` | ||
import {BarService} from 'bar'; | ||
let Test1: Function; | ||
class BarService {} | ||
class Foo { | ||
@@ -211,21 +212,21 @@ constructor(bar: BarService, num: number) { | ||
expect(translate(` | ||
import * as bar from 'bar'; | ||
let Inject: Function; | ||
class BarService {} | ||
let param: any; | ||
class Foo { | ||
constructor(@Inject(param) x: BarService, {a, b}, defArg = 3, optional?: BarService) { | ||
constructor(@Inject(param) x: bar.BarService, {a, b}, defArg = 3, optional?: bar.BarService) { | ||
} | ||
}`).output).to.equal(` | ||
import * as bar from 'bar'; | ||
let Inject: Function; | ||
class BarService {} | ||
let param: any; | ||
class Foo { | ||
constructor( x: BarService, {a, b}, defArg = 3, optional?: BarService) { | ||
constructor( x: bar.BarService, {a, b}, defArg = 3, optional?: bar.BarService) { | ||
} | ||
/** @nocollapse */ | ||
static ctorParameters: {type: Function, decorators?: DecoratorInvocation[]}[] = [ | ||
{type: BarService, decorators: [{ type: Inject, args: [param, ] }, ]}, | ||
{type: bar.BarService, decorators: [{ type: Inject, args: [param, ] }, ]}, | ||
null, | ||
null, | ||
{type: BarService, }, | ||
{type: bar.BarService, }, | ||
]; | ||
@@ -232,0 +233,0 @@ }`); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
342369
0.11%7211
-0.06%