Skip to content

Commit

Permalink
Support typescript 4.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Bocharov committed Sep 8, 2022
1 parent 6189c2a commit d1f34dc
Show file tree
Hide file tree
Showing 15 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"homepage": "https://github.com/timocov/ts-transformer-minify-privates#readme",
"peerDependencies": {
"typescript": ">=2.9.1"
"typescript": ">=4.8.2"
},
"devDependencies": {
"@types/chai": "~4.1.7",
Expand All @@ -35,7 +35,7 @@
"mocha": "~6.2.2",
"ts-node": "~8.4.1",
"tslint": "~5.20.0",
"typescript": "~3.6.4"
"typescript": "^4.8.2"
},
"scripts": {
"tsc": "tsc -p .",
Expand Down
6 changes: 4 additions & 2 deletions src/properties-minifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ function hasPrivateKeyword(node: ClassMember | ts.ParameterDeclaration): boolean
}

function hasModifier(node: ts.Node, modifier: ts.SyntaxKind): boolean {
return node.modifiers !== undefined && node.modifiers.some((mod: ts.Modifier) => mod.kind === modifier);
const modifiers = ts.canHaveModifiers(node) ? ts.getModifiers(node): undefined;

return modifiers !== undefined && modifiers.some((mod: ts.Modifier) => mod.kind === modifier);
}

type AccessExpression = ts.PropertyAccessExpression | ts.ElementAccessExpression;
Expand Down Expand Up @@ -196,5 +198,5 @@ function isPrivateNonStaticClassMember(symbol: ts.Symbol | undefined): boolean {
}

function hasDecorators(node: ts.Node): boolean {
return !!node.decorators;
return ts.canHaveDecorators(node) && !!ts.getDecorators(node);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Class = void 0;
var Class = /** @class */ (function () {
function Class() {
this._private_pimp = {};
Expand Down
1 change: 1 addition & 0 deletions tests/test-cases/accessing-to-other-instance/output.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Class = void 0;
var Class = /** @class */ (function () {
function Class() {
this._private_field = Math.random();
Expand Down
1 change: 1 addition & 0 deletions tests/test-cases/accessing-via-prototype/output.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Class = void 0;
var Class = /** @class */ (function () {
function Class() {
this._private_privateField = 'string-value';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Class = void 0;
var Class = /** @class */ (function () {
function Class(publicField, protectedField, _private_privateField) {
this.publicField = publicField;
Expand Down
1 change: 1 addition & 0 deletions tests/test-cases/destructuring-this/output.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Class = void 0;
var Class = /** @class */ (function () {
function Class() {
this._private_privateField = 'string-value';
Expand Down
1 change: 1 addition & 0 deletions tests/test-cases/indexed-access-in-this/output.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Class = void 0;
var obj = {};
var Class = /** @class */ (function () {
function Class() {
Expand Down
1 change: 1 addition & 0 deletions tests/test-cases/numbered-props/output.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Class = void 0;
var Class = /** @class */ (function () {
function Class() {
this[356] = 3;
Expand Down
1 change: 1 addition & 0 deletions tests/test-cases/private-constructor/output.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Class = void 0;
var Class = /** @class */ (function () {
function Class() {
console.log('hey');
Expand Down
1 change: 1 addition & 0 deletions tests/test-cases/private-method-as-props/output.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Class = void 0;
var Class = /** @class */ (function () {
function Class() {
this._private_methodAsProperty = function () {
Expand Down
1 change: 1 addition & 0 deletions tests/test-cases/private-static-fields/output.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Class = void 0;
var Class = /** @class */ (function () {
function Class() {
this.publicField = 123;
Expand Down
1 change: 1 addition & 0 deletions tests/test-cases/private-with-decorators/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Class = void 0;
var Class = /** @class */ (function () {
function Class() {
this.publicField = 123;
Expand Down
1 change: 1 addition & 0 deletions tests/test-cases/reference-ctor-params/output.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Class = void 0;
var Class = /** @class */ (function () {
function Class(_private_privateField) {
this._private_privateField = _private_privateField;
Expand Down
1 change: 1 addition & 0 deletions tests/test-cases/simple/output.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Class = void 0;
var Class = /** @class */ (function () {
function Class() {
this.publicField = 123;
Expand Down

0 comments on commit d1f34dc

Please sign in to comment.