Skip to content

Commit adc4f53

Browse files
author
Alan Wang
authored
Fix issue vuejs#25: jscodeshift failed to parse some file (vuejs#32)
* fix: closes vuejs#25, jscodeshift failed to parse some files with special syntax * chore: format code with prettier
1 parent a820620 commit adc4f53

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

bin/vue-codemod.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ function processTransformation(
136136
debug(`Processing ${p}…`)
137137
const fileInfo = {
138138
path: p,
139-
source: fs.readFileSync(p).toString().split('\r\n').join('\n'),
139+
source: fs.readFileSync(p).toString().split('\r\n').join('\n')
140140
}
141141
const extension = (/\.([^.]*)$/.exec(fileInfo.path) || [])[0]
142142
if (!extensions.includes(extension)) {

src/wrapAstTransformation.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,16 @@ export default function astTransformationToJSCodeshiftModule<Params = any>(
1515
): Transform {
1616
const transform: Transform = (file, api, options: Params) => {
1717
const j = api.jscodeshift
18-
const root = j(file.source)
18+
let root
19+
try {
20+
root = j(file.source)
21+
} catch (err) {
22+
console.error(
23+
`JSCodeshift failed to parse ${file.path},` +
24+
` please check whether the syntax is valid`
25+
)
26+
return
27+
}
1928

2029
transformAST({ root, j, filename: file.path }, options)
2130

transformations/v-model.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const transformAST: ASTTransformation = ({ j, root }) => {
4242
// remove model option
4343
modelCollection.remove()
4444

45-
if(!valueNodePath.length) return
45+
if (!valueNodePath.length) return
4646

4747
// replace the value with modelValue
4848
// @ts-ignore

vue-transformations/remove-v-on-native.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function fix(node: Node, source: string): Operation[] {
6060
modifiers.forEach((mod: any) => {
6161
if (mod?.name === 'native') {
6262
const comment =
63-
'<!-- native modifier has been removed, please confirm whether the function has been affected -->'
63+
'<!-- native modifier has been removed, please confirm whether the function has been affected -->'
6464
const vStartTag = mod.parent.parent.parent
6565
const vElement = vStartTag.parent
6666
const siblings = vElement.parent.children

0 commit comments

Comments
 (0)