@vue/babel-plugin-jsx
Advanced tools
Comparing version 1.0.7 to 1.1.0
@@ -70,3 +70,3 @@ "use strict"; | ||
]; | ||
if (helper_module_imports_1.isModule(path)) { | ||
if ((0, helper_module_imports_1.isModule)(path)) { | ||
// import { createVNode } from "vue"; | ||
@@ -79,3 +79,3 @@ const importMap = {}; | ||
} | ||
const identifier = helper_module_imports_1.addNamed(path, name, 'vue', { | ||
const identifier = (0, helper_module_imports_1.addNamed)(path, name, 'vue', { | ||
ensureLiveReference: true, | ||
@@ -117,3 +117,3 @@ }); | ||
if (!sourceName) { | ||
sourceName = helper_module_imports_1.addNamespace(path, 'vue', { | ||
sourceName = (0, helper_module_imports_1.addNamespace)(path, 'vue', { | ||
ensureLiveReference: true, | ||
@@ -193,1 +193,2 @@ }); | ||
}); | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=interface.js.map |
@@ -47,9 +47,28 @@ "use strict"; | ||
const parseDirectives = (params) => { | ||
var _a, _b, _c; | ||
const { name, path, value, state, tag, isComponent, } = params; | ||
var _a, _b; | ||
const { path, value, state, tag, isComponent, } = params; | ||
const args = []; | ||
const vals = []; | ||
const modifiersSet = []; | ||
const underscoreModifiers = name.split('_'); | ||
const directiveName = ((_a = underscoreModifiers.shift()) === null || _a === void 0 ? void 0 : _a.replace(/^v/, '').replace(/^-/, '').replace(/^\S/, (s) => s.toLowerCase())) || ''; | ||
let directiveName; | ||
let directiveArgument; | ||
let directiveModifiers; | ||
if ('namespace' in path.node.name) { | ||
[directiveName, directiveArgument] = params.name.split(':'); | ||
directiveName = path.node.name.namespace.name; | ||
directiveArgument = path.node.name.name.name; | ||
directiveModifiers = directiveArgument.split('_').slice(1); | ||
} | ||
else { | ||
const underscoreModifiers = params.name.split('_'); | ||
directiveName = underscoreModifiers.shift() || ''; | ||
directiveModifiers = underscoreModifiers; | ||
} | ||
directiveName = directiveName | ||
.replace(/^v/, '') | ||
.replace(/^-/, '') | ||
.replace(/^\S/, (s) => s.toLowerCase()); | ||
if (directiveArgument) { | ||
args.push(t.stringLiteral(directiveArgument)); | ||
} | ||
const isVModels = directiveName === 'models'; | ||
@@ -65,3 +84,3 @@ const isVModel = directiveName === 'model'; | ||
|| (isVModel && !isComponent); | ||
let modifiers = underscoreModifiers; | ||
let modifiers = directiveModifiers; | ||
if (t.isArrayExpression(value)) { | ||
@@ -96,6 +115,6 @@ const elementsList = isVModels ? value.elements : [value]; | ||
args.push(t.nullLiteral()); | ||
modifiersSet.push(new Set(underscoreModifiers)); | ||
modifiersSet.push(new Set(directiveModifiers)); | ||
} | ||
else { | ||
modifiersSet.push(new Set(underscoreModifiers)); | ||
modifiersSet.push(new Set(directiveModifiers)); | ||
} | ||
@@ -110,6 +129,6 @@ return { | ||
vals[0] || value, | ||
((_b = modifiersSet[0]) === null || _b === void 0 ? void 0 : _b.size) | ||
((_a = modifiersSet[0]) === null || _a === void 0 ? void 0 : _a.size) | ||
? args[0] || t.unaryExpression('void', t.numericLiteral(0), true) | ||
: args[0], | ||
!!((_c = modifiersSet[0]) === null || _c === void 0 ? void 0 : _c.size) && t.objectExpression([...modifiersSet[0]].map((modifier) => t.objectProperty(t.identifier(modifier), t.booleanLiteral(true)))), | ||
!!((_b = modifiersSet[0]) === null || _b === void 0 ? void 0 : _b.size) && t.objectExpression([...modifiersSet[0]].map((modifier) => t.objectProperty(t.identifier(modifier), t.booleanLiteral(true)))), | ||
].filter(Boolean) : undefined, | ||
@@ -121,3 +140,3 @@ }; | ||
if (directiveName === 'show') { | ||
return utils_1.createIdentifier(state, 'vShow'); | ||
return (0, utils_1.createIdentifier)(state, 'vShow'); | ||
} | ||
@@ -129,6 +148,6 @@ if (directiveName === 'model') { | ||
case 'select': | ||
modelToUse = utils_1.createIdentifier(state, 'vModelSelect'); | ||
modelToUse = (0, utils_1.createIdentifier)(state, 'vModelSelect'); | ||
break; | ||
case 'textarea': | ||
modelToUse = utils_1.createIdentifier(state, 'vModelText'); | ||
modelToUse = (0, utils_1.createIdentifier)(state, 'vModelText'); | ||
break; | ||
@@ -139,13 +158,13 @@ default: | ||
case 'checkbox': | ||
modelToUse = utils_1.createIdentifier(state, 'vModelCheckbox'); | ||
modelToUse = (0, utils_1.createIdentifier)(state, 'vModelCheckbox'); | ||
break; | ||
case 'radio': | ||
modelToUse = utils_1.createIdentifier(state, 'vModelRadio'); | ||
modelToUse = (0, utils_1.createIdentifier)(state, 'vModelRadio'); | ||
break; | ||
default: | ||
modelToUse = utils_1.createIdentifier(state, 'vModelText'); | ||
modelToUse = (0, utils_1.createIdentifier)(state, 'vModelText'); | ||
} | ||
} | ||
else { | ||
modelToUse = utils_1.createIdentifier(state, 'vModelDynamic'); | ||
modelToUse = (0, utils_1.createIdentifier)(state, 'vModelDynamic'); | ||
} | ||
@@ -155,3 +174,3 @@ } | ||
} | ||
return t.callExpression(utils_1.createIdentifier(state, 'resolveDirective'), [ | ||
return t.callExpression((0, utils_1.createIdentifier)(state, 'resolveDirective'), [ | ||
t.stringLiteral(directiveName), | ||
@@ -161,1 +180,2 @@ ]); | ||
exports.default = parseDirectives; | ||
//# sourceMappingURL=parseDirectives.js.map |
@@ -20,1 +20,2 @@ "use strict"; | ||
}; | ||
//# sourceMappingURL=patchFlags.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=slotFlags.js.map |
@@ -31,3 +31,3 @@ "use strict"; | ||
enter(path, state) { | ||
const fragmentCallee = utils_1.createIdentifier(state, utils_1.FRAGMENT); | ||
const fragmentCallee = (0, utils_1.createIdentifier)(state, utils_1.FRAGMENT); | ||
path.replaceWith(transformFragment(path, t.isIdentifier(fragmentCallee) | ||
@@ -39,1 +39,2 @@ ? t.jsxIdentifier(fragmentCallee.name) | ||
}); | ||
//# sourceMappingURL=sugar-fragment.js.map |
@@ -39,3 +39,3 @@ "use strict"; | ||
if (valuePath.isJSXExpressionContainer()) { | ||
return utils_1.transformJSXExpressionContainer(valuePath); | ||
return (0, utils_1.transformJSXExpressionContainer)(valuePath); | ||
} | ||
@@ -45,4 +45,4 @@ return null; | ||
const buildProps = (path, state) => { | ||
const tag = utils_1.getTag(path, state); | ||
const isComponent = utils_1.checkIsComponent(path.get('openingElement'), state); | ||
const tag = (0, utils_1.getTag)(path, state); | ||
const isComponent = (0, utils_1.checkIsComponent)(path.get('openingElement'), state); | ||
const props = path.get('openingElement').get('attributes'); | ||
@@ -76,7 +76,7 @@ const directives = []; | ||
if (prop.isJSXAttribute()) { | ||
let name = utils_1.getJSXAttributeName(prop); | ||
let name = (0, utils_1.getJSXAttributeName)(prop); | ||
const attributeValue = getJSXAttributeValue(prop, state); | ||
if (!utils_1.isConstant(attributeValue) || name === 'ref') { | ||
if (!(0, utils_1.isConstant)(attributeValue) || name === 'ref') { | ||
if (!isComponent | ||
&& utils_1.isOn(name) | ||
&& (0, utils_1.isOn)(name) | ||
// omit the flag for click handlers becaues hydration gives click | ||
@@ -99,3 +99,3 @@ // dedicated fast path. | ||
else if (name !== 'key' | ||
&& !utils_1.isDirective(name) | ||
&& !(0, utils_1.isDirective)(name) | ||
&& name !== 'on') { | ||
@@ -107,3 +107,3 @@ dynamicPropNames.add(name); | ||
if (!state.get('transformOn')) { | ||
state.set('transformOn', helper_module_imports_1.addDefault(path, '@vue/babel-helper-vue-transform-on', { nameHint: '_transformOn' })); | ||
state.set('transformOn', (0, helper_module_imports_1.addDefault)(path, '@vue/babel-helper-vue-transform-on', { nameHint: '_transformOn' })); | ||
} | ||
@@ -113,4 +113,4 @@ mergeArgs.push(t.callExpression(state.get('transformOn'), [attributeValue || t.booleanLiteral(true)])); | ||
} | ||
if (utils_1.isDirective(name)) { | ||
const { directive, modifiers, values, args, directiveName, } = parseDirectives_1.default({ | ||
if ((0, utils_1.isDirective)(name)) { | ||
const { directive, modifiers, values, args, directiveName, } = (0, parseDirectives_1.default)({ | ||
tag, | ||
@@ -179,3 +179,3 @@ isComponent, | ||
if (properties.length && mergeProps) { | ||
mergeArgs.push(t.objectExpression(utils_1.dedupeProperties(properties, mergeProps))); | ||
mergeArgs.push(t.objectExpression((0, utils_1.dedupeProperties)(properties, mergeProps))); | ||
properties = []; | ||
@@ -185,3 +185,3 @@ } | ||
hasDynamicKeys = true; | ||
utils_1.transformJSXSpreadAttribute(path, prop, mergeProps, mergeProps ? mergeArgs : properties); | ||
(0, utils_1.transformJSXSpreadAttribute)(path, prop, mergeProps, mergeProps ? mergeArgs : properties); | ||
} | ||
@@ -214,6 +214,6 @@ }); | ||
if (properties.length) { | ||
mergeArgs.push(t.objectExpression(utils_1.dedupeProperties(properties, mergeProps))); | ||
mergeArgs.push(t.objectExpression((0, utils_1.dedupeProperties)(properties, mergeProps))); | ||
} | ||
if (mergeArgs.length > 1) { | ||
propsExpression = t.callExpression(utils_1.createIdentifier(state, 'mergeProps'), mergeArgs); | ||
propsExpression = t.callExpression((0, utils_1.createIdentifier)(state, 'mergeProps'), mergeArgs); | ||
} | ||
@@ -231,3 +231,3 @@ else { | ||
else { | ||
propsExpression = t.objectExpression(utils_1.dedupeProperties(properties, mergeProps)); | ||
propsExpression = t.objectExpression((0, utils_1.dedupeProperties)(properties, mergeProps)); | ||
} | ||
@@ -253,5 +253,5 @@ } | ||
if (path.isJSXText()) { | ||
const transformedText = utils_1.transformJSXText(path); | ||
const transformedText = (0, utils_1.transformJSXText)(path); | ||
if (transformedText) { | ||
return t.callExpression(utils_1.createIdentifier(state, 'createTextVNode'), [transformedText]); | ||
return t.callExpression((0, utils_1.createIdentifier)(state, 'createTextVNode'), [transformedText]); | ||
} | ||
@@ -261,3 +261,3 @@ return transformedText; | ||
if (path.isJSXExpressionContainer()) { | ||
const expression = utils_1.transformJSXExpressionContainer(path); | ||
const expression = (0, utils_1.transformJSXExpressionContainer)(path); | ||
if (t.isIdentifier(expression)) { | ||
@@ -267,3 +267,3 @@ const { name } = expression; | ||
referencePaths.forEach((referencePath) => { | ||
utils_1.walksScope(referencePath, name, 2 /* DYNAMIC */); | ||
(0, utils_1.walksScope)(referencePath, name, 2 /* DYNAMIC */); | ||
}); | ||
@@ -274,3 +274,3 @@ } | ||
if (t.isJSXSpreadChild(path)) { | ||
return utils_1.transformJSXSpreadChild(path); | ||
return (0, utils_1.transformJSXSpreadChild)(path); | ||
} | ||
@@ -302,3 +302,3 @@ if (path.isCallExpression()) { | ||
? t.objectExpression([ | ||
!!children.length && t.objectProperty(t.identifier('default'), t.arrowFunctionExpression([], t.arrayExpression(utils_1.buildIIFE(path, children)))), | ||
!!children.length && t.objectProperty(t.identifier('default'), t.arrowFunctionExpression([], t.arrayExpression((0, utils_1.buildIIFE)(path, children)))), | ||
...(slots ? (t.isObjectExpression(slots) | ||
@@ -319,3 +319,3 @@ ? slots.properties | ||
const objectExpression = t.objectExpression([ | ||
t.objectProperty(t.identifier('default'), t.arrowFunctionExpression([], t.arrayExpression(utils_1.buildIIFE(path, [child])))), | ||
t.objectProperty(t.identifier('default'), t.arrowFunctionExpression([], t.arrayExpression((0, utils_1.buildIIFE)(path, [child])))), | ||
optimize && t.objectProperty(t.identifier('_'), t.numericLiteral(slotFlag)), | ||
@@ -337,4 +337,3 @@ ].filter(Boolean)); | ||
const alternate = t.objectExpression([ | ||
t.objectProperty(t.identifier('default'), t.arrowFunctionExpression([], t.arrayExpression(utils_1.buildIIFE(path, [slotId])))), | ||
optimize && t.objectProperty(t.identifier('_'), t.numericLiteral(slotFlag)), | ||
t.objectProperty(t.identifier('default'), t.arrowFunctionExpression([], t.arrayExpression((0, utils_1.buildIIFE)(path, [slotId])))), optimize && t.objectProperty(t.identifier('_'), t.numericLiteral(slotFlag)), | ||
].filter(Boolean)); | ||
@@ -366,3 +365,3 @@ const assignment = t.assignmentExpression('=', slotId, child); | ||
} | ||
const createVNode = t.callExpression(utils_1.createIdentifier(state, 'createVNode'), [ | ||
const createVNode = t.callExpression((0, utils_1.createIdentifier)(state, 'createVNode'), [ | ||
tag, | ||
@@ -378,3 +377,3 @@ props, | ||
} | ||
return t.callExpression(utils_1.createIdentifier(state, 'withDirectives'), [ | ||
return t.callExpression((0, utils_1.createIdentifier)(state, 'withDirectives'), [ | ||
createVNode, | ||
@@ -391,1 +390,2 @@ t.arrayExpression(directives), | ||
}); | ||
//# sourceMappingURL=transform-vue-jsx.js.map |
@@ -66,6 +66,6 @@ "use strict"; | ||
if (namePath.isJSXMemberExpression()) { | ||
return exports.shouldTransformedToSlots(namePath.node.property.name); // For withCtx | ||
return (0, exports.shouldTransformedToSlots)(namePath.node.property.name); // For withCtx | ||
} | ||
const tag = namePath.node.name; | ||
return !((_b = (_a = state.opts).isCustomElement) === null || _b === void 0 ? void 0 : _b.call(_a, tag)) && exports.shouldTransformedToSlots(tag) && !html_tags_1.default.includes(tag) && !svg_tags_1.default.includes(tag); | ||
return !((_b = (_a = state.opts).isCustomElement) === null || _b === void 0 ? void 0 : _b.call(_a, tag)) && (0, exports.shouldTransformedToSlots)(tag) && !html_tags_1.default.includes(tag) && !svg_tags_1.default.includes(tag); | ||
}; | ||
@@ -82,3 +82,3 @@ exports.checkIsComponent = checkIsComponent; | ||
const transformedObject = t.isJSXMemberExpression(objectPath) | ||
? exports.transformJSXMemberExpression(path.get('object')) | ||
? (0, exports.transformJSXMemberExpression)(path.get('object')) | ||
: t.isJSXIdentifier(objectPath) | ||
@@ -104,3 +104,3 @@ ? t.identifier(objectPath.name) | ||
return (name === exports.FRAGMENT | ||
? exports.createIdentifier(state, exports.FRAGMENT) | ||
? (0, exports.createIdentifier)(state, exports.FRAGMENT) | ||
: path.scope.hasBinding(name) | ||
@@ -110,3 +110,3 @@ ? t.identifier(name) | ||
? t.stringLiteral(name) | ||
: t.callExpression(exports.createIdentifier(state, 'resolveComponent'), [t.stringLiteral(name)])); | ||
: t.callExpression((0, exports.createIdentifier)(state, 'resolveComponent'), [t.stringLiteral(name)])); | ||
} | ||
@@ -116,3 +116,3 @@ return t.stringLiteral(name); | ||
if (namePath.isJSXMemberExpression()) { | ||
return exports.transformJSXMemberExpression(namePath); | ||
return (0, exports.transformJSXMemberExpression)(namePath); | ||
} | ||
@@ -189,3 +189,3 @@ throw new Error(`getTag: ${namePath.type} is not supported`); | ||
} | ||
exports.walksScope(path.parentPath, name, slotFlag); | ||
(0, exports.walksScope)(path.parentPath, name, slotFlag); | ||
} | ||
@@ -267,6 +267,6 @@ }; | ||
const { elements } = node; | ||
return elements.every((element) => element && exports.isConstant(element)); | ||
return elements.every((element) => element && (0, exports.isConstant)(element)); | ||
} | ||
if (t.isObjectExpression(node)) { | ||
return node.properties.every((property) => exports.isConstant(property.value)); | ||
return node.properties.every((property) => (0, exports.isConstant)(property.value)); | ||
} | ||
@@ -284,3 +284,3 @@ if (t.isLiteral(node)) { | ||
if (argument.isIdentifier()) { | ||
exports.walksScope(nodePath, argument.node.name, 2 /* DYNAMIC */); | ||
(0, exports.walksScope)(nodePath, argument.node.name, 2 /* DYNAMIC */); | ||
} | ||
@@ -297,1 +297,2 @@ args.push(mergeProps ? argument.node : t.spreadElement(argument.node)); | ||
exports.transformJSXSpreadAttribute = transformJSXSpreadAttribute; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "@vue/babel-plugin-jsx", | ||
"version": "1.0.7", | ||
"version": "1.1.0", | ||
"description": "Babel plugin for Vue 3.0 JSX", | ||
@@ -15,2 +15,3 @@ "author": "Amour1688 <lcz_1996@foxmail.com>", | ||
"build": "rm -rf dist && tsc", | ||
"watch": "rm -rf dist && tsc --watch", | ||
"lint": "eslint 'src/*.ts'", | ||
@@ -38,16 +39,17 @@ "test": "yarn build && jest --coverage", | ||
"devDependencies": { | ||
"@babel/core": "^7.0.0", | ||
"@babel/preset-env": "^7.0.0", | ||
"@types/jest": "^26.0.7", | ||
"@babel/core": "^7.15.5", | ||
"@babel/preset-env": "^7.15.4", | ||
"@types/jest": "^26.0.24", | ||
"@types/svg-tags": "^1.0.0", | ||
"@typescript-eslint/eslint-plugin": "^4.0.1", | ||
"@typescript-eslint/parser": "^4.0.1", | ||
"@vue/compiler-dom": "3.0.5", | ||
"@typescript-eslint/eslint-plugin": "^4.30.0", | ||
"@typescript-eslint/parser": "^4.30.0", | ||
"@vue/compiler-dom": "3.2.8", | ||
"@vue/test-utils": "2.0.0-beta.2", | ||
"jest": "^26.0.1", | ||
"regenerator-runtime": "^0.13.5", | ||
"regenerator-runtime": "^0.13.9", | ||
"ts-jest": "^26.1.3", | ||
"typescript": "^4.2.3", | ||
"vue": "3.0.7" | ||
} | ||
"typescript": "^4.4.2", | ||
"vue": "3.2.8" | ||
}, | ||
"gitHead": "942b3b4a65c37bc2fb39e9045092460633aab327" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
96243
27
1278