Skip to content

Commit

Permalink
feat(ecma): jsdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
bennypowers committed Apr 10, 2024
1 parent 3dd4973 commit be518e3
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lua/splitjoin/languages/ecmascript/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ return {
join = ECMAScript.join_arrow_function,
},

comment = {
split = ECMAScript.split_jsdoc_comment,
join = ECMAScript.join_jsdoc_comment,
}

},

}
29 changes: 29 additions & 0 deletions lua/splitjoin/languages/ecmascript/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,33 @@ function ECMAScript.join_arrow_function(node, options)
Node.goto_node(node)
end

function ECMAScript.split_jsdoc_comment(node, options)
local indent = options.default_indent or ' '
for child in node:iter_children() do
if child:type() == 'tag' then return end
end
local append, get = String.append('')
append(
'\n',
indent,
' *',
Node.get_text(node:child(0)),
'\n'
)
Node.replace(node, get())
Node.goto_node(node:child(0))
end

function ECMAScript.join_jsdoc_comment(node, options)
local indent = options.default_indent or ' '
for child in node:iter_children() do
if child:type() == 'tag' then return end
end
local append, get = String.append('')
append('\n'..indent..' *')
append(Node.get_text(node:child(0)))
append('\n')
Node.replace(node, get())
Node.goto_node(node:child(0))
end
return ECMAScript
7 changes: 7 additions & 0 deletions test/fixtures/fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ const g = () => 0
function destruct({ a, b, c }, d) { return { a, b, c, d }; }

destruct = ({ a, b, c }, d) => 0;

/** jsdoc */
const jsdoc = (thing) => thing

/** jsdoc @param {number} thing
*/
const jsdoc = (thing) => thing
16 changes: 16 additions & 0 deletions test/javascript_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,22 @@ describe(lang, function()
)
end)

describe('jsdoc', function()
H.make_suite(lang, '',
d[[
/** jsdoc */
const x = y => y
]],
d[[
/**
* jsdoc
*/
const x = y => y
]],
'j'
)
end)

describe('const f = function() { return 0; }', function()
H.make_suite(lang, '',
d[[
Expand Down

0 comments on commit be518e3

Please sign in to comment.