@@ -37,22 +37,6 @@ export const OUTPUT_NAME = 'mrc_component';
3737export const FIELD_NAME = 'NAME' ;
3838export const FIELD_TYPE = 'TYPE' ;
3939
40- // key is a regex pattern that matches a function argument name, value is type of mrc_port block to use.
41- // TODO: Improve these regex pattern.
42- // The types here match the PortType values in external_samples/component.py.
43- const RECOGNIZED_PORT_ARG_NAME_PATTERNS : { [ key : string ] : string } = {
44- 'can_port' : 'CAN_PORT' ,
45- 'io_port' : 'SMART_IO_PORT' ,
46- 'smartIO_port' : 'SMART_IO_PORT' ,
47- 'smart_io_port' : 'SMART_IO_PORT' ,
48- 'motor_port' : 'SMART_MOTOR_PORT' ,
49- 'smart_motor_port' : 'SMART_MOTOR_PORT' ,
50- 'servo_port' : 'SERVO_PORT' ,
51- 'i2c_port' : 'I2C_PORT' ,
52- 'usb_port' : 'USB_PORT' ,
53- } ;
54-
55-
5640export type ConstructorArg = {
5741 name : string ,
5842 type : string ,
@@ -247,10 +231,18 @@ function createComponentBlock(
247231}
248232
249233function getPortTypeForArgument ( argName : string ) : string | null {
250- for ( const pattern in RECOGNIZED_PORT_ARG_NAME_PATTERNS ) {
251- if ( new RegExp ( pattern , 'i' ) . test ( argName ) ) {
252- return RECOGNIZED_PORT_ARG_NAME_PATTERNS [ pattern ] ;
253- }
234+ // TODO(lizlooney): Currently the JSON for component.PortType is ClassData
235+ // instead of EnumData. When it is fixed to be EnumData, this code will need
236+ // to be updated.
237+
238+ const argNameLower = argName . toLowerCase ( ) ;
239+ const classData = getClassData ( 'component.PortType' ) ;
240+ if ( classData ) {
241+ for ( const varData of classData . classVariables ) {
242+ if ( argNameLower === varData . name . toLowerCase ( ) ) {
243+ return varData . name ;
244+ }
245+ }
254246 }
255247 return null ;
256248}
0 commit comments