(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "@angular/core"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var core_1 = require("@angular/core");
    var /** @type {?} */ FACTORY_CLASS_SUFFIX = 'NgFactory';
    /**
     * Configuration for NgModuleLoader.
     * token.
     *
     * \@experimental
     * @abstract
     */
    var NgModuleLoaderConfig = (function () {
        function NgModuleLoaderConfig() {
        }
        return NgModuleLoaderConfig;
    }());
    exports.NgModuleLoaderConfig = NgModuleLoaderConfig;
    function NgModuleLoaderConfig_tsickle_Closure_declarations() {
        /**
         * Prefix to add when computing the name of the factory module for a given module name.
         * @type {?}
         */
        NgModuleLoaderConfig.prototype.factoryPathPrefix;
        /**
         * Suffix to add when computing the name of the factory module for a given module name.
         * @type {?}
         */
        NgModuleLoaderConfig.prototype.factoryPathSuffix;
    }
    var /** @type {?} */ DEFAULT_CONFIG = {
        factoryPathPrefix: '',
        factoryPathSuffix: '.ngfactory',
    };
    /**
     * NgModuleFactoryLoader that uses SystemJS to load NgModuleFactory
     */
    var NgModuleLoader = (function () {
        /**
         * @param {?} _compiler
         * @param {?=} config
         */
        function NgModuleLoader(_compiler, config) {
            this._compiler = _compiler;
            this._config = config || DEFAULT_CONFIG;
        }
        /**
         * @param {?} modulePath
         * @param {?} ngModuleExport
         * @return {?}
         */
        NgModuleLoader.prototype.load = function (modulePath, ngModuleExport) {
            var /** @type {?} */ offlineMode = this._compiler instanceof core_1.Compiler;
            return offlineMode ? loadPrecompiledFactory(this._config, modulePath, ngModuleExport) : loadAndCompile(this._compiler, modulePath, ngModuleExport);
        };
        return NgModuleLoader;
    }());
    NgModuleLoader.decorators = [
        { type: core_1.Injectable },
    ];
    /**
     * @nocollapse
     */
    NgModuleLoader.ctorParameters = function () { return [
        { type: core_1.Compiler, },
        { type: NgModuleLoaderConfig, decorators: [{ type: core_1.Optional },] },
    ]; };
    exports.NgModuleLoader = NgModuleLoader;
    function NgModuleLoader_tsickle_Closure_declarations() {
        /** @type {?} */
        NgModuleLoader.decorators;
        /**
         * @nocollapse
         * @type {?}
         */
        NgModuleLoader.ctorParameters;
        /** @type {?} */
        NgModuleLoader.prototype._config;
        /** @type {?} */
        NgModuleLoader.prototype._compiler;
    }
    /**
     * @param {?} compiler
     * @param {?} modulePath
     * @param {?} ngModuleExport
     * @return {?}
     */
    function loadAndCompile(compiler, modulePath, ngModuleExport) {
        if (!ngModuleExport) {
            ngModuleExport = 'default';
        }
        return System.import(modulePath)
            .then(function (rawModule) {
            var /** @type {?} */ module = rawModule[ngModuleExport];
            if (!module) {
                throw new Error("Module " + modulePath + " does not export " + ngModuleExport);
            }
            return compiler.compileModuleAsync(module);
        });
    }
    /**
     * @param {?} config
     * @param {?} modulePath
     * @param {?} ngModuleExport
     * @return {?}
     */
    function loadPrecompiledFactory(config, modulePath, ngModuleExport) {
        var /** @type {?} */ factoryClassSuffix = FACTORY_CLASS_SUFFIX;
        if (ngModuleExport === undefined) {
            ngModuleExport = 'default';
            factoryClassSuffix = '';
        }
        return System.import(config.factoryPathPrefix + modulePath + config.factoryPathSuffix)
            .then(function (rawModule) {
            var /** @type {?} */ ngModuleFactory = rawModule[ngModuleExport + factoryClassSuffix];
            if (!ngModuleFactory) {
                throw new Error("Module " + modulePath + " does not export " + ngModuleExport);
            }
            return ngModuleFactory;
        });
    }
});
//# sourceMappingURL=ng-module-loader.js.map