@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.
Files changed (214) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +122 -0
  3. package/compiler-sfc/index.d.ts +1 -0
  4. package/compiler-sfc/index.js +1 -0
  5. package/compiler-sfc/index.mjs +1 -0
  6. package/compiler-sfc/package.json +5 -0
  7. package/dist/vue.common.js +5 -0
  8. package/dist/vue.runtime.common.js +5 -0
  9. package/dist/vue.runtime.mjs +76 -0
  10. package/package.json +136 -0
  11. package/packages/compiler-sfc/api-extractor.json +64 -0
  12. package/packages/compiler-sfc/dist/compiler-sfc.js +17146 -0
  13. package/packages/compiler-sfc/node_modules/.bin/lessc +17 -0
  14. package/packages/compiler-sfc/node_modules/.bin/parser +17 -0
  15. package/packages/compiler-sfc/node_modules/.bin/prettier +17 -0
  16. package/packages/compiler-sfc/node_modules/.bin/sass +17 -0
  17. package/packages/compiler-sfc/node_modules/.bin/stylus +17 -0
  18. package/packages/compiler-sfc/package.json +37 -0
  19. package/packages/compiler-sfc/src/babelUtils.ts +423 -0
  20. package/packages/compiler-sfc/src/compileScript.ts +1916 -0
  21. package/packages/compiler-sfc/src/compileStyle.ts +147 -0
  22. package/packages/compiler-sfc/src/compileTemplate.ts +205 -0
  23. package/packages/compiler-sfc/src/cssVars.ts +179 -0
  24. package/packages/compiler-sfc/src/index.ts +31 -0
  25. package/packages/compiler-sfc/src/parse.ts +129 -0
  26. package/packages/compiler-sfc/src/parseComponent.ts +220 -0
  27. package/packages/compiler-sfc/src/prefixIdentifiers.ts +82 -0
  28. package/packages/compiler-sfc/src/rewriteDefault.ts +121 -0
  29. package/packages/compiler-sfc/src/stylePlugins/scoped.ts +203 -0
  30. package/packages/compiler-sfc/src/stylePlugins/trim.ts +18 -0
  31. package/packages/compiler-sfc/src/stylePreprocessors.ts +135 -0
  32. package/packages/compiler-sfc/src/templateCompilerModules/assetUrl.ts +84 -0
  33. package/packages/compiler-sfc/src/templateCompilerModules/srcset.ts +76 -0
  34. package/packages/compiler-sfc/src/templateCompilerModules/utils.ts +86 -0
  35. package/packages/compiler-sfc/src/types.ts +69 -0
  36. package/packages/compiler-sfc/src/warn.ts +16 -0
  37. package/packages/compiler-sfc/test/__snapshots__/compileScript.spec.ts.snap +971 -0
  38. package/packages/compiler-sfc/test/__snapshots__/cssVars.spec.ts.snap +189 -0
  39. package/packages/compiler-sfc/test/compileScript.spec.ts +1635 -0
  40. package/packages/compiler-sfc/test/compileStyle.spec.ts +203 -0
  41. package/packages/compiler-sfc/test/compileTemplate.spec.ts +258 -0
  42. package/packages/compiler-sfc/test/cssVars.spec.ts +247 -0
  43. package/packages/compiler-sfc/test/parseComponent.spec.ts +269 -0
  44. package/packages/compiler-sfc/test/prefixIdentifiers.spec.ts +97 -0
  45. package/packages/compiler-sfc/test/rewriteDefault.spec.ts +311 -0
  46. package/packages/compiler-sfc/test/stylePluginScoped.spec.ts +137 -0
  47. package/packages/compiler-sfc/test/tsconfig.json +7 -0
  48. package/packages/compiler-sfc/test/util.ts +35 -0
  49. package/src/compiler/codeframe.ts +52 -0
  50. package/src/compiler/codegen/events.ts +170 -0
  51. package/src/compiler/codegen/index.ts +668 -0
  52. package/src/compiler/create-compiler.ts +83 -0
  53. package/src/compiler/directives/bind.ts +9 -0
  54. package/src/compiler/directives/index.ts +9 -0
  55. package/src/compiler/directives/model.ts +145 -0
  56. package/src/compiler/directives/on.ts +9 -0
  57. package/src/compiler/error-detector.ts +158 -0
  58. package/src/compiler/helpers.ts +243 -0
  59. package/src/compiler/index.ts +24 -0
  60. package/src/compiler/optimizer.ts +135 -0
  61. package/src/compiler/parser/entity-decoder.ts +9 -0
  62. package/src/compiler/parser/filter-parser.ts +116 -0
  63. package/src/compiler/parser/html-parser.ts +345 -0
  64. package/src/compiler/parser/index.ts +999 -0
  65. package/src/compiler/parser/text-parser.ts +52 -0
  66. package/src/compiler/to-function.ts +119 -0
  67. package/src/core/components/index.ts +5 -0
  68. package/src/core/components/keep-alive.ts +171 -0
  69. package/src/core/config.ts +128 -0
  70. package/src/core/global-api/assets.ts +35 -0
  71. package/src/core/global-api/extend.ts +94 -0
  72. package/src/core/global-api/index.ts +68 -0
  73. package/src/core/global-api/mixin.ts +9 -0
  74. package/src/core/global-api/use.ts +23 -0
  75. package/src/core/index.ts +27 -0
  76. package/src/core/instance/events.ts +160 -0
  77. package/src/core/instance/index.ts +27 -0
  78. package/src/core/instance/init.ts +143 -0
  79. package/src/core/instance/inject.ts +80 -0
  80. package/src/core/instance/lifecycle.ts +421 -0
  81. package/src/core/instance/proxy.ts +97 -0
  82. package/src/core/instance/render-helpers/bind-dynamic-keys.ts +36 -0
  83. package/src/core/instance/render-helpers/bind-object-listeners.ts +18 -0
  84. package/src/core/instance/render-helpers/bind-object-props.ts +59 -0
  85. package/src/core/instance/render-helpers/check-keycodes.ts +33 -0
  86. package/src/core/instance/render-helpers/index.ts +31 -0
  87. package/src/core/instance/render-helpers/render-list.ts +49 -0
  88. package/src/core/instance/render-helpers/render-slot.ts +39 -0
  89. package/src/core/instance/render-helpers/render-static.ts +57 -0
  90. package/src/core/instance/render-helpers/resolve-filter.ts +8 -0
  91. package/src/core/instance/render-helpers/resolve-scoped-slots.ts +30 -0
  92. package/src/core/instance/render-helpers/resolve-slots.ts +51 -0
  93. package/src/core/instance/render.ts +172 -0
  94. package/src/core/instance/state.ts +393 -0
  95. package/src/core/observer/array.ts +54 -0
  96. package/src/core/observer/dep.ts +108 -0
  97. package/src/core/observer/index.ts +339 -0
  98. package/src/core/observer/scheduler.ts +199 -0
  99. package/src/core/observer/traverse.ts +47 -0
  100. package/src/core/observer/watcher.ts +278 -0
  101. package/src/core/util/debug.ts +105 -0
  102. package/src/core/util/env.ts +93 -0
  103. package/src/core/util/error.ts +81 -0
  104. package/src/core/util/index.ts +9 -0
  105. package/src/core/util/lang.ts +45 -0
  106. package/src/core/util/next-tick.ts +117 -0
  107. package/src/core/util/options.ts +489 -0
  108. package/src/core/util/perf.ts +28 -0
  109. package/src/core/util/props.ts +254 -0
  110. package/src/core/vdom/create-component.ts +275 -0
  111. package/src/core/vdom/create-element.ts +172 -0
  112. package/src/core/vdom/create-functional-component.ts +180 -0
  113. package/src/core/vdom/helpers/extract-props.ts +75 -0
  114. package/src/core/vdom/helpers/get-first-component-child.ts +16 -0
  115. package/src/core/vdom/helpers/index.ts +7 -0
  116. package/src/core/vdom/helpers/is-async-placeholder.ts +6 -0
  117. package/src/core/vdom/helpers/merge-hook.ts +40 -0
  118. package/src/core/vdom/helpers/normalize-children.ts +99 -0
  119. package/src/core/vdom/helpers/normalize-scoped-slots.ts +97 -0
  120. package/src/core/vdom/helpers/resolve-async-component.ts +157 -0
  121. package/src/core/vdom/helpers/update-listeners.ts +101 -0
  122. package/src/core/vdom/modules/directives.ts +137 -0
  123. package/src/core/vdom/modules/index.ts +4 -0
  124. package/src/core/vdom/modules/template-ref.ts +94 -0
  125. package/src/core/vdom/patch.ts +907 -0
  126. package/src/core/vdom/vnode.ts +119 -0
  127. package/src/global.d.ts +17 -0
  128. package/src/platforms/web/compiler/directives/html.ts +8 -0
  129. package/src/platforms/web/compiler/directives/index.ts +9 -0
  130. package/src/platforms/web/compiler/directives/model.ts +181 -0
  131. package/src/platforms/web/compiler/directives/text.ts +8 -0
  132. package/src/platforms/web/compiler/index.ts +6 -0
  133. package/src/platforms/web/compiler/modules/class.ts +44 -0
  134. package/src/platforms/web/compiler/modules/index.ts +5 -0
  135. package/src/platforms/web/compiler/modules/model.ts +89 -0
  136. package/src/platforms/web/compiler/modules/style.ts +47 -0
  137. package/src/platforms/web/compiler/options.ts +25 -0
  138. package/src/platforms/web/compiler/util.ts +22 -0
  139. package/src/platforms/web/entry-compiler.ts +4 -0
  140. package/src/platforms/web/entry-runtime-esm.ts +5 -0
  141. package/src/platforms/web/entry-runtime-with-compiler-esm.ts +5 -0
  142. package/src/platforms/web/entry-runtime-with-compiler.ts +10 -0
  143. package/src/platforms/web/entry-runtime.ts +7 -0
  144. package/src/platforms/web/runtime/class-util.ts +61 -0
  145. package/src/platforms/web/runtime/components/index.ts +7 -0
  146. package/src/platforms/web/runtime/components/transition-group.ts +204 -0
  147. package/src/platforms/web/runtime/components/transition.ts +205 -0
  148. package/src/platforms/web/runtime/directives/index.ts +7 -0
  149. package/src/platforms/web/runtime/directives/model.ts +148 -0
  150. package/src/platforms/web/runtime/directives/show.ts +61 -0
  151. package/src/platforms/web/runtime/index.ts +75 -0
  152. package/src/platforms/web/runtime/modules/attrs.ts +115 -0
  153. package/src/platforms/web/runtime/modules/class.ts +37 -0
  154. package/src/platforms/web/runtime/modules/dom-props.ts +123 -0
  155. package/src/platforms/web/runtime/modules/events.ts +127 -0
  156. package/src/platforms/web/runtime/modules/index.ts +8 -0
  157. package/src/platforms/web/runtime/modules/style.ts +102 -0
  158. package/src/platforms/web/runtime/modules/transition.ts +341 -0
  159. package/src/platforms/web/runtime/node-ops.ts +66 -0
  160. package/src/platforms/web/runtime/patch.ts +10 -0
  161. package/src/platforms/web/runtime/transition-util.ts +215 -0
  162. package/src/platforms/web/runtime-with-compiler.ts +110 -0
  163. package/src/platforms/web/util/attrs.ts +58 -0
  164. package/src/platforms/web/util/class.ts +87 -0
  165. package/src/platforms/web/util/compat.ts +16 -0
  166. package/src/platforms/web/util/element.ts +76 -0
  167. package/src/platforms/web/util/index.ts +21 -0
  168. package/src/platforms/web/util/style.ts +71 -0
  169. package/src/shared/constants.ts +20 -0
  170. package/src/shared/util.ts +378 -0
  171. package/src/types/compiler.ts +207 -0
  172. package/src/types/component.ts +212 -0
  173. package/src/types/global-api.ts +37 -0
  174. package/src/types/modules.d.ts +15 -0
  175. package/src/types/options.ts +114 -0
  176. package/src/types/ssr.ts +27 -0
  177. package/src/types/utils.ts +3 -0
  178. package/src/types/vnode.ts +127 -0
  179. package/src/v3/apiAsyncComponent.ts +117 -0
  180. package/src/v3/apiInject.ts +71 -0
  181. package/src/v3/apiLifecycle.ts +68 -0
  182. package/src/v3/apiSetup.ts +246 -0
  183. package/src/v3/apiWatch.ts +353 -0
  184. package/src/v3/currentInstance.ts +23 -0
  185. package/src/v3/debug.ts +21 -0
  186. package/src/v3/h.ts +18 -0
  187. package/src/v3/index.ts +96 -0
  188. package/src/v3/reactivity/computed.ts +100 -0
  189. package/src/v3/reactivity/effect.ts +20 -0
  190. package/src/v3/reactivity/effectScope.ts +137 -0
  191. package/src/v3/reactivity/operations.ts +14 -0
  192. package/src/v3/reactivity/reactive.ts +137 -0
  193. package/src/v3/reactivity/readonly.ts +127 -0
  194. package/src/v3/reactivity/ref.ts +293 -0
  195. package/src/v3/sfc-helpers/useCssModule.ts +24 -0
  196. package/src/v3/sfc-helpers/useCssVars.ts +34 -0
  197. package/types/built-in-components.d.ts +63 -0
  198. package/types/common.d.ts +21 -0
  199. package/types/index.d.ts +81 -0
  200. package/types/jsx.d.ts +1353 -0
  201. package/types/options.d.ts +349 -0
  202. package/types/plugin.d.ts +8 -0
  203. package/types/umd.d.ts +68 -0
  204. package/types/v3-component-options.d.ts +252 -0
  205. package/types/v3-component-props.d.ts +99 -0
  206. package/types/v3-component-public-instance.d.ts +232 -0
  207. package/types/v3-define-async-component.d.ts +26 -0
  208. package/types/v3-define-component.d.ts +201 -0
  209. package/types/v3-directive.d.ts +29 -0
  210. package/types/v3-manual-apis.d.ts +10 -0
  211. package/types/v3-setup-context.d.ts +41 -0
  212. package/types/v3-setup-helpers.d.ts +154 -0
  213. package/types/vnode.d.ts +117 -0
  214. package/types/vue.d.ts +446 -0
