Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81169 views
1
var defaults = {
2
// If you want to use a different branch of esprima, or any other
3
// module that supports a .parse function, pass that module object to
4
// recast.parse as options.esprima.
5
esprima: require("esprima-fb"),
6
7
// Number of spaces the pretty-printer should use per tab for
8
// indentation. If you do not pass this option explicitly, it will be
9
// (quite reliably!) inferred from the original code.
10
tabWidth: 4,
11
12
// If you really want the pretty-printer to use tabs instead of
13
// spaces, make this option true.
14
useTabs: false,
15
16
// The reprinting code leaves leading whitespace untouched unless it
17
// has to reindent a line, or you pass false for this option.
18
reuseWhitespace: true,
19
20
// Some of the pretty-printer code (such as that for printing function
21
// parameter lists) makes a valiant attempt to prevent really long
22
// lines. You can adjust the limit by changing this option; however,
23
// there is no guarantee that line length will fit inside this limit.
24
wrapColumn: 74, // Aspirational for now.
25
26
// Pass a string as options.sourceFileName to recast.parse to tell the
27
// reprinter to keep track of reused code so that it can construct a
28
// source map automatically.
29
sourceFileName: null,
30
31
// Pass a string as options.sourceMapName to recast.print, and
32
// (provided you passed options.sourceFileName earlier) the
33
// PrintResult of recast.print will have a .map property for the
34
// generated source map.
35
sourceMapName: null,
36
37
// If provided, this option will be passed along to the source map
38
// generator as a root directory for relative source file paths.
39
sourceRoot: null,
40
41
// If you provide a source map that was generated from a previous call
42
// to recast.print as options.inputSourceMap, the old source map will
43
// be composed with the new source map.
44
inputSourceMap: null,
45
46
// If you want esprima to generate .range information (recast only
47
// uses .loc internally), pass true for this option.
48
range: false,
49
50
// If you want esprima not to throw exceptions when it encounters
51
// non-fatal errors, keep this option true.
52
tolerant: true,
53
54
// If you want to override the quotes used in string literals, specify
55
// either "single", "double", or "auto" here ("auto" will select the one
56
// which results in the shorter literal)
57
// Otherwise, the input marks will be preserved
58
quote: null,
59
}, hasOwn = defaults.hasOwnProperty;
60
61
// Copy options and fill in default values.
62
exports.normalize = function(options) {
63
options = options || defaults;
64
65
function get(key) {
66
return hasOwn.call(options, key)
67
? options[key]
68
: defaults[key];
69
}
70
71
return {
72
tabWidth: +get("tabWidth"),
73
useTabs: !!get("useTabs"),
74
reuseWhitespace: !!get("reuseWhitespace"),
75
wrapColumn: Math.max(get("wrapColumn"), 0),
76
sourceFileName: get("sourceFileName"),
77
sourceMapName: get("sourceMapName"),
78
sourceRoot: get("sourceRoot"),
79
inputSourceMap: get("inputSourceMap"),
80
esprima: get("esprima"),
81
range: get("range"),
82
tolerant: get("tolerant"),
83
quote: get("quote"),
84
};
85
};
86
87