Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: parse property types containing hyphens #125

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/__tests__/markdown-helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as path from 'path';
import MarkdownIt from 'markdown-it';

import {
convertListToTypedKeys,
safelyJoinTokens,
extractStringEnum,
extractReturnType,
Expand Down Expand Up @@ -667,6 +668,24 @@ foo`),
`"Attempted to consume a typed keys list that has already been consumed"`,
);
});

it('should correctly parse types containing hyphens', () => {
const list = findNextList(getTokens("* `prop` 'string-enum' - description"));
const typedKeys = convertListToTypedKeys(list!);
const consumed = consumeTypedKeysList(typedKeys);
expect(consumed).toStrictEqual([
{
type: {
collection: false,
type: "'string-enum'",
},
key: 'prop',
description: 'description',
required: true,
additionalTags: [],
},
]);
});
});

describe('findProcess()', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/markdown-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,8 @@ const convertNestedListToTypedKeys = (list: List): TypedKey[] => {

let rawType = 'String';
if (typeAndDescriptionTokens.length !== 0) {
rawType = joinedContent.split('-')[0];
// Type can contain hyphen (e.g. 'string-enum') so require surrounding spaces.
rawType = joinedContent.split(' - ')[0];
}

const rawDescription = joinedContent.substr(rawType.length);
Expand Down