Skip to content

Commit 69b6784

Browse files
committed
feature: @putout/plugin-typescript: migrate to ESM
1 parent 7970b9c commit 69b6784

62 files changed

Lines changed: 252 additions & 320 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
File renamed without changes.
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
'use strict';
2-
3-
const {operator, types} = require('putout');
1+
import {operator, types} from 'putout';
42

53
const {TSAsExpression} = types;
64
const {replaceWith} = operator;
75

8-
module.exports.report = () => '"as" should be used for type assertions';
6+
export const report = () => '"as" should be used for type assertions';
97

10-
module.exports.fix = (path) => {
8+
export const fix = (path) => {
119
const typeName = path.get('typeAnnotation').node;
1210
const expression = path.get('expression').node;
1311

1412
replaceWith(path, TSAsExpression(expression, typeName));
1513
};
1614

17-
module.exports.include = () => [
15+
export const include = () => [
1816
'TSTypeAssertion',
1917
];

packages/plugin-typescript/lib/apply-as-type-assertion/index.spec.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as applyAsTypeAssertions from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const applyAsTypeAssertions = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['typescript/apply-as-type-assertions', applyAsTypeAssertions],
97
],

packages/plugin-typescript/lib/apply-type-guards/index.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
'use strict';
2-
3-
const {
1+
import {
42
types,
53
operator,
64
template,
7-
} = require('putout');
5+
} from 'putout';
86

97
const {replaceWith} = operator;
108
const {identifier} = types;
@@ -13,13 +11,13 @@ const create = template('(__a): __a is __c => typeof __a === "__b"', {
1311
placeholderPattern: /__/,
1412
});
1513

16-
module.exports.report = () => `Use 'type guards'`;
14+
export const report = () => `Use 'type guards'`;
1715

18-
module.exports.match = () => ({
16+
export const match = () => ({
1917
'(__a) => typeof __a === "__b"': (vars, path) => !path.node.returnType,
2018
});
2119

22-
module.exports.replace = () => ({
20+
export const replace = () => ({
2321
'(__a) => typeof __a === "__b"': ({__a, __b}, path) => {
2422
replaceWith(path, create({
2523
__a,

packages/plugin-typescript/lib/apply-type-guards/index.spec.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as applyUtilityTypes from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const applyUtilityTypes = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['apply-guards', applyUtilityTypes],
97
],

packages/plugin-typescript/lib/apply-utility-types/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
'use strict';
1+
export const report = () => 'Apply utility types';
22

3-
module.exports.report = () => 'Apply utility types';
4-
5-
module.exports.replace = () => ({
3+
export const replace = () => ({
64
'type __a = {readonly [__b in keyof __c]: __c[__b];}': 'type __a = Readonly<__c>',
75
'type __a = {[__b in keyof __c]?: __c[__b];}': 'type __a = Partial<__c>',
86
'type __a = {[__b in keyof __c]-?: __c[__b];}': 'type __a = Required<__c>',

packages/plugin-typescript/lib/apply-utility-types/index.spec.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as applyUtilityTypes from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const applyUtilityTypes = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['apply-utility-types', applyUtilityTypes],
97
],
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
'use strict';
1+
export const report = () => `Use 'ESM' instead of 'CommonJS'`;
22

3-
module.exports.report = () => `Use 'ESM' instead of 'CommonJS'`;
4-
5-
module.exports.replace = () => ({
3+
export const replace = () => ({
64
'export = __a': 'export default __a',
75
'import __a = require("__b")': 'import __a from "__b"',
86
});

packages/plugin-typescript/lib/convert-commonjs-to-esm/index.spec.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as plugin from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const plugin = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['convert-commonjs-to-esm', plugin],
97
],

0 commit comments

Comments
 (0)