@@ -0,0 +1,203 @@
1
+ import { parse } from '../src/parse'
2
+ import { compileStyle, compileStyleAsync } from '../src/compileStyle'
3
+
4
+ test('preprocess less', () => {
5
+ const style = parse({
6
+ source:
7
+ '<style lang="less">\n' +
8
+ '@red: rgb(255, 0, 0);\n' +
9
+ '.color { color: @red; }\n' +
10
+ '</style>\n',
11
+ filename: 'example.vue',
12
+ sourceMap: true
13
+ }).styles[0]
14
+
15
+ const result = compileStyle({
16
+ id: 'v-scope-xxx',
17
+ filename: 'example.vue',
18
+ source: style.content,
19
+ map: style.map,
20
+ scoped: false,
21
+ preprocessLang: style.lang
22
+ })
23
+
24
+ expect(result.errors.length).toBe(0)
25
+ expect(result.code).toEqual(expect.stringContaining('color: #ff0000;'))
26
+ expect(result.map).toBeTruthy()
27
+ })
28
+
29
+ test('preprocess scss', () => {
30
+ const style = parse({
31
+ source:
32
+ '<style lang="scss">\n' +
33
+ '$red: red;\n' +
34
+ '.color { color: $red; }\n' +
35
+ '</style>\n',
36
+ filename: 'example.vue',
37
+ sourceMap: true
38
+ }).styles[0]
39
+ const result = compileStyle({
40
+ id: 'v-scope-xxx',
41
+ filename: 'example.vue',
42
+ source: style.content,
43
+ map: style.map,
44
+ scoped: false,
45
+ preprocessLang: style.lang
46
+ })
47
+
48
+ expect(result.errors.length).toBe(0)
49
+ expect(result.code).toMatch('color: red;')
50
+ expect(result.map).toBeTruthy()
51
+ })
52
+
53
+ test('preprocess sass', () => {
54
+ const style = parse({
55
+ source:
56
+ '<style lang="sass">\n' +
57
+ '$red: red\n' +
58
+ '.color\n' +
59
+ ' color: $red\n' +
60
+ '</style>\n',
61
+ filename: 'example.vue',
62
+ sourceMap: true
63
+ }).styles[0]
64
+ const result = compileStyle({
65
+ id: 'v-scope-xxx',
66
+ filename: 'example.vue',
67
+ source: style.content,
68
+ map: style.map,
69
+ scoped: false,
70
+ preprocessLang: style.lang
71
+ })
72
+
73
+ expect(result.errors.length).toBe(0)
74
+ expect(result.code).toMatch('color: red;')
75
+ expect(result.map).toBeTruthy()
76
+ })
77
+
78
+ test('preprocess stylus', () => {
79
+ const style = parse({
80
+ source:
81
+ '<style lang="styl">\n' +
82
+ 'red-color = rgb(255, 0, 0);\n' +
83
+ '.color\n' +
84
+ ' color: red-color\n' +
85
+ '</style>\n',
86
+ filename: 'example.vue',
87
+ sourceMap: true
88
+ }).styles[0]
89
+ const result = compileStyle({
90
+ id: 'v-scope-xxx',
91
+ filename: 'example.vue',
92
+ source: style.content,
93
+ map: style.map,
94
+ scoped: false,
95
+ preprocessLang: style.lang
96
+ })
97
+
98
+ expect(result.errors.length).toBe(0)
99
+ expect(result.code).toEqual(expect.stringContaining('color: #f00;'))
100
+ expect(result.map).toBeTruthy()
101
+ })
102
+
103
+ test('custom postcss plugin', () => {
104
+ const spy = vi.fn()
105
+
106
+ compileStyle({
107
+ id: 'v-scope-xxx',
108
+ filename: 'example.vue',
109
+ source: '.foo { color: red }',
110
+ scoped: false,
111
+ postcssPlugins: [require('postcss').plugin('test-plugin', () => spy)()]
112
+ })
113
+
114
+ expect(spy).toHaveBeenCalled()
115
+ })
116
+
117
+ test('custom postcss options', () => {
118
+ const result = compileStyle({
119
+ id: 'v-scope-xxx',
120
+ filename: 'example.vue',
121
+ source: '.foo { color: red }',
122
+ scoped: false,
123
+ postcssOptions: { random: 'foo' }
124
+ })
125
+
126
+ expect((result.rawResult as any).opts.random).toBe('foo')
127
+ })
128
+
129
+ test('async postcss plugin in sync mode', () => {
130
+ const result = compileStyle({
131
+ id: 'v-scope-xxx',
132
+ filename: 'example.vue',
133
+ source: '.foo { color: red }',
134
+ scoped: false,
135
+ postcssPlugins: [
136
+ require('postcss').plugin(
137
+ 'test-plugin',
138
+ () => async (result: any) => result
139
+ )
140
+ ]
141
+ })
142
+
143
+ expect(result.errors).toHaveLength(1)
144
+ })
145
+
146
+ test('async postcss plugin', async () => {
147
+ const promise = compileStyleAsync({
148
+ id: 'v-scope-xxx',
149
+ filename: 'example.vue',
150
+ source: '.foo { color: red }',
151
+ scoped: false,
152
+ postcssPlugins: [
153
+ require('postcss').plugin(
154
+ 'test-plugin',
155
+ () => async (result: any) => result
156
+ )
157
+ ]
158
+ })
159
+
160
+ expect(promise instanceof Promise).toBe(true)
161
+
162
+ const result = await promise
163
+ expect(result.errors).toHaveLength(0)
164
+ expect(result.code).toEqual(expect.stringContaining('color: red'))
165
+ })
166
+
167
+ test('media query', () => {
168
+ const result = compileStyle({
169
+ id: 'v-scope-xxx',
170
+ scoped: true,
171
+ filename: 'example.vue',
172
+ source: `
173
+ @media print {
174
+ .foo {
175
+ color: #000;
176
+ }
177
+ }`
178
+ })
179
+
180
+ expect(result.errors).toHaveLength(0)
181
+ expect(result.code).toContain(
182
+ '@media print {\n.foo[v-scope-xxx] {\n color: #000;\n}\n}'
183
+ )
184
+ })
185
+
186
+ test('supports query', () => {
187
+ const result = compileStyle({
188
+ id: 'v-scope-xxx',
189
+ scoped: true,
190
+ filename: 'example.vue',
191
+ source: `
192
+ @supports ( color: #000 ) {
193
+ .foo {
194
+ color: #000;
195
+ }
196
+ }`
197
+ })
198
+
199
+ expect(result.errors).toHaveLength(0)
200
+ expect(result.code).toContain(
201
+ '@supports ( color: #000 ) {\n.foo[v-scope-xxx] {\n color: #000;\n}\n}'
202
+ )
203
+ })
@@ -0,0 +1,258 @@
1
+ import { parse } from '../src/parse'
2
+ import { SFCBlock } from '../src/parseComponent'
3
+ import { compileTemplate } from '../src/compileTemplate'
4
+ import Vue from 'vue'
5
+
6
+ function mockRender(code: string, mocks: Record<string, any> = {}) {
7
+ const fn = new Function(
8
+ `require`,
9
+ `${code}; return { render, staticRenderFns }`
10
+ )
11
+ const vm = new Vue(
12
+ Object.assign(
13
+ {},
14
+ fn((id: string) => mocks[id])
15
+ )
16
+ )
17
+ vm.$mount()
18
+ return (vm as any)._vnode
19
+ }
20
+
21
+ test('should work', () => {
22
+ const source = `<div><p>{{ render }}</p></div>`
23
+
24
+ const result = compileTemplate({
25
+ filename: 'example.vue',
26
+ source
27
+ })
28
+
29
+ expect(result.errors.length).toBe(0)
30
+ expect(result.source).toBe(source)
31
+ // should expose render fns
32
+ expect(result.code).toMatch(`var render = function`)
33
+ expect(result.code).toMatch(`var staticRenderFns = []`)
34
+ // should mark with stripped
35
+ expect(result.code).toMatch(`render._withStripped = true`)
36
+ // should prefix bindings
37
+ expect(result.code).toMatch(`_vm.render`)
38
+ expect(result.ast).not.toBeUndefined()
39
+ })
40
+
41
+ test('preprocess pug', () => {
42
+ const template = parse({
43
+ source:
44
+ '<template lang="pug">\n' +
45
+ 'body\n' +
46
+ ' h1 Pug Examples\n' +
47
+ ' div.container\n' +
48
+ ' p Cool Pug example!\n' +
49
+ '</template>\n',
50
+ filename: 'example.vue',
51
+ sourceMap: true
52
+ }).template as SFCBlock
53
+
54
+ const result = compileTemplate({
55
+ filename: 'example.vue',
56
+ source: template.content,
57
+ preprocessLang: template.lang
58
+ })
59
+
60
+ expect(result.errors.length).toBe(0)
61
+ })
62
+
63
+ /**
64
+ * vuejs/component-compiler-utils#22 Support uri fragment in transformed require
65
+ */
66
+ test('supports uri fragment in transformed require', () => {
67
+ const source = '<svg>\
68
+ <use href="~@svg/file.svg#fragment"></use>\
69
+ </svg>' //
70
+ const result = compileTemplate({
71
+ filename: 'svgparticle.html',
72
+ source: source,
73
+ transformAssetUrls: {
74
+ use: 'href'
75
+ }
76
+ })
77
+ expect(result.errors.length).toBe(0)
78
+ expect(result.code).toMatch(
79
+ /href: require\("@svg\/file.svg"\) \+ "#fragment"/
80
+ )
81
+ })
82
+
83
+ /**
84
+ * vuejs/component-compiler-utils#22 Support uri fragment in transformed require
85
+ */
86
+ test('when too short uri then empty require', () => {
87
+ const source = '<svg>\
88
+ <use href="~"></use>\
89
+ </svg>' //
90
+ const result = compileTemplate({
91
+ filename: 'svgparticle.html',
92
+ source: source,
93
+ transformAssetUrls: {
94
+ use: 'href'
95
+ }
96
+ })
97
+ expect(result.errors.length).toBe(0)
98
+ expect(result.code).toMatch(/href: require\(""\)/)
99
+ })
100
+
101
+ test('warn missing preprocessor', () => {
102
+ const template = parse({
103
+ source: '<template lang="unknownLang">\n' + '</template>\n',
104
+
105
+ filename: 'example.vue',
106
+ sourceMap: true
107
+ }).template as SFCBlock
108
+
109
+ const result = compileTemplate({
110
+ filename: 'example.vue',
111
+ source: template.content,
112
+ preprocessLang: template.lang
113
+ })
114
+
115
+ expect(result.errors.length).toBe(1)
116
+ })
117
+
118
+ test('transform assetUrls', () => {
119
+ const source = `
120
+ <div>
121
+ <img src="./logo.png">
122
+ <img src="~fixtures/logo.png">
123
+ <img src="~/fixtures/logo.png">
124
+ </div>
125
+ `
126
+ const result = compileTemplate({
127
+ filename: 'example.vue',
128
+ source,
129
+ transformAssetUrls: true
130
+ })
131
+ expect(result.errors.length).toBe(0)
132
+
133
+ const vnode = mockRender(result.code, {
134
+ './logo.png': 'a',
135
+ 'fixtures/logo.png': 'b'
136
+ })
137
+
138
+ expect(vnode.children[0].data.attrs.src).toBe('a')
139
+ expect(vnode.children[2].data.attrs.src).toBe('b')
140
+ expect(vnode.children[4].data.attrs.src).toBe('b')
141
+ })
142
+
143
+ test('transform srcset', () => {
144
+ const source = `
145
+ <div>
146
+ <img src="./logo.png">
147
+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink= "http://www.w3.org/1999/xlink">
148
+ <image xlink:href="./logo.png" />
149
+ </svg>
150
+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink= "http://www.w3.org/1999/xlink">
151
+ <use xlink:href="./logo.png"/>
152
+ </svg>
153
+ </svg>
154
+ <img src="./logo.png" srcset="./logo.png">
155
+ <img src="./logo.png" srcset="./logo.png 2x">
156
+ <img src="./logo.png" srcset="./logo.png, ./logo.png 2x">
157
+ <img src="./logo.png" srcset="./logo.png 2x, ./logo.png">
158
+ <img src="./logo.png" srcset="./logo.png 2x, ./logo.png 3x">
159
+ <img src="./logo.png" srcset="./logo.png, ./logo.png 2x, ./logo.png 3x">
160
+ <img
161
+ src="./logo.png"
162
+ srcset="
163
+ ./logo.png 2x,
164
+ ./logo.png 3x
165
+ ">
166
+ </div>
167
+ `
168
+ const result = compileTemplate({
169
+ filename: 'example.vue',
170
+ source,
171
+ transformAssetUrls: true
172
+ })
173
+ expect(result.errors.length).toBe(0)
174
+
175
+ const vnode = mockRender(result.code, {
176
+ './logo.png': 'test-url'
177
+ })
178
+
179
+ // img tag
180
+ expect(vnode.children[0].data.attrs.src).toBe('test-url')
181
+ // image tag (SVG)
182
+ expect(vnode.children[2].children[0].data.attrs['xlink:href']).toBe(
183
+ 'test-url'
184
+ )
185
+ // use tag (SVG)
186
+ expect(vnode.children[4].children[0].data.attrs['xlink:href']).toBe(
187
+ 'test-url'
188
+ )
189
+
190
+ // image tag with srcset
191
+ expect(vnode.children[6].data.attrs.srcset).toBe('test-url')
192
+ expect(vnode.children[8].data.attrs.srcset).toBe('test-url 2x')
193
+ // image tag with multiline srcset
194
+ expect(vnode.children[10].data.attrs.srcset).toBe('test-url, test-url 2x')
195
+ expect(vnode.children[12].data.attrs.srcset).toBe('test-url 2x, test-url')
196
+ expect(vnode.children[14].data.attrs.srcset).toBe('test-url 2x, test-url 3x')
197
+ expect(vnode.children[16].data.attrs.srcset).toBe(
198
+ 'test-url, test-url 2x, test-url 3x'
199
+ )
200
+ expect(vnode.children[18].data.attrs.srcset).toBe('test-url 2x, test-url 3x')
201
+ })
202
+
203
+ test('transform assetUrls and srcset with base option', () => {
204
+ const source = `
205
+ <div>
206
+ <img src="./logo.png">
207
+ <img src="~fixtures/logo.png">
208
+ <img src="~/fixtures/logo.png">
209
+ <img src="./logo.png" srcset="./logo.png 2x, ./logo.png 3x">
210
+ <img src="@/fixtures/logo.png">
211
+ </div>
212
+ `
213
+ const result = compileTemplate({
214
+ filename: 'example.vue',
215
+ source,
216
+ transformAssetUrls: true,
217
+ transformAssetUrlsOptions: { base: '/base/' }
218
+ })
219
+
220
+ expect(result.errors.length).toBe(0)
221
+
222
+ const vnode = mockRender(result.code, {
223
+ '@/fixtures/logo.png': 'aliased'
224
+ })
225
+ expect(vnode.children[0].data.attrs.src).toBe('/base/logo.png')
226
+ expect(vnode.children[2].data.attrs.src).toBe('/base/fixtures/logo.png')
227
+ expect(vnode.children[4].data.attrs.src).toBe('/base/fixtures/logo.png')
228
+ expect(vnode.children[6].data.attrs.srcset).toBe(
229
+ '/base/logo.png 2x, /base/logo.png 3x'
230
+ )
231
+ expect(vnode.children[8].data.attrs.src).toBe('aliased')
232
+ })
233
+
234
+ test('transform with includeAbsolute', () => {
235
+ const source = `
236
+ <div>
237
+ <img src="./logo.png">
238
+ <img src="/logo.png">
239
+ <img src="https://foo.com/logo.png">
240
+ </div>
241
+ `
242
+ const result = compileTemplate({
243
+ filename: 'example.vue',
244
+ source,
245
+ transformAssetUrls: true,
246
+ transformAssetUrlsOptions: { includeAbsolute: true }
247
+ })
248
+
249
+ expect(result.errors.length).toBe(0)
250
+
251
+ const vnode = mockRender(result.code, {
252
+ './logo.png': 'relative',
253
+ '/logo.png': 'absolute'
254
+ })
255
+ expect(vnode.children[0].data.attrs.src).toBe('relative')
256
+ expect(vnode.children[2].data.attrs.src).toBe('absolute')
257
+ expect(vnode.children[4].data.attrs.src).toBe('https://foo.com/logo.png')
258
+ })
@@ -0,0 +1,247 @@
1
+ import { compileStyle, parse } from '../src'
2
+ import { mockId, compile, assertCode } from './util'
3
+
4
+ describe('CSS vars injection', () => {
5
+ test('generating correct code for nested paths', () => {
6
+ const { content } = compile(
7
+ `<script>const a = 1</script>\n` +
8
+ `<style>div{
9
+ color: v-bind(color);
10
+ font-size: v-bind('font.size');
11
+ }</style>`
12
+ )
13
+ expect(content).toMatch(`_useCssVars((_vm, _setup) => ({
14
+ "${mockId}-color": (_vm.color),
15
+ "${mockId}-font_size": (_vm.font.size)
16
+ })`)
17
+ assertCode(content)
18
+ })
19
+
20
+ test('w/ normal <script> binding analysis', () => {
21
+ const { content } = compile(
22
+ `<script>
23
+ export default {
24
+ setup() {
25
+ return {
26
+ size: ref('100px')
27
+ }
28
+ }
29
+ }
30
+ </script>\n` +
31
+ `<style>
32
+ div {
33
+ font-size: v-bind(size);
34
+ }
35
+ </style>`
36
+ )
37
+ expect(content).toMatch(`_useCssVars((_vm, _setup) => ({
38
+ "${mockId}-size": (_vm.size)
39
+ })`)
40
+ expect(content).toMatch(`import { useCssVars as _useCssVars } from 'vue'`)
41
+ assertCode(content)
42
+ })
43
+
44
+ test('w/ <script setup> binding analysis', () => {
45
+ const { content } = compile(
46
+ `<script setup>
47
+ import { defineProps, ref } from 'vue'
48
+ const color = 'red'
49
+ const size = ref('10px')
50
+ defineProps({
51
+ foo: String
52
+ })
53
+ </script>\n` +
54
+ `<style>
55
+ div {
56
+ color: v-bind(color);
57
+ font-size: v-bind(size);
58
+ border: v-bind(foo);
59
+ }
60
+ </style>`
61
+ )
62
+ // should handle:
63
+ // 1. local const bindings
64
+ // 2. local potential ref bindings
65
+ // 3. props bindings (analyzed)
66
+ expect(content).toMatch(`_useCssVars((_vm, _setup) => ({
67
+ "${mockId}-color": (_setup.color),
68
+ "${mockId}-size": (_setup.size),
69
+ "${mockId}-foo": (_vm.foo)
70
+ })`)
71
+ expect(content).toMatch(`import { useCssVars as _useCssVars } from 'vue'`)
72
+ assertCode(content)
73
+ })
74
+
75
+ test('should rewrite CSS vars in compileStyle', () => {
76
+ const { code } = compileStyle({
77
+ source: `.foo {
78
+ color: v-bind(color);
79
+ font-size: v-bind('font.size');
80
+ }`,
81
+ filename: 'test.css',
82
+ id: 'data-v-test'
83
+ })
84
+ expect(code).toMatchInlineSnapshot(`
85
+ ".foo[data-v-test] {
86
+ color: var(--test-color);
87
+ font-size: var(--test-font_size);
88
+ }"
89
+ `)
90
+ })
91
+
92
+ test('prod mode', () => {
93
+ const { content } = compile(
94
+ `<script>const a = 1</script>\n` +
95
+ `<style>div{
96
+ color: v-bind(color);
97
+ font-size: v-bind('font.size');
98
+ }</style>`,
99
+ { isProd: true }
100
+ )
101
+ expect(content).toMatch(`_useCssVars((_vm, _setup) => ({
102
+ "4003f1a6": (_vm.color),
103
+ "41b6490a": (_vm.font.size)
104
+ }))}`)
105
+
106
+ const { code } = compileStyle({
107
+ source: `.foo {
108
+ color: v-bind(color);
109
+ font-size: v-bind('font.size');
110
+ }`,
111
+ filename: 'test.css',
112
+ id: mockId,
113
+ isProd: true
114
+ })
115
+ expect(code).toMatchInlineSnapshot(`
116
+ ".foo[xxxxxxxx] {
117
+ color: var(--4003f1a6);
118
+ font-size: var(--41b6490a);
119
+ }"
120
+ `)
121
+ })
122
+
123
+ describe('codegen', () => {
124
+ test('<script> w/ no default export', () => {
125
+ assertCode(
126
+ compile(
127
+ `<script>const a = 1</script>\n` +
128
+ `<style>div{ color: v-bind(color); }</style>`
129
+ ).content
130
+ )
131
+ })
132
+
133
+ test('<script> w/ default export', () => {
134
+ assertCode(
135
+ compile(
136
+ `<script>export default { setup() {} }</script>\n` +
137
+ `<style>div{ color: v-bind(color); }</style>`
138
+ ).content
139
+ )
140
+ })
141
+
142
+ test('<script> w/ default export in strings/comments', () => {
143
+ assertCode(
144
+ compile(
145
+ `<script>
146
+ // export default {}
147
+ export default {}
148
+ </script>\n` + `<style>div{ color: v-bind(color); }</style>`
149
+ ).content
150
+ )
151
+ })
152
+
153
+ test('w/ <script setup>', () => {
154
+ assertCode(
155
+ compile(
156
+ `<script setup>const color = 'red'</script>\n` +
157
+ `<style>div{ color: v-bind(color); }</style>`
158
+ ).content
159
+ )
160
+ })
161
+
162
+ //#4185
163
+ test('should ignore comments', () => {
164
+ const { content } = compile(
165
+ `<script setup>const color = 'red';const width = 100</script>\n` +
166
+ `<style>
167
+ /* comment **/
168
+ div{ /* color: v-bind(color); */ width:20; }
169
+ div{ width: v-bind(width); }
170
+ /* comment */
171
+ </style>`
172
+ )
173
+
174
+ expect(content).not.toMatch(`"${mockId}-color": (_setup.color)`)
175
+ expect(content).toMatch(`"${mockId}-width": (_setup.width)`)
176
+ assertCode(content)
177
+ })
178
+
179
+ test('w/ <script setup> using the same var multiple times', () => {
180
+ const { content } = compile(
181
+ `<script setup>
182
+ const color = 'red'
183
+ </script>\n` +
184
+ `<style>
185
+ div {
186
+ color: v-bind(color);
187
+ }
188
+ p {
189
+ color: v-bind(color);
190
+ }
191
+ </style>`
192
+ )
193
+ // color should only be injected once, even if it is twice in style
194
+ expect(content).toMatch(`_useCssVars((_vm, _setup) => ({
195
+ "${mockId}-color": (_setup.color)
196
+ })`)
197
+ assertCode(content)
198
+ })
199
+
200
+ test('should work with w/ complex expression', () => {
201
+ const { content } = compile(
202
+ `<script setup>
203
+ let a = 100
204
+ let b = 200
205
+ let foo = 300
206
+ </script>\n` +
207
+ `<style>
208
+ p{
209
+ width: calc(v-bind(foo) - 3px);
210
+ height: calc(v-bind('foo') - 3px);
211
+ top: calc(v-bind(foo + 'px') - 3px);
212
+ }
213
+ div {
214
+ color: v-bind((a + b) / 2 + 'px' );
215
+ }
216
+ div {
217
+ color: v-bind ((a + b) / 2 + 'px' );
218
+ }
219
+ p {
220
+ color: v-bind(((a + b)) / (2 * a));
221
+ }
222
+ </style>`
223
+ )
224
+ expect(content).toMatch(`_useCssVars((_vm, _setup) => ({
225
+ "${mockId}-foo": (_setup.foo),
226
+ "${mockId}-foo____px_": (_setup.foo + 'px'),
227
+ "${mockId}-_a___b____2____px_": ((_setup.a + _setup.b) / 2 + 'px'),
228
+ "${mockId}-__a___b______2___a_": (((_setup.a + _setup.b)) / (2 * _setup.a))
229
+ })`)
230
+ assertCode(content)
231
+ })
232
+
233
+ // #6022
234
+ test('should be able to parse incomplete expressions', () => {
235
+ const { cssVars } = parse({
236
+ source: `<script setup>let xxx = 1</script>
237
+ <style scoped>
238
+ label {
239
+ font-weight: v-bind("count.toString(");
240
+ font-weight: v-bind(xxx);
241
+ }
242
+ </style>`
243
+ })
244
+ expect(cssVars).toMatchObject([`count.toString(`, `xxx`])
245
+ })
246
+ })
247
+ })