marko 6.0.0-3.9 → 6.0.0-next.3.16
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/debug/dom.js +28 -22
- package/dist/debug/dom.mjs +28 -22
- package/dist/debug/html.js +36 -31
- package/dist/debug/html.mjs +36 -31
- package/dist/dom/compat.d.ts +1 -1
- package/dist/dom/renderer.d.ts +1 -1
- package/dist/dom/signals.d.ts +1 -1
- package/dist/dom.js +24 -19
- package/dist/dom.mjs +24 -19
- package/dist/html/attrs.d.ts +1 -1
- package/dist/html/dynamic-tag.d.ts +4 -4
- package/dist/html/writer.d.ts +5 -5
- package/dist/html.js +28 -23
- package/dist/html.mjs +28 -23
- package/dist/translator/index.d.ts +2 -0
- package/dist/translator/index.js +98 -63
- package/dist/translator/util/entry-builder.d.ts +1 -0
- package/dist/translator/util/runtime.d.ts +1 -0
- package/dist/translator/util/translate-attrs.d.ts +5 -3
- package/index.d.ts +144 -0
- package/package.json +24 -10
- package/tags-html.d.ts +3935 -0
package/dist/translator/index.js
CHANGED
@@ -33,6 +33,8 @@ __export(translator_exports, {
|
|
33
33
|
analyze: () => analyze,
|
34
34
|
getRuntimeEntryFiles: () => getRuntimeEntryFiles,
|
35
35
|
internalEntryBuilder: () => entry_builder_default,
|
36
|
+
preferAPI: () => preferAPI,
|
37
|
+
tagDiscoveryDirs: () => tagDiscoveryDirs,
|
36
38
|
taglibs: () => taglibs,
|
37
39
|
transform: () => transform,
|
38
40
|
translate: () => translate
|
@@ -669,6 +671,7 @@ function analyzeTagNameType(tag) {
|
|
669
671
|
} else if (childFile.ast.program.extra.featureType === "class") {
|
670
672
|
extra.tagNameType = 2 /* DynamicTag */;
|
671
673
|
extra.featureType = "class";
|
674
|
+
(currentProgramPath.node.extra ??= {}).needsCompat = true;
|
672
675
|
}
|
673
676
|
}
|
674
677
|
}
|
@@ -765,7 +768,7 @@ function startSection(path4) {
|
|
765
768
|
"name"
|
766
769
|
);
|
767
770
|
const sectionName = path4.isProgram() ? "" : currentProgramPath.scope.generateUid(
|
768
|
-
sectionNamePath.toString() + "
|
771
|
+
sectionNamePath.toString() + "_content"
|
769
772
|
);
|
770
773
|
const programExtra = path4.hub.file.path.node.extra ??= {};
|
771
774
|
const sections = programExtra.sections ??= [];
|
@@ -1586,9 +1589,6 @@ function isRegisteredFnExtra(extra) {
|
|
1586
1589
|
return isReferencedExtra(extra) && extra.registerId !== void 0;
|
1587
1590
|
}
|
1588
1591
|
|
1589
|
-
// src/translator/visitors/program/dom.ts
|
1590
|
-
var import_compiler20 = require("@marko/compiler");
|
1591
|
-
|
1592
1592
|
// src/translator/util/runtime.ts
|
1593
1593
|
var import_compiler8 = require("@marko/compiler");
|
1594
1594
|
var import_babel_utils8 = require("@marko/compiler/babel-utils");
|
@@ -2038,6 +2038,13 @@ function filterArguments(args) {
|
|
2038
2038
|
}
|
2039
2039
|
return filteredArgs;
|
2040
2040
|
}
|
2041
|
+
function getCompatRuntimeFile() {
|
2042
|
+
const markoOpts = getMarkoOpts();
|
2043
|
+
return `marko/src/runtime/helpers/tags-compat/${isOutputHTML() ? "html" : "dom"}${markoOpts.optimize ? "" : "-debug"}.${markoOpts.modules === "esm" ? "mjs" : "js"}`;
|
2044
|
+
}
|
2045
|
+
|
2046
|
+
// src/translator/visitors/program/dom.ts
|
2047
|
+
var import_compiler20 = require("@marko/compiler");
|
2041
2048
|
|
2042
2049
|
// src/translator/util/signals.ts
|
2043
2050
|
var import_compiler19 = require("@marko/compiler");
|
@@ -3815,6 +3822,19 @@ var program_default = {
|
|
3815
3822
|
} else {
|
3816
3823
|
dom_default.translate.exit(program);
|
3817
3824
|
}
|
3825
|
+
if (program.node.extra?.needsCompat) {
|
3826
|
+
const compatFile = getCompatRuntimeFile();
|
3827
|
+
const body = [void 0];
|
3828
|
+
for (const child of program.node.body) {
|
3829
|
+
if (child.type === "ImportDeclaration" && child.source.value === compatFile) {
|
3830
|
+
body[0] = child;
|
3831
|
+
} else {
|
3832
|
+
body.push(child);
|
3833
|
+
}
|
3834
|
+
}
|
3835
|
+
body[0] ??= import_compiler22.types.importDeclaration([], import_compiler22.types.stringLiteral(compatFile));
|
3836
|
+
program.node.body = body;
|
3837
|
+
}
|
3818
3838
|
currentProgramPath = previousProgramPath.get(currentProgramPath);
|
3819
3839
|
}
|
3820
3840
|
}
|
@@ -5234,8 +5254,8 @@ function getConditionRoot(tag) {
|
|
5234
5254
|
}
|
5235
5255
|
|
5236
5256
|
// src/translator/util/translate-attrs.ts
|
5237
|
-
var
|
5238
|
-
function translateAttrs(tag, templateExports, statements = []) {
|
5257
|
+
var contentProps = /* @__PURE__ */ new WeakSet();
|
5258
|
+
function translateAttrs(tag, templateExports, statements = [], contentKey = "content") {
|
5239
5259
|
const seen = /* @__PURE__ */ new Set();
|
5240
5260
|
const properties = [];
|
5241
5261
|
const attrTagLookup = tag.node.extra?.attributeTags;
|
@@ -5271,13 +5291,15 @@ function translateAttrs(tag, templateExports, statements = []) {
|
|
5271
5291
|
i,
|
5272
5292
|
attrTagLookup,
|
5273
5293
|
statements,
|
5274
|
-
templateExports
|
5294
|
+
templateExports,
|
5295
|
+
contentKey
|
5275
5296
|
);
|
5276
5297
|
} else {
|
5277
5298
|
const translatedAttrTag = translateAttrs(
|
5278
5299
|
child,
|
5279
5300
|
templateExports?.[attrTagMeta.name]?.props,
|
5280
|
-
statements
|
5301
|
+
statements,
|
5302
|
+
contentKey
|
5281
5303
|
);
|
5282
5304
|
if (attrTagMeta.repeated) {
|
5283
5305
|
const prevProp = findObjectProperty(attrTagMeta.name, properties);
|
@@ -5316,22 +5338,23 @@ function translateAttrs(tag, templateExports, statements = []) {
|
|
5316
5338
|
i,
|
5317
5339
|
attrTagLookup,
|
5318
5340
|
statements,
|
5319
|
-
templateExports
|
5341
|
+
templateExports,
|
5342
|
+
contentKey
|
5320
5343
|
);
|
5321
5344
|
}
|
5322
5345
|
}
|
5323
5346
|
}
|
5324
5347
|
}
|
5325
|
-
if (!seen.has(
|
5326
|
-
seen.add(
|
5327
|
-
const
|
5328
|
-
if (
|
5329
|
-
const
|
5330
|
-
import_compiler29.types.identifier(
|
5331
|
-
|
5348
|
+
if (!seen.has(contentKey) && usesExport(templateExports, contentKey)) {
|
5349
|
+
seen.add(contentKey);
|
5350
|
+
const contentExpression = buildContent(tag.get("body"));
|
5351
|
+
if (contentExpression) {
|
5352
|
+
const contentProp = import_compiler29.types.objectProperty(
|
5353
|
+
import_compiler29.types.identifier(contentKey),
|
5354
|
+
contentExpression
|
5332
5355
|
);
|
5333
|
-
|
5334
|
-
properties.push(
|
5356
|
+
contentProps.add(contentProp);
|
5357
|
+
properties.push(contentProp);
|
5335
5358
|
}
|
5336
5359
|
}
|
5337
5360
|
const { attributes } = tag.node;
|
@@ -5348,14 +5371,14 @@ function translateAttrs(tag, templateExports, statements = []) {
|
|
5348
5371
|
properties.reverse();
|
5349
5372
|
return { properties, statements };
|
5350
5373
|
}
|
5351
|
-
function
|
5374
|
+
function getTranslatedBodyContentProperty(props) {
|
5352
5375
|
for (const prop of props) {
|
5353
|
-
if (
|
5376
|
+
if (contentProps.has(prop)) {
|
5354
5377
|
return prop;
|
5355
5378
|
}
|
5356
5379
|
}
|
5357
5380
|
}
|
5358
|
-
function addDynamicAttrTagStatements(attrTags2, index, attrTagLookup, statements, templateExports) {
|
5381
|
+
function addDynamicAttrTagStatements(attrTags2, index, attrTagLookup, statements, templateExports, contentKey = "content") {
|
5359
5382
|
const tag = attrTags2[index];
|
5360
5383
|
if (tag.isMarkoTag()) {
|
5361
5384
|
if ((0, import_babel_utils17.isAttributeTag)(tag)) {
|
@@ -5364,7 +5387,8 @@ function addDynamicAttrTagStatements(attrTags2, index, attrTagLookup, statements
|
|
5364
5387
|
const translatedAttrTag = translateAttrs(
|
5365
5388
|
tag,
|
5366
5389
|
templateExports?.[attrTagMeta.name]?.props,
|
5367
|
-
statements
|
5390
|
+
statements,
|
5391
|
+
contentKey
|
5368
5392
|
);
|
5369
5393
|
if (attrTagMeta.repeated) {
|
5370
5394
|
statements.push(
|
@@ -5403,7 +5427,8 @@ function addDynamicAttrTagStatements(attrTags2, index, attrTagLookup, statements
|
|
5403
5427
|
index,
|
5404
5428
|
attrTagLookup,
|
5405
5429
|
statements,
|
5406
|
-
templateExports
|
5430
|
+
templateExports,
|
5431
|
+
contentKey
|
5407
5432
|
);
|
5408
5433
|
case "for": {
|
5409
5434
|
return translateForAttrTag(
|
@@ -5411,7 +5436,8 @@ function addDynamicAttrTagStatements(attrTags2, index, attrTagLookup, statements
|
|
5411
5436
|
index,
|
5412
5437
|
attrTagLookup,
|
5413
5438
|
statements,
|
5414
|
-
templateExports
|
5439
|
+
templateExports,
|
5440
|
+
contentKey
|
5415
5441
|
);
|
5416
5442
|
}
|
5417
5443
|
}
|
@@ -5422,14 +5448,15 @@ function addDynamicAttrTagStatements(attrTags2, index, attrTagLookup, statements
|
|
5422
5448
|
function propsToExpression(props) {
|
5423
5449
|
return props.length === 1 && import_compiler29.types.isSpreadElement(props[0]) ? props[0].argument : import_compiler29.types.objectExpression(props);
|
5424
5450
|
}
|
5425
|
-
function translateForAttrTag(attrTags2, index, attrTagLookup, statements, templateExports) {
|
5451
|
+
function translateForAttrTag(attrTags2, index, attrTagLookup, statements, templateExports, contentKey) {
|
5426
5452
|
const forTag = attrTags2[index];
|
5427
5453
|
const bodyStatements = [];
|
5428
5454
|
addAllAttrTagsAsDynamic(
|
5429
5455
|
forTag,
|
5430
5456
|
attrTagLookup,
|
5431
5457
|
bodyStatements,
|
5432
|
-
templateExports
|
5458
|
+
templateExports,
|
5459
|
+
contentKey
|
5433
5460
|
);
|
5434
5461
|
statements.push(
|
5435
5462
|
buildForRuntimeCall(
|
@@ -5441,7 +5468,7 @@ function translateForAttrTag(attrTags2, index, attrTagLookup, statements, templa
|
|
5441
5468
|
);
|
5442
5469
|
return index;
|
5443
5470
|
}
|
5444
|
-
function translateIfAttrTag(attrTags2, index, attrTagLookup, statements, templateExports) {
|
5471
|
+
function translateIfAttrTag(attrTags2, index, attrTagLookup, statements, templateExports, contentKey) {
|
5445
5472
|
const ifTag = attrTags2[index];
|
5446
5473
|
const consequentStatements = [];
|
5447
5474
|
let ifStatement = import_compiler29.types.ifStatement(
|
@@ -5453,7 +5480,8 @@ function translateIfAttrTag(attrTags2, index, attrTagLookup, statements, templat
|
|
5453
5480
|
ifTag,
|
5454
5481
|
attrTagLookup,
|
5455
5482
|
consequentStatements,
|
5456
|
-
templateExports
|
5483
|
+
templateExports,
|
5484
|
+
contentKey
|
5457
5485
|
);
|
5458
5486
|
let nextIndex = index + 1;
|
5459
5487
|
while (nextIndex < attrTags2.length) {
|
@@ -5468,7 +5496,8 @@ function translateIfAttrTag(attrTags2, index, attrTagLookup, statements, templat
|
|
5468
5496
|
nextTag,
|
5469
5497
|
attrTagLookup,
|
5470
5498
|
alternateStatements,
|
5471
|
-
templateExports
|
5499
|
+
templateExports,
|
5500
|
+
contentKey
|
5472
5501
|
);
|
5473
5502
|
if (testValue) {
|
5474
5503
|
ifStatement.alternate = ifStatement = import_compiler29.types.ifStatement(
|
@@ -5488,7 +5517,7 @@ function translateIfAttrTag(attrTags2, index, attrTagLookup, statements, templat
|
|
5488
5517
|
}
|
5489
5518
|
return nextIndex - 1;
|
5490
5519
|
}
|
5491
|
-
function addAllAttrTagsAsDynamic(tag, attrTagLookup, statements, templateExports) {
|
5520
|
+
function addAllAttrTagsAsDynamic(tag, attrTagLookup, statements, templateExports, contentKey) {
|
5492
5521
|
const attrTags2 = tag.node.body.attributeTags ? tag.get("body").get("body") : tag.get("attributeTags");
|
5493
5522
|
for (let i = 0; i < attrTags2.length; i++) {
|
5494
5523
|
i = addDynamicAttrTagStatements(
|
@@ -5496,7 +5525,8 @@ function addAllAttrTagsAsDynamic(tag, attrTagLookup, statements, templateExports
|
|
5496
5525
|
i,
|
5497
5526
|
attrTagLookup,
|
5498
5527
|
statements,
|
5499
|
-
templateExports
|
5528
|
+
templateExports,
|
5529
|
+
contentKey
|
5500
5530
|
);
|
5501
5531
|
}
|
5502
5532
|
}
|
@@ -5527,7 +5557,7 @@ function getConditionTestValue({
|
|
5527
5557
|
}) {
|
5528
5558
|
return attributes.length === 1 ? attributes[0].value : void 0;
|
5529
5559
|
}
|
5530
|
-
function
|
5560
|
+
function buildContent(body) {
|
5531
5561
|
const bodySection = body.node.extra?.section;
|
5532
5562
|
if (bodySection) {
|
5533
5563
|
if (isOutputHTML()) {
|
@@ -8181,21 +8211,21 @@ function translateHTML(tag) {
|
|
8181
8211
|
statements: []
|
8182
8212
|
};
|
8183
8213
|
if (node.extra.tagNameNullable) {
|
8184
|
-
const
|
8185
|
-
let
|
8186
|
-
if (
|
8187
|
-
const
|
8188
|
-
|
8189
|
-
const [
|
8214
|
+
const contentProp = getTranslatedBodyContentProperty(properties);
|
8215
|
+
let contentId = void 0;
|
8216
|
+
if (contentProp) {
|
8217
|
+
const contentExpression = contentProp.value;
|
8218
|
+
contentProp.value = contentId = tag.scope.generateUidIdentifier("content");
|
8219
|
+
const [contentPath] = tag.insertBefore(
|
8190
8220
|
import_compiler49.types.variableDeclaration("const", [
|
8191
8221
|
import_compiler49.types.variableDeclarator(
|
8192
|
-
|
8222
|
+
contentId,
|
8193
8223
|
// TODO: only register if needed (child template analysis)
|
8194
|
-
|
8224
|
+
contentExpression
|
8195
8225
|
)
|
8196
8226
|
])
|
8197
8227
|
);
|
8198
|
-
|
8228
|
+
contentPath.skip();
|
8199
8229
|
}
|
8200
8230
|
let renderTagExpr = callExpression(
|
8201
8231
|
tagIdentifier,
|
@@ -8209,7 +8239,7 @@ function translateHTML(tag) {
|
|
8209
8239
|
import_compiler49.types.ifStatement(
|
8210
8240
|
tagIdentifier,
|
8211
8241
|
import_compiler49.types.expressionStatement(renderTagExpr),
|
8212
|
-
|
8242
|
+
contentId && callStatement(contentId)
|
8213
8243
|
)
|
8214
8244
|
);
|
8215
8245
|
} else if (tagVar) {
|
@@ -8568,26 +8598,26 @@ function writeAttrsToExports(tag, templateExport, importAlias, info) {
|
|
8568
8598
|
}
|
8569
8599
|
}
|
8570
8600
|
const bodySection = tag.node.body.extra?.section;
|
8571
|
-
if (bodySection && !seen.has("
|
8572
|
-
seen.add("
|
8573
|
-
if (templateExport.props.
|
8574
|
-
const
|
8601
|
+
if (bodySection && !seen.has("content")) {
|
8602
|
+
seen.add("content");
|
8603
|
+
if (templateExport.props.content) {
|
8604
|
+
const contentExportIdentifier = (0, import_babel_utils37.importNamed)(
|
8575
8605
|
tag.hub.file,
|
8576
8606
|
info.relativePath,
|
8577
|
-
templateExport.props.
|
8578
|
-
`${importAlias}
|
8607
|
+
templateExport.props.content.id,
|
8608
|
+
`${importAlias}_content`
|
8579
8609
|
);
|
8580
8610
|
addValue(
|
8581
8611
|
info.tagSection,
|
8582
8612
|
void 0,
|
8583
|
-
// TODO: pretty sure
|
8584
|
-
identifierToSignal(
|
8613
|
+
// TODO: pretty sure content needs to have the reference group of it's param defaults.
|
8614
|
+
identifierToSignal(contentExportIdentifier),
|
8585
8615
|
import_compiler49.types.callExpression(import_compiler49.types.identifier(bodySection.name), [scopeIdentifier]),
|
8586
8616
|
createScopeReadExpression(info.tagSection, info.childScopeBinding),
|
8587
8617
|
callRuntime(
|
8588
8618
|
"inChild",
|
8589
8619
|
getScopeAccessorLiteral(info.childScopeBinding),
|
8590
|
-
import_compiler49.types.identifier(
|
8620
|
+
import_compiler49.types.identifier(contentExportIdentifier.name)
|
8591
8621
|
)
|
8592
8622
|
);
|
8593
8623
|
}
|
@@ -8739,6 +8769,7 @@ var dynamic_tag_default = {
|
|
8739
8769
|
const extra = node.extra;
|
8740
8770
|
const nodeRef2 = extra[kDOMBinding];
|
8741
8771
|
const section = getSection(tag);
|
8772
|
+
const isClassAPI = extra.featureType === "class";
|
8742
8773
|
let tagExpression = node.name;
|
8743
8774
|
if (import_compiler50.types.isStringLiteral(tagExpression)) {
|
8744
8775
|
tagExpression = (0, import_babel_utils38.importDefault)(
|
@@ -8747,15 +8778,13 @@ var dynamic_tag_default = {
|
|
8747
8778
|
tagExpression.value
|
8748
8779
|
);
|
8749
8780
|
}
|
8750
|
-
if (
|
8751
|
-
const compatRuntimeFile = getCompatRuntimeFile(tag.hub.file.markoOpts);
|
8752
|
-
(0, import_babel_utils38.importDefault)(tag.hub.file, compatRuntimeFile);
|
8781
|
+
if (isClassAPI) {
|
8753
8782
|
if (isOutputHTML()) {
|
8754
8783
|
currentProgramPath.pushContainer(
|
8755
8784
|
"body",
|
8756
8785
|
import_compiler50.types.expressionStatement(
|
8757
8786
|
import_compiler50.types.callExpression(
|
8758
|
-
(0, import_babel_utils38.importNamed)(tag.hub.file,
|
8787
|
+
(0, import_babel_utils38.importNamed)(tag.hub.file, getCompatRuntimeFile(), "s"),
|
8759
8788
|
[
|
8760
8789
|
import_compiler50.types.identifier(tagExpression.name),
|
8761
8790
|
import_compiler50.types.stringLiteral((0, import_babel_utils38.loadFileForTag)(tag).metadata.marko.id)
|
@@ -8776,7 +8805,12 @@ var dynamic_tag_default = {
|
|
8776
8805
|
);
|
8777
8806
|
}
|
8778
8807
|
}
|
8779
|
-
const { properties, statements } = translateAttrs(
|
8808
|
+
const { properties, statements } = translateAttrs(
|
8809
|
+
tag,
|
8810
|
+
void 0,
|
8811
|
+
void 0,
|
8812
|
+
isClassAPI ? "renderBody" : "content"
|
8813
|
+
);
|
8780
8814
|
const args = [];
|
8781
8815
|
let hasMultipleArgs = false;
|
8782
8816
|
if (node.arguments?.length) {
|
@@ -8788,10 +8822,10 @@ var dynamic_tag_default = {
|
|
8788
8822
|
hasMultipleArgs = node.arguments.length > 1 || import_compiler50.types.isSpreadElement(node.arguments[0]);
|
8789
8823
|
}
|
8790
8824
|
} else {
|
8791
|
-
const
|
8792
|
-
if (
|
8793
|
-
properties.splice(properties.indexOf(
|
8794
|
-
args.push(propsToExpression(properties),
|
8825
|
+
const contentProp = getTranslatedBodyContentProperty(properties);
|
8826
|
+
if (contentProp) {
|
8827
|
+
properties.splice(properties.indexOf(contentProp), 1);
|
8828
|
+
args.push(propsToExpression(properties), contentProp.value);
|
8795
8829
|
} else {
|
8796
8830
|
args.push(propsToExpression(properties));
|
8797
8831
|
}
|
@@ -8972,9 +9006,6 @@ var dynamic_tag_default = {
|
|
8972
9006
|
}
|
8973
9007
|
}
|
8974
9008
|
};
|
8975
|
-
function getCompatRuntimeFile(markoOpts) {
|
8976
|
-
return `marko/src/runtime/helpers/tags-compat/${isOutputHTML() ? "html" : "dom"}${markoOpts.optimize ? "" : "-debug"}.${markoOpts.modules === "esm" ? "mjs" : "js"}`;
|
8977
|
-
}
|
8978
9009
|
|
8979
9010
|
// src/translator/visitors/tag/index.ts
|
8980
9011
|
var tag_default = {
|
@@ -9170,6 +9201,8 @@ var visitors = extractVisitors({
|
|
9170
9201
|
MarkoScriptlet: scriptlet_default,
|
9171
9202
|
MarkoComment: comment_default
|
9172
9203
|
});
|
9204
|
+
var tagDiscoveryDirs = ["tags"];
|
9205
|
+
var preferAPI = "tags";
|
9173
9206
|
var { transform, analyze, translate } = visitors;
|
9174
9207
|
var taglibs = [
|
9175
9208
|
[
|
@@ -9190,6 +9223,8 @@ function getRuntimeEntryFiles(output, optimize) {
|
|
9190
9223
|
analyze,
|
9191
9224
|
getRuntimeEntryFiles,
|
9192
9225
|
internalEntryBuilder,
|
9226
|
+
preferAPI,
|
9227
|
+
tagDiscoveryDirs,
|
9193
9228
|
taglibs,
|
9194
9229
|
transform,
|
9195
9230
|
translate
|
@@ -1,12 +1,14 @@
|
|
1
1
|
import { types as t } from "@marko/compiler";
|
2
2
|
import { type TemplateExports } from "../visitors/program";
|
3
3
|
import { type AttrTagLookup } from "./nested-attribute-tags";
|
4
|
-
|
4
|
+
type ContentKey = "renderBody" | "content";
|
5
|
+
export declare function translateAttrs(tag: t.NodePath<t.MarkoTag>, templateExports?: TemplateExports, statements?: t.Statement[], contentKey?: ContentKey): {
|
5
6
|
properties: (t.ObjectMethod | t.ObjectProperty | t.SpreadElement)[];
|
6
7
|
statements: t.Statement[];
|
7
8
|
};
|
8
|
-
export declare function
|
9
|
+
export declare function getTranslatedBodyContentProperty(props: t.ObjectExpression["properties"]): (t.ObjectProperty & {
|
9
10
|
value: t.Expression;
|
10
11
|
}) | undefined;
|
11
|
-
export declare function addDynamicAttrTagStatements(attrTags: t.NodePath<t.MarkoTag["attributeTags"][number]>[], index: number, attrTagLookup: AttrTagLookup, statements: t.Statement[], templateExports: TemplateExports): number;
|
12
|
+
export declare function addDynamicAttrTagStatements(attrTags: t.NodePath<t.MarkoTag["attributeTags"][number]>[], index: number, attrTagLookup: AttrTagLookup, statements: t.Statement[], templateExports: TemplateExports, contentKey?: ContentKey): number;
|
12
13
|
export declare function propsToExpression(props: t.ObjectExpression["properties"]): t.Expression;
|
14
|
+
export {};
|
package/index.d.ts
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
import "./tags-html";
|
2
|
+
|
3
|
+
declare module "*.marko" {
|
4
|
+
const template: Marko.Template;
|
5
|
+
export default template;
|
6
|
+
}
|
7
|
+
|
8
|
+
declare global {
|
9
|
+
namespace NodeJS {
|
10
|
+
interface ReadableStream {}
|
11
|
+
}
|
12
|
+
|
13
|
+
namespace Marko {
|
14
|
+
/** A mutable global object for the current render. */
|
15
|
+
export interface Global {
|
16
|
+
[x: PropertyKey]: unknown;
|
17
|
+
/** An AbortSignal instance that, when aborted, stops further streamed content. */
|
18
|
+
signal?: AbortSignal;
|
19
|
+
/** A CSP Nonce to add to each script output from Marko. */
|
20
|
+
cspNonce?: string;
|
21
|
+
/** Used for rendering multiple Marko templates in a single hydrated page. */
|
22
|
+
renderId?: string;
|
23
|
+
/** Used to uniquely identify a instance of a Marko runtime. */
|
24
|
+
runtimeId?: string;
|
25
|
+
/** A list of globals that should be serialized to the browser. */
|
26
|
+
serializedGlobals?:
|
27
|
+
| (string | number)[]
|
28
|
+
| Record<string | number, boolean>;
|
29
|
+
}
|
30
|
+
|
31
|
+
export type TemplateInput<Input> = Input & {
|
32
|
+
/** Data available within all rendered templates as `$global`. */
|
33
|
+
$global?: Global;
|
34
|
+
};
|
35
|
+
|
36
|
+
/** Body content created by a template. */
|
37
|
+
export interface Body<
|
38
|
+
in Params extends readonly any[] = [],
|
39
|
+
out Return = void,
|
40
|
+
> {}
|
41
|
+
|
42
|
+
/** Valid data types which can be passed in as a <${dynamic}/> tag name. */
|
43
|
+
export type Renderable =
|
44
|
+
| { content: Body<any, any> | Template | string }
|
45
|
+
| Body<any, any>
|
46
|
+
| Template
|
47
|
+
| string;
|
48
|
+
|
49
|
+
/** Extract the return tag type from body content. */
|
50
|
+
export type BodyReturnType<B> =
|
51
|
+
B extends Body<any, infer Return> ? Return : never;
|
52
|
+
|
53
|
+
/** Extract the tag parameter types received by body content. */
|
54
|
+
export type BodyParameters<B> =
|
55
|
+
B extends Body<infer Params, any> ? Params : never;
|
56
|
+
|
57
|
+
/** The top level api for a Marko Template. */
|
58
|
+
export abstract class Template<Input = unknown, Return = unknown> {
|
59
|
+
/**
|
60
|
+
* The folowing types are processed up by the @marko/language-tools
|
61
|
+
* and inlined into the compiled template.
|
62
|
+
*
|
63
|
+
* This is done to support generics on each of these methods
|
64
|
+
* until TypeScript supports higher kinded types.
|
65
|
+
*
|
66
|
+
* https://github.com/microsoft/TypeScript/issues/1213
|
67
|
+
*/
|
68
|
+
|
69
|
+
/** @marko-overload-start */
|
70
|
+
/** Render the template to a string. */
|
71
|
+
abstract render(input: Marko.TemplateInput<Input>): Promise<string> &
|
72
|
+
AsyncIterable<string> & {
|
73
|
+
toReadable(): ReadableStream;
|
74
|
+
pipe(stream: {
|
75
|
+
write(chunk: string): unknown;
|
76
|
+
end(): unknown;
|
77
|
+
flush?(): void;
|
78
|
+
}): void;
|
79
|
+
toString(): string;
|
80
|
+
};
|
81
|
+
|
82
|
+
/** Render and attach the template to a DOM node. */
|
83
|
+
abstract mount(
|
84
|
+
input: Marko.TemplateInput<Input>,
|
85
|
+
reference: ParentNode & Node,
|
86
|
+
position?: "afterbegin" | "afterend" | "beforebegin" | "beforeend",
|
87
|
+
): {
|
88
|
+
update(input: Marko.TemplateInput<Input>): void;
|
89
|
+
destroy(): void;
|
90
|
+
};
|
91
|
+
/** @marko-overload-end */
|
92
|
+
}
|
93
|
+
|
94
|
+
export type AttrTag<T> = T & {
|
95
|
+
[Symbol.iterator](): Iterator<T>;
|
96
|
+
};
|
97
|
+
|
98
|
+
export interface NativeTag<
|
99
|
+
Input extends Record<string, any>,
|
100
|
+
Return extends Element,
|
101
|
+
> {
|
102
|
+
input: Input;
|
103
|
+
return: { value: () => Return };
|
104
|
+
}
|
105
|
+
export interface NativeTags {
|
106
|
+
[name: string]: NativeTag<Record<string, any>, Element>;
|
107
|
+
}
|
108
|
+
|
109
|
+
export type Input<Name> = 0 extends 1 & Name
|
110
|
+
? any
|
111
|
+
: Name extends string
|
112
|
+
? Name extends keyof NativeTags
|
113
|
+
? NativeTags[Name]["input"]
|
114
|
+
: Record<string, unknown>
|
115
|
+
: Name extends
|
116
|
+
| Template<infer Input, any>
|
117
|
+
| { _(): () => (input: infer Input) => any }
|
118
|
+
? Input
|
119
|
+
: Name extends Body<infer Args, any>
|
120
|
+
? Args extends {
|
121
|
+
length: infer Length;
|
122
|
+
}
|
123
|
+
? number extends Length
|
124
|
+
? Args[0] | undefined
|
125
|
+
: 0 extends Length
|
126
|
+
? undefined
|
127
|
+
: Args[0]
|
128
|
+
: never
|
129
|
+
: never;
|
130
|
+
|
131
|
+
export type Return<Name> = 0 extends 1 & Name
|
132
|
+
? any
|
133
|
+
: Name extends string
|
134
|
+
? Name extends keyof NativeTags
|
135
|
+
? NativeTags[Name]["return"]
|
136
|
+
: () => Element
|
137
|
+
: Name extends
|
138
|
+
| { _(): () => (input: any) => { return: infer Return } }
|
139
|
+
| Template<any, infer Return>
|
140
|
+
| Body<any, infer Return>
|
141
|
+
? Return
|
142
|
+
: never;
|
143
|
+
}
|
144
|
+
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "marko",
|
3
|
-
"version": "6.0.0-3.
|
3
|
+
"version": "6.0.0-next.3.16",
|
4
4
|
"description": "Optimized runtime for Marko templates.",
|
5
5
|
"keywords": [
|
6
6
|
"api",
|
@@ -17,23 +17,29 @@
|
|
17
17
|
},
|
18
18
|
"license": "MIT",
|
19
19
|
"exports": {
|
20
|
-
"
|
20
|
+
".": {
|
21
|
+
"types": "./index.d.ts"
|
22
|
+
},
|
21
23
|
"./package.json": "./package.json",
|
22
24
|
"./translator": "./dist/translator/index.js",
|
23
|
-
"
|
24
|
-
"types": "./dist/*.d.ts",
|
25
|
-
"import": "./dist/*.mjs",
|
26
|
-
"default": "./dist/*.js"
|
27
|
-
},
|
25
|
+
"./tag-types/*": "./tag-types/*",
|
28
26
|
"./debug/*": {
|
29
27
|
"types": "./dist/*.d.ts",
|
30
28
|
"import": "./dist/debug/*.mjs",
|
31
29
|
"default": "./dist/debug/*.js"
|
30
|
+
},
|
31
|
+
"./*": {
|
32
|
+
"types": "./dist/*.d.ts",
|
33
|
+
"import": "./dist/*.mjs",
|
34
|
+
"default": "./dist/*.js"
|
32
35
|
}
|
33
36
|
},
|
37
|
+
"types": "index.d.ts",
|
34
38
|
"files": [
|
35
39
|
"dist",
|
36
40
|
"tag-types",
|
41
|
+
"index.d.ts",
|
42
|
+
"tags-html.d.ts",
|
37
43
|
"!**/meta.*.json",
|
38
44
|
"!**/__tests__",
|
39
45
|
"!**/*.tsbuildinfo"
|
@@ -41,10 +47,18 @@
|
|
41
47
|
"scripts": {
|
42
48
|
"build": "node -r ~ts ./scripts/bundle.ts"
|
43
49
|
},
|
50
|
+
"dependencies": {
|
51
|
+
"@marko/compiler": "^5.39.7",
|
52
|
+
"csstype": "^3.1.3",
|
53
|
+
"magic-string": "^0.30.17"
|
54
|
+
},
|
44
55
|
"exports:override": {
|
45
|
-
"
|
56
|
+
".": {
|
57
|
+
"types": "./index.d.ts"
|
58
|
+
},
|
46
59
|
"./translator": "./src/translator/index.ts",
|
47
|
-
"
|
48
|
-
"./debug/*": "./src/*.ts"
|
60
|
+
"./tag-types/*": "./tag-types/*",
|
61
|
+
"./debug/*": "./src/*.ts",
|
62
|
+
"./*": "./src/*.ts"
|
49
63
|
}
|
50
64
|
}
|