From a3b3248a9d33249febedeed0bdc2b662e9982c50 Mon Sep 17 00:00:00 2001 From: maciej-ka Date: Sat, 3 Mar 2018 19:27:50 +0100 Subject: [PATCH] fix: lends with object property using literal key --- __tests__/__snapshots__/test.js.snap | 170 +++++++++++++++++++++++++-- __tests__/fixture/lends.input.js | 2 + src/infer/membership.js | 7 +- 3 files changed, 168 insertions(+), 11 deletions(-) diff --git a/__tests__/__snapshots__/test.js.snap b/__tests__/__snapshots__/test.js.snap index 96f28935f..0360cd901 100644 --- a/__tests__/__snapshots__/test.js.snap +++ b/__tests__/__snapshots__/test.js.snap @@ -19116,7 +19116,7 @@ Array [ "loc": Object { "end": Object { "column": 2, - "line": 26, + "line": 28, }, "start": Object { "column": 0, @@ -19194,17 +19194,124 @@ Array [ "global": Array [], "inner": Array [], "instance": Array [ + Object { + "augments": Array [], + "context": Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 10, + }, + "start": Object { + "column": 4, + "line": 10, + }, + }, + }, + "description": Object { + "children": Array [ + Object { + "children": Array [ + Object { + "position": Object { + "end": Object { + "column": 9, + "line": 1, + "offset": 8, + }, + "indent": Array [], + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "text", + "value": "My field", + }, + ], + "position": Object { + "end": Object { + "column": 9, + "line": 1, + "offset": 8, + }, + "indent": Array [], + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "paragraph", + }, + ], + "position": Object { + "end": Object { + "column": 9, + "line": 1, + "offset": 8, + }, + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "root", + }, + "errors": Array [], + "examples": Array [], + "loc": Object { + "end": Object { + "column": 19, + "line": 9, + }, + "start": Object { + "column": 4, + "line": 9, + }, + }, + "memberof": "TheClass", + "members": Object { + "events": Array [], + "global": Array [], + "inner": Array [], + "instance": Array [], + "static": Array [], + }, + "name": "my-field", + "namespace": "TheClass#my-field", + "params": Array [], + "path": Array [ + Object { + "kind": "class", + "name": "TheClass", + }, + Object { + "name": "my-field", + "scope": "instance", + }, + ], + "properties": Array [], + "returns": Array [], + "scope": "instance", + "sees": Array [], + "tags": Array [], + "throws": Array [], + "todos": Array [], + }, Object { "augments": Array [], "context": Object { "loc": Object { "end": Object { "column": 5, - "line": 16, + "line": 18, }, "start": Object { "column": 4, - "line": 14, + "line": 16, }, }, }, @@ -19266,11 +19373,11 @@ Array [ "loc": Object { "end": Object { "column": 7, - "line": 13, + "line": 15, }, "start": Object { "column": 4, - "line": 9, + "line": 11, }, }, "memberof": "TheClass", @@ -19451,11 +19558,11 @@ Array [ "loc": Object { "end": Object { "column": 5, - "line": 24, + "line": 26, }, "start": Object { "column": 4, - "line": 22, + "line": 24, }, }, }, @@ -19517,11 +19624,11 @@ Array [ "loc": Object { "end": Object { "column": 7, - "line": 21, + "line": 23, }, "start": Object { "column": 4, - "line": 17, + "line": 19, }, }, "memberof": "TheClass", @@ -19805,6 +19912,51 @@ Object { }, "type": "paragraph", }, + Object { + "children": Array [ + Object { + "type": "text", + "value": "my-field", + }, + ], + "depth": 3, + "type": "heading", + }, + Object { + "children": Array [ + Object { + "position": Position { + "end": Object { + "column": 9, + "line": 1, + "offset": 8, + }, + "indent": Array [], + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "text", + "value": "My field", + }, + ], + "position": Position { + "end": Object { + "column": 9, + "line": 1, + "offset": 8, + }, + "indent": Array [], + "start": Object { + "column": 1, + "line": 1, + "offset": 0, + }, + }, + "type": "paragraph", + }, Object { "children": Array [ Object { diff --git a/__tests__/fixture/lends.input.js b/__tests__/fixture/lends.input.js index 3e4f6b7f9..8561b2301 100644 --- a/__tests__/fixture/lends.input.js +++ b/__tests__/fixture/lends.input.js @@ -6,6 +6,8 @@ export default TheClass( /** @lends TheClass.prototype */ { + /** My field */ + 'my-field': true, /** * My neat function * @param {string} word your word diff --git a/src/infer/membership.js b/src/infer/membership.js index 1fc0b51a5..438a3aec4 100644 --- a/src/infer/membership.js +++ b/src/infer/membership.js @@ -280,7 +280,10 @@ module.exports = function() { } // Same as above but for `b: c` vs `b: function () {}`. - if (path.isObjectProperty() && path.get('key').isIdentifier()) { + if ( + path.isObjectProperty() && + (path.get('key').isIdentifier() || path.get('key').isLiteral()) + ) { path = path.get('key'); } @@ -357,7 +360,7 @@ module.exports = function() { let objectParent; if ( - path.isIdentifier() && + (path.isIdentifier() || path.isLiteral()) && path.parentPath.isObjectProperty() && path.parentPath.parentPath.isObjectExpression() ) { 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