marko 5.37.48 → 5.37.50
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/dist/runtime/helpers/tags-compat/runtime-dom.js +1 -1
- package/dist/runtime/helpers/tags-compat/runtime-html.js +94 -47
- package/dist/translator/index.js +35 -23
- package/dist/translator/util/add-dependencies.js +19 -8
- package/package.json +1 -1
- package/src/runtime/helpers/tags-compat/runtime-dom.js +1 -1
- package/src/runtime/helpers/tags-compat/runtime-html.js +86 -39
- package/src/translator/index.js +35 -23
- package/src/translator/util/add-dependencies.js +19 -8
@@ -50,7 +50,7 @@ exports.p = function (domCompat) {
|
|
50
50
|
const TagsCompat = createRenderer(
|
51
51
|
function (_, out, componentDef, component) {
|
52
52
|
const input = Array.isArray(_.i) ? _.i : [_.i];
|
53
|
-
const tagsRenderer = domCompat.resolveRegistered(_.r, global);
|
53
|
+
const tagsRenderer = domCompat.resolveRegistered(_.r, out.global);
|
54
54
|
const newNode = domCompat.render(out, component, tagsRenderer, input);
|
55
55
|
|
56
56
|
out.bf("1", component, !newNode);
|
@@ -10,43 +10,55 @@ const defaultCreateOut = require("../../createOut");
|
|
10
10
|
const dynamicTag5 = require("../dynamic-tag");
|
11
11
|
|
12
12
|
exports.p = function (htmlCompat) {
|
13
|
-
const
|
13
|
+
const writersByGlobal = new WeakMap();
|
14
14
|
const isMarko6 = (fn) => htmlCompat.isTagsAPI(fn);
|
15
15
|
const isMarko5 = (fn) => !isMarko6(fn);
|
16
|
-
const
|
17
|
-
const {
|
18
|
-
const $global = out.global;
|
19
|
-
const outs = outsByGlobal.get($global);
|
20
|
-
const writer = out._state.writer;
|
16
|
+
const writeClassAPIResultToTagsAPI = (result) => {
|
17
|
+
const { writer } = result.out._state;
|
21
18
|
htmlCompat.write(writer._content);
|
22
|
-
writer.
|
23
|
-
|
24
|
-
outs.push(out);
|
25
|
-
} else {
|
26
|
-
outsByGlobal.set($global, [out]);
|
27
|
-
}
|
19
|
+
htmlCompat.writeScript(writer._script);
|
20
|
+
writer._content = writer._scripts = "";
|
28
21
|
};
|
22
|
+
const flushScripts = ($global, flushDefs) => {
|
23
|
+
const writers = writersByGlobal.get($global);
|
24
|
+
if (!writers) return "";
|
29
25
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
if (outs) {
|
34
|
-
chunk.render(() => {
|
35
|
-
const defs = [];
|
36
|
-
outsByGlobal.delete($global);
|
37
|
-
for (const out of outs) {
|
38
|
-
if (out.b_) {
|
39
|
-
__(out.b_, defs);
|
40
|
-
}
|
26
|
+
const { classAPI, tagsAPI } = writers;
|
27
|
+
let scripts = "";
|
28
|
+
let componentDefs = flushDefs;
|
41
29
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
30
|
+
if (classAPI.length) {
|
31
|
+
componentDefs = flushDefs ? flushDefs.concat(classAPI) : classAPI;
|
32
|
+
writers.classAPI = [];
|
33
|
+
}
|
46
34
|
|
47
|
-
|
48
|
-
|
35
|
+
if (componentDefs) {
|
36
|
+
scripts = _g_($global, componentDefs);
|
49
37
|
}
|
38
|
+
|
39
|
+
if (tagsAPI.length) {
|
40
|
+
const [chunk] = tagsAPI;
|
41
|
+
for (let i = 1; i < tagsAPI.length; i++) {
|
42
|
+
chunk.append(tagsAPI[i]);
|
43
|
+
}
|
44
|
+
|
45
|
+
if (!chunk.boundary.done) {
|
46
|
+
throw new Error(
|
47
|
+
"Cannot serialize promise across tags/class compat layer."
|
48
|
+
);
|
49
|
+
}
|
50
|
+
|
51
|
+
scripts = concatScripts(chunk.flushScript().scripts, scripts);
|
52
|
+
writers.tagsAPI = [];
|
53
|
+
}
|
54
|
+
|
55
|
+
return scripts;
|
56
|
+
};
|
57
|
+
|
58
|
+
htmlCompat.onFlush((chunk) => {
|
59
|
+
chunk.render(() => {
|
60
|
+
chunk.writeScript(flushScripts(chunk.boundary.state.$global));
|
61
|
+
});
|
50
62
|
});
|
51
63
|
|
52
64
|
dynamicTag5.bo_ = function tagsToVdom(
|
@@ -58,22 +70,39 @@ exports.p = function (htmlCompat) {
|
|
58
70
|
return tagsRenderer;
|
59
71
|
}
|
60
72
|
|
61
|
-
|
62
|
-
renderBody
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
73
|
+
return (input, out) => {
|
74
|
+
if (!tagsRenderer && renderBody) {
|
75
|
+
renderBody.toJSON = htmlCompat.toJSON(
|
76
|
+
htmlCompat.ensureState(out.global)
|
77
|
+
);
|
78
|
+
}
|
79
|
+
TagsCompat(
|
80
|
+
args ?
|
81
|
+
{ i: args, r: (args) => (tagsRenderer || renderBody)(...args) } :
|
82
|
+
{ i: input, r: tagsRenderer || renderBody },
|
83
|
+
out
|
84
|
+
);
|
85
|
+
};
|
72
86
|
};
|
73
87
|
|
74
88
|
const TagsCompatId = "tags-compat";
|
75
89
|
const TagsCompat = createRenderer(
|
76
90
|
function (_, out, componentDef, component) {
|
91
|
+
// class to tags
|
92
|
+
const $global = out.global;
|
93
|
+
let writers = writersByGlobal.get($global);
|
94
|
+
if (!writers) {
|
95
|
+
writersByGlobal.set($global, writers = { classAPI: [], tagsAPI: [] });
|
96
|
+
out.prependListener("c_", (writer) => {
|
97
|
+
const defs = writer._data?.componentDefs;
|
98
|
+
const scripts = flushScripts($global, defs);
|
99
|
+
if (scripts) {
|
100
|
+
if (defs) writer._data.componentDefs = undefined;
|
101
|
+
writer.script(scripts);
|
102
|
+
}
|
103
|
+
});
|
104
|
+
}
|
105
|
+
|
77
106
|
const input = _.i;
|
78
107
|
const tagsRenderer = _.r;
|
79
108
|
const willRerender = componentDef._wrr || htmlCompat.isInResumedBranch();
|
@@ -83,8 +112,8 @@ exports.p = function (htmlCompat) {
|
|
83
112
|
willRerender,
|
84
113
|
out,
|
85
114
|
component,
|
86
|
-
input,
|
87
|
-
|
115
|
+
input,
|
116
|
+
writers.tagsAPI
|
88
117
|
);
|
89
118
|
out.ef();
|
90
119
|
},
|
@@ -118,7 +147,15 @@ exports.p = function (htmlCompat) {
|
|
118
147
|
htmlCompat.registerRenderBody(renderBody5);
|
119
148
|
}
|
120
149
|
return (input, ...args) => {
|
121
|
-
|
150
|
+
// tags to class
|
151
|
+
const $global = htmlCompat.$global();
|
152
|
+
const state = htmlCompat.ensureState($global);
|
153
|
+
let writers = writersByGlobal.get($global);
|
154
|
+
if (!writers) {
|
155
|
+
writersByGlobal.set($global, writers = { classAPI: [], tagsAPI: [] });
|
156
|
+
}
|
157
|
+
|
158
|
+
const out = defaultCreateOut($global);
|
122
159
|
const branchId = htmlCompat.nextScopeId();
|
123
160
|
let customEvents;
|
124
161
|
|
@@ -134,7 +171,7 @@ exports.p = function (htmlCompat) {
|
|
134
171
|
key[2] === "-" ? key.slice(3) : key.slice(2).toLowerCase(),
|
135
172
|
value]
|
136
173
|
);
|
137
|
-
value.toJSON = htmlCompat.toJSON;
|
174
|
+
value.toJSON = htmlCompat.toJSON(state);
|
138
175
|
}
|
139
176
|
} else {
|
140
177
|
input[key === "content" ? "renderBody" : key] = value;
|
@@ -159,9 +196,15 @@ exports.p = function (htmlCompat) {
|
|
159
196
|
|
160
197
|
let async;
|
161
198
|
out.once("finish", (result) => {
|
199
|
+
if (result.out.b_) {
|
200
|
+
__(
|
201
|
+
result.out.b_,
|
202
|
+
writers.classAPI
|
203
|
+
);
|
204
|
+
}
|
162
205
|
if (!async) {
|
163
206
|
async = false;
|
164
|
-
|
207
|
+
writeClassAPIResultToTagsAPI(result);
|
165
208
|
}
|
166
209
|
});
|
167
210
|
|
@@ -169,10 +212,14 @@ exports.p = function (htmlCompat) {
|
|
169
212
|
|
170
213
|
if (async !== false) {
|
171
214
|
async = true;
|
172
|
-
htmlCompat.fork(scopeId, accessor, out,
|
215
|
+
htmlCompat.fork(scopeId, accessor, out, writeClassAPIResultToTagsAPI);
|
173
216
|
}
|
174
217
|
};
|
175
218
|
});
|
176
219
|
|
177
220
|
return htmlCompat.registerRenderer;
|
178
|
-
};
|
221
|
+
};
|
222
|
+
|
223
|
+
function concatScripts(a, b) {
|
224
|
+
return a ? b ? a + ";" + b : a : b;
|
225
|
+
}
|
package/dist/translator/index.js
CHANGED
@@ -428,32 +428,44 @@ const translate = exports.translate = {
|
|
428
428
|
);
|
429
429
|
}
|
430
430
|
|
431
|
-
|
432
|
-
"
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
),
|
450
|
-
_compiler.types.objectExpression(templateRenderOptionsProps),
|
451
|
-
componentIdentifier]
|
452
|
-
)
|
453
|
-
)
|
431
|
+
let rendererAssignment = _compiler.types.assignmentExpression(
|
432
|
+
"=",
|
433
|
+
templateRendererMember,
|
434
|
+
_compiler.types.callExpression(rendererIdentifier, [
|
435
|
+
_compiler.types.functionExpression(
|
436
|
+
null,
|
437
|
+
[
|
438
|
+
_compiler.types.identifier("input"),
|
439
|
+
_compiler.types.identifier("out"),
|
440
|
+
file._componentDefIdentifier,
|
441
|
+
file._componentInstanceIdentifier,
|
442
|
+
_compiler.types.identifier("state"),
|
443
|
+
_compiler.types.identifier("$global")],
|
444
|
+
|
445
|
+
renderBlock.node
|
446
|
+
),
|
447
|
+
_compiler.types.objectExpression(templateRenderOptionsProps),
|
448
|
+
componentIdentifier]
|
454
449
|
)
|
455
450
|
);
|
456
451
|
|
452
|
+
if (!isHTML && componentBrowserFile && !meta.implicitSplitComponent) {
|
453
|
+
rendererAssignment = _compiler.types.assignmentExpression(
|
454
|
+
"=",
|
455
|
+
_compiler.types.memberExpression(
|
456
|
+
(0, _babelUtils.importDefault)(
|
457
|
+
file,
|
458
|
+
(0, _babelUtils.resolveRelativePath)(file, componentBrowserFile),
|
459
|
+
"marko_split_component"
|
460
|
+
),
|
461
|
+
_compiler.types.identifier("renderer")
|
462
|
+
),
|
463
|
+
rendererAssignment
|
464
|
+
);
|
465
|
+
}
|
466
|
+
|
467
|
+
path.pushContainer("body", _compiler.types.expressionStatement(rendererAssignment));
|
468
|
+
|
457
469
|
if (meta.implicitSplitComponent && isHTML) {
|
458
470
|
renderBlock.unshiftContainer(
|
459
471
|
"body",
|
@@ -43,7 +43,7 @@ const lassoDepPrefix = "package: ";var _default =
|
|
43
43
|
};exports.default = _default;
|
44
44
|
|
45
45
|
const entryBuilder = exports.entryBuilder = {
|
46
|
-
build(entryFile) {
|
46
|
+
build(entryFile, exportInit) {
|
47
47
|
const state = entryFile[kEntryState];
|
48
48
|
if (!state) {
|
49
49
|
throw entryFile.path.buildCodeFrameError(
|
@@ -53,6 +53,7 @@ const entryBuilder = exports.entryBuilder = {
|
|
53
53
|
const { markoOpts } = entryFile;
|
54
54
|
const entryMarkoMeta = entryFile.metadata.marko;
|
55
55
|
const { body } = state;
|
56
|
+
let didExportInit = false;
|
56
57
|
entryMarkoMeta.watchFiles = [...state.watchFiles];
|
57
58
|
entryMarkoMeta.deps = [...state.lassoDeps];
|
58
59
|
|
@@ -69,19 +70,29 @@ const entryBuilder = exports.entryBuilder = {
|
|
69
70
|
|
70
71
|
body.unshift(markoComponentsImport);
|
71
72
|
|
72
|
-
if (markoOpts.hydrateInit) {
|
73
|
+
if (markoOpts.hydrateInit || exportInit) {
|
74
|
+
const initExpression = _compiler.types.callExpression(
|
75
|
+
initId,
|
76
|
+
markoOpts.runtimeId ? [_compiler.types.stringLiteral(markoOpts.runtimeId)] : []
|
77
|
+
);
|
73
78
|
markoComponentsImport.specifiers.push(
|
74
79
|
_compiler.types.importSpecifier(initId, initId)
|
75
80
|
);
|
81
|
+
|
76
82
|
body.push(
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
)
|
83
|
+
exportInit ?
|
84
|
+
_compiler.types.exportDefaultDeclaration(
|
85
|
+
_compiler.types.arrowFunctionExpression([], initExpression)
|
86
|
+
) :
|
87
|
+
_compiler.types.expressionStatement(initExpression)
|
83
88
|
);
|
84
89
|
}
|
90
|
+
} else if (exportInit) {
|
91
|
+
body.push(
|
92
|
+
_compiler.types.exportDefaultDeclaration(
|
93
|
+
_compiler.types.arrowFunctionExpression([], _compiler.types.blockStatement([]))
|
94
|
+
)
|
95
|
+
);
|
85
96
|
}
|
86
97
|
|
87
98
|
return body;
|
package/package.json
CHANGED
@@ -50,7 +50,7 @@ exports.p = function (domCompat) {
|
|
50
50
|
const TagsCompat = createRenderer(
|
51
51
|
function (_, out, componentDef, component) {
|
52
52
|
const input = Array.isArray(_.i) ? _.i : [_.i];
|
53
|
-
const tagsRenderer = domCompat.resolveRegistered(_.r, global);
|
53
|
+
const tagsRenderer = domCompat.resolveRegistered(_.r, out.global);
|
54
54
|
const newNode = domCompat.render(out, component, tagsRenderer, input);
|
55
55
|
|
56
56
|
out.bf("1", component, !newNode);
|
@@ -10,43 +10,55 @@ const defaultCreateOut = require("../../createOut");
|
|
10
10
|
const dynamicTag5 = require("../dynamic-tag");
|
11
11
|
|
12
12
|
exports.p = function (htmlCompat) {
|
13
|
-
const
|
13
|
+
const writersByGlobal = new WeakMap();
|
14
14
|
const isMarko6 = (fn) => htmlCompat.isTagsAPI(fn);
|
15
15
|
const isMarko5 = (fn) => !isMarko6(fn);
|
16
|
-
const
|
17
|
-
const {
|
18
|
-
const $global = out.global;
|
19
|
-
const outs = outsByGlobal.get($global);
|
20
|
-
const writer = out._state.writer;
|
16
|
+
const writeClassAPIResultToTagsAPI = (result) => {
|
17
|
+
const { writer } = result.out._state;
|
21
18
|
htmlCompat.write(writer._content);
|
22
|
-
writer.
|
23
|
-
|
24
|
-
outs.push(out);
|
25
|
-
} else {
|
26
|
-
outsByGlobal.set($global, [out]);
|
27
|
-
}
|
19
|
+
htmlCompat.writeScript(writer._script);
|
20
|
+
writer._content = writer._scripts = "";
|
28
21
|
};
|
22
|
+
const flushScripts = ($global, flushDefs) => {
|
23
|
+
const writers = writersByGlobal.get($global);
|
24
|
+
if (!writers) return "";
|
29
25
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
if (outs) {
|
34
|
-
chunk.render(() => {
|
35
|
-
const defs = [];
|
36
|
-
outsByGlobal.delete($global);
|
37
|
-
for (const out of outs) {
|
38
|
-
if (out.___components) {
|
39
|
-
___addComponentsFromContext(out.___components, defs);
|
40
|
-
}
|
26
|
+
const { classAPI, tagsAPI } = writers;
|
27
|
+
let scripts = "";
|
28
|
+
let componentDefs = flushDefs;
|
41
29
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
30
|
+
if (classAPI.length) {
|
31
|
+
componentDefs = flushDefs ? flushDefs.concat(classAPI) : classAPI;
|
32
|
+
writers.classAPI = [];
|
33
|
+
}
|
46
34
|
|
47
|
-
|
48
|
-
|
35
|
+
if (componentDefs) {
|
36
|
+
scripts = ___getInitComponentsCodeForDefs($global, componentDefs);
|
37
|
+
}
|
38
|
+
|
39
|
+
if (tagsAPI.length) {
|
40
|
+
const [chunk] = tagsAPI;
|
41
|
+
for (let i = 1; i < tagsAPI.length; i++) {
|
42
|
+
chunk.append(tagsAPI[i]);
|
43
|
+
}
|
44
|
+
|
45
|
+
if (!chunk.boundary.done) {
|
46
|
+
throw new Error(
|
47
|
+
"Cannot serialize promise across tags/class compat layer.",
|
48
|
+
);
|
49
|
+
}
|
50
|
+
|
51
|
+
scripts = concatScripts(chunk.flushScript().scripts, scripts);
|
52
|
+
writers.tagsAPI = [];
|
49
53
|
}
|
54
|
+
|
55
|
+
return scripts;
|
56
|
+
};
|
57
|
+
|
58
|
+
htmlCompat.onFlush((chunk) => {
|
59
|
+
chunk.render(() => {
|
60
|
+
chunk.writeScript(flushScripts(chunk.boundary.state.$global));
|
61
|
+
});
|
50
62
|
});
|
51
63
|
|
52
64
|
dynamicTag5.___runtimeCompat = function tagsToVdom(
|
@@ -58,22 +70,39 @@ exports.p = function (htmlCompat) {
|
|
58
70
|
return tagsRenderer;
|
59
71
|
}
|
60
72
|
|
61
|
-
|
62
|
-
renderBody
|
63
|
-
|
64
|
-
|
65
|
-
|
73
|
+
return (input, out) => {
|
74
|
+
if (!tagsRenderer && renderBody) {
|
75
|
+
renderBody.toJSON = htmlCompat.toJSON(
|
76
|
+
htmlCompat.ensureState(out.global),
|
77
|
+
);
|
78
|
+
}
|
66
79
|
TagsCompat(
|
67
80
|
args
|
68
81
|
? { i: args, r: (args) => (tagsRenderer || renderBody)(...args) }
|
69
82
|
: { i: input, r: tagsRenderer || renderBody },
|
70
83
|
out,
|
71
84
|
);
|
85
|
+
};
|
72
86
|
};
|
73
87
|
|
74
88
|
const TagsCompatId = "tags-compat";
|
75
89
|
const TagsCompat = createRenderer(
|
76
90
|
function (_, out, componentDef, component) {
|
91
|
+
// class to tags
|
92
|
+
const $global = out.global;
|
93
|
+
let writers = writersByGlobal.get($global);
|
94
|
+
if (!writers) {
|
95
|
+
writersByGlobal.set($global, (writers = { classAPI: [], tagsAPI: [] }));
|
96
|
+
out.prependListener("___toString", (writer) => {
|
97
|
+
const defs = writer._data?.componentDefs;
|
98
|
+
const scripts = flushScripts($global, defs);
|
99
|
+
if (scripts) {
|
100
|
+
if (defs) writer._data.componentDefs = undefined;
|
101
|
+
writer.script(scripts);
|
102
|
+
}
|
103
|
+
});
|
104
|
+
}
|
105
|
+
|
77
106
|
const input = _.i;
|
78
107
|
const tagsRenderer = _.r;
|
79
108
|
const willRerender = componentDef._wrr || htmlCompat.isInResumedBranch();
|
@@ -84,7 +113,7 @@ exports.p = function (htmlCompat) {
|
|
84
113
|
out,
|
85
114
|
component,
|
86
115
|
input,
|
87
|
-
|
116
|
+
writers.tagsAPI,
|
88
117
|
);
|
89
118
|
out.ef();
|
90
119
|
},
|
@@ -118,7 +147,15 @@ exports.p = function (htmlCompat) {
|
|
118
147
|
htmlCompat.registerRenderBody(renderBody5);
|
119
148
|
}
|
120
149
|
return (input, ...args) => {
|
121
|
-
|
150
|
+
// tags to class
|
151
|
+
const $global = htmlCompat.$global();
|
152
|
+
const state = htmlCompat.ensureState($global);
|
153
|
+
let writers = writersByGlobal.get($global);
|
154
|
+
if (!writers) {
|
155
|
+
writersByGlobal.set($global, (writers = { classAPI: [], tagsAPI: [] }));
|
156
|
+
}
|
157
|
+
|
158
|
+
const out = defaultCreateOut($global);
|
122
159
|
const branchId = htmlCompat.nextScopeId();
|
123
160
|
let customEvents;
|
124
161
|
|
@@ -134,7 +171,7 @@ exports.p = function (htmlCompat) {
|
|
134
171
|
key[2] === "-" ? key.slice(3) : key.slice(2).toLowerCase(),
|
135
172
|
value,
|
136
173
|
]);
|
137
|
-
value.toJSON = htmlCompat.toJSON;
|
174
|
+
value.toJSON = htmlCompat.toJSON(state);
|
138
175
|
}
|
139
176
|
} else {
|
140
177
|
input[key === "content" ? "renderBody" : key] = value;
|
@@ -159,9 +196,15 @@ exports.p = function (htmlCompat) {
|
|
159
196
|
|
160
197
|
let async;
|
161
198
|
out.once("finish", (result) => {
|
199
|
+
if (result.out.___components) {
|
200
|
+
___addComponentsFromContext(
|
201
|
+
result.out.___components,
|
202
|
+
writers.classAPI,
|
203
|
+
);
|
204
|
+
}
|
162
205
|
if (!async) {
|
163
206
|
async = false;
|
164
|
-
|
207
|
+
writeClassAPIResultToTagsAPI(result);
|
165
208
|
}
|
166
209
|
});
|
167
210
|
|
@@ -169,10 +212,14 @@ exports.p = function (htmlCompat) {
|
|
169
212
|
|
170
213
|
if (async !== false) {
|
171
214
|
async = true;
|
172
|
-
htmlCompat.fork(scopeId, accessor, out,
|
215
|
+
htmlCompat.fork(scopeId, accessor, out, writeClassAPIResultToTagsAPI);
|
173
216
|
}
|
174
217
|
};
|
175
218
|
});
|
176
219
|
|
177
220
|
return htmlCompat.registerRenderer;
|
178
221
|
};
|
222
|
+
|
223
|
+
function concatScripts(a, b) {
|
224
|
+
return a ? (b ? a + ";" + b : a) : b;
|
225
|
+
}
|
package/src/translator/index.js
CHANGED
@@ -428,32 +428,44 @@ export const translate = {
|
|
428
428
|
);
|
429
429
|
}
|
430
430
|
|
431
|
-
|
432
|
-
"
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
t.
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
t.identifier("$global"),
|
447
|
-
],
|
448
|
-
renderBlock.node,
|
449
|
-
),
|
450
|
-
t.objectExpression(templateRenderOptionsProps),
|
451
|
-
componentIdentifier,
|
452
|
-
]),
|
431
|
+
let rendererAssignment = t.assignmentExpression(
|
432
|
+
"=",
|
433
|
+
templateRendererMember,
|
434
|
+
t.callExpression(rendererIdentifier, [
|
435
|
+
t.functionExpression(
|
436
|
+
null,
|
437
|
+
[
|
438
|
+
t.identifier("input"),
|
439
|
+
t.identifier("out"),
|
440
|
+
file._componentDefIdentifier,
|
441
|
+
file._componentInstanceIdentifier,
|
442
|
+
t.identifier("state"),
|
443
|
+
t.identifier("$global"),
|
444
|
+
],
|
445
|
+
renderBlock.node,
|
453
446
|
),
|
454
|
-
|
447
|
+
t.objectExpression(templateRenderOptionsProps),
|
448
|
+
componentIdentifier,
|
449
|
+
]),
|
455
450
|
);
|
456
451
|
|
452
|
+
if (!isHTML && componentBrowserFile && !meta.implicitSplitComponent) {
|
453
|
+
rendererAssignment = t.assignmentExpression(
|
454
|
+
"=",
|
455
|
+
t.memberExpression(
|
456
|
+
importDefault(
|
457
|
+
file,
|
458
|
+
resolveRelativePath(file, componentBrowserFile),
|
459
|
+
"marko_split_component",
|
460
|
+
),
|
461
|
+
t.identifier("renderer"),
|
462
|
+
),
|
463
|
+
rendererAssignment,
|
464
|
+
);
|
465
|
+
}
|
466
|
+
|
467
|
+
path.pushContainer("body", t.expressionStatement(rendererAssignment));
|
468
|
+
|
457
469
|
if (meta.implicitSplitComponent && isHTML) {
|
458
470
|
renderBlock.unshiftContainer(
|
459
471
|
"body",
|
@@ -43,7 +43,7 @@ export default (entryFile, isHydrate) => {
|
|
43
43
|
};
|
44
44
|
|
45
45
|
export const entryBuilder = {
|
46
|
-
build(entryFile) {
|
46
|
+
build(entryFile, exportInit) {
|
47
47
|
const state = entryFile[kEntryState];
|
48
48
|
if (!state) {
|
49
49
|
throw entryFile.path.buildCodeFrameError(
|
@@ -53,6 +53,7 @@ export const entryBuilder = {
|
|
53
53
|
const { markoOpts } = entryFile;
|
54
54
|
const entryMarkoMeta = entryFile.metadata.marko;
|
55
55
|
const { body } = state;
|
56
|
+
let didExportInit = false;
|
56
57
|
entryMarkoMeta.watchFiles = [...state.watchFiles];
|
57
58
|
entryMarkoMeta.deps = [...state.lassoDeps];
|
58
59
|
|
@@ -69,19 +70,29 @@ export const entryBuilder = {
|
|
69
70
|
|
70
71
|
body.unshift(markoComponentsImport);
|
71
72
|
|
72
|
-
if (markoOpts.hydrateInit) {
|
73
|
+
if (markoOpts.hydrateInit || exportInit) {
|
74
|
+
const initExpression = t.callExpression(
|
75
|
+
initId,
|
76
|
+
markoOpts.runtimeId ? [t.stringLiteral(markoOpts.runtimeId)] : [],
|
77
|
+
);
|
73
78
|
markoComponentsImport.specifiers.push(
|
74
79
|
t.importSpecifier(initId, initId),
|
75
80
|
);
|
81
|
+
|
76
82
|
body.push(
|
77
|
-
|
78
|
-
t.
|
79
|
-
|
80
|
-
|
81
|
-
),
|
82
|
-
),
|
83
|
+
exportInit
|
84
|
+
? t.exportDefaultDeclaration(
|
85
|
+
t.arrowFunctionExpression([], initExpression),
|
86
|
+
)
|
87
|
+
: t.expressionStatement(initExpression),
|
83
88
|
);
|
84
89
|
}
|
90
|
+
} else if (exportInit) {
|
91
|
+
body.push(
|
92
|
+
t.exportDefaultDeclaration(
|
93
|
+
t.arrowFunctionExpression([], t.blockStatement([])),
|
94
|
+
),
|
95
|
+
);
|
85
96
|
}
|
86
97
|
|
87
98
|
return body;
|