source: trip-planner-front/node_modules/eslint-scope/lib/reference.js@ 571e0df

Last change on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 4.7 KB
RevLine 
[6a3a178]1/*
2 Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>
3
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are met:
6
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12
13 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
17 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23*/
24"use strict";
25
26const READ = 0x1;
27const WRITE = 0x2;
28const RW = READ | WRITE;
29
30/**
31 * A Reference represents a single occurrence of an identifier in code.
32 * @class Reference
33 */
34class Reference {
35 constructor(ident, scope, flag, writeExpr, maybeImplicitGlobal, partial, init) {
36
37 /**
38 * Identifier syntax node.
39 * @member {espreeIdentifier} Reference#identifier
40 */
41 this.identifier = ident;
42
43 /**
44 * Reference to the enclosing Scope.
45 * @member {Scope} Reference#from
46 */
47 this.from = scope;
48
49 /**
50 * Whether the reference comes from a dynamic scope (such as 'eval',
51 * 'with', etc.), and may be trapped by dynamic scopes.
52 * @member {boolean} Reference#tainted
53 */
54 this.tainted = false;
55
56 /**
57 * The variable this reference is resolved with.
58 * @member {Variable} Reference#resolved
59 */
60 this.resolved = null;
61
62 /**
63 * The read-write mode of the reference. (Value is one of {@link
64 * Reference.READ}, {@link Reference.RW}, {@link Reference.WRITE}).
65 * @member {number} Reference#flag
66 * @private
67 */
68 this.flag = flag;
69 if (this.isWrite()) {
70
71 /**
72 * If reference is writeable, this is the tree being written to it.
73 * @member {espreeNode} Reference#writeExpr
74 */
75 this.writeExpr = writeExpr;
76
77 /**
78 * Whether the Reference might refer to a partial value of writeExpr.
79 * @member {boolean} Reference#partial
80 */
81 this.partial = partial;
82
83 /**
84 * Whether the Reference is to write of initialization.
85 * @member {boolean} Reference#init
86 */
87 this.init = init;
88 }
89 this.__maybeImplicitGlobal = maybeImplicitGlobal;
90 }
91
92 /**
93 * Whether the reference is static.
94 * @method Reference#isStatic
95 * @returns {boolean} static
96 */
97 isStatic() {
98 return !this.tainted && this.resolved && this.resolved.scope.isStatic();
99 }
100
101 /**
102 * Whether the reference is writeable.
103 * @method Reference#isWrite
104 * @returns {boolean} write
105 */
106 isWrite() {
107 return !!(this.flag & Reference.WRITE);
108 }
109
110 /**
111 * Whether the reference is readable.
112 * @method Reference#isRead
113 * @returns {boolean} read
114 */
115 isRead() {
116 return !!(this.flag & Reference.READ);
117 }
118
119 /**
120 * Whether the reference is read-only.
121 * @method Reference#isReadOnly
122 * @returns {boolean} read only
123 */
124 isReadOnly() {
125 return this.flag === Reference.READ;
126 }
127
128 /**
129 * Whether the reference is write-only.
130 * @method Reference#isWriteOnly
131 * @returns {boolean} write only
132 */
133 isWriteOnly() {
134 return this.flag === Reference.WRITE;
135 }
136
137 /**
138 * Whether the reference is read-write.
139 * @method Reference#isReadWrite
140 * @returns {boolean} read write
141 */
142 isReadWrite() {
143 return this.flag === Reference.RW;
144 }
145}
146
147/**
148 * @constant Reference.READ
149 * @private
150 */
151Reference.READ = READ;
152
153/**
154 * @constant Reference.WRITE
155 * @private
156 */
157Reference.WRITE = WRITE;
158
159/**
160 * @constant Reference.RW
161 * @private
162 */
163Reference.RW = RW;
164
165module.exports = Reference;
166
167/* vim: set sw=4 ts=4 et tw=80 : */
Note: See TracBrowser for help on using the repository browser.