Skip to content

Commit

Permalink
fix: add hooks for test
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin-ZS committed Dec 22, 2020
1 parent d24fb3c commit a260090
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
"server": "node ./scripts/server",
"build": "esbuild ./src/index.ts --target=es6 --global-name=bow --platform=browser --loader:.ts=ts --bundle --sourcemap --outfile=dist/bow.js"
},
"husky": {
"hooks": {
"pre-commit": "npm test"
}
},
"repository": {
"type": "git",
"url": "git+https://github.com/Justin-ZS/bow.git"
Expand All @@ -26,6 +31,7 @@
"browser-sync": "2.26.12",
"esbuild": "0.7.5",
"eslint": "7.9.0",
"husky": "^5.0.6",
"jest": "26.6.3",
"ts-jest": "26.4.4",
"typescript": "4.0.3"
Expand Down
19 changes: 12 additions & 7 deletions src/expression/transform/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ const isOpFieldsProp = (prop: ESTree.Property) => (
export const predAST = {
isOperator: (node: ESTree.Node) => {
if (node.type !== ExpressionType.Object) return false;

const objExpr = node as ESTree.ObjectExpression;
if (objExpr.properties.length !== 2) return false;
if (objExpr.properties.some(isSpreadElement)) return false;

const [typeProp, fieldsProp] = objExpr.properties as ESTree.Property[];
return isOpTypeProp(typeProp) && isOpFieldsProp(fieldsProp);
},
Expand Down Expand Up @@ -66,16 +66,21 @@ const makeMemberExpr = (objName: string, propName: string, computed: boolean): E
optional: false,
}) as any;

// t => op.sum(t['fields'])
// (t, op) => op.sum(t['fields'])
export const makeOpExpr = (op: Operator, tableName = 't', opName = 'op'): ESTree.ArrowFunctionExpression => ({
type: ExpressionType.ArrowFunction,
expression: true,
generator: false,
async: false,
params: [{
type: SimpleType.Identifier,
name: tableName,
}],
params: [
{
type: SimpleType.Identifier,
name: tableName,
},
{
type: SimpleType.Identifier,
name: opName,
}],
body: {
type: ExpressionType.Call,
callee: makeMemberExpr(opName, op.type, false),
Expand Down
5 changes: 4 additions & 1 deletion src/modules/Aggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ export abstract class Aggregator {
type: AggregateType;
dataType = DataType.Null;

constructor(targetField: FieldDescription, name: string) {
constructor(targetField: FieldDescription, name?: string) {
this.field = targetField;
this.name = name;
}

abstract addUp(value: unknown): Aggregator;
abstract get value(): unknown;

isAnonymous() {
return name === undefined;
}
clone(): Aggregator {
const Ctor = this.constructor as any;
return new Ctor(this.field, this, name);
Expand Down
2 changes: 1 addition & 1 deletion src/typings/operators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FieldDescription } from './table';

export type AggregateDescription = {
type: AggregateType,
name: string;
name?: string;
field: FieldDescription,
}

Expand Down
3 changes: 1 addition & 2 deletions test/expression/operator.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { AggregateType } from 'Typings';
import * as op from '../../src/modules/operators';
import exprResolver from '../../src/expression';

Expand All @@ -15,6 +14,6 @@ describe('Operator', () => {
const resolved = exprResolver(expr);
expect(resolved).toBeInstanceOf(Function);
expect(resolved).not.toEqual(expr);
expect(`${resolved}`).toEqual("t => op.sum(t['price'])");
expect(`${resolved}`).toEqual("(t, op) => op.sum(t['price'])");
});
});

0 comments on commit a260090

Please sign in to comment.