marko 5.39.41 → 5.39.42

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.
@@ -61,6 +61,8 @@ function AsyncStream(global, writer, parentOut) {
61
61
  state = parentOut._state;
62
62
  originalStream = state.stream;
63
63
  } else {
64
+ // Render errors are emitted on the destination stream itself; as with any Node stream an
65
+ // unhandled "error" throws, so callers of `render(input, stream)` must listen for it.
64
66
  var events = finalGlobal.events /* deprecated */ =
65
67
  writer && writer.on ? writer : new EventEmitter();
66
68
 
@@ -634,6 +636,7 @@ var proto = AsyncStream.prototype = {
634
636
  name ? " " + name : "") + (
635
637
  stack ? ":\n" + stack : "");
636
638
  }
639
+ this._state.g_ = e;
637
640
  try {
638
641
  this.emit("error", e);
639
642
  } finally {
@@ -781,6 +784,8 @@ var proto = AsyncStream.prototype = {
781
784
  return new Promise(function (resolve, reject) {
782
785
  out.on("error", reject);
783
786
  out.on("finish", function (result) {
787
+ var error = out._state.g_;
788
+ if (error) reject(error);else
784
789
  resolve(result);
785
790
  });
786
791
  }).then(fn, fnErr);
@@ -23,6 +23,18 @@ function safeRender(renderFunc, finalData, finalOut, shouldEnd) {
23
23
  return finalOut;
24
24
  }
25
25
 
26
+ function listen(out, callback, getResult) {
27
+ var failed = false;
28
+ out.
29
+ on("finish", function () {
30
+ if (!failed) callback(null, getResult(), out);
31
+ }).
32
+ once("error", function (err) {
33
+ failed = true;
34
+ callback(err);
35
+ });
36
+ }
37
+
26
38
  module.exports = function (target, renderer) {
27
39
  var renderFunc =
28
40
  renderer && (renderer.renderer || renderer.render || renderer);
@@ -45,11 +57,9 @@ module.exports = function (target, renderer) {
45
57
  }
46
58
 
47
59
  if (callback) {
48
- out.
49
- on("finish", function () {
50
- callback(null, out.toString(), out);
51
- }).
52
- once("error", callback);
60
+ listen(out, callback, function () {
61
+ return out.toString();
62
+ });
53
63
 
54
64
  return safeRender(render, localData, out, true);
55
65
  } else {
@@ -177,11 +187,9 @@ module.exports = function (target, renderer) {
177
187
  }
178
188
 
179
189
  if (callback) {
180
- finalOut.
181
- on("finish", function () {
182
- callback(null, finalOut.n_(), finalOut);
183
- }).
184
- once("error", callback);
190
+ listen(finalOut, callback, function () {
191
+ return finalOut.n_();
192
+ });
185
193
  }
186
194
 
187
195
  globalData = finalOut.global;
@@ -258,6 +258,7 @@ var proto = AsyncVDOMBuilder.prototype = {
258
258
  },
259
259
 
260
260
  error: function (e) {
261
+ this.A_.g_ = e;
261
262
  try {
262
263
  this.emit("error", e);
263
264
  } finally {
@@ -427,6 +428,8 @@ var proto = AsyncVDOMBuilder.prototype = {
427
428
  var out = this;
428
429
  var promise = new Promise(function (resolve, reject) {
429
430
  out.on("error", reject).on(EVENT_FINISH, function (result) {
431
+ var error = out.A_.g_;
432
+ if (error) reject(error);else
430
433
  resolve(result);
431
434
  });
432
435
  });
@@ -145,6 +145,8 @@ const analyze = exports.analyze = {
145
145
  }
146
146
  }
147
147
 
148
+ // Class and Tags templates only interoperate when imported by their `.marko` path: one reached
149
+ // through a JS module (barrel, glob) is not seen here, so no compat runtime is linked for it.
148
150
  if (relativePath) {
149
151
  tag.node.extra = tag.node.extra || {};
150
152
  tag.node.extra.relativePath = relativePath;
@@ -170,6 +170,8 @@ _marko.json_
170
170
 
171
171
  This example file tells Marko to expose all components directly under the `dist/components/` directory to the application using your package.
172
172
 
173
+ If your components are written in TypeScript, publish the output of [`mtc`](https://github.com/marko-js/language-server/tree/main/packages/type-check). Editors and type checkers read components under `node_modules` as JavaScript, so consumers get their types from the `.d.marko` files it emits. See [TypeScript in Marko](./typescript.md).
174
+
173
175
  We recommend adding the `marko` and `components` keywords to your `package.json` so others can find your components. Then `npm publish`!
174
176
 
175
177
  # Macros
package/docs/http.md CHANGED
@@ -20,7 +20,10 @@ server.on("request", (req, res) => {
20
20
  colors: ["red", "green", "blue"],
21
21
  },
22
22
  res,
23
- );
23
+ ).on("error", (err) => {
24
+ // Without a listener, a render error crashes the process.
25
+ console.error(err);
26
+ });
24
27
  });
25
28
 
26
29
  server.listen(port, () => {
@@ -134,6 +134,7 @@ Similar to [`marko-tag.json`](#single-component-definition), this file is discov
134
134
  "exports": "./dist", // Where to export the compiled components.
135
135
  "tags-dir": "./ui-modules", // What directory to crawl to autodiscover components. Default:`./components/`
136
136
  "taglib-imports": ["./some-folder/marko.json", "./other-folder/marko.json"], // Creates a _combined_ tag library by referencing others.
137
+ "script-lang": "ts", // Overrides the default script language, "js" or "ts", for mixed code such as an incremental TypeScript migration.
137
138
 
138
139
  "tags": { // Definitions for individual tags.
139
140
  "my-tag": {
package/docs/rendering.md CHANGED
@@ -100,7 +100,7 @@ View.render({}, (err, result) => {
100
100
  | `stream` | `WritableStream` | a writeable stream |
101
101
  | return value | `AsyncStream`/`AsyncVDOMBuilder` | the async `out` render target |
102
102
 
103
- The HTML output is written to the passed `stream`.
103
+ The HTML output is written to the passed `stream`. Render errors are emitted as `"error"` events on the stream, and like any unhandled stream `"error"` event, one without a listener crashes the process, so always attach one:
104
104
 
105
105
  ```js
106
106
  import http from "http";
@@ -108,7 +108,9 @@ import View from "./view.marko";
108
108
 
109
109
  http.createServer((req, res) => {
110
110
  res.setHeader("content-type", "text/html");
111
- View.render({}, res);
111
+ View.render({}, res).on("error", (err) => {
112
+ console.error(err);
113
+ });
112
114
  });
113
115
  ```
114
116
 
@@ -18,13 +18,9 @@ There are two (non-exclusive) ways to add TypeScript to a Marko project:
18
18
  📦 package.json
19
19
  <mark><img src="./icons/ts.svg" width=16> tsconfig.json</mark>
20
20
  </pre>
21
- - **If you’re [publishing packages of Marko tags](https://markojs.com/docs/custom-tags/#publishing-tags-to-npm)**, add the following to [your `marko.json`](./marko-json.md):
22
- ```json
23
- "script-lang": "ts"
24
- ```
25
- This will automatically expose type-checking and autocomplete for the published tags.
21
+ - **If you’re [publishing packages of Marko tags](./custom-tags.md#publishing-tags-to-npm)**, publish the output of [`mtc`](#ci-type-checking). Each component gets a `.d.marko` file with its types, which editors and type checkers read in place of the `.marko` file. This exposes type-checking and autocomplete for the published tags.
26
22
 
27
- > **ProTip**: You can also use the `script-lang` method for sites and apps.
23
+ > **ProTip**: For mixed JavaScript and TypeScript code, such as an incremental migration, set `"script-lang": "ts"` or `"js"` in [a `marko.json`](./marko-json.md) to override these defaults. The nearest `marko.json` up the directory tree applies, so folders can opt in or out.
28
24
 
29
25
  ## Typing a tag's `input`
30
26
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marko",
3
- "version": "5.39.41",
3
+ "version": "5.39.42",
4
4
  "private": false,
5
5
  "description": "UI Components + streaming, async, high performance, HTML templating for Node.js and the browser.",
6
6
  "keywords": [
@@ -67,8 +67,8 @@
67
67
  },
68
68
  "types": "index.d.ts",
69
69
  "dependencies": {
70
- "@marko/compiler": "^5.42.5",
71
- "@marko/runtime-tags": "^6.3.52",
70
+ "@marko/compiler": "^5.42.6",
71
+ "@marko/runtime-tags": "^6.3.53",
72
72
  "app-module-path": "^2.2.0",
73
73
  "argly": "^1.2.0",
74
74
  "browser-refresh-client": "1.1.4",
@@ -84,7 +84,7 @@
84
84
  "warp10": "^2.1.0"
85
85
  },
86
86
  "devDependencies": {
87
- "marko": "5.39.41"
87
+ "marko": "5.39.42"
88
88
  },
89
89
  "engines": {
90
90
  "node": ">=22"
@@ -61,6 +61,8 @@ function AsyncStream(global, writer, parentOut) {
61
61
  state = parentOut._state;
62
62
  originalStream = state.stream;
63
63
  } else {
64
+ // Render errors are emitted on the destination stream itself; as with any Node stream an
65
+ // unhandled "error" throws, so callers of `render(input, stream)` must listen for it.
64
66
  var events = (finalGlobal.events /* deprecated */ =
65
67
  writer && writer.on ? writer : new EventEmitter());
66
68
 
@@ -634,6 +636,7 @@ var proto = (AsyncStream.prototype = {
634
636
  (name ? " " + name : "") +
635
637
  (stack ? ":\n" + stack : "");
636
638
  }
639
+ this._state.___error = e;
637
640
  try {
638
641
  this.emit("error", e);
639
642
  } finally {
@@ -781,7 +784,9 @@ var proto = (AsyncStream.prototype = {
781
784
  return new Promise(function (resolve, reject) {
782
785
  out.on("error", reject);
783
786
  out.on("finish", function (result) {
784
- resolve(result);
787
+ var error = out._state.___error;
788
+ if (error) reject(error);
789
+ else resolve(result);
785
790
  });
786
791
  }).then(fn, fnErr);
787
792
  },
@@ -23,6 +23,18 @@ function safeRender(renderFunc, finalData, finalOut, shouldEnd) {
23
23
  return finalOut;
24
24
  }
25
25
 
26
+ function listen(out, callback, getResult) {
27
+ var failed = false;
28
+ out
29
+ .on("finish", function () {
30
+ if (!failed) callback(null, getResult(), out);
31
+ })
32
+ .once("error", function (err) {
33
+ failed = true;
34
+ callback(err);
35
+ });
36
+ }
37
+
26
38
  module.exports = function (target, renderer) {
27
39
  var renderFunc =
28
40
  renderer && (renderer.renderer || renderer.render || renderer);
@@ -45,11 +57,9 @@ module.exports = function (target, renderer) {
45
57
  }
46
58
 
47
59
  if (callback) {
48
- out
49
- .on("finish", function () {
50
- callback(null, out.toString(), out);
51
- })
52
- .once("error", callback);
60
+ listen(out, callback, function () {
61
+ return out.toString();
62
+ });
53
63
 
54
64
  return safeRender(render, localData, out, true);
55
65
  } else {
@@ -177,11 +187,9 @@ module.exports = function (target, renderer) {
177
187
  }
178
188
 
179
189
  if (callback) {
180
- finalOut
181
- .on("finish", function () {
182
- callback(null, finalOut.___getResult(), finalOut);
183
- })
184
- .once("error", callback);
190
+ listen(finalOut, callback, function () {
191
+ return finalOut.___getResult();
192
+ });
185
193
  }
186
194
 
187
195
  globalData = finalOut.global;
@@ -258,6 +258,7 @@ var proto = (AsyncVDOMBuilder.prototype = {
258
258
  },
259
259
 
260
260
  error: function (e) {
261
+ this.___state.___error = e;
261
262
  try {
262
263
  this.emit("error", e);
263
264
  } finally {
@@ -427,7 +428,9 @@ var proto = (AsyncVDOMBuilder.prototype = {
427
428
  var out = this;
428
429
  var promise = new Promise(function (resolve, reject) {
429
430
  out.on("error", reject).on(EVENT_FINISH, function (result) {
430
- resolve(result);
431
+ var error = out.___state.___error;
432
+ if (error) reject(error);
433
+ else resolve(result);
431
434
  });
432
435
  });
433
436
 
@@ -145,6 +145,8 @@ export const analyze = {
145
145
  }
146
146
  }
147
147
 
148
+ // Class and Tags templates only interoperate when imported by their `.marko` path: one reached
149
+ // through a JS module (barrel, glob) is not seen here, so no compat runtime is linked for it.
148
150
  if (relativePath) {
149
151
  tag.node.extra = tag.node.extra || {};
150
152
  tag.node.extra.relativePath = relativePath;