marko 5.37.63 → 5.38.0

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.
@@ -599,9 +599,8 @@ function getRuntimeEntryFiles(output, optimize) {
599
599
 
600
600
  }
601
601
 
602
- function isRenderContent(path) {
603
- const { node } = path;
604
- return _compiler.types.MARKO_TYPES.includes(node.type) && !node.static;
602
+ function isRenderContent({ node }) {
603
+ return /^Marko/.test(node.type) && !node.static;
605
604
  }
606
605
 
607
606
  function resolveRelativeTagEntry(file, tagDef) {
@@ -1,4 +1,35 @@
1
- "use strict";exports.__esModule = true;exports.default = _default;function _default(path) {
1
+ "use strict";exports.__esModule = true;exports.default = _default;var _compiler = require("@marko/compiler");
2
+
3
+ function _default(path) {
2
4
  const { node } = path;
5
+ const isHTML = path.hub.file.markoOpts.output === "html";
6
+ switch (node.target) {
7
+ case "server":
8
+ if (!isHTML) {
9
+ replaceWithUndefinedIdentifiers(path);
10
+ return;
11
+ }
12
+ break;
13
+ case "client":
14
+ if (isHTML) {
15
+ replaceWithUndefinedIdentifiers(path);
16
+ return;
17
+ }
18
+ break;
19
+ }
3
20
  path.replaceWithMultiple(node.body);
21
+ }
22
+
23
+ function replaceWithUndefinedIdentifiers(path) {
24
+ const keys = Object.keys(path.getOuterBindingIdentifiers());
25
+ if (keys.length) {
26
+ path.replaceWith(
27
+ _compiler.types.variableDeclaration(
28
+ "var",
29
+ keys.map((key) => _compiler.types.variableDeclarator(_compiler.types.identifier(key)))
30
+ )
31
+ );
32
+ } else {
33
+ path.remove();
34
+ }
4
35
  }
@@ -5,9 +5,11 @@ var parseMacro = _interopRequireWildcard(require("./macro/parse"));
5
5
  var translateMacro = _interopRequireWildcard(require("./macro/translate"));
6
6
  var _migrate = _interopRequireDefault(require("./migrate"));
7
7
  var parseClass = _interopRequireWildcard(require("./parse-class"));
8
+ var parseClient = _interopRequireWildcard(require("./parse-client"));
8
9
  var parseExport = _interopRequireWildcard(require("./parse-export"));
9
10
  var parseImport = _interopRequireWildcard(require("./parse-import"));
10
11
  var parseModuleCode = _interopRequireWildcard(require("./parse-module-code"));
12
+ var parseServer = _interopRequireWildcard(require("./parse-server"));
11
13
  var parseStatic = _interopRequireWildcard(require("./parse-static"));
12
14
  var transformBody = _interopRequireWildcard(require("./transform-body"));
13
15
  var transformStyle = _interopRequireWildcard(require("./transform-style"));
@@ -55,6 +57,20 @@ var translateWhile = _interopRequireWildcard(require("./translate-while"));funct
55
57
  }]
56
58
 
57
59
  },
