Skip to content

Commit 951bfef

Browse files
author
Ethan Cohen
committed
[fix] - Add expression handler for ThisExpression
Fixes #41
1 parent b131df7 commit 951bfef

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
/**
4+
* Extractor function for a ThisExpression type value node.
5+
* A this expression is using `this` as an identifier.
6+
*
7+
* @returns - 'this' as a string.
8+
*/
9+
export default function extractValueFromThisExpression() {
10+
return 'this';
11+
}

src/util/values/expressions/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import LogicalExpression from './LogicalExpression';
1010
import MemberExpression from './MemberExpression';
1111
import CallExpression from './CallExpression';
1212
import UnaryExpression from './UnaryExpression';
13-
13+
import ThisExpression from './ThisExpression';
1414

1515

1616

@@ -24,7 +24,8 @@ const TYPES = {
2424
LogicalExpression,
2525
MemberExpression,
2626
CallExpression,
27-
UnaryExpression
27+
UnaryExpression,
28+
ThisExpression
2829
};
2930

3031
const noop = () => null;
@@ -50,7 +51,8 @@ const LITERAL_TYPES = assign({}, TYPES, {
5051
UnaryExpression: value => {
5152
const extractedVal = TYPES.UnaryExpression(value);
5253
return extractedVal === undefined ? null : extractedVal;
53-
}
54+
},
55+
ThisExpression: noop
5456
});
5557

5658
/**

tests/src/rules/href-no-hash.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ ruleTester.run('href-no-hash', rule, {
4949
{ code: '<a href={"foo"}/>', parserOptions },
5050
{ code: '<a href="#foo" />', parserOptions },
5151
{ code: '<UX.Layout>test</UX.Layout>', parserOptions },
52+
{ code: '<a href={this} />', parserOptions },
5253

5354
// CUSTOM ELEMENT TEST FOR STRING OPTION
5455
{ code: '<Link />;', options: string, parserOptions },

0 commit comments

Comments
 (0)