@marko/compiler 5.39.35 → 5.39.37

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.
@@ -276,18 +276,57 @@ function getMarkoFile(code, fileOpts, markoOpts) {
276
276
 
277
277
  file.___compileStage = "transform";
278
278
  if (markoOpts.stripTypes) {
279
+ const importScriptlets = new Map();
280
+ for (const path of file.path.get("body")) {
281
+ if (path.type === "MarkoScriptlet" && path.node.static) {
282
+ for (const stmt of path.get("body")) {
283
+ if (stmt.isImportDeclaration()) {
284
+ // Hoist import declarations from scriptlets
285
+ // temporarily so that they will be processed by
286
+ // babel typescript transform.
287
+ const importNode = stmt.node;
288
+ importScriptlets.set(importNode, path.node);
289
+ stmt.remove();
290
+ path.insertBefore(importNode);
291
+ }
292
+ }
293
+ }
294
+ }
295
+
279
296
  traverseAll(file, stripTypesVisitor);
280
297
 
281
298
  for (const path of file.path.get("body")) {
282
- if (
283
- path.type === "ExportNamedDeclaration" &&
284
- !(path.node.declaration || path.node.specifiers.length))
285
- {
286
- // The babel typescript plugin will add an empty export declaration
287
- // if there are no other imports/exports in the file.
288
- // This is not needed for Marko file outputs since there is always
289
- // a default export.
290
- path.remove();
299
+ if (path.type === "ExportNamedDeclaration") {
300
+ if (!(path.node.declaration || path.node.specifiers.length)) {
301
+ // The babel typescript plugin will add an empty export declaration
302
+ // if there are no other imports/exports in the file.
303
+ // This is not needed for Marko file outputs since there is always
304
+ // a default export.
305
+ path.remove();
306
+ }
307
+ } else if (path.isImportDeclaration()) {
308
+ const importNode = path.node;
309
+ const scriptlet = importScriptlets.get(importNode);
310
+ if (scriptlet) {
311
+ let hasTypes = false;
312
+ for (const specifier of path.get("specifiers")) {
313
+ if (
314
+ specifier.node.type === "ImportSpecifier" &&
315
+ specifier.node.importKind === "type")
316
+ {
317
+ hasTypes = true;
318
+ specifier.remove();
319
+ }
320
+ }
321
+
322
+ path.remove();
323
+
324
+ // Add back imports from scriptlets that were
325
+ // hoisted for the babel typescript transform.
326
+ if (!hasTypes || importNode.specifiers.length) {
327
+ scriptlet.body.unshift(importNode);
328
+ }
329
+ }
291
330
  }
292
331
  }
293
332
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marko/compiler",
3
- "version": "5.39.35",
3
+ "version": "5.39.37",
4
4
  "description": "Marko template to JS compiler.",
5
5
  "keywords": [
6
6
  "babel",
@@ -87,7 +87,7 @@
87
87
  "source-map-support": "^0.5.21"
88
88
  },
89
89
  "devDependencies": {
90
- "marko": "^5.37.55"
90
+ "marko": "^5.37.57"
91
91
  },
92
92
  "engines": {
93
93
  "node": "18 || 20 || >=22"