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

feat: split class conversion to enable other Babel plugin conversion #100

Merged
merged 1 commit into from
May 30, 2023
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
18,255 changes: 11,913 additions & 6,342 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"name": "babel-ui5",
"private": true,
"devDependencies": {
"@babel/eslint-parser": "^7.19.1",
"@commitlint/cli": "^17.4.4",
"@commitlint/config-conventional": "^17.4.4",
"@babel/eslint-parser": "^7.21.8",
"@commitlint/cli": "^17.6.3",
"@commitlint/config-conventional": "^17.6.3",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^8.34.0",
"eslint-config-prettier": "^8.6.0",
"eslint": "^8.41.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^8.0.3",
"lerna": "^6.5.1"
"lerna": "^6.6.2"
},
"scripts": {
"prepare": "npm run prepare:husky && npm run prepare:workspace",
Expand Down
57 changes: 53 additions & 4 deletions packages/plugin/__test__/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,35 @@ sap.ui.define(["sap/m/Button"], function (Button) {
});"
`;

exports[`decorators mixin.js 1`] = `
"sap.ui.define(["sap/ui/core/mvc/Controller", "../lib/decorators", "../lib/RoutingSupport"], function (Controller, ___lib_decorators, __RoutingSupport) {
function _interopRequireDefault(obj) {
return obj && obj.__esModule && typeof obj.default !== "undefined" ? obj.default : obj;
}
var _dec, _class;
const mixin = ___lib_decorators["mixin"];
const RoutingSupport = _interopRequireDefault(__RoutingSupport);
let AppController = (_dec = mixin(RoutingSupport), _dec(_class = class AppController extends Controller {}) || _class);
return AppController;
});"
`;

exports[`decorators mixin_mixed.js 1`] = `
"sap.ui.define(["sap/ui/core/mvc/Controller", "../lib/decorators", "../lib/RoutingSupport"], function (Controller, ___lib_decorators, __RoutingSupport) {
function _interopRequireDefault(obj) {
return obj && obj.__esModule && typeof obj.default !== "undefined" ? obj.default : obj;
}
const mixin = ___lib_decorators["mixin"];
const RoutingSupport = _interopRequireDefault(__RoutingSupport);
const AppController = Controller.extend("example.controller.AppController", {});
return AppController;
});"
`;

exports[`empty empty_js.js 1`] = `""`;

exports[`empty empty_ts.ts 1`] = `""`;

exports[`examples Animal.js 1`] = `
"sap.ui.define(["sap/ui/base/ManagedObject"], function (ManagedObject) {
const Animal = ManagedObject.extend("examples.Animal", {
Expand Down Expand Up @@ -1269,6 +1298,24 @@ exports[`preset-env preset-env-class.js 1`] = `
});"
`;

exports[`preset-env preset-env-property-mutators.js 1`] = `
"sap.ui.define(["sap/class", "core-js/modules/es6.object.define-properties.js"], function (SAPClass, __core_js_modules_es6objectdefine_propertiesjs) {
var MyClass = SAPClass.extend("my.MyClass", Object.defineProperties({}, {
thing: {
get: function get() {
return this._thing;
},
set: function set(value) {
this._thing = value;
},
configurable: true,
enumerable: true
}
}));
return MyClass;
});"
`;

exports[`preset-env preset-env-usage.js 1`] = `
"sap.ui.define(["sap/SAPClass", "core-js/modules/es6.object.to-string.js"], function (SAPClass, __core_js_modules_es6objectto_stringjs) {
import "core-js/modules/es6.promise.js";
Expand All @@ -1291,9 +1338,11 @@ exports[`preset-env preset-env-usage.js 1`] = `
exports[`typescript ts-class-param-props.ts 1`] = `
"sap.ui.define(["sap/Class"], function (SAPClass) {
const MyClass = SAPClass.extend("MyClass", {
constructor: function _constructor(bar) {
constructor: function _constructor(bar, x, y) {
SAPClass.prototype.constructor.call(this);
this.bar = bar;
this.x = x;
this.y = y;
this.foo = bar.getFoo();
}
});
Expand Down Expand Up @@ -1376,12 +1425,12 @@ exports[`typescript ts-export-default-typed-arrow-fn-with-named.1.ts 1`] = `
exports[`typescript ts-export-interface.ts 1`] = `
"sap.ui.define([], function () {
const MY_CONSTANT = "constant";
var MyEnum;
(function (MyEnum) {
var MyEnum = function (MyEnum) {
akudev marked this conversation as resolved.
Show resolved Hide resolved
MyEnum[MyEnum["A"] = 0] = "A";
MyEnum[MyEnum["B"] = 1] = "B";
MyEnum[MyEnum["C"] = 2] = "C";
})(MyEnum || (MyEnum = {}));
return MyEnum;
}(MyEnum || {});
;
var __exports = {
__esModule: true
Expand Down
8 changes: 8 additions & 0 deletions packages/plugin/__test__/fixtures/decorators/mixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Controller from "sap/ui/core/mvc/Controller";
import { mixin } from "../lib/decorators";
import RoutingSupport from "../lib/RoutingSupport";

@mixin(RoutingSupport)
export default class AppController extends Controller {
/* ... */
}
9 changes: 9 additions & 0 deletions packages/plugin/__test__/fixtures/decorators/mixin_mixed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Controller from "sap/ui/core/mvc/Controller";
import { mixin } from "../lib/decorators";
import RoutingSupport from "../lib/RoutingSupport";

@namespace("example.controller")
@mixin(RoutingSupport)
export default class AppController extends Controller {
/* ... */
}
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This conversion will be run with preset env set to ie >= 11.
// In general, we want to ensure that the class transform does not get applied before out own.

import SAPClass from "sap/class";

/**
* @name my.MyClass
*/
export default class MyClass extends SAPClass {
get thing() {
return this._thing;
}
set thing(value) {
this._thing = value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import SAPFoo from "sap/Foo";
export default class MyClass extends SAPClass {
foo: SAPFoo;

constructor(public bar: SAPBar) {
constructor(public bar: SAPBar, private x: string, readonly y: string) {
super();
this.foo = bar.getFoo();
}
Expand Down
29 changes: 21 additions & 8 deletions packages/plugin/__test__/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ function processDirectory(dir) {
try {
const opts = getOpts(filePath);
const presets = [];
const plugins = [
[plugin, opts], // we don't rely on the plugin order anymore!
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-syntax-object-rest-spread",
["@babel/plugin-syntax-decorators", { legacy: true }],
["@babel/plugin-syntax-class-properties", { useBuiltIns: true }],
];

if (filePath.endsWith(".ts")) {
presets.push(["@babel/preset-typescript"]);
Expand All @@ -46,19 +53,25 @@ function processDirectory(dir) {
{
targets: undefined, // default targets for preset-env is ES5
modules: false,
useBuiltIns: "usage",
useBuiltIns: "usage", // will include imports to corejs (some tests rely on this)
corejs: 2,
},
]);
}

if (filePath.endsWith("property-mutators.js")) {
plugins.push("@babel/plugin-transform-property-mutators");
}

if (filePath.includes("/decorators/")) {
plugins.push([
"@babel/plugin-proposal-decorators",
{ legacy: true },
]);
}

const result = transformFileSync(filePath, {
plugins: [
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-syntax-object-rest-spread",
["@babel/plugin-syntax-decorators", { legacy: true }],
["@babel/plugin-syntax-class-properties", { useBuiltIns: true }],
[plugin, opts],
],
plugins,
presets,
sourceRoot: __dirname,
comments: filePath.includes("comments"),
Expand Down
Loading