marko 5.39.39 → 5.39.41

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.
@@ -2,6 +2,8 @@
2
2
 
3
3
  // eslint-disable-next-line no-constant-binary-expression
4
4
 
5
+ // eslint-disable-next-line no-constant-binary-expression
6
+
5
7
  var EventEmitter = require("events-light");
6
8
  var SubscriptionTracker = require("listener-tracker");
7
9
  var inherit = require("raptor-util/inherit");
@@ -432,7 +434,10 @@ Component.prototype = componentProto = {
432
434
  // We need to set a flag to preview `this.input = foo` inside
433
435
  // onInput causing infinite recursion
434
436
  this.ap_ = true;
435
- updatedInput = onInput.call(this, newInput || {}, out);
437
+ // eslint-disable-next-line no-constant-condition
438
+ updatedInput =
439
+
440
+ onInput.call(this, newInput || {}, out);
436
441
  this.ap_ = false;
437
442
  }
438
443
 
@@ -482,7 +487,12 @@ Component.prototype = componentProto = {
482
487
  // The UI component is still dirty after process state handlers
483
488
  // then we should rerender
484
489
 
485
- if (this.shouldUpdate(input, state) !== false) {
490
+ if (
491
+ // eslint-disable-next-line no-constant-condition
492
+
493
+
494
+ this.shouldUpdate(input, state) !== false)
495
+ {
486
496
  this.aA_();
487
497
  }
488
498
  }
@@ -611,27 +621,41 @@ Component.prototype = componentProto = {
611
621
 
612
622
  aH_: emit,
613
623
  aI_(input, out) {
614
- this.onCreate && this.onCreate(input, out);
624
+ this.onCreate &&
625
+ // eslint-disable-next-line no-constant-condition
626
+
627
+
628
+ this.onCreate(input, out);
615
629
  this.aH_("create", input, out);
616
630
  },
617
631
 
618
632
  aJ_(out) {
619
- this.onRender && this.onRender(out);
633
+ this.onRender &&
634
+ // eslint-disable-next-line no-constant-condition
635
+
636
+
637
+ this.onRender(out);
620
638
  this.aH_("render", out);
621
639
  },
622
640
 
623
641
  _A_() {
624
- this.onUpdate && this.onUpdate();
642
+ this.onUpdate &&
643
+ // eslint-disable-next-line no-constant-condition
644
+ this.onUpdate();
625
645
  this.aH_("update");
626
646
  },
627
647
 
628
648
  _B_() {
629
- this.onMount && this.onMount();
649
+ this.onMount &&
650
+ // eslint-disable-next-line no-constant-condition
651
+ this.onMount();
630
652
  this.aH_("mount");
631
653
  },
632
654
 
633
655
  ar_() {
634
- this.onDestroy && this.onDestroy();
656
+ this.onDestroy &&
657
+ // eslint-disable-next-line no-constant-condition
658
+ this.onDestroy();
635
659
  this.aH_("destroy");
636
660
  }
637
661
  };
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  // eslint-disable-next-line no-constant-binary-expression
3
3
 
4
+ // eslint-disable-next-line no-constant-binary-expression
5
+
4
6
  var extend = require("raptor-util/extend");
5
7
  var componentUtil = require("@internal/components-util");
6
8
  var w10NOOP = require("../helpers/serialize-noop").aM_;
@@ -123,10 +125,17 @@ ComponentDef._F_ = function (o, types, global, registry) {
123
125
  !(flags & FLAG_OLD_HYDRATE_NO_CREATE))
124
126
  {
125
127
  if (component.onCreate) {
128
+ // eslint-disable-next-line no-constant-condition
129
+
130
+
126
131
  component.onCreate(input, { global: global });
127
132
  }
128
133
  if (component.onInput) {
129
- input = component.onInput(input, { global: global }) || input;
134
+ input =
135
+ // eslint-disable-next-line no-constant-condition
136
+
137
+
138
+ component.onInput(input, { global: global }) || input;
130
139
  }
131
140
  } else {
132
141
  if (state) {
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  // eslint-disable-next-line no-constant-binary-expression
3
3
 
4
+ // eslint-disable-next-line no-constant-binary-expression
5
+
4
6
 
5
7
  class ServerComponent {
6
8
  constructor(id, input, out, typeName, customEvents, scope) {
@@ -11,11 +13,21 @@ class ServerComponent {
11
13
  this.Z_ = undefined; // Used to keep track of bubbling DOM events for components rendered on the server
12
14
  this._a_ = 0;
13
15
 
16
+ // eslint-disable-next-line no-constant-condition
17
+
18
+
14
19
  this.onCreate(input, out);
15
- this._b_ = this.onInput(input, out) || input;
20
+ this._b_ =
21
+ // eslint-disable-next-line no-constant-condition
22
+
23
+
24
+ this.onInput(input, out) || input;
16
25
  if (this.P_ === undefined) {
17
26
  this.P_ = this._b_;
18
27
  }
28
+ // eslint-disable-next-line no-constant-condition
29
+
30
+
19
31
  this.onRender(out);
20
32
  }
21
33
 
@@ -0,0 +1,16 @@
1
+ "use strict";module.exports = function invokeLifecycle(component, name, args, method) {
2
+ try {
3
+ return (method || component[name]).apply(component, args);
4
+ } catch (error) {
5
+ throw new Error(
6
+ "Error in " +
7
+ name +
8
+ ' for component "' + (
9
+ component._s_ || component.typeName) +
10
+ '" (id: ' +
11
+ component.id +
12
+ ").",
13
+ { cause: error }
14
+ );
15
+ }
16
+ };
@@ -1,4 +1,6 @@
1
1
  "use strict";var copyProps = require("raptor-util/copyProps");
2
+ // eslint-disable-next-line no-constant-binary-expression
3
+
2
4
  var beginComponent = require("@internal/components-beginComponent");
3
5
  var endComponent = require("@internal/components-endComponent");
4
6
  var registry = require("@internal/components-registry");
@@ -185,6 +187,12 @@ renderingLogic)
185
187
  if (isExisting === true) {
186
188
  if (
187
189
  component.ax_ === false ||
190
+ // eslint-disable-next-line no-constant-condition
191
+
192
+
193
+
194
+
195
+
188
196
  component.shouldUpdate(input, component.A_) === false)
189
197
  {
190
198
  // We put a placeholder element in the output stream to ensure that the existing
@@ -3,6 +3,9 @@ var setImmediate = require("@internal/set-immediate")._l_;
3
3
  var updateManager = require("../components/update-manager");
4
4
  var runtime = require(".");
5
5
 
6
+
7
+
8
+
6
9
  var createTemplate = runtime.t;
7
10
  var createComponent = registry._I_;
8
11
  var registered = {};
@@ -38,7 +41,11 @@ exports.t = runtime.t = function (typeName) {
38
41
  instance.R_ = (input, out) => {
39
42
  instance.aI_(input, out);
40
43
  if (instance.onInput) {
41
- input = instance.onInput(input, out) || input;
44
+ input =
45
+ // eslint-disable-next-line no-constant-condition
46
+
47
+
48
+ instance.onInput(input, out) || input;
42
49
  }
43
50
  instance.R_ = renderer;
44
51
  instance.R_(input, out);
@@ -130,7 +130,11 @@ const analyze = exports.analyze = {
130
130
  const tagName = tag.node.name.value;
131
131
  const binding =
132
132
  /^[A-Z][a-zA-Z0-9_$]*$/.test(tagName) && tag.scope.getBinding(tagName);
133
- if (binding && binding.kind === "module" && binding.identifier.loc) {
133
+ if (
134
+ binding &&
135
+ binding.path.isImportDefaultSpecifier() &&
136
+ binding.identifier.loc)
137
+ {
134
138
  const importSource = binding.path.parent.source.value;
135
139
  relativePath = (0, _babelUtils.resolveTagImport)(tag, importSource) || importSource;
136
140
  tag.node.extra = tag.node.extra || {};
@@ -22,6 +22,23 @@ function enter(path) {
22
22
  );
23
23
  }
24
24
 
25
+ const body = path.get("body");
26
+ const unsupported =
27
+ body.get("params")[0] ||
28
+ body.
29
+ get("body").
30
+ find(
31
+ (child) =>
32
+ !child.isMarkoComment() &&
33
+ !(child.isMarkoText() && !child.node.value.trim())
34
+ );
35
+
36
+ if (unsupported) {
37
+ throw unsupported.buildCodeFrameError(
38
+ 'The "<await>" tag does not support body content or tag parameters. Use "<@then|result|>" instead.'
39
+ );
40
+ }
41
+
25
42
  const [provider] = args;
26
43
  path.pushContainer(
27
44
  "attributes",
@@ -14,7 +14,13 @@ function getComponentFiles({ hub: { file } }) {
14
14
  const { filename } = file.opts;
15
15
  const fs = file.markoOpts.fileSystem;
16
16
  const dirname = _path.default.dirname(filename);
17
- const dirFiles = fs.readdirSync(dirname).sort();
17
+ let dirFiles;
18
+ try {
19
+ dirFiles = fs.readdirSync(dirname).sort();
20
+ } catch {
21
+ // An in-memory source may name a directory that does not exist.
22
+ dirFiles = [];
23
+ }
18
24
  const base = getBase(filename);
19
25
  const isEntry = "index" === base || "template" === base;
20
26
  const fileMatch = `(${(0, _escapeRegexp.escapeRegExp)(base)}\\.${isEntry ? "|" : ""})`;
package/index.d.ts CHANGED
@@ -1,10 +1,5 @@
1
1
  import "./tags-html";
2
2
 
3
- declare module "*.marko" {
4
- const template: Marko.Template;
5
- export default template;
6
- }
7
-
8
3
  declare global {
9
4
  namespace NodeJS {
10
5
  interface ReadableStream {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marko",
3
- "version": "5.39.39",
3
+ "version": "5.39.41",
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.4",
71
- "@marko/runtime-tags": "^6.3.49",
70
+ "@marko/compiler": "^5.42.5",
71
+ "@marko/runtime-tags": "^6.3.52",
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.39"
87
+ "marko": "5.39.41"
88
88
  },
89
89
  "engines": {
90
90
  "node": ">=22"
@@ -2,6 +2,8 @@
2
2
 
3
3
  // eslint-disable-next-line no-constant-binary-expression
4
4
  var complain = "MARKO_DEBUG" && require("complain");
5
+ // eslint-disable-next-line no-constant-binary-expression
6
+ var invokeLifecycle = "MARKO_DEBUG" && require("./invoke-lifecycle");
5
7
  var EventEmitter = require("events-light");
6
8
  var SubscriptionTracker = require("listener-tracker");
7
9
  var inherit = require("raptor-util/inherit");
@@ -432,7 +434,10 @@ Component.prototype = componentProto = {
432
434
  // We need to set a flag to preview `this.input = foo` inside
433
435
  // onInput causing infinite recursion
434
436
  this.___settingInput = true;
435
- updatedInput = onInput.call(this, newInput || {}, out);
437
+ // eslint-disable-next-line no-constant-condition
438
+ updatedInput = "MARKO_DEBUG"
439
+ ? invokeLifecycle(this, "onInput", [newInput || {}, out], onInput)
440
+ : onInput.call(this, newInput || {}, out);
436
441
  this.___settingInput = false;
437
442
  }
438
443
 
@@ -482,7 +487,12 @@ Component.prototype = componentProto = {
482
487
  // The UI component is still dirty after process state handlers
483
488
  // then we should rerender
484
489
 
485
- if (this.shouldUpdate(input, state) !== false) {
490
+ if (
491
+ // eslint-disable-next-line no-constant-condition
492
+ ("MARKO_DEBUG"
493
+ ? invokeLifecycle(this, "shouldUpdate", [input, state])
494
+ : this.shouldUpdate(input, state)) !== false
495
+ ) {
486
496
  this.___scheduleRerender();
487
497
  }
488
498
  }
@@ -611,27 +621,41 @@ Component.prototype = componentProto = {
611
621
 
612
622
  ___emit: emit,
613
623
  ___emitCreate(input, out) {
614
- this.onCreate && this.onCreate(input, out);
624
+ this.onCreate &&
625
+ // eslint-disable-next-line no-constant-condition
626
+ ("MARKO_DEBUG"
627
+ ? invokeLifecycle(this, "onCreate", [input, out])
628
+ : this.onCreate(input, out));
615
629
  this.___emit("create", input, out);
616
630
  },
617
631
 
618
632
  ___emitRender(out) {
619
- this.onRender && this.onRender(out);
633
+ this.onRender &&
634
+ // eslint-disable-next-line no-constant-condition
635
+ ("MARKO_DEBUG"
636
+ ? invokeLifecycle(this, "onRender", [out])
637
+ : this.onRender(out));
620
638
  this.___emit("render", out);
621
639
  },
622
640
 
623
641
  ___emitUpdate() {
624
- this.onUpdate && this.onUpdate();
642
+ this.onUpdate &&
643
+ // eslint-disable-next-line no-constant-condition
644
+ ("MARKO_DEBUG" ? invokeLifecycle(this, "onUpdate") : this.onUpdate());
625
645
  this.___emit("update");
626
646
  },
627
647
 
628
648
  ___emitMount() {
629
- this.onMount && this.onMount();
649
+ this.onMount &&
650
+ // eslint-disable-next-line no-constant-condition
651
+ ("MARKO_DEBUG" ? invokeLifecycle(this, "onMount") : this.onMount());
630
652
  this.___emit("mount");
631
653
  },
632
654
 
633
655
  ___emitDestroy() {
634
- this.onDestroy && this.onDestroy();
656
+ this.onDestroy &&
657
+ // eslint-disable-next-line no-constant-condition
658
+ ("MARKO_DEBUG" ? invokeLifecycle(this, "onDestroy") : this.onDestroy());
635
659
  this.___emit("destroy");
636
660
  },
637
661
  };
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  // eslint-disable-next-line no-constant-binary-expression
3
3
  var complain = "MARKO_DEBUG" && require("complain");
4
+ // eslint-disable-next-line no-constant-binary-expression
5
+ var invokeLifecycle = "MARKO_DEBUG" && require("./invoke-lifecycle");
4
6
  var extend = require("raptor-util/extend");
5
7
  var componentUtil = require("@internal/components-util");
6
8
  var w10NOOP = require("../helpers/serialize-noop").___noop;
@@ -123,10 +125,17 @@ ComponentDef.___deserialize = function (o, types, global, registry) {
123
125
  !(flags & FLAG_OLD_HYDRATE_NO_CREATE)
124
126
  ) {
125
127
  if (component.onCreate) {
126
- component.onCreate(input, { global: global });
128
+ // eslint-disable-next-line no-constant-condition
129
+ "MARKO_DEBUG"
130
+ ? invokeLifecycle(component, "onCreate", [input, { global: global }])
131
+ : component.onCreate(input, { global: global });
127
132
  }
128
133
  if (component.onInput) {
129
- input = component.onInput(input, { global: global }) || input;
134
+ input =
135
+ // eslint-disable-next-line no-constant-condition
136
+ ("MARKO_DEBUG"
137
+ ? invokeLifecycle(component, "onInput", [input, { global: global }])
138
+ : component.onInput(input, { global: global })) || input;
130
139
  }
131
140
  } else {
132
141
  if (state) {
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  // eslint-disable-next-line no-constant-binary-expression
3
3
  var complain = "MARKO_DEBUG" && require("complain");
4
+ // eslint-disable-next-line no-constant-binary-expression
5
+ var invokeLifecycle = "MARKO_DEBUG" && require("./invoke-lifecycle");
4
6
 
5
7
  class ServerComponent {
6
8
  constructor(id, input, out, typeName, customEvents, scope) {
@@ -11,12 +13,22 @@ class ServerComponent {
11
13
  this.___bubblingDomEvents = undefined; // Used to keep track of bubbling DOM events for components rendered on the server
12
14
  this.___bubblingDomEventsExtraArgsCount = 0;
13
15
 
14
- this.onCreate(input, out);
15
- this.___updatedInput = this.onInput(input, out) || input;
16
+ // eslint-disable-next-line no-constant-condition
17
+ "MARKO_DEBUG"
18
+ ? invokeLifecycle(this, "onCreate", [input, out])
19
+ : this.onCreate(input, out);
20
+ this.___updatedInput =
21
+ // eslint-disable-next-line no-constant-condition
22
+ ("MARKO_DEBUG"
23
+ ? invokeLifecycle(this, "onInput", [input, out])
24
+ : this.onInput(input, out)) || input;
16
25
  if (this.___input === undefined) {
17
26
  this.___input = this.___updatedInput;
18
27
  }
19
- this.onRender(out);
28
+ // eslint-disable-next-line no-constant-condition
29
+ "MARKO_DEBUG"
30
+ ? invokeLifecycle(this, "onRender", [out])
31
+ : this.onRender(out);
20
32
  }
21
33
 
22
34
  set input(newInput) {
@@ -0,0 +1,16 @@
1
+ module.exports = function invokeLifecycle(component, name, args, method) {
2
+ try {
3
+ return (method || component[name]).apply(component, args);
4
+ } catch (error) {
5
+ throw new Error(
6
+ "Error in " +
7
+ name +
8
+ ' for component "' +
9
+ (component.___type || component.typeName) +
10
+ '" (id: ' +
11
+ component.id +
12
+ ").",
13
+ { cause: error },
14
+ );
15
+ }
16
+ };
@@ -1,4 +1,6 @@
1
1
  var copyProps = require("raptor-util/copyProps");
2
+ // eslint-disable-next-line no-constant-binary-expression
3
+ var invokeLifecycle = "MARKO_DEBUG" && require("./invoke-lifecycle");
2
4
  var beginComponent = require("@internal/components-beginComponent");
3
5
  var endComponent = require("@internal/components-endComponent");
4
6
  var registry = require("@internal/components-registry");
@@ -185,7 +187,13 @@ function createRendererFunc(
185
187
  if (isExisting === true) {
186
188
  if (
187
189
  component.___isDirty === false ||
188
- component.shouldUpdate(input, component.___state) === false
190
+ // eslint-disable-next-line no-constant-condition
191
+ ("MARKO_DEBUG"
192
+ ? invokeLifecycle(component, "shouldUpdate", [
193
+ input,
194
+ component.___state,
195
+ ])
196
+ : component.shouldUpdate(input, component.___state)) === false
189
197
  ) {
190
198
  // We put a placeholder element in the output stream to ensure that the existing
191
199
  // DOM node is matched up correctly when using morphdom. We flag the VElement
@@ -2,6 +2,9 @@ var registry = require("@internal/components-registry");
2
2
  var setImmediate = require("@internal/set-immediate").___setImmediate;
3
3
  var updateManager = require("../components/update-manager");
4
4
  var runtime = require(".");
5
+ var invokeLifecycle =
6
+ // eslint-disable-next-line no-constant-binary-expression
7
+ "MARKO_DEBUG" && require("../components/invoke-lifecycle");
5
8
 
6
9
  var createTemplate = runtime.t;
7
10
  var createComponent = registry.___createComponent;
@@ -38,7 +41,11 @@ exports.t = runtime.t = function (typeName) {
38
41
  instance.___renderer = (input, out) => {
39
42
  instance.___emitCreate(input, out);
40
43
  if (instance.onInput) {
41
- input = instance.onInput(input, out) || input;
44
+ input =
45
+ // eslint-disable-next-line no-constant-condition
46
+ ("MARKO_DEBUG"
47
+ ? invokeLifecycle(instance, "onInput", [input, out])
48
+ : instance.onInput(input, out)) || input;
42
49
  }
43
50
  instance.___renderer = renderer;
44
51
  instance.___renderer(input, out);
@@ -130,7 +130,11 @@ export const analyze = {
130
130
  const tagName = tag.node.name.value;
131
131
  const binding =
132
132
  /^[A-Z][a-zA-Z0-9_$]*$/.test(tagName) && tag.scope.getBinding(tagName);
133
- if (binding && binding.kind === "module" && binding.identifier.loc) {
133
+ if (
134
+ binding &&
135
+ binding.path.isImportDefaultSpecifier() &&
136
+ binding.identifier.loc
137
+ ) {
134
138
  const importSource = binding.path.parent.source.value;
135
139
  relativePath = resolveTagImport(tag, importSource) || importSource;
136
140
  tag.node.extra = tag.node.extra || {};
@@ -22,6 +22,23 @@ export function enter(path) {
22
22
  );
23
23
  }
24
24
 
25
+ const body = path.get("body");
26
+ const unsupported =
27
+ body.get("params")[0] ||
28
+ body
29
+ .get("body")
30
+ .find(
31
+ (child) =>
32
+ !child.isMarkoComment() &&
33
+ !(child.isMarkoText() && !child.node.value.trim()),
34
+ );
35
+
36
+ if (unsupported) {
37
+ throw unsupported.buildCodeFrameError(
38
+ 'The "<await>" tag does not support body content or tag parameters. Use "<@then|result|>" instead.',
39
+ );
40
+ }
41
+
25
42
  const [provider] = args;
26
43
  path.pushContainer(
27
44
  "attributes",
@@ -14,7 +14,13 @@ export default function getComponentFiles({ hub: { file } }) {
14
14
  const { filename } = file.opts;
15
15
  const fs = file.markoOpts.fileSystem;
16
16
  const dirname = path.dirname(filename);
17
- const dirFiles = fs.readdirSync(dirname).sort();
17
+ let dirFiles;
18
+ try {
19
+ dirFiles = fs.readdirSync(dirname).sort();
20
+ } catch {
21
+ // An in-memory source may name a directory that does not exist.
22
+ dirFiles = [];
23
+ }
18
24
  const base = getBase(filename);
19
25
  const isEntry = "index" === base || "template" === base;
20
26
  const fileMatch = `(${escapeRegExp(base)}\\.${isEntry ? "|" : ""})`;