@ant-design-vue/babel-plugin-jsx
Advanced tools
Comparing version 1.0.0-beta.1 to 1.0.0-beta.2
@@ -41,2 +41,5 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -46,2 +49,3 @@ var t = __importStar(require("@babel/types")); | ||
var utils_1 = require("./utils"); | ||
var parseDirectives_1 = __importDefault(require("./parseDirectives")); | ||
var patchFlags_1 = require("./patchFlags"); | ||
@@ -136,5 +140,2 @@ var xlinkRE = /^xlink([A-Z])/; | ||
var patchFlag = 0; | ||
if (utils_1.isFragment(path.get('openingElement').get('name'))) { | ||
patchFlag |= 64 /* STABLE_FRAGMENT */; | ||
} | ||
if (props.length === 0) { | ||
@@ -161,2 +162,3 @@ return { | ||
.forEach(function (prop) { | ||
var _a; | ||
if (prop.isJSXAttribute()) { | ||
@@ -198,3 +200,3 @@ var name_1 = utils_1.getJSXAttributeName(prop); | ||
if (utils_1.isDirective(name_1)) { | ||
var _a = utils_1.parseDirectives({ | ||
var _b = parseDirectives_1.default({ | ||
tag: tag, | ||
@@ -206,3 +208,5 @@ isComponent: isComponent, | ||
value: attributeValue, | ||
}), directive = _a.directive, modifiers = _a.modifiers, directiveName = _a.directiveName; | ||
}), directive = _b.directive, modifiers = _b.modifiers, value = _b.value, arg = _b.arg, directiveName = _b.directiveName; | ||
var argVal = (_a = arg) === null || _a === void 0 ? void 0 : _a.value; | ||
var propName = argVal || 'modelValue'; | ||
if (directiveName === 'slots') { | ||
@@ -217,15 +221,15 @@ slots = attributeValue; | ||
// must be v-model and is a component | ||
properties.push(t.objectProperty(t.stringLiteral('modelValue'), | ||
properties.push(t.objectProperty(arg || t.stringLiteral('modelValue'), | ||
// @ts-ignore | ||
attributeValue)); | ||
dynamicPropNames.add('modelValue'); | ||
value)); | ||
dynamicPropNames.add(propName); | ||
if (modifiers.size) { | ||
properties.push(t.objectProperty(t.stringLiteral('modelModifiers'), t.objectExpression(__spread(modifiers).map(function (modifier) { return (t.objectProperty(t.stringLiteral(modifier), t.booleanLiteral(true))); })))); | ||
properties.push(t.objectProperty(t.stringLiteral((argVal || 'model') + "Modifiers"), t.objectExpression(__spread(modifiers).map(function (modifier) { return (t.objectProperty(t.stringLiteral(modifier), t.booleanLiteral(true))); })))); | ||
} | ||
} | ||
if (directiveName === 'model' && attributeValue) { | ||
properties.push(t.objectProperty(t.stringLiteral('onUpdate:modelValue'), t.arrowFunctionExpression([t.identifier('$event')], | ||
if (directiveName === 'model' && value) { | ||
properties.push(t.objectProperty(t.stringLiteral("onUpdate:" + propName), t.arrowFunctionExpression([t.identifier('$event')], | ||
// @ts-ignore | ||
t.assignmentExpression('=', attributeValue, t.identifier('$event'))))); | ||
dynamicPropNames.add('onUpdate:modelValue'); | ||
t.assignmentExpression('=', value, t.identifier('$event'))))); | ||
dynamicPropNames.add("onUpdate:" + propName); | ||
} | ||
@@ -232,0 +236,0 @@ return; |
@@ -21,22 +21,2 @@ "use strict"; | ||
}; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spread = (this && this.__spread) || function () { | ||
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); | ||
return ar; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -46,3 +26,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.walksScope = exports.isFragment = exports.parseDirectives = exports.transformJSXExpressionContainer = exports.transformJSXSpreadChild = exports.transformJSXText = exports.getJSXAttributeName = exports.getTag = exports.transformJSXMemberExpression = exports.checkIsComponent = exports.isDirective = exports.createIdentifier = void 0; | ||
exports.walksScope = exports.isFragment = exports.transformJSXExpressionContainer = exports.transformJSXSpreadChild = exports.transformJSXText = exports.getJSXAttributeName = exports.getTag = exports.transformJSXMemberExpression = exports.checkIsComponent = exports.isDirective = exports.createIdentifier = void 0; | ||
var t = __importStar(require("@babel/types")); | ||
@@ -194,82 +174,4 @@ var html_tags_1 = __importDefault(require("html-tags")); | ||
exports.transformJSXSpreadChild = transformJSXSpreadChild; | ||
/** | ||
* Get JSX element type | ||
* | ||
* @param path Path<JSXOpeningElement> | ||
*/ | ||
var getType = function (path) { | ||
var typePath = path | ||
.get('attributes') | ||
.find(function (attribute) { | ||
if (!t.isJSXAttribute(attribute)) { | ||
return false; | ||
} | ||
return t.isJSXIdentifier(attribute.get('name')) | ||
&& attribute.get('name').get('name') === 'type' | ||
&& t.isStringLiteral(attribute.get('value')); | ||
}); | ||
return typePath ? typePath.get('value.value') : ''; | ||
}; | ||
var resolveDirective = function (path, state, tag, directiveName) { | ||
if (directiveName === 'show') { | ||
return createIdentifier(state, 'vShow'); | ||
} | ||
if (directiveName === 'model') { | ||
var modelToUse = void 0; | ||
var type = getType(path.parentPath); | ||
switch (tag.value) { | ||
case 'select': | ||
modelToUse = createIdentifier(state, 'vModelSelect'); | ||
break; | ||
case 'textarea': | ||
modelToUse = createIdentifier(state, 'vModelText'); | ||
break; | ||
default: | ||
switch (type) { | ||
case 'checkbox': | ||
modelToUse = createIdentifier(state, 'vModelCheckbox'); | ||
break; | ||
case 'radio': | ||
modelToUse = createIdentifier(state, 'vModelRadio'); | ||
break; | ||
default: | ||
modelToUse = createIdentifier(state, 'vModelText'); | ||
} | ||
} | ||
return modelToUse; | ||
} | ||
return t.callExpression(createIdentifier(state, 'resolveDirective'), [ | ||
t.stringLiteral(directiveName), | ||
]); | ||
}; | ||
/** | ||
* Parse directives metadata | ||
* | ||
* @param path JSXAttribute | ||
* @returns null | Object<{ modifiers: Set<string>, valuePath: Path<Expression>}> | ||
*/ | ||
var parseDirectives = function (args) { | ||
var _a; | ||
var name = args.name, path = args.path, value = args.value, state = args.state, tag = args.tag, isComponent = args.isComponent; | ||
var modifiers = name.split('_'); | ||
var directiveName = ((_a = modifiers.shift()) === null || _a === void 0 ? void 0 : _a.replace(/^v/, '').replace(/^-/, '').replace(/^\S/, function (s) { return s.toLowerCase(); })) || ''; | ||
if (directiveName === 'model' && !t.isJSXExpressionContainer(path.get('value'))) { | ||
throw new Error('You have to use JSX Expression inside your v-model'); | ||
} | ||
var modifiersSet = new Set(modifiers); | ||
var hasDirective = directiveName !== 'model' || (directiveName === 'model' && !isComponent); | ||
return { | ||
directiveName: directiveName, | ||
modifiers: modifiersSet, | ||
directive: hasDirective ? [ | ||
resolveDirective(path, state, tag, directiveName), | ||
value, | ||
!!modifiersSet.size && t.unaryExpression('void', t.numericLiteral(0), true), | ||
!!modifiersSet.size && t.objectExpression(__spread(modifiersSet).map(function (modifier) { return t.objectProperty(t.identifier(modifier), t.booleanLiteral(true)); })), | ||
].filter(Boolean) : undefined, | ||
}; | ||
}; | ||
exports.parseDirectives = parseDirectives; | ||
var walksScope = function (path, name) { | ||
if (path.scope.hasBinding(name)) { | ||
if (path.scope.hasBinding(name) && path.parentPath) { | ||
path.parentPath.setData('optimize', false); | ||
@@ -276,0 +178,0 @@ walksScope(path.parentPath, name); |
{ | ||
"name": "@ant-design-vue/babel-plugin-jsx", | ||
"version": "1.0.0-beta.1", | ||
"version": "1.0.0-beta.2", | ||
"description": "Babel plugin for Vue 3.0 JSX", | ||
@@ -40,3 +40,3 @@ "author": "Amour1688 <lcz_1996@foxmail.com>", | ||
"@types/svg-tags": "^1.0.0", | ||
"@vue/compiler-dom": "3.0.0-beta.20", | ||
"@vue/compiler-dom": "3.0.0-beta.21", | ||
"@vue/test-utils": "^2.0.0-alpha.8", | ||
@@ -49,3 +49,3 @@ "babel-jest": "^26.0.1", | ||
"typescript": "^3.9.6", | ||
"vue": "3.0.0-beta.20", | ||
"vue": "3.0.0-beta.21", | ||
"webpack": "^4.43.0", | ||
@@ -52,0 +52,0 @@ "webpack-cli": "^3.3.11", |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
34043
8
783