[EDIT] FILE: jsx-ast-utils.zip
PK ��Y[>q>8\ \ hasEveryProp.jsnu ȯ�� module.exports = require('./lib').hasEveryProp; // eslint-disable-line import/no-unresolved PK ��Y[}:��W W hasProp.jsnu ȯ�� module.exports = require('./lib').hasProp; // eslint-disable-line import/no-unresolved PK ��Y[��] ] eventHandlers.jsnu ȯ�� module.exports = require('./lib').eventHandlers; // eslint-disable-line import/no-unresolved PK ��Y[�n� � .babelrcnu ȯ�� { "presets": ["env"], "plugins": [ ["transform-replace-object-assign", { "moduleSpecifier": "object.assign" }], "transform-object-rest-spread", // "@babel/plugin-proposal-nullish-coalescing-operator", // TODO: update to babel 7 ], } PK ��Y[���\� � src/hasProp.jsnu ȯ�� import propName from './propName'; const DEFAULT_OPTIONS = { spreadStrict: true, ignoreCase: true, }; /** * Returns boolean indicating whether an prop exists on the props * property of a JSX element node. */ export default function hasProp(props = [], prop = '', options = DEFAULT_OPTIONS) { const propToCheck = options.ignoreCase ? prop.toUpperCase() : prop; return props.some((attribute) => { // If the props contain a spread prop, then refer to strict param. if (attribute.type === 'JSXSpreadAttribute') { return !options.spreadStrict; } const currentProp = options.ignoreCase ? propName(attribute).toUpperCase() : propName(attribute); return propToCheck === currentProp; }); } /** * Given the props on a node and a list of props to check, this returns a boolean * indicating if any of them exist on the node. */ export function hasAnyProp(nodeProps = [], props = [], options = DEFAULT_OPTIONS) { const propsToCheck = typeof props === 'string' ? props.split(' ') : props; return propsToCheck.some((prop) => hasProp(nodeProps, prop, options)); } /** * Given the props on a node and a list of props to check, this returns a boolean * indicating if all of them exist on the node */ export function hasEveryProp(nodeProps = [], props = [], options = DEFAULT_OPTIONS) { const propsToCheck = typeof props === 'string' ? props.split(' ') : props; return propsToCheck.every((prop) => hasProp(nodeProps, prop, options)); } PK ��Y[���� src/eventHandlers.jsnu ȯ�� /** * Common event handlers for JSX element event binding. */ const eventHandlersByType = { clipboard: [ 'onCopy', 'onCut', 'onPaste', ], composition: [ 'onCompositionEnd', 'onCompositionStart', 'onCompositionUpdate', ], keyboard: [ 'onKeyDown', 'onKeyPress', 'onKeyUp', ], focus: [ 'onFocus', 'onBlur', ], form: [ 'onChange', 'onInput', 'onSubmit', ], mouse: [ 'onClick', 'onContextMenu', 'onDblClick', 'onDoubleClick', 'onDrag', 'onDragEnd', 'onDragEnter', 'onDragExit', 'onDragLeave', 'onDragOver', 'onDragStart', 'onDrop', 'onMouseDown', 'onMouseEnter', 'onMouseLeave', 'onMouseMove', 'onMouseOut', 'onMouseOver', 'onMouseUp', ], selection: [ 'onSelect', ], touch: [ 'onTouchCancel', 'onTouchEnd', 'onTouchMove', 'onTouchStart', ], ui: [ 'onScroll', ], wheel: [ 'onWheel', ], media: [ 'onAbort', 'onCanPlay', 'onCanPlayThrough', 'onDurationChange', 'onEmptied', 'onEncrypted', 'onEnded', 'onError', 'onLoadedData', 'onLoadedMetadata', 'onLoadStart', 'onPause', 'onPlay', 'onPlaying', 'onProgress', 'onRateChange', 'onSeeked', 'onSeeking', 'onStalled', 'onSuspend', 'onTimeUpdate', 'onVolumeChange', 'onWaiting', ], image: [ 'onLoad', 'onError', ], animation: [ 'onAnimationStart', 'onAnimationEnd', 'onAnimationIteration', ], transition: [ 'onTransitionEnd', ], }; const eventHandlers = Object.keys(eventHandlersByType).reduce( (accumulator, type) => accumulator.concat(eventHandlersByType[type]), [], ); export default eventHandlers; export { eventHandlersByType }; PK ��Y[G��/ / src/values/Literal.jsnu ȯ�� /** * Extractor function for a Literal type value node. * * @param - value - AST Value object with type `Literal` * @returns { String|Boolean } - The extracted value converted to correct type. */ export default function extractValueFromLiteral(value) { const { value: extractedValue } = value; const normalizedStringValue = typeof extractedValue === 'string' && extractedValue.toLowerCase(); if (normalizedStringValue === 'true') { return true; } if (normalizedStringValue === 'false') { return false; } return extractedValue; } PK ��Y[j|�X X $ src/values/expressions/Identifier.jsnu ȯ�� const JS_RESERVED = { Array, Date, Infinity, Math, Number, Object, String, undefined, }; /** * Extractor function for a Identifier type value node. * An Identifier is usually a reference to a variable. * Just return variable name to determine its existence. * * @param - value - AST Value object with type `Identifier` * @returns - The extracted value converted to correct type. */ export default function extractValueFromIdentifier(value) { const { name } = value; if (Object.hasOwnProperty.call(JS_RESERVED, name)) { return JS_RESERVED[name]; } return name; } PK ��Y[�%g� * src/values/expressions/UpdateExpression.jsnu ȯ�� /** * Extractor function for an UpdateExpression type value node. * An update expression is an expression with an update operator. * For example, foo++ will evaluate to foo + 1. * * @param - value - AST Value object with type `UpdateExpression` * @returns - The extracted value converted to correct type. */ export default function extractValueFromUpdateExpression(value) { // eslint-disable-next-line global-require const getValue = require('.').default; const { operator, argument, prefix } = value; let val = getValue(argument); switch (operator) { case '++': return prefix ? ++val : val++; // eslint-disable-line no-plusplus case '--': return prefix ? --val : val--; // eslint-disable-line no-plusplus default: return undefined; } } PK ��Y[��F F 2 src/values/expressions/TaggedTemplateExpression.jsnu ȯ�� import extractValueFromTemplateLiteral from './TemplateLiteral'; /** * Returns the string value of a tagged template literal object. * Redirects the bulk of the work to `TemplateLiteral`. */ export default function extractValueFromTaggedTemplateExpression(value) { return extractValueFromTemplateLiteral(value.quasi); } PK ��Y[�%$,� � ( src/values/expressions/ThisExpression.jsnu ȯ�� /** * Extractor function for a ThisExpression type value node. * A this expression is using `this` as an identifier. * * @returns - 'this' as a string. */ export default function extractValueFromThisExpression() { return 'this'; } PK ��Y[K�� � , src/values/expressions/SequenceExpression.jsnu ȯ�� /** * Extractor function for a SequenceExpression type value node. * A Sequence expression is an object with an attribute named * expressions which contains an array of different types * of expression objects. * * @returns - An array of the extracted elements. */ export default function extractValueFromSequenceExpression(value) { // eslint-disable-next-line global-require const getValue = require('.').default; return value.expressions.map((element) => getValue(element)); } PK ��Y[���6 6 2 src/values/expressions/OptionalMemberExpression.jsnu ȯ�� /** * Extractor function for a OptionalMemberExpression type value node. * A member expression is accessing a property on an object `obj.property`. * * @param - value - AST Value object with type `OptionalMemberExpression` * @returns - The extracted value converted to correct type * and maintaing `obj?.property` convention. */ export default function extractValueFromOptionalMemberExpression(value) { // eslint-disable-next-line global-require const getValue = require('.').default; return `${getValue(value.object)}?.${getValue(value.property)}`; } PK ��Y[�O�K K * src/values/expressions/ObjectExpression.jsnu ȯ�� import assign from 'object.assign'; /** * Extractor function for an ObjectExpression type value node. * An object expression is using {}. * * @returns - a representation of the object */ export default function extractValueFromObjectExpression(value) { // eslint-disable-next-line global-require const getValue = require('.').default; return value.properties.reduce((obj, property) => { const object = { ...obj }; // Support types: SpreadProperty and ExperimentalSpreadProperty if (/^(?:Experimental)?Spread(?:Property|Element)$/.test(property.type)) { if (property.argument.type === 'ObjectExpression') { return assign(object, extractValueFromObjectExpression(property.argument)); } } else { object[getValue(property.key)] = getValue(property.value); } return object; }, {}); } PK ��Y[U��� ) src/values/expressions/ChainExpression.jsnu ȯ�� /** * Extractor function for a ChainExpression type value node. * A member expression is accessing a property on an object `obj.property`. * * @param - value - AST Value object with type `ChainExpression` * @returns - The extracted value converted to correct type * and maintaing `obj?.property` convention. */ export default function extractValueFromChainExpression(value) { // eslint-disable-next-line global-require const getValue = require('.').default; return getValue(value.expression || value); } PK ��Y[C>�� � ) src/values/expressions/TemplateLiteral.jsnu ȯ�� function sortStarts(a, b) { return (a.range ? a.range[0] : a.start) - (b.range ? b.range[0] : b.start); } /** * Returns the string value of a template literal object. * Tries to build it as best as it can based on the passed * prop. For instance `This is a ${prop}` will return 'This is a {prop}'. * * If the template literal builds to undefined (`${undefined}`), then * this should return "undefined". */ export default function extractValueFromTemplateLiteral(value) { const { quasis, expressions, } = value; const partitions = quasis.concat(expressions); return partitions.sort(sortStarts).reduce((raw, part) => { const { type, } = part; if (type === 'TemplateElement') { return raw + part.value.raw; } if (type === 'Identifier') { return part.name === 'undefined' ? `${raw}${part.name}` : `${raw}{${part.name}}`; } if (type.indexOf('Expression') > -1) { return `${raw}{${type}}`; } return raw; }, ''); } PK ��Y[I�2�9 9 * src/values/expressions/MemberExpression.jsnu ȯ�� /** * Extractor function for a MemberExpression type value node. * A member expression is accessing a property on an object `obj.property`. * * @param - value - AST Value object with type `MemberExpression` * @returns - The extracted value converted to correct type * and maintaing `obj.property` convention. */ export default function extractValueFromMemberExpression(value) { // eslint-disable-next-line global-require const getValue = require('.').default; return `${getValue(value.object)}${value.optional ? '?.' : '.'}${getValue(value.property)}`; } PK ��Y[���� � / src/values/expressions/ConditionalExpression.jsnu ȯ�� /** * Extractor function for a ConditionalExpression type value node. * * @param - value - AST Value object with type `ConditionalExpression` * @returns - The extracted value converted to correct type. */ export default function extractValueFromConditionalExpression(value) { // eslint-disable-next-line global-require const getValue = require('.').default; const { test, alternate, consequent, } = value; return getValue(test) ? getValue(consequent) : getValue(alternate); } PK ��Y[�C) '