Skip to content

Commit 449595e

Browse files
martini97bergercookie
authored andcommitted
Fix js variable debugging for complex variables
When debugging with string interpolation it would work for basic types, like: ```javascript > const a = 'some string'; undefined > console.log(`a: ${a}`) a: some text undefined ``` But if you try to print an object/array, you get: ```javascript > const b = {foo: 'bar', baz: ['h', 'a', 'm']} undefined > console.log(`b: ${b}`) b: [object Object] undefined ``` To solve this we could either stringify it, or we could pass the var as another arg, which allows for inspecting it when on browser: ```javascript > const b = {foo: 'bar', baz: ['h', 'a', 'm']} undefined > console.log(`b: `, b) b: { foo: 'bar', baz: [ 'h', 'a', 'm' ] } undefined ```
1 parent c5536ab commit 449595e

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

ftplugin/javascript.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function! s:DebugStringFun()
44
endfunc
55

66
function! s:DebugVarFun(desc, var)
7-
let l:debug_str = 'console.log(`' . a:desc . '${' . a:var . '}`)'
7+
let l:debug_str = 'console.log(`' . a:desc . '`, ' . a:var . ')'
88
return l:debug_str
99
endfunc
1010

0 commit comments

Comments
 (0)