Skip to content

Commit

Permalink
fix: copyright comment must be appended as leading comment to file (#108
Browse files Browse the repository at this point in the history
)
  • Loading branch information
petermuessig committed Jul 18, 2023
1 parent 744a183 commit 8194671
Show file tree
Hide file tree
Showing 13 changed files with 400 additions and 10 deletions.
236 changes: 230 additions & 6 deletions packages/plugin/__test__/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,15 @@ exports[`classic sap-ui-define-copyright.ts 1`] = `
sap.ui.define("", ["foo/bar/MyResource"]);"
`;

exports[`classic sap-ui-define-copyright-file.ts 1`] = `
"/*!
* \${copyright}
*/
// define class
sap.ui.define("", ["foo/bar/MyResource"]);"
`;

exports[`comments copyright.js 1`] = `
"/*!
* \${copyright}
Expand All @@ -604,6 +613,22 @@ sap.ui.define(["sap/SAPClass"], function (SAPClass) {
});"
`;

exports[`comments copyright-file.js 1`] = `
"/*!
* \${copyright}
*/
sap.ui.define(["sap/SAPClass"], function (SAPClass) {
// some imports
const Levels = SAPClass["Levels"];
/**
* @name test.fixtures.libs.MyClass
*/
const MyClass = SAPClass.extend("test.fixtures.libs.MyClass", {});
MyClass.Levels = Levels;
return MyClass;
});"
`;

exports[`comments copyright-multiple-comments.js 1`] = `
"/*!
* \${copyright}
Expand Down Expand Up @@ -633,11 +658,11 @@ sap.ui.define([], function () {
`;

exports[`comments min-wrap-simple-copyright.js 1`] = `
""use strict";
/*!
"/*!
* \${copyright}
*/
"use strict";
const x = 1; // This should not be part of sap-ui-define
sap.ui.define(["./foo"], function (__Foo) {
function _interopRequireDefault(obj) {
Expand All @@ -650,11 +675,11 @@ sap.ui.define(["./foo"], function (__Foo) {
`;

