forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomponent-normalizer.js
More file actions
100 lines (89 loc) · 2.85 KB
/
component-normalizer.js
File metadata and controls
100 lines (89 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* eslint-disable */
/* globals __VUE_SSR_CONTEXT__ */
// IMPORTANT: Do NOT use ES2015 features in this file.
// This module is a runtime utility for cleaner component module output and will
// be included in the final webpack user bundle.
module.exports = function normalizeComponent(
rawScriptExports,
compiledTemplate,
functionalTemplate,
injectStyles,
scopeId,
moduleIdentifier /* server only */
) {
var esModule;
var scriptExports = (rawScriptExports = rawScriptExports || {});
// ES6 modules interop
var type = typeof rawScriptExports.default;
if (type === 'object' || type === 'function') {
esModule = rawScriptExports;
scriptExports = rawScriptExports.default;
}
// Vue.extend constructor export interop
var options =
typeof scriptExports === 'function' ? scriptExports.options : scriptExports;
// render functions
if (compiledTemplate) {
options.render = compiledTemplate.render;
options.staticRenderFns = compiledTemplate.staticRenderFns;
options._compiled = true;
}
// functional template
if (functionalTemplate) {
options.functional = true;
}
// scopedId
if (scopeId) {
options._scopeId = scopeId;
}
var hook;
if (moduleIdentifier) {
// server build
hook = function(context) {
// 2.3 injection
context =
context || // cached call
(this.$vnode && this.$vnode.ssrContext) || // stateful
(this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext); // functional
// 2.2 with runInNewContext: true
if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
context = __VUE_SSR_CONTEXT__;
}
// inject component styles
if (injectStyles) {
injectStyles.call(this, context);
}
// register component module identifier for async chunk inferrence
if (context && context._registeredComponents) {
context._registeredComponents.add(moduleIdentifier);
}
};
// used by ssr in case component is cached and beforeCreate
// never gets called
options._ssrRegister = hook;
} else if (injectStyles) {
hook = injectStyles;
}
if (hook) {
var functional = options.functional;
var existing = functional ? options.render : options.beforeCreate;
if (!functional) {
// inject component registration as beforeCreate hook
options.beforeCreate = existing ? [].concat(existing, hook) : [hook];
} else {
// for template-only hot-reload because in that case the render fn doesn't
// go through the normalizer
options._injectStyles = hook;
// register for functioal component in vue file
options.render = function renderWithStyleInjection(h, context) {
hook.call(context);
return existing(h, context);
};
}
}
return {
esModule: esModule,
exports: scriptExports,
options: options,
};
};