You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.6 KiB
37 lines
1.6 KiB
"use strict"; |
|
Object.defineProperty(exports, "__esModule", { value: true }); |
|
exports.object2Map = exports.objectExp = exports.genRenderFunctionDecl = void 0; |
|
const shared_1 = require("@vue/shared"); |
|
function genRenderFunctionDecl({ targetLanguage, filename, }) { |
|
return `${targetLanguage === 'kotlin' ? '@Suppress("UNUSED_PARAMETER") ' : ''}function ${filename}Render(_ctx: ${filename}): VNode | null`; |
|
} |
|
exports.genRenderFunctionDecl = genRenderFunctionDecl; |
|
exports.objectExp = /\{.*\}/g; |
|
function object2Map(exp, wrap = true) { |
|
const content = (0, shared_1.isString)(exp) ? exp : exp.content; |
|
const matched = content.match(exports.objectExp)[0]; |
|
const keyValues = matched.replace(/\{|\}/g, '').split(','); |
|
let mapConstructor = wrap ? 'new Map<string, any | null>([' : ''; |
|
keyValues.forEach((keyValue, index) => { |
|
const colonIndex = keyValue.indexOf(':'); |
|
const key = needAddQuotes(exp, keyValue) |
|
? `'${keyValue.substring(0, colonIndex)}'` |
|
: keyValue.substring(0, colonIndex); |
|
const value = keyValue.substring(colonIndex + 1); |
|
if (key && value) { |
|
mapConstructor += `[${key},${value}]`; |
|
if (index < keyValues.length - 1) { |
|
mapConstructor += ','; |
|
} |
|
} |
|
}); |
|
mapConstructor += wrap ? '])' : ''; |
|
return content.replace(matched, mapConstructor); |
|
} |
|
exports.object2Map = object2Map; |
|
function needAddQuotes(exp, keyValue) { |
|
return (!(0, shared_1.isString)(exp) && |
|
exp.constType === 3 /* ConstantTypes.CAN_STRINGIFY */ && |
|
!keyValue.startsWith("'") && |
|
!keyValue.startsWith('"')); |
|
}
|
|
|