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

Custom metadata implementation #62

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions packages/plugin-transform-classes/.npmrc
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion packages/plugin-transform-classes/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/plugin-transform-classes/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 2 additions & 0 deletions packages/plugin/.npmrc
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion packages/plugin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/plugin/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
23 changes: 17 additions & 6 deletions packages/plugin/src/classes/helpers/classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.metadata) {
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];
}
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/src/classes/helpers/jsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 18 additions & 1 deletion packages/plugin/src/classes/visitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions packages/plugin/src/utils/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions packages/preset/.npmrc
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion packages/preset/index.js
Original file line number Diff line number Diff line change
@@ -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]],
Expand Down
39 changes: 3 additions & 36 deletions packages/preset/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/preset/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down