react / wstein / node_modules / react / node_modules / envify / node_modules / jstransform / visitors / reserved-words-visitors.js
80540 views/**1* Copyright 2014 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*15*/16/*global exports:true*/1718var Syntax = require('esprima-fb').Syntax;19var utils = require('../src/utils');20var reserverdWordsHelper = require('./reserved-words-helper');2122/**23* Code adapted from https://github.com/spicyj/es3ify24* The MIT License (MIT)25* Copyright (c) 2014 Ben Alpert26*/2728function visitProperty(traverse, node, path, state) {29utils.catchup(node.key.range[0], state);30utils.append('"', state);31utils.catchup(node.key.range[1], state);32utils.append('"', state);33utils.catchup(node.value.range[0], state);34traverse(node.value, path, state);35return false;36}3738visitProperty.test = function(node) {39return node.type === Syntax.Property &&40node.key.type === Syntax.Identifier &&41!node.method &&42!node.shorthand &&43!node.computed &&44reserverdWordsHelper.isES3ReservedWord(node.key.name);45};4647function visitMemberExpression(traverse, node, path, state) {48traverse(node.object, path, state);49utils.catchup(node.property.range[0] - 1, state);50utils.append('[', state);51utils.catchupWhiteSpace(node.property.range[0], state);52utils.append('"', state);53utils.catchup(node.property.range[1], state);54utils.append('"]', state);55return false;56}5758visitMemberExpression.test = function(node) {59return node.type === Syntax.MemberExpression &&60node.property.type === Syntax.Identifier &&61reserverdWordsHelper.isES3ReservedWord(node.property.name);62};6364exports.visitorList = [65visitProperty,66visitMemberExpression67];686970