diff --git a/Composer/packages/lib/indexers/__tests__/validations/expressionValidation.test.ts b/Composer/packages/lib/indexers/__tests__/validations/expressionValidation.test.ts index b064d76fc4..2caef95c2f 100644 --- a/Composer/packages/lib/indexers/__tests__/validations/expressionValidation.test.ts +++ b/Composer/packages/lib/indexers/__tests__/validations/expressionValidation.test.ts @@ -13,6 +13,9 @@ describe('search lg custom function', () => { expect(result.length).toEqual(2); expect(result[0]).toEqual('foo.bar'); expect(result[1]).toEqual('foo.cool'); + const lgFilesWithoutOptions = [{ id: 'test.en-us' }]; + const result1 = searchLgCustomFunction(lgFilesWithoutOptions as LgFile[]); + expect(result1.length).toEqual(0); }); it('should return custom functions with namespace', () => { diff --git a/Composer/packages/lib/indexers/src/validations/expressionValidation/index.ts b/Composer/packages/lib/indexers/src/validations/expressionValidation/index.ts index 3ba6eeabda..aee180ce76 100644 --- a/Composer/packages/lib/indexers/src/validations/expressionValidation/index.ts +++ b/Composer/packages/lib/indexers/src/validations/expressionValidation/index.ts @@ -15,16 +15,17 @@ const ExportsKey = '@exports'; export const searchLgCustomFunction = (lgFiles: LgFile[]): string[] => { const customFunctions = lgFiles.reduce((result: string[], lgFile) => { const { options } = lgFile; - const exports = extractOptionByKey(ExportsKey, options); - let namespace = extractOptionByKey(NamespaceKey, options); - if (!namespace) namespace = lgFile.id; //if namespace doesn't exist, use file name - const funcList = exports.split(','); - funcList.forEach((func) => { - if (func) { - result.push(`${namespace}.${func.trim()}`); - } - }); - + if (options?.length) { + const exports = extractOptionByKey(ExportsKey, options); + let namespace = extractOptionByKey(NamespaceKey, options); + if (!namespace) namespace = lgFile.id; //if namespace doesn't exist, use file name + const funcList = exports.split(','); + funcList.forEach((func) => { + if (func) { + result.push(`${namespace}.${func.trim()}`); + } + }); + } return result; }, []); return customFunctions; diff --git a/Composer/packages/lib/shared/src/types/indexers.ts b/Composer/packages/lib/shared/src/types/indexers.ts index be850e6843..2232466237 100644 --- a/Composer/packages/lib/shared/src/types/indexers.ts +++ b/Composer/packages/lib/shared/src/types/indexers.ts @@ -107,7 +107,7 @@ export interface LgFile { content: string; diagnostics: Diagnostic[]; templates: LgTemplate[]; - options: string[]; + options?: string[]; } export interface Skill {