ts-codemod-lib 4.0.0 → 4.0.1
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/functions/ast-transformers/append-as-const.d.mts +9 -10
- package/dist/functions/ast-transformers/append-as-const.d.mts.map +1 -1
- package/dist/functions/ast-transformers/append-as-const.mjs +123 -114
- package/dist/functions/ast-transformers/append-as-const.mjs.map +1 -1
- package/dist/functions/ast-transformers/convert-to-readonly.d.mts +4 -4
- package/dist/functions/ast-transformers/convert-to-readonly.mjs +248 -252
- package/dist/functions/ast-transformers/convert-to-readonly.mjs.map +1 -1
- package/dist/functions/ast-transformers/enable-no-unchecked-indexed-access.d.mts +8 -8
- package/dist/functions/ast-transformers/enable-no-unchecked-indexed-access.mjs +103 -104
- package/dist/functions/ast-transformers/enable-no-unchecked-indexed-access.mjs.map +1 -1
- package/dist/functions/ast-transformers/replace-record-with-unknown-record.d.mts +2 -2
- package/dist/functions/ast-transformers/replace-record-with-unknown-record.mjs +51 -51
- package/dist/functions/ast-transformers/replace-record-with-unknown-record.mjs.map +1 -1
- package/dist/functions/ast-transformers/transform-source-code.d.mts.map +1 -1
- package/dist/functions/ast-transformers/transform-source-code.mjs +69 -69
- package/dist/functions/ast-transformers/transform-source-code.mjs.map +1 -1
- package/dist/functions/constants/mutable-prefixes.d.mts +8 -8
- package/dist/functions/functions/has-disable-next-line-comment.mjs +23 -23
- package/dist/functions/functions/has-disable-next-line-comment.mjs.map +1 -1
- package/dist/functions/functions/is-readonly-node.d.mts +2 -2
- package/dist/functions/functions/is-readonly-node.d.mts.map +1 -1
- package/dist/functions/functions/is-readonly-node.mjs +13 -13
- package/dist/functions/functions/is-readonly-node.mjs.map +1 -1
- package/dist/functions/functions/wrap-with-parentheses.d.mts +2 -2
- package/dist/functions/functions/wrap-with-parentheses.d.mts.map +1 -1
- package/dist/functions/functions/wrap-with-parentheses.mjs +87 -32
- package/dist/functions/functions/wrap-with-parentheses.mjs.map +1 -1
- package/dist/functions/utils/replace-node-with-text.d.mts +10 -11
- package/dist/functions/utils/replace-node-with-text.d.mts.map +1 -1
- package/dist/functions/utils/replace-node-with-text.mjs +0 -1
- package/dist/functions/utils/replace-node-with-text.mjs.map +1 -1
- package/package.json +6 -6
- package/src/functions/ast-transformers/append-as-const.mts +242 -231
- package/src/functions/ast-transformers/append-as-const.test.mts +39 -6
- package/src/functions/ast-transformers/convert-to-readonly.mts +467 -471
- package/src/functions/ast-transformers/convert-to-readonly.test.mts +60 -33
- package/src/functions/ast-transformers/enable-no-unchecked-indexed-access.mts +178 -179
- package/src/functions/ast-transformers/enable-no-unchecked-indexed-access.test.mts +29 -29
- package/src/functions/ast-transformers/replace-any-with-unknown.test.mts +6 -6
- package/src/functions/ast-transformers/replace-record-with-unknown-record.mts +75 -75
- package/src/functions/ast-transformers/replace-record-with-unknown-record.test.mts +6 -6
- package/src/functions/ast-transformers/transform-source-code.mts +110 -110
- package/src/functions/ast-transformers/transformer-specific-ignore.test.mts +6 -6
- package/src/functions/constants/mutable-prefixes.mts +8 -8
- package/src/functions/functions/has-disable-next-line-comment.mts +35 -35
- package/src/functions/functions/is-readonly-node.mts +25 -25
- package/src/functions/functions/wrap-with-parentheses.mts +138 -52
- package/src/functions/functions/wrap-with-parentheses.test.mts +115 -0
- package/src/functions/utils/replace-node-with-text.mts +10 -11
|
@@ -8,6 +8,12 @@ import * as prettier from 'prettier/standalone';
|
|
|
8
8
|
import { appendAsConstTransformer } from './append-as-const.mjs';
|
|
9
9
|
import { transformSourceCode } from './transform-source-code.mjs';
|
|
10
10
|
|
|
11
|
+
const formatter = (code: string): Promise<string> =>
|
|
12
|
+
prettier.format(code, {
|
|
13
|
+
parser: 'typescript',
|
|
14
|
+
plugins: [prettierPluginTypeScript, prettierPluginEstree],
|
|
15
|
+
});
|
|
16
|
+
|
|
11
17
|
const testFn = async ({
|
|
12
18
|
source,
|
|
13
19
|
expected,
|
|
@@ -38,12 +44,6 @@ const testFn = async ({
|
|
|
38
44
|
expect(transformed).toBe(expectedFormatted);
|
|
39
45
|
};
|
|
40
46
|
|
|
41
|
-
const formatter = (code: string): Promise<string> =>
|
|
42
|
-
prettier.format(code, {
|
|
43
|
-
parser: 'typescript',
|
|
44
|
-
plugins: [prettierPluginTypeScript, prettierPluginEstree],
|
|
45
|
-
});
|
|
46
|
-
|
|
47
47
|
describe(appendAsConstTransformer, () => {
|
|
48
48
|
describe('Primitive types (should not add as const)', () => {
|
|
49
49
|
test.each([
|
|
@@ -794,6 +794,39 @@ describe(appendAsConstTransformer, () => {
|
|
|
794
794
|
const m = h([1], [2] as const);
|
|
795
795
|
`,
|
|
796
796
|
},
|
|
797
|
+
{
|
|
798
|
+
name: 'a declared this parameter should not shift arguments onto the parameter to their left',
|
|
799
|
+
source: dedent`
|
|
800
|
+
declare function f<const T, U>(this: void, a: T, b: U): U;
|
|
801
|
+
const r = f(1, [1, 2] as const);
|
|
802
|
+
`,
|
|
803
|
+
expected: dedent`
|
|
804
|
+
declare function f<const T, U>(this: void, a: T, b: U): U;
|
|
805
|
+
const r = f(1, [1, 2] as const);
|
|
806
|
+
`,
|
|
807
|
+
},
|
|
808
|
+
{
|
|
809
|
+
name: 'a declared this parameter should still let the matching argument lose as const',
|
|
810
|
+
source: dedent`
|
|
811
|
+
declare function f<const T, U>(this: void, a: T, b: U): T;
|
|
812
|
+
const r = f([1, 2] as const, [3] as const);
|
|
813
|
+
`,
|
|
814
|
+
expected: dedent`
|
|
815
|
+
declare function f<const T, U>(this: void, a: T, b: U): T;
|
|
816
|
+
const r = f([1, 2], [3] as const);
|
|
817
|
+
`,
|
|
818
|
+
},
|
|
819
|
+
{
|
|
820
|
+
name: 'a this parameter in a function type should be skipped too',
|
|
821
|
+
source: dedent`
|
|
822
|
+
declare const g: <const T>(this: void, x: T) => T;
|
|
823
|
+
const r = g([1] as const);
|
|
824
|
+
`,
|
|
825
|
+
expected: dedent`
|
|
826
|
+
declare const g: <const T>(this: void, x: T) => T;
|
|
827
|
+
const r = g([1]);
|
|
828
|
+
`,
|
|
829
|
+
},
|
|
797
830
|
{
|
|
798
831
|
name: 'non-const type parameter should keep as const',
|
|
799
832
|
source: dedent`
|