Skip to content
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

fix: [#9151] LG for 'choices' field in multi choice input results in Warning #9321

Merged
merged 10 commits into from
May 16, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,14 @@ describe('validate expression', () => {
const result = checkExpression("=concat('test', '1')", true, [ReturnType.String]);
expect(result).toBe(24);
});

it('use LG expressions will not throw error', () => {
try {
checkExpression('${LGChoiceOptions()}', true, [ReturnType.Number]);
} catch (error) {
expect(error.message).toBe(
"LGChoiceOptions does not have an evaluator, it's not a built-in function or a custom function."
);
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ export const addReturnType = (currentType: number, newType: number) => {
return currentType | newType;
};

export const trimExpression = (expression: string): string => {
let result = expression.trim();
if (result.startsWith('=')) {
result = result.substring(1).trim();
}

if (result.startsWith('$')) {
result = result.substring(1).trim();
}

if (result.startsWith('{') && result.endsWith('}')) {
result = result.substring(1, result.length - 1).trim();
}

return result;
};

export const checkStringExpression = (exp: string, isStringType: boolean): number => {
const origin = exp.trim();
const containsEqual = origin.startsWith('=');
Expand All @@ -28,7 +45,9 @@ export const checkStringExpression = (exp: string, isStringType: boolean): numbe
return ReturnType.String;
}

return Expression.parse(containsEqual ? origin.substring(1) : origin).returnType;
const trimmedOrigin = trimExpression(origin);

return Expression.parse(trimmedOrigin).returnType;
};

export const checkExpression = (exp: any, required: boolean, types: number[]): number => {
Expand Down
4 changes: 2 additions & 2 deletions extensions/azurePublish/yarn-berry.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1994,7 +1994,7 @@ __metadata:

"@bfc/indexers@file:../../Composer/packages/lib/indexers::locator=azurePublish%40workspace%3A.":
version: 0.0.0
resolution: "@bfc/indexers@file:../../Composer/packages/lib/indexers#../../Composer/packages/lib/indexers::hash=f8e51f&locator=azurePublish%40workspace%3A."
resolution: "@bfc/indexers@file:../../Composer/packages/lib/indexers#../../Composer/packages/lib/indexers::hash=5e1a82&locator=azurePublish%40workspace%3A."
dependencies:
"@microsoft/bf-lu": 4.15.0-dev.20210702.cbf708d
adaptive-expressions: ^4.18.0
Expand All @@ -2003,7 +2003,7 @@ __metadata:
tslib: 2.6.2
peerDependencies:
"@bfc/shared": "*"
checksum: 984e67c6cc13359b2415904ce8ab616960ebff71ca7066a491d5f9ac6b8fa299a6e005cbb0ef09a9d2248f9ea2404fde5d76eb7864bea9acc2190801198be3e1
checksum: f7684cb3a745ad13885dc745763b4b461d151536e0de52464a9f44a646c60d2ba6d07b96d5859c4e2a33bb0ef4654ed0f55d9901d3be02602219e3c706f4cac7
languageName: node
linkType: hard

Expand Down
4 changes: 2 additions & 2 deletions extensions/azurePublishNew/yarn-berry.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2031,7 +2031,7 @@ __metadata:

"@bfc/indexers@file:../../Composer/packages/lib/indexers::locator=azure-publish-new%40workspace%3A.":
version: 0.0.0
resolution: "@bfc/indexers@file:../../Composer/packages/lib/indexers#../../Composer/packages/lib/indexers::hash=f8e51f&locator=azure-publish-new%40workspace%3A."
resolution: "@bfc/indexers@file:../../Composer/packages/lib/indexers#../../Composer/packages/lib/indexers::hash=5e1a82&locator=azure-publish-new%40workspace%3A."
dependencies:
"@microsoft/bf-lu": 4.15.0-dev.20210702.cbf708d
adaptive-expressions: ^4.18.0
Expand All @@ -2040,7 +2040,7 @@ __metadata:
tslib: 2.6.2
peerDependencies:
"@bfc/shared": "*"
checksum: 984e67c6cc13359b2415904ce8ab616960ebff71ca7066a491d5f9ac6b8fa299a6e005cbb0ef09a9d2248f9ea2404fde5d76eb7864bea9acc2190801198be3e1
checksum: f7684cb3a745ad13885dc745763b4b461d151536e0de52464a9f44a646c60d2ba6d07b96d5859c4e2a33bb0ef4654ed0f55d9901d3be02602219e3c706f4cac7
languageName: node
linkType: hard

Expand Down
Loading