@marko/compiler 5.27.0 → 5.27.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.
@@ -46,6 +46,14 @@ const SOURCE_FILES = new WeakMap();var _default =
46
46
  return {
47
47
  name: "marko",
48
48
  manipulateOptions(opts) {
49
+ // We need to allow these for now since we are not parsing the entire file
50
+ // These types of syntax errors will be picked up by the bundler / runtime anyways.
51
+ opts.parserOpts.allowAwaitOutsideFunction =
52
+ opts.parserOpts.allowImportExportEverywhere =
53
+ opts.parserOpts.allowReturnOutsideFunction =
54
+ opts.parserOpts.allowSuperOutsideMethod =
55
+ opts.parserOpts.allowUndeclaredExports =
56
+ true;
49
57
  curOpts = opts;
50
58
  },
51
59
  parserOverride(code) {
@@ -65,7 +73,7 @@ const SOURCE_FILES = new WeakMap();var _default =
65
73
  _config.default.fs = markoOpts.fileSystem;
66
74
  curOpts = undefined;
67
75
  try {
68
- if (markoOpts.output === "source" || markoOpts.output === "migrate") {
76
+ if (isMarkoOutput(markoOpts.output)) {
69
77
  return file;
70
78
  }
71
79
 
@@ -106,7 +114,21 @@ const SOURCE_FILES = new WeakMap();var _default =
106
114
  } finally {
107
115
  _config.default.fs = prevFS;
108
116
  }
109
- }
117
+ },
118
+ visitor:
119
+ markoOpts.stripTypes && isMarkoOutput(markoOpts.output) ?
120
+ {
121
+ ExportNamedDeclaration: {
122
+ exit(path) {
123
+ // The babel typescript plugin will add an empty export declaration
124
+ // if there are no other imports/exports in the file.
125
+ // This is not needed for Marko file outputs since there is always
126
+ // a default export.
127
+ if (path.node.specifiers.length === 0) path.remove();
128
+ }
129
+ }
130
+ } :
131
+ undefined
110
132
  };
111
133
  };exports.default = _default;
112
134
 
@@ -324,4 +346,8 @@ function addPlugin(meta, arr, plugin) {
324
346
 
325
347
  function unique(item, i, list) {
326
348
  return list.indexOf(item) === i;
349
+ }
350
+
351
+ function isMarkoOutput(output) {
352
+ return output === "source" || output === "migrate";
327
353
  }
package/dist/index.js CHANGED
@@ -71,6 +71,7 @@ function loadBabelConfig(filename, config) {
71
71
  {
72
72
  isTSX: false,
73
73
  allowNamespaces: true,
74
+ allowDeclareFields: true,
74
75
  optimizeConstEnums: true,
75
76
  onlyRemoveTypeImports: true,
76
77
  disallowAmbiguousJSXLike: false
@@ -3,10 +3,7 @@
3
3
  const nodePath = require("path");
4
4
  const taglibConfig = require("../config");
5
5
  const jsonFileReader = require("./json-file-reader");
6
- const tagDefFromCode = require("./tag-def-from-code");
7
6
  const loaders = require("./loaders");
8
- const fsReadOptions = { encoding: "utf8" };
9
- const extend = require("raptor-util/extend");
10
7
  const types = require("./types");
11
8
 
12
9
  const tagFileTypes = [
@@ -188,19 +185,6 @@ dependencyChain)
188
185
  }
189
186
  }
190
187
  }
191
-
192
- if (!hasTagJson && (tagDef.renderer || tagDef.template)) {
193
- let templateCode = String(
194
- taglibConfig.fs.readFileSync(
195
- tagDef.renderer || tagDef.template,
196
- fsReadOptions));
197
-
198
-
199
- let extractedTagDef = tagDefFromCode.extractTagDef(templateCode);
200
- if (extractedTagDef) {
201
- extend(tagDef, extractedTagDef);
202
- }
203
- }
204
188
  }
205
189
 
206
190
  let tagDependencyChain;
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.27.0",
4
+ "version": "5.27.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": {
@@ -29,7 +29,7 @@
29
29
  "strip-json-comments": "^3.1.1"
30
30
  },
31
31
  "devDependencies": {
32
- "@marko/translator-default": "^5.25.0"
32
+ "@marko/translator-default": "^5.25.2"
33
33
  },
34
34
  "files": [
35
35
  "dist",
@@ -1,58 +0,0 @@
1
- "use strict"; // Rather than using a full-blown JavaScript parser, we are going to use a few regular expressions
2
- // to tokenize the code and find what we are interested in
3
- var tagStartRegExp = /(^\s*(?:(?:exports.(?:tag|TAG))|(?:TAG))\s*=\s*)\{/m;
4
-
5
- // Tokens: "<string>", '<string>', /*<some comment*/, //<single line comment>, {, }, ;
6
- var tokensRegExp =
7
- /"(?:[^"]|\\")*"|'(?:[^'])|(\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/)|(\/\/.*)|[{};]/g;
8
-
9
- function extractTagDef(code) {
10
- var startMatches = tagStartRegExp.exec(code);
11
-
12
- var tagDefStart;
13
- var tagDefEnd;
14
-
15
- if (startMatches) {
16
- tagDefStart = startMatches.index + startMatches[1].length;
17
- var nextTokenMatches;
18
- tokensRegExp.lastIndex = tagDefStart;
19
- var depth = 0;
20
-
21
- while (nextTokenMatches = tokensRegExp.exec(code)) {
22
- if (nextTokenMatches[0] === "{") {
23
- depth++;
24
- continue;
25
- } else if (nextTokenMatches[0] === "}") {
26
- if (--depth === 0) {
27
- tagDefEnd = tokensRegExp.lastIndex;
28
- break;
29
- }
30
- } else if (nextTokenMatches[0] === ";") {
31
- tagDefEnd = nextTokenMatches.index;
32
- break;
33
- }
34
- }
35
-
36
- if (tagDefStart != null && tagDefEnd != null) {
37
- var jsTagDef = code.substring(tagDefStart, tagDefEnd);
38
- var tagDefObject;
39
-
40
- try {
41
- // Try parsing it as JSON
42
- tagDefObject = JSON.parse(jsTagDef);
43
- } catch (e) {
44
- // Try parsing it as JavaScript
45
- try {
46
- tagDefObject = eval("(" + jsTagDef + ")");
47
- } catch (e) {
48
- tagDefObject = {};
49
- }
50
- }
51
- return tagDefObject;
52
- }
53
- } else {
54
- return null;
55
- }
56
- }
57
-
58
- exports.extractTagDef = extractTagDef;