Skip to content

Commit

Permalink
Adjust TSParameterProperty handling to work with transform-parameters (
Browse files Browse the repository at this point in the history
  • Loading branch information
existentialism committed Sep 14, 2018
1 parent 6059637 commit 402bd1c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/babel-plugin-transform-typescript/src/index.js
Expand Up @@ -151,10 +151,6 @@ export default declare((api, { jsxPragma = "React" }) => {
// Rest handled by Function visitor
},

TSParameterProperty(path) {
path.replaceWith(path.node.parameter);
},

ClassProperty(path) {
const { node } = path;

Expand Down Expand Up @@ -208,6 +204,13 @@ export default declare((api, { jsxPragma = "React" }) => {
if (p0 && t.isIdentifier(p0) && p0.name === "this") {
node.params.shift();
}

// We replace `TSParameterProperty` here so that transforms that
// rely on a `Function` visitor to deal with arguments, like
// `transform-parameters`, work properly.
node.params = node.params.map(p => {
return p.type === "TSParameterProperty" ? p.parameter : p;
});
},

TSModuleDeclaration(path) {
Expand Down
@@ -0,0 +1,3 @@
export default class Example {
constructor(public arg1 = null) { }
}
@@ -0,0 +1,3 @@
{
"plugins": ["transform-typescript", "transform-parameters"]
}
@@ -0,0 +1,7 @@
export default class Example {
constructor() {
let arg1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
this.arg1 = arg1;
}

}

0 comments on commit 402bd1c

Please sign in to comment.