Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80542 views
1
/**
2
* Copyright 2013 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
17
/*jslint node: true*/
18
19
/**
20
* Desugars ES6 Object Literal short notations into ES3 full notation.
21
*
22
* // Easier return values.
23
* function foo(x, y) {
24
* return {x, y}; // {x: x, y: y}
25
* };
26
*
27
* // Destructuring.
28
* function init({port, ip, coords: {x, y}}) { ... }
29
*
30
*/
31
var Syntax = require('esprima-fb').Syntax;
32
var utils = require('../src/utils');
33
34
/**
35
* @public
36
*/
37
function visitObjectLiteralShortNotation(traverse, node, path, state) {
38
utils.catchup(node.key.range[1], state);
39
utils.append(':' + node.key.name, state);
40
return false;
41
}
42
43
visitObjectLiteralShortNotation.test = function(node, path, state) {
44
return node.type === Syntax.Property &&
45
node.kind === 'init' &&
46
node.shorthand === true &&
47
path[0].type !== Syntax.ObjectPattern;
48
};
49
50
exports.visitorList = [
51
visitObjectLiteralShortNotation
52
];
53
54
55