Skip to content

Commit 5586828

Browse files
committed
Refactored decorator creation, made decorators case-insensitive
1 parent 35381a9 commit 5586828

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
lines changed

src/Decorator.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
11
export class Decorator {
2+
3+
public static isValid(decoratorKindString: string): boolean {
4+
return this.getDecoratorKind(decoratorKindString) !== undefined;
5+
}
6+
7+
public static getDecoratorKind(decoratorKindString: string): DecoratorKind {
8+
switch (decoratorKindString.toLowerCase()) {
9+
case "extension": return DecoratorKind.Extension;
10+
case "metaextension": return DecoratorKind.MetaExtension;
11+
case "customconstructor": return DecoratorKind.CustomConstructor;
12+
case "compilemembersonly": return DecoratorKind.CompileMembersOnly;
13+
case "pureabstract": return DecoratorKind.PureAbstract;
14+
case "phantom": return DecoratorKind.Phantom;
15+
case "tuplereturn": return DecoratorKind.TupleReturn;
16+
case "noclassor": return DecoratorKind.NoClassOr;
17+
}
18+
19+
return undefined;
20+
}
21+
222
public kind: DecoratorKind;
323
public args: string[];
424

5-
constructor(raw: string) {
6-
let nameEnd = raw.indexOf(" ");
7-
if (nameEnd === -1) {
8-
nameEnd = raw.length;
9-
}
10-
this.kind = DecoratorKind[raw.substring(0, nameEnd)];
11-
this.args = raw.split(" ").slice(1);
25+
constructor(name: string, args: string[]) {
26+
this.kind = Decorator.getDecoratorKind(name);
27+
this.args = args;
1228
}
1329
}
1430

src/TSHelper.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ export class TSHelper {
117117
const decMap = new Map<DecoratorKind, Decorator>();
118118

119119
decorators.forEach(decStr => {
120-
const dec = new Decorator(decStr.substr(1));
121-
if (dec.kind !== undefined) {
120+
const [decoratorName, ...decoratorArguments] = decStr.split(" ");
121+
if (Decorator.isValid(decoratorName.substr(1))) {
122+
const dec = new Decorator(decoratorName.substr(1), decoratorArguments);
122123
decMap.set(dec.kind, dec);
123124
console.warn(`[Deprecated] Decorators with ! are being deprecated, `
124125
+ `use @${decStr.substr(1)} instead`);
@@ -128,8 +129,8 @@ export class TSHelper {
128129
});
129130

130131
type.symbol.getJsDocTags().forEach(tag => {
131-
const dec = new Decorator(tag.name);
132-
if (dec.kind !== undefined) {
132+
if (Decorator.isValid(tag.name)) {
133+
const dec = new Decorator(tag.name, tag.text.split(" "));
133134
decMap.set(dec.kind, dec);
134135
}
135136
});

test/runner.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { TestRunner, TestSet } from "alsatian";
2-
import { TapBark } from "tap-bark";
32

43
import * as fs from "fs";
54
import * as path from "path";
@@ -21,9 +20,6 @@ fs.copyFileSync(
2120

2221
// setup the output
2322
testRunner.outputStream
24-
// this will use alsatian's default output if you remove this
25-
// you'll get TAP or you can add your favourite TAP reporter in it's place
26-
.pipe(TapBark.create().getPipeable())
2723
// pipe to the console
2824
.pipe(process.stdout);
2925

0 commit comments

Comments
 (0)