(body: string)
| 1992 | // V8 parses a function declared for a sixth less than a constant holding it, and |
| 1993 | // a call reads it without checking it's been initialized |
| 1994 | const functionsDeclared = (body: string): string => { |
| 1995 | const { program } = parseUnits(body) |
| 1996 | const s = new MagicString(body) |
| 1997 | for (const statement of program.body as Node[]) { |
| 1998 | if (statement.type !== "VariableDeclaration" || statement.kind !== "const") |
| 1999 | continue |
| 2000 | const { declarations } = statement |
| 2001 | if (!declarations.some(declaresFunction)) continue |
| 2002 | s.overwrite( |
| 2003 | statement.start, |
| 2004 | statement.end, |
| 2005 | declarations |
| 2006 | .map(declarator => |
| 2007 | declaresFunction(declarator) ? |
| 2008 | `function ${(declarator.id as { name: string }).name}${body.slice( |
| 2009 | declarator.init!.start + "function".length, |
| 2010 | declarator.init!.end |
| 2011 | )}` |
| 2012 | : `const ${body.slice(declarator.start, declarator.end)}` |
| 2013 | ) |
| 2014 | .join("\n") |
| 2015 | ) |
| 2016 | } |
| 2017 | return s.toString() |
| 2018 | } |
| 2019 | |
| 2020 | const declaresFunction = ({ id, init }: VariableDeclarator): boolean => |
| 2021 | id.type === "Identifier" && !!init && isPlainFunction(init) |
no test coverage detected