Skip to content

Commit 9a1bb46

Browse files
committed
refactor: rename rootOption to rootProp, to be in line with the type definition in vue-next
1 parent 6719d0c commit 9a1bb46

File tree

8 files changed

+14
-14
lines changed

8 files changed

+14
-14
lines changed

generator/codemods/global-api/__tests__/global-api-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ jest.autoMockOff()
33
const { defineTest } = require('jscodeshift/dist/testUtils')
44

55
defineTest(__dirname, 'index', null, 'basic')
6-
defineTest(__dirname, 'index', null, 'custom-root-option')
6+
defineTest(__dirname, 'index', null, 'custom-root-prop')
77
// defineTest(__dirname, 'index', null, 'el')
88
defineTest(__dirname, 'index', null, 'vue-router')
99
defineTest(__dirname, 'index', null, 'vuex')

generator/codemods/global-api/create-app-mount.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ module.exports = function createAppMount(context) {
2424
addImport(context, { imported: 'createApp' }, 'vue')
2525

2626
mountCalls.replaceWith(({ node }) => {
27-
let options = node.callee.object.arguments[0]
27+
let rootProps = node.callee.object.arguments[0]
2828
const el = node.arguments[0]
2929

3030
return j.callExpression(
3131
j.memberExpression(
32-
j.callExpression(j.identifier('createApp'), [options]),
32+
j.callExpression(j.identifier('createApp'), [rootProps]),
3333
j.identifier('mount')
3434
),
3535
[el]

generator/codemods/global-api/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ module.exports = function(fileInfo, api) {
55
const context = { j, root }
66

77
require('./create-app-mount')(context)
8-
require('./root-option-to-use')(context, 'store')
9-
require('./root-option-to-use')(context, 'router')
8+
require('./root-prop-to-use')(context, 'store')
9+
require('./root-prop-to-use')(context, 'router')
1010
require('./remove-trivial-root')(context)
1111
require('./remove-production-tip')(context)
1212
require('./remove-vue-use')(context)

generator/codemods/global-api/remove-trivial-root.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* It is expected to be run after the `createApp` transformataion
3-
* if a root component is trivial, that is, it contains only one simple option,
3+
* if a root component is trivial, that is, it contains only one simple prop,
44
* like `{ render: h => h(App) }`, then just use the `App` variable
55
*
66
* TODO: implement `remove-trivial-render`,

generator/codemods/global-api/remove-vue-use.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* But in library implementations like `vue-router` and `vuex`,
55
* the new `app.use` does not reuse the same argument passed to `Vue.use()`,
66
* but expects instantiated instances that are used to pass to the root components instead.
7-
* So we now expect the migration to be done in the `root-option-to-use` transformation,
7+
* So we now expect the migration to be done in the `root-prop-to-use` transformation,
88
* and the `Vue.use` statements can be just abandoned.
99
* @param {Object} context
1010
* @param {import('jscodeshift').JSCodeshift} context.j

generator/codemods/global-api/root-option-to-use.js renamed to generator/codemods/global-api/root-prop-to-use.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,30 @@
55
* @param {import('jscodeshift').JSCodeshift} context.j
66
* @param {ReturnType<import('jscodeshift').Core>} context.root
77
*/
8-
module.exports = function rootOptionToUse(context, rootOptionName) {
8+
module.exports = function rootPropToUse(context, rootPropName) {
99
const { j, root } = context
1010

1111
const appRoots = root.find(j.CallExpression, {
1212
callee: { name: 'createApp' },
1313
arguments: args =>
1414
args.length === 1 &&
1515
args[0].type === 'ObjectExpression' &&
16-
args[0].properties.find(p => p.key.name === rootOptionName)
16+
args[0].properties.find(p => p.key.name === rootPropName)
1717
})
1818

1919
appRoots.replaceWith(({ node: createAppCall }) => {
20-
const rootOptions = createAppCall.arguments[0]
21-
const propertyIndex = rootOptions.properties.findIndex(
22-
p => p.key.name === rootOptionName
20+
const rootProps = createAppCall.arguments[0]
21+
const propertyIndex = rootProps.properties.findIndex(
22+
p => p.key.name === rootPropName
2323
)
24-
const [{ value: pluginInstance }] = rootOptions.properties.splice(
24+
const [{ value: pluginInstance }] = rootProps.properties.splice(
2525
propertyIndex,
2626
1
2727
)
2828

2929
return j.callExpression(
3030
j.memberExpression(
31-
j.callExpression(j.identifier('createApp'), [rootOptions]),
31+
j.callExpression(j.identifier('createApp'), [rootProps]),
3232
j.identifier('use')
3333
),
3434
[pluginInstance]

0 commit comments

Comments
 (0)