diff --git a/packages/compiler-core/__tests__/codegen.spec.ts b/packages/compiler-core/__tests__/codegen.spec.ts index 61908a91..b51ca132 100644 --- a/packages/compiler-core/__tests__/codegen.spec.ts +++ b/packages/compiler-core/__tests__/codegen.spec.ts @@ -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() diff --git a/packages/compiler-core/__tests__/parse.spec.ts b/packages/compiler-core/__tests__/parse.spec.ts index 84c3d538..dbc982b9 100644 --- a/packages/compiler-core/__tests__/parse.spec.ts +++ b/packages/compiler-core/__tests__/parse.spec.ts @@ -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( diff --git a/packages/compiler-core/__tests__/transforms/hoistStatic.spec.ts b/packages/compiler-core/__tests__/transforms/hoistStatic.spec.ts index 04363431..e21fe745 100644 --- a/packages/compiler-core/__tests__/transforms/hoistStatic.spec.ts +++ b/packages/compiler-core/__tests__/transforms/hoistStatic.spec.ts @@ -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, diff --git a/packages/compiler-core/__tests__/transforms/vFor.spec.ts b/packages/compiler-core/__tests__/transforms/vFor.spec.ts index 50d8d625..b677ca58 100644 --- a/packages/compiler-core/__tests__/transforms/vFor.spec.ts +++ b/packages/compiler-core/__tests__/transforms/vFor.spec.ts @@ -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, diff --git a/packages/compiler-core/__tests__/transforms/vModel.spec.ts b/packages/compiler-core/__tests__/transforms/vModel.spec.ts index fd611cdd..92051b76 100644 --- a/packages/compiler-core/__tests__/transforms/vModel.spec.ts +++ b/packages/compiler-core/__tests__/transforms/vModel.spec.ts @@ -290,8 +290,8 @@ describe('compiler: transform v-model', () => { test('with dynamic argument', () => { const root = parseWithVModel('') 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( - '
', - { - prefixIdentifiers: true, - cacheHandlers: true - } - ) + const root = parseWithVModel('
', { + 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"]`) }) diff --git a/packages/compiler-core/__tests__/transforms/vOn.spec.ts b/packages/compiler-core/__tests__/transforms/vOn.spec.ts index fe2f6be7..7a8fba9c 100644 --- a/packages/compiler-core/__tests__/transforms/vOn.spec.ts +++ b/packages/compiler-core/__tests__/transforms/vOn.spec.ts @@ -531,10 +531,13 @@ describe('compiler: transform v-on', () => { }) test('should not be cached inside v-once', () => { - const { root } = parseWithVOn(`
`, { - prefixIdentifiers: true, - cacheHandlers: true - }) + const { root } = parseWithVOn( + `
`, + { + prefixIdentifiers: true, + cacheHandlers: true + } + ) expect(root.cached).not.toBe(2) expect(root.cached).toBe(1) }) diff --git a/packages/compiler-core/src/ast.ts b/packages/compiler-core/src/ast.ts index 0694b422..58fa76ab 100644 --- a/packages/compiler-core/src/ast.ts +++ b/packages/compiler-core/src/ast.ts @@ -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, diff --git a/packages/compiler-core/src/codegen.ts b/packages/compiler-core/src/codegen.ts index f37e7295..56774e31 100644 --- a/packages/compiler-core/src/codegen.ts +++ b/packages/compiler-core/src/codegen.ts @@ -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] diff --git a/packages/compiler-core/src/compile.ts b/packages/compiler-core/src/compile.ts index fa2dcfbe..a3442fc8 100644 --- a/packages/compiler-core/src/compile.ts +++ b/packages/compiler-core/src/compile.ts @@ -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, { diff --git a/packages/compiler-core/src/parse.ts b/packages/compiler-core/src/parse.ts index 96aec726..d48f93c1 100644 --- a/packages/compiler-core/src/parse.ts +++ b/packages/compiler-core/src/parse.ts @@ -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]) { diff --git a/packages/compiler-core/src/transform.ts b/packages/compiler-core/src/transform.ts index 77164f90..29a04bc7 100644 --- a/packages/compiler-core/src/transform.ts +++ b/packages/compiler-core/src/transform.ts @@ -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`) diff --git a/packages/compiler-core/src/transforms/vFor.ts b/packages/compiler-core/src/transforms/vFor.ts index e4b02eaa..5d3049f0 100644 --- a/packages/compiler-core/src/transforms/vFor.ts +++ b/packages/compiler-core/src/transforms/vFor.ts @@ -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) { // or @@ -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) diff --git a/packages/compiler-core/src/transforms/vIf.ts b/packages/compiler-core/src/transforms/vIf.ts index 01810090..0c18597d 100644 --- a/packages/compiler-core/src/transforms/vIf.ts +++ b/packages/compiler-core/src/transforms/vIf.ts @@ -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 } diff --git a/packages/compiler-core/src/transforms/vSlot.ts b/packages/compiler-core/src/transforms/vSlot.ts index 1e784c82..68aa1f67 100644 --- a/packages/compiler-core/src/transforms/vSlot.ts +++ b/packages/compiler-core/src/transforms/vSlot.ts @@ -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( diff --git a/packages/compiler-core/src/utils.ts b/packages/compiler-core/src/utils.ts index b0237917..88e91d6c 100644 --- a/packages/compiler-core/src/utils.ts +++ b/packages/compiler-core/src/utils.ts @@ -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] ) } diff --git a/packages/compiler-core/src/validateExpression.ts b/packages/compiler-core/src/validateExpression.ts index 3ba98572..fce56773 100644 --- a/packages/compiler-core/src/validateExpression.ts +++ b/packages/compiler-core/src/validateExpression.ts @@ -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( diff --git a/packages/compiler-dom/__tests__/transforms/vOn.spec.ts b/packages/compiler-dom/__tests__/transforms/vOn.spec.ts index b148422b..efc7fee3 100644 --- a/packages/compiler-dom/__tests__/transforms/vOn.spec.ts +++ b/packages/compiler-dom/__tests__/transforms/vOn.spec.ts @@ -27,8 +27,10 @@ function parseWithVOn(template: string, options: CompilerOptions = {}) { }) return { root: ast, - props: (((ast.children[0] as ElementNode).codegenNode as VNodeCall) - .props as ObjectExpression).properties + props: ( + ((ast.children[0] as ElementNode).codegenNode as VNodeCall) + .props as ObjectExpression + ).properties } } diff --git a/packages/compiler-dom/src/transforms/vOn.ts b/packages/compiler-dom/src/transforms/vOn.ts index d2207b3f..660003b4 100644 --- a/packages/compiler-dom/src/transforms/vOn.ts +++ b/packages/compiler-dom/src/transforms/vOn.ts @@ -96,14 +96,14 @@ const transformClick = (key: ExpressionNode, event: string) => { return isStaticClick ? createSimpleExpression(event, true) : key.type !== NodeTypes.SIMPLE_EXPRESSION - ? createCompoundExpression([ - `(`, - key, - `) === "onClick" ? "${event}" : (`, - key, - `)` - ]) - : key + ? createCompoundExpression([ + `(`, + key, + `) === "onClick" ? "${event}" : (`, + key, + `)` + ]) + : key } export const transformOn: DirectiveTransform = (dir, node, context) => { @@ -112,11 +112,8 @@ export const transformOn: DirectiveTransform = (dir, node, context) => { if (!modifiers.length) return baseResult let { key, value: handlerExp } = baseResult.props[0] - const { - keyModifiers, - nonKeyModifiers, - eventOptionModifiers - } = resolveModifiers(key, modifiers, context, dir.loc) + const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = + resolveModifiers(key, modifiers, context, dir.loc) // normalize click.right and click.middle since they don't actually fire if (nonKeyModifiers.includes('right')) { diff --git a/packages/compiler-sfc/__tests__/templateTransformAssetUrl.spec.ts b/packages/compiler-sfc/__tests__/templateTransformAssetUrl.spec.ts index 6dbb7680..ba253583 100644 --- a/packages/compiler-sfc/__tests__/templateTransformAssetUrl.spec.ts +++ b/packages/compiler-sfc/__tests__/templateTransformAssetUrl.spec.ts @@ -59,8 +59,8 @@ describe('compiler sfc: transform asset url', () => { test('with explicit base', () => { const { code } = compileWithAssetUrls( `` + // -> /foo/bar.png - `` + // -> bar.png (untouched) - `` + // -> still converts to import + `` + // -> bar.png (untouched) + `` + // -> still converts to import ``, // -> still converts to import { base: '/foo' diff --git a/packages/compiler-sfc/src/compileScript.ts b/packages/compiler-sfc/src/compileScript.ts index 9999bcc7..432d977f 100644 --- a/packages/compiler-sfc/src/compileScript.ts +++ b/packages/compiler-sfc/src/compileScript.ts @@ -678,7 +678,9 @@ export function compileScript( .map(key => { let defaultString: string | undefined if (hasStaticDefaults) { - const prop = (propsRuntimeDefaults as ObjectExpression).properties.find( + const prop = ( + propsRuntimeDefaults as ObjectExpression + ).properties.find( (node: any) => node.key.name === key ) as ObjectProperty if (prop) { @@ -776,9 +778,7 @@ export function compileScript( // rewrite to `import { x as __default__ } from './x'` and // add to top s.prepend( - `import { ${ - defaultSpecifier.local.name - } as ${defaultTempVar} } from '${node.source.value}'\n` + `import { ${defaultSpecifier.local.name} as ${defaultTempVar} } from '${node.source.value}'\n` ) } else { // export { x as default } @@ -1376,11 +1376,11 @@ export function compileScript( ...scriptSetup, bindings: bindingMetadata, content: s.toString(), - map: (s.generateMap({ + map: s.generateMap({ source: filename, hires: true, includeContent: true - }) as unknown) as RawSourceMap, + }) as unknown as RawSourceMap, scriptAst, scriptSetupAst } @@ -1470,8 +1470,8 @@ function walkObjectPattern( const type = isDefineCall ? BindingTypes.SETUP_CONST : isConst - ? BindingTypes.SETUP_MAYBE_REF - : BindingTypes.SETUP_LET + ? BindingTypes.SETUP_MAYBE_REF + : BindingTypes.SETUP_LET registerBinding(bindings, p.key, type) } else { walkPattern(p.value, bindings, isConst, isDefineCall) @@ -1507,8 +1507,8 @@ function walkPattern( const type = isDefineCall ? BindingTypes.SETUP_CONST : isConst - ? BindingTypes.SETUP_MAYBE_REF - : BindingTypes.SETUP_LET + ? BindingTypes.SETUP_MAYBE_REF + : BindingTypes.SETUP_LET registerBinding(bindings, node, type) } else if (node.type === 'RestElement') { // argument can only be identifer when destructuring @@ -1523,8 +1523,8 @@ function walkPattern( const type = isDefineCall ? BindingTypes.SETUP_CONST : isConst - ? BindingTypes.SETUP_MAYBE_REF - : BindingTypes.SETUP_LET + ? BindingTypes.SETUP_MAYBE_REF + : BindingTypes.SETUP_LET registerBinding(bindings, node.left, type) } else { walkPattern(node.left, bindings, isConst) @@ -1651,9 +1651,9 @@ function inferRuntimeType( case 'TSUnionType': return [ ...new Set( - [].concat(node.types.map(t => - inferRuntimeType(t, declaredTypes) - ) as any) + [].concat( + node.types.map(t => inferRuntimeType(t, declaredTypes)) as any + ) ) ] case 'TSIntersectionType': @@ -1668,8 +1668,8 @@ function toRuntimeTypeString(types: string[]) { return types.some(t => t === 'null') ? `null` : types.length > 1 - ? `[${types.join(', ')}]` - : types[0] + ? `[${types.join(', ')}]` + : types[0] } function extractRuntimeEmits( diff --git a/packages/compiler-sfc/src/compileStyle.ts b/packages/compiler-sfc/src/compileStyle.ts index 7da2713c..4a87a2b0 100644 --- a/packages/compiler-sfc/src/compileStyle.ts +++ b/packages/compiler-sfc/src/compileStyle.ts @@ -79,9 +79,10 @@ export function compileStyle( export function compileStyleAsync( options: SFCAsyncStyleCompileOptions ): Promise { - return doCompileStyle({ ...options, isAsync: true }) as Promise< - SFCStyleCompileResults - > + return doCompileStyle({ + ...options, + isAsync: true + }) as Promise } export function doCompileStyle( diff --git a/packages/compiler-sfc/src/compileTemplate.ts b/packages/compiler-sfc/src/compileTemplate.ts index 9fa099a3..b980cc3c 100644 --- a/packages/compiler-sfc/src/compileTemplate.ts +++ b/packages/compiler-sfc/src/compileTemplate.ts @@ -140,14 +140,10 @@ export function compileTemplate( code: `export default function render() {}`, source: options.source, tips: [ - `Component ${ - options.filename - } uses lang ${preprocessLang} for template. Please install the language preprocessor.` + `Component ${options.filename} uses lang ${preprocessLang} for template. Please install the language preprocessor.` ], errors: [ - `Component ${ - options.filename - } uses lang ${preprocessLang} for template, however it is not installed.` + `Component ${options.filename} uses lang ${preprocessLang} for template, however it is not installed.` ] } } else { diff --git a/packages/compiler-sfc/src/cssVars.ts b/packages/compiler-sfc/src/cssVars.ts index 884742f2..853db99f 100644 --- a/packages/compiler-sfc/src/cssVars.ts +++ b/packages/compiler-sfc/src/cssVars.ts @@ -12,7 +12,8 @@ import { PluginCreator } from 'postcss' import hash from 'hash-sum' export const CSS_VARS_HELPER = `useCssVars` -export const cssVarRE = /\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([^'"][^)]*))\s*\)/g +export const cssVarRE = + /\bv-bind\(\s*(?:'([^']+)'|"([^"]+)"|([^'"][^)]*))\s*\)/g export function genCssVarsFromList( vars: string[], diff --git a/packages/compiler-sfc/src/rewriteDefault.ts b/packages/compiler-sfc/src/rewriteDefault.ts index 44a7d41a..f4b2f2e8 100644 --- a/packages/compiler-sfc/src/rewriteDefault.ts +++ b/packages/compiler-sfc/src/rewriteDefault.ts @@ -3,7 +3,8 @@ import MagicString from 'magic-string' const defaultExportRE = /((?:^|\n|;)\s*)export(\s*)default/ const namedDefaultExportRE = /((?:^|\n|;)\s*)export(.+)as(\s*)default/s -const exportDefaultClassRE = /((?:^|\n|;)\s*)export\s+default\s+class\s+([\w$]+)/ +const exportDefaultClassRE = + /((?:^|\n|;)\s*)export\s+default\s+class\s+([\w$]+)/ /** * Utility for rewriting `export default` in a script block into a variable diff --git a/packages/compiler-ssr/__tests__/ssrElement.spec.ts b/packages/compiler-ssr/__tests__/ssrElement.spec.ts index 796fd41f..d77b607a 100644 --- a/packages/compiler-ssr/__tests__/ssrElement.spec.ts +++ b/packages/compiler-ssr/__tests__/ssrElement.spec.ts @@ -71,9 +71,10 @@ describe('ssr: element', () => { `) }) - test("multiple _ssrInterpolate at parent and child import dependency once", () => { - expect( compile(`
{{ hello }}
`).code) - .toMatchInlineSnapshot(` + test('multiple _ssrInterpolate at parent and child import dependency once', () => { + expect( + compile(`
{{ hello }}
`).code + ).toMatchInlineSnapshot(` "const { ssrRenderAttrs: _ssrRenderAttrs, ssrInterpolate: _ssrInterpolate } = require(\\"@vue/server-renderer\\") return function ssrRender(_ctx, _push, _parent, _attrs) { @@ -89,8 +90,8 @@ describe('ssr: element', () => { _ssrInterpolate((\\"value\\" in _temp0) ? _temp0.value : \\"\\") }
\`) }" - `); - }); + `) + }) test('should pass tag to custom elements w/ dynamic v-bind', () => { expect( diff --git a/packages/compiler-ssr/src/ssrCodegenTransform.ts b/packages/compiler-ssr/src/ssrCodegenTransform.ts index 7f53ee62..c30b90aa 100644 --- a/packages/compiler-ssr/src/ssrCodegenTransform.ts +++ b/packages/compiler-ssr/src/ssrCodegenTransform.ts @@ -56,11 +56,10 @@ export function ssrCodegenTransform(ast: RootNode, options: CompilerOptions) { // Finalize helpers. // We need to separate helpers imported from 'vue' vs. '@vue/server-renderer' - ast.ssrHelpers = Array.from(new Set([ - ...ast.helpers.filter(h => h in ssrHelpers), - ...context.helpers - ])) - + ast.ssrHelpers = Array.from( + new Set([...ast.helpers.filter(h => h in ssrHelpers), ...context.helpers]) + ) + ast.helpers = ast.helpers.filter(h => !(h in ssrHelpers)) } diff --git a/packages/compiler-ssr/src/transforms/ssrTransformComponent.ts b/packages/compiler-ssr/src/transforms/ssrTransformComponent.ts index ecc1379b..ccbca9fd 100644 --- a/packages/compiler-ssr/src/transforms/ssrTransformComponent.ts +++ b/packages/compiler-ssr/src/transforms/ssrTransformComponent.ts @@ -225,9 +225,8 @@ export function ssrProcessComponent( export const rawOptionsMap = new WeakMap() -const [baseNodeTransforms, baseDirectiveTransforms] = getBaseTransformPreset( - true -) +const [baseNodeTransforms, baseDirectiveTransforms] = + getBaseTransformPreset(true) const vnodeNodeTransforms = [...baseNodeTransforms, ...DOMNodeTransforms] const vnodeDirectiveTransforms = { ...baseDirectiveTransforms, diff --git a/packages/global.d.ts b/packages/global.d.ts index 72ab2fe9..9b7e3795 100644 --- a/packages/global.d.ts +++ b/packages/global.d.ts @@ -24,9 +24,7 @@ declare namespace jest { } } -declare module '*.vue' { - -} +declare module '*.vue' {} declare module '*?raw' { const content: string export default content diff --git a/packages/reactivity/__tests__/collections/Set.spec.ts b/packages/reactivity/__tests__/collections/Set.spec.ts index b5936c07..5bd5f246 100644 --- a/packages/reactivity/__tests__/collections/Set.spec.ts +++ b/packages/reactivity/__tests__/collections/Set.spec.ts @@ -422,7 +422,7 @@ describe('reactivity/collections', () => { const proxy = reactive(raw) const thisArg = {} let count = 0 - proxy.forEach(function(this: {}, value, _, set) { + proxy.forEach(function (this: {}, value, _, set) { ++count expect(this).toBe(thisArg) expect(value).toBe('value') diff --git a/packages/reactivity/__tests__/readonly.spec.ts b/packages/reactivity/__tests__/readonly.spec.ts index c8bf65b3..63426bb5 100644 --- a/packages/reactivity/__tests__/readonly.spec.ts +++ b/packages/reactivity/__tests__/readonly.spec.ts @@ -178,7 +178,10 @@ describe('reactivity/readonly', () => { test('should make nested values readonly', () => { const key1 = {} const key2 = {} - const original = new Collection([[key1, {}], [key2, {}]]) + const original = new Collection([ + [key1, {}], + [key2, {}] + ]) const wrapped = readonly(original) expect(wrapped).not.toBe(original) expect(isProxy(wrapped)).toBe(true) @@ -228,7 +231,10 @@ describe('reactivity/readonly', () => { test('should retrieve readonly values on iteration', () => { const key1 = {} const key2 = {} - const original = new Map([[key1, {}], [key2, {}]]) + const original = new Map([ + [key1, {}], + [key2, {}] + ]) const wrapped: any = readonly(original) expect(wrapped.size).toBe(2) for (const [key, value] of wrapped) { @@ -246,7 +252,12 @@ describe('reactivity/readonly', () => { test('should retrieve reactive + readonly values on iteration', () => { const key1 = {} const key2 = {} - const original = reactive(new Map([[key1, {}], [key2, {}]])) + const original = reactive( + new Map([ + [key1, {}], + [key2, {}] + ]) + ) const wrapped: any = readonly(original) expect(wrapped.size).toBe(2) for (const [key, value] of wrapped) { diff --git a/packages/reactivity/src/baseHandlers.ts b/packages/reactivity/src/baseHandlers.ts index 8ce7f756..29367007 100644 --- a/packages/reactivity/src/baseHandlers.ts +++ b/packages/reactivity/src/baseHandlers.ts @@ -49,7 +49,7 @@ function createArrayInstrumentations() { // instrument identity-sensitive Array methods to account for possible reactive // values ;(['includes', 'indexOf', 'lastIndexOf'] as const).forEach(key => { - instrumentations[key] = function(this: unknown[], ...args: unknown[]) { + instrumentations[key] = function (this: unknown[], ...args: unknown[]) { const arr = toRaw(this) as any for (let i = 0, l = this.length; i < l; i++) { track(arr, TrackOpTypes.GET, i + '') @@ -67,7 +67,7 @@ function createArrayInstrumentations() { // instrument length-altering mutation methods to avoid length being tracked // which leads to infinite loops in some cases (#2137) ;(['push', 'pop', 'shift', 'unshift', 'splice'] as const).forEach(key => { - instrumentations[key] = function(this: unknown[], ...args: unknown[]) { + instrumentations[key] = function (this: unknown[], ...args: unknown[]) { pauseTracking() const res = (toRaw(this) as any)[key].apply(this, args) resetTracking() @@ -91,8 +91,8 @@ function createGetter(isReadonly = false, shallow = false) { ? shallowReadonlyMap : readonlyMap : shallow - ? shallowReactiveMap - : reactiveMap + ? shallowReactiveMap + : reactiveMap ).get(target) ) { return target diff --git a/packages/reactivity/src/collectionHandlers.ts b/packages/reactivity/src/collectionHandlers.ts index 0d62ba57..fe79ad9e 100644 --- a/packages/reactivity/src/collectionHandlers.ts +++ b/packages/reactivity/src/collectionHandlers.ts @@ -184,7 +184,7 @@ function createIterableMethod( isReadonly: boolean, isShallow: boolean ) { - return function( + return function ( this: IterableCollections, ...args: unknown[] ): Iterable & Iterator { @@ -224,7 +224,7 @@ function createIterableMethod( } function createReadonlyMethod(type: TriggerOpTypes): Function { - return function(this: CollectionTypes, ...args: unknown[]) { + return function (this: CollectionTypes, ...args: unknown[]) { if (__DEV__) { const key = args[0] ? `on key "${args[0]}" ` : `` console.warn( @@ -242,7 +242,7 @@ function createInstrumentations() { return get(this, key) }, get size() { - return size((this as unknown) as IterableCollections) + return size(this as unknown as IterableCollections) }, has, add, @@ -257,7 +257,7 @@ function createInstrumentations() { return get(this, key, false, true) }, get size() { - return size((this as unknown) as IterableCollections) + return size(this as unknown as IterableCollections) }, has, add, @@ -272,7 +272,7 @@ function createInstrumentations() { return get(this, key, true) }, get size() { - return size((this as unknown) as IterableCollections, true) + return size(this as unknown as IterableCollections, true) }, has(this: MapTypes, key: unknown) { return has.call(this, key, true) @@ -289,7 +289,7 @@ function createInstrumentations() { return get(this, key, true, true) }, get size() { - return size((this as unknown) as IterableCollections, true) + return size(this as unknown as IterableCollections, true) }, has(this: MapTypes, key: unknown) { return has.call(this, key, true) @@ -346,8 +346,8 @@ function createInstrumentationGetter(isReadonly: boolean, shallow: boolean) { ? shallowReadonlyInstrumentations : shallowInstrumentations : isReadonly - ? readonlyInstrumentations - : mutableInstrumentations + ? readonlyInstrumentations + : mutableInstrumentations return ( target: CollectionTypes, @@ -384,11 +384,10 @@ export const readonlyCollectionHandlers: ProxyHandler = { get: /*#__PURE__*/ createInstrumentationGetter(true, false) } -export const shallowReadonlyCollectionHandlers: ProxyHandler< - CollectionTypes -> = { - get: /*#__PURE__*/ createInstrumentationGetter(true, true) -} +export const shallowReadonlyCollectionHandlers: ProxyHandler = + { + get: /*#__PURE__*/ createInstrumentationGetter(true, true) + } function checkIdentityKeys( target: CollectionTypes, diff --git a/packages/reactivity/src/computed.ts b/packages/reactivity/src/computed.ts index fdc5c58f..dec3a833 100644 --- a/packages/reactivity/src/computed.ts +++ b/packages/reactivity/src/computed.ts @@ -37,7 +37,7 @@ class ComputedRefImpl { private _dirty = true public readonly effect: ReactiveEffect - public readonly __v_isRef = true; + public readonly __v_isRef = true public readonly [ReactiveFlags.IS_READONLY]: boolean constructor( diff --git a/packages/reactivity/src/reactive.ts b/packages/reactivity/src/reactive.ts index 2137e7cf..148a583c 100644 --- a/packages/reactivity/src/reactive.ts +++ b/packages/reactivity/src/reactive.ts @@ -119,22 +119,22 @@ type Builtin = Primitive | Function | Date | Error | RegExp export type DeepReadonly = T extends Builtin ? T : T extends Map - ? ReadonlyMap, DeepReadonly> - : T extends ReadonlyMap - ? ReadonlyMap, DeepReadonly> - : T extends WeakMap - ? WeakMap, DeepReadonly> - : T extends Set - ? ReadonlySet> - : T extends ReadonlySet - ? ReadonlySet> - : T extends WeakSet - ? WeakSet> - : T extends Promise - ? Promise> - : T extends {} - ? { readonly [K in keyof T]: DeepReadonly } - : Readonly + ? ReadonlyMap, DeepReadonly> + : T extends ReadonlyMap + ? ReadonlyMap, DeepReadonly> + : T extends WeakMap + ? WeakMap, DeepReadonly> + : T extends Set + ? ReadonlySet> + : T extends ReadonlySet + ? ReadonlySet> + : T extends WeakSet + ? WeakSet> + : T extends Promise + ? Promise> + : T extends {} + ? { readonly [K in keyof T]: DeepReadonly } + : Readonly /** * Creates a readonly copy of the original object. Note the returned copy is not diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index 5648bb26..010fb8d8 100644 --- a/packages/reactivity/src/ref.ts +++ b/packages/reactivity/src/ref.ts @@ -259,8 +259,10 @@ export type ShallowUnwrapRef = { [K in keyof T]: T[K] extends Ref ? V : T[K] extends Ref | undefined // if `V` is `unknown` that means it does not extend `Ref` and is undefined - ? unknown extends V ? undefined : V | undefined - : T[K] + ? unknown extends V + ? undefined + : V | undefined + : T[K] } export type UnwrapRef = T extends Ref @@ -275,8 +277,10 @@ type UnwrapRefSimple = T extends | RefUnwrapBailTypes[keyof RefUnwrapBailTypes] ? T : T extends Array - ? { [K in keyof T]: UnwrapRefSimple } - : T extends object ? UnwrappedObject : T + ? { [K in keyof T]: UnwrapRefSimple } + : T extends object + ? UnwrappedObject + : T // Extract all known symbols from an object // when unwrapping Object the symbols are not `in keyof`, this should cover all the diff --git a/packages/runtime-core/__tests__/apiSetupHelpers.spec.ts b/packages/runtime-core/__tests__/apiSetupHelpers.spec.ts index 3dc22e67..1f2852d5 100644 --- a/packages/runtime-core/__tests__/apiSetupHelpers.spec.ts +++ b/packages/runtime-core/__tests__/apiSetupHelpers.spec.ts @@ -123,15 +123,16 @@ describe('SFC