Skip to content

Commit 085d188

Browse files
liximomoyyx990803
authored andcommittedApr 25, 2019
fix(compiler): Remove the warning for valid v-slot value (#9917)
1 parent 861aea1 commit 085d188

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed
 

‎src/compiler/error-detector.js

+15
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ function checkNode (node: ASTNode, warn: Function) {
3636
const range = node.rawAttrsMap[name]
3737
if (name === 'v-for') {
3838
checkFor(node, `v-for="${value}"`, warn, range)
39+
} else if (name === 'v-slot' || name[0] === '#') {
40+
checkFunctionParameterExpression(value, `${name}="${value}"`, warn, range)
3941
} else if (onRE.test(name)) {
4042
checkEvent(value, `${name}="${value}"`, warn, range)
4143
} else {
@@ -111,3 +113,16 @@ function checkExpression (exp: string, text: string, warn: Function, range?: Ran
111113
}
112114
}
113115
}
116+
117+
function checkFunctionParameterExpression (exp: string, text: string, warn: Function, range?: Range) {
118+
try {
119+
new Function(exp, '')
120+
} catch (e) {
121+
warn(
122+
`invalid function parameter expression: ${e.message} in\n\n` +
123+
` ${exp}\n\n` +
124+
` Raw expression: ${text.trim()}\n`,
125+
range
126+
)
127+
}
128+
}

‎src/compiler/parser/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import {
2323

2424
export const onRE = /^@|^v-on:/
2525
export const dirRE = process.env.VBIND_PROP_SHORTHAND
26-
? /^v-|^@|^:|^\./
27-
: /^v-|^@|^:/
26+
? /^v-|^@|^:|^\.|^#/
27+
: /^v-|^@|^:|^#/
2828
export const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/
2929
export const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/
3030
const stripParensRE = /^\(|\)$/g

‎test/unit/features/component/component-scoped-slot.spec.js

+16
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,22 @@ describe('Component scoped slot', () => {
759759
}).$mount()
760760
expect(`Unexpected mixed usage of different slot syntaxes`).toHaveBeenWarned()
761761
})
762+
763+
it('should warn invalid parameter expression', () => {
764+
new Vue({
765+
template: `<foo ${syntax}="1"></foo>`,
766+
components: { Foo }
767+
}).$mount();
768+
expect('invalid function parameter expression').toHaveBeenWarned()
769+
})
770+
771+
it('should allow destructuring props with default value', () => {
772+
new Vue({
773+
template: `<foo ${syntax}="{ foo = { bar: '1' } }"></foo>`,
774+
components: { Foo }
775+
}).$mount();
776+
expect('invalid function parameter expression').not.toHaveBeenWarned()
777+
})
762778
}
763779

764780
// run tests for both full syntax and shorthand

0 commit comments

Comments
 (0)
Please sign in to comment.