diff --git a/src/linter/ui5Types/amdTranspiler/requireExpressionToTransformation.ts b/src/linter/ui5Types/amdTranspiler/requireExpressionToTransformation.ts index 38b92a2a..0031e426 100644 --- a/src/linter/ui5Types/amdTranspiler/requireExpressionToTransformation.ts +++ b/src/linter/ui5Types/amdTranspiler/requireExpressionToTransformation.ts @@ -104,7 +104,7 @@ export function transformAsyncRequireCall( errbackDeclaration = nodeFactory.createFunctionDeclaration( errback.modifiers, errback.asteriskToken, - errback.name, + errback.name ?? nodeFactory.createUniqueName("extracted_require_errback"), errback.typeParameters, errback.parameters, errback.type, diff --git a/src/linter/ui5Types/amdTranspiler/transpiler.ts b/src/linter/ui5Types/amdTranspiler/transpiler.ts index 2370a351..9c994953 100644 --- a/src/linter/ui5Types/amdTranspiler/transpiler.ts +++ b/src/linter/ui5Types/amdTranspiler/transpiler.ts @@ -102,7 +102,7 @@ export default function transpileAmdToEsm(fileName: string, content: string, str throw err; } if (err instanceof UnsupportedModuleError) { - log.verbose(`Failed to transform module: ${err.message}`); + log.verbose(`Failed to transform module ${fileName}: ${err.message}`); if (err.stack && log.isLevelEnabled("verbose")) { log.verbose(`Stack trace:`); log.verbose(err.stack); @@ -110,7 +110,7 @@ export default function transpileAmdToEsm(fileName: string, content: string, str return {source: content, map: ""}; } else if (err instanceof Error && err.message.startsWith("Debug Failure")) { // We probably failed to create a valid AST - log.verbose(`AST transformation failed for module: ${err.message}`); + log.verbose(`AST transformation failed for module ${fileName}: ${err.message}`); if (err.stack && log.isLevelEnabled("verbose")) { log.verbose(`Stack trace:`); log.verbose(err.stack); diff --git a/test/fixtures/transpiler/amd/Require_Errback_2.js b/test/fixtures/transpiler/amd/Require_Errback_2.js new file mode 100644 index 00000000..a16ac143 --- /dev/null +++ b/test/fixtures/transpiler/amd/Require_Errback_2.js @@ -0,0 +1,13 @@ +sap.ui.require(["my/module"], (Module) => { + return Module; +}, function (err) { + console.log(err); +}); + +var err = function (err) { + console.log(err); +}; + +sap.ui.require(["my/module"], (Module) => { + return Module; +}, err); diff --git a/test/lib/linter/amdTranspiler/snapshots/transpiler.ts.md b/test/lib/linter/amdTranspiler/snapshots/transpiler.ts.md index 8833c8ab..4f89f0e9 100644 --- a/test/lib/linter/amdTranspiler/snapshots/transpiler.ts.md +++ b/test/lib/linter/amdTranspiler/snapshots/transpiler.ts.md @@ -1,4 +1,4 @@ -# Snapshot report for `test/lib/linter/js/transpiler.ts` +# Snapshot report for `test/lib/linter/amdTranspiler/transpiler.ts` The actual snapshot is saved in `transpiler.ts.snap`. @@ -1069,6 +1069,42 @@ Generated by [AVA](https://avajs.dev). version: 3, } +## Transpile Require_Errback_2.js + +> Snapshot 1 + + `import Module from "my/module";␊ + import Module from "my/module";␊ + ((Module) => {␊ + return Module;␊ + })(Module);␊ + var err = function (err) {␊ + console.log(err);␊ + };␊ + ((Module) => {␊ + return Module;␊ + })(Module);␊ + function extracted_require_errback_1(err) {␊ + console.log(err);␊ + }␊ + function extracted_require_errback_2(err) {␊ + console.log(err);␊ + }␊ + //# sourceMappingURL=Require_Errback_2.js.map` + +> Snapshot 2 + + { + file: 'Require_Errback_2.js', + mappings: 'OAA+B,MAAM,MAArB,WAAW;OAUI,MAAM,MAArB,WAAW;AAVG,CAAA,CAAC,MAAM,EAAE,EAAE;IACxC,OAAO,MAAM,CAAC;AACf,CAAC,CAAA,CAF8B,MAAM,EAIlC;AAEH,IAAI,GAAG,GAAG,UAAU,GAAG;IACtB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAClB,CAAC,CAAC;AAE4B,CAAA,CAAC,MAAM,EAAE,EAAE;IACxC,OAAO,MAAM,CAAC;AACf,CAAC,CAAA,CAF8B,MAAM,EAE7B;qCAVK,GAAG;IACf,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAClB,CAAC;qCAEmB,GAAG;IACtB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAClB,CAAC', + names: [], + sourceRoot: '', + sources: [ + 'Require_Errback_2.js', + ], + version: 3, + } + ## Transpile Require_Import.js > Snapshot 1 diff --git a/test/lib/linter/amdTranspiler/snapshots/transpiler.ts.snap b/test/lib/linter/amdTranspiler/snapshots/transpiler.ts.snap index ec070bbd..eb044778 100644 Binary files a/test/lib/linter/amdTranspiler/snapshots/transpiler.ts.snap and b/test/lib/linter/amdTranspiler/snapshots/transpiler.ts.snap differ