Skip to content

Commit

Permalink
fix: Control renderer check with quoted property
Browse files Browse the repository at this point in the history
  • Loading branch information
matz3 committed Oct 29, 2024
1 parent 90b1627 commit 540614f
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/linter/ui5Types/SourceFileLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export default class SourceFileLinter {
const rendererMember = node.members.find((member) => {
return (ts.isPropertyDeclaration(member) || ts.isMethodDeclaration(member)) &&
member.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.StaticKeyword) &&
member.name.getText() === "renderer";
(ts.isIdentifier(member.name) || ts.isStringLiteral(member.name)) && member.name.text === "renderer";
});

if (!rendererMember) {
Expand Down
12 changes: 6 additions & 6 deletions src/linter/ui5Types/amdTranspiler/rewriteExtendCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,21 @@ function getClassBodyFromArguments(
prop.initializer.body);
} else {
const modifiers: ts.ModifierLike[] = [];

let propertyName;
if (ts.isIdentifier(prop.name) || ts.isStringLiteral(prop.name)) {
propertyName = prop.name.text;
}
// Special handling:
// - metadata: *readonly static*
// - renderer: *static*
// This aligns it with how UI5 projects should declare those properties in TypeScript
if (
ts.isObjectLiteralExpression(prop.initializer) &&
(
ts.isIdentifier(prop.name) || ts.isStringLiteral(prop.name)
) &&
prop.name.text === "metadata"
propertyName === "metadata"
) {
modifiers.push(nodeFactory.createToken(ts.SyntaxKind.ReadonlyKeyword));
modifiers.push(nodeFactory.createToken(ts.SyntaxKind.StaticKeyword));
} else if (ts.isIdentifier(prop.name) && prop.name.text === "renderer") {
} else if (propertyName === "renderer") {
modifiers.push(nodeFactory.createToken(ts.SyntaxKind.StaticKeyword));
} else if (prop.initializer.kind === ts.SyntaxKind.NullKeyword ||
prop.initializer.kind === ts.SyntaxKind.UndefinedKeyword
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sap.ui.define(["sap/ui/core/Control", "sap/m/Button"], function(Control, Button)
const Example3 = Control.extend("sap.ui.demo.linter.controls.Example3", {
metadata: {},
// Declaration of renderer module as template literal with substitution (deprecated)
renderer: `sap.ui.demo.linter.controls.Example${1+2}Renderer`
"renderer": `sap.ui.demo.linter.controls.Example${1+2}Renderer`
});
const Example4 = Control.extend("sap.ui.demo.linter.controls.Example4", {
metadata: {},
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/transpiler/amd/Factory_ClassLocalVariable.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ sap.ui.define(["sap/ui/core/Control", "sap/m/Button"], function(Control, Button)
*/
Control.extend("test.ExampleControl5", {
"metadata": {}, // Quoted metadata property should be transformed to static property
renderer: (oRm, oControl) => {
"renderer": (oRm, oControl) => {
// Quoted renderer property should be transformed to static property
}
});
/* This comment should be below the "class" statement of ExampleControl5 after transpiling */
Expand Down
5 changes: 3 additions & 2 deletions test/lib/linter/amdTranspiler/snapshots/transpiler.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ Generated by [AVA](https://avajs.dev).
}␊
class ExampleControl5_1 extends Control {␊
static "metadata" = {};␊
static renderer = (oRm, oControl) => {␊
static "renderer" = (oRm, oControl) => {␊
// Quoted renderer property should be transformed to static property␊
};␊
}␊
/* This comment should be below the "class" statement of ExampleControl5 after transpiling */␊
Expand Down Expand Up @@ -328,7 +329,7 @@ Generated by [AVA](https://avajs.dev).
{
file: 'Factory_ClassLocalVariable.js',
mappings: 'OAAgE,OAAO,MAAxD,qBAAqB;OAAqC,MAAM,MAAzC,cAAc;;8BAG3B,OAAO;WAC9B,QAAQ,GAAE,EAAE;WACZ,QAAQ,GAAE;QACT,UAAU,EAAE,CAAC;QACb,MAAM,EAAE,UAAS,GAAG,EAAE,QAAQ;QAC9B,CAAC;KACD;;AAEF,6FAA6F;AAE7F,MAAM,CAAC,GAAG,CAA+D,CAAC;8BAA3C,OAAO;;AAEtC,MAAM,CAAC,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C,MAAM,CAAC,GAAG,CAAC,EAGV,CAAC,GAAG,CAA+D,CAAC;;8BADlD,OAAO;;8BACA,OAAO;;gCAKjC,OAAO;WACN,UAAU,GAAE,EAAE;WACd,UAAU,GAAE,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE;QAC7B,oEAAoE;IACrE,CAAC;;AAEF,6FAA6F;AAE7F,CAAC;IACA,MAAM,CAAC,GAAG,CAAC,EAKV,CAAC,GAAG,CAA+D,CAAC;kCADlD,OAAO;;kCACA,OAAO;;;oCAGjC,OAAO;eACN,QAAQ,GAAE,EAAE;eACZ,QAAQ,CAAW,GAAG,EAAE,QAAQ;QAChC,CAAC;;CAEF,CAAC,EAAE,CAAC;AAEL,MAAM,QAAQ,GAAG,EAAE,CAAC;AACpB,MAAM,QAAQ,GAAG,UAAU,GAAG,EAAE,UAAU,IAAG,CAAC,CAAC;AAC/C,MAAM,YAAY,GAAG;IACpB,IAAI,GAAG,GAAG,IAAI,MAAM,CAAC;QACpB,OAAO,EAAE,IAAI;KACb,CAAC,CAAC;IACH,GAAG,CAAC,SAAS,CAAC;QACb,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;IACH,OAAO,GAAG,CAAC;AACZ,CAAC,CAAC;wBACc,OAAO;WACtB,QAAQ,GAAR,QAAQ;WACR,QAAQ,GAAR,QAAQ;IACR,YAAY,GAAZ,YAAY;;;+CAIN,OAAO;WACb,QAAQ,GAAE,EAAE;IACZ,OAAA,QAAQ,CAAC,GAAG,EAAE,QAAQ;IACtB,CAAC',
names: [],
sourceRoot: '',
sources: [
Expand Down
Binary file modified test/lib/linter/amdTranspiler/snapshots/transpiler.ts.snap
Binary file not shown.
2 changes: 1 addition & 1 deletion test/lib/linter/rules/snapshots/renderer.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ Generated by [AVA](https://avajs.dev).
severity: 2,
},
{
column: 13,
column: 15,
line: 15,
message: 'Deprecated declaration of renderer for control \'Example3\'',
messageDetails: 'Defining the \'renderer\' for control \'Example3\' by its name may lead to synchronous loading of the renderer module. Import the renderer module and assign it to the \'renderer\' property.',
Expand Down
Binary file modified test/lib/linter/rules/snapshots/renderer.ts.snap
Binary file not shown.

0 comments on commit 540614f

Please sign in to comment.