Skip to content

Commit

Permalink
Merge pull request #3 from slune-org/update
Browse files Browse the repository at this point in the history
Update dependencies
  • Loading branch information
sveyret authored Sep 10, 2022
2 parents 5ca8c25 + 4de7c4c commit 22cb8b4
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 43 deletions.
6 changes: 2 additions & 4 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
env:
shared-node-browser: true
es6: true
es2017: true
node: true
es2021: true
parser: '@typescript-eslint/parser'
parserOptions:
project:
Expand All @@ -20,7 +19,6 @@ extends:
- plugin:import/typescript
- plugin:jsdoc/recommended
- prettier
- prettier/@typescript-eslint
rules:
curly: error
dot-notation: error
Expand Down
46 changes: 23 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
}
}
15 changes: 7 additions & 8 deletions src/transform/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ type TransformerMetaFactory = (program: Program, configuration: unknown) => Tran

export default function <C extends NodeVisitorContext>(
Context: NodeVisitorContextType<C>,
NodeVisitors: NodeVisitorType<C>[]
NodeVisitors: Array<NodeVisitorType<C>>
): TransformerMetaFactory {
return (program: Program, configuration: unknown): TransformerFactory<SourceFile> => {
const context: C = new Context(program, configuration)
return (transContext: TransformationContext): Transformer<SourceFile> => (
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): SourceFile => {
context.initNewFile(transContext, sourceFile)
const nodeVisitors = NodeVisitors.map(NodeVisitor => new NodeVisitor(context))
return visitNode(sourceFile, buildVisitor(transContext, nodeVisitors))
}
}
}
16 changes: 10 additions & 6 deletions src/transform/visit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,23 @@ function visit<N extends Node>(nodeVisitor: NodeVisitor<N>, nodes: Node[]): Node
return nextNodes
}

export default function (context: TransformationContext, nodeVisitors: NodeVisitor<any>[]): Visitor {
export default function (context: TransformationContext, nodeVisitors: Array<NodeVisitor<any>>): Visitor {
const visitor: Visitor = node => {
const newNodes = nodeVisitors.reduce(
(nodes, nodeVisitor) => {
return visit(nodeVisitor, nodes)
},
[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
}
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"compilerOptions": {
"target": "ES2018",
"target": "ES2021",
"moduleResolution": "node",
"esModuleInterop": false,
"esModuleInterop": true,
"module": "CommonJS",
"baseUrl": ".",
"rootDir": "src",
Expand Down

0 comments on commit 22cb8b4

Please sign in to comment.