UNPKG

vue-styleguidist

Version:
26 lines (23 loc) 1.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = _default; var _vueInbrowserCompilerUtils = require("vue-inbrowser-compiler-utils"); function _default(code, jsxInExamples) { // In case we are loading a vue component as an example, extract script tag if ((0, _vueInbrowserCompilerUtils.isCodeVueSfc)(code)) { var _descriptor$script$co, _descriptor$script; var descriptor = (0, _vueInbrowserCompilerUtils.parseComponent)(code); return (_descriptor$script$co = descriptor === null || descriptor === void 0 ? void 0 : (_descriptor$script = descriptor.script) === null || _descriptor$script === void 0 ? void 0 : _descriptor$script.content) !== null && _descriptor$script$co !== void 0 ? _descriptor$script$co : ''; } // if in JSX mode or literal return examples code as is if (jsxInExamples || /new Vue\(/.test(code)) { return code; } if (/\n\W+?export\W+default\W/.test(code) || /\n\W+?module.exports(\W+)?=/.test(code)) { return code; } //else it could be the weird almost jsx of vue-styleguidist return /^</.test(code.trim()) ? '' : code.split(/\n[\t ]*</)[0]; }