@marko/compiler 5.27.9 → 5.28.0
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.
- package/config.d.ts +4 -2
- package/dist/babel-plugin/file.js +8 -38
- package/dist/babel-plugin/index.js +63 -10
- package/dist/config.js +22 -1
- package/dist/index.js +59 -11
- package/dist/traverse.d.ts +1 -6
- package/dist/util/build-code-frame.js +56 -0
- package/index.d.ts +2 -1
- package/package.json +4 -3
package/config.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
const Config: {
|
|
1
|
+
declare const Config: {
|
|
2
2
|
output?: "html" | "dom" | "hydrate" | "migrate" | "source";
|
|
3
|
+
errorRecovery?: boolean;
|
|
4
|
+
applyFixes?: Map<number, unknown>;
|
|
3
5
|
stripTypes?: boolean;
|
|
4
6
|
runtimeId?: string | null;
|
|
5
7
|
ast?: boolean;
|
|
@@ -13,7 +15,7 @@ const Config: {
|
|
|
13
15
|
resolveVirtualDependency?:
|
|
14
16
|
| ((
|
|
15
17
|
filename: string,
|
|
16
|
-
dep: { virtualPath: string; code: string; map?:
|
|
18
|
+
dep: { virtualPath: string; code: string; map?: any }
|
|
17
19
|
) => string)
|
|
18
20
|
| null;
|
|
19
21
|
hydrateIncludeImports?: RegExp | ((request: string) => boolean);
|
|
@@ -1,48 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var
|
|
3
|
-
var _codeFrame = require("@babel/code-frame");
|
|
4
|
-
const CWD = process.cwd();
|
|
1
|
+
"use strict";exports.__esModule = true;exports.MarkoFile = void 0;var _core = require("@babel/core");
|
|
2
|
+
var _buildCodeFrame = require("../util/build-code-frame");
|
|
5
3
|
|
|
6
4
|
class MarkoFile extends _core.File {
|
|
7
5
|
addHelper() {
|
|
8
6
|
throw new Error("addHelper is not supported during a Marko transform");
|
|
9
7
|
}
|
|
10
8
|
|
|
11
|
-
buildCodeFrameError(node, msg, Error
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
loc &&
|
|
15
|
-
(0, _codeFrame.codeFrameColumns)(
|
|
9
|
+
buildCodeFrameError(node, msg, Error) {
|
|
10
|
+
return (0, _buildCodeFrame.buildCodeFrameError)(
|
|
11
|
+
this.opts.filename,
|
|
16
12
|
this.code,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
column: loc.start.column + 1
|
|
21
|
-
},
|
|
22
|
-
end:
|
|
23
|
-
loc.end && loc.start.line === loc.end.line ?
|
|
24
|
-
{
|
|
25
|
-
line: loc.end.line,
|
|
26
|
-
column: loc.end.column + 1
|
|
27
|
-
} :
|
|
28
|
-
undefined
|
|
29
|
-
},
|
|
30
|
-
{ highlightCode: true });
|
|
13
|
+
node.loc,
|
|
14
|
+
msg,
|
|
15
|
+
Error);
|
|
31
16
|
|
|
32
|
-
|
|
33
|
-
const finalMsg = `${_path.default.relative(CWD, this.opts.filename)}${
|
|
34
|
-
loc ? `(${loc.start.line},${loc.start.column + 1})` : ""
|
|
35
|
-
}: ${msg}\n${frame || ""}`;
|
|
36
|
-
|
|
37
|
-
const err = new Error();
|
|
38
|
-
|
|
39
|
-
// Prevent babel from changing our error message.
|
|
40
|
-
Object.defineProperty(err, "message", {
|
|
41
|
-
get() {
|
|
42
|
-
return finalMsg;
|
|
43
|
-
},
|
|
44
|
-
set() {}
|
|
45
|
-
});
|
|
46
|
-
return err;
|
|
47
17
|
}
|
|
48
18
|
}exports.MarkoFile = MarkoFile;
|
|
@@ -73,17 +73,19 @@ const SOURCE_FILES = new WeakMap();var _default =
|
|
|
73
73
|
_config.default.fs = markoOpts.fileSystem;
|
|
74
74
|
curOpts = undefined;
|
|
75
75
|
try {
|
|
76
|
+
const { ast, metadata } = file;
|
|
77
|
+
const sourceFile = SOURCE_FILES.get(ast);
|
|
78
|
+
metadata.marko = shallowClone(sourceFile.metadata.marko);
|
|
79
|
+
|
|
76
80
|
if (isMarkoOutput(markoOpts.output)) {
|
|
77
|
-
|
|
81
|
+
finalizeMeta(metadata.marko);
|
|
82
|
+
return;
|
|
78
83
|
}
|
|
79
84
|
|
|
80
|
-
const { ast, metadata } = file;
|
|
81
|
-
const sourceFile = SOURCE_FILES.get(ast);
|
|
82
85
|
const taglibLookup = sourceFile.___taglibLookup;
|
|
83
86
|
const rootTranslators = [];
|
|
84
87
|
const { buildCodeFrameError } = file;
|
|
85
88
|
const { buildError } = file.hub;
|
|
86
|
-
metadata.marko = shallowClone(sourceFile.metadata.marko);
|
|
87
89
|
file.buildCodeFrameError = _file.MarkoFile.prototype.buildCodeFrameError;
|
|
88
90
|
file.hub.buildError = file.buildCodeFrameError.bind(file);
|
|
89
91
|
file.markoOpts = markoOpts;
|
|
@@ -101,6 +103,7 @@ const SOURCE_FILES = new WeakMap();var _default =
|
|
|
101
103
|
}
|
|
102
104
|
|
|
103
105
|
rootTranslators.push(translator.translate);
|
|
106
|
+
file.___compileStage = "translate";
|
|
104
107
|
traverseAll(file, rootTranslators);
|
|
105
108
|
file.buildCodeFrameError = buildCodeFrameError;
|
|
106
109
|
file.hub.buildError = buildError;
|
|
@@ -109,7 +112,7 @@ const SOURCE_FILES = new WeakMap();var _default =
|
|
|
109
112
|
file.___getMarkoFile =
|
|
110
113
|
undefined;
|
|
111
114
|
|
|
112
|
-
metadata.marko
|
|
115
|
+
finalizeMeta(metadata.marko);
|
|
113
116
|
file.path.scope.crawl(); // Ensure all scopes are accurate for subsequent babel plugins
|
|
114
117
|
} finally {
|
|
115
118
|
_config.default.fs = prevFS;
|
|
@@ -202,13 +205,15 @@ function getMarkoFile(code, fileOpts, markoOpts) {
|
|
|
202
205
|
macros: {},
|
|
203
206
|
deps: [],
|
|
204
207
|
tags: [],
|
|
205
|
-
watchFiles: []
|
|
208
|
+
watchFiles: [],
|
|
209
|
+
diagnostics: []
|
|
206
210
|
};
|
|
207
211
|
|
|
208
212
|
file.markoOpts = markoOpts;
|
|
209
213
|
file.___taglibLookup = taglibLookup;
|
|
210
214
|
file.___getMarkoFile = getMarkoFile;
|
|
211
215
|
|
|
216
|
+
file.___compileStage = "parse";
|
|
212
217
|
(0, _parser.parseMarko)(file);
|
|
213
218
|
|
|
214
219
|
if (isSource) {
|
|
@@ -225,8 +230,29 @@ function getMarkoFile(code, fileOpts, markoOpts) {
|
|
|
225
230
|
}
|
|
226
231
|
|
|
227
232
|
rootMigrators.push(_migrate.visitor);
|
|
233
|
+
file.___compileStage = "migrate";
|
|
228
234
|
traverseAll(file, rootMigrators);
|
|
229
235
|
|
|
236
|
+
const { applyFixes } = markoOpts;
|
|
237
|
+
if (applyFixes) {
|
|
238
|
+
for (let i = 0; i < meta.diagnostics.length; i++) {
|
|
239
|
+
const diag = meta.diagnostics[i];
|
|
240
|
+
if (diag.fix) {
|
|
241
|
+
if (applyFixes.has(i)) {
|
|
242
|
+
(typeof diag.fix === "function" ? diag.fix : diag.fix.apply)(
|
|
243
|
+
applyFixes.get(i));
|
|
244
|
+
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
} else {
|
|
249
|
+
for (const diag of meta.diagnostics) {
|
|
250
|
+
if (diag.fix) {
|
|
251
|
+
(typeof diag.fix === "function" ? diag.fix : diag.fix.apply)(undefined);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
230
256
|
if (isMigrate) {
|
|
231
257
|
return file;
|
|
232
258
|
}
|
|
@@ -239,6 +265,7 @@ function getMarkoFile(code, fileOpts, markoOpts) {
|
|
|
239
265
|
}
|
|
240
266
|
|
|
241
267
|
rootTransformers.push(_transform.visitor);
|
|
268
|
+
file.___compileStage = "transform";
|
|
242
269
|
traverseAll(file, rootTransformers);
|
|
243
270
|
|
|
244
271
|
for (const taglibId in taglibLookup.taglibsById) {
|
|
@@ -260,6 +287,7 @@ function getMarkoFile(code, fileOpts, markoOpts) {
|
|
|
260
287
|
|
|
261
288
|
if (translator.analyze) {
|
|
262
289
|
try {
|
|
290
|
+
file.___compileStage = "analyze";
|
|
263
291
|
traverseAll(file, translator.analyze);
|
|
264
292
|
} catch (e) {
|
|
265
293
|
compileCache.delete(cacheKey);
|
|
@@ -351,10 +379,35 @@ function addPlugin(meta, arr, plugin) {
|
|
|
351
379
|
}
|
|
352
380
|
}
|
|
353
381
|
|
|
354
|
-
function unique(item, i, list) {
|
|
355
|
-
return list.indexOf(item) === i;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
382
|
function isMarkoOutput(output) {
|
|
359
383
|
return output === "source" || output === "migrate";
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function finalizeMeta(meta) {
|
|
387
|
+
meta.watchFiles = [...new Set(meta.watchFiles)];
|
|
388
|
+
meta.diagnostics = meta.diagnostics.map(
|
|
389
|
+
({ type, label, loc, fix: rawFix }) => {
|
|
390
|
+
let fix = false;
|
|
391
|
+
|
|
392
|
+
switch (typeof rawFix) {
|
|
393
|
+
case "function":
|
|
394
|
+
fix = true;
|
|
395
|
+
break;
|
|
396
|
+
case "object":
|
|
397
|
+
// strip off the apply function.
|
|
398
|
+
({
|
|
399
|
+
// eslint-disable-next-line no-empty-pattern
|
|
400
|
+
apply: {},
|
|
401
|
+
...fix
|
|
402
|
+
} = rawFix);
|
|
403
|
+
break;}
|
|
404
|
+
|
|
405
|
+
return {
|
|
406
|
+
type,
|
|
407
|
+
label,
|
|
408
|
+
loc,
|
|
409
|
+
fix
|
|
410
|
+
};
|
|
411
|
+
});
|
|
412
|
+
|
|
360
413
|
}
|
package/dist/config.js
CHANGED
|
@@ -134,6 +134,19 @@ var _lassoPackageRoot = require("lasso-package-root");
|
|
|
134
134
|
|
|
135
135
|
|
|
136
136
|
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
137
150
|
|
|
138
151
|
|
|
139
152
|
|
|
@@ -198,4 +211,12 @@ var _config = _interopRequireDefault(require("./taglib/config"));const config =
|
|
|
198
211
|
* A regexp or function that receives an import path that matches file types known to be client side assets.
|
|
199
212
|
*/hydrateIncludeImports: /\.(css|less|s[ac]ss|styl|png|jpe?g|gif|svg|ico|webp|avif|mp4|webm|ogg|mp3|wav|flac|aac|woff2?|eot|ttf|otf)$/, /**
|
|
200
213
|
* Set to true in order to bring in the hot module replacement runtime.
|
|
201
|
-
*/hot: false
|
|
214
|
+
*/hot: false, /**
|
|
215
|
+
* Wether error diagnostics should be thrown as errors
|
|
216
|
+
* before the compile result is returned.
|
|
217
|
+
*
|
|
218
|
+
* Note that the compiler can still throw errors even when true.
|
|
219
|
+
* When the errorRecovery is true, any recoverable errors will be
|
|
220
|
+
* returned in the `meta.diagnostics` property of the compile result.
|
|
221
|
+
*/errorRecovery: false, // When supplied, any diagnostics which have a fix specified in the lookup will be applied to the source code.
|
|
222
|
+
applyFixes: undefined };if (process.env.MARKO_CONFIG) {Object.assign(config, JSON.parse(process.env.MARKO_CONFIG));}var _default = config;exports.default = _default;_config.default.fs = config.fileSystem;
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
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
|
+
var _kleur = _interopRequireDefault(require("kleur"));
|
|
3
4
|
var babel = _interopRequireWildcard(require("@babel/core"));
|
|
4
5
|
var _pluginTransformModulesCommonjs = _interopRequireDefault(require("@babel/plugin-transform-modules-commonjs"));
|
|
5
6
|
var _pluginSyntaxTypescript = _interopRequireDefault(require("@babel/plugin-syntax-typescript"));
|
|
6
7
|
var _pluginTransformTypescript = _interopRequireDefault(require("@babel/plugin-transform-typescript"));
|
|
8
|
+
var _babelUtils = require("@marko/babel-utils");
|
|
7
9
|
var _babelPlugin = _interopRequireDefault(require("./babel-plugin"));
|
|
8
10
|
var _config = _interopRequireDefault(require("./config"));
|
|
9
11
|
var taglib = _interopRequireWildcard(require("./taglib"));exports.taglib = taglib;
|
|
10
12
|
var _shouldOptimize = _interopRequireDefault(require("./util/should-optimize"));
|
|
11
|
-
var _tryLoadTranslator = _interopRequireDefault(require("./util/try-load-translator"));
|
|
13
|
+
var _tryLoadTranslator = _interopRequireDefault(require("./util/try-load-translator"));
|
|
14
|
+
var _buildCodeFrame = require("./util/build-code-frame");function _getRequireWildcardCache(nodeInterop) {if (typeof WeakMap !== "function") return null;var cacheBabelInterop = new WeakMap();var cacheNodeInterop = new WeakMap();return (_getRequireWildcardCache = function (nodeInterop) {return nodeInterop ? cacheNodeInterop : cacheBabelInterop;})(nodeInterop);}function _interopRequireWildcard(obj, nodeInterop) {if (!nodeInterop && obj && obj.__esModule) {return obj;}if (obj === null || typeof obj !== "object" && typeof obj !== "function") {return { default: obj };}var cache = _getRequireWildcardCache(nodeInterop);if (cache && cache.has(obj)) {return cache.get(obj);}var newObj = {};var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var key in obj) {if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;if (desc && (desc.get || desc.set)) {Object.defineProperty(newObj, key, desc);} else {newObj[key] = obj[key];}}}newObj.default = obj;if (cache) {cache.set(obj, newObj);}return newObj;}
|
|
12
15
|
|
|
13
16
|
|
|
14
17
|
let globalConfig = { ..._config.default };
|
|
@@ -17,17 +20,19 @@ function configure(newConfig) {
|
|
|
17
20
|
}
|
|
18
21
|
|
|
19
22
|
async function compile(src, filename, config) {
|
|
20
|
-
const
|
|
23
|
+
const markoConfig = loadMarkoConfig(config);
|
|
24
|
+
const babelConfig = loadBabelConfig(filename, markoConfig);
|
|
21
25
|
const babelResult = await babel.transformAsync(src, babelConfig);
|
|
22
|
-
scheduleDefaultClear(
|
|
23
|
-
return buildResult(babelResult);
|
|
26
|
+
scheduleDefaultClear(markoConfig);
|
|
27
|
+
return buildResult(src, filename, markoConfig.errorRecovery, babelResult);
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
function compileSync(src, filename, config) {
|
|
27
|
-
const
|
|
31
|
+
const markoConfig = loadMarkoConfig(config);
|
|
32
|
+
const babelConfig = loadBabelConfig(filename, markoConfig);
|
|
28
33
|
const babelResult = babel.transformSync(src, babelConfig);
|
|
29
|
-
scheduleDefaultClear(
|
|
30
|
-
return buildResult(babelResult);
|
|
34
|
+
scheduleDefaultClear(markoConfig);
|
|
35
|
+
return buildResult(src, filename, markoConfig.errorRecovery, babelResult);
|
|
31
36
|
}
|
|
32
37
|
|
|
33
38
|
async function compileFile(filename, config) {
|
|
@@ -56,14 +61,18 @@ function getRuntimeEntryFiles(output, requestedTranslator) {
|
|
|
56
61
|
return [];
|
|
57
62
|
}
|
|
58
63
|
|
|
59
|
-
function
|
|
60
|
-
const markoConfig = { ...globalConfig, ...config
|
|
64
|
+
function loadMarkoConfig(config) {
|
|
65
|
+
const markoConfig = { ...globalConfig, ...config };
|
|
61
66
|
|
|
62
67
|
if (markoConfig.stripTypes === undefined) {
|
|
63
68
|
markoConfig.stripTypes =
|
|
64
69
|
markoConfig.output !== "source" && markoConfig.output !== "migrate";
|
|
65
70
|
}
|
|
66
71
|
|
|
72
|
+
return markoConfig;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function loadBabelConfig(filename, { babelConfig, ...markoConfig }) {
|
|
67
76
|
const requiredPlugins = [
|
|
68
77
|
[_babelPlugin.default, markoConfig],
|
|
69
78
|
[
|
|
@@ -83,7 +92,7 @@ function loadBabelConfig(filename, config) {
|
|
|
83
92
|
_path.default.relative(process.cwd(), filename) :
|
|
84
93
|
undefined,
|
|
85
94
|
sourceFileName: filename ? _path.default.basename(filename) : undefined,
|
|
86
|
-
...
|
|
95
|
+
...babelConfig,
|
|
87
96
|
filename,
|
|
88
97
|
sourceType: "module",
|
|
89
98
|
sourceMaps: markoConfig.sourceMaps,
|
|
@@ -102,13 +111,52 @@ function loadBabelConfig(filename, config) {
|
|
|
102
111
|
return babel.loadPartialConfig(baseBabelConfig).options;
|
|
103
112
|
}
|
|
104
113
|
|
|
105
|
-
function buildResult(babelResult) {
|
|
114
|
+
function buildResult(src, filename, errorRecovery, babelResult) {
|
|
106
115
|
const {
|
|
107
116
|
ast,
|
|
108
117
|
map,
|
|
109
118
|
code,
|
|
110
119
|
metadata: { marko: meta }
|
|
111
120
|
} = babelResult;
|
|
121
|
+
|
|
122
|
+
if (!errorRecovery) {
|
|
123
|
+
const errors = [];
|
|
124
|
+
|
|
125
|
+
for (const diag of meta.diagnostics) {
|
|
126
|
+
if (diag.type === _babelUtils.DiagnosticType.Error) {
|
|
127
|
+
errors.push(diag);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
switch (errors.length) {
|
|
132
|
+
case 0:
|
|
133
|
+
break;
|
|
134
|
+
case 1:{
|
|
135
|
+
const [diag] = errors;
|
|
136
|
+
throw (0, _buildCodeFrame.buildCodeFrameError)(filename, src, diag.loc, diag.label);
|
|
137
|
+
}
|
|
138
|
+
default:{
|
|
139
|
+
let err;
|
|
140
|
+
const message = `${_kleur.default.red("AggregationError:")}\n${errors.
|
|
141
|
+
map((diag) => (0, _buildCodeFrame.buildCodeFrame)(filename, src, diag.loc, diag.label)).
|
|
142
|
+
join("\n\n").
|
|
143
|
+
replace(/^(?!\s*$)/gm, "\t")}\n`;
|
|
144
|
+
|
|
145
|
+
if (typeof AggregateError === "function") {
|
|
146
|
+
err = new AggregateError(errors, message);
|
|
147
|
+
} else {
|
|
148
|
+
err = new Error(message);
|
|
149
|
+
err.name = "AggregateError";
|
|
150
|
+
err.errors = errors;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Remove the stack trace from the error since it is not useful.
|
|
154
|
+
err.stack = "";
|
|
155
|
+
throw err;
|
|
156
|
+
}}
|
|
157
|
+
|
|
158
|
+
}
|
|
159
|
+
|
|
112
160
|
return { ast, map, code, meta };
|
|
113
161
|
}
|
|
114
162
|
|
package/dist/traverse.d.ts
CHANGED
|
@@ -1203,12 +1203,7 @@ export interface BabelFile {
|
|
|
1203
1203
|
code: string,
|
|
1204
1204
|
opts: Record<string, unknown>,
|
|
1205
1205
|
metadata: Record<string, unknown> & {
|
|
1206
|
-
marko:
|
|
1207
|
-
id: string,
|
|
1208
|
-
tags: string[],
|
|
1209
|
-
deps: Array<string | { type: string, code: string, path: string, virtualPath: string, [x:string]: unknown }>,
|
|
1210
|
-
watchFiles: string[]
|
|
1211
|
-
}
|
|
1206
|
+
marko: import("@marko/compiler").MarkoMeta
|
|
1212
1207
|
},
|
|
1213
1208
|
markoOpts: Required<import('@marko/compiler').Config>
|
|
1214
1209
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.buildCodeFrame = buildCodeFrame;exports.buildCodeFrameError = buildCodeFrameError;var _path = _interopRequireDefault(require("path"));
|
|
2
|
+
var _kleur = _interopRequireDefault(require("kleur"));
|
|
3
|
+
var _codeFrame = require("@babel/code-frame");
|
|
4
|
+
const CWD = process.cwd();
|
|
5
|
+
|
|
6
|
+
function buildCodeFrame(filename, code, loc, message) {
|
|
7
|
+
return `${_kleur.default.cyan(_path.default.relative(CWD, filename))}${
|
|
8
|
+
loc ?
|
|
9
|
+
`:${_kleur.default.yellow(loc.start.line)}:${_kleur.default.yellow(loc.start.column + 1)}` :
|
|
10
|
+
""
|
|
11
|
+
}\n\n${
|
|
12
|
+
loc ?
|
|
13
|
+
(0, _codeFrame.codeFrameColumns)(
|
|
14
|
+
code,
|
|
15
|
+
{
|
|
16
|
+
start: {
|
|
17
|
+
line: loc.start.line,
|
|
18
|
+
column: loc.start.column + 1
|
|
19
|
+
},
|
|
20
|
+
end:
|
|
21
|
+
loc.end && loc.start.line === loc.end.line ?
|
|
22
|
+
{
|
|
23
|
+
line: loc.end.line,
|
|
24
|
+
column: loc.end.column + 1
|
|
25
|
+
} :
|
|
26
|
+
undefined
|
|
27
|
+
},
|
|
28
|
+
{ highlightCode: true, message }) :
|
|
29
|
+
|
|
30
|
+
""
|
|
31
|
+
}`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function buildCodeFrameError(
|
|
35
|
+
filename,
|
|
36
|
+
code,
|
|
37
|
+
loc,
|
|
38
|
+
message,
|
|
39
|
+
Error = SyntaxError)
|
|
40
|
+
{
|
|
41
|
+
const err = new Error();
|
|
42
|
+
const codeFrame = buildCodeFrame(filename, code, loc, message);
|
|
43
|
+
|
|
44
|
+
// Avoid showing the stack trace for this error.
|
|
45
|
+
err.stack = "";
|
|
46
|
+
|
|
47
|
+
// Prevent babel from changing our error message.
|
|
48
|
+
Object.defineProperty(err, "message", {
|
|
49
|
+
get() {
|
|
50
|
+
return codeFrame;
|
|
51
|
+
},
|
|
52
|
+
set() {}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
return err;
|
|
56
|
+
}
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SourceMap } from "magic-string";
|
|
2
|
-
import { TaglibLookup } from "@marko/babel-utils";
|
|
2
|
+
import { TaglibLookup, Diagnostic } from "@marko/babel-utils";
|
|
3
3
|
import * as types from "./babel-types";
|
|
4
4
|
export { types };
|
|
5
5
|
|
|
@@ -22,6 +22,7 @@ export type MarkoMeta = {
|
|
|
22
22
|
watchFiles: string[];
|
|
23
23
|
tags?: string[];
|
|
24
24
|
deps: Array<string | Dep>;
|
|
25
|
+
diagnostics: Diagnostic[];
|
|
25
26
|
};
|
|
26
27
|
|
|
27
28
|
export type CompileResult = {
|
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.
|
|
4
|
+
"version": "5.28.0",
|
|
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": {
|
|
@@ -15,11 +15,12 @@
|
|
|
15
15
|
"@babel/runtime": "^7.16.0",
|
|
16
16
|
"@babel/traverse": "^7.16.0",
|
|
17
17
|
"@babel/types": "^7.16.0",
|
|
18
|
-
"@marko/babel-utils": "^5.
|
|
18
|
+
"@marko/babel-utils": "^5.22.0",
|
|
19
19
|
"complain": "^1.6.0",
|
|
20
20
|
"he": "^1.2.0",
|
|
21
21
|
"htmljs-parser": "^5.4.3",
|
|
22
22
|
"jsesc": "^3.0.2",
|
|
23
|
+
"kleur": "^4.1.5",
|
|
23
24
|
"lasso-package-root": "^1.0.1",
|
|
24
25
|
"raptor-regexp": "^1.0.1",
|
|
25
26
|
"raptor-util": "^3.2.0",
|
|
@@ -29,7 +30,7 @@
|
|
|
29
30
|
"strip-json-comments": "^3.1.1"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
|
-
"@marko/translator-default": "^5.
|
|
33
|
+
"@marko/translator-default": "^5.26.0"
|
|
33
34
|
},
|
|
34
35
|
"files": [
|
|
35
36
|
"dist",
|