@marko/compiler 5.40.1 → 5.40.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.
package/babel-utils.d.ts
CHANGED
|
@@ -178,11 +178,14 @@ export function assertAllowedAttributes(
|
|
|
178
178
|
path: t.NodePath<t.MarkoTag>,
|
|
179
179
|
allowed: string[],
|
|
180
180
|
): void;
|
|
181
|
-
export function assertNoArgs(path: t.NodePath<t.MarkoTag
|
|
181
|
+
export function assertNoArgs(path: t.NodePath<t.MarkoTag>, hint?: string): void;
|
|
182
182
|
export function assertNoVar(path: t.NodePath<t.MarkoTag>): void;
|
|
183
183
|
export function assertNoAttributes(path: t.NodePath<t.MarkoTag>): void;
|
|
184
184
|
export function assertNoParams(path: t.NodePath<t.MarkoTag>): void;
|
|
185
|
-
export function assertNoAttributeTags(
|
|
185
|
+
export function assertNoAttributeTags(
|
|
186
|
+
path: t.NodePath<t.MarkoTag>,
|
|
187
|
+
hint?: string,
|
|
188
|
+
): void;
|
|
186
189
|
export function assertAttributesOrArgs(path: t.NodePath<t.MarkoTag>): void;
|
|
187
190
|
export function assertAttributesOrSingleArg(path: t.NodePath<t.MarkoTag>): void;
|
|
188
191
|
|
|
@@ -323,6 +323,29 @@ function getMarkoFile(code, fileOpts, markoOpts) {
|
|
|
323
323
|
try {
|
|
324
324
|
file.___compileStage = "analyze";
|
|
325
325
|
traverseAll(file, translator.analyze);
|
|
326
|
+
|
|
327
|
+
if (!markoOpts.errorRecovery) {
|
|
328
|
+
// Analyze failures are recorded as error diagnostics so the whole
|
|
329
|
+
// template reports at once (and editors compiling with
|
|
330
|
+
// `errorRecovery` keep them as recoverable diagnostics); mirror
|
|
331
|
+
// the parse layer by throwing them together at the stage's end.
|
|
332
|
+
const seen = new Set();
|
|
333
|
+
const errors = [];
|
|
334
|
+
for (const diag of meta.diagnostics) {
|
|
335
|
+
if (diag.type !== _diagnostics.DiagnosticType.Error) continue;
|
|
336
|
+
const key = `${
|
|
337
|
+
diag.loc ? `${diag.loc.start.line}:${diag.loc.start.column}` : ""}:${
|
|
338
|
+
diag.label}`;
|
|
339
|
+
if (seen.has(key)) continue;
|
|
340
|
+
seen.add(key);
|
|
341
|
+
errors.push(
|
|
342
|
+
(0, _buildCodeFrame.buildCodeFrameError)(filename, file.code, diag.loc, diag.label)
|
|
343
|
+
);
|
|
344
|
+
if (errors.length === 8) break;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
(0, _mergeErrors.default)(errors);
|
|
348
|
+
}
|
|
326
349
|
} catch (e) {
|
|
327
350
|
compileCache.delete(id);
|
|
328
351
|
throw e;
|
|
@@ -16,6 +16,22 @@ var _buildCodeFrame = require("../util/build-code-frame");
|
|
|
16
16
|
var _mergeErrors = _interopRequireDefault(require("../util/merge-errors"));function _interopRequireDefault(e) {return e && e.__esModule ? e : { default: e };}
|
|
17
17
|
|
|
18
18
|
const noop = () => {};
|
|
19
|
+
const jsxStyleAttrValueReg = /^\{[\s\S]*\}$/;
|
|
20
|
+
// A brace wrapped attribute value that only parses once unwrapped is almost
|
|
21
|
+
// certainly a JSX/Svelte style value (eg `onClick={handler}`); say so instead
|
|
22
|
+
// of surfacing the bare expression parse error.
|
|
23
|
+
const withWrappedAttrValueHint = (file, part, rawValue, node) => {
|
|
24
|
+
const trimmed = rawValue.trim();
|
|
25
|
+
if (
|
|
26
|
+
node.type === "MarkoParseError" &&
|
|
27
|
+
jsxStyleAttrValueReg.test(trimmed) &&
|
|
28
|
+
(0, _babelUtils.parseExpression)(file, trimmed.slice(1, -1), part.value.start).type !==
|
|
29
|
+
"MarkoParseError")
|
|
30
|
+
{
|
|
31
|
+
node.label += `${node.label.endsWith(".") ? "" : "."} Attribute values in Marko are plain JavaScript expressions, not JSX; remove the wrapping \`{ }\`.`;
|
|
32
|
+
}
|
|
33
|
+
return node;
|
|
34
|
+
};
|
|
19
35
|
const emptyRange = (part) => part.start === part.end;
|
|
20
36
|
const isAttrTag = (tag) => tag.name.value?.[0] === "@";
|
|
21
37
|
const isStatementTag = (tag) => tag.tagDef?.parseOptions?.statement;
|
|
@@ -412,10 +428,12 @@ function parseMarko(file) {
|
|
|
412
428
|
onAttrValue(part) {
|
|
413
429
|
currentAttr.end = part.end;
|
|
414
430
|
currentAttr.bound = part.bound;
|
|
415
|
-
|
|
431
|
+
const rawAttrValue = parser.read(part.value);
|
|
432
|
+
currentAttr.value = withWrappedAttrValueHint(
|
|
416
433
|
file,
|
|
417
|
-
|
|
418
|
-
|
|
434
|
+
part,
|
|
435
|
+
rawAttrValue,
|
|
436
|
+
(0, _babelUtils.parseExpression)(file, rawAttrValue, part.value.start)
|
|
419
437
|
);
|
|
420
438
|
},
|
|
421
439
|
|
|
@@ -41,23 +41,23 @@ function assertNoParams(path) {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
function assertNoAttributeTags(path) {
|
|
44
|
+
function assertNoAttributeTags(path, hint) {
|
|
45
45
|
if (path.node.attributeTags.length) {
|
|
46
46
|
throw path.hub.buildError(
|
|
47
47
|
path.node.attributeTags[0],
|
|
48
|
-
|
|
48
|
+
`Tag does not support nested attribute tags.${hint ? ` ${hint}` : ""}`
|
|
49
49
|
);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
function assertNoArgs(path) {
|
|
53
|
+
function assertNoArgs(path, hint) {
|
|
54
54
|
const args = path.node.arguments;
|
|
55
55
|
if (args && args.length) {
|
|
56
56
|
const start = args[0].loc.start;
|
|
57
57
|
const end = args[args.length - 1].loc.end;
|
|
58
58
|
throw path.hub.buildError(
|
|
59
59
|
{ loc: { start, end } },
|
|
60
|
-
|
|
60
|
+
`Tag does not support arguments.${hint ? ` ${hint}` : ""}`
|
|
61
61
|
);
|
|
62
62
|
}
|
|
63
63
|
}
|