marko 5.38.7 → 5.38.8

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.
@@ -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.8",
4
4
  "description": "UI Components + streaming, async, high performance, HTML templating for Node.js and the browser.",
5
5
  "keywords": [
6
6
  "front-end",
@@ -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;