From 211793d3767b12dd457de62160b672af24b921e7 Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 28 Jun 2021 18:48:38 -0400 Subject: [PATCH] fix(compiler-sfc): avoid script setup marker showing up in devtools --- packages/compiler-sfc/src/compileScript.ts | 23 ++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/packages/compiler-sfc/src/compileScript.ts b/packages/compiler-sfc/src/compileScript.ts index 3e72da9cf56..cfc5f8021ac 100644 --- a/packages/compiler-sfc/src/compileScript.ts +++ b/packages/compiler-sfc/src/compileScript.ts @@ -1121,15 +1121,22 @@ export function compileScript( allBindings[key] = true } } - const keys = Object.keys(allBindings) - if (!__TEST__) { - // the `__isScriptSetup: true` flag is used by componentPublicInstance - // proxy to allow properties that start with $ or _ - keys.push(`__isScriptSetup: true`) - } - returned = `{ ${keys.join(', ')} }` + returned = `{ ${Object.keys(allBindings).join(', ')} }` + } + + if (!options.inlineTemplate && !__TEST__) { + // in non-inline mode, the `__isScriptSetup: true` flag is used by + // componentPublicInstance proxy to allow properties that start with $ or _ + s.appendRight( + endOffset, + `\nconst __returned__ = ${returned}\n` + + `Object.defineProperty(__returned__, '__isScriptSetup', { enumerable: false, value: true })\n` + + `return __returned__` + + `\n}\n\n` + ) + } else { + s.appendRight(endOffset, `\nreturn ${returned}\n}\n\n`) } - s.appendRight(endOffset, `\nreturn ${returned}\n}\n\n`) // 11. finalize default export let runtimeOptions = ``