Skip to content

Commit 5e26ee3

Browse files
author
Chris K
committed
Additional fix for DFL-3310, added some tests and fixed a regression.
1 parent f1e6d2a commit 5e26ee3

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

src/repl/propertyfinder.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,32 +61,29 @@ window.cls.PropertyFinder = function(rt_id) {
6161
this._find_input_parts = function(input)
6262
{
6363
var tokens = [];
64-
6564
this._parser.tokenize(input, function(token_type, token)
6665
{
6766
tokens.push([token_type, token]);
6867
});
69-
7068
var last_bracket = this._get_last_token(tokens, PUNCTUATOR, '[');
7169
var last_brace = this._get_last_token(tokens, PUNCTUATOR, '(');
72-
7370
last_brace = this._get_last_token(tokens, PUNCTUATOR, ')') <= last_brace
7471
? last_brace
7572
: -1;
7673
last_bracket = this._get_last_token(tokens, PUNCTUATOR, ']') <= last_bracket
7774
? last_bracket
7875
: -1;
79-
input = input.slice(Math.max(last_brace,
80-
last_bracket,
81-
this._get_last_token(tokens, PUNCTUATOR, '='),
82-
this._get_last_token(tokens, IDENTIFIER, 'in')));
76+
var pos = Math.max(last_brace,
77+
last_bracket,
78+
this._get_last_token(tokens, PUNCTUATOR, '='),
79+
this._get_last_token(tokens, IDENTIFIER, 'in'));
80+
if (pos > -1)
81+
input = input.slice(pos);
8382
input = input.replace(/^\s+/, '');
84-
8583
var last_dot = input.lastIndexOf('.');
8684
var new_path = '';
8785
var new_id = '';
8886
var ret = '';
89-
9087
if(last_dot > -1)
9188
{
9289
new_path = input.slice(0, last_dot);
@@ -96,7 +93,6 @@ window.cls.PropertyFinder = function(rt_id) {
9693
{
9794
new_id = input;
9895
}
99-
10096
return {scope: new_path, identifier: new_id, input: input};
10197
};
10298

tests/propertyfinder.qunit.html

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
<link rel="stylesheet" href="qunit/qunit.css" media="screen">
66
<script src="qunit/qunit.js"></script>
77
<script src="../src/lib/json.js"></script>
8+
<script src="../src/syntaxhighlight/js/syntax.js"></script>
9+
<script src="../src/syntaxhighlight/js/tokenizer.js"></script>
810
<script src="../src/repl/propertyfinder.js"></script>
911
<script>
1012

1113
test("Input scope smoketest", function() {
12-
var fp = new cls.PropertyFinder()._find_input_parts;
14+
var propfinder = new cls.PropertyFinder();
15+
var fp = propfinder._find_input_parts.bind(propfinder);
1316
var parts;
1417

1518
parts = fp("foo");
@@ -40,6 +43,30 @@
4043
equal(parts.scope, "bar");
4144
equal(parts.identifier, "baz");
4245

46+
parts = fp("foo().bar.baz");
47+
equal(parts.scope, "foo().bar");
48+
equal(parts.identifier, "baz");
49+
50+
parts = fp("foo(bar.baz");
51+
equal(parts.scope, "bar");
52+
equal(parts.identifier, "baz");
53+
54+
parts = fp("foo = bar.baz");
55+
equal(parts.scope, "bar");
56+
equal(parts.identifier, "baz");
57+
58+
parts = fp("foo in baz");
59+
equal(parts.scope, "");
60+
equal(parts.identifier, "baz");
61+
62+
parts = fp("foo in bar.baz");
63+
equal(parts.scope, "bar");
64+
equal(parts.identifier, "baz");
65+
66+
parts = fp("foo = bar(baz");
67+
equal(parts.scope, "");
68+
equal(parts.identifier, "baz");
69+
4370
});
4471

4572
</script>

0 commit comments

Comments
 (0)