-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from ktutnik/master
Big update coming
- Loading branch information
Showing
48 changed files
with
1,001 additions
and
719 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { SyntaxKind, MethodMetaData, MetaData, AnalysisType, SourceLocation } from "../../core" | ||
import * as H from "./helper" | ||
|
||
|
||
export class ChildDecoratorAnalyzer { | ||
constructor(private node) { } | ||
|
||
isMethodDecorator() { | ||
return !H.isReservedDecorator(this.node); | ||
} | ||
|
||
isParameterDecorator() { | ||
return H.getMethodNameFromCallee(this.node.callee) == "__param"; | ||
} | ||
|
||
getMethodName() { | ||
return H.getMethodNameFromCallee(this.node.callee); | ||
} | ||
|
||
getMethodLocation() { | ||
return <SourceLocation>{ | ||
start: this.node.start, | ||
end: this.node.end | ||
} | ||
} | ||
|
||
getMethodParameters() { | ||
return this.node.arguments.map(x => this.getParameter(x)); | ||
} | ||
|
||
getParameterDecoratorName() { | ||
return H.getMethodNameFromCallee(this.node.arguments[1].callee); | ||
} | ||
|
||
getParameterDecoratorLocation() { | ||
return <SourceLocation>{ | ||
start: this.node.start, | ||
end: this.node.end | ||
} | ||
} | ||
|
||
getParameterDecoratorParameters() { | ||
return this.node.arguments[1].arguments | ||
.map(x => this.getParameter(x)); | ||
} | ||
|
||
|
||
private getParameter(x) { | ||
return <MetaData>{ | ||
type: "Parameter", | ||
name: H.getDecoratorParameterName(x), | ||
analysis: AnalysisType.Valid, | ||
location: <SourceLocation>{ | ||
start: this.node.start, | ||
end: this.node.end | ||
}, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import * as Core from "../../core" | ||
|
||
|
||
export class ConstructorAnalyzer { | ||
constructor(private node) { } | ||
|
||
isConstructor(className: string) { | ||
return this.node.type == Core.SyntaxKind.FunctionDeclaration | ||
&& this.node.id.name == className; | ||
} | ||
|
||
getName() { | ||
return this.node.id.name; | ||
} | ||
|
||
getLocation() { | ||
return <Core.SourceLocation> { | ||
start: this.node.start, | ||
end: this.node.end | ||
}; | ||
} | ||
|
||
getParameters(){ | ||
return this.node.params; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { SyntaxKind, MetaData } from "../../core" | ||
import * as HP from "./helper" | ||
|
||
|
||
export class DecoratorAnalyzer { | ||
constructor(private node) { } | ||
|
||
isMethodDecorator() { | ||
return this.node.type == SyntaxKind.ExpressionStatement | ||
&& HP.getMethodNameFromCallee(this.node.expression.callee) == "__decorate" | ||
&& this.node.expression.arguments.length == 4 | ||
} | ||
|
||
getClassName() { | ||
if (this.isMethodDecorator()) | ||
return this.node.expression.arguments[1].object.name; | ||
if (this.isClassDecorator()) { | ||
return this.node.expression.left.name; | ||
} | ||
else return null; | ||
} | ||
|
||
getMethodName() { | ||
if (this.isMethodDecorator()) | ||
return this.node.expression.arguments[2].value | ||
else return null; | ||
} | ||
|
||
isClassDecorator() { | ||
return this.node.type == SyntaxKind.ExpressionStatement | ||
&& this.node.expression.type == SyntaxKind.AssignmentExpression | ||
&& this.node.expression.left.type == SyntaxKind.Identifier | ||
&& this.node.expression.right.type == SyntaxKind.CallExpression | ||
&& HP.getMethodNameFromCallee(this.node.expression.right.callee) == "__decorate" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { SyntaxKind, SourceLocation } from "../../core" | ||
|
||
|
||
export class FileAnalyzer { | ||
constructor(private node) { } | ||
|
||
getChildren(){ | ||
return this.node.program.body; | ||
} | ||
|
||
getLocation() { | ||
return <SourceLocation> { | ||
start: this.node.start, | ||
end: this.node.end | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import {AnalyzerType} from "../baseclasses" | ||
|
||
import { ChildDecoratorAnalyzer } from "./child-decorator-analyzer" | ||
import { ClassAnalyzer } from "./class-analyzer" | ||
import { ConstructorAnalyzer } from "./constructor-analyser" | ||
import { DecoratorAnalyzer } from "./decorator-analyzer" | ||
import { FileAnalyzer } from "./file-analyzer" | ||
import { MethodAnalyzer } from "./method-analyzer" | ||
import { ModuleAnalyzer } from "./module-analyzer" | ||
import { ParameterAnalyzer } from "./parameter-analyzer" | ||
|
||
export function get(type:AnalyzerType, node){ | ||
switch(type){ | ||
case AnalyzerType.ChildDecorator: | ||
return new ChildDecoratorAnalyzer(node) | ||
case AnalyzerType.File: | ||
return new FileAnalyzer(node); | ||
case AnalyzerType.Decorator: | ||
return new DecoratorAnalyzer(node); | ||
case AnalyzerType.Method: | ||
return new MethodAnalyzer(node); | ||
case AnalyzerType.Parameter: | ||
return new ParameterAnalyzer(node); | ||
case AnalyzerType.Constructor: | ||
return new ConstructorAnalyzer(node); | ||
case AnalyzerType.TSClass: | ||
return new ClassAnalyzer(node); | ||
case AnalyzerType.TSModule: | ||
return new ModuleAnalyzer(node); | ||
} | ||
} | ||
|
||
|
||
export { ChildDecoratorAnalyzer } from "./child-decorator-analyzer" | ||
export { ClassAnalyzer } from "./class-analyzer" | ||
export { ConstructorAnalyzer } from "./constructor-analyser" | ||
export { DecoratorAnalyzer } from "./decorator-analyzer" | ||
export { FileAnalyzer } from "./file-analyzer" | ||
export { MethodAnalyzer } from "./method-analyzer" | ||
export { ModuleAnalyzer } from "./module-analyzer" | ||
export { ParameterAnalyzer } from "./parameter-analyzer" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { SyntaxKind, SourceLocation } from "../../core" | ||
|
||
|
||
export class ParameterAnalyzer { | ||
constructor(private node) { } | ||
|
||
getName() { | ||
return this.node.name; | ||
} | ||
|
||
getLocation() { | ||
return <SourceLocation> { | ||
start: this.node.start, | ||
end: this.node.end | ||
}; | ||
} | ||
} |
Oops, something went wrong.