Skip to content

Commit 1944c9e

Browse files
committed
chore: run yarn fix to format code
1 parent fc74010 commit 1944c9e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+787
-714
lines changed

src/VueTransformation.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
interface FileInfo {
22
/** The absolute path to the current file. */
3-
path: string;
3+
path: string
44
/** The source code of the current file. */
5-
source: string;
5+
source: string
66
}
77

88
interface Options {
9-
[option: string]: any;
9+
[option: string]: any
1010
}
1111

1212
export default interface VueTransformation {
13-
(file: FileInfo, options: Options): string | null | undefined | void;
13+
(file: FileInfo, options: Options): string | null | undefined | void
1414
type: string
1515
}

src/astUtils.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type {
99
Expression,
1010
ObjectExpression,
1111
FunctionExpression,
12-
ArrowFunctionExpression,
12+
ArrowFunctionExpression
1313
} from 'jscodeshift'
1414
import type { Context } from './wrapAstTransformation'
1515

@@ -42,8 +42,9 @@ export function getVueOptions(context: Context): Collection<VueOptionsType> {
4242
return null
4343
}
4444

45-
const declarationKind = declarator.closest(j.VariableDeclaration).nodes()[0]
46-
.kind
45+
const declarationKind = declarator
46+
.closest(j.VariableDeclaration)
47+
.nodes()[0].kind
4748

