mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-31 07:40:33 +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) {
|
export function serializeFunction(func) {
|
||||||
let open = false
|
let open = false
|
||||||
return serialize(func)
|
return serialize(func)
|
||||||
.replace(/^(\s*):(\w+)\(/gm, (_, spaces) => {
|
.replace(serializeFunction.assignmentRE, (_, spaces) => {
|
||||||
return `${spaces}:function(`
|
return `${spaces}:function(`
|
||||||
})
|
})
|
||||||
.replace(/^(\s*)(\w+)\s*\((.*?)\)\s*\{/gm, (_, spaces, name, args) => {
|
.replace(serializeFunction.internalFunctionRE, (_, spaces, name, args) => {
|
||||||
if (open) {
|
if (open) {
|
||||||
return `${spaces}${name}:function(${args}) {`
|
return `${spaces}${name}:function(${args}) {`
|
||||||
} else {
|
} else {
|
||||||
@ -476,3 +476,6 @@ export function serializeFunction(func) {
|
|||||||
})
|
})
|
||||||
.replace(`${func.name}(`, 'function(')
|
.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