diff --git a/packages/common/src/utils.js b/packages/common/src/utils.js index 939a7287c3..127a4ce85c 100644 --- a/packages/common/src/utils.js +++ b/packages/common/src/utils.js @@ -463,10 +463,10 @@ export function defineAlias(src, target, prop, opts = {}) { export function serializeFunction(func) { let open = false return serialize(func) - .replace(/^(\s*):(\w+)\(/gm, (_, spaces) => { + .replace(serializeFunction.assignmentRE, (_, spaces) => { return `${spaces}:function(` }) - .replace(/^(\s*)(\w+)\s*\((.*?)\)\s*\{/gm, (_, spaces, name, args) => { + .replace(serializeFunction.internalFunctionRE, (_, spaces, name, args) => { if (open) { return `${spaces}${name}:function(${args}) {` } else { @@ -476,3 +476,6 @@ export function serializeFunction(func) { }) .replace(`${func.name}(`, 'function(') } + +serializeFunction.internalFunctionRE = /^(\s*)(?!(?:if)|(?:for)|(?:while)|(?:switch))(\w+)\s*\((.*?)\)\s*\{/gm +serializeFunction.assignmentRE = /^(\s*):(\w+)\(/gm