@@ -5,8 +5,9 @@ const traverse = require('babel-traverse').default;
55const generate = require ( 'babel-generator' ) . default ;
66const treeShake = require ( './shake' ) ;
77const mangleScope = require ( './mangler' ) ;
8+ const { getName, getIdentifier} = require ( './utils' ) ;
89
9- const EXPORTS_RE = / ^ \$ ( [ \d ] + ) \$ e x p o r t s $ / ;
10+ const EXPORTS_RE = / ^ \$ ( . + ? ) \$ e x p o r t s $ / ;
1011
1112const DEFAULT_INTEROP_TEMPLATE = template (
1213 'var NAME = $parcel$interopDefault(MODULE)'
@@ -43,7 +44,7 @@ module.exports = (packager, ast) => {
4344
4445 // If the module is not in this bundle, create a `require` call for it.
4546 if ( ! node && ! mod ) {
46- node = REQUIRE_TEMPLATE ( { ID : t . numericLiteral ( id ) } ) . expression ;
47+ node = REQUIRE_TEMPLATE ( { ID : t . stringLiteral ( id ) } ) . expression ;
4748 return interop ( module , name , path , node ) ;
4849 }
4950
@@ -55,7 +56,7 @@ module.exports = (packager, ast) => {
5556
5657 // If it is CommonJS, look for an exports object.
5758 if ( ! node && mod . cacheData . isCommonJS ) {
58- node = findSymbol ( path , `$ ${ id } $ exports` ) ;
59+ node = findSymbol ( path , getName ( mod , ' exports' ) ) ;
5960 if ( ! node ) {
6061 return null ;
6162 }
@@ -82,7 +83,7 @@ module.exports = (packager, ast) => {
8283 function interop ( mod , originalName , path , node ) {
8384 // Handle interop for default imports of CommonJS modules.
8485 if ( mod . cacheData . isCommonJS && originalName === 'default' ) {
85- let name = `$ ${ mod . id } $interop$default` ;
86+ let name = getName ( mod , ' $interop$default' ) ;
8687 if ( ! path . scope . getBinding ( name ) ) {
8788 let [ decl ] = path . getStatementParent ( ) . insertBefore (
8889 DEFAULT_INTEROP_TEMPLATE ( {
@@ -91,7 +92,7 @@ module.exports = (packager, ast) => {
9192 } )
9293 ) ;
9394
94- let binding = path . scope . getBinding ( `$ ${ mod . id } $ exports` ) ;
95+ let binding = path . scope . getBinding ( getName ( mod , ' exports' ) ) ;
9596 if ( binding ) {
9697 binding . reference ( decl . get ( 'declarations.0.init' ) ) ;
9798 }
@@ -133,7 +134,7 @@ module.exports = (packager, ast) => {
133134
134135 if (
135136 args . length !== 2 ||
136- ! t . isNumericLiteral ( id ) ||
137+ ! t . isStringLiteral ( id ) ||
137138 ! t . isStringLiteral ( source )
138139 ) {
139140 throw new Error (
@@ -158,19 +159,19 @@ module.exports = (packager, ast) => {
158159 if ( assets . get ( mod . id ) ) {
159160 // Replace with nothing if the require call's result is not used.
160161 if ( ! isUnusedValue ( path ) ) {
161- let name = `$ ${ mod . id } $ exports` ;
162+ let name = getName ( mod , ' exports' ) ;
162163 node = t . identifier ( replacements . get ( name ) || name ) ;
163164 }
164165
165166 // We need to wrap the module in a function when a require
166167 // call happens inside a non top-level scope, e.g. in a
167168 // function, if statement, or conditional expression.
168169 if ( mod . cacheData . shouldWrap ) {
169- let call = t . callExpression ( t . identifier ( `$ ${ mod . id } $ init` ) , [ ] ) ;
170+ let call = t . callExpression ( getIdentifier ( mod , ' init' ) , [ ] ) ;
170171 node = node ? t . sequenceExpression ( [ call , node ] ) : call ;
171172 }
172173 } else {
173- node = REQUIRE_TEMPLATE ( { ID : t . numericLiteral ( mod . id ) } ) . expression ;
174+ node = REQUIRE_TEMPLATE ( { ID : t . stringLiteral ( mod . id ) } ) . expression ;
174175 }
175176
176177 if ( node ) {
@@ -184,7 +185,7 @@ module.exports = (packager, ast) => {
184185
185186 if (
186187 args . length !== 2 ||
187- ! t . isNumericLiteral ( id ) ||
188+ ! t . isStringLiteral ( id ) ||
188189 ! t . isStringLiteral ( source )
189190 ) {
190191 throw new Error (
0 commit comments