1- import fs from "fs" ;
2- import path from "path" ;
3- import yaml from "js-yaml" ;
1+ import "dotenv/config" ;
42import parser from "@babel/parser" ;
53import _traverse from "@babel/traverse" ;
64import * as t from "@babel/types" ;
7- import { promisify } from "util" ;
85import { Preprocessor } from "content-tag" ;
9- import "dotenv/config" ;
6+ import fs from "fs" ;
7+ import yaml from "js-yaml" ;
8+ import path from "path" ;
9+ import { promisify } from "util" ;
1010
1111const discourseDir = process . env . DISCOURSE_CORE ;
1212const traverse = _traverse . default ;
@@ -26,7 +26,7 @@ const EXCLUDED_DIR_PATTERNS = [
2626 "/discourse/plugins/chat/test" ,
2727 "/discourse/plugins/discourse-deprecation-collector/" ,
2828] ;
29- const UNPARSABLE_INDICATOR = ' undefined' ;
29+ const UNPARSABLE_INDICATOR = " undefined" ;
3030const filesToDebug = [ ] ;
3131
3232async function isExcludedDir ( filePath ) {
@@ -104,7 +104,7 @@ function extractAppEvents(path, filePath, eventTriggers, hasAppEventsTrigger) {
104104 const args = node . arguments . slice ( 1 ) . map ( ( arg , index ) => {
105105 return {
106106 ...extractArgument ( arg ) ,
107- argPosition : index + 1
107+ argPosition : index + 1 ,
108108 } ;
109109 } ) ;
110110
@@ -152,7 +152,7 @@ function extractAppEventsFromOptionalExpressions(
152152 const args = node . arguments . slice ( 1 ) . map ( ( arg , index ) => {
153153 return {
154154 ...extractArgument ( arg ) ,
155- argPosition : index + 1
155+ argPosition : index + 1 ,
156156 } ;
157157 } ) ;
158158
@@ -175,20 +175,31 @@ function extractArgument(argNode) {
175175 if ( t . isStringLiteral ( argNode ) ) {
176176 argValue = argNode . value ;
177177 argType = "string" ;
178+ } else if ( t . isNumericLiteral ( argNode ) ) {
179+ argValue = argNode . value ;
180+ argType = "integer" ;
178181 } else if ( t . isIdentifier ( argNode ) ) {
179182 argValue = argNode . name ;
180183 argType = "variable" ;
181184 } else if ( t . isMemberExpression ( argNode ) ) {
182185 argValue = extractNameFromMemberExpression ( argNode ) ;
183186 argType = "property" ;
187+ } else if ( t . isThisExpression ( argNode ) ) {
188+ argValue = "this" ;
189+ argType = "this" ;
184190 } else if ( t . isCallExpression ( argNode ) ) {
185191 let calleeObjectName ;
186- if ( argNode . callee . object ) {
187- calleeObjectName = t . isThisExpression ( argNode . callee . object )
188- ? "this"
189- : argNode . callee . object . name ;
192+ // TODO: possibly some duplication here? quite nested code
193+ if ( t . isMemberExpression ( argNode . callee ) ) {
194+ argValue = extractNameFromMemberExpression ( argNode . callee ) ;
195+ } else {
196+ if ( argNode . callee . object ) {
197+ calleeObjectName = t . isThisExpression ( argNode . callee . object )
198+ ? "this"
199+ : argNode . callee . object . name ;
200+ }
201+ argValue = `${ calleeObjectName } .${ argNode . callee . property . name } ` ;
190202 }
191- argValue = `${ calleeObjectName } .${ argNode . callee . property . name } ` ;
192203 argType = "called_function" ;
193204 } else if ( t . isTemplateLiteral ( argNode ) ) {
194205 argValue = argNode . quasis . reduce ( ( acc , quasi , index ) => {
@@ -216,9 +227,14 @@ function extractArgument(argNode) {
216227 } , "" ) ;
217228 argType = "templated_string" ;
218229 } else if ( t . isObjectExpression ( argNode ) ) {
219- //TODO process object expressions into structured data - keys and their valueTypes
220230 argValue = extractDetailsFromObjectExpression ( argNode . properties ) ;
221231 argType = "object" ;
232+ } else if ( t . isSpreadElement ( argNode ) ) {
233+ argValue = argNode . argument . name ;
234+ argType = "spread_element" ;
235+ } else if ( t . isNullLiteral ( argNode ) ) {
236+ argValue = null ;
237+ argType = "null" ;
222238 } else {
223239 argValue = UNPARSABLE_INDICATOR ;
224240 argType = UNPARSABLE_INDICATOR ;
@@ -229,7 +245,7 @@ function extractArgument(argNode) {
229245
230246function extractDetailsFromObjectExpression ( props ) {
231247 return props . reduce ( ( result , prop ) => {
232- const key = prop . key . name || prop . key . value ;
248+ const key = prop . key . name || prop . key . value ;
233249
234250 let valueType ;
235251 if ( t . isStringLiteral ( prop . value ) ) {
@@ -251,7 +267,7 @@ function extractDetailsFromObjectExpression(props) {
251267 }
252268
253269 result . push ( { key, valueType } ) ;
254- return result
270+ return result ;
255271 } , [ ] ) ;
256272}
257273
@@ -367,7 +383,9 @@ async function parseDirectory(directoryPath) {
367383 `${ allEventIds . length } Extracted event IDs saved to ${ eventIdsFilePath } `
368384 ) ;
369385
370- // Output detailed information
386+ // Event triggers are saved without any further processing to group by filePath
387+ // or by event ID intentionally, as this maintains flexibility in how we can
388+ // use the raw data
371389 const detailedOutputPath = path . join (
372390 "." ,
373391 "lib" ,
0 commit comments