@marko/compiler 5.21.7 → 5.22.2

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.
@@ -102,6 +102,7 @@ const SOURCE_FILES = new WeakMap();var _default =
102
102
  undefined;
103
103
 
104
104
  metadata.marko.watchFiles = metadata.marko.watchFiles.filter(unique);
105
+ file.path.scope.crawl(); // Ensure all scopes are accurate for subsequent babel plugins
105
106
  } finally {
106
107
  (0, _fs.setFS)(prevFS);
107
108
  }
@@ -267,9 +267,9 @@ function parseMarko(file) {
267
267
  onTagVar(part) {
268
268
  currentTag.node.var = (0, _babelUtils.parseExpression)(
269
269
  file,
270
- `${parser.read(part.value)}=1`,
271
- part.value.start).
272
- left;
270
+ `(${parser.read(part.value)})=>{}`,
271
+ part.value.start - 1).
272
+ params[0];
273
273
  },
274
274
 
275
275
  onTagParams(part) {
@@ -337,7 +337,7 @@ function parseMarko(file) {
337
337
  (0, _babelUtils.parseExpression)(
338
338
  file,
339
339
  `()=>${parser.read(part.body)}`,
340
- part.params.start + "()=>".length).
340
+ part.body.start - 4).
341
341
  body),
342
342
 
343
343
  part);
@@ -171,6 +171,10 @@ Object.assign(_printer.default.prototype, {
171
171
  if (node.var) {
172
172
  this.token("/");
173
173
  this.print(node.var, node);
174
+
175
+ if (node.var.typeAnnotation) {
176
+ this.print(node.var.typeAnnotation, node.var);
177
+ }
174
178
  }
175
179
 
176
180
  if (node.arguments && node.arguments.length) {
package/dist/config.js CHANGED
@@ -141,6 +141,13 @@ var _lassoPackageRoot = require("lasso-package-root");
141
141
 
142
142
 
143
143
 
144
+
145
+
146
+
147
+
148
+
149
+
150
+
144
151
 
145
152
 
146
153
 
@@ -151,7 +158,11 @@ var _lassoPackageRoot = require("lasso-package-root");
151
158
 
152
159
  var _fs2 = require("./taglib/fs");let config;const globalThis = typeof window === "undefined" ? global : window;const MARKO_CONFIG_KEY = Symbol("Default Marko Compiler Config");if (globalThis[MARKO_CONFIG_KEY]) {config = globalThis[MARKO_CONFIG_KEY];} else {config = globalThis[MARKO_CONFIG_KEY] = { // The default output mode for compiled templates
153
160
  output: "html", // Override the runtimeid used when calling `marko/components.init` in the `hydrate` output.
154
- runtimeId: null, // Have Marko provide the final AST in the compile result.
161
+ runtimeId: null, /**
162
+ * Remove all typescript types from the output.
163
+ * By default, the compiler will remove types from the output if the
164
+ * `output` option is not `source` or `migrate`.
165
+ */stripTypes: undefined, // Have Marko provide the final AST in the compile result.
155
166
  ast: false, // Set the false to have Marko not generate the final code string, useful if just reading metadata or AST.
156
167
  code: true, /**
157
168
  * Whether the version should be written to the template as a comment e.g.
package/dist/index.js CHANGED
@@ -1,6 +1,9 @@
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 = void 0;var _types = _interopRequireWildcard(require("./babel-types"));exports.types = _types;
2
2
  var _path = _interopRequireDefault(require("path"));
3
3
  var babel = _interopRequireWildcard(require("@babel/core"));
4
+ var _pluginTransformModulesCommonjs = _interopRequireDefault(require("@babel/plugin-transform-modules-commonjs"));
5
+ var _pluginSyntaxTypescript = _interopRequireDefault(require("@babel/plugin-syntax-typescript"));
6
+ var _pluginTransformTypescript = _interopRequireDefault(require("@babel/plugin-transform-typescript"));
4
7
  var _babelPlugin = _interopRequireDefault(require("./babel-plugin"));
5
8
  var _config = _interopRequireDefault(require("./config"));
6
9
  var taglib = _interopRequireWildcard(require("./taglib"));exports.taglib = taglib;
@@ -55,7 +58,25 @@ function getRuntimeEntryFiles(output, requestedTranslator) {
55
58
 
56
59
  function loadBabelConfig(filename, config) {
57
60
  const markoConfig = { ...globalConfig, ...config, babelConfig: undefined };
58
- const requiredPlugins = [[_babelPlugin.default, markoConfig]];
61
+
62
+ if (markoConfig.stripTypes === undefined) {
63
+ markoConfig.stripTypes =
64
+ markoConfig.output !== "source" && markoConfig.output !== "migrate";
65
+ }
66
+
67
+ const requiredPlugins = [
68
+ [_babelPlugin.default, markoConfig],
69
+ [
70
+ markoConfig.stripTypes ? _pluginTransformTypescript.default : _pluginSyntaxTypescript.default,
71
+ {
72
+ isTSX: false,
73
+ allowNamespaces: true,
74
+ optimizeConstEnums: true,
75
+ onlyRemoveTypeImports: true,
76
+ disallowAmbiguousJSXLike: false }]];
77
+
78
+
79
+
59
80
  const baseBabelConfig = {
60
81
  filenameRelative: filename ?
61
82
  _path.default.relative(process.cwd(), filename) :
@@ -70,10 +91,7 @@ function loadBabelConfig(filename, config) {
70
91
 
71
92
 
72
93
  if (markoConfig.modules === "cjs") {
73
- requiredPlugins.push([
74
- require.resolve("@babel/plugin-transform-modules-commonjs"),
75
- { loose: true }]);
76
-
94
+ requiredPlugins.push([_pluginTransformModulesCommonjs.default, { loose: true }]);
77
95
  }
78
96
 
79
97
  baseBabelConfig.plugins = requiredPlugins.concat(
package/index.d.ts CHANGED
@@ -16,6 +16,7 @@ type Dep = {
16
16
 
17
17
  export type Config = {
18
18
  output?: "html" | "dom" | "hydrate" | "migrate" | "source";
19
+ stripTypes?: boolean;
19
20
  runtimeId?: string | null;
20
21
  ast?: boolean;
21
22
  code?: boolean;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@marko/compiler",
3
3
  "description": "Marko template to JS compiler.",
4
- "version": "5.21.7",
4
+ "version": "5.22.2",
5
5
  "author": "Dylan Piercey <dpiercey@ebay.com>",
6
6
  "bugs": "https://github.com/marko-js/marko/issues/new?template=Bug_report.md",
7
7
  "dependencies": {
@@ -9,14 +9,16 @@
9
9
  "@babel/core": "^7.16.0",
10
10
  "@babel/generator": "^7.16.0",
11
11
  "@babel/parser": "^7.16.0",
12
+ "@babel/plugin-syntax-typescript": "^7.16.0",
12
13
  "@babel/plugin-transform-modules-commonjs": "^7.16.0",
14
+ "@babel/plugin-transform-typescript": "^7.16.0",
13
15
  "@babel/runtime": "^7.16.0",
14
16
  "@babel/traverse": "^7.16.0",
15
17
  "@babel/types": "^7.16.0",
16
18
  "@marko/babel-utils": "^5.21.1",
17
19
  "complain": "^1.6.0",
18
20
  "he": "^1.2.0",
19
- "htmljs-parser": "^5.0.0",
21
+ "htmljs-parser": "^5.0.4",
20
22
  "jsesc": "^3.0.2",
21
23
  "lasso-package-root": "^1.0.1",
22
24
  "property-handlers": "^1.1.1",