Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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:master
base:master
Choose a base branch
Loading
fromoriginjs:master
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions.github/workflows/ci.yml
View file
Open in desktop
Original file line numberDiff line numberDiff 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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
import { createApp } from 'vue';
import App from './App.vue';

createApp(App).mount('#app');
const app = createApp(App);
app.mount('#app');
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
import { createApp, h } from 'vue';
import App from './App.vue';

createApp({
const app =createApp({
myOption: 'hello!',
render: () => h(App),
}).mount('#app');
});

app.mount('#app');
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
import Vue from 'vue';

Vue.nextTick(() => {
console.log('foo');
})
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
import { nextTick } from 'vue';

nextTick(() => {
console.log('foo');
})
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,4 +2,5 @@ import { createApp } from 'vue';
import App from './App.vue';
import router from './router';

createApp(App).use(router).mount('#app');
const app = createApp(App).use(router);
app.mount('#app');
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@ import App from './App.vue';
import store from './store';
import anotherStore from './another-store';

createApp(App).use(store).mount('#app');

createApp(App).use(anotherStore).mount('#app');
const app = createApp({}).use(h => h(App));
app.mount('#app');
const app = createApp({}).use(h => h(App));
app.mount('#app');
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,3 +8,4 @@ defineTest(__dirname, 'index', null, 'custom-root-prop')
defineTest(__dirname, 'index', null, 'vue-router')
defineTest(__dirname, 'index', null, 'vuex')
defineTest(__dirname, 'index', null, 'vue-use')
defineTest(__dirname, 'index', null, 'next-tick')
52 changes: 35 additions & 17 deletionsgenerator/codemods/global-api/create-app-mount.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,13 +7,21 @@ module.exports = function createAppMount(context) {
const { j, root } = context

// new Vue(...).$mount()
const mountCalls = root.find(j.CallExpression, n => {
return (
n.callee.type === 'MemberExpression' &&
n.callee.property.name === '$mount' &&
n.callee.object.type === 'NewExpression' &&
n.callee.object.callee.name === 'Vue'
)
const mountCalls = root.find(j.ExpressionStatement, {
expression: {
type: 'CallExpression',
callee: {
type: 'MemberExpression',
object: {
type: 'NewExpression',
callee: {
type: 'Identifier',
name: 'Vue'
}
},
property: { type: 'Identifier', name: '$mount' }
}
}
})

if (!mountCalls.length) {
Expand All@@ -23,16 +31,26 @@ module.exports = function createAppMount(context) {
const addImport = require('../utils/add-import')
addImport(context, { imported: 'createApp' }, 'vue')

mountCalls.replaceWith(({ node }) => {
let rootProps = node.callee.object.arguments[0]
const el = node.arguments[0]
const rootProps = mountCalls.at(0).get().node.expression.callee.object
.arguments
mountCalls.insertBefore(
j.variableDeclaration('const', [
j.variableDeclarator(
j.identifier('app'),
j.callExpression(j.identifier('createApp'), rootProps)
)
])
)

return j.callExpression(
j.memberExpression(
j.callExpression(j.identifier('createApp'), [rootProps]),
j.identifier('mount')
),
[el]
const args = mountCalls.at(0).get().node.expression.arguments
mountCalls.insertBefore(
j.expressionStatement(
j.callExpression(
j.memberExpression(j.identifier('app'), j.identifier('mount'), false),
args
)
)
})
)

mountCalls.remove()
}
75 changes: 75 additions & 0 deletionsgenerator/codemods/global-api/global-filter.js
View file
Open in desktop
Original file line numberDiff line numberDiff 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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,6 +11,10 @@ module.exports = function(fileInfo, api) {
require('./remove-production-tip')(context)
require('./remove-vue-use')(context)
require('./remove-contextual-h')(context)
require('./next-tick')(context)
require('./observable')(context)
require('./version')(context)
require('./global-filter')(context)

// remove extraneous imports
const removeExtraneousImport = require('../utils/remove-extraneous-import')
Expand Down
30 changes: 30 additions & 0 deletionsgenerator/codemods/global-api/next-tick.js
View file
Open in desktop
Original file line numberDiff line numberDiff 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
View file
Open in desktop
Original file line numberDiff line numberDiff 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
View file
Open in desktop
Original file line numberDiff line numberDiff 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
View file
Open in desktop
Original file line numberDiff line numberDiff 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')
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
export default {
props: ['text'],
methods: {
input: function(){
this.$emit('increment');
this.$emit('decrement');
}
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
export default {
emits: ["increment", "decrement"],
props: ['text'],

methods: {
input: function(){
this.$emit('increment');
this.$emit('decrement');
}
}
};
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
export default {
destroyed: function () {
console.log('foo')
},
beforeDestroy: function () {
console.log('bar')
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
export default {
unmounted: function () {
console.log('foo')
},
beforeUnmount: function () {
console.log('bar')
}
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp