Register binding when transforming TSParameterProperty (#12796)
This commit is contained in:
parent
0bb57005c6
commit
99130bcfdd
@ -177,14 +177,14 @@ const rewriteReferencesVisitor = {
|
||||
|
||||
const localName = path.node.name;
|
||||
|
||||
const localBinding = path.scope.getBinding(localName);
|
||||
const rootBinding = scope.getBinding(localName);
|
||||
|
||||
// redeclared in this scope
|
||||
if (rootBinding !== localBinding) return;
|
||||
|
||||
const importData = imported.get(localName);
|
||||
if (importData) {
|
||||
const localBinding = path.scope.getBinding(localName);
|
||||
const rootBinding = scope.getBinding(localName);
|
||||
|
||||
// redeclared in this scope
|
||||
if (rootBinding !== localBinding) return;
|
||||
|
||||
const ref = buildImportReference(importData, path.node);
|
||||
|
||||
// Preserve the binding location so that sourcemaps are nicer.
|
||||
|
||||
@ -384,21 +384,26 @@ export default declare((api, opts) => {
|
||||
});
|
||||
},
|
||||
|
||||
Function({ node }) {
|
||||
Function(path) {
|
||||
const { node, scope } = path;
|
||||
if (node.typeParameters) node.typeParameters = null;
|
||||
if (node.returnType) node.returnType = null;
|
||||
|
||||
const p0 = node.params[0];
|
||||
if (p0 && t.isIdentifier(p0) && p0.name === "this") {
|
||||
node.params.shift();
|
||||
const params = node.params;
|
||||
if (params.length > 0 && t.isIdentifier(params[0], { name: "this" })) {
|
||||
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;
|
||||
});
|
||||
const paramsPath = path.get("params");
|
||||
for (const p of paramsPath) {
|
||||
if (p.type === "TSParameterProperty") {
|
||||
p.replaceWith(p.get("parameter"));
|
||||
scope.registerBinding("param", p);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
TSModuleDeclaration(path) {
|
||||
|
||||
8
packages/babel-plugin-transform-typescript/test/fixtures/regression/11061/input.mjs
vendored
Normal file
8
packages/babel-plugin-transform-typescript/test/fixtures/regression/11061/input.mjs
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
import { messaging } from 'firebase-admin'
|
||||
|
||||
export class Something {
|
||||
constructor(
|
||||
public messaging: messaging.Messaging
|
||||
) {
|
||||
}
|
||||
}
|
||||
3
packages/babel-plugin-transform-typescript/test/fixtures/regression/11061/options.json
vendored
Normal file
3
packages/babel-plugin-transform-typescript/test/fixtures/regression/11061/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins":["transform-typescript", "transform-classes", "transform-modules-commonjs"]
|
||||
}
|
||||
18
packages/babel-plugin-transform-typescript/test/fixtures/regression/11061/output.js
vendored
Normal file
18
packages/babel-plugin-transform-typescript/test/fixtures/regression/11061/output.js
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.Something = void 0;
|
||||
|
||||
var _firebaseAdmin = require("firebase-admin");
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
let Something = function Something(messaging) {
|
||||
_classCallCheck(this, Something);
|
||||
|
||||
this.messaging = messaging;
|
||||
};
|
||||
|
||||
exports.Something = Something;
|
||||
Loading…
x
Reference in New Issue
Block a user