Skip to content

Commit

Permalink
chore: run updated prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jul 19, 2021
1 parent 69344ff commit 47f4883
Show file tree
Hide file tree
Showing 110 changed files with 695 additions and 698 deletions.
48 changes: 10 additions & 38 deletions packages/compiler-core/__tests__/codegen.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ describe('compiler: codegen', () => {
})
const { code } = generate(root, { mode: 'module' })
expect(code).toMatch(
`import { ${helperNameMap[CREATE_VNODE]} as _${
helperNameMap[CREATE_VNODE]
}, ${helperNameMap[RESOLVE_DIRECTIVE]} as _${
helperNameMap[RESOLVE_DIRECTIVE]
} } from "vue"`
`import { ${helperNameMap[CREATE_VNODE]} as _${helperNameMap[CREATE_VNODE]}, ${helperNameMap[RESOLVE_DIRECTIVE]} as _${helperNameMap[RESOLVE_DIRECTIVE]} } from "vue"`
)
expect(code).toMatchSnapshot()
})
Expand All @@ -76,16 +72,10 @@ describe('compiler: codegen', () => {
})
const { code } = generate(root, { mode: 'module', optimizeImports: true })
expect(code).toMatch(
`import { ${helperNameMap[CREATE_VNODE]}, ${
helperNameMap[RESOLVE_DIRECTIVE]
} } from "vue"`
`import { ${helperNameMap[CREATE_VNODE]}, ${helperNameMap[RESOLVE_DIRECTIVE]} } from "vue"`
)
expect(code).toMatch(
`const _${helperNameMap[CREATE_VNODE]} = ${
helperNameMap[CREATE_VNODE]
}, _${helperNameMap[RESOLVE_DIRECTIVE]} = ${
helperNameMap[RESOLVE_DIRECTIVE]
}`
`const _${helperNameMap[CREATE_VNODE]} = ${helperNameMap[CREATE_VNODE]}, _${helperNameMap[RESOLVE_DIRECTIVE]} = ${helperNameMap[RESOLVE_DIRECTIVE]}`
)
expect(code).toMatchSnapshot()
})
Expand All @@ -97,11 +87,7 @@ describe('compiler: codegen', () => {
const { code } = generate(root, { mode: 'function' })
expect(code).toMatch(`const _Vue = Vue`)
expect(code).toMatch(
`const { ${helperNameMap[CREATE_VNODE]}: _${
helperNameMap[CREATE_VNODE]
}, ${helperNameMap[RESOLVE_DIRECTIVE]}: _${
helperNameMap[RESOLVE_DIRECTIVE]
} } = _Vue`
`const { ${helperNameMap[CREATE_VNODE]}: _${helperNameMap[CREATE_VNODE]}, ${helperNameMap[RESOLVE_DIRECTIVE]}: _${helperNameMap[RESOLVE_DIRECTIVE]} } = _Vue`
)
expect(code).toMatchSnapshot()
})
Expand All @@ -116,11 +102,7 @@ describe('compiler: codegen', () => {
})
expect(code).not.toMatch(`const _Vue = Vue`)
expect(code).toMatch(
`const { ${helperNameMap[CREATE_VNODE]}: _${
helperNameMap[CREATE_VNODE]
}, ${helperNameMap[RESOLVE_DIRECTIVE]}: _${
helperNameMap[RESOLVE_DIRECTIVE]
} } = Vue`
`const { ${helperNameMap[CREATE_VNODE]}: _${helperNameMap[CREATE_VNODE]}, ${helperNameMap[RESOLVE_DIRECTIVE]}: _${helperNameMap[RESOLVE_DIRECTIVE]} } = Vue`
)
expect(code).toMatchSnapshot()
})
Expand All @@ -136,30 +118,20 @@ describe('compiler: codegen', () => {
`const _component_Foo = _${helperNameMap[RESOLVE_COMPONENT]}("Foo")\n`
)
expect(code).toMatch(
`const _component_bar_baz = _${
helperNameMap[RESOLVE_COMPONENT]
}("bar-baz")\n`
`const _component_bar_baz = _${helperNameMap[RESOLVE_COMPONENT]}("bar-baz")\n`
)
expect(code).toMatch(
`const _component_barbaz = _${
helperNameMap[RESOLVE_COMPONENT]
}("barbaz")\n`
`const _component_barbaz = _${helperNameMap[RESOLVE_COMPONENT]}("barbaz")\n`
)
// implicit self reference from SFC filename
expect(code).toMatch(
`const _component_Qux = _${
helperNameMap[RESOLVE_COMPONENT]
}("Qux", true)\n`
`const _component_Qux = _${helperNameMap[RESOLVE_COMPONENT]}("Qux", true)\n`
)
expect(code).toMatch(
`const _directive_my_dir_0 = _${
helperNameMap[RESOLVE_DIRECTIVE]
}("my_dir_0")\n`
`const _directive_my_dir_0 = _${helperNameMap[RESOLVE_DIRECTIVE]}("my_dir_0")\n`
)
expect(code).toMatch(
`const _directive_my_dir_1 = _${
helperNameMap[RESOLVE_DIRECTIVE]
}("my_dir_1")\n`
`const _directive_my_dir_1 = _${helperNameMap[RESOLVE_DIRECTIVE]}("my_dir_1")\n`
)
expect(code).toMatch(`let _temp0, _temp1, _temp2`)
expect(code).toMatchSnapshot()
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-core/__tests__/parse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2871,7 +2871,7 @@ foo
]
}

