add raw export for named reexport from non-harmony

This commit is contained in:
Tobias Koppers 2020-09-15 12:21:37 +02:00
parent bd2106b512
commit eddd3206dc
4 changed files with 49 additions and 4 deletions

View File

@ -23,6 +23,7 @@ const NAMESPACE_OBJECT_EXPORT = "__WEBPACK_NAMESPACE_OBJECT__";
* @property {number} index
* @property {Module} module
* @property {Map<string, string>} exportMap mapping from export name to symbol
* @property {Map<string, string>} rawExportMap mapping from export name to symbol
* @property {string=} namespaceExportSymbol
*/
@ -64,11 +65,28 @@ class ConcatenationScope {
* @param {string} symbol identifier of the export in source code
*/
registerExport(exportName, symbol) {
if (!this._currentModule.exportMap) {
this._currentModule.exportMap = new Map();
}
if (!this._currentModule.exportMap.has(exportName)) {
this._currentModule.exportMap.set(exportName, symbol);
}
}
/**
*
* @param {string} exportName name of the export
* @param {string} expression expression to be used
*/
registerRawExport(exportName, expression) {
if (!this._currentModule.rawExportMap) {
this._currentModule.rawExportMap = new Map();
}
if (!this._currentModule.rawExportMap.has(exportName)) {
this._currentModule.rawExportMap.set(exportName, expression);
}
}
/**
* @param {string} symbol identifier of the export in source code
*/

View File

@ -746,13 +746,23 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
* @returns {void}
*/
apply(dependency, source, templateContext) {
if (templateContext.concatenationScope) return;
const { moduleGraph, runtime } = templateContext;
const { moduleGraph, runtime, concatenationScope } = templateContext;
const dep = /** @type {HarmonyExportImportedSpecifierDependency} */ (dependency);
const mode = dep.getMode(moduleGraph, runtime);
if (concatenationScope) {
switch (mode.type) {
case "reexport-undefined":
concatenationScope.registerRawExport(
mode.name,
"/* reexport non-default export from non-harmony */ undefined"
);
}
return;
}
if (mode.type !== "unused" && mode.type !== "empty-star") {
super.apply(dependency, source, templateContext);

View File

@ -90,6 +90,7 @@ const propertyAccess = require("../util/propertyAccess");
* @property {Scope} moduleScope
* @property {Map<string, string>} internalNames
* @property {Map<string, string>} exportMap
* @property {Map<string, string>} rawExportMap
* @property {string=} namespaceExportSymbol
* @property {string} namespaceObjectName
* @property {boolean} interopNamespaceObjectUsed
@ -326,7 +327,7 @@ const getFinalBinding = (
switch (info.type) {
case "concatenated": {
const exportId = exportName[0];
const directExport = info.exportMap.get(exportId);
const directExport = info.exportMap && info.exportMap.get(exportId);
if (directExport) {
const usedName = /** @type {string[]} */ (exportsInfo.getUsedName(
exportName,
@ -339,6 +340,15 @@ const getFinalBinding = (
exportName
};
}
const rawExport = info.rawExportMap && info.rawExportMap.get(exportId);
if (rawExport) {
return {
info,
rawName: rawExport,
ids: exportName.slice(1),
exportName
};
}
const reexport = exportInfo.findTarget(moduleGraph, module =>
moduleToInfoMap.has(module)
);
@ -1495,7 +1505,8 @@ class ConcatenatedModule extends Module {
globalScope: undefined,
moduleScope: undefined,
internalNames: new Map(),
exportMap: new Map(),
exportMap: undefined,
rawExportMap: undefined,
namespaceExportSymbol: undefined,
namespaceObjectName: undefined,
interopNamespaceObjectUsed: false,

6
types.d.ts vendored
View File

@ -1674,6 +1674,11 @@ declare interface ConcatenatedModuleInfo {
* mapping from export name to symbol
*/
exportMap: Map<string, string>;
/**
* mapping from export name to symbol
*/
rawExportMap: Map<string, string>;
namespaceExportSymbol?: string;
}
declare interface ConcatenationBailoutReasonContext {
@ -1694,6 +1699,7 @@ declare class ConcatenationScope {
);
isModuleInScope(module: Module): boolean;
registerExport(exportName: string, symbol: string): void;
registerRawExport(exportName: string, expression: string): void;
registerNamespaceExport(symbol: string): void;
createModuleReference(
module: Module,