From a56d9364cc053410c63af05b96241dd891b8cd80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Fri, 14 Apr 2023 11:10:39 +0200 Subject: [PATCH 1/3] Fixed exports that are illegal identifiers in the es output --- src/finalisers/es.ts | 10 +++++++++- .../samples/export-illegal-identifier/_config.js | 6 ++++++ .../export-illegal-identifier/_expected/amd/main.js | 8 ++++++++ .../export-illegal-identifier/_expected/cjs/main.js | 6 ++++++ .../export-illegal-identifier/_expected/es/main.js | 3 +++ .../export-illegal-identifier/_expected/system/main.js | 10 ++++++++++ .../samples/export-illegal-identifier/main.js | 3 +++ 7 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 test/chunking-form/samples/export-illegal-identifier/_config.js create mode 100644 test/chunking-form/samples/export-illegal-identifier/_expected/amd/main.js create mode 100644 test/chunking-form/samples/export-illegal-identifier/_expected/cjs/main.js create mode 100644 test/chunking-form/samples/export-illegal-identifier/_expected/es/main.js create mode 100644 test/chunking-form/samples/export-illegal-identifier/_expected/system/main.js create mode 100644 test/chunking-form/samples/export-illegal-identifier/main.js diff --git a/src/finalisers/es.ts b/src/finalisers/es.ts index ac49a9113c6..6cd3dd51f20 100644 --- a/src/finalisers/es.ts +++ b/src/finalisers/es.ts @@ -121,6 +121,10 @@ function getImportBlock( return importBlock; } +function isLegalJsIdentifier(name: string): boolean { + return /^[$A-Z_a-z][\w$]*$/.test(name); +} + function getExportBlock(exports: ChunkExports, { _, cnst }: GenerateCodeSnippets): string[] { const exportBlock: string[] = []; const exportDeclaration: string[] = []; @@ -131,7 +135,11 @@ function getExportBlock(exports: ChunkExports, { _, cnst }: GenerateCodeSnippets exportDeclaration.push( specifier.exported === specifier.local ? specifier.local - : `${specifier.local} as ${specifier.exported}` + : `${specifier.local} as ${ + isLegalJsIdentifier(specifier.exported) + ? specifier.exported + : JSON.stringify(specifier.exported) + }` ); } if (exportDeclaration.length > 0) { diff --git a/test/chunking-form/samples/export-illegal-identifier/_config.js b/test/chunking-form/samples/export-illegal-identifier/_config.js new file mode 100644 index 00000000000..1306fd9a4c7 --- /dev/null +++ b/test/chunking-form/samples/export-illegal-identifier/_config.js @@ -0,0 +1,6 @@ +module.exports = { + description: 'correctly handles illegal identifiers in exports', + options: { + input: ['main'] + } +}; diff --git a/test/chunking-form/samples/export-illegal-identifier/_expected/amd/main.js b/test/chunking-form/samples/export-illegal-identifier/_expected/amd/main.js new file mode 100644 index 00000000000..f3d888f471c --- /dev/null +++ b/test/chunking-form/samples/export-illegal-identifier/_expected/amd/main.js @@ -0,0 +1,8 @@ +define(['exports'], (function (exports) { 'use strict'; + + const legal = 10; + + exports.legal = legal; + exports["🔥illegal"] = legal; + +})); diff --git a/test/chunking-form/samples/export-illegal-identifier/_expected/cjs/main.js b/test/chunking-form/samples/export-illegal-identifier/_expected/cjs/main.js new file mode 100644 index 00000000000..e28cb721894 --- /dev/null +++ b/test/chunking-form/samples/export-illegal-identifier/_expected/cjs/main.js @@ -0,0 +1,6 @@ +'use strict'; + +const legal = 10; + +exports.legal = legal; +exports["🔥illegal"] = legal; diff --git a/test/chunking-form/samples/export-illegal-identifier/_expected/es/main.js b/test/chunking-form/samples/export-illegal-identifier/_expected/es/main.js new file mode 100644 index 00000000000..5793d4fdefe --- /dev/null +++ b/test/chunking-form/samples/export-illegal-identifier/_expected/es/main.js @@ -0,0 +1,3 @@ +const legal = 10; + +export { legal, legal as "🔥illegal" }; diff --git a/test/chunking-form/samples/export-illegal-identifier/_expected/system/main.js b/test/chunking-form/samples/export-illegal-identifier/_expected/system/main.js new file mode 100644 index 00000000000..fe32087efae --- /dev/null +++ b/test/chunking-form/samples/export-illegal-identifier/_expected/system/main.js @@ -0,0 +1,10 @@ +System.register([], (function (exports) { + 'use strict'; + return { + execute: (function () { + + const legal = 10; exports({ legal: legal, '🔥illegal': legal }); + + }) + }; +})); diff --git a/test/chunking-form/samples/export-illegal-identifier/main.js b/test/chunking-form/samples/export-illegal-identifier/main.js new file mode 100644 index 00000000000..532e7aeadcb --- /dev/null +++ b/test/chunking-form/samples/export-illegal-identifier/main.js @@ -0,0 +1,3 @@ +export const legal = 10; + +export { legal as '🔥illegal' }; From 7d8a1860d097229dfb59dc9e80bc9127a15ab1a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Fri, 14 Apr 2023 11:20:24 +0200 Subject: [PATCH 2/3] Unify shared~ regex into `isValidIdentifier` util --- src/finalisers/es.ts | 7 ++----- src/utils/generateCodeSnippets.ts | 7 +++---- src/utils/isValidIdentifier.ts | 5 +++++ 3 files changed, 10 insertions(+), 9 deletions(-) create mode 100644 src/utils/isValidIdentifier.ts diff --git a/src/finalisers/es.ts b/src/finalisers/es.ts index 6cd3dd51f20..5af537af019 100644 --- a/src/finalisers/es.ts +++ b/src/finalisers/es.ts @@ -3,6 +3,7 @@ import type { ChunkDependency, ChunkExports, ImportSpecifier, ReexportSpecifier import type { NormalizedOutputOptions } from '../rollup/types'; import type { GenerateCodeSnippets } from '../utils/generateCodeSnippets'; import { getHelpersBlock } from '../utils/interopHelpers'; +import { isValidIdentifier } from '../utils/isValidIdentifier'; import type { FinaliserOptions } from './index'; export default function es( @@ -121,10 +122,6 @@ function getImportBlock( return importBlock; } -function isLegalJsIdentifier(name: string): boolean { - return /^[$A-Z_a-z][\w$]*$/.test(name); -} - function getExportBlock(exports: ChunkExports, { _, cnst }: GenerateCodeSnippets): string[] { const exportBlock: string[] = []; const exportDeclaration: string[] = []; @@ -136,7 +133,7 @@ function getExportBlock(exports: ChunkExports, { _, cnst }: GenerateCodeSnippets specifier.exported === specifier.local ? specifier.local : `${specifier.local} as ${ - isLegalJsIdentifier(specifier.exported) + isValidIdentifier(specifier.exported) ? specifier.exported : JSON.stringify(specifier.exported) }` diff --git a/src/utils/generateCodeSnippets.ts b/src/utils/generateCodeSnippets.ts index da7ee4fae48..3117859ec19 100644 --- a/src/utils/generateCodeSnippets.ts +++ b/src/utils/generateCodeSnippets.ts @@ -1,5 +1,6 @@ import type { NormalizedOutputOptions } from '../rollup/types'; import RESERVED_NAMES from './RESERVED_NAMES'; +import { isValidIdentifier } from './isValidIdentifier'; export interface GenerateCodeSnippets { _: string; @@ -83,8 +84,8 @@ export function getGenerateCodeSnippets({ ]; const isValidPropertyName = reservedNamesAsProps - ? (name: string): boolean => validPropertyName.test(name) - : (name: string): boolean => !RESERVED_NAMES.has(name) && validPropertyName.test(name); + ? isValidIdentifier + : (name: string): boolean => !RESERVED_NAMES.has(name) && isValidIdentifier(name); return { _, @@ -130,5 +131,3 @@ export function getGenerateCodeSnippets({ const wrapIfNeeded = (code: string, needsParens: boolean | undefined): string => needsParens ? `(${code})` : code; - -const validPropertyName = /^(?!\d)[\w$]+$/; diff --git a/src/utils/isValidIdentifier.ts b/src/utils/isValidIdentifier.ts new file mode 100644 index 00000000000..1ad7b168221 --- /dev/null +++ b/src/utils/isValidIdentifier.ts @@ -0,0 +1,5 @@ +const validIdentifier = /^(?!\d)[\w$]+$/; + +export function isValidIdentifier(name: string): boolean { + return validIdentifier.test(name); +} From 09208dfc3c4d1a834e0cd9fdf95b08bb14e94e8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Mon, 17 Apr 2023 12:27:54 +0200 Subject: [PATCH 3/3] fixed more cases --- src/finalisers/es.ts | 19 ++++---- src/utils/safeName.ts | 6 ++- .../export-illegal-identifier/_config.js | 6 --- .../_expected/amd/main.js | 8 ---- .../_expected/cjs/main.js | 6 --- .../_expected/es/main.js | 3 -- .../_expected/system/main.js | 10 ----- .../samples/export-illegal-identifier/main.js | 3 -- .../_config.js | 10 +++++ .../_expected/amd.js | 41 +++++++++++++++++ .../_expected/cjs.js | 41 +++++++++++++++++ .../_expected/es.js | 10 +++++ .../_expected/iife.js | 44 ++++++++++++++++++ .../_expected/system.js | 18 ++++++++ .../_expected/umd.js | 45 +++++++++++++++++++ .../main.js | 11 +++++ 16 files changed, 234 insertions(+), 47 deletions(-) delete mode 100644 test/chunking-form/samples/export-illegal-identifier/_config.js delete mode 100644 test/chunking-form/samples/export-illegal-identifier/_expected/amd/main.js delete mode 100644 test/chunking-form/samples/export-illegal-identifier/_expected/cjs/main.js delete mode 100644 test/chunking-form/samples/export-illegal-identifier/_expected/es/main.js delete mode 100644 test/chunking-form/samples/export-illegal-identifier/_expected/system/main.js delete mode 100644 test/chunking-form/samples/export-illegal-identifier/main.js create mode 100644 test/form/samples/illegal-identifiers-in-imports-exports/_config.js create mode 100644 test/form/samples/illegal-identifiers-in-imports-exports/_expected/amd.js create mode 100644 test/form/samples/illegal-identifiers-in-imports-exports/_expected/cjs.js create mode 100644 test/form/samples/illegal-identifiers-in-imports-exports/_expected/es.js create mode 100644 test/form/samples/illegal-identifiers-in-imports-exports/_expected/iife.js create mode 100644 test/form/samples/illegal-identifiers-in-imports-exports/_expected/system.js create mode 100644 test/form/samples/illegal-identifiers-in-imports-exports/_expected/umd.js create mode 100644 test/form/samples/illegal-identifiers-in-imports-exports/main.js diff --git a/src/finalisers/es.ts b/src/finalisers/es.ts index 5af537af019..bc83fcef919 100644 --- a/src/finalisers/es.ts +++ b/src/finalisers/es.ts @@ -6,6 +6,9 @@ import { getHelpersBlock } from '../utils/interopHelpers'; import { isValidIdentifier } from '../utils/isValidIdentifier'; import type { FinaliserOptions } from './index'; +const safeExportName = (name: string): string => + isValidIdentifier(name) ? name : JSON.stringify(name); + export default function es( magicString: MagicStringBundle, { accessedGlobals, indent: t, intro, outro, dependencies, exports, snippets }: FinaliserOptions, @@ -69,7 +72,7 @@ function getImportBlock( .map(specifier => specifier.imported === specifier.local ? specifier.imported - : `${specifier.imported} as ${specifier.local}` + : `${safeExportName(specifier.imported)} as ${specifier.local}` ) .join(`,${_}`)}${_}}${_}from${_}${pathWithAssertion}` ); @@ -101,7 +104,9 @@ function getImportBlock( for (const specifier of namespaceReexports) { importBlock.push( `export${_}{${_}${ - name === specifier.reexported ? name : `${name} as ${specifier.reexported}` + name === specifier.reexported + ? name + : `${name} as ${safeExportName(specifier.reexported)}` } };` ); } @@ -111,8 +116,8 @@ function getImportBlock( `export${_}{${_}${namedReexports .map(specifier => specifier.imported === specifier.reexported - ? specifier.imported - : `${specifier.imported} as ${specifier.reexported}` + ? safeExportName(specifier.imported) + : `${safeExportName(specifier.imported)} as ${safeExportName(specifier.reexported)}` ) .join(`,${_}`)}${_}}${_}from${_}${pathWithAssertion}` ); @@ -132,11 +137,7 @@ function getExportBlock(exports: ChunkExports, { _, cnst }: GenerateCodeSnippets exportDeclaration.push( specifier.exported === specifier.local ? specifier.local - : `${specifier.local} as ${ - isValidIdentifier(specifier.exported) - ? specifier.exported - : JSON.stringify(specifier.exported) - }` + : `${specifier.local} as ${safeExportName(specifier.exported)}` ); } if (exportDeclaration.length > 0) { diff --git a/src/utils/safeName.ts b/src/utils/safeName.ts index 560d5a10ca8..20342acc669 100644 --- a/src/utils/safeName.ts +++ b/src/utils/safeName.ts @@ -1,15 +1,17 @@ import RESERVED_NAMES from './RESERVED_NAMES'; import { toBase64 } from './base64'; +import { isValidIdentifier } from './isValidIdentifier'; export function getSafeName( baseName: string, usedNames: Set, forbiddenNames: Set | null ): string { - let safeName = baseName; + const safeBase = isValidIdentifier(baseName) ? baseName : '_safe'; + let safeName = safeBase; let count = 1; while (usedNames.has(safeName) || RESERVED_NAMES.has(safeName) || forbiddenNames?.has(safeName)) { - safeName = `${baseName}$${toBase64(count++)}`; + safeName = `${safeBase}$${toBase64(count++)}`; } usedNames.add(safeName); return safeName; diff --git a/test/chunking-form/samples/export-illegal-identifier/_config.js b/test/chunking-form/samples/export-illegal-identifier/_config.js deleted file mode 100644 index 1306fd9a4c7..00000000000 --- a/test/chunking-form/samples/export-illegal-identifier/_config.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - description: 'correctly handles illegal identifiers in exports', - options: { - input: ['main'] - } -}; diff --git a/test/chunking-form/samples/export-illegal-identifier/_expected/amd/main.js b/test/chunking-form/samples/export-illegal-identifier/_expected/amd/main.js deleted file mode 100644 index f3d888f471c..00000000000 --- a/test/chunking-form/samples/export-illegal-identifier/_expected/amd/main.js +++ /dev/null @@ -1,8 +0,0 @@ -define(['exports'], (function (exports) { 'use strict'; - - const legal = 10; - - exports.legal = legal; - exports["🔥illegal"] = legal; - -})); diff --git a/test/chunking-form/samples/export-illegal-identifier/_expected/cjs/main.js b/test/chunking-form/samples/export-illegal-identifier/_expected/cjs/main.js deleted file mode 100644 index e28cb721894..00000000000 --- a/test/chunking-form/samples/export-illegal-identifier/_expected/cjs/main.js +++ /dev/null @@ -1,6 +0,0 @@ -'use strict'; - -const legal = 10; - -exports.legal = legal; -exports["🔥illegal"] = legal; diff --git a/test/chunking-form/samples/export-illegal-identifier/_expected/es/main.js b/test/chunking-form/samples/export-illegal-identifier/_expected/es/main.js deleted file mode 100644 index 5793d4fdefe..00000000000 --- a/test/chunking-form/samples/export-illegal-identifier/_expected/es/main.js +++ /dev/null @@ -1,3 +0,0 @@ -const legal = 10; - -export { legal, legal as "🔥illegal" }; diff --git a/test/chunking-form/samples/export-illegal-identifier/_expected/system/main.js b/test/chunking-form/samples/export-illegal-identifier/_expected/system/main.js deleted file mode 100644 index fe32087efae..00000000000 --- a/test/chunking-form/samples/export-illegal-identifier/_expected/system/main.js +++ /dev/null @@ -1,10 +0,0 @@ -System.register([], (function (exports) { - 'use strict'; - return { - execute: (function () { - - const legal = 10; exports({ legal: legal, '🔥illegal': legal }); - - }) - }; -})); diff --git a/test/chunking-form/samples/export-illegal-identifier/main.js b/test/chunking-form/samples/export-illegal-identifier/main.js deleted file mode 100644 index 532e7aeadcb..00000000000 --- a/test/chunking-form/samples/export-illegal-identifier/main.js +++ /dev/null @@ -1,3 +0,0 @@ -export const legal = 10; - -export { legal as '🔥illegal' }; diff --git a/test/form/samples/illegal-identifiers-in-imports-exports/_config.js b/test/form/samples/illegal-identifiers-in-imports-exports/_config.js new file mode 100644 index 00000000000..ddda2482ff9 --- /dev/null +++ b/test/form/samples/illegal-identifiers-in-imports-exports/_config.js @@ -0,0 +1,10 @@ +module.exports = { + description: 'correctly handles illegal identifiers in exports/imports', + options: { + input: ['main'], + output: { + name: 'illegalIdentifiers' + }, + external: ['external'] + } +}; diff --git a/test/form/samples/illegal-identifiers-in-imports-exports/_expected/amd.js b/test/form/samples/illegal-identifiers-in-imports-exports/_expected/amd.js new file mode 100644 index 00000000000..7714dd2f464 --- /dev/null +++ b/test/form/samples/illegal-identifiers-in-imports-exports/_expected/amd.js @@ -0,0 +1,41 @@ +define(['exports', 'external'], (function (exports, external) { 'use strict'; + + function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); + } + + var external__namespace = /*#__PURE__*/_interopNamespaceDefault(external); + + console.log(external[":"], external["🤷‍♂️"]); // retain those local bindings + + const legal = 10; + + Object.defineProperty(exports, '-', { + enumerable: true, + get: function () { return external.bar; } + }); + Object.defineProperty(exports, '/', { + enumerable: true, + get: function () { return external["/"]; } + }); + exports["🍅"] = external__namespace; + Object.defineProperty(exports, '😭', { + enumerable: true, + get: function () { return external["😂"]; } + }); + exports["🔥illegal"] = legal; + +})); diff --git a/test/form/samples/illegal-identifiers-in-imports-exports/_expected/cjs.js b/test/form/samples/illegal-identifiers-in-imports-exports/_expected/cjs.js new file mode 100644 index 00000000000..9680e49ac63 --- /dev/null +++ b/test/form/samples/illegal-identifiers-in-imports-exports/_expected/cjs.js @@ -0,0 +1,41 @@ +'use strict'; + +var external = require('external'); + +function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); +} + +var external__namespace = /*#__PURE__*/_interopNamespaceDefault(external); + +console.log(external[":"], external["🤷‍♂️"]); // retain those local bindings + +const legal = 10; + +Object.defineProperty(exports, '-', { + enumerable: true, + get: function () { return external.bar; } +}); +Object.defineProperty(exports, '/', { + enumerable: true, + get: function () { return external["/"]; } +}); +exports["🍅"] = external__namespace; +Object.defineProperty(exports, '😭', { + enumerable: true, + get: function () { return external["😂"]; } +}); +exports["🔥illegal"] = legal; diff --git a/test/form/samples/illegal-identifiers-in-imports-exports/_expected/es.js b/test/form/samples/illegal-identifiers-in-imports-exports/_expected/es.js new file mode 100644 index 00000000000..7fdcae43e5f --- /dev/null +++ b/test/form/samples/illegal-identifiers-in-imports-exports/_expected/es.js @@ -0,0 +1,10 @@ +import { ":" as _safe, "🤷‍♂️" as _safe$1 } from 'external'; +import * as external from 'external'; +export { external as "🍅" }; +export { bar as "-", "/", "😂" as "😭" } from 'external'; + +console.log(_safe, _safe$1); // retain those local bindings + +const legal = 10; + +export { legal as "🔥illegal" }; diff --git a/test/form/samples/illegal-identifiers-in-imports-exports/_expected/iife.js b/test/form/samples/illegal-identifiers-in-imports-exports/_expected/iife.js new file mode 100644 index 00000000000..8858b6fed35 --- /dev/null +++ b/test/form/samples/illegal-identifiers-in-imports-exports/_expected/iife.js @@ -0,0 +1,44 @@ +var illegalIdentifiers = (function (exports, external) { + 'use strict'; + + function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); + } + + var external__namespace = /*#__PURE__*/_interopNamespaceDefault(external); + + console.log(external[":"], external["🤷‍♂️"]); // retain those local bindings + + const legal = 10; + + Object.defineProperty(exports, '-', { + enumerable: true, + get: function () { return external.bar; } + }); + Object.defineProperty(exports, '/', { + enumerable: true, + get: function () { return external["/"]; } + }); + exports["🍅"] = external__namespace; + Object.defineProperty(exports, '😭', { + enumerable: true, + get: function () { return external["😂"]; } + }); + exports["🔥illegal"] = legal; + + return exports; + +})({}, external); diff --git a/test/form/samples/illegal-identifiers-in-imports-exports/_expected/system.js b/test/form/samples/illegal-identifiers-in-imports-exports/_expected/system.js new file mode 100644 index 00000000000..08516b3b24d --- /dev/null +++ b/test/form/samples/illegal-identifiers-in-imports-exports/_expected/system.js @@ -0,0 +1,18 @@ +System.register('illegalIdentifiers', ['external'], (function (exports) { + 'use strict'; + var _safe, _safe$1; + return { + setters: [function (module) { + _safe = module[":"]; + _safe$1 = module["🤷‍♂️"]; + exports({ '-': module.bar, '/': module["/"], '🍅': module, '😭': module["😂"] }); + }], + execute: (function () { + + console.log(_safe, _safe$1); // retain those local bindings + + const legal = exports('🔥illegal', 10); + + }) + }; +})); diff --git a/test/form/samples/illegal-identifiers-in-imports-exports/_expected/umd.js b/test/form/samples/illegal-identifiers-in-imports-exports/_expected/umd.js new file mode 100644 index 00000000000..b2e85246135 --- /dev/null +++ b/test/form/samples/illegal-identifiers-in-imports-exports/_expected/umd.js @@ -0,0 +1,45 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('external')) : + typeof define === 'function' && define.amd ? define(['exports', 'external'], factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.illegalIdentifiers = {}, global.external)); +})(this, (function (exports, external) { 'use strict'; + + function _interopNamespaceDefault(e) { + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { return e[k]; } + }); + } + }); + } + n.default = e; + return Object.freeze(n); + } + + var external__namespace = /*#__PURE__*/_interopNamespaceDefault(external); + + console.log(external[":"], external["🤷‍♂️"]); // retain those local bindings + + const legal = 10; + + Object.defineProperty(exports, '-', { + enumerable: true, + get: function () { return external.bar; } + }); + Object.defineProperty(exports, '/', { + enumerable: true, + get: function () { return external["/"]; } + }); + exports["🍅"] = external__namespace; + Object.defineProperty(exports, '😭', { + enumerable: true, + get: function () { return external["😂"]; } + }); + exports["🔥illegal"] = legal; + +})); diff --git a/test/form/samples/illegal-identifiers-in-imports-exports/main.js b/test/form/samples/illegal-identifiers-in-imports-exports/main.js new file mode 100644 index 00000000000..fca9262d46c --- /dev/null +++ b/test/form/samples/illegal-identifiers-in-imports-exports/main.js @@ -0,0 +1,11 @@ +import { ':' as baz, '🤷‍♂️' as bazinga } from 'external'; +console.log(baz, bazinga); // retain those local bindings + +const legal = 10; + +export { legal as '🔥illegal' }; + +export { bar as '-', '/', '😂' as '😭' } from 'external'; + +import * as lib from 'external'; +export { lib as '🍅' }