lib/runtime/values.js
function(value) {
        switch (values.typeOf(value)) {
            case 'Null':
                return { type: 'NullLiteral' };

            case 'Boolean':
                return { type: 'BooleanLiteral', value: value };

            case 'Number':
                if (value !== value) {
                    return { type: 'NaNLiteral' };
                } else if (value === Infinity) {
                    return { type: 'InfinityLiteral', negative: false };
                } else if (value === -Infinity) {
                    return { type: 'InfinityLiteral', negative: true };
                } else {
                    return { type: 'NumberLiteral', value: value };
                }
                break;   // silence ESLint

            case 'String':
                return { type: 'StringLiteral', value: value };

            case 'RegExp':
                return {
                    type: 'RegExpLiteral',
                    pattern: value.source,
                    flags: value.toString().match(/\/(\w*)$/)[1]
                };

            case 'Date':
                return { type: 'MomentLiteral', value: value.valueOf() };

            case 'Duration':
                return { type: 'DurationLiteral', value: value.valueOf() };

            case 'Filter':
                return { type: 'FilterLiteral', ast: value.ast, source: value.source };

            case 'Array':
                return { type: 'ArrayLiteral', elements: _.map(value, values.toAST) };

            case 'Object':
                return {
                    type: 'ObjectLiteral',
                    properties: _.map(value, function(value, key) {
                        return {
                            type: 'ObjectProperty',
                            key: values.toAST(key),
                            value: values.toAST(value)
                        };
                    })
                };
        }
    }
function(value) {
        switch (values.typeOf(value)) {
            case 'Null':
                return { type: 'NullLiteral' };

            case 'Boolean':
                return { type: 'BooleanLiteral', value: value };

            case 'Number':
                if (value !== value) {
                    return { type: 'NaNLiteral' };
                } else if (value === Infinity) {
                    return { type: 'InfinityLiteral', negative: false };
                } else if (value === -Infinity) {
                    return { type: 'InfinityLiteral', negative: true };
                } else {
                    return { type: 'NumberLiteral', value: value };
                }
                break;   // silence ESLint

            case 'String':
                return { type: 'StringLiteral', value: value };

            case 'RegExp':
                return {
                    type: 'RegExpLiteral',
                    pattern: value.source,
                    flags: value.toString().match(/\/(\w*)$/)[1]
                };

            case 'Date':
                return { type: 'MomentLiteral', value: value.valueOf() };

            case 'Duration':
                return { type: 'DurationLiteral', value: value.valueOf() };

            case 'Filter':
                return { type: 'FilterLiteral', ast: value.ast, source: value.source };

            case 'Array':
                return { type: 'ArrayLiteral', elements: _.map(value, values.toAST) };

            case 'Object':
                return {
                    type: 'ObjectLiteral',
                    properties: _.map(value, function(value, key) {
                        return {
                            type: 'ObjectProperty',
                            key: values.toAST(key),
                            value: values.toAST(value)
                        };
                    })
                };
        }
    }
function ( value ) { switch ( values . typeOf ( value ) ) { case 'Null' : return { type : 'NullLiteral' } ; case 'Boolean' : return { type : 'BooleanLiteral' , value : value } ; case 'Number' : if ( value !== value ) { return { type : 'NaNLiteral' } ; } else if ( value === Infinity ) { return { type : 'InfinityLiteral' , negative : false } ; } else if ( value === - Infinity ) { return { type : 'InfinityLiteral' , negative : true } ; } else { return { type : 'NumberLiteral' , value : value } ; } break ; // silence ESLint case 'String' : return { type : 'StringLiteral' , value : value } ; case 'RegExp' : return { type : 'RegExpLiteral' , pattern : value . source , flags : value . toString ( ) . match ( / \/(\w*)$ / ) [ 1 ] } ; case 'Date' : return { type : 'MomentLiteral' , value : value . valueOf ( ) } ; case 'Duration' : return { type : 'DurationLiteral' , value : value . valueOf ( ) } ; case 'Filter' : return { type : 'FilterLiteral' , ast : value . ast , source : value . source } ; case 'Array' : return { type : 'ArrayLiteral' , elements : _ . map ( value , values . toAST ) } ; case 'Object' : return { type : 'ObjectLiteral' , properties : _ . map ( value , function ( value , key ) { return { type : 'ObjectProperty' , key : values . toAST ( key ) , value : values . toAST ( value ) } ; } ) } ; } }
Returns an AST corresponding to a Juttle value.
Returns an AST corresponding to a Juttle value .