react / wstein / node_modules / react / node_modules / envify / node_modules / jstransform / visitors / es6-object-short-notation-visitors.js
80542 views/**1* Copyright 2013 Facebook, Inc.2*3* Licensed under the Apache License, Version 2.0 (the "License");4* you may not use this file except in compliance with the License.5* You may obtain a copy of the License at6*7* http://www.apache.org/licenses/LICENSE-2.08*9* Unless required by applicable law or agreed to in writing, software10* distributed under the License is distributed on an "AS IS" BASIS,11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12* See the License for the specific language governing permissions and13* limitations under the License.14*/1516/*jslint node: true*/1718/**19* Desugars ES6 Object Literal short notations into ES3 full notation.20*21* // Easier return values.22* function foo(x, y) {23* return {x, y}; // {x: x, y: y}24* };25*26* // Destructuring.27* function init({port, ip, coords: {x, y}}) { ... }28*29*/30var Syntax = require('esprima-fb').Syntax;31var utils = require('../src/utils');3233/**34* @public35*/36function visitObjectLiteralShortNotation(traverse, node, path, state) {37utils.catchup(node.key.range[1], state);38utils.append(':' + node.key.name, state);39return false;40}4142visitObjectLiteralShortNotation.test = function(node, path, state) {43return node.type === Syntax.Property &&44node.kind === 'init' &&45node.shorthand === true &&46path[0].type !== Syntax.ObjectPattern;47};4849exports.visitorList = [50visitObjectLiteralShortNotation51];52535455