@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,147 @@
1
+ const postcss = require('postcss')
2
+ import { ProcessOptions, LazyResult } from 'postcss'
3
+ import trimPlugin from './stylePlugins/trim'
4
+ import scopedPlugin from './stylePlugins/scoped'
5
+ import {
6
+ processors,
7
+ StylePreprocessor,
8
+ StylePreprocessorResults
9
+ } from './stylePreprocessors'
10
+ import { cssVarsPlugin } from './cssVars'
11
+
12
+ export interface SFCStyleCompileOptions {
13
+ source: string
14
+ filename: string
15
+ id: string
16
+ map?: any
17
+ scoped?: boolean
18
+ trim?: boolean
19
+ preprocessLang?: string
20
+ preprocessOptions?: any
21
+ postcssOptions?: any
22
+ postcssPlugins?: any[]
23
+ isProd?: boolean
24
+ }
25
+
26
+ export interface SFCAsyncStyleCompileOptions extends SFCStyleCompileOptions {
27
+ isAsync?: boolean
28
+ }
29
+
30
+ export interface SFCStyleCompileResults {
31
+ code: string
32
+ map: any | void
33
+ rawResult: LazyResult | void
34
+ errors: string[]
35
+ }
36
+
37
+ export function compileStyle(
38
+ options: SFCStyleCompileOptions
39
+ ): SFCStyleCompileResults {
40
+ return doCompileStyle({ ...options, isAsync: false })
41
+ }
42
+
43
+ export function compileStyleAsync(
44
+ options: SFCStyleCompileOptions
45
+ ): Promise<SFCStyleCompileResults> {
46
+ return Promise.resolve(doCompileStyle({ ...options, isAsync: true }))
47
+ }
48
+
49
+ export function doCompileStyle(
50
+ options: SFCAsyncStyleCompileOptions
51
+ ): SFCStyleCompileResults {
52
+ const {
53
+ filename,
54
+ id,
55
+ scoped = true,
56
+ trim = true,
57
+ isProd = false,
58
+ preprocessLang,
59
+ postcssOptions,
60
+ postcssPlugins
61
+ } = options
62
+ const preprocessor = preprocessLang && processors[preprocessLang]
63
+ const preProcessedSource = preprocessor && preprocess(options, preprocessor)
64
+ const map = preProcessedSource ? preProcessedSource.map : options.map
65
+ const source = preProcessedSource ? preProcessedSource.code : options.source
66
+
67
+ const plugins = (postcssPlugins || []).slice()
68
+ plugins.unshift(cssVarsPlugin({ id: id.replace(/^data-v-/, ''), isProd }))
69
+ if (trim) {
70
+ plugins.push(trimPlugin())
71
+ }
72
+ if (scoped) {
73
+ plugins.push(scopedPlugin(id))
74
+ }
75
+
76
+ const postCSSOptions: ProcessOptions = {
77
+ ...postcssOptions,
78
+ to: filename,
79
+ from: filename
80
+ }
81
+ if (map) {
82
+ postCSSOptions.map = {
83
+ inline: false,
84
+ annotation: false,
85
+ prev: map
86
+ }
87
+ }
88
+
89
+ let result, code, outMap
90
+ const errors: any[] = []
91
+ if (preProcessedSource && preProcessedSource.errors.length) {
92
+ errors.push(...preProcessedSource.errors)
93
+ }
94
+ try {
95
+ result = postcss(plugins).process(source, postCSSOptions)
96
+
97
+ // In async mode, return a promise.
98
+ if (options.isAsync) {
99
+ return result
100
+ .then(
101
+ (result: LazyResult): SFCStyleCompileResults => ({
102
+ code: result.css || '',
103
+ map: result.map && result.map.toJSON(),
104
+ errors,
105
+ rawResult: result
106
+ })
107
+ )
108
+ .catch(
109
+ (error: Error): SFCStyleCompileResults => ({
110
+ code: '',
111
+ map: undefined,
112
+ errors: [...errors, error.message],
113
+ rawResult: undefined
114
+ })
115
+ )
116
+ }
117
+
118
+ // force synchronous transform (we know we only have sync plugins)
119
+ code = result.css
120
+ outMap = result.map
121
+ } catch (e) {
122
+ errors.push(e)
123
+ }
124
+
125
+ return {
126
+ code: code || ``,
127
+ map: outMap && outMap.toJSON(),
128
+ errors,
129
+ rawResult: result
130
+ }
131
+ }
132
+
133
+ function preprocess(
134
+ options: SFCStyleCompileOptions,
135
+ preprocessor: StylePreprocessor
136
+ ): StylePreprocessorResults {
137
+ return preprocessor(
138
+ options.source,
139
+ options.map,
140
+ Object.assign(
141
+ {
142
+ filename: options.filename
143
+ },
144
+ options.preprocessOptions
145
+ )
146
+ )
147
+ }
@@ -0,0 +1,205 @@
1
+ import { BindingMetadata, TemplateCompiler } from './types'
2
+ import assetUrlsModule, {
3
+ AssetURLOptions,
4
+ TransformAssetUrlsOptions
5
+ } from './templateCompilerModules/assetUrl'
6
+ import srcsetModule from './templateCompilerModules/srcset'
7
+ import consolidate from '@vue/consolidate'
8
+ import * as _compiler from 'web/entry-compiler'
9
+ import { prefixIdentifiers } from './prefixIdentifiers'
10
+ import { CompilerOptions, WarningMessage } from 'types/compiler'
11
+
12
+ export interface SFCTemplateCompileOptions {
13
+ source: string
14
+ filename: string
15
+ compiler?: TemplateCompiler
16
+ compilerOptions?: CompilerOptions
17
+ transformAssetUrls?: AssetURLOptions | boolean
18
+ transformAssetUrlsOptions?: TransformAssetUrlsOptions
19
+ preprocessLang?: string
20
+ preprocessOptions?: any
21
+ transpileOptions?: any
22
+ isProduction?: boolean
23
+ isFunctional?: boolean
24
+ optimizeSSR?: boolean
25
+ prettify?: boolean
26
+ isTS?: boolean
27
+ bindings?: BindingMetadata
28
+ }
29
+
30
+ export interface SFCTemplateCompileResults {
31
+ ast: Object | undefined
32
+ code: string
33
+ source: string
34
+ tips: (string | WarningMessage)[]
35
+ errors: (string | WarningMessage)[]
36
+ }
37
+
38
+ export function compileTemplate(
39
+ options: SFCTemplateCompileOptions
40
+ ): SFCTemplateCompileResults {
41
+ const { preprocessLang } = options
42
+ const preprocessor = preprocessLang && consolidate[preprocessLang]
43
+ if (preprocessor) {
44
+ return actuallyCompile(
45
+ Object.assign({}, options, {
46
+ source: preprocess(options, preprocessor)
47
+ })
48
+ )
49
+ } else if (preprocessLang) {
50
+ return {
51
+ ast: {},
52
+ code: `var render = function () {}\n` + `var staticRenderFns = []\n`,
53
+ source: options.source,
54
+ tips: [
55
+ `Component ${options.filename} uses lang ${preprocessLang} for template. Please install the language preprocessor.`
56
+ ],
57
+ errors: [
58
+ `Component ${options.filename} uses lang ${preprocessLang} for template, however it is not installed.`
59
+ ]
60
+ }
61
+ } else {
62
+ return actuallyCompile(options)
63
+ }
64
+ }
65
+
66
+ function preprocess(
67
+ options: SFCTemplateCompileOptions,
68
+ preprocessor: any
69
+ ): string {
70
+ const { source, filename, preprocessOptions } = options
71
+
72
+ const finalPreprocessOptions = Object.assign(
73
+ {
74
+ filename
75
+ },
76
+ preprocessOptions
77
+ )
78
+
79
+ // Consolidate exposes a callback based API, but the callback is in fact
80
+ // called synchronously for most templating engines. In our case, we have to
81
+ // expose a synchronous API so that it is usable in Jest transforms (which
82
+ // have to be sync because they are applied via Node.js require hooks)
83
+ let res: any, err
84
+ preprocessor.render(
85
+ source,
86
+ finalPreprocessOptions,
87
+ (_err: Error | null, _res: string) => {
88
+ if (_err) err = _err
89
+ res = _res
90
+ }
91
+ )
92
+
93
+ if (err) throw err
94
+ return res
95
+ }
96
+
97
+ function actuallyCompile(
98
+ options: SFCTemplateCompileOptions
99
+ ): SFCTemplateCompileResults {
100
+ const {
101
+ source,
102
+ compiler = _compiler,
103
+ compilerOptions = {},
104
+ transpileOptions = {},
105
+ transformAssetUrls,
106
+ transformAssetUrlsOptions,
107
+ isProduction = process.env.NODE_ENV === 'production',
108
+ isFunctional = false,
109
+ optimizeSSR = false,
110
+ prettify = true,
111
+ isTS = false,
112
+ bindings
113
+ } = options
114
+
115
+ const compile =
116
+ optimizeSSR && compiler.ssrCompile ? compiler.ssrCompile : compiler.compile
117
+
118
+ let finalCompilerOptions = compilerOptions
119
+ if (transformAssetUrls) {
120
+ const builtInModules = [
121
+ transformAssetUrls === true
122
+ ? assetUrlsModule(undefined, transformAssetUrlsOptions)
123
+ : assetUrlsModule(transformAssetUrls, transformAssetUrlsOptions),
124
+ srcsetModule(transformAssetUrlsOptions)
125
+ ]
126
+ finalCompilerOptions = Object.assign({}, compilerOptions, {
127
+ modules: [...builtInModules, ...(compilerOptions.modules || [])],
128
+ filename: options.filename
129
+ })
130
+ }
131
+ finalCompilerOptions.bindings = bindings
132
+
133
+ const { ast, render, staticRenderFns, tips, errors } = compile(
134
+ source,
135
+ finalCompilerOptions
136
+ )
137
+
138
+ if (errors && errors.length) {
139
+ return {
140
+ ast,
141
+ code: `var render = function () {}\n` + `var staticRenderFns = []\n`,
142
+ source,
143
+ tips,
144
+ errors
145
+ }
146
+ } else {
147
+ // stripping `with` usage
148
+ let code =
149
+ `var __render__ = ${prefixIdentifiers(
150
+ `function render(${isFunctional ? `_c,_vm` : ``}){${render}\n}`,
151
+ isFunctional,
152
+ isTS,
153
+ transpileOptions,
154
+ bindings
155
+ )}\n` +
156
+ `var __staticRenderFns__ = [${staticRenderFns.map(code =>
157
+ prefixIdentifiers(
158
+ `function (${isFunctional ? `_c,_vm` : ``}){${code}\n}`,
159
+ isFunctional,
160
+ isTS,
161
+ transpileOptions,
162
+ bindings
163
+ )
164
+ )}]` +
165
+ `\n`
166
+
167
+ // #23 we use __render__ to avoid `render` not being prefixed by the
168
+ // transpiler when stripping with, but revert it back to `render` to
169
+ // maintain backwards compat
170
+ code = code.replace(/\s__(render|staticRenderFns)__\s/g, ' $1 ')
171
+
172
+ if (!isProduction) {
173
+ // mark with stripped (this enables Vue to use correct runtime proxy
174
+ // detection)
175
+ code += `render._withStripped = true`
176
+
177
+ if (prettify) {
178
+ try {
179
+ code = require('prettier').format(code, {
180
+ semi: false,
181
+ parser: 'babel'
182
+ })
183
+ } catch (e: any) {
184
+ if (e.code === 'MODULE_NOT_FOUND') {
185
+ tips.push(
186
+ 'The `prettify` option is on, but the dependency `prettier` is not found.\n' +
187
+ 'Please either turn off `prettify` or manually install `prettier`.'
188
+ )
189
+ }
190
+ tips.push(
191
+ `Failed to prettify component ${options.filename} template source after compilation.`
192
+ )
193
+ }
194
+ }
195
+ }
196
+
197
+ return {
198
+ ast,
199
+ code,
200
+ source,
201
+ tips,
202
+ errors
203
+ }
204
+ }
205
+ }
@@ -0,0 +1,179 @@
1
+ import { BindingMetadata } from './types'
2
+ import { SFCDescriptor } from './parseComponent'
3
+ import { PluginCreator } from 'postcss'
4
+ import hash from 'hash-sum'
5
+ import { prefixIdentifiers } from './prefixIdentifiers'
6
+
7
+ export const CSS_VARS_HELPER = `useCssVars`
8
+
9
+ export function genCssVarsFromList(
10
+ vars: string[],
11
+ id: string,
12
+ isProd: boolean,
13
+ isSSR = false
14
+ ): string {
15
+ return `{\n ${vars
16
+ .map(
17
+ key => `"${isSSR ? `--` : ``}${genVarName(id, key, isProd)}": (${key})`
18
+ )
19
+ .join(',\n ')}\n}`
20
+ }
21
+
22
+ function genVarName(id: string, raw: string, isProd: boolean): string {
23
+ if (isProd) {
24
+ return hash(id + raw)
25
+ } else {
26
+ return `${id}-${raw.replace(/([^\w-])/g, '_')}`
27
+ }
28
+ }
29
+
30
+ function normalizeExpression(exp: string) {
31
+ exp = exp.trim()
32
+ if (
33
+ (exp[0] === `'` && exp[exp.length - 1] === `'`) ||
34
+ (exp[0] === `"` && exp[exp.length - 1] === `"`)
35
+ ) {
36
+ return exp.slice(1, -1)
37
+ }
38
+ return exp
39
+ }
40
+
41
+ const vBindRE = /v-bind\s*\(/g
42
+
43
+ export function parseCssVars(sfc: SFCDescriptor): string[] {
44
+ const vars: string[] = []
45
+ sfc.styles.forEach(style => {
46
+ let match
47
+ // ignore v-bind() in comments /* ... */
48
+ const content = style.content.replace(/\/\*([\s\S]*?)\*\//g, '')
49
+ while ((match = vBindRE.exec(content))) {
50
+ const start = match.index + match[0].length
51
+ const end = lexBinding(content, start)
52
+ if (end !== null) {
53
+ const variable = normalizeExpression(content.slice(start, end))
54
+ if (!vars.includes(variable)) {
55
+ vars.push(variable)
56
+ }
57
+ }
58
+ }
59
+ })
60
+ return vars
61
+ }
62
+
63
+ const enum LexerState {
64
+ inParens,
65
+ inSingleQuoteString,
66
+ inDoubleQuoteString
67
+ }
68
+
69
+ function lexBinding(content: string, start: number): number | null {
70
+ let state: LexerState = LexerState.inParens
71
+ let parenDepth = 0
72
+
73
+ for (let i = start; i < content.length; i++) {
74
+ const char = content.charAt(i)
75
+ switch (state) {
76
+ case LexerState.inParens:
77
+ if (char === `'`) {
78
+ state = LexerState.inSingleQuoteString
79
+ } else if (char === `"`) {
80
+ state = LexerState.inDoubleQuoteString
81
+ } else if (char === `(`) {
82
+ parenDepth++
83
+ } else if (char === `)`) {
84
+ if (parenDepth > 0) {
85
+ parenDepth--
86
+ } else {
87
+ return i
88
+ }
89
+ }
90
+ break
91
+ case LexerState.inSingleQuoteString:
92
+ if (char === `'`) {
93
+ state = LexerState.inParens
94
+ }
95
+ break
96
+ case LexerState.inDoubleQuoteString:
97
+ if (char === `"`) {
98
+ state = LexerState.inParens
99
+ }
100
+ break
101
+ }
102
+ }
103
+ return null
104
+ }
105
+
106
+ // for compileStyle
107
+ export interface CssVarsPluginOptions {
108
+ id: string
109
+ isProd: boolean
110
+ }
111
+
112
+ export const cssVarsPlugin: PluginCreator<CssVarsPluginOptions> = opts => {
113
+ const { id, isProd } = opts!
114
+ return {
115
+ postcssPlugin: 'vue-sfc-vars',
116
+ Declaration(decl) {
117
+ // rewrite CSS variables
118
+ const value = decl.value
119
+ if (vBindRE.test(value)) {
120
+ vBindRE.lastIndex = 0
121
+ let transformed = ''
122
+ let lastIndex = 0
123
+ let match
124
+ while ((match = vBindRE.exec(value))) {
125
+ const start = match.index + match[0].length
126
+ const end = lexBinding(value, start)
127
+ if (end !== null) {
128
+ const variable = normalizeExpression(value.slice(start, end))
129
+ transformed +=
130
+ value.slice(lastIndex, match.index) +
131
+ `var(--${genVarName(id, variable, isProd)})`
132
+ lastIndex = end + 1
133
+ }
134
+ }
135
+ decl.value = transformed + value.slice(lastIndex)
136
+ }
137
+ }
138
+ }
139
+ }
140
+ cssVarsPlugin.postcss = true
141
+
142
+ export function genCssVarsCode(
143
+ vars: string[],
144
+ bindings: BindingMetadata,
145
+ id: string,
146
+ isProd: boolean
147
+ ) {
148
+ const varsExp = genCssVarsFromList(vars, id, isProd)
149
+ return `_${CSS_VARS_HELPER}((_vm, _setup) => ${prefixIdentifiers(
150
+ `(${varsExp})`,
151
+ false,
152
+ false,
153
+ undefined,
154
+ bindings
155
+ )})`
156
+ }
157
+
158
+ // <script setup> already gets the calls injected as part of the transform
159
+ // this is only for single normal <script>
160
+ export function genNormalScriptCssVarsCode(
161
+ cssVars: string[],
162
+ bindings: BindingMetadata,
163
+ id: string,
164
+ isProd: boolean
165
+ ): string {
166
+ return (
167
+ `\nimport { ${CSS_VARS_HELPER} as _${CSS_VARS_HELPER} } from 'vue'\n` +
168
+ `const __injectCSSVars__ = () => {\n${genCssVarsCode(
169
+ cssVars,
170
+ bindings,
171
+ id,
172
+ isProd
173
+ )}}\n` +
174
+ `const __setup__ = __default__.setup\n` +
175
+ `__default__.setup = __setup__\n` +
176
+ ` ? (props, ctx) => { __injectCSSVars__();return __setup__(props, ctx) }\n` +
177
+ ` : __injectCSSVars__\n`
178
+ )
179
+ }
@@ -0,0 +1,31 @@
1
+ // API
2
+ export { parse } from './parse'
3
+ export { compileTemplate } from './compileTemplate'
4
+ export { compileStyle, compileStyleAsync } from './compileStyle'
5
+ export { compileScript } from './compileScript'
6
+ export { generateCodeFrame } from 'compiler/codeframe'
7
+ export { rewriteDefault } from './rewriteDefault'
8
+
9
+ // For backwards compat only. Some existing tools like
10
+ // fork-ts-checker-webpack-plugin relies on its presence for differentiating
11
+ // between Vue 2 and Vue 3.
12
+ // ref #12719
13
+ // ref https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/issues/765
14
+ export { parseComponent } from './parseComponent'
15
+
16
+ // types
17
+ export { SFCParseOptions } from './parse'
18
+ export { CompilerOptions, WarningMessage } from 'types/compiler'
19
+ export { TemplateCompiler } from './types'
20
+ export {
21
+ SFCBlock,
22
+ SFCCustomBlock,
23
+ SFCScriptBlock,
24
+ SFCDescriptor
25
+ } from './parseComponent'
26
+ export {
27
+ SFCTemplateCompileOptions,
28
+ SFCTemplateCompileResults
29
+ } from './compileTemplate'
30
+ export { SFCStyleCompileOptions, SFCStyleCompileResults } from './compileStyle'
31
+ export { SFCScriptCompileOptions } from './compileScript'
@@ -0,0 +1,129 @@
1
+ import { SourceMapGenerator } from 'source-map'
2
+ import { RawSourceMap, TemplateCompiler } from './types'
3
+ import {
4
+ parseComponent,
5
+ VueTemplateCompilerParseOptions,
6
+ SFCDescriptor,
7
+ DEFAULT_FILENAME
8
+ } from './parseComponent'
9
+
10
+ import hash from 'hash-sum'
11
+ import LRU from 'lru-cache'
12
+ import { hmrShouldReload } from './compileScript'
13
+ import { parseCssVars } from './cssVars'
14
+
15
+ const cache = new LRU<string, SFCDescriptor>(100)
16
+
17
+ const splitRE = /\r?\n/g
18
+ const emptyRE = /^(?:\/\/)?\s*$/
19
+
20
+ export interface SFCParseOptions {
21
+ source: string
22
+ filename?: string
23
+ compiler?: TemplateCompiler
24
+ compilerParseOptions?: VueTemplateCompilerParseOptions
25
+ sourceRoot?: string
26
+ sourceMap?: boolean
27
+ /**
28
+ * @deprecated use `sourceMap` instead.
29
+ */
30
+ needMap?: boolean
31
+ }
32
+
33
+ export function parse(options: SFCParseOptions): SFCDescriptor {
34
+ const {
35
+ source,
36
+ filename = DEFAULT_FILENAME,
37
+ compiler,
38
+ compilerParseOptions = { pad: false } as VueTemplateCompilerParseOptions,
39
+ sourceRoot = '',
40
+ needMap = true,
41
+ sourceMap = needMap
42
+ } = options
43
+ const cacheKey = hash(
44
+ filename + source + JSON.stringify(compilerParseOptions)
45
+ )
46
+
47
+ let output = cache.get(cacheKey)
48
+ if (output) {
49
+ return output
50
+ }
51
+
52
+ if (compiler) {
53
+ // user-provided compiler
54
+ output = compiler.parseComponent(source, compilerParseOptions)
55
+ } else {
56
+ // use built-in compiler
57
+ output = parseComponent(source, compilerParseOptions)
58
+ }
59
+
60
+ output.filename = filename
61
+
62
+ // parse CSS vars
63
+ output.cssVars = parseCssVars(output)
64
+
65
+ output.shouldForceReload = prevImports =>
66
+ hmrShouldReload(prevImports, output!)
67
+
68
+ if (sourceMap) {
69
+ if (output.script && !output.script.src) {
70
+ output.script.map = generateSourceMap(
71
+ filename,
72
+ source,
73
+ output.script.content,
74
+ sourceRoot,
75
+ compilerParseOptions.pad
76
+ )
77
+ }
78
+ if (output.styles) {
79
+ output.styles.forEach(style => {
80
+ if (!style.src) {
81
+ style.map = generateSourceMap(
82
+ filename,
83
+ source,
84
+ style.content,
85
+ sourceRoot,
86
+ compilerParseOptions.pad
87
+ )
88
+ }
89
+ })
90
+ }
91
+ }
92
+
93
+ cache.set(cacheKey, output)
94
+ return output
95
+ }
96
+
97
+ function generateSourceMap(
98
+ filename: string,
99
+ source: string,
100
+ generated: string,
101
+ sourceRoot: string,
102
+ pad?: 'line' | 'space' | boolean
103
+ ): RawSourceMap {
104
+ const map = new SourceMapGenerator({
105
+ file: filename.replace(/\\/g, '/'),
106
+ sourceRoot: sourceRoot.replace(/\\/g, '/')
107
+ })
108
+ let offset = 0
109
+ if (!pad) {
110
+ offset = source.split(generated).shift()!.split(splitRE).length - 1
111
+ }
112
+ map.setSourceContent(filename, source)
113
+ generated.split(splitRE).forEach((line, index) => {
114
+ if (!emptyRE.test(line)) {
115
+ map.addMapping({
116
+ source: filename,
117
+ original: {
118
+ line: index + 1 + offset,
119
+ column: 0
120
+ },
121
+ generated: {
122
+ line: index + 1,
123
+ column: 0
124
+ }
125
+ })
126
+ }
127
+ })
128
+ return JSON.parse(map.toString())
129
+ }