Skip to content

Commit

Permalink
Merge pull request #4 from ktutnik/master
Browse files Browse the repository at this point in the history
Big update coming
  • Loading branch information
ktutnik authored Jan 29, 2017
2 parents add6bc2 + 6c14cf1 commit a230139
Show file tree
Hide file tree
Showing 48 changed files with 1,001 additions and 719 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"**/*.js.map": true,
//"**/*.js.map": true,
//"**/*.js": {"when": "$(basename).ts"},
//"**/*.d.ts": {"when": "$(basename).ts"},
"**/.git": true,
Expand Down
4 changes: 0 additions & 4 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ gulp.task("clean", function (cb) {
//******** BUILD *************

var tsProject = tsc.createProject("tsconfig.json", {
declaration: false,
noResolve: false,
typescript: require("typescript")
});

Expand All @@ -55,8 +53,6 @@ gulp.task("build-source", function () {
});

var tsTestProject = tsc.createProject("tsconfig.json", {
declaration: false,
noResolve: false,
typescript: require("typescript")
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kecubung",
"version": "0.0.2-4",
"version": "0.0.2",
"description": "Javascript transformer to Type Metadata",
"main": "./lib/source/index.js",
"typings": "./lib/dts/index.d.ts",
Expand Down
59 changes: 59 additions & 0 deletions src/analyzers/astree/child-decorator-analyzer.ts
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
},
};
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SyntaxKind } from "../core"
import { SyntaxKind, SourceLocation } from "../../core"
import * as HP from "./helper"

export class ClassAnalyzer {
Expand All @@ -17,6 +17,18 @@ export class ClassAnalyzer {
&& this.node.expression.right.name == name
}

getLocation() {
return <SourceLocation>{
start: this.node.start,
end: this.node.end
};
}

//constructors & methods
getMember() {
return this.node.declarations[0].init.callee.body.body;
}

/**
* expect ExpressionStatement
*/
Expand Down
26 changes: 26 additions & 0 deletions src/analyzers/astree/constructor-analyser.ts
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;
}
}
36 changes: 36 additions & 0 deletions src/analyzers/astree/decorator-analyzer.ts
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"
}
}
17 changes: 17 additions & 0 deletions src/analyzers/astree/file-analyzer.ts
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
};
}
}
2 changes: 1 addition & 1 deletion src/analyzers/helper.ts → src/analyzers/astree/helper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SyntaxKind, MetaData, AnalysisType } from "../core"
import { SyntaxKind, MetaData, AnalysisType } from "../../core"

/**
* require CallExpression.callee
Expand Down
41 changes: 41 additions & 0 deletions src/analyzers/astree/index.ts
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"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SyntaxKind } from "../core"
import { SyntaxKind, SourceLocation } from "../../core"
import * as MH from "./helper"


Expand All @@ -8,7 +8,7 @@ export class MethodAnalyzer {
*/
constructor(private node) { }


isMethod(className: String) {
return this.isMethodStatement()
&& this.node.expression.left.object.object.name == className
Expand All @@ -35,6 +35,16 @@ export class MethodAnalyzer {
else return null;
}

getLocation() {
return <SourceLocation> {
start: this.node.start,
end: this.node.end
};
}

getParameters(){
return this.node.expression.right.params;
}

getParams() {
if (this.isMethodStatement())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SyntaxKind } from "../core"
import { SyntaxKind, SourceLocation } from "../../core"

export class ModuleAnalyzer {
/**
Expand All @@ -22,7 +22,7 @@ export class ModuleAnalyzer {
&& this.node.expression.arguments[0].left.name == this.node.expression.callee.params[0].name
}

getBody(){
getBody() {
return this.node.expression.callee.body.body;
}

Expand All @@ -33,6 +33,13 @@ export class ModuleAnalyzer {
return null;
}

getLocation() {
return <SourceLocation>{
start: this.node.start,
end: this.node.end
};
}

isExported(parentName: string) {
//(function(Children){})(Children = (Parent.Children) || ())
//(function(Children){})(Children = (exports.Children) || ())
Expand Down
17 changes: 17 additions & 0 deletions src/analyzers/astree/parameter-analyzer.ts
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
};
}
}
Loading

0 comments on commit a230139

Please sign in to comment.