Skip to content

Commit ce63699

Browse files
Allow quoted strings in comma-separated jstags (#1586) (#1587)
Co-authored-by: Sylvain Wallez <[email protected]>
1 parent 8323709 commit ce63699

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
@@ -595,7 +595,7 @@ export function hoistRequestAnnotations (
595595
'maintenance', 'manage', 'manage_follow_index', 'manage_ilm', 'manage_leader_index', 'monitor',
596596
'read', 'read_cross_cluster', 'view_index_metadata', 'write'
597597
]
598-
const values = value.split(',').map(v => v.trim())
598+
const values = parseCommaSeparated(value)
599599
for (const v of values) {
600600
assert(jsDocs, privileges.includes(v), `The index privilege '${v}' does not exists.`)
601601
}
@@ -610,7 +610,7 @@ export function hoistRequestAnnotations (
610610
'manage_watcher', 'monitor', 'monitor_ml', 'monitor_rollup', 'monitor_snapshot', 'monitor_text_structure',
611611
'monitor_transform', 'monitor_watcher', 'read_ccr', 'read_ilm', 'read_pipeline', 'read_slm', 'transport_client'
612612
]
613-
const values = value.split(',').map(v => v.trim())
613+
const values = parseCommaSeparated(value)
614614
for (const v of values) {
615615
assert(jsDocs, privileges.includes(v), `The cluster privilege '${v}' does not exists.`)
616616
}
@@ -657,7 +657,7 @@ export function hoistTypeAnnotations (type: model.TypeDefinition, jsDocs: JSDoc[
657657
assert(jsDocs, value.trim() !== '', `Type ${type.name.namespace}.${type.name.name}'s @doc_id cannot be empty`)
658658
type.docId = value.trim()
659659
} else if (tag === 'codegen_names') {
660-
type.codegenNames = value.split(',').map(v => v.trim())
660+
type.codegenNames = parseCommaSeparated(value)
661661
assert(jsDocs,
662662
type.kind === 'type_alias' && type.type.kind === 'union_of' && type.type.items.length === type.codegenNames.length,
663663
'@codegen_names must have the number of items as the union definition'
@@ -685,7 +685,7 @@ function hoistPropertyAnnotations (property: model.Property, jsDocs: JSDoc[]): v
685685
setTags(jsDocs, property, tags, validTags, (tags, tag, value) => {
686686
if (tag.endsWith('_serializer')) {
687687
} else if (tag === 'aliases') {
688-
property.aliases = value.split(',').map(v => v.trim())
688+
property.aliases = parseCommaSeparated(value)
689689
} else if (tag === 'codegen_name') {
690690
property.codegenName = value
691691
} else if (tag === 'doc_url') {
@@ -778,7 +778,7 @@ function hoistEnumMemberAnnotations (member: model.EnumMember, jsDocs: JSDoc[]):
778778
if (tag === 'codegen_name') {
779779
member.codegenName = value
780780
} else if (tag === 'aliases') {
781-
member.aliases = value.split(',').map(v => v.trim())
781+
member.aliases = parseCommaSeparated(value)
782782
} else if (tag === 'since') {
783783
assert(jsDocs, semver.valid(value), `${member.name}'s @since is not valid semver: ${value}`)
784784
member.since = value
@@ -962,6 +962,14 @@ export function parseVariantNameTag (jsDoc: JSDoc[]): string | undefined {
962962
return name.replace(/'/g, '')
963963
}
964964

965+
/**
966+
* Parses a list of comma-separated values as an array. Values can optionally be enclosed with single
967+
* or double quotes.
968+
*/
969+
export function parseCommaSeparated (value: string): string[] {
970+
return value.split(',').map(v => v.trim().replace(/["']/g, ''))
971+
}
972+
965973
/**
966974
* Given a declaration, returns true if the declaration
967975
* if defined but never used, false otherwise.

0 commit comments

Comments
 (0)