Comparing version 0.1.1 to 0.1.2
@@ -55,2 +55,3 @@ "use strict"; | ||
decorators = param.decorators.slice(); | ||
hasDecoratedParam = true; | ||
} | ||
@@ -71,5 +72,3 @@ if (param.type) { | ||
} | ||
if (paramCtor) { | ||
if (decorators) | ||
hasDecoratedParam = true; | ||
if (paramCtor || decorators) { | ||
ctorParameters.push([paramCtor, decorators]); | ||
@@ -89,3 +88,3 @@ } | ||
*/ | ||
ClassRewriter.prototype.gatherMethod = function (method) { | ||
ClassRewriter.prototype.gatherMethodOrProperty = function (method) { | ||
if (!method.decorators) | ||
@@ -121,4 +120,7 @@ return; | ||
return false; // Proceed with ordinary emit of the ctor. | ||
case ts.SyntaxKind.PropertyDeclaration: | ||
case ts.SyntaxKind.SetAccessor: | ||
case ts.SyntaxKind.GetAccessor: | ||
case ts.SyntaxKind.MethodDeclaration: | ||
this.gatherMethod(node); | ||
this.gatherMethodOrProperty(node); | ||
return false; // Proceed with ordinary emit of the method. | ||
@@ -125,0 +127,0 @@ case ts.SyntaxKind.Decorator: |
{ | ||
"name": "tsickle", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Transpile TypeScript code to JavaScript with Closure annotations.", | ||
@@ -5,0 +5,0 @@ "main": "build/src/tsickle.js", |
@@ -52,2 +52,3 @@ import * as ts from 'typescript'; | ||
decorators = param.decorators.slice(); | ||
hasDecoratedParam = true; | ||
} | ||
@@ -69,4 +70,3 @@ if (param.type) { | ||
} | ||
if (paramCtor) { | ||
if (decorators) hasDecoratedParam = true; | ||
if (paramCtor || decorators) { | ||
ctorParameters.push([paramCtor, decorators]); | ||
@@ -87,3 +87,3 @@ } else { | ||
*/ | ||
private gatherMethod(method: ts.MethodDeclaration) { | ||
private gatherMethodOrProperty(method: ts.Declaration) { | ||
if (!method.decorators) return; | ||
@@ -120,4 +120,7 @@ if (method.name.kind !== ts.SyntaxKind.Identifier) { | ||
return false; // Proceed with ordinary emit of the ctor. | ||
case ts.SyntaxKind.PropertyDeclaration: | ||
case ts.SyntaxKind.SetAccessor: | ||
case ts.SyntaxKind.GetAccessor: | ||
case ts.SyntaxKind.MethodDeclaration: | ||
this.gatherMethod(node as ts.MethodDeclaration); | ||
this.gatherMethodOrProperty(node as ts.Declaration); | ||
return false; // Proceed with ordinary emit of the method. | ||
@@ -124,0 +127,0 @@ case ts.SyntaxKind.Decorator: |
@@ -206,4 +206,17 @@ import * as ts from 'typescript'; | ||
it('includes decorators for primitive type ctor parameters', () => { | ||
expect(translate(` | ||
class ViewUtils { | ||
constructor(@Inject(APP_ID) private _appId: string) {} | ||
}`).output).to.equal(` | ||
class ViewUtils { | ||
constructor( private _appId: string) {} | ||
static ctorParameters: {type: Function, decorators?: DecoratorInvocation[]}[] = [ | ||
{type: undefined, decorators: [{ type: Inject, args: [APP_ID, ] }, ]}, | ||
]; | ||
}`); | ||
}); | ||
it('strips generic type arguments', () => { | ||
expect(translate(` | ||
expect(translate(` | ||
class Foo { | ||
@@ -248,2 +261,21 @@ constructor(@Inject typed: Promise<string>) { | ||
it('gathers decorators from fields and setters', () => { | ||
expect(translate(` | ||
class ClassWithDecorators { | ||
@PropDecorator("p1") @PropDecorator("p2") a; | ||
b; | ||
@PropDecorator("p3") | ||
set c(value) {} | ||
}`).output).to.equal(` | ||
class ClassWithDecorators { a; | ||
b; | ||
set c(value) {} | ||
static propDecorators: {[key: string]: DecoratorInvocation[]} = { | ||
'a': [{ type: PropDecorator, args: ["p1", ] },{ type: PropDecorator, args: ["p2", ] },], | ||
'c': [{ type: PropDecorator, args: ["p3", ] },], | ||
}; | ||
}`); | ||
}); | ||
it('errors on weird class members', () => { | ||
@@ -250,0 +282,0 @@ let {diagnostics} = translate( |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
364424
120
6186