Skip to content

Commit ba7337f

Browse files
committed
First implementation
1 parent f061031 commit ba7337f

File tree

5 files changed

+83
-49
lines changed

5 files changed

+83
-49
lines changed

package.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,18 @@
3939
"setupwebpack": "npm i -D webpack webpack-cli webpack-dev-server html-webpack-plugin source-map-loader ts-loader html-loader swc-loader @swc/core",
4040
"commit": "git-cz"
4141
},
42+
"peerDependencies": {
43+
"typescript": ">=3.2"
44+
},
4245
"devDependencies": {
4346
"@semantic-release/changelog": "^3.0.2",
4447
"@semantic-release/commit-analyzer": "^7.0.0-beta.2",
4548
"@semantic-release/git": "^7.1.0-beta.3",
4649
"@semantic-release/github": "^5.4.0-beta.1",
4750
"@semantic-release/npm": "^5.2.0-beta.6",
4851
"@semantic-release/release-notes-generator": "^7.1.7",
49-
"@types/node": "^12.0.2",
5052
"@types/jest": "^24.0.13",
53+
"@types/node": "^12.0.2",
5154
"@typescript-eslint/eslint-plugin-tslint": "^1.9.0",
5255
"@typescript-eslint/parser": "^1.9.0",
5356
"eslint": "^5.16.0",
@@ -65,14 +68,19 @@
6568
"remark-toc": "^5.1.1",
6669
"semantic-release": "^16.0.0-beta.19",
6770
"simplytyped": "^3.1.0",
71+
"source-map-loader": "^0.2.4",
6872
"ts-jest": "^24.0.2",
73+
"ts-loader": "^6.0.2",
74+
"ts-node": "^8.2.0",
6975
"tslint": "^5.16.0",
7076
"tslint-clean-code": "^0.2.9",
7177
"tslint-microsoft-contrib": "^6.2.0",
7278
"tslint-sonarts": "^1.9.0",
7379
"type-coverage": "^2.0.2",
7480
"typescript": "~3.4.5",
75-
"watchexec-bin": "^1.0.0"
81+
"watchexec-bin": "^1.0.0",
82+
"webpack": "^4.33.0",
83+
"webpack-cli": "^3.3.4"
7684
},
7785
"config": {
7886
"commitizen": {

src/index.ts

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
1-
import { PlainObject } from 'simplytyped';
1+
import * as ts from 'typescript';
22

3-
const dict: PlainObject = {};
4-
5-
/**
6-
* Hello function whithout parameter
7-
* @returns result string
8-
*/
9-
export function hello(): string;
10-
11-
/**
12-
* This is hello function
13-
* @returns result string
14-
*/
15-
export function hello(greet?: string) {
16-
return `${greet} world`;
3+
function typescriptTransformUnspec<T extends ts.Node>(program: ts.Program): ts.TransformerFactory<T> {
4+
return (context: ts.TransformationContext) => {
5+
const visit: ts.Visitor = (node) => {
6+
if (isSpecExpressionStatement(node)) {
7+
return undefined;
8+
}
9+
return ts.visitEachChild(node, (child) => visit(child), context);
10+
};
11+
return (node) => ts.visitNode(node, visit);
12+
};
1713
}
1814

19-
export class X {
15+
function isSpecExpressionStatement(node: ts.Node) {
16+
return (ts.isExpressionStatement(node) && ts.isCallExpression(node.expression)
17+
&& ts.isIdentifier(node.expression.expression)
18+
&& node.expression.expression.escapedText === 'it');
19+
}
2020

21-
constructor(
22-
private readonly o: PlainObject,
23-
) { }
21+
if (typeof it !== 'function') {
22+
// @ts-ignore
23+
var it: any = () => { };
2424
}
25+
it('smoke', () => {
26+
expect(typescriptTransformUnspec).toBeTruthy();
27+
});
28+
29+
module.exports = typescriptTransformUnspec;
30+
module.exports.default = typescriptTransformUnspec;

src/transformers/transformer.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.
File renamed without changes.

webpack.config.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const unspecTransformer = require('./src/index');
2+
3+
module.exports = async (options) => ({
4+
externals: {
5+
typescript: 'typescript',
6+
},
7+
entry: {
8+
lib: `${__dirname}/src/index.ts`,
9+
},
10+
output: {
11+
path: `${__dirname}/dist`,
12+
filename: '[name].js',
13+
},
14+
mode: 'development',
15+
devtool: 'source-map',
16+
module: {
17+
rules: [
18+
{
19+
test: /\.js$/,
20+
enforce: 'pre',
21+
use: 'source-map-loader',
22+
},
23+
{
24+
test: /\.tsx?$/,
25+
exclude: /node_modules/,
26+
use: {
27+
loader: 'ts-loader',
28+
options: {
29+
transpileOnly: true,
30+
getCustomTransformers: program => ({
31+
before: [
32+
unspecTransformer(program),
33+
]
34+
}),
35+
},
36+
}
37+
},
38+
]
39+
},
40+
resolve: {
41+
extensions: ['.js', '.ts', '.tsx'],
42+
},
43+
devServer: {
44+
contentBase: `${__dirname}/dist`,
45+
},
46+
plugins: [
47+
]
48+
});

0 commit comments

Comments
 (0)