@@ -44,7 +44,7 @@ test('supports a compact argument', () => {
4444 { compact : true , objectShorthand : false }
4545 )
4646 ) . toBe (
47- 'export var some={deep:{object:"definition",here:"here"}};export default{some:some,"else":{deep:{object:"definition",here:"here"}}};'
47+ 'export var some={deep:{object:"definition",here:"here"}};var _arbitrary0={deep:{object:"definition",here:"here"}};export{_arbitrary0 as else}; export default{some:some,"else":{deep:{object:"definition",here:"here"}}};'
4848 ) ;
4949} ) ;
5050
@@ -63,7 +63,10 @@ test('supports nested arrays', () => {
6363} ) ;
6464
6565test ( 'serializes null' , ( ) => {
66- expect ( dataToEsm ( { null : null } ) ) . toBe ( 'export default {\n\t"null": null\n};\n' ) ;
66+ // `null` is a valid IdentifierName, so it is re-exported with the unquoted form.
67+ expect ( dataToEsm ( { null : null } ) ) . toBe (
68+ 'var _arbitrary0 = null;\nexport {\n\t_arbitrary0 as null\n};\nexport default {\n\t"null": null\n};\n'
69+ ) ;
6770} ) ;
6871
6972test ( 'supports default only' , ( ) => {
@@ -125,3 +128,30 @@ test('does not emit a named export for a `default` key with includeArbitraryName
125128 dataToEsm ( { default : 'a' , normal : 'b' } , { namedExports : true , includeArbitraryNames : true } )
126129 ) . toBe ( 'export var normal = "b";\nexport default {\n\t"default": "a",\n\tnormal: normal\n};\n' ) ;
127130} ) ;
131+
132+ test ( 'exports reserved-word / global keys as ES2015-safe named exports' , ( ) => {
133+ // `switch` is a reserved word, `Promise` is a global — both are valid
134+ // IdentifierNames, so they are re-exported with the unquoted form without
135+ // `includeArbitraryNames`. `default` stays object-only.
136+ expect (
137+ dataToEsm (
138+ { switch : 'a' , Promise : 'b' , default : 'c' , normal : 'd' } ,
139+ { namedExports : true , preferConst : true }
140+ )
141+ ) . toBe (
142+ 'const _arbitrary0 = "a";\nconst _arbitrary1 = "b";\nexport const normal = "d";\nexport {\n\t_arbitrary0 as switch,\n\t_arbitrary1 as Promise\n};\nexport default {\n\t"switch": "a",\n\t"Promise": "b",\n\t"default": "c",\n\tnormal: normal\n};\n'
143+ ) ;
144+ } ) ;
145+
146+ test ( 'keeps reserved-word exports unquoted even with includeArbitraryNames' , ( ) => {
147+ // Reserved words use the unquoted ES2015 form; only non-identifier-name keys
148+ // (e.g. `foo-bar`) use the quoted ES2022 arbitrary-namespace form.
149+ expect (
150+ dataToEsm (
151+ { switch : 'a' , 'foo-bar' : 'b' } ,
152+ { namedExports : true , preferConst : true , includeArbitraryNames : true }
153+ )
154+ ) . toBe (
155+ 'const _arbitrary0 = "a";\nconst _arbitrary1 = "b";\nexport {\n\t_arbitrary0 as switch,\n\t_arbitrary1 as "foo-bar"\n};\nexport default {\n\t"switch": "a",\n\t"foo-bar": "b"\n};\n'
156+ ) ;
157+ } ) ;
0 commit comments