@@ -7,12 +7,13 @@ const HarmonyImportDependency = require("./HarmonyImportDependency");
77const Template = require ( "../Template" ) ;
88
99class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
10- constructor ( request , originModule , sourceOrder , parserScope , id , name , activeExports , otherStarExports ) {
10+ constructor ( request , originModule , sourceOrder , parserScope , id , name , activeExports , otherStarExports , strictExportPresence ) {
1111 super ( request , originModule , sourceOrder , parserScope ) ;
1212 this . id = id ;
1313 this . name = name ;
1414 this . activeExports = activeExports ;
1515 this . otherStarExports = otherStarExports ;
16+ this . strictExportPresence = strictExportPresence ;
1617 }
1718
1819 get type ( ) {
@@ -40,32 +41,57 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
4041 }
4142
4243 const isNotAHarmonyModule = importedModule . meta && ! importedModule . meta . harmonyModule ;
44+ const strictHarmonyModule = this . originModule . meta . strictHarmonyModule ;
4345 if ( name && id === "default" && isNotAHarmonyModule ) {
44- return {
45- type : "reexport-non-harmony-default" ,
46- module : importedModule ,
47- name
48- } ;
46+ if ( strictHarmonyModule ) {
47+ return {
48+ type : "reexport-non-harmony-default-strict" ,
49+ module : importedModule ,
50+ name
51+ } ;
52+ } else {
53+ return {
54+ type : "reexport-non-harmony-default" ,
55+ module : importedModule ,
56+ name
57+ } ;
58+ }
4959 }
5060
5161 if ( name ) {
5262 // export { name as name }
5363 if ( id ) {
64+ if ( isNotAHarmonyModule && strictHarmonyModule ) {
65+ return {
66+ type : "rexport-non-harmony-undefined" ,
67+ module : importedModule ,
68+ name
69+ } ;
70+ } else {
71+ return {
72+ type : "safe-reexport" ,
73+ module : importedModule ,
74+ map : new Map ( [
75+ [ name , id ]
76+ ] )
77+ } ;
78+ }
79+ }
80+
81+ // export { * as name }
82+ if ( isNotAHarmonyModule && strictHarmonyModule ) {
5483 return {
55- type : "safe- reexport" ,
84+ type : "reexport-fake-namespace-object " ,
5685 module : importedModule ,
57- map : new Map ( [
58- [ name , id ]
59- ] )
86+ name
87+ } ;
88+ } else {
89+ return {
90+ type : "reexport-namespace-object" ,
91+ module : importedModule ,
92+ name
6093 } ;
6194 }
62-
63- // export { * as name }
64- return {
65- type : "reexport-namespace-object" ,
66- module : importedModule ,
67- name
68- } ;
6995 }
7096
7197 const hasUsedExports = Array . isArray ( this . originModule . usedExports ) ;
@@ -166,6 +192,9 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
166192 } ;
167193
168194 case "reexport-namespace-object" :
195+ case "reexport-non-harmony-default-strict" :
196+ case "reexport-fake-namespace-object" :
197+ case "rexport-non-harmony-undefined" :
169198 return {
170199 module : mode . module ,
171200 importedNames : true
@@ -239,6 +268,55 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
239268 } ;
240269 }
241270
271+ getWarnings ( ) {
272+ if ( this . strictExportPresence || this . originModule . meta . strictHarmonyModule ) {
273+ return [ ] ;
274+ }
275+ return this . _getErrors ( ) ;
276+ }
277+
278+ getErrors ( ) {
279+ if ( this . strictExportPresence || this . originModule . meta . strictHarmonyModule ) {
280+ return this . _getErrors ( ) ;
281+ }
282+ return [ ] ;
283+ }
284+
285+ _getErrors ( ) {
286+ const importedModule = this . module ;
287+ if ( ! importedModule ) {
288+ return ;
289+ }
290+
291+ if ( ! importedModule . meta || ! importedModule . meta . harmonyModule ) {
292+ // It's not an harmony module
293+ if ( this . originModule . meta . strictHarmonyModule && this . id !== "default" ) {
294+ // In strict harmony modules we only support the default export
295+ const exportName = this . id ? `the named export '${ this . id } '` : "the namespace object" ;
296+ const err = new Error ( `Can't reexport ${ exportName } from non EcmaScript module (only default export is available)` ) ;
297+ err . hideStack = true ;
298+ return [ err ] ;
299+ }
300+ return ;
301+ }
302+
303+ if ( ! this . id ) {
304+ return ;
305+ }
306+
307+ if ( importedModule . isProvided ( this . id ) !== false ) {
308+ // It's provided or we are not sure
309+ return ;
310+ }
311+
312+ // We are sure that it's not provided
313+ const idIsNotNameMessage = this . id !== this . name ? ` (reexported as '${ this . name } ')` : "" ;
314+ const errorMessage = `"export '${ this . id } '${ idIsNotNameMessage } was not found in '${ this . userRequest } '` ;
315+ const err = new Error ( errorMessage ) ;
316+ err . hideStack = true ;
317+ return [ err ] ;
318+ }
319+
242320 updateHash ( hash ) {
243321 super . updateHash ( hash ) ;
244322 const hashValue = this . getHashValue ( this . module ) ;
@@ -317,6 +395,15 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
317395 case "reexport-non-harmony-default" :
318396 return "/* harmony reexport (default from non-hamory) */ " + this . getReexportStatement ( module , module . isUsed ( mode . name ) , importVar , null ) ;
319397
398+ case "reexport-fake-namespace-object" :
399+ return "/* harmony reexport (fake namespace object from non-hamory) */ " + this . getReexportFakeNamespaceObjectStatement ( module , module . isUsed ( mode . name ) , importVar ) ;
400+
401+ case "rexport-non-harmony-undefined" :
402+ return "/* harmony reexport (non default export from non-hamory) */ " + this . getReexportStatement ( module , module . isUsed ( mode . name ) , "undefined" , "" ) ;
403+
404+ case "reexport-non-harmony-default-strict" :
405+ return "/* harmony reexport (default from non-hamory) */ " + this . getReexportStatement ( module , module . isUsed ( mode . name ) , importVar , "" ) ;
406+
320407 case "reexport-namespace-object" :
321408 return "/* harmony reexport (module object) */ " + this . getReexportStatement ( module , module . isUsed ( mode . name ) , importVar , "" ) ;
322409
@@ -359,6 +446,11 @@ HarmonyExportImportedSpecifierDependency.Template = class HarmonyExportImportedS
359446 return `__webpack_require__.d(${ exportsName } , ${ JSON . stringify ( key ) } , function() { return ${ name } ${ returnValue } ; });\n` ;
360447 }
361448
449+ getReexportFakeNamespaceObjectStatement ( module , key , name ) {
450+ const exportsName = module . exportsArgument ;
451+ return `__webpack_require__.d(${ exportsName } , ${ JSON . stringify ( key ) } , function() { return { "default": ${ name } }; });\n` ;
452+ }
453+
362454 getConditionalReexportStatement ( module , key , name , valueKey ) {
363455 const exportsName = module . exportsArgument ;
364456 const returnValue = this . getReturnValue ( valueKey ) ;
0 commit comments