Skip to content

Commit 7205cb1

Browse files
committed
allow string names in exports
1 parent 00b01ff commit 7205cb1

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodejs 20.9.0

hook.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,22 @@ async function processModule ({
191191
continue
192192
}
193193

194+
if (NODE_MAJOR >= 15) {
195+
// const modName = `v${Buffer.from(n, 'utf-8').toString('hex')}`
196+
const modName = normalizeModName(n)
197+
198+
setters.set(`$${modName}` + ns, `
199+
let $${modName} = ${ns}["${n}"]
200+
export { $${modName} as "${n}" }
201+
set["${n}"] = (v) => {
202+
$${modName} = v
203+
return true
204+
}
205+
`)
206+
207+
continue
208+
}
209+
194210
setters.set(`$${n}` + ns, `
195211
let $${n} = ${ns}.${n}
196212
export { $${n} as ${n} }

test/fixtures/string-export.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const foo = 41
2+
3+
export { foo as "non-valid-identifier" }

test/hook/v15-string-export.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License.
2+
//
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
4+
5+
import Hook from '../../index.js'
6+
import * as stringExportMjs from '../fixtures/string-export.mjs'
7+
import { strictEqual } from 'assert'
8+
9+
Hook((exports, name) => {
10+
if (name.match(/fixtures\/string-export\.mjs/)) {
11+
exports['non-valid-identifier'] += 1
12+
}
13+
})
14+
15+
strictEqual(stringExportMjs['non-valid-identifier'], 42)

0 commit comments

Comments
 (0)