marko 6.0.0-3.8 → 6.0.0-next.3.15
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 +27 -21
- package/dist/debug/dom.mjs +27 -21
- 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 +23 -18
- package/dist/dom.mjs +23 -18
- 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 +105 -79
- 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()) {
|
@@ -7329,9 +7359,7 @@ var script_default = {
|
|
7329
7359
|
const { node } = tag;
|
7330
7360
|
const { body } = node.body;
|
7331
7361
|
if (body.length) {
|
7332
|
-
|
7333
|
-
const codeSuffix = "}";
|
7334
|
-
let code = codePrefix;
|
7362
|
+
let code = "";
|
7335
7363
|
for (const child of body) {
|
7336
7364
|
if (child.type !== "MarkoText") {
|
7337
7365
|
throw tag.hub.file.hub.buildError(
|
@@ -7342,22 +7370,15 @@ var script_default = {
|
|
7342
7370
|
}
|
7343
7371
|
code += child.value;
|
7344
7372
|
}
|
7345
|
-
code += codeSuffix;
|
7346
7373
|
const start = body[0]?.start;
|
7347
7374
|
const end = body[body.length - 1]?.end;
|
7348
|
-
const
|
7349
|
-
|
7350
|
-
|
7351
|
-
|
7352
|
-
|
7353
|
-
codePrefix.length
|
7354
|
-
);
|
7355
|
-
bodyExpression.async = traverseContains(
|
7356
|
-
bodyExpression.body,
|
7357
|
-
isAwaitExpression
|
7375
|
+
const bodyStatements = (0, import_babel_utils30.parseStatements)(tag.hub.file, code, start, end);
|
7376
|
+
const valueFn = import_compiler41.types.arrowFunctionExpression(
|
7377
|
+
[],
|
7378
|
+
import_compiler41.types.blockStatement(bodyStatements),
|
7379
|
+
traverseContains(bodyStatements, isAwaitExpression)
|
7358
7380
|
);
|
7359
|
-
|
7360
|
-
node.attributes.push(import_compiler41.types.markoAttribute("value", bodyExpression));
|
7381
|
+
node.attributes.push(import_compiler41.types.markoAttribute("value", valueFn));
|
7361
7382
|
node.body.body = [];
|
7362
7383
|
}
|
7363
7384
|
},
|
@@ -8190,21 +8211,21 @@ function translateHTML(tag) {
|
|
8190
8211
|
statements: []
|
8191
8212
|
};
|
8192
8213
|
if (node.extra.tagNameNullable) {
|
8193
|
-
const
|
8194
|
-
let
|
8195
|
-
if (
|
8196
|
-
const
|
8197
|
-
|
8198
|
-
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(
|
8199
8220
|
import_compiler49.types.variableDeclaration("const", [
|
8200
8221
|
import_compiler49.types.variableDeclarator(
|
8201
|
-
|
8222
|
+
contentId,
|
8202
8223
|
// TODO: only register if needed (child template analysis)
|
8203
|
-
|
8224
|
+
contentExpression
|
8204
8225
|
)
|
8205
8226
|
])
|
8206
8227
|
);
|
8207
|
-
|
8228
|
+
contentPath.skip();
|
8208
8229
|
}
|
8209
8230
|
let renderTagExpr = callExpression(
|
8210
8231
|
tagIdentifier,
|
@@ -8218,7 +8239,7 @@ function translateHTML(tag) {
|
|
8218
8239
|
import_compiler49.types.ifStatement(
|
8219
8240
|
tagIdentifier,
|
8220
8241
|
import_compiler49.types.expressionStatement(renderTagExpr),
|
8221
|
-
|
8242
|
+
contentId && callStatement(contentId)
|
8222
8243
|
)
|
8223
8244
|
);
|
8224
8245
|
} else if (tagVar) {
|
@@ -8577,26 +8598,26 @@ function writeAttrsToExports(tag, templateExport, importAlias, info) {
|
|
8577
8598
|
}
|
8578
8599
|
}
|
8579
8600
|
const bodySection = tag.node.body.extra?.section;
|
8580
|
-
if (bodySection && !seen.has("
|
8581
|
-
seen.add("
|
8582
|
-
if (templateExport.props.
|
8583
|
-
const
|
8601
|
+
if (bodySection && !seen.has("content")) {
|
8602
|
+
seen.add("content");
|
8603
|
+
if (templateExport.props.content) {
|
8604
|
+
const contentExportIdentifier = (0, import_babel_utils37.importNamed)(
|
8584
8605
|
tag.hub.file,
|
8585
8606
|
info.relativePath,
|
8586
|
-
templateExport.props.
|
8587
|
-
`${importAlias}
|
8607
|
+
templateExport.props.content.id,
|
8608
|
+
`${importAlias}_content`
|
8588
8609
|
);
|
8589
8610
|
addValue(
|
8590
8611
|
info.tagSection,
|
8591
8612
|
void 0,
|
8592
|
-
// TODO: pretty sure
|
8593
|
-
identifierToSignal(
|
8613
|
+
// TODO: pretty sure content needs to have the reference group of it's param defaults.
|
8614
|
+
identifierToSignal(contentExportIdentifier),
|
8594
8615
|
import_compiler49.types.callExpression(import_compiler49.types.identifier(bodySection.name), [scopeIdentifier]),
|
8595
8616
|
createScopeReadExpression(info.tagSection, info.childScopeBinding),
|
8596
8617
|
callRuntime(
|
8597
8618
|
"inChild",
|
8598
8619
|
getScopeAccessorLiteral(info.childScopeBinding),
|
8599
|
-
import_compiler49.types.identifier(
|
8620
|
+
import_compiler49.types.identifier(contentExportIdentifier.name)
|
8600
8621
|
)
|
8601
8622
|
);
|
8602
8623
|
}
|
@@ -8748,6 +8769,7 @@ var dynamic_tag_default = {
|
|
8748
8769
|
const extra = node.extra;
|
8749
8770
|
const nodeRef2 = extra[kDOMBinding];
|
8750
8771
|
const section = getSection(tag);
|
8772
|
+
const isClassAPI = extra.featureType === "class";
|
8751
8773
|
let tagExpression = node.name;
|
8752
8774
|
if (import_compiler50.types.isStringLiteral(tagExpression)) {
|
8753
8775
|
tagExpression = (0, import_babel_utils38.importDefault)(
|
@@ -8756,15 +8778,13 @@ var dynamic_tag_default = {
|
|
8756
8778
|
tagExpression.value
|
8757
8779
|
);
|
8758
8780
|
}
|
8759
|
-
if (
|
8760
|
-
const compatRuntimeFile = getCompatRuntimeFile(tag.hub.file.markoOpts);
|
8761
|
-
(0, import_babel_utils38.importDefault)(tag.hub.file, compatRuntimeFile);
|
8781
|
+
if (isClassAPI) {
|
8762
8782
|
if (isOutputHTML()) {
|
8763
8783
|
currentProgramPath.pushContainer(
|
8764
8784
|
"body",
|
8765
8785
|
import_compiler50.types.expressionStatement(
|
8766
8786
|
import_compiler50.types.callExpression(
|
8767
|
-
(0, import_babel_utils38.importNamed)(tag.hub.file,
|
8787
|
+
(0, import_babel_utils38.importNamed)(tag.hub.file, getCompatRuntimeFile(), "s"),
|
8768
8788
|
[
|
8769
8789
|
import_compiler50.types.identifier(tagExpression.name),
|
8770
8790
|
import_compiler50.types.stringLiteral((0, import_babel_utils38.loadFileForTag)(tag).metadata.marko.id)
|
@@ -8785,7 +8805,12 @@ var dynamic_tag_default = {
|
|
8785
8805
|
);
|
8786
8806
|
}
|
8787
8807
|
}
|
8788
|
-
const { properties, statements } = translateAttrs(
|
8808
|
+
const { properties, statements } = translateAttrs(
|
8809
|
+
tag,
|
8810
|
+
void 0,
|
8811
|
+
void 0,
|
8812
|
+
isClassAPI ? "renderBody" : "content"
|
8813
|
+
);
|
8789
8814
|
const args = [];
|
8790
8815
|
let hasMultipleArgs = false;
|
8791
8816
|
if (node.arguments?.length) {
|
@@ -8797,10 +8822,10 @@ var dynamic_tag_default = {
|
|
8797
8822
|
hasMultipleArgs = node.arguments.length > 1 || import_compiler50.types.isSpreadElement(node.arguments[0]);
|
8798
8823
|
}
|
8799
8824
|
} else {
|
8800
|
-
const
|
8801
|
-
if (
|
8802
|
-
properties.splice(properties.indexOf(
|
8803
|
-
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);
|
8804
8829
|
} else {
|
8805
8830
|
args.push(propsToExpression(properties));
|
8806
8831
|
}
|
@@ -8981,9 +9006,6 @@ var dynamic_tag_default = {
|
|
8981
9006
|
}
|
8982
9007
|
}
|
8983
9008
|
};
|
8984
|
-
function getCompatRuntimeFile(markoOpts) {
|
8985
|
-
return `marko/src/runtime/helpers/tags-compat/${isOutputHTML() ? "html" : "dom"}${markoOpts.optimize ? "" : "-debug"}.${markoOpts.modules === "esm" ? "mjs" : "js"}`;
|
8986
|
-
}
|
8987
9009
|
|
8988
9010
|
// src/translator/visitors/tag/index.ts
|
8989
9011
|
var tag_default = {
|
@@ -9179,6 +9201,8 @@ var visitors = extractVisitors({
|
|
9179
9201
|
MarkoScriptlet: scriptlet_default,
|
9180
9202
|
MarkoComment: comment_default
|
9181
9203
|
});
|
9204
|
+
var tagDiscoveryDirs = ["tags"];
|
9205
|
+
var preferAPI = "tags";
|
9182
9206
|
var { transform, analyze, translate } = visitors;
|
9183
9207
|
var taglibs = [
|
9184
9208
|
[
|
@@ -9199,6 +9223,8 @@ function getRuntimeEntryFiles(output, optimize) {
|
|
9199
9223
|
analyze,
|
9200
9224
|
getRuntimeEntryFiles,
|
9201
9225
|
internalEntryBuilder,
|
9226
|
+
preferAPI,
|
9227
|
+
tagDiscoveryDirs,
|
9202
9228
|
taglibs,
|
9203
9229
|
transform,
|
9204
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
|
+
}
|