Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(parser): fixed dynamicArgAttribute RegExp #9785

Merged
merged 3 commits into from Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/parser/html-parser.js
Expand Up @@ -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}`)
Expand Down
20 changes: 20 additions & 0 deletions test/unit/modules/compiler/parser.spec.js
Expand Up @@ -569,6 +569,26 @@ describe('parser', () => {
})
})

// #9781
it('multiple dynamic slot names without warning', () => {
const ast = parse(`<my-component>
<template #[foo]>foo</template>
<template #[data]="scope">scope</template>
<template #[bar]>bar</template>
</my-component>`, baseOptions)

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)
Expand Down