marko 5.38.7 → 5.38.9

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.
@@ -177,12 +177,16 @@ function _default(path, isNullable) {
177
177
  }
178
178
 
179
179
  let needsBlock;
180
+ let needsIIFE;
180
181
  for (const childNode of body) {
181
182
  if (_compiler.types.isVariableDeclaration(childNode)) {
182
183
  if (childNode.kind === "const" || childNode.kind === "let") {
183
184
  needsBlock = true;
184
- break;
185
+ } else {
186
+ needsIIFE = true;
185
187
  }
188
+
189
+ break;
186
190
  }
187
191
  }
188
192
 
@@ -203,7 +207,18 @@ function _default(path, isNullable) {
203
207
 
204
208
  path.replaceWithMultiple(
205
209
  [writeStartNode].
206
- concat(needsBlock ? _compiler.types.blockStatement(body) : body).
210
+ concat(
211
+ needsIIFE ?
212
+ _compiler.types.expressionStatement(
213
+ _compiler.types.callExpression(
214
+ _compiler.types.arrowFunctionExpression([], _compiler.types.blockStatement(body)),
215
+ []
216
+ )
217
+ ) :
218
+ needsBlock ?
219
+ _compiler.types.blockStatement(body) :
220
+ body
221
+ ).
207
222
  concat(writeEndNode)
208
223
  );
209
224
  }
@@ -65,18 +65,33 @@ function _default(path, isNullable) {
65
65
  }
66
66
 
67
67
  let needsBlock;
68
+ let needsIIFE;
68
69
  for (const childNode of body) {
69
70
  if (_compiler.types.isVariableDeclaration(childNode)) {
70
71
  if (childNode.kind === "const" || childNode.kind === "let") {
71
72
  needsBlock = true;
72
- break;
73
+ } else {
74
+ needsIIFE = true;
73
75
  }
76
+
77
+ break;
74
78
  }
75
79
  }
76
80
 
77
81
  path.replaceWithMultiple(
78
82
  [writeStartNode].
79
- concat(needsBlock ? _compiler.types.blockStatement(body) : body).
83
+ concat(
84
+ needsIIFE ?
85
+ _compiler.types.expressionStatement(
86
+ _compiler.types.callExpression(
87
+ _compiler.types.arrowFunctionExpression([], _compiler.types.blockStatement(body)),
88
+ []
89
+ )
90
+ ) :
91
+ needsBlock ?
92
+ _compiler.types.blockStatement(body) :
93
+ body
94
+ ).
80
95
  concat(writeEndNode)
81
96
  );
82
97
  }
@@ -267,52 +267,54 @@ function importPath(path) {
267
267
  }
268
268
 
