77
88/**
99 * This class contains the state at a specified offset into a file
10- * @public @constructor scope
10+ * @public
11+ * @constructor Scope
1112 * @property {file } file {@link FILE.md|:link: }
1213 * @property {Integer } offset
1314 * @property {namespace } namespace {@link NAMESPACE.md|:link: }
1718 * @property {method|null } method {@link METHOD.md|:link: }
1819 * @property {function|null } function {@link FUNCTION.md|:link: }
1920 */
20- var scope = function ( file , offset ) {
21+ var Scope = function ( file , offset ) {
2122
22- this . file = file ;
23- this . offset = offset ;
24- this . namespace = null ;
25- this . class = null ;
26- this . trait = null ;
27- this . interface = null ;
28- this . method = null ;
29- this . function = null ;
30- this . variables = [ ] ;
23+ this . file = file ;
24+ this . offset = offset ;
25+ this . namespace = null ;
26+ this . class = null ;
27+ this . trait = null ;
28+ this . interface = null ;
29+ this . method = null ;
30+ this . function = null ;
31+ this . variables = [ ] ;
32+
33+ // scanning file scope
34+ file . eachNode ( function ( node ) {
35+ if ( node . position && node . position . hit ( offset ) ) {
36+ if ( node . type === 'namespace' ) {
37+ this . namespace = node ;
38+ // this.variables = this.variables.concat(node.variables);
39+ } else if ( node . type === 'class' ) {
40+ this . class = node ;
41+ } else if ( node . type === 'interface' ) {
42+ this . interface = node ;
43+ } else if ( node . type === 'trait' ) {
44+ this . trait = node ;
45+ } else if ( node . type === 'function' ) {
46+ this . function = node ;
47+ } else if ( node . type === 'method' ) {
48+ this . method = node ;
49+ } else if ( node . variables ) {
50+ // this.variables = this.variables.concat(node.variables);
51+ }
52+ }
53+ } ) ;
3154
32- // scanning file scope
33- for ( var i = 0 ; i < file . nodes . length ; i ++ ) {
34- var node = file . nodes [ i ] ;
35- if ( node . position && node . position . hit ( offset ) ) {
36- if ( node . type === 'namespace' ) {
37- this . namespace = node ;
38- this . variables = this . variables . concat ( node . variables ) ;
39- } else if ( node . type === 'class' ) {
40- this . class = node ;
41- } else if ( node . type === 'interface' ) {
42- this . interface = node ;
43- } else if ( node . type === 'trait' ) {
44- this . trait = node ;
45- } else if ( node . type === 'function' ) {
46- this . function = node ;
47- } else if ( node . type === 'method' ) {
48- this . method = node ;
49- } else if ( node . variables ) {
50- this . variables = this . variables . concat ( node . variables ) ;
51- }
52- }
53- }
5455} ;
5556
5657/**
5758 * Gets variables depending on current state
5859 * @return {variable[]|null } {@link VARIABLE.md|:link: }
5960 */
60- scope . prototype . getVariables = function ( ) {
61+ Scope . prototype . getVariables = function ( ) {
6162 // scope restricted
6263 if ( this . method ) {
6364 return this . method . variables ;
@@ -68,4 +69,4 @@ scope.prototype.getVariables = function() {
6869 return this . variables ;
6970} ;
7071
71- module . exports = scope ;
72+ module . exports = Scope ;
0 commit comments