Skip to content

Commit e7afd37

Browse files
committed
fix: Removed debug code
1 parent bc09372 commit e7afd37

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22
"name": "typescript-transform-unspec",
33
"version": "0.0.0-dev",
44
"license": "MIT",
5-
"description": "Typescript transform plugin",
5+
"description": "Typescript transform plugin removes spec definition from source file",
66
"main": "index.js",
77
"typings": "index.d.ts",
88
"author": "2019",
9-
"keywords": [],
9+
"keywords": [
10+
"typescript-transformer",
11+
"typescript-plugin",
12+
"typescript-transform-plugin",
13+
"typescript-compiler"
14+
],
1015
"engines": {
1116
"node": ">=8"
1217
},

src/example.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ it('hello world test', () => {
66
expect(hello()).toBe('hello world');
77
});
88

9-
jest.mock('foo');
10-
119
describe('hello world test', () => {
1210
beforeAll(() => {
13-
jest.mock('foo');
11+
jest.mock('inspector');
1412
});
1513
});

src/index.spec.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
/* eslint-disable @typescript-eslint/tslint/config */
2-
import * as lib from './index';
2+
import transformPlugin from './index';
33
import * as ts from 'typescript';
44

5-
let transformPlugin: typeof lib.typescriptTransformUnspec = lib as any;
6-
75
function transform(sourceText: string) {
86
const program = ts.createProgram({
97
rootNames: [],
108
options: {},
119
});
12-
const transformer = transformPlugin(program, {});
10+
const transformer = transformPlugin(program);
1311
const sourceFile = ts.createSourceFile('filename.tsx', sourceText, ts.ScriptTarget.ES5, true, ts.ScriptKind.TSX);
1412
let result: string | undefined;
1513
const writeCallback = (fileName: string, data: string) => {
@@ -20,7 +18,7 @@ function transform(sourceText: string) {
2018
}
2119

2220
it('smoke test', () => {
23-
expect(lib).toBeTruthy();
21+
expect(transformPlugin).toBeTruthy();
2422
expect(transform(';')).toBe(';');
2523
});
2624

src/index.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import * as ts from 'typescript';
22

3-
export function typescriptTransformUnspec(program: ts.Program, options?): ts.TransformerFactory<ts.SourceFile> {
3+
export default function typescriptTransformUnspec(program: ts.Program): ts.TransformerFactory<ts.SourceFile> { // tslint:disable-line:no-default-export
44
return (context) => (file) => visitNodeAndChildren(file, program, context);
55
}
66

77
function visitNodeAndChildren(node: ts.Node, program: ts.Program, context: ts.TransformationContext): ts.SourceFile {
8-
return ts.visitEachChild(visitor(node), (childNode) => visitNodeAndChildren(childNode, program, context), context) as ts.SourceFile;
8+
const visitor = (childNode) => visitNodeAndChildren(childNode, program, context);
9+
return ts.visitEachChild<ts.SourceFile>(<ts.SourceFile>filterNode(node), visitor, context);
910
}
1011

11-
function visitor(node: ts.Node): ts.Node | undefined {
12+
function filterNode<T extends ts.Node>(node: T): T | undefined {
1213
if (isSpecExpressionStatement(node)) {
1314
return undefined;
1415
}
@@ -44,18 +45,16 @@ function isSpecExpressionStatement(node: ts.Node) {
4445
if (ts.isExpressionStatement(node) && ts.isCallExpression(node.expression)) {
4546
const callExpr = node.expression.expression;
4647
if (ts.isIdentifier(callExpr) && isTestExpressionText(callExpr.escapedText)) {
47-
console.log("callExpr", callExpr.flags);
4848
return true;
4949
}
5050
if (ts.isPropertyAccessExpression(callExpr)) {
5151
const propertyAccessExpr = callExpr.expression;
5252
if (ts.isIdentifier(propertyAccessExpr) && isTestExpressionText(propertyAccessExpr.escapedText)) {
53-
console.log("propertyAccessExpr", propertyAccessExpr.flags);
5453
return true;
5554
}
5655
}
57-
return false;
5856
}
57+
return false;
5958
}
6059

6160
module.exports = typescriptTransformUnspec;

0 commit comments

Comments
 (0)