index.js
function literalNode (value) {
  if (value === undefined) {
    return {
      type: 'Identifier',
      name: 'undefined'
    };
  }
  else if (typeof value == 'function') {
    throw Error('Unist property contains a function');
  }
  else if (value === null || typeof value != 'object') {
    return {
      type: 'Literal',
      value: value
    };
  }
  else if (Array.isArray(value)) {
    return {
      type: 'ArrayExpression',
      elements: value.map(literalNode)
    };
  }
  else {
    return {
      type: 'ObjectExpression',
      properties: Object.keys(value).map(function (key) {
        return {
          type: 'Property',
          key: {
            type: 'Identifier',
            name: key
          },
          value: literalNode(value[key])
        };
      })
    };
  }
}
function literalNode (value) {
  if (value === undefined) {
    return {
      type: 'Identifier',
      name: 'undefined'
    };
  }
  else if (typeof value == 'function') {
    throw Error('Unist property contains a function');
  }
  else if (value === null || typeof value != 'object') {
    return {
      type: 'Literal',
      value: value
    };
  }
  else if (Array.isArray(value)) {
    return {
      type: 'ArrayExpression',
      elements: value.map(literalNode)
    };
  }
  else {
    return {
      type: 'ObjectExpression',
      properties: Object.keys(value).map(function (key) {
        return {
          type: 'Property',
          key: {
            type: 'Identifier',
            name: key
          },
          value: literalNode(value[key])
        };
      })
    };
  }
}
function literalNode ( value ) { if ( value === undefined ) { return { type : 'Identifier' , name : 'undefined' } ; } else if ( typeof value == 'function' ) { throw Error ( 'Unist property contains a function' ) ; } else if ( value === null || typeof value != 'object' ) { return { type : 'Literal' , value : value } ; } else if ( Array . isArray ( value ) ) { return { type : 'ArrayExpression' , elements : value . map ( literalNode ) } ; } else { return { type : 'ObjectExpression' , properties : Object . keys ( value ) . map ( function ( key ) { return { type : 'Property' , key : { type : 'Identifier' , name : key } , value : literalNode ( value [ key ] ) } ; } ) } ; } }
Create ESTree node representing particular JavaScript literal.
Create ESTree node representing particular JavaScript literal .