Skip to content

Commit 1bcc976

Browse files
iwehrmanmarijnh
authored andcommitted
track global variables alongside locals in the parser state
1 parent 2c6294f commit 1bcc976

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

mode/javascript/javascript.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,19 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
196196
return true;
197197
}
198198
function register(varname) {
199+
function inList(list) {
200+
for (var v = list; v; v = v.next)
201+
if (v.name == varname) return true;
202+
return false;
203+
}
199204
var state = cx.state;
200205
if (state.context) {
201206
cx.marked = "def";
202-
for (var v = state.localVars; v; v = v.next)
203-
if (v.name == varname) return;
207+
if (inList(state.localVars)) return;
204208
state.localVars = {name: varname, next: state.localVars};
209+
} else {
210+
if (inList(state.globalVars)) return;
211+
state.globalVars = {name: varname, next: state.globalVars};
205212
}
206213
}
207214

@@ -364,6 +371,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
364371
cc: [],
365372
lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false),
366373
localVars: parserConfig.localVars,
374+
globalVars: parserConfig.globalVars,
367375
context: parserConfig.localVars && {vars: parserConfig.localVars},
368376
indented: 0
369377
};

0 commit comments

Comments
 (0)