All files / transform/passes FoldFiniteIntegerRange.js

66.67% Statements 2/3
0% Branches 0/3
33.33% Functions 1/3
66.67% Lines 2/3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51          1x                                                                             19x            
import Transformation from '../transformation.js';
import TokenType from '../../parser/vsltokentype';
import t from '../../parser/nodes';
 
/** @private */
const MAX_SAFE_LEN = Number.MAX_SAFE_INTEGER.toString().length - 1;
 
/** @private */
function isSafeInteger(node: Node): bool {
    return node instanceof t.Literal && node.type === TokenType.Integer &&
        node.literal.length <= MAX_SAFE_LEN;
}
 
/**
 * Transforms any finite with raw `VSLNodeType.Integer`s ({@link VSLNodeType})
 * 
 * Note: This won't apply for complex intger types as those wouldn't be the same
 * AST node as {@link Literal} only applies to simple literals.
 * 
 * This will transform integers within the bounds of a private `MAX_SAFE_LEN` which
 * is 15 on most platforms, set to: `Number.MAX_SAFE_INTEGER.toString().length - 1`.
 * A number is checked on whether it's string length exceedes this range. Due to 
 * integer promotion, it is not exactly safe to rely on the bounded Integer type
 * and therefore string types are used.
 * 
 * @example
 * BinaryExpression {
 *   lhs: Literal { literal: "1", type: Integer }, 
 *   rhs: Literal { literal: "3", type: Integer },
 *   op: "..."
 * }
 * 
 * =>
 * 
 * ArrayLiteral {
 *   data: [
 *     Literal { literal: "1", type: Integer },
 *     Literal { literal: "2", type: Integer },
 *     Literal { literal: "3", type: Integer }
 *   ]
 * }
 */
export default class FoldFiniteIntegerRange extends Transformation {
    constructor() {
        super(t.BinaryExpression, "Optimize::FoldFiniteIntegerRange");
    }
    
    modify(node: Node, tool: ASTTool) {
        
    }
}