Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.forEachTopLevel('leading-and-interposing', (t, name) => {
const camelCaseName = modifySource(camelCase, name)
this.emitDescription(this.descriptionForType(t))
// Override sourceFor behavior to disable `{ [key: string]: any }`
// if no properties are set for an event.
let type = this.sourceFor(t).source
if (t instanceof MapType) {
type = '{}'
}
if (this.ajsOptions.client === Client.js) {
this.emitLine([
camelCaseName,
'(props?: ',
type,
', options?: SegmentOptions, callback?: AnalyticsJSCallback): void'
])
withOptions: boolean
): void {
// TODO: Emit a function description, once we support top-level event descriptions in JSON Schema
const description: Sourcelike = [
['@see <a href="https://segment.com/docs/spec/track/">Track Documentation</a>']
]
if (hasProperties) {
description.unshift([
'@param props {@link ',
name,
'} to add extra information to this call.'
])
}
this.emitDescriptionBlock(description)
const camelCaseName = modifySource(camelCase, name)
this.emitBlock(
[
'public void ',
camelCaseName,
'(',
...(hasProperties ? ['final @Nullable ', name, ' props'] : []),
hasProperties && withOptions ? ', ' : '',
withOptions ? 'final @Nullable Options options' : '',
')'
],
() => {
this.emitLine([
'this.analytics.track("',
getRawName(name),
'", ',
hasProperties ? 'props.toProperties()' : 'new Properties()',
this.emitPropertyTable(c, (_, jsonName, p) => {
const t = p.type
return [
[modifySource(quotePropertyName, jsonName), p.isOptional ? '?' : '', ': '],
[this.sourceFor(t).source, ';']
]
})
}
this.forEachTopLevel('leading-and-interposing', (t, name) => {
const camelCaseName = modifySource(camelCase, name)
const typeMap = this.typeMapTypeFor(t)
this.emitBlock(
[
'export function ',
camelCaseName,
'(props: ',
this.sourceFor(t).source,
', context?: any): void'
],
'',
() => {
this.emitLine('const payload = transform(props, ', typeMap, ', jsToJSONProps, typeMap);')
const rawEventName = name
.proposeUnstyledNames(null)
.values()