60
+ "<client>": {
61
+ "node-factory": parseClient,
62
+ "parse-options": {
63
+ statement: true,
64
+ rawOpenTag: true
65
+ }
66
+ },
67
+ "<server>": {
68
+ "node-factory": parseServer,
69
+ "parse-options": {
70
+ statement: true,
71
+ rawOpenTag: true
72
+ }
73
+ },
58
74
  "<class>": {
59
75
  "node-factory": parseClass,
60
76
  "parse-options": {
@@ -0,0 +1,18 @@
1
+ "use strict";exports.__esModule = true;exports.default = _default;var _compiler = require("@marko/compiler");
2
+ var _babelUtils = require("@marko/compiler/babel-utils");
3
+
4
+ function _default(path) {
5
+ const {
6
+ node,
7
+ hub: { file }
8
+ } = path;
9
+ const { rawValue, end } = node;
10
+ const code = rawValue.replace(/^client\s*/, "");
11
+ const start = node.start + (rawValue.length - code.length);
12
+ let body = (0, _babelUtils.parseStatements)(file, code, start, end);
13
+ if (body.length === 1 && _compiler.types.isBlockStatement(body[0])) {
14
+ body = body[0].body;
15
+ }
16
+
17
+ path.replaceWith(_compiler.types.markoScriptlet(body, true, "client"));
18
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";exports.__esModule = true;exports.default = _default;var _compiler = require("@marko/compiler");
2
+ var _babelUtils = require("@marko/compiler/babel-utils");
3
+
4
+ function _default(path) {
5
+ const {
6
+ node,
7
+ hub: { file }
8
+ } = path;
9
+ const { rawValue, end } = node;
10
+ const code = rawValue.replace(/^server\s*/, "");
11
+ const start = node.start + (rawValue.length - code.length);
12
+ let body = (0, _babelUtils.parseStatements)(file, code, start, end);
13
+ if (body.length === 1 && _compiler.types.isBlockStatement(body[0])) {
14
+ body = body[0].body;
15
+ }
16
+
17
+ path.replaceWith(_compiler.types.markoScriptlet(body, true, "server"));
18
+ }
@@ -140,6 +140,23 @@ const entryBuilder = exports.entryBuilder = {
140
140
  resolveRelativeToEntry(entryFile, file, value)
141
141
  );
142
142
  }
143
+ } else if (
144
+ _compiler.types.isMarkoScriptlet(child) &&
145
+ child.static &&
146
+ child.target !== "server")
147
+ {
148
+ for (const stmt of child.body) {
149
+ if (_compiler.types.isImportDeclaration(stmt)) {
150
+ const { value } = stmt.source;
151
+ if (child.target === "client" || state.shouldIncludeImport(value)) {
152
+ addImport(
153
+ imports,
154
+ body,
155
+ resolveRelativeToEntry(entryFile, file, value)
156
+ );
157
+ }
158
+ }
159
+ }
143
160
  }
144
161
  }
145
162
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marko",
3
- "version": "5.37.63",
3
+ "version": "5.38.0",
4
4
  "description": "UI Components + streaming, async, high performance, HTML templating for Node.js and the browser.",
5
5
  "keywords": [
6
6
  "front-end",
@@ -70,7 +70,7 @@
70
70
  },
71
71
  "dependencies": {
72
72
  "@babel/runtime": "^7.28.2",
73
- "@marko/compiler": "^5.39.43",
73
+ "@marko/compiler": "^5.39.44",
74
74
  "app-module-path": "^2.2.0",
75
75
  "argly": "^1.2.0",
76
76
  "browser-refresh-client": "1.1.4",
@@ -599,9 +599,8 @@ export function getRuntimeEntryFiles(output, optimize) {
599
599
  ];
600
600
  }
601
601
 
