@babel/types#numericLiteral TypeScript Examples
The following examples show how to use
@babel/types#numericLiteral.
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: rawObjectCompiler.ts From engine with MIT License | 6 votes |
rawObjectCompiler = (obj: any): ObjectExpression => {
const props = Object.keys(obj).reduce((acc, x) => {
let val: any = obj[x];
let result;
if (isString(val)) {
result = stringLiteral(val);
} else if (typeof val === "number") {
result = numericLiteral(toNumber(val));
} else if (isArray(val)) {
let list = val.map((x) => stringLiteral(x));
result = arrayExpression(list);
} else if (isPlainObject(val)) {
result = rawObjectCompiler(val);
} else {
throw new Error("Meta type for " + val + " not supported");
}
if (result) {
acc.push(objectProperty(identifier(x), result));
}
return acc;
}, [] as ObjectProperty[]);
return objectExpression(props);
}
Example #2
Source File: babel-polyfill.ts From nota with MIT License | 6 votes |
objectProperty = (
key: Expression | Identifier | StringLiteral | NumericLiteral,
value: Expression | PatternLike,
shorthand: boolean = false
): ObjectProperty => ({
type: "ObjectProperty",
key,
value,
computed: false,
shorthand,
...baseNode,
})
Example #3
Source File: valueOperationCompiler.ts From engine with MIT License | 5 votes |
valueOperationCompiler = (
op: ValueOperation
): ObjectExpression => {
let value = objectProperty(identifier("path"), stringLiteral("___"));
const type = objectProperty(identifier("type"), stringLiteral(op.type));
if (op.value.type === ValueTypes.CONST) {
const val = op.value.value;
let valType;
if (val && val.__node__) {
valType = val.__node__;
} else if (typeof val === "string") {
valType = stringLiteral(val);
} else if (typeof val === "number") {
valType = numericLiteral(val);
} else if (typeof val === "boolean") {
valType = booleanLiteral(val);
} else {
throw new Error("Value type not supported yet: " + typeof val);
}
value = objectProperty(
identifier("value"),
objectExpression([
objectProperty(identifier("type"), stringLiteral(ValueTypes.CONST)),
objectProperty(identifier("value"), valType),
])
);
} else if (
op.value.type === ValueTypes.EXTERNAL ||
op.value.type === ValueTypes.INTERNAL
) {
const path = arrayExpression(op.value.path.map((x) => stringLiteral(x)));
value = objectProperty(
identifier("value"),
objectExpression([
objectProperty(identifier("type"), stringLiteral(op.value.type)),
objectProperty(identifier("path"), path),
])
);
}
return objectExpression([type, value]);
}
Example #4
Source File: babel-polyfill.ts From nota with MIT License | 5 votes |
numericLiteral = (value: number): NumericLiteral => ({
type: "NumericLiteral",
value,
...baseNode,
})