Skip to content

Commit

Permalink
fix: match defs at end of string
Browse files Browse the repository at this point in the history
Also, function declarations are not allowed anything but space characters - no new lines
  • Loading branch information
ShaunSHamilton committed Nov 25, 2023
1 parent a15c8a4 commit cc01bc7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const getIsDeclaredAfter = (styleRule: CSSStyleRule) => (selector: string) => {
export module python {
export function getDef(code: string, functionName: string) {
const regex = new RegExp(
`\\n(?<function_indentation>\\s*?)def\\s+${functionName}\\s*\\((?<function_parameters>[^\\)]*)\\)\\s*:\\n(?<function_body>.*?)(?=\\n\\k<function_indentation>[\\w#])`,
`\\n(?<function_indentation> *?)def +${functionName} *\\((?<function_parameters>[^\\)]*)\\)\\s*:\\n(?<function_body>.*?)(?=\\n\\k<function_indentation>[\\w#]|$)`,
"s"
);

Expand All @@ -114,7 +114,8 @@ export module python {
""
);
return {
def: matchedCode[0],
// Entire function definition without additional \n
def: matchedCode[0].slice(1),
function_parameters,
function_body,
function_indentation: functionIndentationSansNewLine.length,
Expand Down

0 comments on commit cc01bc7

Please sign in to comment.