4849
if (declarationKind !== 'const') {
4950
// TODO: check reassignments (=, for in)
@@ -54,7 +55,7 @@ export function getVueOptions(context: Context): Collection<VueOptionsType> {
5455
}
5556

5657
function hasRenderOrTemplateProps(obj: ObjectExpression) {
57-
return obj.properties.some((prop) => {
58+
return obj.properties.some(prop => {
5859
// skip spread properties
5960
if (j.SpreadElement.check(prop) || j.SpreadProperty.check(prop)) {
6061
return false
@@ -124,7 +125,7 @@ export function getVueOptions(context: Context): Collection<VueOptionsType> {
124125

125126
return (
126127
returnStatements.length > 0 &&
127-
returnStatements.every((path) =>
128+
returnStatements.every(path =>
128129
!!path.node.argument ? isPromiseExpression(path.node.argument) : true
129130
)
130131
)
@@ -146,7 +147,7 @@ export function getVueOptions(context: Context): Collection<VueOptionsType> {
146147
comp: ASTNode | null,
147148
{
148149
mayBeAsyncComponent = false,
149-
shouldCheckProps = false,
150+
shouldCheckProps = false
150151
}: {
151152
mayBeAsyncComponent?: boolean
152153
shouldCheckProps?: boolean
@@ -172,13 +173,13 @@ export function getVueOptions(context: Context): Collection<VueOptionsType> {
172173
// export default {}
173174
const defaultObjectExport = root
174175
.find(j.ExportDefaultDeclaration)
175-
.map((path) => {
176+
.map(path => {
176177
const decl = path.node.declaration
177178

178179
if (
179180
isLikelyVueOptions(decl, {
180181
shouldCheckProps: !isInSFC,
181-
mayBeAsyncComponent: !isInSFC,
182+
mayBeAsyncComponent: !isInSFC
182183
})
183184
) {
184185
return wrapOptionsInPaths(decl)
@@ -188,7 +189,7 @@ export function getVueOptions(context: Context): Collection<VueOptionsType> {
188189
const init = getConstDeclarationInit(decl)
189190
return isLikelyVueOptions(init, {
190191
shouldCheckProps: !isInSFC,
191-
mayBeAsyncComponent: !isInSFC,
192+
mayBeAsyncComponent: !isInSFC
192193
})
193194
? wrapOptionsInPaths(init)
194195
: null
@@ -220,7 +221,7 @@ export function getVueOptions(context: Context): Collection<VueOptionsType> {
220221

221222
return false
222223
})
223-
.map((path) => {
224+
.map(path => {
224225
const arg = path.node.arguments[0]
225226
if (isLikelyVueOptions(arg)) {
226227
return wrapOptionsInPaths(arg)
@@ -242,10 +243,10 @@ export function getVueOptions(context: Context): Collection<VueOptionsType> {
242243
.find(j.NewExpression, {
243244
callee: {
244245
type: 'Identifier',
245-
name: 'Vue',
246-
},
246+
name: 'Vue'
247+
}
247248
})
248-
.map((path) => {
249+
.map(path => {
249250
const arg = path.node.arguments[0]
250251
if (isLikelyVueOptions(arg)) {
251252
return wrapOptionsInPaths(arg)
@@ -275,7 +276,7 @@ export function getVueOptions(context: Context): Collection<VueOptionsType> {
275276
node.callee.property.name === 'component'
276277
)
277278
})
278-
.map((path) => {
279+
.map(path => {
279280
if (path.node.arguments.length !== 2) {
280281
return null
281282
}
@@ -311,7 +312,7 @@ export function getVueOptions(context: Context): Collection<VueOptionsType> {
311312
}
312313

313314
const componentsProp = node.properties.find(
314-
(prop) =>
315+
prop =>
315316
j.ObjectProperty.check(prop) &&
316317
((j.Identifier.check(prop.key) && prop.key.name === 'components') ||
317318
(j.StringLiteral.check(prop.key) && prop.key.value === 'components'))
@@ -338,7 +339,7 @@ export function getVueOptions(context: Context): Collection<VueOptionsType> {
338339
}
339340

340341
const subComponentDefinitions = componentsObject.properties
341-
.map((prop) => {
342+
.map(prop => {
342343
if (j.ObjectProperty.check(prop)) {
343344
if (isLikelyVueOptions(prop.value, { mayBeAsyncComponent: true })) {
344345
return prop.value

src/operationUtils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export type Operation = {
1717
export function insertTextAt(index: number, text: string): Operation {
1818
return {
1919
range: [index, index],
20-
text,
20+
text
2121
}
2222
}
2323

@@ -101,7 +101,7 @@ export function replaceText(
101101
export function replaceTextRange(range: number[], text: string): Operation {
102102
return {
103103
range,
104-
text,
104+
text
105105
}
106106
}
107107

@@ -125,6 +125,6 @@ export function remove(nodeOrToken: Node | Token): Operation {
125125
export function removeRange(range: number[]): Operation {
126126
return {
127127
range,
128-
text: '',
128+
text: ''
129129
}
130130
}

src/runTransformation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type JSTransformationModule =
3030
type VueTransformationModule =
3131
| VueTransformation
3232
| {
33-
default: VueTransformation,
33+
default: VueTransformation
3434
}
3535

3636
export type TransformationModule =
@@ -138,7 +138,7 @@ export default function runTransformation(
138138
j,
139139
jscodeshift: j,
140140
stats: () => {},
141-
report: () => {},
141+
report: () => {}
142142
}
143143

144144
const out = transformation(fileInfo, api, params)

src/sfcUtils.ts

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
SourceLocation,
99
CompilerError,
1010
TextModes,
11-
BindingMetadata,
11+
BindingMetadata
1212
} from '@vue/compiler-core'
1313
import * as CompilerDom from '@vue/compiler-dom'
1414
import { RawSourceMap, SourceMapGenerator } from 'source-map'
@@ -44,13 +44,15 @@ export function stringify(sfcDescriptor: SFCDescriptor) {
4444
const { template, script, styles, customBlocks } = sfcDescriptor
4545

4646
return (
47-
([template, script, ...styles, ...customBlocks]
48-
// discard blocks that don't exist
49-
.filter((block) => block != null) as Array<NonNullable<SFCBlock>>)
47+
(
48+
[template, script, ...styles, ...customBlocks]
49+
// discard blocks that don't exist
50+
.filter(block => block != null) as Array<NonNullable<SFCBlock>>
51+
)
5052
// sort blocks by source position
5153
.sort((a, b) => a.loc.start.offset - b.loc.start.offset)
5254
// figure out exact source positions of blocks
53-
.map((block) => {
55+
.map(block => {
5456
const openTag = makeOpenTag(block)
5557
const closeTag = makeCloseTag(block)
5658

@@ -62,7 +64,7 @@ export function stringify(sfcDescriptor: SFCDescriptor) {
6264
endOfOpenTag: block.loc.start.offset,
6365

6466
startOfCloseTag: block.loc.end.offset,
65-
endOfCloseTag: block.loc.end.offset + closeTag.length,
67+
endOfCloseTag: block.loc.end.offset + closeTag.length
6668
})
6769
})
6870
// generate sfc source
@@ -94,7 +96,7 @@ function makeOpenTag(block: SFCBlock) {
9496

9597
source += Object.keys(block.attrs)
9698
.sort()
97-
.map((name) => {
99+
.map(name => {
98100
const value = block.attrs[name]
99101

100102
if (value === true) {
@@ -103,7 +105,7 @@ function makeOpenTag(block: SFCBlock) {
103105
return `${name}="${value}"`
104106
}
105107
})
106-
.map((attr) => ' ' + attr)
108+
.map(attr => ' ' + attr)
107109
.join('')
108110

109111
return source + '>'
@@ -187,7 +189,7 @@ export function parse(
187189
filename = 'anonymous.vue',
188190
sourceRoot = '',
189191
pad = false,
190-
compiler = CompilerDom,
192+
compiler = CompilerDom
191193
}: SFCParseOptions = {}
192194
): SFCParseResult {
193195
const sourceKey =
@@ -204,7 +206,7 @@ export function parse(
204206
script: null,
205207
scriptSetup: null,
206208
styles: [],
207-
customBlocks: [],
209+
customBlocks: []
208210
}
209211

210212
const errors: (CompilerError | SyntaxError)[] = []
@@ -221,7 +223,7 @@ export function parse(
221223
// <template lang="xxx"> should also be treated as raw text
222224
(tag === 'template' &&
223225
props.some(
224-
(p) =>
226+
p =>
225227
p.type === NodeTypes.ATTRIBUTE &&
226228
p.name === 'lang' &&
227229
p.value &&
@@ -233,12 +235,12 @@ export function parse(
233235
return TextModes.DATA
234236
}
235237
},
236-
onError: (e) => {
238+
onError: e => {
237239
errors.push(e)
238-
},
240+
}
239241
})
240242

241-
ast.children.forEach((node) => {
243+
ast.children.forEach(node => {
242244
if (node.type !== NodeTypes.ELEMENT) {
243245
return
244246
}
@@ -330,7 +332,7 @@ export function parse(
330332

331333
const result = {
332334
descriptor,
333-
errors,
335+
errors
334336
}
335337
sourceToSFC.set(sourceKey, result)
336338
return result
@@ -365,19 +367,19 @@ function createBlock(
365367
const loc = {
366368
source: content,
367369
start,
368-
end,
370+
end
369371
}
370372
const attrs: Record<string, string | true> = {}
371373
const block: SFCBlock = {
372374
type,
373375
content,
374376
loc,
375-
attrs,
377+
attrs
376378
}
377379
if (pad) {
378380
block.content = padContent(source, block, pad) + block.content
379381
}
380-
node.props.forEach((p) => {
382+
node.props.forEach(p => {
381383
if (p.type === NodeTypes.ATTRIBUTE) {
382384
attrs[p.name] = p.value ? p.value.content || true : true
383385
if (p.name === 'lang') {
@@ -411,7 +413,7 @@ function generateSourceMap(
411413
): RawSourceMap {
412414
const map = new SourceMapGenerator({
413415
file: filename.replace(/\\/g, '/'),
414-
sourceRoot: sourceRoot.replace(/\\/g, '/'),
416+
sourceRoot: sourceRoot.replace(/\\/g, '/')
415417
})
416418
map.setSourceContent(filename, source)
417419
generated.split(splitRE).forEach((line, index) => {
@@ -424,12 +426,12 @@ function generateSourceMap(
424426
source: filename,
425427
original: {
426428
line: originalLine,
427-
column: i,
429+
column: i
428430
},
429431
generated: {
430432
line: generatedLine,
431-
column: i,
432-
},
433+
column: i
434+
}
433435
})
434436
}
435437
}
@@ -454,7 +456,7 @@ function padContent(
454456
}
455457

456458
function hasSrc(node: ElementNode) {
457-
return node.props.some((p) => {
459+
return node.props.some(p => {
458460
if (p.type !== NodeTypes.ATTRIBUTE) {
459461
return false
460462
}

src/testUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const runTest = (
3232

3333
const fileInfo = {
3434
path: inputPath,
35-
source: fs.readFileSync(inputPath).toString(),
35+
source: fs.readFileSync(inputPath).toString()
3636
}
3737
const transformation = require((transformationType == 'vue'
3838
? '../vue-transformations'

0 commit comments

Comments
 (0)