From 0020e163702ce82a7dd8360391ef8fd8b0b43130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Tue, 19 Oct 2021 20:00:51 +0900 Subject: [PATCH] fix(es/minifier): Fix minifier (#2477) swc_ecma_minifier: - `MultiReplacer`: Handle inlining into shorthands. - `ExprReplacer`: Handle inlining into shorthands. --- Cargo.lock | 2 +- ecmascript/minifier/Cargo.toml | 2 +- .../src/compress/optimize/collapse_vars.rs | 27 +- .../minifier/src/compress/optimize/util.rs | 44 ++ ecmascript/minifier/src/compress/util/mod.rs | 8 + .../fixture/issues/firebase/dist/1/input.js | 473 ++++++++++++++++++ .../fixture/issues/firebase/dist/1/output.js | 156 ++++++ .../full/firebase/dist/1/input/index.js | 473 ++++++++++++++++++ .../full/firebase/dist/1/output/index.js | 148 ++++++ 9 files changed, 1305 insertions(+), 28 deletions(-) create mode 100644 ecmascript/minifier/tests/compress/fixture/issues/firebase/dist/1/input.js create mode 100644 ecmascript/minifier/tests/compress/fixture/issues/firebase/dist/1/output.js create mode 100644 tests/vercel/full/firebase/dist/1/input/index.js create mode 100644 tests/vercel/full/firebase/dist/1/output/index.js diff --git a/Cargo.lock b/Cargo.lock index 94eca8e7e348..ab2acd6f1881 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2676,7 +2676,7 @@ dependencies = [ [[package]] name = "swc_ecma_minifier" -version = "0.44.0" +version = "0.44.1" dependencies = [ "ansi_term 0.12.1", "anyhow", diff --git a/ecmascript/minifier/Cargo.toml b/ecmascript/minifier/Cargo.toml index ccbd82cf0d4e..9666857ebf0c 100644 --- a/ecmascript/minifier/Cargo.toml +++ b/ecmascript/minifier/Cargo.toml @@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs", "src/lists/*.json"] license = "Apache-2.0/MIT" name = "swc_ecma_minifier" repository = "https://github.com/swc-project/swc.git" -version = "0.44.0" +version = "0.44.1" [features] debug = ["backtrace"] diff --git a/ecmascript/minifier/src/compress/optimize/collapse_vars.rs b/ecmascript/minifier/src/compress/optimize/collapse_vars.rs index 03cb78ede0dd..e84a556b0cf5 100644 --- a/ecmascript/minifier/src/compress/optimize/collapse_vars.rs +++ b/ecmascript/minifier/src/compress/optimize/collapse_vars.rs @@ -1,9 +1,7 @@ use super::Optimizer; use crate::mode::Mode; -use swc_common::collections::AHashMap; use swc_ecma_ast::*; -use swc_ecma_utils::{ident::IdentLike, Id}; -use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; +use swc_ecma_utils::ident::IdentLike; /// Methods related to the option `collapse_vars`. impl Optimizer<'_, M> @@ -78,26 +76,3 @@ where } } } - -struct Inliner<'a> { - values: &'a mut AHashMap>>, -} - -impl VisitMut for Inliner<'_> { - noop_visit_mut_type!(); - - fn visit_mut_expr(&mut self, e: &mut Expr) { - e.visit_mut_children_with(self); - - match e { - Expr::Ident(i) => { - if let Some(value) = self.values.remove(&i.to_id()) { - tracing::debug!("collapse_vars: Inlining {}{:?}", i.sym, i.span.ctxt); - - *e = *value.expect("should be used only once"); - } - } - _ => {} - } - } -} diff --git a/ecmascript/minifier/src/compress/optimize/util.rs b/ecmascript/minifier/src/compress/optimize/util.rs index f6e8b65b233d..21ebbe6f4ae5 100644 --- a/ecmascript/minifier/src/compress/optimize/util.rs +++ b/ecmascript/minifier/src/compress/optimize/util.rs @@ -219,6 +219,27 @@ impl VisitMut for MultiReplacer { } } } + + fn visit_mut_prop(&mut self, p: &mut Prop) { + p.visit_mut_children_with(self); + + match p { + Prop::Shorthand(i) => { + if let Some(value) = self.vars.remove(&i.to_id()) { + debug!("multi-replacer: Replaced `{}` as shorthand", i); + self.changed = true; + + *p = Prop::KeyValue(KeyValueProp { + key: PropName::Ident(i.clone()), + value, + }); + + return; + } + } + _ => {} + } + } } pub(crate) fn replace_id_with_expr(node: &mut N, from: Id, to: Box) -> Option> @@ -266,4 +287,27 @@ impl VisitMut for ExprReplacer { e.prop.visit_mut_with(self); } } + + fn visit_mut_prop(&mut self, p: &mut Prop) { + p.visit_mut_children_with(self); + + match p { + Prop::Shorthand(i) => { + if self.from.0 == i.sym && self.from.1 == i.span.ctxt { + let value = if let Some(new) = self.to.take() { + new + } else { + unreachable!("`{}` is already taken", i) + }; + *p = Prop::KeyValue(KeyValueProp { + key: PropName::Ident(i.clone()), + value, + }); + + return; + } + } + _ => {} + } + } } diff --git a/ecmascript/minifier/src/compress/util/mod.rs b/ecmascript/minifier/src/compress/util/mod.rs index fa1feec15c5d..a935f9ac9e3c 100644 --- a/ecmascript/minifier/src/compress/util/mod.rs +++ b/ecmascript/minifier/src/compress/util/mod.rs @@ -576,6 +576,14 @@ where (self.op)(e); } + + fn visit_mut_member_expr(&mut self, e: &mut MemberExpr) { + e.obj.visit_mut_with(self); + + if e.computed { + e.prop.visit_mut_with(self); + } + } } pub fn replace_expr(node: &mut N, op: F) diff --git a/ecmascript/minifier/tests/compress/fixture/issues/firebase/dist/1/input.js b/ecmascript/minifier/tests/compress/fixture/issues/firebase/dist/1/input.js new file mode 100644 index 000000000000..bfa451902894 --- /dev/null +++ b/ecmascript/minifier/tests/compress/fixture/issues/firebase/dist/1/input.js @@ -0,0 +1,473 @@ +'use strict'; + +var util = require('@firebase/util'); +var tslib = require('tslib'); +var component = require('@firebase/component'); +var modularAPIs = require('@firebase/app'); +var logger$1 = require('@firebase/logger'); + +function _interopNamespace(e) { + if (e && e.__esModule) return e; + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n["default"] = e; + return Object.freeze(n); +} + +var modularAPIs__namespace = /*#__PURE__*/_interopNamespace(modularAPIs); + +/** + * @license + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * Global context object for a collection of services using + * a shared authentication state. + * + * marked as internal because it references internal types exported from @firebase/app + * @internal + */ +var FirebaseAppImpl = /** @class */ (function () { + function FirebaseAppImpl(_delegate, firebase) { + var _this = this; + this._delegate = _delegate; + this.firebase = firebase; + // add itself to container + modularAPIs._addComponent(_delegate, new component.Component('app-compat', function () { return _this; }, "PUBLIC" /* PUBLIC */)); + this.container = _delegate.container; + } + Object.defineProperty(FirebaseAppImpl.prototype, "automaticDataCollectionEnabled", { + get: function () { + return this._delegate.automaticDataCollectionEnabled; + }, + set: function (val) { + this._delegate.automaticDataCollectionEnabled = val; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(FirebaseAppImpl.prototype, "name", { + get: function () { + return this._delegate.name; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(FirebaseAppImpl.prototype, "options", { + get: function () { + return this._delegate.options; + }, + enumerable: false, + configurable: true + }); + FirebaseAppImpl.prototype.delete = function () { + var _this = this; + return new Promise(function (resolve) { + _this._delegate.checkDestroyed(); + resolve(); + }).then(function () { + _this.firebase.INTERNAL.removeApp(_this.name); + return modularAPIs.deleteApp(_this._delegate); + }); + }; + /** + * Return a service instance associated with this app (creating it + * on demand), identified by the passed instanceIdentifier. + * + * NOTE: Currently storage and functions are the only ones that are leveraging this + * functionality. They invoke it by calling: + * + * ```javascript + * firebase.app().storage('STORAGE BUCKET ID') + * ``` + * + * The service name is passed to this already + * @internal + */ + FirebaseAppImpl.prototype._getService = function (name, instanceIdentifier) { + var _a; + if (instanceIdentifier === void 0) { instanceIdentifier = modularAPIs._DEFAULT_ENTRY_NAME; } + this._delegate.checkDestroyed(); + // Initialize instance if InstatiationMode is `EXPLICIT`. + var provider = this._delegate.container.getProvider(name); + if (!provider.isInitialized() && + ((_a = provider.getComponent()) === null || _a === void 0 ? void 0 : _a.instantiationMode) === "EXPLICIT" /* EXPLICIT */) { + provider.initialize(); + } + // getImmediate will always succeed because _getService is only called for registered components. + return provider.getImmediate({ + identifier: instanceIdentifier + }); + }; + /** + * Remove a service instance from the cache, so we will create a new instance for this service + * when people try to get it again. + * + * NOTE: currently only firestore uses this functionality to support firestore shutdown. + * + * @param name The service name + * @param instanceIdentifier instance identifier in case multiple instances are allowed + * @internal + */ + FirebaseAppImpl.prototype._removeServiceInstance = function (name, instanceIdentifier) { + if (instanceIdentifier === void 0) { instanceIdentifier = modularAPIs._DEFAULT_ENTRY_NAME; } + this._delegate.container + // eslint-disable-next-line @typescript-eslint/no-explicit-any + .getProvider(name) + .clearInstance(instanceIdentifier); + }; + /** + * @param component the component being added to this app's container + * @internal + */ + FirebaseAppImpl.prototype._addComponent = function (component) { + modularAPIs._addComponent(this._delegate, component); + }; + FirebaseAppImpl.prototype._addOrOverwriteComponent = function (component) { + modularAPIs._addOrOverwriteComponent(this._delegate, component); + }; + FirebaseAppImpl.prototype.toJSON = function () { + return { + name: this.name, + automaticDataCollectionEnabled: this.automaticDataCollectionEnabled, + options: this.options + }; + }; + return FirebaseAppImpl; +}()); +// TODO: investigate why the following needs to be commented out +// Prevent dead-code elimination of these methods w/o invalid property +// copying. +// (FirebaseAppImpl.prototype.name && FirebaseAppImpl.prototype.options) || +// FirebaseAppImpl.prototype.delete || +// console.log('dc'); + +/** + * @license + * Copyright 2019 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var _a; +var ERRORS = (_a = {}, + _a["no-app" /* NO_APP */] = "No Firebase App '{$appName}' has been created - " + + 'call Firebase App.initializeApp()', + _a["invalid-app-argument" /* INVALID_APP_ARGUMENT */] = 'firebase.{$appName}() takes either no argument or a ' + + 'Firebase App instance.', + _a); +var ERROR_FACTORY = new util.ErrorFactory('app-compat', 'Firebase', ERRORS); + +/** + * @license + * Copyright 2019 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * Because auth can't share code with other components, we attach the utility functions + * in an internal namespace to share code. + * This function return a firebase namespace object without + * any utility functions, so it can be shared between the regular firebaseNamespace and + * the lite version. + */ +function createFirebaseNamespaceCore(firebaseAppImpl) { + var apps = {}; + // // eslint-disable-next-line @typescript-eslint/no-explicit-any + // const components = new Map>(); + // A namespace is a plain JavaScript Object. + var namespace = { + // Hack to prevent Babel from modifying the object returned + // as the firebase namespace. + // @ts-ignore + __esModule: true, + initializeApp: initializeAppCompat, + // @ts-ignore + app: app, + registerVersion: modularAPIs__namespace.registerVersion, + setLogLevel: modularAPIs__namespace.setLogLevel, + onLog: modularAPIs__namespace.onLog, + // @ts-ignore + apps: null, + SDK_VERSION: modularAPIs__namespace.SDK_VERSION, + INTERNAL: { + registerComponent: registerComponentCompat, + removeApp: removeApp, + useAsService: useAsService, + modularAPIs: modularAPIs__namespace + } + }; + // Inject a circular default export to allow Babel users who were previously + // using: + // + // import firebase from 'firebase'; + // which becomes: var firebase = require('firebase').default; + // + // instead of + // + // import * as firebase from 'firebase'; + // which becomes: var firebase = require('firebase'); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + namespace['default'] = namespace; + // firebase.apps is a read-only getter. + Object.defineProperty(namespace, 'apps', { + get: getApps + }); + /** + * Called by App.delete() - but before any services associated with the App + * are deleted. + */ + function removeApp(name) { + delete apps[name]; + } + /** + * Get the App object for a given name (or DEFAULT). + */ + function app(name) { + name = name || modularAPIs__namespace._DEFAULT_ENTRY_NAME; + if (!util.contains(apps, name)) { + throw ERROR_FACTORY.create("no-app" /* NO_APP */, { appName: name }); + } + return apps[name]; + } + // @ts-ignore + app['App'] = firebaseAppImpl; + /** + * Create a new App instance (name must be unique). + * + * This function is idempotent. It can be called more than once and return the same instance using the same options and config. + */ + function initializeAppCompat(options, rawConfig) { + if (rawConfig === void 0) { rawConfig = {}; } + var app = modularAPIs__namespace.initializeApp(options, rawConfig); + if (util.contains(apps, app.name)) { + return apps[app.name]; + } + var appCompat = new firebaseAppImpl(app, namespace); + apps[app.name] = appCompat; + return appCompat; + } + /* + * Return an array of all the non-deleted FirebaseApps. + */ + function getApps() { + // Make a copy so caller cannot mutate the apps list. + return Object.keys(apps).map(function (name) { return apps[name]; }); + } + function registerComponentCompat(component) { + var componentName = component.name; + var componentNameWithoutCompat = componentName.replace('-compat', ''); + if (modularAPIs__namespace._registerComponent(component) && + component.type === "PUBLIC" /* PUBLIC */) { + // create service namespace for public components + // The Service namespace is an accessor function ... + var serviceNamespace = function (appArg) { + if (appArg === void 0) { appArg = app(); } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + if (typeof appArg[componentNameWithoutCompat] !== 'function') { + // Invalid argument. + // This happens in the following case: firebase.storage('gs:/') + throw ERROR_FACTORY.create("invalid-app-argument" /* INVALID_APP_ARGUMENT */, { + appName: componentName + }); + } + // Forward service instance lookup to the FirebaseApp. + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return appArg[componentNameWithoutCompat](); + }; + // ... and a container for service-level properties. + if (component.serviceProps !== undefined) { + util.deepExtend(serviceNamespace, component.serviceProps); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + namespace[componentNameWithoutCompat] = serviceNamespace; + // Patch the FirebaseAppImpl prototype + // eslint-disable-next-line @typescript-eslint/no-explicit-any + firebaseAppImpl.prototype[componentNameWithoutCompat] = + // TODO: The eslint disable can be removed and the 'ignoreRestArgs' + // option added to the no-explicit-any rule when ESlint releases it. + // eslint-disable-next-line @typescript-eslint/no-explicit-any + function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + var serviceFxn = this._getService.bind(this, componentName); + return serviceFxn.apply(this, component.multipleInstances ? args : []); + }; + } + return component.type === "PUBLIC" /* PUBLIC */ + ? // eslint-disable-next-line @typescript-eslint/no-explicit-any + namespace[componentNameWithoutCompat] + : null; + } + // Map the requested service to a registered service name + // (used to map auth to serverAuth service when needed). + function useAsService(app, name) { + if (name === 'serverAuth') { + return null; + } + var useService = name; + return useService; + } + return namespace; +} + +/** + * @license + * Copyright 2019 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * Return a firebase namespace object. + * + * In production, this will be called exactly once and the result + * assigned to the 'firebase' global. It may be called multiple times + * in unit tests. + */ +function createFirebaseNamespace() { + var namespace = createFirebaseNamespaceCore(FirebaseAppImpl); + namespace.INTERNAL = tslib.__assign(tslib.__assign({}, namespace.INTERNAL), { + createFirebaseNamespace: createFirebaseNamespace, + extendNamespace: extendNamespace, + createSubscribe: util.createSubscribe, + ErrorFactory: util.ErrorFactory, + deepExtend: util.deepExtend + }); + /** + * Patch the top-level firebase namespace with additional properties. + * + * firebase.INTERNAL.extendNamespace() + */ + function extendNamespace(props) { + util.deepExtend(namespace, props); + } + return namespace; +} +var firebase$1 = createFirebaseNamespace(); + +/** + * @license + * Copyright 2019 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var logger = new logger$1.Logger('@firebase/app-compat'); + +var name = "@firebase/app-compat"; +var version = "0.1.5"; + +/** + * @license + * Copyright 2019 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +function registerCoreComponents(variant) { + // Register `app` package. + modularAPIs.registerVersion(name, version, variant); +} + +/** + * @license + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Firebase Lite detection +// eslint-disable-next-line @typescript-eslint/no-explicit-any +if (util.isBrowser() && self.firebase !== undefined) { + logger.warn("\n Warning: Firebase is already defined in the global scope. Please make sure\n Firebase library is only loaded once.\n "); + // eslint-disable-next-line + var sdkVersion = self.firebase.SDK_VERSION; + if (sdkVersion && sdkVersion.indexOf('LITE') >= 0) { + logger.warn("\n Warning: You are trying to load Firebase while using Firebase Performance standalone script.\n You should load Firebase Performance with this instance of Firebase to avoid loading duplicate code.\n "); + } +} +var firebase = firebase$1; +registerCoreComponents(); + +module.exports = firebase; +//# sourceMappingURL=index.cjs.js.map \ No newline at end of file diff --git a/ecmascript/minifier/tests/compress/fixture/issues/firebase/dist/1/output.js b/ecmascript/minifier/tests/compress/fixture/issues/firebase/dist/1/output.js new file mode 100644 index 000000000000..169129cde584 --- /dev/null +++ b/ecmascript/minifier/tests/compress/fixture/issues/firebase/dist/1/output.js @@ -0,0 +1,156 @@ +"use strict"; +var _a, util = require("@firebase/util"), tslib = require("tslib"), component = require("@firebase/component"), modularAPIs = require("@firebase/app"), logger$1 = require("@firebase/logger"); +function _interopNamespace(e) { + if (e && e.__esModule) return e; + var n = Object.create(null); + return e && Object.keys(e).forEach(function(k) { + if ("default" !== k) { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: !0, + get: function() { + return e[k]; + } + }); + } + }), n.default = e, Object.freeze(n); +} +var modularAPIs__namespace = _interopNamespace(modularAPIs), FirebaseAppImpl = function() { + function FirebaseAppImpl(_delegate, firebase) { + var _this = this; + this._delegate = _delegate, this.firebase = firebase, modularAPIs._addComponent(_delegate, new component.Component("app-compat", function() { + return _this; + }, "PUBLIC")), this.container = _delegate.container; + } + return Object.defineProperty(FirebaseAppImpl.prototype, "automaticDataCollectionEnabled", { + get: function() { + return this._delegate.automaticDataCollectionEnabled; + }, + set: function(val) { + this._delegate.automaticDataCollectionEnabled = val; + }, + enumerable: !1, + configurable: !0 + }), Object.defineProperty(FirebaseAppImpl.prototype, "name", { + get: function() { + return this._delegate.name; + }, + enumerable: !1, + configurable: !0 + }), Object.defineProperty(FirebaseAppImpl.prototype, "options", { + get: function() { + return this._delegate.options; + }, + enumerable: !1, + configurable: !0 + }), FirebaseAppImpl.prototype.delete = function() { + var _this = this; + return new Promise(function(resolve) { + _this._delegate.checkDestroyed(), resolve(); + }).then(function() { + return _this.firebase.INTERNAL.removeApp(_this.name), modularAPIs.deleteApp(_this._delegate); + }); + }, FirebaseAppImpl.prototype._getService = function(name, instanceIdentifier) { + var _a; + void 0 === instanceIdentifier && (instanceIdentifier = modularAPIs._DEFAULT_ENTRY_NAME), this._delegate.checkDestroyed(); + var provider = this._delegate.container.getProvider(name); + return provider.isInitialized() || (null === (_a = provider.getComponent()) || void 0 === _a ? void 0 : _a.instantiationMode) !== "EXPLICIT" || provider.initialize(), provider.getImmediate({ + identifier: instanceIdentifier + }); + }, FirebaseAppImpl.prototype._removeServiceInstance = function(name, instanceIdentifier) { + void 0 === instanceIdentifier && (instanceIdentifier = modularAPIs._DEFAULT_ENTRY_NAME), this._delegate.container.getProvider(name).clearInstance(instanceIdentifier); + }, FirebaseAppImpl.prototype._addComponent = function(component) { + modularAPIs._addComponent(this._delegate, component); + }, FirebaseAppImpl.prototype._addOrOverwriteComponent = function(component) { + modularAPIs._addOrOverwriteComponent(this._delegate, component); + }, FirebaseAppImpl.prototype.toJSON = function() { + return { + name: this.name, + automaticDataCollectionEnabled: this.automaticDataCollectionEnabled, + options: this.options + }; + }, FirebaseAppImpl; +}(), ERRORS = ((_a = { +})["no-app"] = "No Firebase App '{$appName}' has been created - call Firebase App.initializeApp()", _a["invalid-app-argument"] = "firebase.{$appName}() takes either no argument or a Firebase App instance.", _a), ERROR_FACTORY = new util.ErrorFactory("app-compat", "Firebase", ERRORS); +function createFirebaseNamespaceCore(firebaseAppImpl) { + var apps = { + }, namespace = { + __esModule: !0, + initializeApp: function(options, rawConfig) { + void 0 === rawConfig && (rawConfig = { + }); + var app = modularAPIs__namespace.initializeApp(options, rawConfig); + if (util.contains(apps, app.name)) return apps[app.name]; + var appCompat = new firebaseAppImpl(app, namespace); + return apps[app.name] = appCompat, appCompat; + }, + app: app, + registerVersion: modularAPIs__namespace.registerVersion, + setLogLevel: modularAPIs__namespace.setLogLevel, + onLog: modularAPIs__namespace.onLog, + apps: null, + SDK_VERSION: modularAPIs__namespace.SDK_VERSION, + INTERNAL: { + registerComponent: function(component) { + var componentName = component.name, componentNameWithoutCompat = componentName.replace("-compat", ""); + if (modularAPIs__namespace._registerComponent(component) && "PUBLIC" === component.type) { + var serviceNamespace = function(appArg) { + if (void 0 === appArg && (appArg = app()), "function" != typeof appArg[componentNameWithoutCompat]) throw ERROR_FACTORY.create("invalid-app-argument", { + appName: componentName + }); + return appArg[componentNameWithoutCompat](); + }; + void 0 !== component.serviceProps && util.deepExtend(serviceNamespace, component.serviceProps), namespace[componentNameWithoutCompat] = serviceNamespace, firebaseAppImpl.prototype[componentNameWithoutCompat] = function() { + for(var args = [], _i = 0; _i < arguments.length; _i++)args[_i] = arguments[_i]; + return this._getService.bind(this, componentName).apply(this, component.multipleInstances ? args : []); + }; + } + return "PUBLIC" === component.type ? namespace[componentNameWithoutCompat] : null; + }, + removeApp: function(name) { + delete apps[name]; + }, + useAsService: function(app, name) { + return "serverAuth" === name ? null : name; + }, + modularAPIs: modularAPIs__namespace + } + }; + function app(name) { + if (name = name || modularAPIs__namespace._DEFAULT_ENTRY_NAME, !util.contains(apps, name)) throw ERROR_FACTORY.create("no-app", { + appName: name + }); + return apps[name]; + } + return namespace.default = namespace, Object.defineProperty(namespace, "apps", { + get: function() { + return Object.keys(apps).map(function(name) { + return apps[name]; + }); + } + }), app.App = firebaseAppImpl, namespace; +} +function createFirebaseNamespace() { + var namespace = createFirebaseNamespaceCore(FirebaseAppImpl); + return namespace.INTERNAL = tslib.__assign(tslib.__assign({ + }, namespace.INTERNAL), { + createFirebaseNamespace: createFirebaseNamespace, + extendNamespace: function(props) { + util.deepExtend(namespace, props); + }, + createSubscribe: util.createSubscribe, + ErrorFactory: util.ErrorFactory, + deepExtend: util.deepExtend + }), namespace; +} +var firebase$1 = createFirebaseNamespace(), logger = new logger$1.Logger("@firebase/app-compat"), name = "@firebase/app-compat", version = "0.1.5"; +function registerCoreComponents(variant) { + modularAPIs.registerVersion(name, version, variant); +} +if (util.isBrowser() && void 0 !== self.firebase) { + logger.warn("\n Warning: Firebase is already defined in the global scope. Please make sure\n Firebase library is only loaded once.\n "); + var sdkVersion = self.firebase.SDK_VERSION; + sdkVersion && sdkVersion.indexOf("LITE") >= 0 && logger.warn("\n Warning: You are trying to load Firebase while using Firebase Performance standalone script.\n You should load Firebase Performance with this instance of Firebase to avoid loading duplicate code.\n "); +} +var firebase = firebase$1; +registerCoreComponents(), module.exports = firebase; diff --git a/tests/vercel/full/firebase/dist/1/input/index.js b/tests/vercel/full/firebase/dist/1/input/index.js new file mode 100644 index 000000000000..bfa451902894 --- /dev/null +++ b/tests/vercel/full/firebase/dist/1/input/index.js @@ -0,0 +1,473 @@ +'use strict'; + +var util = require('@firebase/util'); +var tslib = require('tslib'); +var component = require('@firebase/component'); +var modularAPIs = require('@firebase/app'); +var logger$1 = require('@firebase/logger'); + +function _interopNamespace(e) { + if (e && e.__esModule) return e; + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n["default"] = e; + return Object.freeze(n); +} + +var modularAPIs__namespace = /*#__PURE__*/_interopNamespace(modularAPIs); + +/** + * @license + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * Global context object for a collection of services using + * a shared authentication state. + * + * marked as internal because it references internal types exported from @firebase/app + * @internal + */ +var FirebaseAppImpl = /** @class */ (function () { + function FirebaseAppImpl(_delegate, firebase) { + var _this = this; + this._delegate = _delegate; + this.firebase = firebase; + // add itself to container + modularAPIs._addComponent(_delegate, new component.Component('app-compat', function () { return _this; }, "PUBLIC" /* PUBLIC */)); + this.container = _delegate.container; + } + Object.defineProperty(FirebaseAppImpl.prototype, "automaticDataCollectionEnabled", { + get: function () { + return this._delegate.automaticDataCollectionEnabled; + }, + set: function (val) { + this._delegate.automaticDataCollectionEnabled = val; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(FirebaseAppImpl.prototype, "name", { + get: function () { + return this._delegate.name; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(FirebaseAppImpl.prototype, "options", { + get: function () { + return this._delegate.options; + }, + enumerable: false, + configurable: true + }); + FirebaseAppImpl.prototype.delete = function () { + var _this = this; + return new Promise(function (resolve) { + _this._delegate.checkDestroyed(); + resolve(); + }).then(function () { + _this.firebase.INTERNAL.removeApp(_this.name); + return modularAPIs.deleteApp(_this._delegate); + }); + }; + /** + * Return a service instance associated with this app (creating it + * on demand), identified by the passed instanceIdentifier. + * + * NOTE: Currently storage and functions are the only ones that are leveraging this + * functionality. They invoke it by calling: + * + * ```javascript + * firebase.app().storage('STORAGE BUCKET ID') + * ``` + * + * The service name is passed to this already + * @internal + */ + FirebaseAppImpl.prototype._getService = function (name, instanceIdentifier) { + var _a; + if (instanceIdentifier === void 0) { instanceIdentifier = modularAPIs._DEFAULT_ENTRY_NAME; } + this._delegate.checkDestroyed(); + // Initialize instance if InstatiationMode is `EXPLICIT`. + var provider = this._delegate.container.getProvider(name); + if (!provider.isInitialized() && + ((_a = provider.getComponent()) === null || _a === void 0 ? void 0 : _a.instantiationMode) === "EXPLICIT" /* EXPLICIT */) { + provider.initialize(); + } + // getImmediate will always succeed because _getService is only called for registered components. + return provider.getImmediate({ + identifier: instanceIdentifier + }); + }; + /** + * Remove a service instance from the cache, so we will create a new instance for this service + * when people try to get it again. + * + * NOTE: currently only firestore uses this functionality to support firestore shutdown. + * + * @param name The service name + * @param instanceIdentifier instance identifier in case multiple instances are allowed + * @internal + */ + FirebaseAppImpl.prototype._removeServiceInstance = function (name, instanceIdentifier) { + if (instanceIdentifier === void 0) { instanceIdentifier = modularAPIs._DEFAULT_ENTRY_NAME; } + this._delegate.container + // eslint-disable-next-line @typescript-eslint/no-explicit-any + .getProvider(name) + .clearInstance(instanceIdentifier); + }; + /** + * @param component the component being added to this app's container + * @internal + */ + FirebaseAppImpl.prototype._addComponent = function (component) { + modularAPIs._addComponent(this._delegate, component); + }; + FirebaseAppImpl.prototype._addOrOverwriteComponent = function (component) { + modularAPIs._addOrOverwriteComponent(this._delegate, component); + }; + FirebaseAppImpl.prototype.toJSON = function () { + return { + name: this.name, + automaticDataCollectionEnabled: this.automaticDataCollectionEnabled, + options: this.options + }; + }; + return FirebaseAppImpl; +}()); +// TODO: investigate why the following needs to be commented out +// Prevent dead-code elimination of these methods w/o invalid property +// copying. +// (FirebaseAppImpl.prototype.name && FirebaseAppImpl.prototype.options) || +// FirebaseAppImpl.prototype.delete || +// console.log('dc'); + +/** + * @license + * Copyright 2019 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var _a; +var ERRORS = (_a = {}, + _a["no-app" /* NO_APP */] = "No Firebase App '{$appName}' has been created - " + + 'call Firebase App.initializeApp()', + _a["invalid-app-argument" /* INVALID_APP_ARGUMENT */] = 'firebase.{$appName}() takes either no argument or a ' + + 'Firebase App instance.', + _a); +var ERROR_FACTORY = new util.ErrorFactory('app-compat', 'Firebase', ERRORS); + +/** + * @license + * Copyright 2019 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * Because auth can't share code with other components, we attach the utility functions + * in an internal namespace to share code. + * This function return a firebase namespace object without + * any utility functions, so it can be shared between the regular firebaseNamespace and + * the lite version. + */ +function createFirebaseNamespaceCore(firebaseAppImpl) { + var apps = {}; + // // eslint-disable-next-line @typescript-eslint/no-explicit-any + // const components = new Map>(); + // A namespace is a plain JavaScript Object. + var namespace = { + // Hack to prevent Babel from modifying the object returned + // as the firebase namespace. + // @ts-ignore + __esModule: true, + initializeApp: initializeAppCompat, + // @ts-ignore + app: app, + registerVersion: modularAPIs__namespace.registerVersion, + setLogLevel: modularAPIs__namespace.setLogLevel, + onLog: modularAPIs__namespace.onLog, + // @ts-ignore + apps: null, + SDK_VERSION: modularAPIs__namespace.SDK_VERSION, + INTERNAL: { + registerComponent: registerComponentCompat, + removeApp: removeApp, + useAsService: useAsService, + modularAPIs: modularAPIs__namespace + } + }; + // Inject a circular default export to allow Babel users who were previously + // using: + // + // import firebase from 'firebase'; + // which becomes: var firebase = require('firebase').default; + // + // instead of + // + // import * as firebase from 'firebase'; + // which becomes: var firebase = require('firebase'); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + namespace['default'] = namespace; + // firebase.apps is a read-only getter. + Object.defineProperty(namespace, 'apps', { + get: getApps + }); + /** + * Called by App.delete() - but before any services associated with the App + * are deleted. + */ + function removeApp(name) { + delete apps[name]; + } + /** + * Get the App object for a given name (or DEFAULT). + */ + function app(name) { + name = name || modularAPIs__namespace._DEFAULT_ENTRY_NAME; + if (!util.contains(apps, name)) { + throw ERROR_FACTORY.create("no-app" /* NO_APP */, { appName: name }); + } + return apps[name]; + } + // @ts-ignore + app['App'] = firebaseAppImpl; + /** + * Create a new App instance (name must be unique). + * + * This function is idempotent. It can be called more than once and return the same instance using the same options and config. + */ + function initializeAppCompat(options, rawConfig) { + if (rawConfig === void 0) { rawConfig = {}; } + var app = modularAPIs__namespace.initializeApp(options, rawConfig); + if (util.contains(apps, app.name)) { + return apps[app.name]; + } + var appCompat = new firebaseAppImpl(app, namespace); + apps[app.name] = appCompat; + return appCompat; + } + /* + * Return an array of all the non-deleted FirebaseApps. + */ + function getApps() { + // Make a copy so caller cannot mutate the apps list. + return Object.keys(apps).map(function (name) { return apps[name]; }); + } + function registerComponentCompat(component) { + var componentName = component.name; + var componentNameWithoutCompat = componentName.replace('-compat', ''); + if (modularAPIs__namespace._registerComponent(component) && + component.type === "PUBLIC" /* PUBLIC */) { + // create service namespace for public components + // The Service namespace is an accessor function ... + var serviceNamespace = function (appArg) { + if (appArg === void 0) { appArg = app(); } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + if (typeof appArg[componentNameWithoutCompat] !== 'function') { + // Invalid argument. + // This happens in the following case: firebase.storage('gs:/') + throw ERROR_FACTORY.create("invalid-app-argument" /* INVALID_APP_ARGUMENT */, { + appName: componentName + }); + } + // Forward service instance lookup to the FirebaseApp. + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return appArg[componentNameWithoutCompat](); + }; + // ... and a container for service-level properties. + if (component.serviceProps !== undefined) { + util.deepExtend(serviceNamespace, component.serviceProps); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + namespace[componentNameWithoutCompat] = serviceNamespace; + // Patch the FirebaseAppImpl prototype + // eslint-disable-next-line @typescript-eslint/no-explicit-any + firebaseAppImpl.prototype[componentNameWithoutCompat] = + // TODO: The eslint disable can be removed and the 'ignoreRestArgs' + // option added to the no-explicit-any rule when ESlint releases it. + // eslint-disable-next-line @typescript-eslint/no-explicit-any + function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + var serviceFxn = this._getService.bind(this, componentName); + return serviceFxn.apply(this, component.multipleInstances ? args : []); + }; + } + return component.type === "PUBLIC" /* PUBLIC */ + ? // eslint-disable-next-line @typescript-eslint/no-explicit-any + namespace[componentNameWithoutCompat] + : null; + } + // Map the requested service to a registered service name + // (used to map auth to serverAuth service when needed). + function useAsService(app, name) { + if (name === 'serverAuth') { + return null; + } + var useService = name; + return useService; + } + return namespace; +} + +/** + * @license + * Copyright 2019 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * Return a firebase namespace object. + * + * In production, this will be called exactly once and the result + * assigned to the 'firebase' global. It may be called multiple times + * in unit tests. + */ +function createFirebaseNamespace() { + var namespace = createFirebaseNamespaceCore(FirebaseAppImpl); + namespace.INTERNAL = tslib.__assign(tslib.__assign({}, namespace.INTERNAL), { + createFirebaseNamespace: createFirebaseNamespace, + extendNamespace: extendNamespace, + createSubscribe: util.createSubscribe, + ErrorFactory: util.ErrorFactory, + deepExtend: util.deepExtend + }); + /** + * Patch the top-level firebase namespace with additional properties. + * + * firebase.INTERNAL.extendNamespace() + */ + function extendNamespace(props) { + util.deepExtend(namespace, props); + } + return namespace; +} +var firebase$1 = createFirebaseNamespace(); + +/** + * @license + * Copyright 2019 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var logger = new logger$1.Logger('@firebase/app-compat'); + +var name = "@firebase/app-compat"; +var version = "0.1.5"; + +/** + * @license + * Copyright 2019 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +function registerCoreComponents(variant) { + // Register `app` package. + modularAPIs.registerVersion(name, version, variant); +} + +/** + * @license + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Firebase Lite detection +// eslint-disable-next-line @typescript-eslint/no-explicit-any +if (util.isBrowser() && self.firebase !== undefined) { + logger.warn("\n Warning: Firebase is already defined in the global scope. Please make sure\n Firebase library is only loaded once.\n "); + // eslint-disable-next-line + var sdkVersion = self.firebase.SDK_VERSION; + if (sdkVersion && sdkVersion.indexOf('LITE') >= 0) { + logger.warn("\n Warning: You are trying to load Firebase while using Firebase Performance standalone script.\n You should load Firebase Performance with this instance of Firebase to avoid loading duplicate code.\n "); + } +} +var firebase = firebase$1; +registerCoreComponents(); + +module.exports = firebase; +//# sourceMappingURL=index.cjs.js.map \ No newline at end of file diff --git a/tests/vercel/full/firebase/dist/1/output/index.js b/tests/vercel/full/firebase/dist/1/output/index.js new file mode 100644 index 000000000000..0533cf60c9cd --- /dev/null +++ b/tests/vercel/full/firebase/dist/1/output/index.js @@ -0,0 +1,148 @@ +"use strict"; +var a, b = require("@firebase/util"), c = require("tslib"), d = require("@firebase/component"), e = require("@firebase/app"), f = require("@firebase/logger"), g = function(h) { + if (h && h.__esModule) return h; + var i = Object.create(null); + return h && Object.keys(h).forEach(function(j) { + if ("default" !== j) { + var k = Object.getOwnPropertyDescriptor(h, j); + Object.defineProperty(i, j, k.get ? k : { + enumerable: !0, + get: function() { + return h[j]; + } + }); + } + }), i.default = h, Object.freeze(i); +}(e), l = function() { + var m = function(n, o) { + var p = this; + this._delegate = n, this.firebase = o, e._addComponent(n, new d.Component("app-compat", function() { + return p; + }, "PUBLIC")), this.container = n.container; + }; + return Object.defineProperty(m.prototype, "automaticDataCollectionEnabled", { + get: function() { + return this._delegate.automaticDataCollectionEnabled; + }, + set: function(q) { + this._delegate.automaticDataCollectionEnabled = q; + }, + enumerable: !1, + configurable: !0 + }), Object.defineProperty(m.prototype, "name", { + get: function() { + return this._delegate.name; + }, + enumerable: !1, + configurable: !0 + }), Object.defineProperty(m.prototype, "options", { + get: function() { + return this._delegate.options; + }, + enumerable: !1, + configurable: !0 + }), m.prototype.delete = function() { + var r = this; + return new Promise(function(s) { + r._delegate.checkDestroyed(), s(); + }).then(function() { + return r.firebase.INTERNAL.removeApp(r.name), e.deleteApp(r._delegate); + }); + }, m.prototype._getService = function(t, u) { + var v; + void 0 === u && (u = e._DEFAULT_ENTRY_NAME), this._delegate.checkDestroyed(); + var w = this._delegate.container.getProvider(t); + return w.isInitialized() || (null === (v = w.getComponent()) || void 0 === v ? void 0 : v.instantiationMode) !== "EXPLICIT" || w.initialize(), w.getImmediate({ + identifier: u + }); + }, m.prototype._removeServiceInstance = function(x, y) { + void 0 === y && (y = e._DEFAULT_ENTRY_NAME), this._delegate.container.getProvider(x).clearInstance(y); + }, m.prototype._addComponent = function(z) { + e._addComponent(this._delegate, z); + }, m.prototype._addOrOverwriteComponent = function(A) { + e._addOrOverwriteComponent(this._delegate, A); + }, m.prototype.toJSON = function() { + return { + name: this.name, + automaticDataCollectionEnabled: this.automaticDataCollectionEnabled, + options: this.options + }; + }, m; +}(), B = ((a = { +})["no-app"] = "No Firebase App '{$appName}' has been created - call Firebase App.initializeApp()", a["invalid-app-argument"] = "firebase.{$appName}() takes either no argument or a Firebase App instance.", a), C = new b.ErrorFactory("app-compat", "Firebase", B); +function D() { + var E = function(F) { + var G = function(H) { + if (H = H || g._DEFAULT_ENTRY_NAME, !b.contains(I, H)) throw C.create("no-app", { + appName: H + }); + return I[H]; + }, I = { + }, J = { + __esModule: !0, + initializeApp: function(K, L) { + void 0 === L && (L = { + }); + var M = g.initializeApp(K, L); + if (b.contains(I, M.name)) return I[M.name]; + var N = new F(M, J); + return I[M.name] = N, N; + }, + app: G, + registerVersion: g.registerVersion, + setLogLevel: g.setLogLevel, + onLog: g.onLog, + apps: null, + SDK_VERSION: g.SDK_VERSION, + INTERNAL: { + registerComponent: function(O) { + var P = O.name, Q = P.replace("-compat", ""); + if (g._registerComponent(O) && "PUBLIC" === O.type) { + var R = function(S) { + if (void 0 === S && (S = G()), "function" != typeof S[Q]) throw C.create("invalid-app-argument", { + appName: P + }); + return S[Q](); + }; + void 0 !== O.serviceProps && b.deepExtend(R, O.serviceProps), J[Q] = R, F.prototype[Q] = function() { + for(var T = [], U = 0; U < arguments.length; U++)T[U] = arguments[U]; + return this._getService.bind(this, P).apply(this, O.multipleInstances ? T : []); + }; + } + return "PUBLIC" === O.type ? J[Q] : null; + }, + removeApp: function(V) { + delete I[V]; + }, + useAsService: function(W, X) { + return "serverAuth" === X ? null : X; + }, + modularAPIs: g + } + }; + return J.default = J, Object.defineProperty(J, "apps", { + get: function() { + return Object.keys(I).map(function(Y) { + return I[Y]; + }); + } + }), G.App = F, J; + }(l); + return E.INTERNAL = c.__assign(c.__assign({ + }, E.INTERNAL), { + createFirebaseNamespace: D, + extendNamespace: function(Z) { + b.deepExtend(E, Z); + }, + createSubscribe: b.createSubscribe, + ErrorFactory: b.ErrorFactory, + deepExtend: b.deepExtend + }), E; +} +var $ = D(), _ = new f.Logger("@firebase/app-compat"); +if (b.isBrowser() && void 0 !== self.firebase) { + _.warn("\n Warning: Firebase is already defined in the global scope. Please make sure\n Firebase library is only loaded once.\n "); + var aa = self.firebase.SDK_VERSION; + aa && aa.indexOf("LITE") >= 0 && _.warn("\n Warning: You are trying to load Firebase while using Firebase Performance standalone script.\n You should load Firebase Performance with this instance of Firebase to avoid loading duplicate code.\n "); +} +e.registerVersion("@firebase/app-compat", "0.1.5", void 0), module.exports = $;