Skip to content
This repository has been archived by the owner on Sep 9, 2019. It is now read-only.

Commit

Permalink
fix: update node types
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Aug 24, 2019
1 parent fc0fc5c commit 36ffc9f
Show file tree
Hide file tree
Showing 3 changed files with 1,302 additions and 509 deletions.
46 changes: 25 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,46 @@
"scripts": {
"build": "cross-env NODE_ENV=production tsc -p .",
"example": "npm i && npm run build && cd example && npm test",
"postcommit": "git reset",
"precommit": "lint-staged",
"prepublish": "npm run --if-present build",
"test": "mocha \"test/**/*.ts\"",
"updateSnapshot": "UPDATE_SNAPSHOT=1 npm test",
"watch": "tsc -p . --watch"
},
"dependencies": {
"@babel/core": "^7.2.2",
"@babel/parser": "^7.2.3",
"@babel/template": "^7.2.2",
"@babel/traverse": "^7.2.3",
"@babel/types": "^7.2.2",
"concat-stream": "^1.5.0"
"@babel/core": "^7.5.5",
"@babel/parser": "^7.5.5",
"@babel/template": "^7.4.4",
"@babel/traverse": "^7.5.5",
"@babel/types": "^7.5.5",
"concat-stream": "^2.0.0"
},
"devDependencies": {
"@types/babel__core": "^7.0.4",
"@types/babel__generator": "^7.0.1",
"@types/babel__template": "^7.0.1",
"@types/babel__traverse": "^7.0.4",
"@types/mocha": "^5.2.5",
"@types/node": "^10.12.18",
"@types/babel__core": "^7.1.2",
"@types/babel__generator": "^7.0.2",
"@types/babel__template": "^7.0.2",
"@types/babel__traverse": "^7.0.7",
"@types/mocha": "^5.2.7",
"@types/node": "^12.7.2",
"cross-env": "^5.2.0",
"husky": "^0.14.3",
"lint-staged": "^4.1.3",
"mocha": "^5.2.0",
"prettier": "^1.6.1",
"ts-node": "^7.0.1",
"ts-node-test-register": "^4.0.0",
"typescript": "^3.2.4"
"husky": "^3.0.4",
"lint-staged": "^9.2.3",
"mocha": "^6.2.0",
"prettier": "^1.18.2",
"ts-node": "^8.3.0",
"ts-node-test-register": "^8.0.1",
"typescript": "^3.5.3"
},
"email": "azuciao@gmail.com",
"lint-staged": {
"*.{ts,tsx,css}": [
"prettier --write",
"git add"
]
},
"husky": {
"hooks": {
"post-commit": "git reset",
"pre-commit": "lint-staged"
}
}
}
8 changes: 4 additions & 4 deletions src/comment-to-assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
wrapAssert,
wrapAssertOptions
} from "./ast-utils";
import { transformFromAstSync } from "@babel/core";
import { transformFromAstSync, Node } from "@babel/core";
import { identifier, isExpressionStatement, File } from "@babel/types";
import { parse, parseExpression, ParserOptions } from "@babel/parser";
import traverse from "@babel/traverse";
Expand Down Expand Up @@ -61,13 +61,13 @@ export function toAssertFromSource(code: string, options?: toAssertFromSourceOpt
const ast = parse(code, {
// parse in strict mode and allow module declarations
sourceType: "module",
...options && options.babel ? options.babel : {}
...(options && options.babel ? options.babel : {})
});
if (!ast) {
throw new Error("Can not parse the code");
}
const output = toAssertFromAST(ast, options);
const babelFileResult = transformFromAstSync(output, code, { comments: true });
const babelFileResult = transformFromAstSync(output as Node, code, { comments: true });
if (!babelFileResult) {
throw new Error("can not generate from ast: " + JSON.stringify(output));
}
Expand All @@ -77,7 +77,7 @@ export function toAssertFromSource(code: string, options?: toAssertFromSourceOpt
/**
* transform AST to asserted AST.
*/
export function toAssertFromAST(ast: File, options: wrapAssertOptions = {}) {
export function toAssertFromAST(ast: File, options: wrapAssertOptions = {}): File {
const replaceSet = new Set();
let id = 0;
traverse(ast, {
Expand Down
Loading

0 comments on commit 36ffc9f

Please sign in to comment.