Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions packages/plugin/__test__/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,28 @@ sap.ui.define(["./foo"], function (__Foo) {
});"
`;

exports[`min-wrap min-wrap-test.js 1`] = `
"sap.ui.define(["../../model/someFile", "../schema/otherFile"], function (____model_someFile, ___schema_otherFile) {
"use strict";

const getElementPath = ____model_someFile["getElementPath"];
const createSchema = ___schema_otherFile["createSchema"];
getElementPath(createSchema(), "elementSchema");
});"
`;

exports[`min-wrap min-wrap-test-wrap.js 1`] = `
""use strict";

const x = 1;
sap.ui.define(["../../model/someFile", "../schema/otherFile"], function (____model_someFile, ___schema_otherFile) {
const getElementPath = ____model_someFile["getElementPath"];
const createSchema = ___schema_otherFile["createSchema"];
getElementPath(createSchema(), "elementSchema");
console.log(x);
});"
`;

exports[`min-wrap min-wrap-ui5.js 1`] = `
""use strict";

Expand Down Expand Up @@ -2109,6 +2131,46 @@ exports[`typescript ts-export-type.ts 1`] = `

exports[`typescript ts-export-type-only.ts 1`] = `""`;

exports[`typescript ts-export-type-reexport.ts 1`] = `
"sap.ui.define(["./ts-export-type-reexport-enum"], function (___ts_export_type_reexport_enum) {
"use strict";

var __exports = {
__esModule: true
};
function extendExports(exports, obj) {
obj && Object.keys(obj).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return obj[key];
}
});
});
}
extendExports(__exports, ___ts_export_type_reexport_enum);
return __exports;
});"
`;

exports[`typescript ts-export-type-reexport-enum.ts 1`] = `
"sap.ui.define([], function () {
"use strict";

var FemRendererModel = function (FemRendererModel) {
FemRendererModel["AppModel"] = "AppModel";
FemRendererModel["RouteModel"] = "RouteModel";
return FemRendererModel;
}(FemRendererModel || {});
var __exports = {
__esModule: true
};
__exports.FemRendererModel = FemRendererModel;
return __exports;
});"
`;

exports[`typescript ts-index.ts 1`] = `
"sap.ui.define(["./_private_/index"], function (____private__index) {
"use strict";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const x = 1; // This should not be part of sap-ui-define

import { getElementPath } from "../../model/someFile";
import { createSchema } from "../schema/otherFile";

getElementPath(createSchema(), "elementSchema");
console.log(x);
4 changes: 4 additions & 0 deletions packages/plugin/__test__/fixtures/min-wrap/min-wrap-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { getElementPath } from "../../model/someFile";
import { createSchema } from "../schema/otherFile";

getElementPath(createSchema(), "elementSchema");
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum FemRendererModel {
AppModel = "AppModel",
RouteModel = "RouteModel",
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type RouterContext = {
mock: boolean;
service: string;
path: string;
};

export * from "./ts-export-type-reexport-enum";
5 changes: 5 additions & 0 deletions packages/plugin/src/modules/helpers/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ export function wrap(visitor, programNode, opts) {
const fullBody = body;
const newBody = [];

// If there is no lastBeforeWrapping, the first import is not marked
if (!fullBody.find((item) => item.lastBeforeWrapping)) {
reachedFirstImport = true;
}

for (const item of fullBody) {
if (reachedFirstImport) {
newBody.push(item);
Expand Down
15 changes: 7 additions & 8 deletions packages/plugin/src/modules/visitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,13 @@ export const ModuleTransformVisitor = {
}

// this is the very first import in noWrapBeforeImport mode and there are sibling nodes before this import
if (
opts.noWrapBeforeImport &&
!this.firstImportMarked &&
path.inList &&
path.key > 0
) {
// mark the direct predecessor as the last one to exclude from wrapping
path.getSibling(path.key - 1).node.lastBeforeWrapping = true;
if (opts.noWrapBeforeImport && !this.firstImportMarked && path.inList) {
// for the first element there is a special case as we can't mark the previous one
// therefore we do not mark anything to make clear that there's nothing to exclude
Comment on lines +207 to +208
Copy link

Copilot AI May 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider clarifying in the comment that when path.key equals 0 no marking takes place because there is no valid previous node, to improve maintainability and ease of understanding of this special case.

Suggested change
// for the first element there is a special case as we can't mark the previous one
// therefore we do not mark anything to make clear that there's nothing to exclude
// For the first element, there is a special case: when path.key === 0, we can't mark the previous node
// because there is no valid previous node. Therefore, we do not mark anything to make clear that there's nothing to exclude.

Copilot uses AI. Check for mistakes.
if (path.key > 0) {
// mark the direct predecessor as the last one to exclude from wrapping
path.getSibling(path.key - 1).node.lastBeforeWrapping = true;
}
this.firstImportMarked = true;
}

Expand Down
Loading