Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80552 views
1
/**
2
* Copyright 2014 Facebook, Inc.
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*
16
* @emails [email protected]
17
*/
18
19
/*jshint evil:true*/
20
21
jest.autoMockOff();
22
23
describe('reserved-words', function() {
24
var transformFn;
25
var visitors;
26
27
beforeEach(function() {
28
require('mock-modules').dumpCache();
29
visitors = require('../reserved-words-visitors').visitorList;
30
transformFn = require('../../src/jstransform').transform;
31
});
32
33
function transform(code, opts) {
34
// No need for visitors as long as we are not in es5 mode.
35
return transformFn(visitors, code, opts).code;
36
}
37
38
describe('reserved words in member expressions', function() {
39
it('should transform to reserved word members to computed', function() {
40
var code = 'foo.delete;';
41
42
expect(transform(code)).toEqual('foo["delete"];');
43
44
code = '(foo++).delete;';
45
expect(transform(code)).toEqual('(foo++)["delete"];');
46
});
47
48
it('should handle call expressions', function() {
49
var code = 'foo.return();';
50
51
expect(transform(code)).toEqual('foo["return"]();');
52
});
53
54
it('should only quote ES3 reserved words', function() {
55
var code = 'foo.await();';
56
57
expect(transform(code)).toEqual('foo.await();');
58
});
59
});
60
61
describe('reserved words in properties', function() {
62
it('should quote reserved words in properties', function() {
63
var code = 'var x = {null: 1};';
64
65
expect(transform(code)).toEqual('var x = {"null": 1};');
66
});
67
68
it('should only quote ES3 reserved words', function() {
69
var code = 'var x = {await: 1};';
70
71
expect(transform(code)).toEqual('var x = {await: 1};');
72
});
73
});
74
});
75
76