@nest-vue/vue-security-patched 2.7.16-patch.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +122 -0
- package/compiler-sfc/index.d.ts +1 -0
- package/compiler-sfc/index.js +1 -0
- package/compiler-sfc/index.mjs +1 -0
- package/compiler-sfc/package.json +5 -0
- package/dist/vue.common.js +5 -0
- package/dist/vue.runtime.common.js +5 -0
- package/dist/vue.runtime.mjs +76 -0
- package/package.json +136 -0
- package/packages/compiler-sfc/api-extractor.json +64 -0
- package/packages/compiler-sfc/dist/compiler-sfc.js +17146 -0
- package/packages/compiler-sfc/node_modules/.bin/lessc +17 -0
- package/packages/compiler-sfc/node_modules/.bin/parser +17 -0
- package/packages/compiler-sfc/node_modules/.bin/prettier +17 -0
- package/packages/compiler-sfc/node_modules/.bin/sass +17 -0
- package/packages/compiler-sfc/node_modules/.bin/stylus +17 -0
- package/packages/compiler-sfc/package.json +37 -0
- package/packages/compiler-sfc/src/babelUtils.ts +423 -0
- package/packages/compiler-sfc/src/compileScript.ts +1916 -0
- package/packages/compiler-sfc/src/compileStyle.ts +147 -0
- package/packages/compiler-sfc/src/compileTemplate.ts +205 -0
- package/packages/compiler-sfc/src/cssVars.ts +179 -0
- package/packages/compiler-sfc/src/index.ts +31 -0
- package/packages/compiler-sfc/src/parse.ts +129 -0
- package/packages/compiler-sfc/src/parseComponent.ts +220 -0
- package/packages/compiler-sfc/src/prefixIdentifiers.ts +82 -0
- package/packages/compiler-sfc/src/rewriteDefault.ts +121 -0
- package/packages/compiler-sfc/src/stylePlugins/scoped.ts +203 -0
- package/packages/compiler-sfc/src/stylePlugins/trim.ts +18 -0
- package/packages/compiler-sfc/src/stylePreprocessors.ts +135 -0
- package/packages/compiler-sfc/src/templateCompilerModules/assetUrl.ts +84 -0
- package/packages/compiler-sfc/src/templateCompilerModules/srcset.ts +76 -0
- package/packages/compiler-sfc/src/templateCompilerModules/utils.ts +86 -0
- package/packages/compiler-sfc/src/types.ts +69 -0
- package/packages/compiler-sfc/src/warn.ts +16 -0
- package/packages/compiler-sfc/test/__snapshots__/compileScript.spec.ts.snap +971 -0
- package/packages/compiler-sfc/test/__snapshots__/cssVars.spec.ts.snap +189 -0
- package/packages/compiler-sfc/test/compileScript.spec.ts +1635 -0
- package/packages/compiler-sfc/test/compileStyle.spec.ts +203 -0
- package/packages/compiler-sfc/test/compileTemplate.spec.ts +258 -0
- package/packages/compiler-sfc/test/cssVars.spec.ts +247 -0
- package/packages/compiler-sfc/test/parseComponent.spec.ts +269 -0
- package/packages/compiler-sfc/test/prefixIdentifiers.spec.ts +97 -0
- package/packages/compiler-sfc/test/rewriteDefault.spec.ts +311 -0
- package/packages/compiler-sfc/test/stylePluginScoped.spec.ts +137 -0
- package/packages/compiler-sfc/test/tsconfig.json +7 -0
- package/packages/compiler-sfc/test/util.ts +35 -0
- package/src/compiler/codeframe.ts +52 -0
- package/src/compiler/codegen/events.ts +170 -0
- package/src/compiler/codegen/index.ts +668 -0
- package/src/compiler/create-compiler.ts +83 -0
- package/src/compiler/directives/bind.ts +9 -0
- package/src/compiler/directives/index.ts +9 -0
- package/src/compiler/directives/model.ts +145 -0
- package/src/compiler/directives/on.ts +9 -0
- package/src/compiler/error-detector.ts +158 -0
- package/src/compiler/helpers.ts +243 -0
- package/src/compiler/index.ts +24 -0
- package/src/compiler/optimizer.ts +135 -0
- package/src/compiler/parser/entity-decoder.ts +9 -0
- package/src/compiler/parser/filter-parser.ts +116 -0
- package/src/compiler/parser/html-parser.ts +345 -0
- package/src/compiler/parser/index.ts +999 -0
- package/src/compiler/parser/text-parser.ts +52 -0
- package/src/compiler/to-function.ts +119 -0
- package/src/core/components/index.ts +5 -0
- package/src/core/components/keep-alive.ts +171 -0
- package/src/core/config.ts +128 -0
- package/src/core/global-api/assets.ts +35 -0
- package/src/core/global-api/extend.ts +94 -0
- package/src/core/global-api/index.ts +68 -0
- package/src/core/global-api/mixin.ts +9 -0
- package/src/core/global-api/use.ts +23 -0
- package/src/core/index.ts +27 -0
- package/src/core/instance/events.ts +160 -0
- package/src/core/instance/index.ts +27 -0
- package/src/core/instance/init.ts +143 -0
- package/src/core/instance/inject.ts +80 -0
- package/src/core/instance/lifecycle.ts +421 -0
- package/src/core/instance/proxy.ts +97 -0
- package/src/core/instance/render-helpers/bind-dynamic-keys.ts +36 -0
- package/src/core/instance/render-helpers/bind-object-listeners.ts +18 -0
- package/src/core/instance/render-helpers/bind-object-props.ts +59 -0
- package/src/core/instance/render-helpers/check-keycodes.ts +33 -0
- package/src/core/instance/render-helpers/index.ts +31 -0
- package/src/core/instance/render-helpers/render-list.ts +49 -0
- package/src/core/instance/render-helpers/render-slot.ts +39 -0
- package/src/core/instance/render-helpers/render-static.ts +57 -0
- package/src/core/instance/render-helpers/resolve-filter.ts +8 -0
- package/src/core/instance/render-helpers/resolve-scoped-slots.ts +30 -0
- package/src/core/instance/render-helpers/resolve-slots.ts +51 -0
- package/src/core/instance/render.ts +172 -0
- package/src/core/instance/state.ts +393 -0
- package/src/core/observer/array.ts +54 -0
- package/src/core/observer/dep.ts +108 -0
- package/src/core/observer/index.ts +339 -0
- package/src/core/observer/scheduler.ts +199 -0
- package/src/core/observer/traverse.ts +47 -0
- package/src/core/observer/watcher.ts +278 -0
- package/src/core/util/debug.ts +105 -0
- package/src/core/util/env.ts +93 -0
- package/src/core/util/error.ts +81 -0
- package/src/core/util/index.ts +9 -0
- package/src/core/util/lang.ts +45 -0
- package/src/core/util/next-tick.ts +117 -0
- package/src/core/util/options.ts +489 -0
- package/src/core/util/perf.ts +28 -0
- package/src/core/util/props.ts +254 -0
- package/src/core/vdom/create-component.ts +275 -0
- package/src/core/vdom/create-element.ts +172 -0
- package/src/core/vdom/create-functional-component.ts +180 -0
- package/src/core/vdom/helpers/extract-props.ts +75 -0
- package/src/core/vdom/helpers/get-first-component-child.ts +16 -0
- package/src/core/vdom/helpers/index.ts +7 -0
- package/src/core/vdom/helpers/is-async-placeholder.ts +6 -0
- package/src/core/vdom/helpers/merge-hook.ts +40 -0
- package/src/core/vdom/helpers/normalize-children.ts +99 -0
- package/src/core/vdom/helpers/normalize-scoped-slots.ts +97 -0
- package/src/core/vdom/helpers/resolve-async-component.ts +157 -0
- package/src/core/vdom/helpers/update-listeners.ts +101 -0
- package/src/core/vdom/modules/directives.ts +137 -0
- package/src/core/vdom/modules/index.ts +4 -0
- package/src/core/vdom/modules/template-ref.ts +94 -0
- package/src/core/vdom/patch.ts +907 -0
- package/src/core/vdom/vnode.ts +119 -0
- package/src/global.d.ts +17 -0
- package/src/platforms/web/compiler/directives/html.ts +8 -0
- package/src/platforms/web/compiler/directives/index.ts +9 -0
- package/src/platforms/web/compiler/directives/model.ts +181 -0
- package/src/platforms/web/compiler/directives/text.ts +8 -0
- package/src/platforms/web/compiler/index.ts +6 -0
- package/src/platforms/web/compiler/modules/class.ts +44 -0
- package/src/platforms/web/compiler/modules/index.ts +5 -0
- package/src/platforms/web/compiler/modules/model.ts +89 -0
- package/src/platforms/web/compiler/modules/style.ts +47 -0
- package/src/platforms/web/compiler/options.ts +25 -0
- package/src/platforms/web/compiler/util.ts +22 -0
- package/src/platforms/web/entry-compiler.ts +4 -0
- package/src/platforms/web/entry-runtime-esm.ts +5 -0
- package/src/platforms/web/entry-runtime-with-compiler-esm.ts +5 -0
- package/src/platforms/web/entry-runtime-with-compiler.ts +10 -0
- package/src/platforms/web/entry-runtime.ts +7 -0
- package/src/platforms/web/runtime/class-util.ts +61 -0
- package/src/platforms/web/runtime/components/index.ts +7 -0
- package/src/platforms/web/runtime/components/transition-group.ts +204 -0
- package/src/platforms/web/runtime/components/transition.ts +205 -0
- package/src/platforms/web/runtime/directives/index.ts +7 -0
- package/src/platforms/web/runtime/directives/model.ts +148 -0
- package/src/platforms/web/runtime/directives/show.ts +61 -0
- package/src/platforms/web/runtime/index.ts +75 -0
- package/src/platforms/web/runtime/modules/attrs.ts +115 -0
- package/src/platforms/web/runtime/modules/class.ts +37 -0
- package/src/platforms/web/runtime/modules/dom-props.ts +123 -0
- package/src/platforms/web/runtime/modules/events.ts +127 -0
- package/src/platforms/web/runtime/modules/index.ts +8 -0
- package/src/platforms/web/runtime/modules/style.ts +102 -0
- package/src/platforms/web/runtime/modules/transition.ts +341 -0
- package/src/platforms/web/runtime/node-ops.ts +66 -0
- package/src/platforms/web/runtime/patch.ts +10 -0
- package/src/platforms/web/runtime/transition-util.ts +215 -0
- package/src/platforms/web/runtime-with-compiler.ts +110 -0
- package/src/platforms/web/util/attrs.ts +58 -0
- package/src/platforms/web/util/class.ts +87 -0
- package/src/platforms/web/util/compat.ts +16 -0
- package/src/platforms/web/util/element.ts +76 -0
- package/src/platforms/web/util/index.ts +21 -0
- package/src/platforms/web/util/style.ts +71 -0
- package/src/shared/constants.ts +20 -0
- package/src/shared/util.ts +378 -0
- package/src/types/compiler.ts +207 -0
- package/src/types/component.ts +212 -0
- package/src/types/global-api.ts +37 -0
- package/src/types/modules.d.ts +15 -0
- package/src/types/options.ts +114 -0
- package/src/types/ssr.ts +27 -0
- package/src/types/utils.ts +3 -0
- package/src/types/vnode.ts +127 -0
- package/src/v3/apiAsyncComponent.ts +117 -0
- package/src/v3/apiInject.ts +71 -0
- package/src/v3/apiLifecycle.ts +68 -0
- package/src/v3/apiSetup.ts +246 -0
- package/src/v3/apiWatch.ts +353 -0
- package/src/v3/currentInstance.ts +23 -0
- package/src/v3/debug.ts +21 -0
- package/src/v3/h.ts +18 -0
- package/src/v3/index.ts +96 -0
- package/src/v3/reactivity/computed.ts +100 -0
- package/src/v3/reactivity/effect.ts +20 -0
- package/src/v3/reactivity/effectScope.ts +137 -0
- package/src/v3/reactivity/operations.ts +14 -0
- package/src/v3/reactivity/reactive.ts +137 -0
- package/src/v3/reactivity/readonly.ts +127 -0
- package/src/v3/reactivity/ref.ts +293 -0
- package/src/v3/sfc-helpers/useCssModule.ts +24 -0
- package/src/v3/sfc-helpers/useCssVars.ts +34 -0
- package/types/built-in-components.d.ts +63 -0
- package/types/common.d.ts +21 -0
- package/types/index.d.ts +81 -0
- package/types/jsx.d.ts +1353 -0
- package/types/options.d.ts +349 -0
- package/types/plugin.d.ts +8 -0
- package/types/umd.d.ts +68 -0
- package/types/v3-component-options.d.ts +252 -0
- package/types/v3-component-props.d.ts +99 -0
- package/types/v3-component-public-instance.d.ts +232 -0
- package/types/v3-define-async-component.d.ts +26 -0
- package/types/v3-define-component.d.ts +201 -0
- package/types/v3-directive.d.ts +29 -0
- package/types/v3-manual-apis.d.ts +10 -0
- package/types/v3-setup-context.d.ts +41 -0
- package/types/v3-setup-helpers.d.ts +154 -0
- package/types/vnode.d.ts +117 -0
- package/types/vue.d.ts +446 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { compileStyle } from '../src/compileStyle'
|
|
2
|
+
|
|
3
|
+
// vue-loader/#1370
|
|
4
|
+
test('spaces after selector', () => {
|
|
5
|
+
const { code } = compileStyle({
|
|
6
|
+
source: `.foo , .bar { color: red; }`,
|
|
7
|
+
filename: 'test.css',
|
|
8
|
+
id: 'test'
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
expect(code).toMatch(`.foo[test], .bar[test] { color: red;`)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
test('leading deep selector', () => {
|
|
15
|
+
const { code } = compileStyle({
|
|
16
|
+
source: `>>> .foo { color: red; }`,
|
|
17
|
+
filename: 'test.css',
|
|
18
|
+
id: 'test'
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
expect(code).toMatch(`[test] .foo { color: red;`)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('scoped css', () => {
|
|
25
|
+
const { code: style } = compileStyle({
|
|
26
|
+
id: 'v-scope-xxx',
|
|
27
|
+
scoped: true,
|
|
28
|
+
filename: 'example.vue',
|
|
29
|
+
source: `
|
|
30
|
+
.test {
|
|
31
|
+
color: yellow;
|
|
32
|
+
}
|
|
33
|
+
.test:after {
|
|
34
|
+
content: 'bye!';
|
|
35
|
+
}
|
|
36
|
+
h1 {
|
|
37
|
+
color: green;
|
|
38
|
+
}
|
|
39
|
+
.anim {
|
|
40
|
+
animation: color 5s infinite, other 5s;
|
|
41
|
+
}
|
|
42
|
+
.anim-2 {
|
|
43
|
+
animation-name: color;
|
|
44
|
+
animation-duration: 5s;
|
|
45
|
+
}
|
|
46
|
+
.anim-3 {
|
|
47
|
+
animation: 5s color infinite, 5s other;
|
|
48
|
+
}
|
|
49
|
+
.anim-multiple {
|
|
50
|
+
animation: color 5s infinite, opacity 2s;
|
|
51
|
+
}
|
|
52
|
+
.anim-multiple-2 {
|
|
53
|
+
animation-name: color, opacity;
|
|
54
|
+
animation-duration: 5s, 2s;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@keyframes color {
|
|
58
|
+
from { color: red; }
|
|
59
|
+
to { color: green; }
|
|
60
|
+
}
|
|
61
|
+
@-webkit-keyframes color {
|
|
62
|
+
from { color: red; }
|
|
63
|
+
to { color: green; }
|
|
64
|
+
}
|
|
65
|
+
@keyframes opacity {
|
|
66
|
+
from { opacity: 0; }
|
|
67
|
+
to { opacity: 1; }
|
|
68
|
+
}
|
|
69
|
+
@-webkit-keyframes opacity {
|
|
70
|
+
from { opacity: 0; }
|
|
71
|
+
to { opacity: 1; }
|
|
72
|
+
}
|
|
73
|
+
.foo p >>> .bar {
|
|
74
|
+
color: red;
|
|
75
|
+
}
|
|
76
|
+
.foo div /deep/ .bar {
|
|
77
|
+
color: red;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.foo span ::v-deep .bar {
|
|
81
|
+
color: red;
|
|
82
|
+
}
|
|
83
|
+
`
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
expect(style).toContain(`.test[v-scope-xxx] {\n color: yellow;\n}`)
|
|
87
|
+
expect(style).toContain(`.test[v-scope-xxx]:after {\n content: \'bye!\';\n}`)
|
|
88
|
+
expect(style).toContain(`h1[v-scope-xxx] {\n color: green;\n}`)
|
|
89
|
+
// scoped keyframes
|
|
90
|
+
expect(style).toContain(
|
|
91
|
+
`.anim[v-scope-xxx] {\n animation: color-v-scope-xxx 5s infinite, other 5s;`
|
|
92
|
+
)
|
|
93
|
+
expect(style).toContain(
|
|
94
|
+
`.anim-2[v-scope-xxx] {\n animation-name: color-v-scope-xxx`
|
|
95
|
+
)
|
|
96
|
+
expect(style).toContain(
|
|
97
|
+
`.anim-3[v-scope-xxx] {\n animation: 5s color-v-scope-xxx infinite, 5s other;`
|
|
98
|
+
)
|
|
99
|
+
expect(style).toContain(`@keyframes color-v-scope-xxx {`)
|
|
100
|
+
expect(style).toContain(`@-webkit-keyframes color-v-scope-xxx {`)
|
|
101
|
+
|
|
102
|
+
expect(style).toContain(
|
|
103
|
+
`.anim-multiple[v-scope-xxx] {\n animation: color-v-scope-xxx 5s infinite,opacity-v-scope-xxx 2s;`
|
|
104
|
+
)
|
|
105
|
+
expect(style).toContain(
|
|
106
|
+
`.anim-multiple-2[v-scope-xxx] {\n animation-name: color-v-scope-xxx,opacity-v-scope-xxx;`
|
|
107
|
+
)
|
|
108
|
+
expect(style).toContain(`@keyframes opacity-v-scope-xxx {`)
|
|
109
|
+
expect(style).toContain(`@-webkit-keyframes opacity-v-scope-xxx {`)
|
|
110
|
+
// >>> combinator
|
|
111
|
+
expect(style).toContain(`.foo p[v-scope-xxx] .bar {\n color: red;\n}`)
|
|
112
|
+
// /deep/ alias for >>>
|
|
113
|
+
expect(style).toContain(`.foo div[v-scope-xxx] .bar {\n color: red;\n}`)
|
|
114
|
+
// ::-v-deep alias for >>>
|
|
115
|
+
expect(style).toContain(`.foo span[v-scope-xxx] .bar {\n color: red;\n}`)
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
test('pseudo element', () => {
|
|
119
|
+
const { code } = compileStyle({
|
|
120
|
+
source: '::selection { display: none; }',
|
|
121
|
+
filename: 'test.css',
|
|
122
|
+
id: 'test'
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
expect(code).toContain('[test]::selection {')
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
test('spaces before pseudo element', () => {
|
|
129
|
+
const { code } = compileStyle({
|
|
130
|
+
source: '.abc, ::selection { color: red; }',
|
|
131
|
+
filename: 'test.css',
|
|
132
|
+
id: 'test'
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
expect(code).toContain('.abc[test],')
|
|
136
|
+
expect(code).toContain('[test]::selection {')
|
|
137
|
+
})
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parse,
|
|
3
|
+
compileScript,
|
|
4
|
+
type SFCParseOptions,
|
|
5
|
+
type SFCScriptCompileOptions
|
|
6
|
+
} from '../src'
|
|
7
|
+
import { parse as babelParse } from '@babel/parser'
|
|
8
|
+
|
|
9
|
+
export const mockId = 'xxxxxxxx'
|
|
10
|
+
|
|
11
|
+
export function compile(
|
|
12
|
+
source: string,
|
|
13
|
+
options?: Partial<SFCScriptCompileOptions>,
|
|
14
|
+
parseOptions?: Partial<SFCParseOptions>
|
|
15
|
+
) {
|
|
16
|
+
const sfc = parse({
|
|
17
|
+
...parseOptions,
|
|
18
|
+
source
|
|
19
|
+
})
|
|
20
|
+
return compileScript(sfc, { id: mockId, ...options })
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function assertCode(code: string) {
|
|
24
|
+
// parse the generated code to make sure it is valid
|
|
25
|
+
try {
|
|
26
|
+
babelParse(code, {
|
|
27
|
+
sourceType: 'module',
|
|
28
|
+
plugins: ['typescript']
|
|
29
|
+
})
|
|
30
|
+
} catch (e: any) {
|
|
31
|
+
console.log(code)
|
|
32
|
+
throw e
|
|
33
|
+
}
|
|
34
|
+
expect(code).toMatchSnapshot()
|
|
35
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const range = 2
|
|
2
|
+
|
|
3
|
+
export function generateCodeFrame(
|
|
4
|
+
source: string,
|
|
5
|
+
start: number = 0,
|
|
6
|
+
end: number = source.length
|
|
7
|
+
): string {
|
|
8
|
+
const lines = source.split(/\r?\n/)
|
|
9
|
+
let count = 0
|
|
10
|
+
const res: string[] = []
|
|
11
|
+
for (let i = 0; i < lines.length; i++) {
|
|
12
|
+
count += lines[i].length + 1
|
|
13
|
+
if (count >= start) {
|
|
14
|
+
for (let j = i - range; j <= i + range || end > count; j++) {
|
|
15
|
+
if (j < 0 || j >= lines.length) continue
|
|
16
|
+
res.push(
|
|
17
|
+
`${j + 1}${repeat(` `, 3 - String(j + 1).length)}| ${lines[j]}`
|
|
18
|
+
)
|
|
19
|
+
const lineLength = lines[j].length
|
|
20
|
+
if (j === i) {
|
|
21
|
+
// push underline
|
|
22
|
+
const pad = start - (count - lineLength) + 1
|
|
23
|
+
const length = end > count ? lineLength - pad : end - start
|
|
24
|
+
res.push(` | ` + repeat(` `, pad) + repeat(`^`, length))
|
|
25
|
+
} else if (j > i) {
|
|
26
|
+
if (end > count) {
|
|
27
|
+
const length = Math.min(end - count, lineLength)
|
|
28
|
+
res.push(` | ` + repeat(`^`, length))
|
|
29
|
+
}
|
|
30
|
+
count += lineLength + 1
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
break
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return res.join('\n')
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function repeat(str: string, n: number) {
|
|
40
|
+
let result = ''
|
|
41
|
+
if (n > 0) {
|
|
42
|
+
// eslint-disable-next-line no-constant-condition
|
|
43
|
+
while (true) {
|
|
44
|
+
// eslint-disable-line
|
|
45
|
+
if (n & 1) result += str
|
|
46
|
+
n >>>= 1
|
|
47
|
+
if (n <= 0) break
|
|
48
|
+
str += str
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return result
|
|
52
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { ASTElementHandler, ASTElementHandlers } from 'types/compiler'
|
|
2
|
+
|
|
3
|
+
const fnExpRE = /^([\w$_]+|\([^)]*?\))\s*=>|^function(?:\s+[\w$]+)?\s*\(/
|
|
4
|
+
const fnInvokeRE = /\([^)]*?\);*$/
|
|
5
|
+
const simplePathRE =
|
|
6
|
+
/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?']|\["[^"]*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*$/
|
|
7
|
+
|
|
8
|
+
// KeyboardEvent.keyCode aliases
|
|
9
|
+
const keyCodes: { [key: string]: number | Array<number> } = {
|
|
10
|
+
esc: 27,
|
|
11
|
+
tab: 9,
|
|
12
|
+
enter: 13,
|
|
13
|
+
space: 32,
|
|
14
|
+
up: 38,
|
|
15
|
+
left: 37,
|
|
16
|
+
right: 39,
|
|
17
|
+
down: 40,
|
|
18
|
+
delete: [8, 46]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// KeyboardEvent.key aliases
|
|
22
|
+
const keyNames: { [key: string]: string | Array<string> } = {
|
|
23
|
+
// #7880: IE11 and Edge use `Esc` for Escape key name.
|
|
24
|
+
esc: ['Esc', 'Escape'],
|
|
25
|
+
tab: 'Tab',
|
|
26
|
+
enter: 'Enter',
|
|
27
|
+
// #9112: IE11 uses `Spacebar` for Space key name.
|
|
28
|
+
space: [' ', 'Spacebar'],
|
|
29
|
+
// #7806: IE11 uses key names without `Arrow` prefix for arrow keys.
|
|
30
|
+
up: ['Up', 'ArrowUp'],
|
|
31
|
+
left: ['Left', 'ArrowLeft'],
|
|
32
|
+
right: ['Right', 'ArrowRight'],
|
|
33
|
+
down: ['Down', 'ArrowDown'],
|
|
34
|
+
// #9112: IE11 uses `Del` for Delete key name.
|
|
35
|
+
delete: ['Backspace', 'Delete', 'Del']
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// #4868: modifiers that prevent the execution of the listener
|
|
39
|
+
// need to explicitly return null so that we can determine whether to remove
|
|
40
|
+
// the listener for .once
|
|
41
|
+
const genGuard = condition => `if(${condition})return null;`
|
|
42
|
+
|
|
43
|
+
const modifierCode: { [key: string]: string } = {
|
|
44
|
+
stop: '$event.stopPropagation();',
|
|
45
|
+
prevent: '$event.preventDefault();',
|
|
46
|
+
self: genGuard(`$event.target !== $event.currentTarget`),
|
|
47
|
+
ctrl: genGuard(`!$event.ctrlKey`),
|
|
48
|
+
shift: genGuard(`!$event.shiftKey`),
|
|
49
|
+
alt: genGuard(`!$event.altKey`),
|
|
50
|
+
meta: genGuard(`!$event.metaKey`),
|
|
51
|
+
left: genGuard(`'button' in $event && $event.button !== 0`),
|
|
52
|
+
middle: genGuard(`'button' in $event && $event.button !== 1`),
|
|
53
|
+
right: genGuard(`'button' in $event && $event.button !== 2`)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function genHandlers(
|
|
57
|
+
events: ASTElementHandlers,
|
|
58
|
+
isNative: boolean
|
|
59
|
+
): string {
|
|
60
|
+
const prefix = isNative ? 'nativeOn:' : 'on:'
|
|
61
|
+
let staticHandlers = ``
|
|
62
|
+
let dynamicHandlers = ``
|
|
63
|
+
for (const name in events) {
|
|
64
|
+
const handlerCode = genHandler(events[name])
|
|
65
|
+
//@ts-expect-error
|
|
66
|
+
if (events[name] && events[name].dynamic) {
|
|
67
|
+
dynamicHandlers += `${name},${handlerCode},`
|
|
68
|
+
} else {
|
|
69
|
+
staticHandlers += `"${name}":${handlerCode},`
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
staticHandlers = `{${staticHandlers.slice(0, -1)}}`
|
|
73
|
+
if (dynamicHandlers) {
|
|
74
|
+
return prefix + `_d(${staticHandlers},[${dynamicHandlers.slice(0, -1)}])`
|
|
75
|
+
} else {
|
|
76
|
+
return prefix + staticHandlers
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function genHandler(
|
|
81
|
+
handler: ASTElementHandler | Array<ASTElementHandler>
|
|
82
|
+
): string {
|
|
83
|
+
if (!handler) {
|
|
84
|
+
return 'function(){}'
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (Array.isArray(handler)) {
|
|
88
|
+
return `[${handler.map(handler => genHandler(handler)).join(',')}]`
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const isMethodPath = simplePathRE.test(handler.value)
|
|
92
|
+
const isFunctionExpression = fnExpRE.test(handler.value)
|
|
93
|
+
const isFunctionInvocation = simplePathRE.test(
|
|
94
|
+
handler.value.replace(fnInvokeRE, '')
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
if (!handler.modifiers) {
|
|
98
|
+
if (isMethodPath || isFunctionExpression) {
|
|
99
|
+
return handler.value
|
|
100
|
+
}
|
|
101
|
+
return `function($event){${
|
|
102
|
+
isFunctionInvocation ? `return ${handler.value}` : handler.value
|
|
103
|
+
}}` // inline statement
|
|
104
|
+
} else {
|
|
105
|
+
let code = ''
|
|
106
|
+
let genModifierCode = ''
|
|
107
|
+
const keys: string[] = []
|
|
108
|
+
for (const key in handler.modifiers) {
|
|
109
|
+
if (modifierCode[key]) {
|
|
110
|
+
genModifierCode += modifierCode[key]
|
|
111
|
+
// left/right
|
|
112
|
+
if (keyCodes[key]) {
|
|
113
|
+
keys.push(key)
|
|
114
|
+
}
|
|
115
|
+
} else if (key === 'exact') {
|
|
116
|
+
const modifiers = handler.modifiers
|
|
117
|
+
genModifierCode += genGuard(
|
|
118
|
+
['ctrl', 'shift', 'alt', 'meta']
|
|
119
|
+
.filter(keyModifier => !modifiers[keyModifier])
|
|
120
|
+
.map(keyModifier => `$event.${keyModifier}Key`)
|
|
121
|
+
.join('||')
|
|
122
|
+
)
|
|
123
|
+
} else {
|
|
124
|
+
keys.push(key)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (keys.length) {
|
|
128
|
+
code += genKeyFilter(keys)
|
|
129
|
+
}
|
|
130
|
+
// Make sure modifiers like prevent and stop get executed after key filtering
|
|
131
|
+
if (genModifierCode) {
|
|
132
|
+
code += genModifierCode
|
|
133
|
+
}
|
|
134
|
+
const handlerCode = isMethodPath
|
|
135
|
+
? `return ${handler.value}.apply(null, arguments)`
|
|
136
|
+
: isFunctionExpression
|
|
137
|
+
? `return (${handler.value}).apply(null, arguments)`
|
|
138
|
+
: isFunctionInvocation
|
|
139
|
+
? `return ${handler.value}`
|
|
140
|
+
: handler.value
|
|
141
|
+
return `function($event){${code}${handlerCode}}`
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function genKeyFilter(keys: Array<string>): string {
|
|
146
|
+
return (
|
|
147
|
+
// make sure the key filters only apply to KeyboardEvents
|
|
148
|
+
// #9441: can't use 'keyCode' in $event because Chrome autofill fires fake
|
|
149
|
+
// key events that do not have keyCode property...
|
|
150
|
+
`if(!$event.type.indexOf('key')&&` +
|
|
151
|
+
`${keys.map(genFilterCode).join('&&')})return null;`
|
|
152
|
+
)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function genFilterCode(key: string): string {
|
|
156
|
+
const keyVal = parseInt(key, 10)
|
|
157
|
+
if (keyVal) {
|
|
158
|
+
return `$event.keyCode!==${keyVal}`
|
|
159
|
+
}
|
|
160
|
+
const keyCode = keyCodes[key]
|
|
161
|
+
const keyName = keyNames[key]
|
|
162
|
+
return (
|
|
163
|
+
`_k($event.keyCode,` +
|
|
164
|
+
`${JSON.stringify(key)},` +
|
|
165
|
+
`${JSON.stringify(keyCode)},` +
|
|
166
|
+
`$event.key,` +
|
|
167
|
+
`${JSON.stringify(keyName)}` +
|
|
168
|
+
`)`
|
|
169
|
+
)
|
|
170
|
+
}
|