602
- function isRenderContent(path) {
603
- const { node } = path;
604
- return t.MARKO_TYPES.includes(node.type) && !node.static;
602
+ function isRenderContent({ node }) {
603
+ return /^Marko/.test(node.type) && !node.static;
605
604
  }
606
605
 
607
606
  function resolveRelativeTagEntry(file, tagDef) {
@@ -1,4 +1,35 @@
1
+ import { types as t } from "@marko/compiler";
2
+
1
3
  export default function (path) {
2
4
  const { node } = path;
5
+ const isHTML = path.hub.file.markoOpts.output === "html";
6
+ switch (node.target) {
7
+ case "server":
8
+ if (!isHTML) {
9
+ replaceWithUndefinedIdentifiers(path);
10
+ return;
11
+ }
12
+ break;
13
+ case "client":
14
+ if (isHTML) {
15
+ replaceWithUndefinedIdentifiers(path);
16
+ return;
17
+ }
18
+ break;
19
+ }
3
20
  path.replaceWithMultiple(node.body);
4
21
  }
22
+
23
+ function replaceWithUndefinedIdentifiers(path) {
24
+ const keys = Object.keys(path.getOuterBindingIdentifiers());
25
+ if (keys.length) {
26
+ path.replaceWith(
27
+ t.variableDeclaration(
28
+ "var",
29
+ keys.map((key) => t.variableDeclarator(t.identifier(key))),
30
+ ),
31
+ );
32
+ } else {
33
+ path.remove();
34
+ }
35
+ }
@@ -5,9 +5,11 @@ import * as parseMacro from "./macro/parse";
5
5
  import * as translateMacro from "./macro/translate";
6
6
  import migrate from "./migrate";
7
7
  import * as parseClass from "./parse-class";
8
+ import * as parseClient from "./parse-client";
8
9
  import * as parseExport from "./parse-export";
9
10
  import * as parseImport from "./parse-import";
10
11
  import * as parseModuleCode from "./parse-module-code";
12
+ import * as parseServer from "./parse-server";
11
13
  import * as parseStatic from "./parse-static";
12
14
  import * as transformBody from "./transform-body";
13
15
  import * as transformStyle from "./transform-style";
@@ -55,6 +57,20 @@ export default {
55
57
  },
56
58
  ],
57
59
  },
60
+ "<client>": {
61
+ "node-factory": parseClient,
62
+ "parse-options": {
63
+ statement: true,
64
+ rawOpenTag: true,
65
+ },
66
+ },
67
+ "<server>": {
68
+ "node-factory": parseServer,
69
+ "parse-options": {
70
+ statement: true,
71
+ rawOpenTag: true,
72
+ },
73
+ },
58
74
  "<class>": {
59
75
  "node-factory": parseClass,
60
76
  "parse-options": {
@@ -0,0 +1,18 @@
1
+ import { types as t } from "@marko/compiler";
2
+ import { parseStatements } from "@marko/compiler/babel-utils";
3
+
4
+ export default function (path) {
5
+ const {
6
+ node,
7
+ hub: { file },
8
+ } = path;
9
+ const { rawValue, end } = node;
10
+ const code = rawValue.replace(/^client\s*/, "");
11
+ const start = node.start + (rawValue.length - code.length);
12
+ let body = parseStatements(file, code, start, end);
13
+ if (body.length === 1 && t.isBlockStatement(body[0])) {
14
+ body = body[0].body;
15
+ }
16
+
17
+ path.replaceWith(t.markoScriptlet(body, true, "client"));
18
+ }
@@ -0,0 +1,18 @@
1
+ import { types as t } from "@marko/compiler";
2
+ import { parseStatements } from "@marko/compiler/babel-utils";
3
+
4
+ export default function (path) {
5
+ const {
6
+ node,
7
+ hub: { file },
8
+ } = path;
9
+ const { rawValue, end } = node;
10
+ const code = rawValue.replace(/^server\s*/, "");
11
+ const start = node.start + (rawValue.length - code.length);
12
+ let body = parseStatements(file, code, start, end);
13
+ if (body.length === 1 && t.isBlockStatement(body[0])) {
14
+ body = body[0].body;
15
+ }
16
+
17
+ path.replaceWith(t.markoScriptlet(body, true, "server"));
18
+ }
@@ -140,6 +140,23 @@ export const entryBuilder = {
140
140
  resolveRelativeToEntry(entryFile, file, value),
141
141
  );
142
142
  }
143
+ } else if (
144
+ t.isMarkoScriptlet(child) &&
145
+ child.static &&
146
+ child.target !== "server"
147
+ ) {
148
+ for (const stmt of child.body) {
149
+ if (t.isImportDeclaration(stmt)) {
150
+ const { value } = stmt.source;
151
+ if (child.target === "client" || state.shouldIncludeImport(value)) {
152
+ addImport(
153
+ imports,
154
+ body,
155
+ resolveRelativeToEntry(entryFile, file, value),
156
+ );
157
+ }
158
+ }
159
+ }
143
160
  }
144
161
  }
145
162