From 74c49bb100fb26bcac6edcb02347d632d505d850 Mon Sep 17 00:00:00 2001 From: "WEISSENFELS, Niklas" Date: Tue, 20 Jul 2021 12:18:05 +0200 Subject: [PATCH 1/4] added basic implementation --- .../plugin/src/classes/helpers/classes.js | 23 ++++++++++++++----- packages/plugin/src/classes/helpers/jsdoc.js | 2 +- packages/plugin/src/classes/visitor.js | 19 ++++++++++++++- packages/plugin/src/utils/templates.js | 4 ++++ 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/packages/plugin/src/classes/helpers/classes.js b/packages/plugin/src/classes/helpers/classes.js index 018219c..d30a51f 100644 --- a/packages/plugin/src/classes/helpers/classes.js +++ b/packages/plugin/src/classes/helpers/classes.js @@ -234,12 +234,23 @@ export function convertClassToUI5Extend( } } - const extendAssign = th.buildExtendAssign({ - NAME: classNameIdentifier, - SUPER: superClass, // Needs Identifier node - FQN: t.stringLiteral(getFullyQualifiedName(classInfo)), - OBJECT: t.objectExpression(extendProps), - }); + let extendAssign; + if (classInfo) { + extendAssign = th.buildExtendAssignWithMD({ + NAME: classNameIdentifier, + SUPER: superClass, // Needs Identifier node + FQN: t.stringLiteral(getFullyQualifiedName(classInfo)), + OBJECT: t.objectExpression(extendProps), + FN_META_IMPL: "MetadataObject", + }); + } else { + extendAssign = th.buildExtendAssign({ + NAME: classNameIdentifier, + SUPER: superClass, // Needs Identifier node + FQN: t.stringLiteral(getFullyQualifiedName(classInfo)), + OBJECT: t.objectExpression(extendProps), + }); + } return [extendAssign, ...staticMembers]; } diff --git a/packages/plugin/src/classes/helpers/jsdoc.js b/packages/plugin/src/classes/helpers/jsdoc.js index c24b8c1..ceda50d 100644 --- a/packages/plugin/src/classes/helpers/jsdoc.js +++ b/packages/plugin/src/classes/helpers/jsdoc.js @@ -2,7 +2,7 @@ import { types as t } from "@babel/core"; import doctrine from "doctrine"; import ignoreCase from "ignore-case"; -const classInfoValueTags = ["alias", "name", "namespace"]; +const classInfoValueTags = ["alias", "name", "namespace", "metadata"]; const classInfoBoolTags = ["nonUI5", "controller", "keepConstructor"]; export function getJsDocClassInfo(node, parent) { diff --git a/packages/plugin/src/classes/visitor.js b/packages/plugin/src/classes/visitor.js index 006afeb..cf3a965 100644 --- a/packages/plugin/src/classes/visitor.js +++ b/packages/plugin/src/classes/visitor.js @@ -35,6 +35,20 @@ export const ClassTransformVisitor = { return; } + if (classInfo.metadata) { + const identifier = t.identifier("MetadataObject"); + const importDefaultSpecifier = t.importDefaultSpecifier(identifier); + const importDeclaration = t.importDeclaration( + [importDefaultSpecifier], + t.stringLiteral( + classInfo.metadata.replace(new RegExp("\\.", "g"), "/") + ) + ); + path + .findParent(path => path.isBlock()) + .unshiftContainer("body", importDeclaration); + } + // Save super class name for converting super calls this.superClassName = classInfo.superClassName; @@ -129,7 +143,10 @@ export const ClassTransformVisitor = { }; function isSuperApply(callee) { - return t.isIdentifier(callee.property, { "name": "apply" }) && t.isSuper(callee.object.object); + return ( + t.isIdentifier(callee.property, { name: "apply" }) && + t.isSuper(callee.object.object) + ); } function getRequiredParamsOfSAPUIDefine(path, node) { diff --git a/packages/plugin/src/utils/templates.js b/packages/plugin/src/utils/templates.js index 5e4fc6d..dbdce40 100644 --- a/packages/plugin/src/utils/templates.js +++ b/packages/plugin/src/utils/templates.js @@ -111,6 +111,10 @@ export const buildExtendAssign = template(` const NAME = SUPER.extend(FQN, OBJECT); `); +export const buildExtendAssignWithMD = template(` + const NAME = SUPER.extend(FQN, OBJECT, FN_META_IMPL); +`); + // This is use when there is not already the function, so always propagate arguments. export const buildInheritingFunction = template(` function NAME() { From 1596da700a22711d17fc80d4126a3accdf2587bf Mon Sep 17 00:00:00 2001 From: "WEISSENFELS, Niklas" Date: Tue, 17 Aug 2021 15:55:00 +0200 Subject: [PATCH 2/4] use metadata implementation only if classInfo is set --- .../plugin/src/classes/helpers/classes.js | 2 +- packages/preset/package-lock.json | 37 +------------------ 2 files changed, 3 insertions(+), 36 deletions(-) diff --git a/packages/plugin/src/classes/helpers/classes.js b/packages/plugin/src/classes/helpers/classes.js index d30a51f..0cbf14e 100644 --- a/packages/plugin/src/classes/helpers/classes.js +++ b/packages/plugin/src/classes/helpers/classes.js @@ -235,7 +235,7 @@ export function convertClassToUI5Extend( } let extendAssign; - if (classInfo) { + if (classInfo.metadata) { extendAssign = th.buildExtendAssignWithMD({ NAME: classNameIdentifier, SUPER: superClass, // Needs Identifier node diff --git a/packages/preset/package-lock.json b/packages/preset/package-lock.json index 1205411..6309775 100644 --- a/packages/preset/package-lock.json +++ b/packages/preset/package-lock.json @@ -152,22 +152,6 @@ "color-convert": "^1.9.0" } }, - "array-flatten": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-2.1.2.tgz", - "integrity": "sha512-hNfzcOV8W4NdualtqBFPyVO+54DSJuZGY9qT4pRroB6S9e3iiido2ISIC5h9R2sPJ8H3FHCIiEnsv1lPXO3KtQ==" - }, - "babel-plugin-transform-modules-ui5": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/babel-plugin-transform-modules-ui5/-/babel-plugin-transform-modules-ui5-7.0.3.tgz", - "integrity": "sha512-NJgY/fPQqiLOO9bm5hoROQZ5qGfkrjJTj2KjGaz4Dq51mxXdxNYZTtbGC94PLWGWKL9zKeCWK3Ug4KwCPj5H6w==", - "requires": { - "array-flatten": "^2.1.2", - "doctrine": "^3.0.0", - "ignore-case": "^0.1.0", - "object-assign-defined": "^1.0.2" - } - }, "chalk": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", @@ -212,14 +196,6 @@ "ms": "^2.1.1" } }, - "doctrine": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", - "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==", - "requires": { - "esutils": "^2.0.2" - } - }, "escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", @@ -229,7 +205,8 @@ "esutils": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz", - "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=" + "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=", + "dev": true }, "globals": { "version": "11.12.0", @@ -243,11 +220,6 @@ "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", "dev": true }, - "ignore-case": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/ignore-case/-/ignore-case-0.1.0.tgz", - "integrity": "sha1-3Adh5l+wB5vhJQ0g4kWEMr3Apf4=" - }, "js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -287,11 +259,6 @@ "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "dev": true }, - "object-assign-defined": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/object-assign-defined/-/object-assign-defined-1.0.2.tgz", - "integrity": "sha512-xO24o25GXklHv9k1eQUvHpNpqhfv3sXmT4yQaLXdaig0EiK9ts7M2UECjjyIpEg8ckCiSZBec0qsAr4knbgdDA==" - }, "path-parse": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", From de2e329509e7577a9f5f6de56b9abbe026bcdaaf Mon Sep 17 00:00:00 2001 From: "WEISSENFELS, Niklas" Date: Wed, 13 Oct 2021 15:58:52 +0200 Subject: [PATCH 3/4] added npmrc --- .npmrc | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .npmrc diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..1882384 --- /dev/null +++ b/.npmrc @@ -0,0 +1,2 @@ +@registry=http://sst-sapgit.swtdev.local/api/v4/projects/131/packages/npm/ +//sst-sapgit.swtdev.local/api/v4/projects/131/packages/npm/:_authToken=rtu1Nwwo91wsdSW9PpdL \ No newline at end of file From 9a1a91922ccea908a4574a5aebcd3c2ba5d7eb0c Mon Sep 17 00:00:00 2001 From: "WEISSENFELS, Niklas" Date: Wed, 13 Oct 2021 16:58:02 +0200 Subject: [PATCH 4/4] renames to ser namespace --- .npmrc | 2 +- packages/plugin-transform-classes/.npmrc | 2 ++ packages/plugin-transform-classes/package-lock.json | 2 +- packages/plugin-transform-classes/package.json | 2 +- packages/plugin/.npmrc | 2 ++ packages/plugin/package-lock.json | 2 +- packages/plugin/package.json | 2 +- packages/preset/.npmrc | 2 ++ packages/preset/index.js | 2 +- packages/preset/package-lock.json | 2 +- packages/preset/package.json | 4 ++-- 11 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 packages/plugin-transform-classes/.npmrc create mode 100644 packages/plugin/.npmrc create mode 100644 packages/preset/.npmrc diff --git a/.npmrc b/.npmrc index 1882384..24b7ff7 100644 --- a/.npmrc +++ b/.npmrc @@ -1,2 +1,2 @@ -@registry=http://sst-sapgit.swtdev.local/api/v4/projects/131/packages/npm/ +@dx4babel:registry=http://sst-sapgit.swtdev.local/api/v4/projects/131/packages/npm/ //sst-sapgit.swtdev.local/api/v4/projects/131/packages/npm/:_authToken=rtu1Nwwo91wsdSW9PpdL \ No newline at end of file diff --git a/packages/plugin-transform-classes/.npmrc b/packages/plugin-transform-classes/.npmrc new file mode 100644 index 0000000..24b7ff7 --- /dev/null +++ b/packages/plugin-transform-classes/.npmrc @@ -0,0 +1,2 @@ +@dx4babel:registry=http://sst-sapgit.swtdev.local/api/v4/projects/131/packages/npm/ +//sst-sapgit.swtdev.local/api/v4/projects/131/packages/npm/:_authToken=rtu1Nwwo91wsdSW9PpdL \ No newline at end of file diff --git a/packages/plugin-transform-classes/package-lock.json b/packages/plugin-transform-classes/package-lock.json index d00f5b2..534b83b 100644 --- a/packages/plugin-transform-classes/package-lock.json +++ b/packages/plugin-transform-classes/package-lock.json @@ -1,5 +1,5 @@ { - "name": "babel-plugin-transform-classes-ui5", + "name": "@dx4babel/babel-plugin-transform-classes-ui5", "version": "7.0.2", "lockfileVersion": 1 } diff --git a/packages/plugin-transform-classes/package.json b/packages/plugin-transform-classes/package.json index e055ee3..8adc61d 100644 --- a/packages/plugin-transform-classes/package.json +++ b/packages/plugin-transform-classes/package.json @@ -1,5 +1,5 @@ { - "name": "babel-plugin-transform-classes-ui5", + "name": "@dx4babel/babel-plugin-transform-classes-ui5", "version": "7.0.2", "description": "An unofficial babel plugin for SAP UI5.", "main": "src/index.js", diff --git a/packages/plugin/.npmrc b/packages/plugin/.npmrc new file mode 100644 index 0000000..24b7ff7 --- /dev/null +++ b/packages/plugin/.npmrc @@ -0,0 +1,2 @@ +@dx4babel:registry=http://sst-sapgit.swtdev.local/api/v4/projects/131/packages/npm/ +//sst-sapgit.swtdev.local/api/v4/projects/131/packages/npm/:_authToken=rtu1Nwwo91wsdSW9PpdL \ No newline at end of file diff --git a/packages/plugin/package-lock.json b/packages/plugin/package-lock.json index 2138f02..9e5cd02 100644 --- a/packages/plugin/package-lock.json +++ b/packages/plugin/package-lock.json @@ -1,5 +1,5 @@ { - "name": "babel-plugin-transform-modules-ui5", + "name": "@dx4babel/babel-plugin-transform-modules-ui5", "version": "7.0.5", "lockfileVersion": 1, "requires": true, diff --git a/packages/plugin/package.json b/packages/plugin/package.json index 6394070..495c05e 100644 --- a/packages/plugin/package.json +++ b/packages/plugin/package.json @@ -1,5 +1,5 @@ { - "name": "babel-plugin-transform-modules-ui5", + "name": "@dx4babel/babel-plugin-transform-modules-ui5", "version": "7.0.5", "description": "An unofficial babel plugin for SAP UI5.", "main": "dist/index.js", diff --git a/packages/preset/.npmrc b/packages/preset/.npmrc new file mode 100644 index 0000000..24b7ff7 --- /dev/null +++ b/packages/preset/.npmrc @@ -0,0 +1,2 @@ +@dx4babel:registry=http://sst-sapgit.swtdev.local/api/v4/projects/131/packages/npm/ +//sst-sapgit.swtdev.local/api/v4/projects/131/packages/npm/:_authToken=rtu1Nwwo91wsdSW9PpdL \ No newline at end of file diff --git a/packages/preset/index.js b/packages/preset/index.js index c74aa44..2fb8a7d 100644 --- a/packages/preset/index.js +++ b/packages/preset/index.js @@ -1,4 +1,4 @@ -const transformUI5 = require("babel-plugin-transform-modules-ui5"); +const transformUI5 = require("@dx4babel/babel-plugin-transform-modules-ui5"); module.exports = (context, opts = {}) => ({ plugins: [[transformUI5, opts]], diff --git a/packages/preset/package-lock.json b/packages/preset/package-lock.json index de70dee..a8695f5 100644 --- a/packages/preset/package-lock.json +++ b/packages/preset/package-lock.json @@ -1,5 +1,5 @@ { - "name": "babel-preset-transform-ui5", + "name": "@dx4babel/babel-preset-transform-ui5", "version": "7.0.5", "lockfileVersion": 1, "requires": true, diff --git a/packages/preset/package.json b/packages/preset/package.json index 2cc47fa..c37d847 100644 --- a/packages/preset/package.json +++ b/packages/preset/package.json @@ -1,11 +1,11 @@ { - "name": "babel-preset-transform-ui5", + "name": "@dx4babel/babel-preset-transform-ui5", "version": "7.0.5", "main": "index.js", "license": "MIT", "repository": "https://github.com/r-murphy/babel-plugin-ui5/tree/master/packages/preset", "dependencies": { - "babel-plugin-transform-modules-ui5": "^7.0.5" + "@dx4babel/babel-plugin-transform-modules-ui5": "^7.0.5" }, "devDependencies": { "@babel/core": "^7.7.4",