UNPKG

3.27 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3class Variable {
4 constructor(name, nameRange, range, modifier, modifierRange, substitutionParameter, substitutionRange, defined, buildVariable, stringValue) {
5 this.name = name;
6 this.nameRange = nameRange;
7 this.range = range;
8 this.modifier = modifier;
9 this.modifierRange = modifierRange;
10 this.substitutionParameter = substitutionParameter;
11 this.substitutionRange = substitutionRange;
12 this.defined = defined;
13 this.buildVariable = buildVariable;
14 this.stringValue = stringValue;
15 }
16 toString() {
17 return this.stringValue;
18 }
19 getName() {
20 return this.name;
21 }
22 getNameRange() {
23 return this.nameRange;
24 }
25 /**
26 * Returns the range of the entire variable. This includes the symbols for
27 * the declaration of the variable such as the $, {, and } symbols.
28 *
29 * @return the range in the document that this variable encompasses in its
30 * entirety
31 */
32 getRange() {
33 return this.range;
34 }
35 /**
36 * Returns the modifier character that has been set for
37 * specifying how this variable should be expanded and resolved.
38 * If this variable is ${variable:+value} then the modifier
39 * character is '+'. Will be the empty string if the variable is
40 * declared as ${variable:}. Otherwise, will be null if this
41 * variable will not use variable substitution at all (such as
42 * ${variable} or $variable).
43 *
44 * @return this variable's modifier character, or the empty
45 * string if it does not have one, or null if this
46 * variable will not use variable substitution
47 */
48 getModifier() {
49 return this.modifier;
50 }
51 getModifierRange() {
52 return this.modifierRange;
53 }
54 /**
55 * Returns the parameter that will be used for substitution if
56 * this variable uses modifiers to define how its value should be
57 * resolved. If this variable is ${variable:+value} then the
58 * substitution value will be 'value'. Will be the empty string
59 * if the variable is declared as ${variable:+} or some other
60 * variant where the only thing that follows the modifier
61 * character (excluding considerations of escape characters and
62 * so on) is the variable's closing bracket. May be null if this
63 * variable does not have a modifier character defined (such as
64 * ${variable} or $variable).
65 *
66 * @return this variable's substitution parameter, or the empty
67 * string if it does not have one, or null if there is
68 * not one defined
69 */
70 getSubstitutionParameter() {
71 return this.substitutionParameter;
72 }
73 getSubstitutionRange() {
74 return this.substitutionRange;
75 }
76 /**
77 * Returns whether this variable has been defined or not.
78 *
79 * @return true if this variable has been defined, false otherwise
80 */
81 isDefined() {
82 return this.defined;
83 }
84 isBuildVariable() {
85 return this.buildVariable === true;
86 }
87 isEnvironmentVariable() {
88 return this.buildVariable === false;
89 }
90}
91exports.Variable = Variable;