Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

# Ignore TypeScript-emitted files
*.js
*.js.map
*.swp
!.*rc.js
*.d.ts
dist/
# Except...
!/types/**/*.d.ts
46 changes: 35 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,38 @@
"url": "git://github.com/coderaiser/recast.git"
},
"license": "MIT",
"main": "main.js",
"main": "./dist/src/main.js",
"types": "main.d.ts",
"scripts": {
"mocha": "test/run.sh",
"debug": "test/run.sh --inspect-brk",
"test": "npm run lint && npm run build && npm run mocha",
"build": "npm run clean && tsc",
"test": "jest",
"watch": "jest --watch",
"snapupdate": "jest --updateSnapshot",
"build": "npm run clean && npm run compile",
"lint": "eslint --ext .ts .",
"format": "prettier --write '{lib,test}/**.ts' '*rc.js'",
"clean": "ts-emit-clean",
"prepack": "npm run build",
"postpack": "npm run clean"
"clean": "rimraf ./dist",
"compile": "tsc -p .",
"prepack": "npm run build"
},
"jest": {
"testEnvironment": "node",
"roots": [
"./test"
],
"testMatch": [
"**/test/**/*\\.[jt]s?(x)",
"**/run\\.[jt]s"
],
"transform": {
"^.+\\.ts$": "ts-jest"
},
"testPathIgnorePatterns": ["<rootDir>/test/data/"],
"moduleFileExtensions": [
"ts",
"js",
"json",
"node"
]
},
"lint-staged": {
"*.ts": [
Expand All @@ -53,18 +73,22 @@
"@babel/preset-env": "7.11.5",
"@types/esprima": "4.0.2",
"@types/glob": "7.1.3",
"@types/mocha": "8.0.3",
"@types/jest": "^27.4.1",
"@types/node": "^16.0.0",
"@typescript-eslint/parser": "^5.8.0",
"eslint": "^8.5.0",
"esprima-fb": "15001.1001.0-dev-harmony-fb",
"expect": "^27.5.1",
"jest": "^27.5.1",
"jest-mock": "^27.5.1",
"flow-parser": "^0.159.0",
"glob": "^7.1.7",
"lint-staged": "^10.2.6",
"mocha": "^9.0.2",
"prettier": "^2.0.5",
"rimraf": "^3.0.2",
"reify": "0.20.12",
"ts-emit-clean": "1.0.0",
"ts-jest": "^27.1.4",
"ts-node": "^10.7.0",
"typescript": "^4.3.5"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion test/lines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ describe("lines", function () {

fs.readFile(__filename, "utf-8", function (err, source) {
assert.equal(err, null);
assert.strictEqual(fromString(source).guessTabWidth(), 4);
assert.strictEqual(fromString(source).guessTabWidth(), 2);

fs.readFile(
path.join(__dirname, "..", "package.json"),
Expand Down
60 changes: 32 additions & 28 deletions test/perf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,35 @@ import path from "path";
import fs from "fs";
import * as recast from "../main";

const source = fs.readFileSync(
path.join(__dirname, "data", "backbone.js"),
"utf8",
);

const start = +new Date();
const ast = recast.parse(source);
const types = Object.create(null);

const parseTime = +new Date() - start;
console.log("parse", parseTime, "ms");

recast.visit(ast, {
visitNode: function (path) {
types[path.value.type] = true;
this.traverse(path);
},
});

const visitTime = +new Date() - start - parseTime;
console.log("visit", visitTime, "ms");

recast.prettyPrint(ast).code;

const printTime = +new Date() - start - visitTime - parseTime;
console.log("print", printTime, "ms");

console.log("total", +new Date() - start, "ms");
describe('performance metrics', () => {
it('should print out', () => {
const source = fs.readFileSync(
path.join(__dirname, "data", "backbone.js"),
"utf8",
);

const start = +new Date();
const ast = recast.parse(source);
const types = Object.create(null);

const parseTime = +new Date() - start;
console.log("parse", parseTime, "ms");

recast.visit(ast, {
visitNode: function (path) {
types[path.value.type] = true;
this.traverse(path);
},
});

const visitTime = +new Date() - start - parseTime;
console.log("visit", visitTime, "ms");

recast.prettyPrint(ast).code;

const printTime = +new Date() - start - visitTime - parseTime;
console.log("print", printTime, "ms");

console.log("total", +new Date() - start, "ms");
});
})
2 changes: 1 addition & 1 deletion test/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ function testReprinting(pattern: any, description: any) {
return;
}

this.timeout(20000);
jest.setTimeout(20000);

assert.strictEqual(recast.print(ast).code, source);
const reprintedCode = recast.prettyPrint(ast).code;
Expand Down
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
"lib": ["es2015"],
"module": "commonjs",
"declaration": true,
"declarationMap": true,
"rootDir": ".",
"outDir": "dist",
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"moduleResolution": "node",
"esModuleInterop": true,
"importHelpers": true,
"sourceMap": true,
"stripInternal": true
},
"exclude": [
Expand Down