@babel/types#LogicalExpression TypeScript Examples
The following examples show how to use
@babel/types#LogicalExpression.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: valueParser.ts From engine with MIT License | 7 votes |
logicalExpression = (
babel: typeof Babel,
node: LogicalExpression
): FuncOperation => {
const t = babel.types;
const params: StaticOperation[] = [];
let temp: any = node;
while (temp.left) {
temp = temp.left;
if (!temp) {
temp = false;
} else {
if (t.isMemberExpression(temp)) {
const result = Values.MemberExpression(babel, temp) as StaticOperation;
if (result) {
params.push(result);
}
} else {
params.push({
type: OperationTypes.VALUE,
value: {
type: ValueTypes.CONST,
value: { __node__: temp },
},
});
}
}
}
// do right
return {
type: OperationTypes.FUNC,
value: {
params,
fn: () => {},
},
};
}
Example #2
Source File: valueParser.ts From engine with MIT License | 7 votes |
logicalExpression = (node: LogicalExpression): FuncOperation => {
const params: StaticOperation[] = [];
let temp: any = node;
while (temp.left) {
temp = temp.left;
if (!temp) {
temp = false;
} else {
if (isMemberExpression(temp)) {
const result = Values.MemberExpression(temp) as StaticOperation;
if (result) {
params.push(result);
}
} else {
params.push({
type: OperationTypes.VALUE,
value: {
type: ValueTypes.CONST,
value: { __node__: temp },
},
});
}
}
}
// do right
return {
type: OperationTypes.FUNC,
value: {
params,
fn: () => {},
},
};
}
Example #3
Source File: valueParser.ts From engine with MIT License | 5 votes |
Values: Values = {
// foo = get.foo.bar
MemberExpression: (babel, node) => {
const params = getMemberExpressionParams(babel, node);
const op = params[0] as PathType;
const rawPath = params.slice(1);
const path: InvokableValue[] = invokablePathValueParser(rawPath);
// TODO: Is path valid? e.g. get operations with invoke
if (op === PathType.GET) {
return {
type: OperationTypes.GET,
path,
} as GetOperation;
} else if (op === PathType.OBSERVE) {
return {
type: OperationTypes.OBSERVE,
path,
} as ObserveOperation;
} else if (op === PathType.UPDATE) {
return {
type: OperationTypes.UPDATE,
path,
} as UpdateOperation;
} else if (op === PathType.PROP) {
return {
type: OperationTypes.VALUE,
value: {
type: ValueTypes.EXTERNAL,
path: rawPath,
},
} as ValueOperation;
} else if (op === PathType.ARG) {
return {
type: OperationTypes.VALUE,
value: {
type: ValueTypes.INTERNAL,
path: rawPath,
},
} as ValueOperation;
} else {
return constValue({ __node__: node });
}
},
// foo = get.foo || get.bar
LogicalExpression: (babel, node) => {
return logicalExpression(babel, node);
},
// foo = get.foo ? true : false
ConditionalExpression: (babel, node) => {
return funcValue(node);
},
BinaryExpression: (babel, node) => {
return funcValue(node);
},
ObjectExpression: (babel, node) => {
const value = structParser(babel, node);
return value as StructOperation;
},
}
Example #4
Source File: valueParser.ts From engine with MIT License | 5 votes |
Values: Values = {
// foo = get.foo.bar
MemberExpression: (node) => {
const params = getMemberExpressionParams(node);
const op = params[0] as PathType;
const rawPath = params.slice(1);
const path: InvokableValue[] = invokablePathValueParser(rawPath);
// TODO: Is path valid? e.g. get operations with invoke
if (op === PathType.GET) {
return {
type: OperationTypes.GET,
path,
} as GetOperation;
} else if (op === PathType.OBSERVE) {
return {
type: OperationTypes.OBSERVE,
path,
} as ObserveOperation;
} else if (op === PathType.UPDATE) {
return {
type: OperationTypes.UPDATE,
path,
} as UpdateOperation;
} else if (op === PathType.PROP) {
return {
type: OperationTypes.VALUE,
value: {
type: ValueTypes.EXTERNAL,
path: rawPath,
},
} as ValueOperation;
} else if (op === PathType.ARG) {
return {
type: OperationTypes.VALUE,
value: {
type: ValueTypes.INTERNAL,
path: rawPath,
},
} as ValueOperation;
} else {
return constValue({ __node__: node });
}
},
// foo = get.foo || get.bar
LogicalExpression: (node) => {
return logicalExpression(node);
},
// foo = get.foo ? true : false
ConditionalExpression: (node) => {
return funcValue(node);
},
BinaryExpression: (node) => {
return funcValue(node);
},
ObjectExpression: (node) => {
const value = structParser(node);
return value as StructOperation;
},
}