diff --git a/hook.js b/hook.js index 3639fbf..484f376 100644 --- a/hook.js +++ b/hook.js @@ -124,14 +124,17 @@ function createHook (meta) { import { register } from '${iitmURL}' import * as namespace from ${JSON.stringify(url)} const set = {} -${exportNames.map((n) => ` -let $${n} = namespace.${n} -export { $${n} as ${n} } -set.${n} = (v) => { - $${n} = v +${exportNames.map((n) => { + const variableName = btoa(n).replace(/=/g, ""); + return ` +let $${variableName} = namespace["${n}"] +export { $${variableName} as "${n}" } +set["${n}"] = (v) => { + $${variableName} = v return true } -`).join('\n')} +` +}).join('\n')} register(${JSON.stringify(realUrl)}, namespace, set, ${JSON.stringify(specifiers.get(realUrl))}) ` } diff --git a/test/fixtures/string-export.mjs b/test/fixtures/string-export.mjs new file mode 100644 index 0000000..c92ced4 --- /dev/null +++ b/test/fixtures/string-export.mjs @@ -0,0 +1,3 @@ +export const foo = 41 + +export { foo as "non-valid-identifier" } diff --git a/test/hook/v20-string-export.mjs b/test/hook/v20-string-export.mjs new file mode 100644 index 0000000..4782160 --- /dev/null +++ b/test/hook/v20-string-export.mjs @@ -0,0 +1,15 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License. +// +// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc. + +import Hook from '../../index.js' +import * as stringExportMjs from '../fixtures/string-export.mjs' +import { strictEqual } from 'assert' + +Hook((exports, name) => { + if (name.match(/\/string-export\.mjs/)) { + exports['non-valid-identifier'] += 1 + } +}) + +strictEqual(stringExportMjs['non-valid-identifier'], 42)