react / wstein / node_modules / react / node_modules / envify / node_modules / jstransform / visitors / __tests__ / reserved-words-test.js
80552 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* @emails [email protected]16*/1718/*jshint evil:true*/1920jest.autoMockOff();2122describe('reserved-words', function() {23var transformFn;24var visitors;2526beforeEach(function() {27require('mock-modules').dumpCache();28visitors = require('../reserved-words-visitors').visitorList;29transformFn = require('../../src/jstransform').transform;30});3132function transform(code, opts) {33// No need for visitors as long as we are not in es5 mode.34return transformFn(visitors, code, opts).code;35}3637describe('reserved words in member expressions', function() {38it('should transform to reserved word members to computed', function() {39var code = 'foo.delete;';4041expect(transform(code)).toEqual('foo["delete"];');4243code = '(foo++).delete;';44expect(transform(code)).toEqual('(foo++)["delete"];');45});4647it('should handle call expressions', function() {48var code = 'foo.return();';4950expect(transform(code)).toEqual('foo["return"]();');51});5253it('should only quote ES3 reserved words', function() {54var code = 'foo.await();';5556expect(transform(code)).toEqual('foo.await();');57});58});5960describe('reserved words in properties', function() {61it('should quote reserved words in properties', function() {62var code = 'var x = {null: 1};';6364expect(transform(code)).toEqual('var x = {"null": 1};');65});6667it('should only quote ES3 reserved words', function() {68var code = 'var x = {await: 1};';6970expect(transform(code)).toEqual('var x = {await: 1};');71});72});73});747576