mirror of
https://github.com/bobwen-dev/react-templates
synced 2025-04-12 00:56:39 +02:00
added jsdoc
This commit is contained in:
parent
17d8eec7f3
commit
09a46dd543
@ -49,7 +49,7 @@ var propsProp = 'rt-props';
|
|||||||
var defaultOptions = {modules: 'amd', version: false, force: false, format: 'stylish', targetVersion: '0.12.2'};
|
var defaultOptions = {modules: 'amd', version: false, force: false, format: 'stylish', targetVersion: '0.12.2'};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param context
|
* @param {Context} context
|
||||||
* @return {boolean}
|
* @return {boolean}
|
||||||
*/
|
*/
|
||||||
function shouldUseCreateElement(context) {
|
function shouldUseCreateElement(context) {
|
||||||
@ -93,6 +93,11 @@ function concatChildren(children) {
|
|||||||
*/
|
*/
|
||||||
var curlyMap = {'{': 1, '}': -1};
|
var curlyMap = {'{': 1, '}': -1};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {{boundParams: Array.<string>, injectedFunctions: Array.<string>, html: string, options: *}} Context
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param node
|
* @param node
|
||||||
* @param context
|
* @param context
|
||||||
@ -144,6 +149,13 @@ function isStringOnlyCode(txt) {
|
|||||||
return txt.length && txt.charAt(0) === '{' && txt.charAt(txt.length - 1) === '}';
|
return txt.length && txt.charAt(0) === '{' && txt.charAt(txt.length - 1) === '}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Context} context
|
||||||
|
* @param {string} namePrefix
|
||||||
|
* @param {string} body
|
||||||
|
* @param {*?} params
|
||||||
|
* @return {string}
|
||||||
|
*/
|
||||||
function generateInjectedFunc(context, namePrefix, body, params) {
|
function generateInjectedFunc(context, namePrefix, body, params) {
|
||||||
params = params || context.boundParams;
|
params = params || context.boundParams;
|
||||||
var generatedFuncName = namePrefix.replace(',', '') + (context.injectedFunctions.length + 1);
|
var generatedFuncName = namePrefix.replace(',', '') + (context.injectedFunctions.length + 1);
|
||||||
@ -153,6 +165,11 @@ function generateInjectedFunc(context, namePrefix, body, params) {
|
|||||||
return generatedFuncName;
|
return generatedFuncName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param node
|
||||||
|
* @param {Context} context
|
||||||
|
* @return {string}
|
||||||
|
*/
|
||||||
function generateProps(node, context) {
|
function generateProps(node, context) {
|
||||||
// console.log(node);
|
// console.log(node);
|
||||||
var props = {};
|
var props = {};
|
||||||
@ -203,6 +220,11 @@ function generateProps(node, context) {
|
|||||||
}).join(',') + '}';
|
}).join(',') + '}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} tagName
|
||||||
|
* @param context
|
||||||
|
* @return {string}
|
||||||
|
*/
|
||||||
function convertTagNameToConstructor(tagName, context) {
|
function convertTagNameToConstructor(tagName, context) {
|
||||||
var isHtmlTag = _.contains(reactDOMSupport[context.options.targetVersion], tagName);
|
var isHtmlTag = _.contains(reactDOMSupport[context.options.targetVersion], tagName);
|
||||||
if (shouldUseCreateElement(context)) {
|
if (shouldUseCreateElement(context)) {
|
||||||
@ -212,6 +234,11 @@ function convertTagNameToConstructor(tagName, context) {
|
|||||||
return isHtmlTag ? 'React.DOM.' + tagName : tagName;
|
return isHtmlTag ? 'React.DOM.' + tagName : tagName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} html
|
||||||
|
* @param options
|
||||||
|
* @return {Context}
|
||||||
|
*/
|
||||||
function defaultContext(html, options) {
|
function defaultContext(html, options) {
|
||||||
return {
|
return {
|
||||||
boundParams: [],
|
boundParams: [],
|
||||||
@ -221,12 +248,21 @@ function defaultContext(html, options) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param node
|
||||||
|
* @return {boolean}
|
||||||
|
*/
|
||||||
function hasNonSimpleChildren(node) {
|
function hasNonSimpleChildren(node) {
|
||||||
return _.any(node.children, function (child) {
|
return _.any(node.children, function (child) {
|
||||||
return child.type === 'tag' && child.attribs[templateProp];
|
return child.type === 'tag' && child.attribs[templateProp];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param node
|
||||||
|
* @param {Context} context
|
||||||
|
* @return {string}
|
||||||
|
*/
|
||||||
function convertHtmlToReact(node, context) {
|
function convertHtmlToReact(node, context) {
|
||||||
if (node.type === 'tag' || node.type === 'style') {
|
if (node.type === 'tag' || node.type === 'style') {
|
||||||
context = {
|
context = {
|
||||||
@ -319,6 +355,10 @@ function convertHtmlToReact(node, context) {
|
|||||||
// });
|
// });
|
||||||
// return html;
|
// return html;
|
||||||
//}
|
//}
|
||||||
|
/**
|
||||||
|
* @param node
|
||||||
|
* @return {boolean}
|
||||||
|
*/
|
||||||
function isTag(node) {
|
function isTag(node) {
|
||||||
return node.type === 'tag';
|
return node.type === 'tag';
|
||||||
}
|
}
|
||||||
@ -343,7 +383,7 @@ function handleSelfClosingHtmlTags(nodes) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} html
|
* @param {string} html
|
||||||
* @param {{modules:string}?} options
|
* @param {{modules:string,defines:*}?} options
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
function convertTemplateToReact(html, options) {
|
function convertTemplateToReact(html, options) {
|
||||||
@ -412,7 +452,7 @@ function generate(data, options) {
|
|||||||
/**
|
/**
|
||||||
* @param {string} code
|
* @param {string} code
|
||||||
* @param node
|
* @param node
|
||||||
* @param context
|
* @param {Context} context
|
||||||
*/
|
*/
|
||||||
function validateJS(code, node, context) {
|
function validateJS(code, node, context) {
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user