Skip to content

Commit 013e4b0

Browse files
Allow quoted strings in comma-separated jstags (#1586) (#1588)
Co-authored-by: Sylvain Wallez <[email protected]>
1 parent 66651e2 commit 013e4b0

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

compiler/src/model/utils.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ export function hoistRequestAnnotations (
607607
'maintenance', 'manage', 'manage_follow_index', 'manage_ilm', 'manage_leader_index', 'monitor',
608608
'read', 'read_cross_cluster', 'view_index_metadata', 'write'
609609
]
610-
const values = value.split(',').map(v => v.trim())
610+
const values = parseCommaSeparated(value)
611611
for (const v of values) {
612612
assert(jsDocs, privileges.includes(v), `The index privilege '${v}' does not exists.`)
613613
}
@@ -622,7 +622,7 @@ export function hoistRequestAnnotations (
622622
'manage_watcher', 'monitor', 'monitor_ml', 'monitor_rollup', 'monitor_snapshot', 'monitor_text_structure',
623623
'monitor_transform', 'monitor_watcher', 'read_ccr', 'read_ilm', 'read_pipeline', 'read_slm', 'transport_client'
624624
]
625-
const values = value.split(',').map(v => v.trim())
625+
const values = parseCommaSeparated(value)
626626
for (const v of values) {
627627
assert(jsDocs, privileges.includes(v), `The cluster privilege '${v}' does not exists.`)
628628
}
@@ -675,7 +675,7 @@ export function hoistTypeAnnotations (type: model.TypeDefinition, jsDocs: JSDoc[
675675
assert(jsDocs, docUrl != null, `The @doc_id '${value.trim()}' is not present in _doc_ids/table.csv`)
676676
type.docUrl = docUrl[1]
677677
} else if (tag === 'codegen_names') {
678-
type.codegenNames = value.split(',').map(v => v.trim())
678+
type.codegenNames = parseCommaSeparated(value)
679679
assert(jsDocs,
680680
type.kind === 'type_alias' && type.type.kind === 'union_of' && type.type.items.length === type.codegenNames.length,
681681
'@codegen_names must have the number of items as the union definition'
@@ -711,7 +711,7 @@ function hoistPropertyAnnotations (property: model.Property, jsDocs: JSDoc[]): v
711711
setTags(jsDocs, property, tags, validTags, (tags, tag, value) => {
712712
if (tag.endsWith('_serializer')) {
713713
} else if (tag === 'aliases') {
714-
property.aliases = value.split(',').map(v => v.trim())
714+
property.aliases = parseCommaSeparated(value)
715715
} else if (tag === 'codegen_name') {
716716
property.codegenName = value
717717
} else if (tag === 'doc_url') {
@@ -808,7 +808,7 @@ function hoistEnumMemberAnnotations (member: model.EnumMember, jsDocs: JSDoc[]):
808808
if (tag === 'codegen_name') {
809809
member.codegenName = value
810810
} else if (tag === 'aliases') {
811-
member.aliases = value.split(',').map(v => v.trim())
811+
member.aliases = parseCommaSeparated(value)
812812
} else if (tag === 'since') {
813813
assert(jsDocs, semver.valid(value), `${member.name}'s @since is not valid semver: ${value}`)
814814
member.since = value
@@ -992,6 +992,14 @@ export function parseVariantNameTag (jsDoc: JSDoc[]): string | undefined {
992992
return name.replace(/'/g, '')
993993
}
994994

995+
/**
996+
* Parses a list of comma-separated values as an array. Values can optionally be enclosed with single
997+
* or double quotes.
998+
*/
999+
export function parseCommaSeparated (value: string): string[] {
1000+
return value.split(',').map(v => v.trim().replace(/["']/g, ''))
1001+
}
1002+
9951003
/**
9961004
* Given a declaration, returns true if the declaration
9971005
* if defined but never used, false otherwise.

0 commit comments

Comments
 (0)