Skip to content

Commit

Permalink
ignore this in field definition value (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
LongTengDao authored Aug 31, 2022
1 parent eb1ce8c commit badc24f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
10 changes: 3 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ function declaresArguments(node) {
return node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration';
}

function declaresThis(node) {
return node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration';
}

function reallyParse(source, options) {
var parseOptions = Object.assign({}, options,
{
Expand Down Expand Up @@ -159,9 +155,9 @@ function findGlobals(source, options) {
'Identifier': identifier,
'ThisExpression': function (node, parents) {
for (var i = 0; i < parents.length; i++) {
if (declaresThis(parents[i])) {
return;
}
var parent = parents[i];
if ( parent.type === 'FunctionExpression' || parent.type === 'FunctionDeclaration' ) { return; }
if ( parent.type === 'PropertyDefinition' && parents[i+1]===parent.value ) { return; }
}
node.parents = parents.slice();
globals.push(node);
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/class-field-definition-this.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class MyClass {
prop = this;
}
3 changes: 3 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ test('class.js - ES2015 classes', function () {
test('class-expression.js - class as expression', function () {
assert.deepEqual(detect(read('class-expression.js')), []);
});
test('class-field-definition-this.js - this in field value', function () {
assert.deepEqual(detect(read('class-field-definition-this.js')), []);
});
test('default-argument.js - ES2015 default argument', function () {
assert.deepEqual(detect(read('default-argument.js')).map(nameOf), ['c', 'h', 'j', 'k']);
});
Expand Down

0 comments on commit badc24f

Please sign in to comment.