Adjust TSParameterProperty handling to work with transform-parameters (#8695)

This commit is contained in:
Brian Ng 2018-09-14 10:20:43 -05:00 committed by GitHub
parent 6059637f09
commit 402bd1cc42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 4 deletions

View File

@ -151,10 +151,6 @@ export default declare((api, { jsxPragma = "React" }) => {
// Rest handled by Function visitor // Rest handled by Function visitor
}, },
TSParameterProperty(path) {
path.replaceWith(path.node.parameter);
},
ClassProperty(path) { ClassProperty(path) {
const { node } = path; const { node } = path;
@ -208,6 +204,13 @@ export default declare((api, { jsxPragma = "React" }) => {
if (p0 && t.isIdentifier(p0) && p0.name === "this") { if (p0 && t.isIdentifier(p0) && p0.name === "this") {
node.params.shift(); 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) { TSModuleDeclaration(path) {

View File

@ -0,0 +1,3 @@
export default class Example {
constructor(public arg1 = null) { }
}

View File

@ -0,0 +1,3 @@
{
"plugins": ["transform-typescript", "transform-parameters"]
}

View File

@ -0,0 +1,7 @@
export default class Example {
constructor() {
let arg1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
this.arg1 = arg1;
}
}