- Notifications
You must be signed in to change notification settings - Fork24
Apply more rules#45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
ygj6 wants to merge10 commits intovuejs:masterChoose a base branch fromoriginjs:master
base:master
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Open
Changes fromall commits
Commits
Show all changes
10 commits Select commitHold shift + click to select a range
a433902
feat: add emits declaration
ygj65fff976
add deep option for watch
ygj6c237c50
feet: remove event native; add transition from
ygj6da31b58
feat: implement tree-shaking api
ygj6448f2f7
feat: rename deprecated lifecycle
ygj6267d977
split app mount expression
ygj649af33f
feat: adapt global filters
ygj68b10312
test: fix global-api tests
wangsongc1b87065
ci: add github action
ygj6d97e07e
test: add testcase
ygj6File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
27 changes: 27 additions & 0 deletions.github/workflows/ci.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: CI | ||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [10.x, 12.x, 14.x, 15.x] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Run test | ||
run: | | ||
npm install | ||
npm test |
3 changes: 2 additions & 1 deletiongenerator/codemods/global-api/__testfixtures__/basic.output.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { createApp } from 'vue'; | ||
import App from './App.vue'; | ||
const app = createApp(App); | ||
app.mount('#app'); |
6 changes: 4 additions & 2 deletionsgenerator/codemods/global-api/__testfixtures__/custom-root-prop.output.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import { createApp, h } from 'vue'; | ||
import App from './App.vue'; | ||
const app =createApp({ | ||
myOption: 'hello!', | ||
render: () => h(App), | ||
}); | ||
app.mount('#app'); |
5 changes: 5 additions & 0 deletionsgenerator/codemods/global-api/__testfixtures__/next-tick.input.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Vue from 'vue'; | ||
Vue.nextTick(() => { | ||
console.log('foo'); | ||
}) |
5 changes: 5 additions & 0 deletionsgenerator/codemods/global-api/__testfixtures__/next-tick.output.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { nextTick } from 'vue'; | ||
nextTick(() => { | ||
console.log('foo'); | ||
}) |
3 changes: 2 additions & 1 deletiongenerator/codemods/global-api/__testfixtures__/vue-router.output.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
7 changes: 4 additions & 3 deletionsgenerator/codemods/global-api/__testfixtures__/vuex.output.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletionsgenerator/codemods/global-api/__tests__/global-api-test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
52 changes: 35 additions & 17 deletionsgenerator/codemods/global-api/create-app-mount.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletionsgenerator/codemods/global-api/global-filter.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* @param {Object} context | ||
* @param {import('jscodeshift').JSCodeshift} context.j | ||
* @param {ReturnType<import('jscodeshift').Core>} context.root | ||
*/ | ||
module.exports = function createAppMount(context) { | ||
const { j, root } = context | ||
// find const appName = createApp(...) | ||
const appDeclare = root.find(j.VariableDeclarator, { | ||
id: { type: 'Identifier' }, | ||
init: { | ||
type: 'CallExpression', | ||
callee: { | ||
type: 'Identifier', | ||
name: 'createApp' | ||
} | ||
} | ||
}) | ||
if (!appDeclare.length) { | ||
return | ||
} | ||
const appName = appDeclare.at(0).get().node.id.name | ||
// Vue.filter('filterName', function(value) {}) => | ||
// app.config.globalProperties.$filters = { filterName(value) {} } | ||
const filters = root.find(j.ExpressionStatement, { | ||
expression: { | ||
type: 'CallExpression', | ||
callee: { | ||
type: 'MemberExpression', | ||
object: { type: 'Identifier', name: 'Vue' }, | ||
property: { type: 'Identifier', name: 'filter' } | ||
} | ||
} | ||
}) | ||
if (!filters.length) { | ||
return | ||
} | ||
const methods = [] | ||
for (let i = 0; i < filters.length; i++) { | ||
const filter = filters.at(i) | ||
const args = filter.get().node.expression.arguments | ||
methods.push( | ||
j.objectMethod( | ||
'method', | ||
j.identifier(args[0].value), | ||
args[1].params, | ||
args[1].body | ||
) | ||
) | ||
} | ||
filters | ||
.at(0) | ||
.insertBefore( | ||
j.expressionStatement( | ||
j.assignmentExpression( | ||
'=', | ||
j.memberExpression( | ||
j.identifier(appName), | ||
j.identifier('config.globalProperties.$filters'), | ||
false | ||
), | ||
j.objectExpression(methods) | ||
) | ||
) | ||
) | ||
for (let i = 0; i < filters.length; i++) { | ||
filters.at(i).remove() | ||
} | ||
} |
4 changes: 4 additions & 0 deletionsgenerator/codemods/global-api/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletionsgenerator/codemods/global-api/next-tick.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* @param {Object} context | ||
* @param {import('jscodeshift').JSCodeshift} context.j | ||
* @param {ReturnType<import('jscodeshift').Core>} context.root | ||
*/ | ||
module.exports = function createAppMount(context) { | ||
const { j, root } = context | ||
// Vue.nextTick(() => {}) | ||
const nextTickCalls = root.find(j.CallExpression, n => { | ||
return ( | ||
n.callee.type === 'MemberExpression' && | ||
n.callee.property.name === 'nextTick' && | ||
n.callee.object.name === 'Vue' | ||
) | ||
}) | ||
if (!nextTickCalls.length) { | ||
return | ||
} | ||
const addImport = require('../utils/add-import') | ||
addImport(context, { imported: 'nextTick' }, 'vue') | ||
nextTickCalls.replaceWith(({ node }) => { | ||
const el = node.arguments[0] | ||
return j.callExpression(j.identifier('nextTick'), [el]) | ||
}) | ||
} |
30 changes: 30 additions & 0 deletionsgenerator/codemods/global-api/observable.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* @param {Object} context | ||
* @param {import('jscodeshift').JSCodeshift} context.j | ||
* @param {ReturnType<import('jscodeshift').Core>} context.root | ||
*/ | ||
module.exports = function createAppMount(context) { | ||
const { j, root } = context | ||
// Vue.observable(state) | ||
const observableCalls = root.find(j.CallExpression, n => { | ||
return ( | ||
n.callee.type === 'MemberExpression' && | ||
n.callee.property.name === 'observable' && | ||
n.callee.object.name === 'Vue' | ||
) | ||
}) | ||
if (!observableCalls.length) { | ||
return | ||
} | ||
const addImport = require('../utils/add-import') | ||
addImport(context, { imported: 'reactive' }, 'vue') | ||
observableCalls.replaceWith(({ node }) => { | ||
const el = node.arguments[0] | ||
return j.callExpression(j.identifier('reactive'), [el]) | ||
}) | ||
} |
29 changes: 29 additions & 0 deletionsgenerator/codemods/global-api/version.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* @param {Object} context | ||
* @param {import('jscodeshift').JSCodeshift} context.j | ||
* @param {ReturnType<import('jscodeshift').Core>} context.root | ||
*/ | ||
module.exports = function createAppMount(context) { | ||
const { j, root } = context | ||
// Vue.version | ||
const versionCalls = root.find(j.MemberExpression, n => { | ||
return ( | ||
n.property.name === 'version' && | ||
n.object.name === 'Vue' | ||
) | ||
}) | ||
if (!versionCalls.length) { | ||
return | ||
} | ||
const addImport = require('../utils/add-import') | ||
addImport(context, { imported: 'version' }, 'vue') | ||
versionCalls.replaceWith(({ node }) => { | ||
const property = node.property.name | ||
return j.identifier(property) | ||
}) | ||
} |
28 changes: 28 additions & 0 deletionsgenerator/codemods/vue-addition/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module.exports = function(files, filename) { | ||
let content = files[filename] | ||
content = removeEventNative(content) | ||
content = addTransitionFrom(content) | ||
files[filename] = content | ||
} | ||
// template | ||
// v-on:event.native => v-on:event | ||
// @event.native => @event | ||
function removeEventNative(content) { | ||
const reg = new RegExp( | ||
'(?<=<template>[\\s\\S]*?\\s(?:v-on:|@)\\w+).native(?==[\\s\\S]*?</template>)', | ||
'g' | ||
) | ||
return content.replace(reg, '') | ||
} | ||
// style | ||
// .xxx-enter => .xxx-enter-from | ||
// .xxx-leave => .xxx-leave-from | ||
function addTransitionFrom(content) { | ||
const reg = new RegExp( | ||
'(?<=<style[\\s>][\\s\\S]*?\\s\\.[A-Za-z0-9_-]+-)(enter|leave)(?=[,{\\s][\\s\\S]*?</style>)', | ||
'g' | ||
) | ||
return content.replace(reg, '$1-from') | ||
} |
9 changes: 9 additions & 0 deletionsgenerator/codemods/vue/__testfixtures__/add-emit-declaration.input.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export default { | ||
props: ['text'], | ||
methods: { | ||
input: function(){ | ||
this.$emit('increment'); | ||
this.$emit('decrement'); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletionsgenerator/codemods/vue/__testfixtures__/add-emit-declaration.output.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export default { | ||
emits: ["increment", "decrement"], | ||
props: ['text'], | ||
methods: { | ||
input: function(){ | ||
this.$emit('increment'); | ||
this.$emit('decrement'); | ||
} | ||
} | ||
}; |
8 changes: 8 additions & 0 deletionsgenerator/codemods/vue/__testfixtures__/rename-lifecycle.input.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default { | ||
destroyed: function () { | ||
console.log('foo') | ||
}, | ||
beforeDestroy: function () { | ||
console.log('bar') | ||
} | ||
} |
8 changes: 8 additions & 0 deletionsgenerator/codemods/vue/__testfixtures__/rename-lifecycle.output.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default { | ||
unmounted: function () { | ||
console.log('foo') | ||
}, | ||
beforeUnmount: function () { | ||
console.log('bar') | ||
} | ||
} |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.