diff --git a/packages/babel-helper-module-transforms/src/rewrite-live-references.js b/packages/babel-helper-module-transforms/src/rewrite-live-references.js index 4f31fd926c..a5de3a2492 100644 --- a/packages/babel-helper-module-transforms/src/rewrite-live-references.js +++ b/packages/babel-helper-module-transforms/src/rewrite-live-references.js @@ -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. diff --git a/packages/babel-plugin-transform-typescript/src/index.js b/packages/babel-plugin-transform-typescript/src/index.js index 89b24c8104..b302ea5aa7 100644 --- a/packages/babel-plugin-transform-typescript/src/index.js +++ b/packages/babel-plugin-transform-typescript/src/index.js @@ -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) { diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/regression/11061/input.mjs b/packages/babel-plugin-transform-typescript/test/fixtures/regression/11061/input.mjs new file mode 100644 index 0000000000..58ac1d3d91 --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/regression/11061/input.mjs @@ -0,0 +1,8 @@ +import { messaging } from 'firebase-admin' + +export class Something { + constructor( + public messaging: messaging.Messaging + ) { + } +} diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/regression/11061/options.json b/packages/babel-plugin-transform-typescript/test/fixtures/regression/11061/options.json new file mode 100644 index 0000000000..b93bd8c8fd --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/regression/11061/options.json @@ -0,0 +1,3 @@ +{ + "plugins":["transform-typescript", "transform-classes", "transform-modules-commonjs"] +} diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/regression/11061/output.js b/packages/babel-plugin-transform-typescript/test/fixtures/regression/11061/output.js new file mode 100644 index 0000000000..7582ed08e3 --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/regression/11061/output.js @@ -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;