Skip to content

Commit

Permalink
fix(deps): Type casting inside decorator
Browse files Browse the repository at this point in the history
fix #727
  • Loading branch information
vogloblinsky committed Feb 12, 2019
1 parent daa03cc commit f597531
Show file tree
Hide file tree
Showing 7 changed files with 225 additions and 184 deletions.
21 changes: 20 additions & 1 deletion src/app/compiler/angular/deps/helpers/class-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,26 @@ export class ClassHelper {
)}: <a href="${path}" target="_blank">${arg.type}</a>`;
} else {
if (arg.type) {
return `${arg.name}${this.getOptionalString(arg)}: ${arg.type}`;
let finalStringifiedArgument = '';
let separator = ':';
if (arg.name) {
finalStringifiedArgument += arg.name;
}
if (
arg.kind === SyntaxKind.AsExpression &&
arg.expression &&
arg.expression.text
) {
finalStringifiedArgument += arg.expression.text;
separator = ' as';
}
if (arg.optional) {
finalStringifiedArgument += this.getOptionalString(arg);
}
if (arg.type) {
finalStringifiedArgument += separator + ' ' + this.visitType(arg.type);
}
return finalStringifiedArgument;
} else if (arg.text) {
return `${arg.text}`;
} else {
Expand Down
359 changes: 179 additions & 180 deletions src/templates/partials/block-method.hbs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/utils/basic-type.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class BasicTypeUtil {
* @param type The type to check
*/
public isJavascriptType(type: string): boolean {
if (typeof type !== 'undefined') {
if (typeof type !== 'undefined' && type.toLowerCase) {
return type.toLowerCase() in BasicTypes;
} else {
return false;
Expand All @@ -41,7 +41,7 @@ export class BasicTypeUtil {
* @param type The type to check
*/
public isTypeScriptType(type: string): boolean {
if (typeof type !== 'undefined') {
if (typeof type !== 'undefined' && type.toLowerCase) {
return type.toLowerCase() in BasicTypeScriptTypes;
} else {
return false;
Expand Down
4 changes: 4 additions & 0 deletions src/utils/object-literal-expression.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export function StringifyObjectLiteralExpression(ole) {
if (property.initializer) {
if (property.initializer.kind === SyntaxKind.StringLiteral) {
returnedString += `'` + property.initializer.text + `'`;
} else if (property.initializer.kind === SyntaxKind.TrueKeyword) {
returnedString += `true`;
} else if (property.initializer.kind === SyntaxKind.FalseKeyword) {
returnedString += `false`;
} else {
returnedString += property.initializer.text;
}
Expand Down
7 changes: 6 additions & 1 deletion test/src/cli/cli-generation-big-app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ describe('CLI simple generation - big app', () => {
it('should support Type parameters', () => {
let file = read(distFolder + '/components/AppComponent.html');
expect(file).to.contain(
`<ul class="type-parameters">\n <li>T</li>\n <li>K</li>\n </ul>`
`<ul class="type-parameters">\n <li>T</li>\n <li>K</li>\n </ul>`
);
});

Expand Down Expand Up @@ -774,4 +774,9 @@ describe('CLI simple generation - big app', () => {
let file = read(distFolder + '/classes/Todo.html');
expect(file).to.contain('() &#x3D;&gt; {...}</code>');
});

it('correct supports 1000 as PollingSpeed for decorator arguments', () => {
let file = read(distFolder + '/classes/SomeFeature.html');
expect(file).to.contain('code>@throttle(1000 as PollingSpeed');
});
});
10 changes: 10 additions & 0 deletions test/src/todomvc-ng2/src/app/shared/miscellaneous/some-feature.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { throttle } from 'lodash-decorators';

import { PollingSpeed } from './util.const.ts';

export class SomeFeature {
@throttle(1000 as PollingSpeed, { leading: true })
doSomething() {
// do something throttled
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const enum PollingSpeed {
Low = 1000,
High = 100
}

0 comments on commit f597531

Please sign in to comment.