chore: run updated prettier
This commit is contained in:
@@ -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()
|
||||
})
|
||||
@@ -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()
|
||||
})
|
||||
@@ -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()
|
||||
})
|
||||
@@ -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()
|
||||
})
|
||||
@@ -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()
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
@@ -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,
|
||||
@@ -417,8 +417,9 @@ 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
|
||||
@@ -426,13 +427,10 @@ describe('compiler: transform v-model', () => {
|
||||
})
|
||||
|
||||
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)
|
||||
})
|
||||
@@ -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"]`)
|
||||
})
|
||||
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
@@ -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
|
||||
@@ -328,7 +329,8 @@ export interface CallExpression extends Node {
|
||||
| JSChildNode
|
||||
| SSRCodegenNode
|
||||
| TemplateChildNode
|
||||
| TemplateChildNode[])[]
|
||||
| TemplateChildNode[]
|
||||
)[]
|
||||
}
|
||||
|
||||
export interface ObjectExpression extends Node {
|
||||
@@ -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]
|
||||
@@ -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,
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -41,8 +41,8 @@ export function getBaseTransformPreset(
|
||||
transformExpression
|
||||
]
|
||||
: __BROWSER__ && __DEV__
|
||||
? [transformExpression]
|
||||
: []),
|
||||
? [transformExpression]
|
||||
: []),
|
||||
transformSlotOutlet,
|
||||
transformElement,
|
||||
trackSlotScopes,
|
||||
@@ -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, {
|
||||
|
||||
@@ -774,9 +774,10 @@ 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 =
|
||||
@@ -784,8 +785,8 @@ function parseAttribute(
|
||||
(isPropShorthand || startsWith(name, ':')
|
||||
? 'bind'
|
||||
: startsWith(name, '@')
|
||||
? 'on'
|
||||
: 'slot')
|
||||
? 'on'
|
||||
: 'slot')
|
||||
let arg: ExpressionNode | undefined
|
||||
|
||||
if (match[2]) {
|
||||
|
||||
@@ -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`)
|
||||
|
||||
@@ -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,
|
||||
@@ -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>
|
||||
@@ -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
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -273,7 +273,7 @@ export function hasDynamicKeyVBind(node: ElementNode): boolean {
|
||||
p.type === NodeTypes.DIRECTIVE &&
|
||||
p.name === 'bind' &&
|
||||
(!p.arg || // v-bind="obj"
|
||||
p.arg.type !== NodeTypes.SIMPLE_EXPRESSION || // v-bind:[_ctx.foo]
|
||||
p.arg.type !== NodeTypes.SIMPLE_EXPRESSION || // v-bind:[_ctx.foo]
|
||||
!p.arg.isStatic) // v-bind:[foo]
|
||||
)
|
||||
}
|
||||
|
||||
@@ -18,7 +18,8 @@ const prohibitedKeywordRE = new RegExp(
|
||||
)
|
||||
|
||||
// strip strings in expressions
|
||||
const stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g
|
||||
const stripStringRE =
|
||||
/'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g
|
||||
|
||||
/**
|
||||
* Validate a non-prefixed expression.
|
||||
@@ -51,9 +52,7 @@ export function validateBrowserExpression(
|
||||
.replace(stripStringRE, '')
|
||||
.match(prohibitedKeywordRE)
|
||||
if (keywordMatch) {
|
||||
message = `avoid using JavaScript keyword as property name: "${
|
||||
keywordMatch[0]
|
||||
}"`
|
||||
message = `avoid using JavaScript keyword as property name: "${keywordMatch[0]}"`
|
||||
}
|
||||
context.onError(
|
||||
createCompilerError(
|
||||
|
||||
Reference in New Issue
Block a user