summaryrefslogtreecommitdiff
path: root/tools/eslint/lib/util/estraverse.js
blob: 53015fe06794af7f6d7d890fb7f83dd8b81b58ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
 * @fileoverview Patch for estraverse
 * @author Toru Nagashima
 * @copyright 2015 Toru Nagashima. All rights reserved.
 * See LICENSE file in root directory for full license.
 */
"use strict";

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

var estraverse = require("estraverse"),
    jsxKeys = require("estraverse-fb/keys");

//------------------------------------------------------------------------------
// Helers
//------------------------------------------------------------------------------

var experimentalKeys = {
    ExperimentalRestProperty: ["argument"],
    ExperimentalSpreadProperty: ["argument"]
};

/**
 * Adds a given keys to Syntax and VisitorKeys of estraverse.
 *
 * @param {object} keys - Key definitions to add.
 *   This is an object as map.
 *   Keys are the node type.
 *   Values are an array of property names to visit.
 * @returns {void}
 */
function installKeys(keys) {
    for (var key in keys) {
        if (keys.hasOwnProperty(key)) {
            estraverse.Syntax[key] = key;
            if (keys[key]) {
                estraverse.VisitorKeys[key] = keys[key];
            }
        }
    }
}

// Add JSX node types.
installKeys(jsxKeys);
// Add Experimental node types.
installKeys(experimentalKeys);

//------------------------------------------------------------------------------
// Public Interface
//------------------------------------------------------------------------------

module.exports = estraverse;