Browse Source
fix(parser): allow multiple slots with new syntax (#9785 )
* fix(#9781 ): non greedy `dynamicArgAttribute` RegExp
* test(parser): add test case for multiple dynamic slot names
* test: add test with value
Co-authored-by: Eduardo San Martin Morote <posva13@gmail.com>
dev
DSha
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
21 additions and
1 deletions
src/compiler/parser/html-parser.js
test/unit/modules/compiler/parser.spec.js
@ -15,7 +15,7 @@ import { unicodeRegExp } from 'core/util/lang'
// Regular Expressions for parsing tags and attributes
const attribute = /^\s*([^\s"'<>\/=]+)(?:\s*(=)\s*(?:"([^"]*)"+|'([^']*)'+|([^\s"'=<>`]+)))?/
const dynamicArgAttribute = /^\s*((?:v-[\w-]+:|@|:|#)\[[^=]+\][^\s"'<>\/=]*)(?:\s*(=)\s*(?:"([^"]*)"+|'([^']*)'+|([^\s"'=<>`]+)))?/
const dynamicArgAttribute = /^\s*((?:v-[\w-]+:|@|:|#)\[[^=]+? \][^\s"'<>\/=]*)(?:\s*(=)\s*(?:"([^"]*)"+|'([^']*)'+|([^\s"'=<>`]+)))?/
const ncname = ` [a-zA-Z_][ \\ - \\ .0-9_a-zA-Z ${ unicodeRegExp . source } ]* `
const qnameCapture = ` ((?: ${ ncname } \\ :)? ${ ncname } ) `
const startTagOpen = new RegExp ( ` ^< ${ qnameCapture } ` )
@ -569,6 +569,26 @@ describe('parser', () => {
} )
} )
// #9781
it ( 'multiple dynamic slot names without warning' , ( ) => {
const ast = parse ( ` <my-component>
< template # [ foo ] > foo < / t e m p l a t e >
< template # [ data ] = "scope" > scope < / t e m p l a t e >
< template # [ bar ] > bar < / t e m p l a t e >
< / m y - c o m p o n e n t > ` , b a s e O p t i o n s )
expect ( ` Invalid dynamic argument expression ` ) . not . toHaveBeenWarned ( )
expect ( ast . scopedSlots . foo ) . not . toBeUndefined ( )
expect ( ast . scopedSlots . data ) . not . toBeUndefined ( )
expect ( ast . scopedSlots . bar ) . not . toBeUndefined ( )
expect ( ast . scopedSlots . foo . type ) . toBe ( 1 )
expect ( ast . scopedSlots . data . type ) . toBe ( 1 )
expect ( ast . scopedSlots . bar . type ) . toBe ( 1 )
expect ( ast . scopedSlots . foo . attrsMap [ '#[foo]' ] ) . toBe ( '' )
expect ( ast . scopedSlots . bar . attrsMap [ '#[bar]' ] ) . toBe ( '' )
expect ( ast . scopedSlots . data . attrsMap [ '#[data]' ] ) . toBe ( 'scope' )
} )
// #6887
it ( 'special case static attribute that must be props' , ( ) => {
const ast = parse ( '<video muted></video>' , baseOptions )