Skip to content

Commit 8548a32

Browse files
committed
refactor
1 parent bb1a55c commit 8548a32

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

packages/datadog-instrumentations/src/helpers/rewriter/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function rewrite (content, filename, format) {
7272
ast ??= parse(content.toString(), { range: true, sourceType })
7373

7474
const query = astQuery || fromFunctionQuery(functionQuery)
75-
const state = { ...inst, format, functionQuery }
75+
const state = { ...inst, sourceType, functionQuery }
7676

7777
traverse(ast, query, (...args) => transform(state, ...args))
7878
}

packages/datadog-instrumentations/src/helpers/rewriter/transforms.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ const tracingChannelPredicate = (node) => (
88
)
99

1010
const transforms = module.exports = {
11-
tracingChannelImport ({ format }, node) {
11+
tracingChannelImport ({ sourceType }, node) {
1212
if (node.body.some(tracingChannelPredicate)) return
1313

1414
const index = node.body.findIndex(child => child.directive === 'use strict')
15-
const code = format === 'module'
15+
const code = sourceType === 'module'
1616
? 'import { tracingChannel as tr_ch_apm_tracingChannel } from "diagnostics_channel"'
1717
: 'const {tracingChannel: tr_ch_apm_tracingChannel} = require("diagnostics_channel")'
1818

19-
node.body.splice(index + 1, 0, parse(code, { sourceType: format }).body[0])
19+
node.body.splice(index + 1, 0, parse(code, { sourceType }).body[0])
2020
},
2121

2222
tracingChannelDeclaration (state, node) {

0 commit comments

Comments
 (0)