exports[`comments min-wrap-ui5-copyright.js 1`] = `
""use strict";
/*!
"/*!
* \${copyright}
*/
"use strict";
const x = 1; // This should not be part of sap-ui-define
sap.ui.define(["sap/m/Button"], function (Button) {
const b = new Button();
Expand Down Expand Up @@ -1390,6 +1415,27 @@ sap.ui.define(["sap/Class"], function (SAPClass) {
});"
`;
exports[`typescript ts-class-anonymous-copyright-file.ts 1`] = `
"/*!
* \${copyright}
*/
sap.ui.define(["sap/Class"], function (SAPClass) {
/**
* @name MyClass
*/
const MyClass = SAPClass.extend("MyClass", {
createAnonymousClass: function _createAnonymousClass() {
return new class {
getClipboardContentType() {
/* ... */
}
}();
}
});
return MyClass;
});"
`;
exports[`typescript ts-class-param-props.ts 1`] = `
"sap.ui.define(["sap/Class"], function (SAPClass) {
const MyClass = SAPClass.extend("MyClass", {
Expand Down Expand Up @@ -1426,6 +1472,27 @@ sap.ui.define(["sap/Class"], function (SAPClass) {
});"
`;
exports[`typescript ts-class-param-props-copyright-file.ts 1`] = `
"/*!
* \${copyright}
*/
sap.ui.define(["sap/Class"], function (SAPClass) {
/**
* @name MyClass
*/
const MyClass = SAPClass.extend("MyClass", {
constructor: function _constructor(bar, x, y) {
SAPClass.prototype.constructor.call(this);
this.bar = bar;
this.x = x;
this.y = y;
this.foo = bar.getFoo();
}
});
return MyClass;
});"
`;
exports[`typescript ts-class-props.ts 1`] = `
"sap.ui.define(["sap/Class"], function (SAPClass) {
const MyClass = SAPClass.extend("MyClass", {
Expand Down Expand Up @@ -1528,6 +1595,163 @@ exports[`typescript ts-export-type.ts 1`] = `
});"
`;
exports[`typescript-preset-env ts-class-anonymous.ts 1`] = `
"sap.ui.define(["sap/Class"], function (SAPClass) {
import "core-js/modules/es6.symbol.js";
import "core-js/modules/es6.number.constructor.js";
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
var MyClass = SAPClass.extend("MyClass", {
createAnonymousClass: function _createAnonymousClass() {
return new (function () {
function _class() {
_classCallCheck(this, _class);
}
_createClass(_class, [{
key: "getClipboardContentType",
value: function getClipboardContentType() {}
}]);
return _class;
}())();
}
});
return MyClass;
});"
`;
exports[`typescript-preset-env ts-class-anonymous-copyright.ts 1`] = `
"/*!
* \${copyright}
*/
sap.ui.define(["sap/Class"], function (SAPClass) {
import "core-js/modules/es6.symbol.js";
import "core-js/modules/es6.number.constructor.js";
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
/**
* @name MyClass
*/
var MyClass = SAPClass.extend("MyClass", {
createAnonymousClass: function _createAnonymousClass() {
return new ( /*#__PURE__*/function () {
function _class() {
_classCallCheck(this, _class);
}
_createClass(_class, [{
key: "getClipboardContentType",
value: function getClipboardContentType() {
/* ... */
}
}]);
return _class;
}())();
}
});
return MyClass;
});"
`;
exports[`typescript-preset-env ts-class-anonymous-copyright-file.ts 1`] = `
"/*!
* \${copyright}
*/
sap.ui.define(["sap/Class"], function (SAPClass) {
import "core-js/modules/es6.symbol.js";
import "core-js/modules/es6.number.constructor.js";
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
/**
* @name MyClass
*/
var MyClass = SAPClass.extend("MyClass", {
createAnonymousClass: function _createAnonymousClass() {
return new ( /*#__PURE__*/function () {
function _class() {
_classCallCheck(this, _class);
}
_createClass(_class, [{
key: "getClipboardContentType",
value: function getClipboardContentType() {
/* ... */
}
}]);
return _class;
}())();
}
});
return MyClass;
});"
`;
exports[`typescript-preset-env ts-class-param-props.ts 1`] = `
"sap.ui.define(["sap/Class"], function (SAPClass) {
var MyClass = SAPClass.extend("MyClass", {
constructor: function _constructor(bar, x, y) {
SAPClass.prototype.constructor.call(this);
this.bar = bar;
this.x = x;
this.y = y;
this.foo = bar.getFoo();
}
});
return MyClass;
});"
`;
exports[`typescript-preset-env ts-class-param-props-copyright.ts 1`] = `
"/*!
* \${copyright}
*/
sap.ui.define(["sap/Class"], function (SAPClass) {
/**
* @name MyClass
*/
var MyClass = SAPClass.extend("MyClass", {
constructor: function _constructor(bar, x, y) {
SAPClass.prototype.constructor.call(this);
this.bar = bar;
this.x = x;
this.y = y;
this.foo = bar.getFoo();
}
});
return MyClass;
});"
`;
exports[`typescript-preset-env ts-class-param-props-copyright-file.ts 1`] = `
"/*!
* \${copyright}
*/
sap.ui.define(["sap/Class"], function (SAPClass) {
/**
* @name MyClass
*/
var MyClass = SAPClass.extend("MyClass", {
constructor: function _constructor(bar, x, y) {
SAPClass.prototype.constructor.call(this);
this.bar = bar;
this.x = x;
this.y = y;
this.foo = bar.getFoo();
}
});
return MyClass;
});"
`;
exports[`wrapping export-const.js 1`] = `
"sap.ui.define([], function () {
const X = {};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*!
* ${copyright}
*/

// define class
sap.ui.define("", ["foo/bar/MyResource"]);
13 changes: 13 additions & 0 deletions packages/plugin/__test__/fixtures/comments/copyright-file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*!
* ${copyright}
*/

// some imports
import SAPClass, { Levels } from "sap/SAPClass";

/**
* @name test.fixtures.libs.MyClass
*/
export default class MyClass extends SAPClass {
static Levels = Levels;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*!
* ${copyright}
*/

// some imports
import SAPClass from "sap/Class";
import IClipboardContent from "sap/IClipboardContent";

/**
* @name MyClass
*/
export default class MyClass extends SAPClass {
createAnonymousClass() {
return new (class implements IClipboardContent {
getClipboardContentType() {
/* ... */
}
})();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*!
* ${copyright}
*/
import SAPClass from "sap/Class";
import IClipboardContent from "sap/IClipboardContent";

/**
* @name MyClass
*/
export default class MyClass extends SAPClass {
createAnonymousClass() {
return new (class implements IClipboardContent {
getClipboardContentType() {
/* ... */
}
})();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import SAPClass from "sap/Class";
import IClipboardContent from "sap/IClipboardContent";

/**
* @name MyClass
*/
export default class MyClass extends SAPClass {
createAnonymousClass() {
return new (class implements IClipboardContent {
getClipboardContentType() {
/* ... */
}
})();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*!
* ${copyright}
*/

// some imports
import SAPClass from "sap/Class";
import SAPBar from "sap/Bar";
import SAPFoo from "sap/Foo";

/**
* @name MyClass
*/
export default class MyClass extends SAPClass {
foo: SAPFoo;

constructor(public bar: SAPBar, private x: string, readonly y: string) {
super();
this.foo = bar.getFoo();
}
}

0 comments on commit 8194671

Please sign in to comment.