diff --git a/.eslintrc.yaml b/.eslintrc.yaml index c0b8f15..dc29121 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -1,7 +1,6 @@ env: - shared-node-browser: true - es6: true - es2017: true + node: true + es2021: true parser: '@typescript-eslint/parser' parserOptions: project: @@ -20,7 +19,6 @@ extends: - plugin:import/typescript - plugin:jsdoc/recommended - prettier - - prettier/@typescript-eslint rules: curly: error dot-notation: error diff --git a/package.json b/package.json index 0f0657a..c8a98ab 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "simple-ts-transform", - "version": "1.1.0", + "version": "1.2.0", "description": "Library to help create simple typescript transformers", "keywords": [ "typescript", @@ -40,36 +40,36 @@ "debug:watch": "onchange 'src/**' -- pm-exec run test:unit", "clean": "rimraf dist" }, - "dependencies": {}, "devDependencies": { - "@istanbuljs/nyc-config-typescript": "1.0.1", - "@types/chai": "4.2.12", - "@types/mocha": "8.0.3", - "@typescript-eslint/eslint-plugin": "4.0.1", - "@typescript-eslint/parser": "4.0.1", - "chai": "4.2.0", - "depcheck": "1.2.0", - "eslint": "7.7.0", - "eslint-config-prettier": "6.11.0", - "eslint-plugin-import": "2.22.0", - "eslint-plugin-jsdoc": "30.3.0", + "@istanbuljs/nyc-config-typescript": "1.0.2", + "@types/chai": "4.3.3", + "@types/mocha": "9.1.1", + "@types/node": "18.7.16", + "@typescript-eslint/eslint-plugin": "5.36.2", + "@typescript-eslint/parser": "5.36.2", + "chai": "4.3.6", + "depcheck": "1.4.3", + "eslint": "8.23.0", + "eslint-config-prettier": "8.5.0", + "eslint-plugin-import": "2.26.0", + "eslint-plugin-jsdoc": "39.3.6", "eslint-plugin-node": "11.1.0", - "eslint-plugin-prettier": "3.1.4", - "mocha": "8.1.3", + "eslint-plugin-prettier": "4.2.1", + "mocha": "10.0.0", "nyc": "15.1.0", - "onchange": "7.0.2", + "onchange": "7.1.0", "pm-exec": "1.0.0", - "prettier": "2.1.1", + "prettier": "2.7.1", "rimraf": "3.0.2", - "source-map-support": "0.5.19", - "ts-node": "9.0.0", - "ts-transform-test-compiler": "1.1.0", - "typescript": "4.0.2" + "source-map-support": "0.5.21", + "ts-node": "10.9.1", + "ts-transform-test-compiler": "1.2.0", + "typescript": "4.8.3" }, "peerDependencies": { - "typescript": "^4.0.2" + "typescript": "^4.8.3" }, "engines": { - "node": ">=10.0.0" + "node": ">=16.10.0" } } diff --git a/src/transform/transform.ts b/src/transform/transform.ts index d6d2ac8..ad93114 100644 --- a/src/transform/transform.ts +++ b/src/transform/transform.ts @@ -14,16 +14,15 @@ type TransformerMetaFactory = (program: Program, configuration: unknown) => Tran export default function ( Context: NodeVisitorContextType, - NodeVisitors: NodeVisitorType[] + NodeVisitors: Array> ): TransformerMetaFactory { return (program: Program, configuration: unknown): TransformerFactory => { const context: C = new Context(program, configuration) - return (transContext: TransformationContext): Transformer => ( - sourceFile: SourceFile - ): SourceFile => { - context.initNewFile(transContext, sourceFile) - const nodeVisitors = NodeVisitors.map(NodeVisitor => new NodeVisitor(context)) - return visitNode(sourceFile, buildVisitor(transContext, nodeVisitors)) - } + return (transContext: TransformationContext): Transformer => + (sourceFile: SourceFile): SourceFile => { + context.initNewFile(transContext, sourceFile) + const nodeVisitors = NodeVisitors.map(NodeVisitor => new NodeVisitor(context)) + return visitNode(sourceFile, buildVisitor(transContext, nodeVisitors)) + } } } diff --git a/src/transform/visit.ts b/src/transform/visit.ts index ea9a41f..ce771e1 100644 --- a/src/transform/visit.ts +++ b/src/transform/visit.ts @@ -15,7 +15,7 @@ function visit(nodeVisitor: NodeVisitor, nodes: Node[]): Node return nextNodes } -export default function (context: TransformationContext, nodeVisitors: NodeVisitor[]): Visitor { +export default function (context: TransformationContext, nodeVisitors: Array>): Visitor { const visitor: Visitor = node => { const newNodes = nodeVisitors.reduce( (nodes, nodeVisitor) => { @@ -23,11 +23,15 @@ export default function (context: TransformationContext, nodeVisitors: NodeVisit }, [node] ) - return newNodes.length === 0 - ? undefined - : newNodes.length === 1 - ? visitEachChild(newNodes[0], visitor, context) - : newNodes.map(newNode => visitEachChild(newNode, visitor, context)) + if (newNodes.length === 0) { + return undefined + } else if (newNodes.length === 1) { + return visitEachChild(newNodes[0], visitor, context, undefined, visitor) + } else { + return newNodes + .map(newNode => visitEachChild(newNode, visitor, context, undefined, visitor)) + .filter((newNode): newNode is Node => !!newNode) + } } return visitor } diff --git a/tsconfig.json b/tsconfig.json index 9718833..0a674b6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,8 +1,8 @@ { "compilerOptions": { - "target": "ES2018", + "target": "ES2021", "moduleResolution": "node", - "esModuleInterop": false, + "esModuleInterop": true, "module": "CommonJS", "baseUrl": ".", "rootDir": "src",