269
269
  function tryGetTemplateImports(file, rendererRelativePath) {
270
- const resolvedRendererPath = _path.default.join(
271
- file.opts.filename,
272
- "..",
273
- rendererRelativePath
270
+ const resolvedRendererPath = tryResolveFrom(
271
+ rendererRelativePath,
272
+ file.opts.filename
274
273
  );
275
274
  let templateImports;
276
275
 
277
- try {
278
- for (const statement of (0, _babelUtils.parseStatements)(
279
- file,
280
- file.markoOpts.fileSystem.readFileSync(resolvedRendererPath, "utf-8")
281
- )) {
282
- if (statement.type === "ImportDeclaration") {
283
- addTemplateImport(statement.source.value);
284
- } else {
285
- _compiler.types.traverseFast(statement, (node) => {
286
- if (
287
- node.type === "CallExpression" && (
288
- node.callee.name === "require" ||
289
- node.callee.type === "MemberExpression" &&
290
- node.callee.object.type === "Identifier" &&
291
- node.callee.object.name === "require" &&
292
- node.callee.property.type === "Identifier" &&
293
- node.callee.property.name === "resolve") &&
294
- node.arguments.length === 1 &&
295
- node.arguments[0].type === "StringLiteral")
296
- {
297
- addTemplateImport(node.arguments[0].value);
276
+ if (resolvedRendererPath) {
277
+ if (resolvedRendererPath.endsWith(".marko")) {
278
+ addTemplateImport(resolvedRendererPath);
279
+ } else if (resolvedRendererPath.endsWith(".js")) {
280
+ try {
281
+ for (const statement of (0, _babelUtils.parseStatements)(
282
+ file,
283
+ file.markoOpts.fileSystem.readFileSync(resolvedRendererPath, "utf-8")
284
+ )) {
285
+ if (statement.type === "ImportDeclaration") {
286
+ addTemplateImport(statement.source.value);
287
+ } else {
288
+ _compiler.types.traverseFast(statement, (node) => {
289
+ if (
290
+ node.type === "CallExpression" && (
291
+ node.callee.name === "require" ||
292
+ node.callee.type === "MemberExpression" &&
293
+ node.callee.object.type === "Identifier" &&
294
+ node.callee.object.name === "require" &&
295
+ node.callee.property.type === "Identifier" &&
296
+ node.callee.property.name === "resolve") &&
297
+ node.arguments.length === 1 &&
298
+ node.arguments[0].type === "StringLiteral")
299
+ {
300
+ addTemplateImport(node.arguments[0].value);
301
+ }
302
+ });
298
303
  }
299
- });
300
- }
301
- }
302
- } catch {
304
+ }
305
+ } catch {
303
306
 
304
- // Ignore
307
+ // Ignore
308
+ }}
305
309
  }
310
+
306
311
  return templateImports;
307
312
 
308
313
  function addTemplateImport(request) {
309
314
  if (request.endsWith(".marko")) {
310
- const resolvedTemplatePath =
311
- request[0] === "." ?
312
- _path.default.resolve(resolvedRendererPath, "..", request) :
313
- _modules.default.tryResolve(
315
+ const resolvedTemplatePath = tryResolveFrom(
314
316
  request,
315
- _path.default.dirname(resolvedRendererPath)
317
+ resolvedRendererPath
316
318
  );
317
319
  if (resolvedTemplatePath) {
318
320
  if (templateImports) {
@@ -325,6 +327,14 @@ function tryGetTemplateImports(file, rendererRelativePath) {
325
327
  }
326
328
  }
327
329
 
330
+ function tryResolveFrom(request, from) {
331
+ return request[0] === "." ?
332
+ _path.default.resolve(from, "..", request) :
333
+ /^(?:[/\\]|[a-zA-Z]:)/.test(request) ?
334
+ request :
335
+ _modules.default.tryResolve(request, _path.default.dirname(from));
336
+ }
337
+
328
338
  function toTestFn(val) {
329
339
  if (typeof val === "function") {
330
340
  return val;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marko",
3
- "version": "5.38.7",
3
+ "version": "5.38.9",
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.45",
73
+ "@marko/compiler": "^5.39.47",
74
74
  "@marko/runtime-tags": "^6.0.126",
75
75
  "app-module-path": "^2.2.0",
76
76
  "argly": "^1.2.0",
@@ -177,12 +177,16 @@ export default function (path, isNullable) {
177
177
  }
178
178
 
179
179
  let needsBlock;
180
+ let needsIIFE;
180
181
  for (const childNode of body) {
181
182
  if (t.isVariableDeclaration(childNode)) {
182
183
  if (childNode.kind === "const" || childNode.kind === "let") {
183
184
  needsBlock = true;
184
- break;
185
+ } else {
186
+ needsIIFE = true;
185
187
  }
188
+
189
+ break;
186
190
  }
187
191
  }
188
192
 
@@ -203,7 +207,18 @@ export default function (path, isNullable) {
203
207
 
204
208
  path.replaceWithMultiple(
205
209
  [writeStartNode]
206
- .concat(needsBlock ? t.blockStatement(body) : body)
210
+ .concat(
211
+ needsIIFE
212
+ ? t.expressionStatement(
213
+ t.callExpression(
214
+ t.arrowFunctionExpression([], t.blockStatement(body)),
215
+ [],
216
+ ),
217
+ )
218
+ : needsBlock
219
+ ? t.blockStatement(body)
220
+ : body,
221
+ )
207
222
  .concat(writeEndNode),
208
223
  );
209
224
  }
@@ -65,18 +65,33 @@ export default function (path, isNullable) {
65
65
  }
66
66
 
67
67
  let needsBlock;
68
+ let needsIIFE;
68
69
  for (const childNode of body) {
69
70
  if (t.isVariableDeclaration(childNode)) {
70
71
  if (childNode.kind === "const" || childNode.kind === "let") {
71
72
  needsBlock = true;
72
- break;
73
+ } else {
74
+ needsIIFE = true;
73
75
  }
76
+
77
+ break;
74
78
  }
75
79
  }
76
80
 
77
81
  path.replaceWithMultiple(
78
82
  [writeStartNode]
79
- .concat(needsBlock ? t.blockStatement(body) : body)
83
+ .concat(
84
+ needsIIFE
85
+ ? t.expressionStatement(
86
+ t.callExpression(
87
+ t.arrowFunctionExpression([], t.blockStatement(body)),
88
+ [],
89
+ ),
90
+ )
91
+ : needsBlock
92
+ ? t.blockStatement(body)
93
+ : body,
94
+ )
80
95
  .concat(writeEndNode),
81
96
  );
82
97
  }
@@ -267,53 +267,55 @@ function importPath(path) {
267
267
  }
268
268
 
269
269
  function tryGetTemplateImports(file, rendererRelativePath) {
270
- const resolvedRendererPath = path.join(
271
- file.opts.filename,
272
- "..",
270
+ const resolvedRendererPath = tryResolveFrom(
273
271
  rendererRelativePath,
272
+ file.opts.filename,
274
273
  );
275
274
  let templateImports;
276
275
 
277
- try {
278
- for (const statement of parseStatements(
279
- file,
280
- file.markoOpts.fileSystem.readFileSync(resolvedRendererPath, "utf-8"),
281
- )) {
282
- if (statement.type === "ImportDeclaration") {
283
- addTemplateImport(statement.source.value);
284
- } else {
285
- t.traverseFast(statement, (node) => {
286
- if (
287
- node.type === "CallExpression" &&
288
- (node.callee.name === "require" ||
289
- (node.callee.type === "MemberExpression" &&
290
- node.callee.object.type === "Identifier" &&
291
- node.callee.object.name === "require" &&
292
- node.callee.property.type === "Identifier" &&
293
- node.callee.property.name === "resolve")) &&
294
- node.arguments.length === 1 &&
295
- node.arguments[0].type === "StringLiteral"
296
- ) {
297
- addTemplateImport(node.arguments[0].value);
276
+ if (resolvedRendererPath) {
277
+ if (resolvedRendererPath.endsWith(".marko")) {
278
+ addTemplateImport(resolvedRendererPath);
279
+ } else if (resolvedRendererPath.endsWith(".js")) {
280
+ try {
281
+ for (const statement of parseStatements(
282
+ file,
283
+ file.markoOpts.fileSystem.readFileSync(resolvedRendererPath, "utf-8"),
284
+ )) {
285
+ if (statement.type === "ImportDeclaration") {
286
+ addTemplateImport(statement.source.value);
287
+ } else {
288
+ t.traverseFast(statement, (node) => {
289
+ if (
290
+ node.type === "CallExpression" &&
291
+ (node.callee.name === "require" ||
292
+ (node.callee.type === "MemberExpression" &&
293
+ node.callee.object.type === "Identifier" &&
294
+ node.callee.object.name === "require" &&
295
+ node.callee.property.type === "Identifier" &&
296
+ node.callee.property.name === "resolve")) &&
297
+ node.arguments.length === 1 &&
298
+ node.arguments[0].type === "StringLiteral"
299
+ ) {
300
+ addTemplateImport(node.arguments[0].value);
301
+ }
302
+ });
298
303
  }
299
- });
304
+ }
305
+ } catch {
306
+ // Ignore
300
307
  }
301
308
  }
302
- } catch {
303
- // Ignore
304
309
  }
305
310
 
306
311
  return templateImports;
307
312
 
308
313
  function addTemplateImport(request) {
309
314
  if (request.endsWith(".marko")) {
310
- const resolvedTemplatePath =
311
- request[0] === "."
312
- ? path.resolve(resolvedRendererPath, "..", request)
313
- : markoModules.tryResolve(
314
- request,
315
- path.dirname(resolvedRendererPath),
316
- );
315
+ const resolvedTemplatePath = tryResolveFrom(
316
+ request,
317
+ resolvedRendererPath,
318
+ );
317
319
  if (resolvedTemplatePath) {
318
320
  if (templateImports) {
319
321
  templateImports.push(resolvedTemplatePath);
@@ -325,6 +327,14 @@ function tryGetTemplateImports(file, rendererRelativePath) {
325
327
  }
326
328
  }
327
329
 
330
+ function tryResolveFrom(request, from) {
331
+ return request[0] === "."
332
+ ? path.resolve(from, "..", request)
333
+ : /^(?:[/\\]|[a-zA-Z]:)/.test(request)
334
+ ? request
335
+ : markoModules.tryResolve(request, path.dirname(from));
336
+ }
337
+
328
338
  function toTestFn(val) {
329
339
  if (typeof val === "function") {
330
340
  return val;