@@ -137,19 +137,20 @@ export function bulletProofNamespaces (code, chunkFileName, isResurrectionBuild,
137137 let rewrites = [ ] ;
138138 let parsed = ast . parse ( code , { withComments : true } ) ;
139139 const pureComments = parsed . allComments . filter ( c => c . text === '#__PURE__' ) ;
140- if ( pureComments . length === 0 ) return null ;
141- parsed = ast . ReplaceVisitor . run ( parsed , ( node ) => {
142- if ( node . type === 'VariableDeclaration' ) {
143- const matchingComment = pureComments . find ( c => node . start < c . start && c . end > node . end ) ;
144- if ( ! matchingComment ) return node ;
145- const matchingGetter = node . declarations [ 0 ] ?. init ?. arguments ?. [ 0 ] ?. properties ?. find ( prop => prop . key . name === 'default' && prop . kind === 'get' ) ;
146- if ( ! matchingGetter ) return node ;
147- const getterBody = matchingGetter . value . body ;
148- const [ returnStmt ] = getterBody . body ;
149- rewrites . push ( [ getterBody , `\nif (typeof ${ returnStmt . argument . name } === 'undefined') throw new Error('Module not yet initialized!');\n` ] ) ;
150- }
151- return node ;
152- } ) ;
140+ if ( pureComments . length > 0 ) {
141+ ast . ReplaceVisitor . run ( parsed , ( node ) => {
142+ if ( node . type === 'VariableDeclaration' ) {
143+ const matchingComment = pureComments . find ( c => node . start < c . start && c . end > node . end ) ;
144+ if ( ! matchingComment ) return node ;
145+ const matchingGetter = node . declarations [ 0 ] ?. init ?. arguments ?. [ 0 ] ?. properties ?. find ( prop => prop . key . name === 'default' && prop . kind === 'get' ) ;
146+ if ( ! matchingGetter ) return node ;
147+ const getterBody = matchingGetter . value . body ;
148+ const [ returnStmt ] = getterBody . body ;
149+ rewrites . push ( [ getterBody , `\nif (typeof ${ returnStmt . argument . name } === 'undefined') throw new Error('Module not yet initialized!');\n` ] ) ;
150+ }
151+ return node ;
152+ } ) ;
153+ }
153154 if ( rewrites . length > 0 ) {
154155 arr . sortBy ( rewrites , ( [ node ] ) => node . start ) . forEach ( ( [ node , snippet ] ) => {
155156 code = code . slice ( 0 , node . start + 1 ) + snippet + code . slice ( node . start + 1 ) ;
@@ -159,7 +160,7 @@ export function bulletProofNamespaces (code, chunkFileName, isResurrectionBuild,
159160 // this messes up the source map
160161 code = code . replace ( 'System.register' , `BootstrapSystem._currentFile = "${ chunkFileName } ";\nBootstrapSystem.register` ) ;
161162 }
162- code = code . replace ( "'use strict'" , "var __contextModule__ = typeof module !== 'undefined' ? module : arguments[1];\n" ) ;
163+ code = code . replace ( "'use strict'; " , "var __contextModule__ = typeof module !== 'undefined' ? module : arguments[1];\n" ) ;
163164 return { code } ;
164165}
165166
0 commit comments