test: improve coverage

This commit is contained in:
Evan You 2019-09-28 14:15:10 -04:00
parent 1c410205de
commit 798a9cbe9b
5 changed files with 134 additions and 1 deletions

View File

@ -7117,6 +7117,109 @@ Object {
} }
`; `;
exports[`compiler: parse Errors X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END <div v-foo:[sef fsef] /> 1`] = `
Object {
"children": Array [
Object {
"children": Array [],
"codegenNode": undefined,
"isSelfClosing": true,
"loc": Object {
"end": Object {
"column": 25,
"line": 1,
"offset": 24,
},
"source": "<div v-foo:[sef fsef] />",
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"ns": 0,
"props": Array [
Object {
"arg": Object {
"content": "se",
"isStatic": false,
"loc": Object {
"end": Object {
"column": 16,
"line": 1,
"offset": 15,
},
"source": "[sef",
"start": Object {
"column": 12,
"line": 1,
"offset": 11,
},
},
"type": 4,
},
"exp": undefined,
"loc": Object {
"end": Object {
"column": 16,
"line": 1,
"offset": 15,
},
"source": "v-foo:[sef",
"start": Object {
"column": 6,
"line": 1,
"offset": 5,
},
},
"modifiers": Array [],
"name": "foo",
"type": 7,
},
Object {
"loc": Object {
"end": Object {
"column": 22,
"line": 1,
"offset": 21,
},
"source": "fsef]",
"start": Object {
"column": 17,
"line": 1,
"offset": 16,
},
},
"name": "fsef]",
"type": 6,
"value": undefined,
},
],
"tag": "div",
"tagType": 0,
"type": 1,
},
],
"hoists": Array [],
"imports": Array [],
"loc": Object {
"end": Object {
"column": 25,
"line": 1,
"offset": 24,
},
"source": "<div v-foo:[sef fsef] />",
"start": Object {
"column": 1,
"line": 1,
"offset": 0,
},
},
"statements": Array [],
"type": 0,
}
`;
exports[`compiler: parse Errors X_MISSING_END_TAG <template><div> 1`] = ` exports[`compiler: parse Errors X_MISSING_END_TAG <template><div> 1`] = `
Object { Object {
"children": Array [ "children": Array [

View File

@ -2464,6 +2464,17 @@ foo
code: '{{}}', code: '{{}}',
errors: [] errors: []
} }
],
X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END: [
{
code: `<div v-foo:[sef fsef] />`,
errors: [
{
type: ErrorCodes.X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END,
loc: { offset: 15, line: 1, column: 16 }
}
]
}
] ]
} }

View File

@ -342,6 +342,24 @@ describe('compiler: expression transform', () => {
}) })
}) })
test('function params should not affect out of scope identifiers', () => {
const node = parseWithExpressionTransform(
`{{ { a: foo => foo, b: foo } }}`
) as InterpolationNode
expect(node.content).toMatchObject({
type: NodeTypes.COMPOUND_EXPRESSION,
children: [
`{ a: `,
{ content: `foo` },
` => `,
{ content: `foo` },
`, b: `,
{ content: `_ctx.foo` },
` }`
]
})
})
test('should prefix default value of function param destructuring', () => { test('should prefix default value of function param destructuring', () => {
const node = parseWithExpressionTransform( const node = parseWithExpressionTransform(
`{{ ({ foo = bar }) => foo + bar }}` `{{ ({ foo = bar }) => foo + bar }}`

View File

@ -374,8 +374,8 @@ function genNode(node: CodegenNode, context: CodegenContext) {
case NodeTypes.JS_SLOT_FUNCTION: case NodeTypes.JS_SLOT_FUNCTION:
genSlotFunction(node, context) genSlotFunction(node, context)
break break
/* istanbul ignore next */
default: default:
/* istanbul ignore if */
if (__DEV__) { if (__DEV__) {
assert(false, `unhandled codegen node type: ${(node as any).type}`) assert(false, `unhandled codegen node type: ${(node as any).type}`)
// make sure we exhaust all possible types // make sure we exhaust all possible types

View File

@ -22,6 +22,7 @@ export function baseCompile(
template: string | RootNode, template: string | RootNode,
options: CompilerOptions = {} options: CompilerOptions = {}
): CodegenResult { ): CodegenResult {
/* istanbul ignore if */
if (__BROWSER__) { if (__BROWSER__) {
const onError = options.onError || defaultOnError const onError = options.onError || defaultOnError
if (options.prefixIdentifiers === true) { if (options.prefixIdentifiers === true) {