@openrewrite/recipes-nodejs 0.34.0-20251117-134541 → 0.34.0-20251117-150614
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/migrate/{crypto-hash.d.ts → crypto-constructors.d.ts} +2 -2
- package/dist/migrate/crypto-constructors.d.ts.map +1 -0
- package/dist/migrate/{crypto-hash.js → crypto-constructors.js} +30 -17
- package/dist/migrate/crypto-constructors.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +2 -2
- package/src/migrate/crypto-constructors.ts +71 -0
- package/dist/migrate/crypto-hash.d.ts.map +0 -1
- package/dist/migrate/crypto-hash.js.map +0 -1
- package/src/migrate/crypto-hash.ts +0 -64
package/dist/index.js
CHANGED
|
@@ -4,11 +4,11 @@ exports.activate = activate;
|
|
|
4
4
|
const util_type_checking_1 = require("./migrate/util-type-checking");
|
|
5
5
|
const buffer_slice_1 = require("./migrate/buffer-slice");
|
|
6
6
|
const process_features_tls_1 = require("./migrate/process-features-tls");
|
|
7
|
-
const
|
|
7
|
+
const crypto_constructors_1 = require("./migrate/crypto-constructors");
|
|
8
8
|
function activate(registry) {
|
|
9
9
|
registry.register(util_type_checking_1.UseNativeTypeCheckingMethods);
|
|
10
10
|
registry.register(buffer_slice_1.ReplaceDeprecatedBufferSlice);
|
|
11
11
|
registry.register(process_features_tls_1.RemoveUsageOfProcessFeaturesTlsConstants);
|
|
12
|
-
registry.register(
|
|
12
|
+
registry.register(crypto_constructors_1.ReplaceCryptoConstructors);
|
|
13
13
|
}
|
|
14
14
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAOA,4BAKC;AAZD,qEAA0E;AAC1E,yDAAoE;AAEpE,yEAAwF;AACxF,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAOA,4BAKC;AAZD,qEAA0E;AAC1E,yDAAoE;AAEpE,yEAAwF;AACxF,uEAAwE;AAGxE,SAAgB,QAAQ,CAAC,QAAwB;IAC7C,QAAQ,CAAC,QAAQ,CAAC,iDAA4B,CAAC,CAAC;IAChD,QAAQ,CAAC,QAAQ,CAAC,2CAA4B,CAAC,CAAC;IAChD,QAAQ,CAAC,QAAQ,CAAC,+DAAwC,CAAC,CAAC;IAC5D,QAAQ,CAAC,QAAQ,CAAC,+CAAyB,CAAC,CAAC;AACjD,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ExecutionContext, Recipe, TreeVisitor } from "@openrewrite/rewrite";
|
|
2
|
-
export declare class
|
|
2
|
+
export declare class ReplaceCryptoConstructors extends Recipe {
|
|
3
3
|
readonly name = "org.openrewrite.node.migrate.crypto.replace-hash-constructor";
|
|
4
4
|
readonly displayName: string;
|
|
5
5
|
readonly description: string;
|
|
6
6
|
readonly tags: string[];
|
|
7
7
|
editor(): Promise<TreeVisitor<any, ExecutionContext>>;
|
|
8
8
|
}
|
|
9
|
-
//# sourceMappingURL=crypto-
|
|
9
|
+
//# sourceMappingURL=crypto-constructors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto-constructors.d.ts","sourceRoot":"","sources":["../../src/migrate/crypto-constructors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,gBAAgB,EAAE,MAAM,EAAE,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAUlF,qBAAa,yBAA0B,SAAQ,MAAM;IACjD,QAAQ,CAAC,IAAI,kEAAiE;IAC9E,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAyF;IACrH,QAAQ,CAAC,WAAW,EAAE,MAAM,CAA2M;IACvO,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAA0B;IAE3C,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;CAsD9D"}
|
|
@@ -9,17 +9,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.ReplaceCryptoConstructors = void 0;
|
|
13
13
|
const rewrite_1 = require("@openrewrite/rewrite");
|
|
14
14
|
const javascript_1 = require("@openrewrite/rewrite/javascript");
|
|
15
15
|
const java_1 = require("@openrewrite/rewrite/java");
|
|
16
|
-
class
|
|
16
|
+
class ReplaceCryptoConstructors extends rewrite_1.Recipe {
|
|
17
17
|
constructor() {
|
|
18
18
|
super(...arguments);
|
|
19
19
|
this.name = "org.openrewrite.node.migrate.crypto.replace-hash-constructor";
|
|
20
|
-
this.displayName = "Replace deprecated `new crypto.Hash()`
|
|
21
|
-
this.description = "Replace deprecated `new crypto.Hash(algorithm)` constructor calls with `crypto.createHash(algorithm)` factory
|
|
22
|
-
this.tags = ["DEP0179"];
|
|
20
|
+
this.displayName = "Replace deprecated `new crypto.Hash()` and `new crypto.Hmac()` with factory methods";
|
|
21
|
+
this.description = "Replace deprecated `new crypto.Hash(algorithm)` constructor calls with `crypto.createHash(algorithm)` and `new crypto.Hmac(algorithm, key)` with `crypto.createHmac(algorithm, key)` factory methods.";
|
|
22
|
+
this.tags = ["DEP0179", "DEP0181"];
|
|
23
23
|
}
|
|
24
24
|
editor() {
|
|
25
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -32,28 +32,41 @@ class ReplaceCryptoHashConstructor extends rewrite_1.Recipe {
|
|
|
32
32
|
var _a, _b;
|
|
33
33
|
const clazz = newClass.class;
|
|
34
34
|
const args = (_a = newClass.arguments) === null || _a === void 0 ? void 0 : _a.elements;
|
|
35
|
-
if (!args || args.length !== 1) {
|
|
35
|
+
if (!args || (args.length !== 1 && args.length !== 2)) {
|
|
36
36
|
return _super.visitNewClass.call(this, newClass, p);
|
|
37
37
|
}
|
|
38
|
-
const
|
|
38
|
+
const firstArg = args[0].element;
|
|
39
39
|
if (clazz && clazz.kind === java_1.J.Kind.FieldAccess) {
|
|
40
40
|
const fieldAccess = clazz;
|
|
41
41
|
const target = fieldAccess.target;
|
|
42
42
|
if (target.kind === java_1.J.Kind.Identifier
|
|
43
|
-
&& ((_b = clazz.type) === null || _b === void 0 ? void 0 : _b.kind) == java_1.Type.Kind.Class
|
|
44
|
-
|
|
43
|
+
&& ((_b = clazz.type) === null || _b === void 0 ? void 0 : _b.kind) == java_1.Type.Kind.Class) {
|
|
44
|
+
const fullyQualifiedName = clazz.type.fullyQualifiedName;
|
|
45
45
|
const cryptoIdentifier = target;
|
|
46
|
-
|
|
46
|
+
if (fullyQualifiedName == "crypto.Hash" && args.length === 1) {
|
|
47
|
+
return yield (0, javascript_1.template) `${cryptoIdentifier}.createHash(${firstArg})`.apply(this.cursor, newClass);
|
|
48
|
+
}
|
|
49
|
+
else if (fullyQualifiedName == "crypto.Hmac" && args.length === 2) {
|
|
50
|
+
const secondArg = args[1].element;
|
|
51
|
+
return yield (0, javascript_1.template) `${cryptoIdentifier}.createHmac(${firstArg}, ${secondArg})`.apply(this.cursor, newClass);
|
|
52
|
+
}
|
|
47
53
|
}
|
|
48
54
|
}
|
|
49
55
|
if (clazz && clazz.kind === java_1.J.Kind.Identifier) {
|
|
50
56
|
const constructorType = newClass.constructorType;
|
|
51
57
|
if ((constructorType === null || constructorType === void 0 ? void 0 : constructorType.declaringType.kind) == java_1.Type.Kind.Class
|
|
52
|
-
&& constructorType.declaringType.fullyQualifiedName == "crypto"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
&& constructorType.declaringType.fullyQualifiedName == "crypto") {
|
|
59
|
+
if (constructorType.name == "Hash" && args.length === 1) {
|
|
60
|
+
(0, javascript_1.maybeAddImport)(this, { target: "crypto", member: "createHash", onlyIfReferenced: false });
|
|
61
|
+
(0, javascript_1.maybeRemoveImport)(this, "crypto", "Hash");
|
|
62
|
+
return yield (0, javascript_1.template) `createHash(${firstArg})`.apply(this.cursor, newClass);
|
|
63
|
+
}
|
|
64
|
+
else if (constructorType.name == "Hmac" && args.length === 2) {
|
|
65
|
+
const secondArg = args[1].element;
|
|
66
|
+
(0, javascript_1.maybeAddImport)(this, { target: "crypto", member: "createHmac", onlyIfReferenced: false });
|
|
67
|
+
(0, javascript_1.maybeRemoveImport)(this, "crypto", "Hmac");
|
|
68
|
+
return yield (0, javascript_1.template) `createHmac(${firstArg}, ${secondArg})`.apply(this.cursor, newClass);
|
|
69
|
+
}
|
|
57
70
|
}
|
|
58
71
|
}
|
|
59
72
|
return _super.visitNewClass.call(this, newClass, p);
|
|
@@ -63,5 +76,5 @@ class ReplaceCryptoHashConstructor extends rewrite_1.Recipe {
|
|
|
63
76
|
});
|
|
64
77
|
}
|
|
65
78
|
}
|
|
66
|
-
exports.
|
|
67
|
-
//# sourceMappingURL=crypto-
|
|
79
|
+
exports.ReplaceCryptoConstructors = ReplaceCryptoConstructors;
|
|
80
|
+
//# sourceMappingURL=crypto-constructors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto-constructors.js","sourceRoot":"","sources":["../../src/migrate/crypto-constructors.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAAkF;AAClF,gEAMyC;AACzC,oDAA8D;AAE9D,MAAa,yBAA0B,SAAQ,gBAAM;IAArD;;QACa,SAAI,GAAG,8DAA8D,CAAA;QACrE,gBAAW,GAAW,qFAAqF,CAAC;QAC5G,gBAAW,GAAW,uMAAuM,CAAC;QAC9N,SAAI,GAAa,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAwDrD,CAAC;IAtDS,MAAM;;YACR,OAAO,IAAI,KAAM,SAAQ,8BAAmC;gBACxC,aAAa,CAAC,QAAoB,EAAE,CAAmB;;;;;;wBACnE,MAAM,KAAK,GAAG,Q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AE,QAAQ,EAAE,MAAM,CAAC,CAAC;oCAC1C,OAAO,MAAM,IAAA,qBAAQ,EAAA,cAAc,QAAQ,KAAK,SAAS,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;gCAC9F,CAAC;4BACL,CAAC;wBACL,CAAC;wBAED,OAAO,OAAM,aAAa,YAAC,QAAQ,EAAE,CAAC,EAAE;oBAC5C,CAAC;iBAAA;aACJ,CAAC;QACN,CAAC;KAAA;CACJ;AA5DD,8DA4DC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openrewrite/recipes-nodejs",
|
|
3
|
-
"version": "0.34.0-20251117-
|
|
3
|
+
"version": "0.34.0-20251117-150614",
|
|
4
4
|
"license": "Moderne Source Available License",
|
|
5
5
|
"description": "OpenRewrite recipes for Node.js library migrations.",
|
|
6
6
|
"homepage": "https://github.com/moderneinc/rewrite-node",
|
package/src/index.ts
CHANGED
|
@@ -2,12 +2,12 @@ import {UseNativeTypeCheckingMethods} from "./migrate/util-type-checking";
|
|
|
2
2
|
import {ReplaceDeprecatedBufferSlice} from "./migrate/buffer-slice";
|
|
3
3
|
import {RecipeRegistry} from "@openrewrite/rewrite";
|
|
4
4
|
import {RemoveUsageOfProcessFeaturesTlsConstants} from "./migrate/process-features-tls";
|
|
5
|
-
import {
|
|
5
|
+
import {ReplaceCryptoConstructors} from "./migrate/crypto-constructors";
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
export function activate(registry: RecipeRegistry) {
|
|
9
9
|
registry.register(UseNativeTypeCheckingMethods);
|
|
10
10
|
registry.register(ReplaceDeprecatedBufferSlice);
|
|
11
11
|
registry.register(RemoveUsageOfProcessFeaturesTlsConstants);
|
|
12
|
-
registry.register(
|
|
12
|
+
registry.register(ReplaceCryptoConstructors);
|
|
13
13
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import {check, ExecutionContext, Recipe, TreeVisitor} from "@openrewrite/rewrite";
|
|
2
|
+
import {
|
|
3
|
+
JavaScriptVisitor,
|
|
4
|
+
maybeAddImport,
|
|
5
|
+
maybeRemoveImport,
|
|
6
|
+
template,
|
|
7
|
+
usesType
|
|
8
|
+
} from "@openrewrite/rewrite/javascript";
|
|
9
|
+
import {Expression, J, Type} from "@openrewrite/rewrite/java";
|
|
10
|
+
|
|
11
|
+
export class ReplaceCryptoConstructors extends Recipe {
|
|
12
|
+
readonly name = "org.openrewrite.node.migrate.crypto.replace-hash-constructor"
|
|
13
|
+
readonly displayName: string = "Replace deprecated `new crypto.Hash()` and `new crypto.Hmac()` with factory methods";
|
|
14
|
+
readonly description: string = "Replace deprecated `new crypto.Hash(algorithm)` constructor calls with `crypto.createHash(algorithm)` and `new crypto.Hmac(algorithm, key)` with `crypto.createHmac(algorithm, key)` factory methods.";
|
|
15
|
+
readonly tags: string[] = ["DEP0179", "DEP0181"];
|
|
16
|
+
|
|
17
|
+
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
18
|
+
return new class extends JavaScriptVisitor<ExecutionContext> {
|
|
19
|
+
protected async visitNewClass(newClass: J.NewClass, p: ExecutionContext): Promise<J | undefined> {
|
|
20
|
+
const clazz = newClass.class;
|
|
21
|
+
const args = newClass.arguments?.elements;
|
|
22
|
+
|
|
23
|
+
if (!args || (args.length !== 1 && args.length !== 2)) {
|
|
24
|
+
return super.visitNewClass(newClass, p);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const firstArg = args[0].element;
|
|
28
|
+
|
|
29
|
+
// Case 1: new crypto.Hash(...) or new crypto.Hmac(...) or new identifier.Hash(...) or new identifier.Hmac(...)
|
|
30
|
+
if (clazz && clazz.kind === J.Kind.FieldAccess) {
|
|
31
|
+
const fieldAccess = clazz as J.FieldAccess;
|
|
32
|
+
const target = fieldAccess.target;
|
|
33
|
+
|
|
34
|
+
if (target.kind === J.Kind.Identifier
|
|
35
|
+
&& (clazz as J.FieldAccess).type?.kind == Type.Kind.Class) {
|
|
36
|
+
const fullyQualifiedName = ((clazz as J.FieldAccess).type as Type.Class).fullyQualifiedName;
|
|
37
|
+
const cryptoIdentifier = target as J.Identifier;
|
|
38
|
+
|
|
39
|
+
if (fullyQualifiedName == "crypto.Hash" && args.length === 1) {
|
|
40
|
+
return await template`${cryptoIdentifier}.createHash(${firstArg})`.apply(this.cursor, newClass);
|
|
41
|
+
} else if (fullyQualifiedName == "crypto.Hmac" && args.length === 2) {
|
|
42
|
+
const secondArg = args[1].element;
|
|
43
|
+
return await template`${cryptoIdentifier}.createHmac(${firstArg}, ${secondArg})`.apply(this.cursor, newClass);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Case 2: new Hash(...) or new Hmac(...) - direct import
|
|
49
|
+
if (clazz && clazz.kind === J.Kind.Identifier) {
|
|
50
|
+
const constructorType = newClass.constructorType;
|
|
51
|
+
if (constructorType?.declaringType.kind == Type.Kind.Class
|
|
52
|
+
&& (constructorType.declaringType as Type.Class).fullyQualifiedName == "crypto") {
|
|
53
|
+
|
|
54
|
+
if (constructorType.name == "Hash" && args.length === 1) {
|
|
55
|
+
maybeAddImport(this, {target: "crypto", member: "createHash", onlyIfReferenced: false});
|
|
56
|
+
maybeRemoveImport(this, "crypto", "Hash");
|
|
57
|
+
return await template`createHash(${firstArg})`.apply(this.cursor, newClass);
|
|
58
|
+
} else if (constructorType.name == "Hmac" && args.length === 2) {
|
|
59
|
+
const secondArg = args[1].element;
|
|
60
|
+
maybeAddImport(this, {target: "crypto", member: "createHmac", onlyIfReferenced: false});
|
|
61
|
+
maybeRemoveImport(this, "crypto", "Hmac");
|
|
62
|
+
return await template`createHmac(${firstArg}, ${secondArg})`.apply(this.cursor, newClass);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return super.visitNewClass(newClass, p);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"crypto-hash.d.ts","sourceRoot":"","sources":["../../src/migrate/crypto-hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,gBAAgB,EAAE,MAAM,EAAE,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAgBlF,qBAAa,4BAA6B,SAAQ,MAAM;IACpD,QAAQ,CAAC,IAAI,kEAAiE;IAC9E,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAuE;IACnG,QAAQ,CAAC,WAAW,EAAE,MAAM,CAA2H;IACvJ,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAe;IAEhC,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;CAyC9D"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"crypto-hash.js","sourceRoot":"","sources":["../../src/migrate/crypto-hash.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAAkF;AAClF,gEAMyC;AACzC,oDAA8D;AAQ9D,MAAa,4BAA6B,SAAQ,gBAAM;IAAxD;;QACa,SAAI,GAAG,8DAA8D,CAAA;QACrE,gBAAW,GAAW,mEAAmE,CAAC;QAC1F,gBAAW,GAAW,uHAAuH,CAAC;QAC9I,SAAI,GAAa,CAAC,SAAS,CAAC,CAAC;IA2C1C,CAAC;IAzCS,MAAM;;YACR,OAAO,IAAI,KAAM,SAAQ,8BAAmC;gBACxC,aAAa,CAAC,QAAoB,EAAE,CAAmB;;;;;;wBACnE,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;wBAC7B,MAAM,IAAI,GAAG,MAAA,QAAQ,CAAC,SAAS,0CAAE,QAAQ,CAAC;wBAE1C,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;4BAC7B,OAAO,OAAM,aAAa,YAAC,QAAQ,EAAE,CAAC,EAA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MAAM,CAAC,CAAC;gCAC1C,OAAO,MAAM,IAAA,qBAAQ,EAAA,cAAc,SAAS,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;4BACjF,CAAC;wBACL,CAAC;wBAED,OAAO,OAAM,aAAa,YAAC,QAAQ,EAAE,CAAC,EAAE;oBAC5C,CAAC;iBAAA;aACJ,CAAC;QACN,CAAC;KAAA;CACJ;AA/CD,oEA+CC"}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import {check, ExecutionContext, Recipe, TreeVisitor} from "@openrewrite/rewrite";
|
|
2
|
-
import {
|
|
3
|
-
JavaScriptVisitor,
|
|
4
|
-
maybeAddImport,
|
|
5
|
-
maybeRemoveImport,
|
|
6
|
-
template,
|
|
7
|
-
usesType
|
|
8
|
-
} from "@openrewrite/rewrite/javascript";
|
|
9
|
-
import {Expression, J, Type} from "@openrewrite/rewrite/java";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Replace deprecated new crypto.Hash() constructor with crypto.createHash()
|
|
13
|
-
*
|
|
14
|
-
* DEP0179: new crypto.Hash() was deprecated because the crypto.Hash class
|
|
15
|
-
* should not be instantiated directly. Use the crypto.createHash() factory method instead.
|
|
16
|
-
*/
|
|
17
|
-
export class ReplaceCryptoHashConstructor extends Recipe {
|
|
18
|
-
readonly name = "org.openrewrite.node.migrate.crypto.replace-hash-constructor"
|
|
19
|
-
readonly displayName: string = "Replace deprecated `new crypto.Hash()` with `crypto.createHash()`";
|
|
20
|
-
readonly description: string = "Replace deprecated `new crypto.Hash(algorithm)` constructor calls with `crypto.createHash(algorithm)` factory method.";
|
|
21
|
-
readonly tags: string[] = ["DEP0179"];
|
|
22
|
-
|
|
23
|
-
async editor(): Promise<TreeVisitor<any, ExecutionContext>> {
|
|
24
|
-
return new class extends JavaScriptVisitor<ExecutionContext> {
|
|
25
|
-
protected async visitNewClass(newClass: J.NewClass, p: ExecutionContext): Promise<J | undefined> {
|
|
26
|
-
const clazz = newClass.class;
|
|
27
|
-
const args = newClass.arguments?.elements;
|
|
28
|
-
|
|
29
|
-
if (!args || args.length !== 1) {
|
|
30
|
-
return super.visitNewClass(newClass, p);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const algorithm = args[0].element;
|
|
34
|
-
|
|
35
|
-
// Case 1: new crypto.Hash(...) or new identifier.Hash(...)
|
|
36
|
-
if (clazz && clazz.kind === J.Kind.FieldAccess) {
|
|
37
|
-
const fieldAccess = clazz as J.FieldAccess;
|
|
38
|
-
const target = fieldAccess.target;
|
|
39
|
-
|
|
40
|
-
if (target.kind === J.Kind.Identifier
|
|
41
|
-
&& (clazz as J.FieldAccess).type?.kind == Type.Kind.Class
|
|
42
|
-
&& ((clazz as J.FieldAccess).type as Type.Class).fullyQualifiedName == "crypto.Hash") {
|
|
43
|
-
const cryptoIdentifier = target as J.Identifier;
|
|
44
|
-
return await template`${cryptoIdentifier}.createHash(${algorithm})`.apply(this.cursor, newClass);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Case 2: new Hash(...) or new CryptoHash(...) - direct import
|
|
49
|
-
if (clazz && clazz.kind === J.Kind.Identifier) {
|
|
50
|
-
const constructorType = newClass.constructorType;
|
|
51
|
-
if (constructorType?.declaringType.kind == Type.Kind.Class
|
|
52
|
-
&& (constructorType.declaringType as Type.Class).fullyQualifiedName == "crypto"
|
|
53
|
-
&& constructorType.name == "Hash") {
|
|
54
|
-
maybeAddImport(this, {target: "crypto", member: "createHash", onlyIfReferenced: false});
|
|
55
|
-
maybeRemoveImport(this, "crypto", "Hash");
|
|
56
|
-
return await template`createHash(${algorithm})`.apply(this.cursor, newClass);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return super.visitNewClass(newClass, p);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
}
|