@marko/compiler 5.39.34 → 5.39.36

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.
@@ -1,4 +1,5 @@
1
- "use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.default = void 0;var _traverse = _interopRequireDefault(require("@babel/traverse"));
1
+ "use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.default = void 0;var _pluginTransformTypescript = _interopRequireDefault(require("@babel/plugin-transform-typescript"));
2
+ var _traverse = _interopRequireDefault(require("@babel/traverse"));
2
3
  var _path = _interopRequireDefault(require("path"));
3
4
 
4
5
  var t = _interopRequireWildcard(require("../babel-types"));
@@ -17,7 +18,8 @@ var _parser = require("./parser");
17
18
  var _migrate = require("./plugins/migrate");
18
19
  var _transform = require("./plugins/transform");function _interopRequireWildcard(e, t) {if ("function" == typeof WeakMap) var r = new WeakMap(),n = new WeakMap();return (_interopRequireWildcard = function (e, t) {if (!t && e && e.__esModule) return e;var o,i,f = { __proto__: null, default: e };if (null === e || "object" != typeof e && "function" != typeof e) return f;if (o = t ? n : r) {if (o.has(e)) return o.get(e);o.set(e, f);}for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]);return f;})(e, t);}
19
20
 
20
- const SOURCE_FILES = new WeakMap();var _default =
21
+ const SOURCE_FILES = new WeakMap();
22
+ let stripTypesVisitor;var _default =
21
23
 
22
24
  (api, markoOpts) => {
23
25
  api.assertVersion(7);
@@ -46,6 +48,17 @@ const SOURCE_FILES = new WeakMap();var _default =
46
48
  );
47
49
  }
48
50
 
51
+ if (markoOpts.stripTypes) {
52
+ stripTypesVisitor ||= (0, _pluginTransformTypescript.default)(api, {
53
+ isTSX: false,
54
+ allowNamespaces: true,
55
+ allowDeclareFields: true,
56
+ optimizeConstEnums: true,
57
+ onlyRemoveTypeImports: true,
58
+ disallowAmbiguousJSXLike: false
59
+ }).visitor;
60
+ }
61
+
49
62
  let curOpts;
50
63
 
51
64
  return {
@@ -60,6 +73,14 @@ const SOURCE_FILES = new WeakMap();var _default =
60
73
  opts.parserOpts.allowUndeclaredExports =
61
74
  opts.parserOpts.allowNewTargetOutsideFunction =
62
75
  true;
76
+
77
+ opts.parserOpts.plugins.push("objectRestSpread", "classProperties", [
78
+ "typescript",
79
+ {
80
+ disallowAmbiguousJSXLike: false,
81
+ dts: false
82
+ }]
83
+ );
63
84
  curOpts = opts;
64
85
  },
65
86
  parserOverride(code) {
@@ -120,29 +141,7 @@ const SOURCE_FILES = new WeakMap();var _default =
120
141
  file.___getMarkoFile =
121
142
  undefined;
122
143
  }
123
- },
124
- visitor:
125
- markoOpts.stripTypes && isMarkoOutput(markoOpts.output) ?
126
- {
127
- MarkoClass(path) {
128
- // We replace the MarkoClass with a regular class declaration so babel can strip it's types.
129
- path.replaceWith(
130
- t.classDeclaration(t.identifier(""), null, path.node.body)
131
- );
132
- },
133
- ExportNamedDeclaration: {
134
- exit(path) {
135
- const { node } = path;
136
- // The babel typescript plugin will add an empty export declaration
137
- // if there are no other imports/exports in the file.
138
- // This is not needed for Marko file outputs since there is always
139
- // a default export.
140
- if (!(node.declaration || node.specifiers.length))
141
- path.remove();
142
- }
143
- }
144
- } :
145
- undefined
144
+ }
146
145
  };
147
146
  };exports.default = _default;
148
147
 
@@ -275,6 +274,49 @@ function getMarkoFile(code, fileOpts, markoOpts) {
275
274
  return file;
276
275
  }
277
276
 
277
+ file.___compileStage = "transform";
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
+
296
+ traverseAll(file, stripTypesVisitor);
297
+
298
+ for (const path of file.path.get("body")) {
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
+ path.remove();
312
+ // Add back imports from scriptlets that were
313
+ // hoisted for the babel typescript transform.
314
+ scriptlet.body.unshift(importNode);
315
+ }
316
+ }
317
+ }
318
+ }
319
+
278
320
  const rootTransformers = [];
