Register binding when transforming TSParameterProperty (#12796)

This commit is contained in:
Huáng Jùnliàng 2021-02-16 18:42:01 -05:00 committed by GitHub
parent 0bb57005c6
commit 99130bcfdd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 13 deletions

View File

@ -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.

View File

@ -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) {

View File

@ -0,0 +1,8 @@
import { messaging } from 'firebase-admin'
export class Something {
constructor(
public messaging: messaging.Messaging
) {
}
}

View File

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

View 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;