From f1b585e236f794db2b28e8beff291a008920fa71 Mon Sep 17 00:00:00 2001 From: huiqiangdev Date: Mon, 10 Feb 2025 16:07:20 +0800 Subject: [PATCH] add @Provide({ allowOverride: 'xx'}) --- arkoala/ets-plugin/src/utils.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/arkoala/ets-plugin/src/utils.ts b/arkoala/ets-plugin/src/utils.ts index 8204aab49..b1ff71a9d 100644 --- a/arkoala/ets-plugin/src/utils.ts +++ b/arkoala/ets-plugin/src/utils.ts @@ -263,7 +263,7 @@ export function deduceProvideConsumeName(property: ts.PropertyDeclaration, name: if (ts.isIdentifier(decorator.expression)) { return idTextOrError(property.name) } - // @Provide("bar") foo + // @Provide("bar") foo && @Provide({ allowOverride: 'bar'}) bar if (ts.isCallExpression(decorator.expression)) { const arg = decorator.expression.arguments[0]! if (ts.isIdentifier(arg)) { @@ -272,6 +272,16 @@ export function deduceProvideConsumeName(property: ts.PropertyDeclaration, name: if (ts.isStringLiteral(arg)) { return arg.text } + // @Provide({ allowOverride: 'bar'}) bar + if (ts.isObjectLiteralExpression(arg)) { + return (arg as ts.ObjectLiteralExpression).properties + .filter( + (property) => + ts.isPropertyAssignment(property) && + property.name.getText() === "allowOveride" + ) + .map((p) => (p as ts.PropertyAssignment).initializer.getText())[0]; + } } throw new Error("Unexpected decorator kind: " + asString(decorator.expression)) -- Gitee