279
321
  for (const id in taglibLookup.taglibsById) {
280
322
  for (const transformer of taglibLookup.taglibsById[id].transformers) {
@@ -286,7 +328,6 @@ function getMarkoFile(code, fileOpts, markoOpts) {
286
328
  if (translator.transform) {
287
329
  rootTransformers.push(translator.transform);
288
330
  }
289
- file.___compileStage = "transform";
290
331
  traverseAll(file, rootTransformers);
291
332
 
292
333
  for (const taglibId in taglibLookup.taglibsById) {
@@ -378,7 +419,7 @@ function traverseAll(file, visitors) {
378
419
  program.node,
379
420
  mergeVisitors(visitors),
380
421
  program.scope,
381
- program.state = {},
422
+ program.state = { file },
382
423
  program,
383
424
  true
384
425
  );
@@ -94,7 +94,7 @@ const MarkoDefinitions = {
94
94
  },
95
95
 
96
96
  MarkoClass: {
97
- aliases: ["Marko", "Statement"],
97
+ aliases: ["Marko", "Statement", "Class"],
98
98
  builder: ["body"],
99
99
  visitor: ["body"],
100
100
  fields: {
package/dist/index.js CHANGED
@@ -1,8 +1,6 @@
1
1
  "use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports._clearDefaults = _clearDefaults;exports.compile = compile;exports.compileFile = compileFile;exports.compileFileSync = compileFileSync;exports.compileSync = compileSync;exports.configure = configure;exports.getRuntimeEntryFiles = getRuntimeEntryFiles;exports.types = exports.taglib = exports.globalConfig = void 0;var _types = _interopRequireWildcard(require("./babel-types"));exports.types = _types;
2
2
  var babel = _interopRequireWildcard(require("@babel/core"));
3
- var _pluginSyntaxTypescript = _interopRequireDefault(require("@babel/plugin-syntax-typescript"));
4
3
  var _pluginTransformModulesCommonjs = _interopRequireDefault(require("@babel/plugin-transform-modules-commonjs"));
5
- var _pluginTransformTypescript = _interopRequireDefault(require("@babel/plugin-transform-typescript"));
6
4
  var _babelUtils = require("@marko/compiler/babel-utils");
7
5
  var _modules = _interopRequireDefault(require("@marko/compiler/modules"));
8
6
  var _path = _interopRequireDefault(require("path"));
@@ -87,20 +85,7 @@ function loadBabelConfigSync(filename, config) {
87
85
 
88
86
  function getBaseBabelConfig(filename, { babelConfig, ...markoConfig }) {
89
87
  const isTranslated = isTranslatedOutput(markoConfig.output);
90
- const requiredPlugins = [
91
- [_babelPlugin.default, markoConfig],
92
- [
93
- markoConfig.stripTypes ? _pluginTransformTypescript.default : _pluginSyntaxTypescript.default,
94
- {
95
- isTSX: false,
96
- allowNamespaces: true,
97
- allowDeclareFields: true,
98
- optimizeConstEnums: true,
99
- onlyRemoveTypeImports: true,
100
- disallowAmbiguousJSXLike: false
101
- }]];
102
-
103
-
88
+ const requiredPlugins = [[_babelPlugin.default, markoConfig]];
104
89
  const baseBabelConfig = {
105
90
  filenameRelative: filename ?
106
91
  _path.default.relative(_modules.default.cwd, filename) :
package/dist/types.d.ts CHANGED
@@ -1826,7 +1826,7 @@ export type ObjectMember = ObjectMethod | ObjectProperty;
1826
1826
  export type Property = ObjectProperty | ClassProperty | ClassAccessorProperty | ClassPrivateProperty;
1827
1827
  export type UnaryLike = UnaryExpression | SpreadElement;
1828
1828
  export type Pattern = AssignmentPattern | ArrayPattern | ObjectPattern | VoidPattern;
1829
- export type Class = ClassExpression | ClassDeclaration;
1829
+ export type Class = ClassExpression | ClassDeclaration | MarkoClass;
1830
1830
  export type ImportOrExportDeclaration = ExportAllDeclaration | ExportDefaultDeclaration | ExportNamedDeclaration | ImportDeclaration;
1831
1831
  export type ExportDeclaration = ExportAllDeclaration | ExportDefaultDeclaration | ExportNamedDeclaration;
1832
1832
  export type ModuleSpecifier = ExportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier | ImportSpecifier | ExportNamespaceSpecifier | ExportDefaultSpecifier;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marko/compiler",
3
- "version": "5.39.34",
3
+ "version": "5.39.36",
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.53"
90
+ "marko": "^5.37.56"
91
91
  },
92
92
  "engines": {
93
93
  "node": "18 || 20 || >=22"