aboutsummaryrefslogtreecommitdiff
path: root/node_modules/babel-plugin-transform-vue-jsx/lib
diff options
context:
space:
mode:
authorruki <waruqi@gmail.com>2018-11-08 00:38:48 +0800
committerruki <waruqi@gmail.com>2018-11-07 21:53:09 +0800
commit26105034da4fcce7ac883c899d781f016559310d (patch)
treec459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/babel-plugin-transform-vue-jsx/lib
parent2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff)
downloadxmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz
xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip
switch to vuepress
Diffstat (limited to 'node_modules/babel-plugin-transform-vue-jsx/lib')
-rw-r--r--node_modules/babel-plugin-transform-vue-jsx/lib/group-props.js77
-rw-r--r--node_modules/babel-plugin-transform-vue-jsx/lib/make-map.js8
-rw-r--r--node_modules/babel-plugin-transform-vue-jsx/lib/must-use-prop.js9
3 files changed, 94 insertions, 0 deletions
diff --git a/node_modules/babel-plugin-transform-vue-jsx/lib/group-props.js b/node_modules/babel-plugin-transform-vue-jsx/lib/group-props.js
new file mode 100644
index 00000000..62aa4563
--- /dev/null
+++ b/node_modules/babel-plugin-transform-vue-jsx/lib/group-props.js
@@ -0,0 +1,77 @@
+var makeMap = require('./make-map')
+var isTopLevel = makeMap('class,staticClass,style,key,ref,refInFor,slot,scopedSlots')
+var nestableRE = /^(props|domProps|on|nativeOn|hook)([\-_A-Z])/
+var dirRE = /^v-/
+var xlinkRE = /^xlink([A-Z])/
+
+module.exports = function groupProps (props, t) {
+ var newProps = []
+ var currentNestedObjects = Object.create(null)
+ props.forEach(function (prop) {
+ var name = prop.key.value || prop.key.name
+ if (isTopLevel(name)) {
+ // top-level special props
+ newProps.push(prop)
+ } else {
+ // nested modules
+ var nestMatch = name.match(nestableRE)
+ if (nestMatch) {
+ var prefix = nestMatch[1]
+ var suffix = name.replace(nestableRE, function (_, $1, $2) {
+ return $2 === '-' ? '' : $2.toLowerCase()
+ })
+ var nestedProp = t.objectProperty(t.stringLiteral(suffix), prop.value)
+ var nestedObject = currentNestedObjects[prefix]
+ if (!nestedObject) {
+ nestedObject = currentNestedObjects[prefix] = t.objectProperty(
+ t.identifier(prefix),
+ t.objectExpression([nestedProp])
+ )
+ newProps.push(nestedObject)
+ } else {
+ nestedObject.value.properties.push(nestedProp)
+ }
+ } else if (dirRE.test(name)) {
+ // custom directive
+ name = name.replace(dirRE, '')
+ var dirs = currentNestedObjects.directives
+ if (!dirs) {
+ dirs = currentNestedObjects.directives = t.objectProperty(
+ t.identifier('directives'),
+ t.arrayExpression([])
+ )
+ newProps.push(dirs)
+ }
+ dirs.value.elements.push(t.objectExpression([
+ t.objectProperty(
+ t.identifier('name'),
+ t.stringLiteral(name)
+ ),
+ t.objectProperty(
+ t.identifier('value'),
+ prop.value
+ )
+ ]))
+ } else {
+ // rest are nested under attrs
+ var attrs = currentNestedObjects.attrs
+ // guard xlink attributes
+ if (xlinkRE.test(prop.key.name)) {
+ prop.key.name = JSON.stringify(prop.key.name.replace(xlinkRE, function (m, p1) {
+ return 'xlink:' + p1.toLowerCase()
+ }))
+ }
+ if (!attrs) {
+ attrs = currentNestedObjects.attrs = t.objectProperty(
+ t.identifier('attrs'),
+ t.objectExpression([prop])
+ )
+ newProps.push(attrs)
+ } else {
+ attrs.value.properties.push(prop)
+ }
+ }
+ }
+ })
+ return t.objectExpression(newProps)
+}
diff --git a/node_modules/babel-plugin-transform-vue-jsx/lib/make-map.js b/node_modules/babel-plugin-transform-vue-jsx/lib/make-map.js
new file mode 100644
index 00000000..0665cf59
--- /dev/null
+++ b/node_modules/babel-plugin-transform-vue-jsx/lib/make-map.js
@@ -0,0 +1,8 @@
+module.exports = function makeMap (str) {
+ var map = Object.create(null)
+ var list = str.split(',')
+ for (var i = 0; i < list.length; i++) {
+ map[list[i]] = true
+ }
+ return val => map[val]
+}
diff --git a/node_modules/babel-plugin-transform-vue-jsx/lib/must-use-prop.js b/node_modules/babel-plugin-transform-vue-jsx/lib/must-use-prop.js
new file mode 100644
index 00000000..77369071
--- /dev/null
+++ b/node_modules/babel-plugin-transform-vue-jsx/lib/must-use-prop.js
@@ -0,0 +1,9 @@
+const acceptValue = ['input','textarea','option','select']
+module.exports = (tag, type, attr) => {
+ return (
+ (attr === 'value' && acceptValue.includes(tag)) && type !== 'button' ||
+ (attr === 'selected' && tag === 'option') ||
+ (attr === 'checked' && tag === 'input') ||
+ (attr === 'muted' && tag === 'video')
+ )
+}