Closed kasbah closed 6 years ago
Currently transformers work only with js files in commonjs style. But soon I'll implement supporting ts files Second problem that you give a wrapper function, but transformers must be without this one
export default function(/*opts?: Opts*/)
Work transformer version
//transform.js
'use strict';
var ts = require('typescript');
function visitor(ctx, sf, opts) {
var visitor = function(node) {
if (ts.isCallExpression(node) && ts.getTextOfNodeFromSourceText(sf.text, node.expression)) {
var target = node.arguments[0];
if (ts.isPropertyAccessExpression(target)) {
return ts.createBinary(
target.expression, // the left hand operand is the object
ts.SyntaxKind.AmpersandAmpersandToken, // the && operator
target
);
}
}
return ts.visitEachChild(node, visitor, ctx);
};
return visitor;
}
module.exports = function(ctx) {
return function(sf) {
return ts.visitNode(sf, visitor(ctx, sf, {}));
};
};
Thanks for your help. I copied your transform.js and changed tsconfig.json to:
{
"compilerOptions": {
"customTransformers": {
"before": [
"./transform.js"
]
}
}
}
But the ttsc
transformation is still as above. In fact, I noticed even if I change ./transform.js
to a non-existent file it runs the same.
I've publish new version(1.0.5) that can works with transformers written in ts Also I've attach an example project Read readme.md
Nice, I tried the example and it does work for me when I run ttsc
on its own. However, if I run ttsc test.ts
it doesn't work as expected (seems to be like running tsc
-- the transform is not applied).
(Also, I noticed you committed an out of date example/test.js
)
When you run tsc test.ts
tsc
doesn't use your tsconfig.json
Ah, thanks. That's kind of confusing behaviour but I haven't used tsc
very much. It might make sense for ttsc file.ts
to still use the transform section of the config because right now it's just like calling tsc file.ts
?
Yeah, you right, maybe in the next version I'll add this feature
Thanks again for this project and your help. I feel like with the addition of an example this is resolved.
I took this simple example from this blog post but I couldn't get it to run:
tsconfig.json
I ran:
Result:
Expected: