Skip to content

Commit

Permalink
fix: esm support categorise (#192)
Browse files Browse the repository at this point in the history
Co-authored-by: Konstantin Lobkov <klobkov@ozon.ru>
  • Loading branch information
MrWaip and Konstantin Lobkov committed Apr 3, 2023
1 parent b6383bd commit 496cea7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
14 changes: 11 additions & 3 deletions analysis/frame-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class FrameNode {
/* istanbul ignore next: must be a string; can be null but can't replicate in tests */
// If backslashes have been hard-escaped as their unicode escape char, swap them back in
this.name = data.name
.replace(/\\u005c/g, '\\')
.replace('\n', ' /') || ''
.replace(/\\u005c/g, '\\')
.replace('\n', ' /') || ''

this.onStack = data.value
this.onStackTop = { base: data.top }
Expand Down Expand Up @@ -108,7 +108,8 @@ class FrameNode {
const {
category,
type
} = this.getWasmType(name) ||
} = this.getESMAppType(name, appName) ||
this.getWasmType(name) ||
this.getCoreOrV8Type(name, systemInfo) ||
this.getDepType(name, systemInfo) ||
this.getAppType(name, appName)
Expand Down Expand Up @@ -143,6 +144,13 @@ class FrameNode {
return null
}

getESMAppType (name, appName) {
if (/.+file:\/\/.+\.js/.test(name)) {
return this.getAppType(name, appName)
}
return null
}

getCoreOrV8Type (name, systemInfo) {
// TODO: see if any subdivisions of core are useful
const core = { type: 'core', category: 'core' }
Expand Down
20 changes: 18 additions & 2 deletions test/analysis-categorise.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ const windows = {
nodeVersions: { node: '8.13.0' }
}

const mac = {
mainDirectory: '/Users/username/code/repo',
pathSeparator: '/',
nodeVersions: { node: '16.19.1' }
}

function byProps (properties, sysinfo, appName = 'some-app') {
const node = new FrameNode(properties)
node.categorise(sysinfo, appName)
Expand Down Expand Up @@ -61,11 +67,11 @@ test('analysis - categorise node names', (t) => {
})
t.match(byProps({ name: 'wasm-to-js:iii:i [WASM:Builtin]' }, linux), {
category: 'wasm',
type: 'wasm',
type: 'wasm'
})
t.match(byProps({ name: 'wasm-to-js:iiii:i-0-turbofan [WASM]' }, linux), {
category: 'wasm',
type: 'wasm',
type: 'wasm'
})
t.match(byProps({ name: 'ressa::Parser<CH>::parse_statement_list_item::ha21ba52d257287dd [WASM:Opt]' }, linux), {
category: 'wasm',
Expand All @@ -89,6 +95,14 @@ test('analysis - categorise node names', (t) => {
category: 'app',
type: 'some-app'
})
t.match(byProps({ name: '(anonymous) file:///Users/username/code/repo/server.js:7:14' }, mac), {
category: 'app',
type: 'some-app'
})
t.match(byProps({ name: 'payload file:///Users/username/code/repo/lib/init.js:3:26' }, mac), {
category: 'app',
type: 'some-app'
})

t.equal(byName('/usr/bin/node [SHARED_LIB]', linux), 'cpp')
t.equal(byName('C:\\Program Files\\nodejs\\node.exe [SHARED_LIB]', windows), 'cpp')
Expand All @@ -100,6 +114,8 @@ test('analysis - categorise node names', (t) => {
t.equal(byName('(anonymous) C:\\Documents\\Contains spaces\\0x\\examples\\rest-api\\etag.js:1:11', windows), 'some-app')
t.equal(byName('InnerArraySort native array.js:486:24', linux), 'native')
t.equal(byName('[\u0000zA-Z\u0000#$%&\'*+.|~]+$ [CODE:RegExp]', linux), 'regexp')
t.equal(byName('(anonymous) file:///Users/username/code/repo/server.js:7:14', mac), 'some-app')
t.equal(byName('payload file:///Users/username/code/repo/lib/init.js:3:26', mac), 'some-app')

t.end()
})
Expand Down

0 comments on commit 496cea7

Please sign in to comment.