Skip to content

Commit 99ad49b

Browse files
maciej-katmcw
authored andcommitted
fix: lends with object property using literal key (#1035)
1 parent e1528c4 commit 99ad49b

File tree

3 files changed

+168
-11
lines changed

3 files changed

+168
-11
lines changed

__tests__/__snapshots__/test.js.snap

Lines changed: 161 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19116,7 +19116,7 @@ Array [
1911619116
"loc": Object {
1911719117
"end": Object {
1911819118
"column": 2,
19119-
"line": 26,
19119+
"line": 28,
1912019120
},
1912119121
"start": Object {
1912219122
"column": 0,
@@ -19194,17 +19194,124 @@ Array [
1919419194
"global": Array [],
1919519195
"inner": Array [],
1919619196
"instance": Array [
19197+
Object {
19198+
"augments": Array [],
19199+
"context": Object {
19200+
"loc": Object {
19201+
"end": Object {
19202+
"column": 20,
19203+
"line": 10,
19204+
},
19205+
"start": Object {
19206+
"column": 4,
19207+
"line": 10,
19208+
},
19209+
},
19210+
},
19211+
"description": Object {
19212+
"children": Array [
19213+
Object {
19214+
"children": Array [
19215+
Object {
19216+
"position": Object {
19217+
"end": Object {
19218+
"column": 9,
19219+
"line": 1,
19220+
"offset": 8,
19221+
},
19222+
"indent": Array [],
19223+
"start": Object {
19224+
"column": 1,
19225+
"line": 1,
19226+
"offset": 0,
19227+
},
19228+
},
19229+
"type": "text",
19230+
"value": "My field",
19231+
},
19232+
],
19233+
"position": Object {
19234+
"end": Object {
19235+
"column": 9,
19236+
"line": 1,
19237+
"offset": 8,
19238+
},
19239+
"indent": Array [],
19240+
"start": Object {
19241+
"column": 1,
19242+
"line": 1,
19243+
"offset": 0,
19244+
},
19245+
},
19246+
"type": "paragraph",
19247+
},
19248+
],
19249+
"position": Object {
19250+
"end": Object {
19251+
"column": 9,
19252+
"line": 1,
19253+
"offset": 8,
19254+
},
19255+
"start": Object {
19256+
"column": 1,
19257+
"line": 1,
19258+
"offset": 0,
19259+
},
19260+
},
19261+
"type": "root",
19262+
},
19263+
"errors": Array [],
19264+
"examples": Array [],
19265+
"loc": Object {
19266+
"end": Object {
19267+
"column": 19,
19268+
"line": 9,
19269+
},
19270+
"start": Object {
19271+
"column": 4,
19272+
"line": 9,
19273+
},
19274+
},
19275+
"memberof": "TheClass",
19276+
"members": Object {
19277+
"events": Array [],
19278+
"global": Array [],
19279+
"inner": Array [],
19280+
"instance": Array [],
19281+
"static": Array [],
19282+
},
19283+
"name": "my-field",
19284+
"namespace": "TheClass#my-field",
19285+
"params": Array [],
19286+
"path": Array [
19287+
Object {
19288+
"kind": "class",
19289+
"name": "TheClass",
19290+
},
19291+
Object {
19292+
"name": "my-field",
19293+
"scope": "instance",
19294+
},
19295+
],
19296+
"properties": Array [],
19297+
"returns": Array [],
19298+
"scope": "instance",
19299+
"sees": Array [],
19300+
"tags": Array [],
19301+
"throws": Array [],
19302+
"todos": Array [],
19303+
},
1919719304
Object {
1919819305
"augments": Array [],
1919919306
"context": Object {
1920019307
"loc": Object {
1920119308
"end": Object {
1920219309
"column": 5,
19203-
"line": 16,
19310+
"line": 18,
1920419311
},
1920519312
"start": Object {
1920619313
"column": 4,
19207-
"line": 14,
19314+
"line": 16,
1920819315
},
1920919316
},
1921019317
},
@@ -19266,11 +19373,11 @@ Array [
1926619373
"loc": Object {
1926719374
"end": Object {
1926819375
"column": 7,
19269-
"line": 13,
19376+
"line": 15,
1927019377
},
1927119378
"start": Object {
1927219379
"column": 4,
19273-
"line": 9,
19380+
"line": 11,
1927419381
},
1927519382
},
1927619383
"memberof": "TheClass",
@@ -19451,11 +19558,11 @@ Array [
1945119558
"loc": Object {
1945219559
"end": Object {
1945319560
"column": 5,
19454-
"line": 24,
19561+
"line": 26,
1945519562
},
1945619563
"start": Object {
1945719564
"column": 4,
19458-
"line": 22,
19565+
"line": 24,
1945919566
},
1946019567
},
1946119568
},
@@ -19517,11 +19624,11 @@ Array [
1951719624
"loc": Object {
1951819625
"end": Object {
1951919626
"column": 7,
19520-
"line": 21,
19627+
"line": 23,
1952119628
},
1952219629
"start": Object {
1952319630
"column": 4,
19524-
"line": 17,
19631+
"line": 19,
1952519632
},
1952619633
},
1952719634
"memberof": "TheClass",
@@ -19805,6 +19912,51 @@ Object {
1980519912
},
1980619913
"type": "paragraph",
1980719914
},
19915+
Object {
19916+
"children": Array [
19917+
Object {
19918+
"type": "text",
19919+
"value": "my-field",
19920+
},
19921+
],
19922+
"depth": 3,
19923+
"type": "heading",
19924+
},
19925+
Object {
19926+
"children": Array [
19927+
Object {
19928+
"position": Position {
19929+
"end": Object {
19930+
"column": 9,
19931+
"line": 1,
19932+
"offset": 8,
19933+
},
19934+
"indent": Array [],
19935+
"start": Object {
19936+
"column": 1,
19937+
"line": 1,
19938+
"offset": 0,
19939+
},
19940+
},
19941+
"type": "text",
19942+
"value": "My field",
19943+
},
19944+
],
19945+
"position": Position {
19946+
"end": Object {
19947+
"column": 9,
19948+
"line": 1,
19949+
"offset": 8,
19950+
},
19951+
"indent": Array [],
19952+
"start": Object {
19953+
"column": 1,
19954+
"line": 1,
19955+
"offset": 0,
19956+
},
19957+
},
19958+
"type": "paragraph",
19959+
},
1980819960
Object {
1980919961
"children": Array [
1981019962
Object {

__tests__/fixture/lends.input.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
export default TheClass(
77
/** @lends TheClass.prototype */
88
{
9+
/** My field */
10+
'my-field': true,
911
/**
1012
* My neat function
1113
* @param {string} word your word

src/infer/membership.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,10 @@ module.exports = function() {
280280
}
281281

282282
// Same as above but for `b: c` vs `b: function () {}`.
283-
if (path.isObjectProperty() && path.get('key').isIdentifier()) {
283+
if (
284+
path.isObjectProperty() &&
285+
(path.get('key').isIdentifier() || path.get('key').isLiteral())
286+
) {
284287
path = path.get('key');
285288
}
286289

@@ -357,7 +360,7 @@ module.exports = function() {
357360
let objectParent;
358361

359362
if (
360-
path.isIdentifier() &&
363+
(path.isIdentifier() || path.isLiteral()) &&
361364
path.parentPath.isObjectProperty() &&
362365
path.parentPath.parentPath.isObjectExpression()
363366
) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy