-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use selected time range for metaqueries in DE
- Loading branch information
Showing
9 changed files
with
141 additions
and
60 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
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
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
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
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,36 @@ | ||
import {Expression} from 'src/types/ast' | ||
|
||
export const formatExpression = (expr: Expression): string => { | ||
switch (expr.type) { | ||
case 'DateTimeLiteral': | ||
case 'BooleanLiteral': | ||
case 'UnsignedIntegerLiteral': | ||
case 'IntegerLiteral': | ||
return String(expr.value) | ||
case 'StringLiteral': | ||
return `"${expr.value}"` | ||
case 'DurationLiteral': | ||
return expr.values.reduce( | ||
(acc, {magnitude, unit}) => `${acc}${magnitude}${unit}`, | ||
'' | ||
) | ||
case 'FloatLiteral': | ||
return String(expr.value).includes('.') | ||
? String(expr.value) | ||
: expr.value.toFixed(1) | ||
case 'UnaryExpression': | ||
return `${expr.operator}${formatExpression(expr.argument)}` | ||
case 'BinaryExpression': | ||
return `${formatExpression(expr.left)} ${ | ||
expr.operator | ||
} ${formatExpression(expr.right)}` | ||
case 'CallExpression': | ||
// This doesn't handle formatting a call expression with arguments, or | ||
// with any other sort of callee except an `Identifier` | ||
return `${formatExpression(expr.callee)}()` | ||
case 'Identifier': | ||
return expr.name | ||
default: | ||
throw new Error(`cant format expression of type ${expr.type}`) | ||
} | ||
} |
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