Skip to content

Allow quoted strings in comma-separated jstags #1586

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

Merged
merged 2 commits into from
Mar 29, 2022
Merged
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
18 changes: 13 additions & 5 deletions compiler/src/model/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ export function hoistRequestAnnotations (
'maintenance', 'manage', 'manage_follow_index', 'manage_ilm', 'manage_leader_index', 'monitor',
'read', 'read_cross_cluster', 'view_index_metadata', 'write'
]
const values = value.split(',').map(v => v.trim())
const values = parseCommaSeparated(value)
for (const v of values) {
assert(jsDocs, privileges.includes(v), `The index privilege '${v}' does not exists.`)
}
Expand All @@ -622,7 +622,7 @@ export function hoistRequestAnnotations (
'manage_watcher', 'monitor', 'monitor_ml', 'monitor_rollup', 'monitor_snapshot', 'monitor_text_structure',
'monitor_transform', 'monitor_watcher', 'read_ccr', 'read_ilm', 'read_pipeline', 'read_slm', 'transport_client'
]
const values = value.split(',').map(v => v.trim())
const values = parseCommaSeparated(value)
for (const v of values) {
assert(jsDocs, privileges.includes(v), `The cluster privilege '${v}' does not exists.`)
}
Expand Down Expand Up @@ -675,7 +675,7 @@ export function hoistTypeAnnotations (type: model.TypeDefinition, jsDocs: JSDoc[
assert(jsDocs, docUrl != null, `The @doc_id '${value.trim()}' is not present in _doc_ids/table.csv`)
type.docUrl = docUrl[1]
} else if (tag === 'codegen_names') {
type.codegenNames = value.split(',').map(v => v.trim())
type.codegenNames = parseCommaSeparated(value)
assert(jsDocs,
type.kind === 'type_alias' && type.type.kind === 'union_of' && type.type.items.length === type.codegenNames.length,
'@codegen_names must have the number of items as the union definition'
Expand Down Expand Up @@ -711,7 +711,7 @@ function hoistPropertyAnnotations (property: model.Property, jsDocs: JSDoc[]): v
setTags(jsDocs, property, tags, validTags, (tags, tag, value) => {
if (tag.endsWith('_serializer')) {
} else if (tag === 'aliases') {
property.aliases = value.split(',').map(v => v.trim())
property.aliases = parseCommaSeparated(value)
} else if (tag === 'codegen_name') {
property.codegenName = value
} else if (tag === 'doc_url') {
Expand Down Expand Up @@ -808,7 +808,7 @@ function hoistEnumMemberAnnotations (member: model.EnumMember, jsDocs: JSDoc[]):
if (tag === 'codegen_name') {
member.codegenName = value
} else if (tag === 'aliases') {
member.aliases = value.split(',').map(v => v.trim())
member.aliases = parseCommaSeparated(value)
} else if (tag === 'since') {
assert(jsDocs, semver.valid(value), `${member.name}'s @since is not valid semver: ${value}`)
member.since = value
Expand Down Expand Up @@ -992,6 +992,14 @@ export function parseVariantNameTag (jsDoc: JSDoc[]): string | undefined {
return name.replace(/'/g, '')
}

/**
* Parses a list of comma-separated values as an array. Values can optionally be enclosed with single
* or double quotes.
*/
export function parseCommaSeparated (value: string): string[] {
return value.split(',').map(v => v.trim().replace(/["']/g, ''))
}

/**
* Given a declaration, returns true if the declaration
* if defined but never used, false otherwise.
Expand Down