Skip to content

Commit 3e116ef

Browse files
committed
Merge branch 'dev' of https://hub.fastgit.org/originjs/vue-codemod into dev
2 parents ca26401 + ae63ea2 commit 3e116ef

16 files changed

+217
-4
lines changed

bin/vue-codemod.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import * as globby from 'globby'
1010
import createDebug from 'debug'
1111

1212
import builtInTransformations from '../transformations'
13+
import { excludedTransformations } from "../transformations"
1314
import vueTransformations from '../vue-transformations'
1415
import runTransformation from '../src/runTransformation'
1516

@@ -67,7 +68,9 @@ async function main() {
6768

6869
if (runAllTransformation) {
6970
for (let key in builtInTransformations) {
70-
processTransformation(resolvedPaths, key, builtInTransformations[key])
71+
if (!excludedTransformations.includes(key)) {
72+
processTransformation(resolvedPaths, key, builtInTransformations[key])
73+
}
7174
}
7275

7376
for (let key in vueTransformations) {

transformations/add-emit-declaration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const transformAST: ASTTransformation = ({ root, j }) => {
3939

4040
if(!hasEmitsProperty){
4141
// no emits property then create emits:[...] AST
42-
defaultExportBody.get(0).node.declaration.properties.unshift(j.objectProperty(j.identifier('emits'),j.arrayExpression(elements)));
42+
defaultExportBody.get(0).node.declaration.properties?.unshift(j.objectProperty(j.identifier('emits'),j.arrayExpression(elements)));
4343
}
4444
}
4545
}

transformations/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,17 @@ const transformationMap: {
3737
'remove-extraneous-import': require('./remove-extraneous-import'),
3838
}
3939

40+
export const excludedTransformations = [
41+
'define-component',
42+
'new-vue-to-create-app',
43+
'remove-contextual-h-from-render',
44+
'remove-production-tip',
45+
'remove-trivial-root',
46+
'remove-vue-use',
47+
'root-prop-to-use',
48+
'vue-as-namespace-import',
49+
'add-import',
50+
'remove-extraneous-import'
51+
]
52+
4053
export default transformationMap

transformations/remove-vue-use.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const transformAST: ASTTransformation<Params> = (
3636
const removableUseCalls = vueUseCalls.filter(({ node }) => {
3737
if (j.Identifier.check(node.arguments[0])) {
3838
const plugin = node.arguments[0].name
39-
if (removablePlugins.includes(plugin)) {
39+
if (removablePlugins?.includes(plugin)) {
4040
removedPlugins.push(plugin)
4141
return true
4242
}

transformations/render-to-resolveComponent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const transformAST: ASTTransformation = (context) => {
1111
&& node.params.length === 1
1212
})
1313
.filter(nodePath => nodePath.parent.parent.node.type === 'ExportDefaultDeclaration')
14-
if (!renderCollections) return
14+
if (!renderCollections.length) return
1515

1616
// add import
1717
addImport(context, {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { runTest } from '../../src/testUtils'
2+
3+
runTest(
4+
'Fix v-bind Merge Behavior',
5+
'v-bind-order-sensitive',
6+
'v-bind-object',
7+
'vue',
8+
'vue'
9+
)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { runTest } from '../../src/testUtils'
2+
3+
runTest(
4+
'Fix the precedence problem of v-for and v-if before vue 2.6',
5+
'v-for-v-if-precedence-changed',
6+
'v-for-if-with-key',
7+
'vue',
8+
'vue'
9+
)
10+
11+
runTest(
12+
'Fix the precedence problem of v-for and v-if before vue 2.6',
13+
'v-for-v-if-precedence-changed',
14+
'v-for-if-without-key',
15+
'vue',
16+
'vue'
17+
)
18+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<div id='red' v-bind="{id:'blue'}"></div>
3+
</template>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<div v-bind="{id:'blue'}" id='red' ></div>
3+
</template>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<template>
2+
<ul>
3+
<li
4+
v-for='user in users'
5+
v-if='user.isActive'
6+
:key='user.id'
7+
>
8+
{{user.name}}
9+
</li>
10+
</ul>
11+
</template>

0 commit comments

Comments
 (0)