mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-30 23:32:38 +00:00
fix: prevent matching native statements in serializeFunction (#4585)
This commit is contained in:
parent
186b3cb233
commit
5b58272d1a
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user