-
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 #3 from RezaRostamiNikoo/dev
dev
- Loading branch information
Showing
28 changed files
with
416 additions
and
303 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
on: | ||
push: | ||
branches: master | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: "18" | ||
- run: npm ci | ||
- run: npm run build | ||
- run: npm test | ||
- uses: JS-DevTools/npm-publish@v2 | ||
with: | ||
token: ${{ secrets.NPM_TOKEN }} |
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,7 @@ | ||
test | ||
src | ||
public | ||
|
||
webpack.config.js | ||
tsconfig.json | ||
jest.config.js |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,10 +1,27 @@ | ||
import * as ts from "typescript"; | ||
import { statementFromExpression } from "./statements"; | ||
import { getPropertyOfClassExpression } from "./expressions"; | ||
|
||
export class BodyGenerator { | ||
|
||
generate() { | ||
// ts.factory.createBlock( | ||
private _statements: ts.Statement[] = [] | ||
|
||
// ) | ||
|
||
addStatement(statement: ts.Statement): this { | ||
this._statements.push(statement); | ||
return this; | ||
} | ||
addExpression(expression: ts.Expression): this { | ||
this._statements.push(statementFromExpression(expression)); | ||
return this; | ||
} | ||
|
||
returnsProperty(name: string | ts.Identifier): this { | ||
this._statements.push(ts.factory.createReturnStatement(getPropertyOfClassExpression(name))) | ||
return this; | ||
} | ||
|
||
generate(): ts.Block { | ||
return ts.factory.createBlock(this._statements, true); | ||
} | ||
} |
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
File renamed without changes.
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,29 @@ | ||
import * as ts from "typescript"; | ||
import { statementFromExpression } from "./statements"; | ||
|
||
export function or(expr1: ts.Expression, expr2: ts.Expression): ts.BinaryExpression { | ||
return ts.factory.createBinaryExpression(expr1, ts.SyntaxKind.BarBarToken, expr2); | ||
} | ||
|
||
export function expOrNull(expr: ts.Expression): ts.BinaryExpression { | ||
return ts.factory.createBinaryExpression(expr, ts.SyntaxKind.BarBarToken, ts.factory.createNull()) | ||
} | ||
|
||
export function assignToClassProperty(name: string | ts.Identifier, expresion: ts.Expression): ts.AssignmentExpression<ts.AssignmentOperatorToken> { | ||
const property = getPropertyOfClassExpression(name); | ||
return ts.factory.createAssignment(property, expresion); | ||
} | ||
|
||
export function getPropertyOfClassExpression(name: string | ts.Identifier): ts.Expression { | ||
return ts.factory.createPropertyAccessExpression( | ||
ts.factory.createIdentifier("this"), | ||
typeof name === "string" | ||
? ts.factory.createIdentifier(name) | ||
: name | ||
); | ||
} | ||
|
||
|
||
export function expressionToStatement(expr: ts.Expression): ts.Statement { | ||
return statementFromExpression(expr); | ||
} |
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,54 @@ | ||
import * as ts from "typescript"; | ||
import { ModifierLikeHandler } from "./modifiers"; | ||
import { BodyGenerator } from "./bodyGenerator"; | ||
import { ParameterGenerator } from "./parameters"; | ||
|
||
export class GetterGenerator { | ||
private _name: string; | ||
private _modifiers: ModifierLikeHandler = new ModifierLikeHandler(); | ||
private _parameters: ParameterGenerator[] = []; | ||
private _identifier: ts.Identifier; | ||
private _block: BodyGenerator; | ||
private _type: ts.TypeNode; | ||
|
||
|
||
constructor(name: string | ts.Identifier) { | ||
if (typeof name === "string") { | ||
this._name = name; | ||
this._identifier = ts.factory.createIdentifier(name); | ||
} else { | ||
this._name = name.text; | ||
this._identifier = name; | ||
} | ||
} | ||
|
||
readonly(): this { | ||
this._modifiers.readonly(); | ||
return this; | ||
} | ||
|
||
private(): this { | ||
this._modifiers.private(); | ||
return this; | ||
} | ||
|
||
setType(typeNode: ts.TypeNode): this { this._type = typeNode; return this; } | ||
|
||
|
||
generate(): ts.GetAccessorDeclaration { | ||
return ts.factory.createGetAccessorDeclaration( | ||
this._modifiers.toArray(), | ||
this._name, | ||
this._parameters.map(p => p.generate()), | ||
this._type, | ||
this._block.generate() | ||
); | ||
} | ||
|
||
setBody() { | ||
if (this._block) return this._block; | ||
this._block = new BodyGenerator(); | ||
return this._block; | ||
} | ||
|
||
} |
Oops, something went wrong.