for (const key of Object.keys(patterns) as (keyof (typeof patterns))[]) {
for (const key of Object.keys(patterns) as (keyof typeof patterns)[]) {
describe(key, () => {
for (const { code, errors, options } of patterns[key]) {
test(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,9 @@ describe('compiler: hoistStatic transform', () => {
},
hoistedChildrenArrayMatcher(2)
])
const forBlockCodegen = ((root.children[0] as ElementNode)
.children[0] as ForNode).codegenNode
const forBlockCodegen = (
(root.children[0] as ElementNode).children[0] as ForNode
).codegenNode
expect(forBlockCodegen).toMatchObject({
type: NodeTypes.VNODE_CALL,
tag: FRAGMENT,
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-core/__tests__/transforms/vFor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,8 @@ describe('compiler: v-for', () => {
patchFlag: !disableTracking
? genFlagText(PatchFlags.STABLE_FRAGMENT)
: keyed
? genFlagText(PatchFlags.KEYED_FRAGMENT)
: genFlagText(PatchFlags.UNKEYED_FRAGMENT),
? genFlagText(PatchFlags.KEYED_FRAGMENT)
: genFlagText(PatchFlags.UNKEYED_FRAGMENT),
children: {
type: NodeTypes.JS_CALL_EXPRESSION,
callee: RENDER_LIST,
Expand Down
29 changes: 14 additions & 15 deletions packages/compiler-core/__tests__/transforms/vModel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ describe('compiler: transform v-model', () => {
test('with dynamic argument', () => {
const root = parseWithVModel('<input v-model:[value]="model" />')
const node = root.children[0] as ElementNode
const props = ((node.codegenNode as VNodeCall)
.props as unknown) as CallExpression
const props = (node.codegenNode as VNodeCall)
.props as unknown as CallExpression

expect(props).toMatchObject({
type: NodeTypes.JS_CALL_EXPRESSION,
Expand Down Expand Up @@ -344,8 +344,8 @@ describe('compiler: transform v-model', () => {
prefixIdentifiers: true
})
const node = root.children[0] as ElementNode
const props = ((node.codegenNode as VNodeCall)
.props as unknown) as CallExpression
const props = (node.codegenNode as VNodeCall)
.props as unknown as CallExpression

expect(props).toMatchObject({
type: NodeTypes.JS_CALL_EXPRESSION,
Expand Down Expand Up @@ -417,22 +417,20 @@ describe('compiler: transform v-model', () => {
}
)
expect(root.cached).toBe(0)
const codegen = ((root.children[0] as ForNode)
.children[0] as PlainElementNode).codegenNode as VNodeCall
const codegen = (
(root.children[0] as ForNode).children[0] as PlainElementNode
).codegenNode as VNodeCall
expect(codegen.dynamicProps).toBe(`["modelValue", "onUpdate:modelValue"]`)
expect(
(codegen.props as ObjectExpression).properties[1].value.type
).not.toBe(NodeTypes.JS_CACHE_EXPRESSION)
})

test('should not cache update handler if it inside v-once', () => {
const root = parseWithVModel(
'<div v-once><input v-model="foo" /></div>',
{
prefixIdentifiers: true,
cacheHandlers: true
}
)
const root = parseWithVModel('<div v-once><input v-model="foo" /></div>', {
prefixIdentifiers: true,
cacheHandlers: true
})
expect(root.cached).not.toBe(2)
expect(root.cached).toBe(1)
})
Expand All @@ -444,8 +442,9 @@ describe('compiler: transform v-model', () => {
prefixIdentifiers: true
}
)
const codegen = ((root.children[0] as ComponentNode)
.children[0] as PlainElementNode).codegenNode as VNodeCall
const codegen = (
(root.children[0] as ComponentNode).children[0] as PlainElementNode
).codegenNode as VNodeCall
expect(codegen.dynamicProps).toBe(`["modelValue", "onUpdate:modelValue"]`)
})

Expand Down
11 changes: 7 additions & 4 deletions packages/compiler-core/__tests__/transforms/vOn.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,13 @@ describe('compiler: transform v-on', () => {
})

test('should not be cached inside v-once', () => {
const { root } = parseWithVOn(`<div v-once><div v-on:click="foo"/></div>`, {
prefixIdentifiers: true,
cacheHandlers: true
})
const { root } = parseWithVOn(
`<div v-once><div v-on:click="foo"/></div>`,
{
prefixIdentifiers: true,
cacheHandlers: true
}
)
expect(root.cached).not.toBe(2)
expect(root.cached).toBe(1)
})
Expand Down
14 changes: 8 additions & 6 deletions packages/compiler-core/src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ export interface CompoundExpressionNode extends Node {
| InterpolationNode
| TextNode
| string
| symbol)[]
| symbol
)[]

/**
* an expression parsed as the params of a function will track
Expand Down Expand Up @@ -328,7 +329,8 @@ export interface CallExpression extends Node {
| JSChildNode
| SSRCodegenNode
| TemplateChildNode
| TemplateChildNode[])[]
| TemplateChildNode[]
)[]
}

export interface ObjectExpression extends Node {
Expand Down Expand Up @@ -439,8 +441,8 @@ export interface DirectiveArguments extends ArrayExpression {
}

export interface DirectiveArgumentNode extends ArrayExpression {
elements: // dir, exp, arg, modifiers
| [string]
elements: // dir, exp, arg, modifiers
| [string]
| [string, ExpressionNode]
| [string, ExpressionNode, ExpressionNode]
| [string, ExpressionNode, ExpressionNode, ObjectExpression]
Expand All @@ -449,8 +451,8 @@ export interface DirectiveArgumentNode extends ArrayExpression {
// renderSlot(...)
export interface RenderSlotCall extends CallExpression {
callee: typeof RENDER_SLOT
arguments: // $slots, name, props, fallback
| [string, string | ExpressionNode]
arguments: // $slots, name, props, fallback
| [string, string | ExpressionNode]
| [string, string | ExpressionNode, PropsExpression]
| [
string,
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-core/src/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,8 @@ function genAssets(
__COMPAT__ && type === 'filter'
? RESOLVE_FILTER
: type === 'component'
? RESOLVE_COMPONENT
: RESOLVE_DIRECTIVE
? RESOLVE_COMPONENT
: RESOLVE_DIRECTIVE
)
for (let i = 0; i < assets.length; i++) {
let id = assets[i]
Expand Down
9 changes: 4 additions & 5 deletions packages/compiler-core/src/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export function getBaseTransformPreset(
transformExpression
]
: __BROWSER__ && __DEV__
? [transformExpression]
: []),
? [transformExpression]
: []),
transformSlotOutlet,
transformElement,
trackSlotScopes,
Expand Down Expand Up @@ -83,9 +83,8 @@ export function baseCompile(
}

const ast = isString(template) ? baseParse(template, options) : template
const [nodeTransforms, directiveTransforms] = getBaseTransformPreset(
prefixIdentifiers
)
const [nodeTransforms, directiveTransforms] =
getBaseTransformPreset(prefixIdentifiers)
transform(
ast,
extend({}, options, {
Expand Down
11 changes: 6 additions & 5 deletions packages/compiler-core/src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -774,18 +774,19 @@ function parseAttribute(
const loc = getSelection(context, start)

if (!context.inVPre && /^(v-|:|\.|@|#)/.test(name)) {
const match = /(?:^v-([a-z0-9-]+))?(?:(?::|^\.|^@|^#)(\[[^\]]+\]|[^\.]+))?(.+)?$/i.exec(
name
)!
const match =
/(?:^v-([a-z0-9-]+))?(?:(?::|^\.|^@|^#)(\[[^\]]+\]|[^\.]+))?(.+)?$/i.exec(
name
)!

let isPropShorthand = startsWith(name, '.')
let dirName =
match[1] ||
(isPropShorthand || startsWith(name, ':')
? 'bind'
: startsWith(name, '@')
? 'on'
: 'slot')
? 'on'
: 'slot')
let arg: ExpressionNode | undefined

if (match[2]) {
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-core/src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ export function createTransformContext(
const removalIndex = node
? list.indexOf(node)
: context.currentNode
? context.childIndex
: -1
? context.childIndex
: -1
/* istanbul ignore if */
if (__DEV__ && removalIndex < 0) {
throw new Error(`node being removed is not a child of current parent`)
Expand Down
24 changes: 12 additions & 12 deletions packages/compiler-core/src/transforms/vFor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ export const transformFor = createStructuralDirectiveTransform(
const fragmentFlag = isStableFragment
? PatchFlags.STABLE_FRAGMENT
: keyProp
? PatchFlags.KEYED_FRAGMENT
: PatchFlags.UNKEYED_FRAGMENT
? PatchFlags.KEYED_FRAGMENT
: PatchFlags.UNKEYED_FRAGMENT

forNode.codegenNode = createVNodeCall(
context,
Expand Down Expand Up @@ -135,8 +135,8 @@ export const transformFor = createStructuralDirectiveTransform(
: isTemplate &&
node.children.length === 1 &&
isSlotOutlet(node.children[0])
? (node.children[0] as SlotOutletNode) // api-extractor somehow fails to infer this
: null
? (node.children[0] as SlotOutletNode) // api-extractor somehow fails to infer this
: null

if (slotOutlet) {
// <slot v-for="..."> or <template v-for="..."><slot/></template>
Expand Down Expand Up @@ -221,11 +221,13 @@ export const transformFor = createStructuralDirectiveTransform(
createSimpleExpression(String(context.cached++))
)
} else {
renderExp.arguments.push(createFunctionExpression(
createForLoopParams(forNode.parseResult),
childBlock,
true /* force newline */
) as ForIteratorExpression)
renderExp.arguments.push(
createFunctionExpression(
createForLoopParams(forNode.parseResult),
childBlock,
true /* force newline */
) as ForIteratorExpression
)
}
}
})
Expand Down Expand Up @@ -343,9 +345,7 @@ export function parseForExpression(
validateBrowserExpression(result.source as SimpleExpressionNode, context)
}

let valueContent = LHS.trim()
.replace(stripParensRE, '')
.trim()
let valueContent = LHS.trim().replace(stripParensRE, '').trim()
const trimmedOffset = LHS.indexOf(valueContent)

const iteratorMatch = valueContent.match(forIteratorRE)
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-core/src/transforms/vIf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ function isSameKey(
}
if (
exp.type !== NodeTypes.SIMPLE_EXPRESSION ||
(exp.isStatic !== (branchExp as SimpleExpressionNode).isStatic ||
exp.content !== (branchExp as SimpleExpressionNode).content)
exp.isStatic !== (branchExp as SimpleExpressionNode).isStatic ||
exp.content !== (branchExp as SimpleExpressionNode).content
) {
return false
}
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-core/src/transforms/vSlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ export function buildSlots(
const slotFlag = hasDynamicSlots
? SlotFlags.DYNAMIC
: hasForwardedSlots(node.children)
? SlotFlags.FORWARDED
: SlotFlags.STABLE
? SlotFlags.FORWARDED
: SlotFlags.STABLE

let slots = createObjectExpression(
slotsProperties.concat(
Expand Down
Loading

0 comments on commit 47f4883

Please sign in to comment.