Skip to content

Commit cc69372

Browse files
committed
fix: compat with latest marko compiler
1 parent 7d5b608 commit cc69372

File tree

110 files changed

+3671
-3077
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+3671
-3077
lines changed

.changeset/nervous-kids-rescue.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"marko-widgets": patch
3+
"@marko/compat-utils": patch
4+
"@marko/compat-v4": patch
5+
---
6+
7+
Fix incompatibilty with latest @marko/compiler

package-lock.json

+2,740-2,402
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"@babel/register": "^7.22.5",
2929
"@changesets/changelog-github": "^0.4.8",
3030
"@changesets/cli": "^2.26.2",
31-
"@marko/compiler": "^5.33.0",
31+
"@marko/compiler": "^5.37.11",
3232
"@testing-library/dom": "^9.3.1",
3333
"@types/babel__register": "^7.17.0",
3434
"@types/jsdom": "^21.1.1",
@@ -47,7 +47,7 @@
4747
"husky": "^8.0.3",
4848
"jsdom": "^22.1.0",
4949
"lint-staged": "^13.2.3",
50-
"marko": "^5.31.3",
50+
"marko": "^5.35.16",
5151
"mocha": "^10.2.0",
5252
"mocha-snap": "^5.0.0",
5353
"prettier": "^3.0.1",

packages/compat-utils/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"!**/*.tsbuildinfo"
2525
],
2626
"dependencies": {
27-
"@marko/babel-utils": "^6.3.1"
27+
"@marko/babel-utils": "^6.5.6"
2828
},
2929
"peerDependencies": {
3030
"@marko/compiler": "^5",

packages/compat-utils/src/render-call-to-dynamic-tag.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ export function replaceRenderCallExpression(
9090
node.operator === "||"
9191
? t.unaryExpression("!", node.left)
9292
: node.operator === "??"
93-
? t.binaryExpression(
94-
"===",
95-
node.left,
96-
t.unaryExpression("void", t.numericLiteral(0)),
97-
)
98-
: node.left,
93+
? t.binaryExpression(
94+
"===",
95+
node.left,
96+
t.unaryExpression("void", t.numericLiteral(0)),
97+
)
98+
: node.left,
9999
],
100100
),
101101
);

packages/compat-v4/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"!**/*.tsbuildinfo"
2626
],
2727
"dependencies": {
28-
"@marko/babel-utils": "^6.3.1",
28+
"@marko/babel-utils": "^6.5.6",
2929
"@marko/compat-utils": "^1.0.1"
3030
},
3131
"peerDependencies": {

packages/compat-v4/src/components/await/migrate.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ import { types as t } from "@marko/compiler";
22
import {
33
diagnosticDeprecate,
44
diagnosticError,
5+
getEnd,
6+
getStart,
57
parseExpression,
68
withLoc,
79
} from "@marko/babel-utils";
810

911
export default {
1012
exit(tag: t.NodePath<t.MarkoTag>) {
13+
const { file } = tag.hub;
1114
const firstArg = tag.node.arguments?.[0];
1215
if (firstArg?.type !== "MarkoParseError") return;
1316
const match = /^\s*([$a-zA-Z_][0-9a-zA-Z_$]*)\s+from\s+/.exec(
@@ -19,11 +22,11 @@ export default {
1922
label:
2023
'The "<await(result from promise)>" syntax has been deprecated, please use the modern syntax of "<await(promise)><@then|result|>". See: https://github.com/marko-js/marko/wiki/Deprecation:-legacy-await',
2124
fix() {
22-
const start = firstArg.start!;
25+
const start = getStart(file, firstArg)!;
2326
const fromStart = match[0].length;
2427
const identifierName = match[1];
2528
const valueIdentifier = withLoc(
26-
tag.hub.file,
29+
file,
2730
t.identifier(identifierName),
2831
start,
2932
start + identifierName.length,
@@ -33,10 +36,10 @@ export default {
3336
const timeoutChildren: t.MarkoTagBody["body"] = [];
3437
const errorChildren: t.MarkoTagBody["body"] = [];
3538
let providerExpression = parseExpression(
36-
tag.hub.file,
39+
file,
3740
firstArg.source.slice(fromStart),
3841
start + fromStart,
39-
firstArg.end!,
42+
getEnd(file, firstArg)!,
4043
);
4144
let providerMethod: t.Expression | undefined;
4245
let providerScope: t.Expression | undefined;

packages/compat-v4/src/components/for/migrate.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import { types as t } from "@marko/compiler";
22
import {
33
diagnosticDeprecate,
44
diagnosticError,
5+
getEnd,
56
getLocRange,
7+
getStart,
68
parseExpression,
79
parseParams,
810
parseStatements,
@@ -17,11 +19,11 @@ export default {
1719
const len = args?.length;
1820
if (!len) return;
1921

20-
const start = args[0].start;
21-
const end = args[len - 1].end;
22+
const { file } = tag.hub;
23+
const start = getStart(file, args[0]);
24+
const end = getEnd(file, args[len - 1]);
2225
if (start == null || end == null) return;
2326

24-
const { file } = tag.hub;
2527
const source = file.code.slice(start, end);
2628
const parsed = parseFor(source);
2729
if (!parsed) return;
@@ -103,12 +105,13 @@ export default {
103105
if (statusExpression.type === "StringLiteral") {
104106
if (t.isValidIdentifier(statusExpression.value)) {
105107
const statusIdentifier = t.identifier(statusExpression.value);
106-
if (statusExpression.start != null) {
108+
const statusExprStart = getStart(file, statusExpression);
109+
if (statusExprStart != null) {
107110
withLoc(
108111
file,
109112
statusIdentifier,
110-
statusExpression.start + 1,
111-
statusExpression.end! - 1,
113+
statusExprStart + 1,
114+
getEnd(file, statusExpression)! - 1,
112115
);
113116
}
114117

@@ -528,7 +531,7 @@ function forInitToRange(
528531
varName = declarator.id;
529532
from = declarator.init;
530533
} else if (init.type === "AssignmentExpression" && init.operator === "=") {
531-
varName = init.left;
534+
varName = init.left as t.LVal;
532535
from = init.right;
533536
} else {
534537
return;

packages/compat-v4/src/migrate/legacy-attribute-tags.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { types as t } from "@marko/compiler";
22
import {
33
diagnosticDeprecate,
44
findParentTag,
5+
getEnd,
56
withLoc,
67
} from "@marko/babel-utils";
78

@@ -37,14 +38,16 @@ export default {
3738
label:
3839
'The "<my-tag:nested>" tagName syntax is deprecated. Please use the "<@nested>" tagName syntax instead. See: https://github.com/marko-js/marko/wiki/Deprecation:-legacy-nested-tags',
3940
fix() {
41+
const { file } = tag.hub;
4042
const attrTagNameLiteral = t.stringLiteral(`@${attrTagName}`);
43+
const nameEnd = getEnd(file, node.name);
4144

42-
if (node.name.start != null && node.name.end != null) {
45+
if (nameEnd != null) {
4346
withLoc(
44-
tag.hub.file,
47+
file,
4548
attrTagNameLiteral,
46-
node.name.end - attrTagName.length + 1,
47-
node.name.end,
49+
nameEnd - attrTagName.length + 1,
50+
nameEnd,
4851
);
4952
}
5053

packages/compat-v4/src/migrate/non-standard-template-literals/parse.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { types as t } from "@marko/compiler";
2-
import { parseExpression } from "@marko/babel-utils";
2+
import { getStart, parseExpression } from "@marko/babel-utils";
33

44
const enum CODE {
55
ASTERISK = 42,
@@ -28,7 +28,8 @@ export function parseNonStandardTemplateLiteral(
2828
if (typeof value !== "string") return;
2929
value = value.slice(1, -1);
3030
const { length } = value;
31-
const valueStart = string.node.start == null ? null : string.node.start + 1;
31+
const nodeStart = getStart(file, string.node);
32+
const valueStart = nodeStart == null ? null : nodeStart + 1;
3233
let elements: undefined | t.TemplateElement[];
3334
let expressions: undefined | t.Expression[];
3435
let lastEndBracket = 0;

packages/marko-widgets/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"!**/*.tsbuildinfo"
3232
],
3333
"dependencies": {
34-
"@marko/babel-utils": "^6.3.1",
34+
"@marko/babel-utils": "^6.5.6",
3535
"@marko/compat-utils": "^1.0.1",
3636
"@marko/compat-v4": "^1.0.7",
3737
"raptor-dom": "^1.1.1",

packages/marko-widgets/src/components/assign/migrate.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { types as t } from "@marko/compiler";
22
import {
33
diagnosticDeprecate,
44
diagnosticError,
5+
getEnd,
6+
getStart,
57
parseExpression,
68
} from "@marko/babel-utils";
79

@@ -21,6 +23,7 @@ export default {
2123
label:
2224
'The "<assign>" tag is deprecated. Please use "$ <js_code>" for JavaScript in the template. See: https://github.com/marko-js/marko/wiki/Deprecation:-var,-assign,-invoke-tags',
2325
fix() {
26+
const { file } = tag.hub;
2427
const statements: t.Statement[] = [];
2528
let condition: t.Expression | undefined;
2629

@@ -47,14 +50,16 @@ export default {
4750
continue;
4851
}
4952

53+
const nodeStart = getStart(file, node);
54+
const nodeEnd = getEnd(file, node);
5055
statements.push(
5156
t.expressionStatement(
5257
t.isBooleanLiteral(value) &&
5358
value.value === true &&
5459
/^[+-]{2,}|[+-]{2,}$/.test(name)
55-
? node.start != null && node.end != null
56-
? parseExpression(attr.hub.file, name, node.start, node.end!)
57-
: parseExpression(attr.hub.file, name)
60+
? nodeStart != null && nodeEnd != null
61+
? parseExpression(file, name, nodeStart, nodeEnd)
62+
: parseExpression(file, name)
5863
: t.assignmentExpression("=", t.identifier(name), value),
5964
),
6065
);

packages/marko-widgets/src/components/async-fragment/migrate.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { types as t } from "@marko/compiler";
22
import {
33
diagnosticDeprecate,
44
diagnosticError,
5+
getEnd,
6+
getStart,
57
withLoc,
68
} from "@marko/babel-utils";
79

@@ -10,6 +12,7 @@ export default {
1012
diagnosticDeprecate(tag, {
1113
label: `The "<async-fragment>" tag is deprecated. Please use "<await>" instead. See: https://github.com/marko-js/marko/wiki/Deprecation:-async-fragment`,
1214
fix() {
15+
const { file } = tag.hub;
1316
const thenChildren: t.MarkoTagBody["body"] = [];
1417
const placeholderChildren: t.MarkoTagBody["body"] = [];
1518
const timeoutChildren: t.MarkoTagBody["body"] = [];
@@ -128,13 +131,10 @@ export default {
128131
}
129132

130133
const valueIdentifier = t.identifier(varExpression.value);
131-
if (varExpression.start != null && varExpression.end != null) {
132-
withLoc(
133-
tag.hub.file,
134-
valueIdentifier,
135-
varExpression.start + 1,
136-
varExpression.end - 1,
137-
);
134+
const varStart = getStart(file, varExpression);
135+
const varEnd = getEnd(file, varExpression);
136+
if (varStart != null && varEnd != null) {
137+
withLoc(file, valueIdentifier, varStart + 1, varEnd - 1);
138138
}
139139

140140
if (providerMethod) {

packages/marko-widgets/src/components/invoke/migrate.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { types as t } from "@marko/compiler";
2-
import { diagnosticError, parseExpression, withLoc } from "@marko/babel-utils";
2+
import {
3+
diagnosticError,
4+
getEnd,
5+
getStart,
6+
parseExpression,
7+
withLoc,
8+
} from "@marko/babel-utils";
39
import {
410
isSourceBooleanAttribute,
511
renderCallToDynamicTag,
@@ -36,7 +42,8 @@ export default {
3642
}
3743

3844
const { file } = tag.hub;
39-
const start = functionAttr.node.start;
45+
const start = getStart(file, functionAttr.node);
46+
const end = getEnd(file, functionAttr.node);
4047
const callIdentifier =
4148
start == null
4249
? parseExpression(file, functionAttr.node.name)
@@ -50,8 +57,8 @@ export default {
5057
callIdentifier,
5158
functionAttr.node.arguments!,
5259
);
53-
if (start != null) {
54-
withLoc(file, callExpression, start, functionAttr.node.end!);
60+
if (start != null && end !== null) {
61+
withLoc(file, callExpression, start, end);
5562
}
5663

5764
const dynamicTag = renderCallToDynamicTag(callExpression);

packages/marko-widgets/src/components/layout-placeholder/migrate.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ import { types as t } from "@marko/compiler";
22
import {
33
diagnosticDeprecate,
44
diagnosticError,
5+
getStart,
56
withLoc,
67
} from "@marko/babel-utils";
78
import { getAttributeValue } from "@marko/compat-utils";
89

910
export default {
1011
exit(tag: t.NodePath<t.MarkoTag>) {
11-
const { node } = tag;
12+
const {
13+
node,
14+
hub: { file },
15+
} = tag;
1216
const name = getAttributeValue(tag, "name");
1317

1418
if (!name || !name.isStringLiteral()) {
@@ -30,12 +34,13 @@ export default {
3034
}
3135

3236
const memberProperty = t.identifier(toCamelCase(name.node.value));
33-
if (node.name.start != null && node.name.end != null) {
37+
const nameStart = getStart(file, node.name);
38+
if (nameStart != null) {
3439
withLoc(
3540
tag.hub.file,
3641
memberProperty,
37-
node.name.start + 1,
38-
node.name.start + name.node.value.length,
42+
nameStart + 1,
43+
nameStart + name.node.value.length,
3944
);
4045
}
4146

packages/marko-widgets/src/components/layout-put/migrate.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ import { types as t } from "@marko/compiler";
22
import {
33
diagnosticDeprecate,
44
diagnosticError,
5+
getStart,
56
withLoc,
67
} from "@marko/babel-utils";
78
import { getAttributeValue } from "@marko/compat-utils";
89

910
export default {
1011
exit(tag: t.NodePath<t.MarkoTag>) {
11-
const { node } = tag;
12+
const {
13+
node,
14+
hub: { file },
15+
} = tag;
1216
const into = getAttributeValue(tag, "into");
1317

1418
if (!into || !into.isStringLiteral()) {
@@ -46,13 +50,9 @@ export default {
4650
}
4751

4852
const newName = t.stringLiteral(`@${toCamelCase(into.node.value)}`);
49-
if (node.name.start != null && node.name.end != null) {
50-
withLoc(
51-
tag.hub.file,
52-
newName,
53-
node.name.start,
54-
node.name.start + into.node.value.length,
55-
);
53+
const nameStart = getStart(file, node.name);
54+
if (nameStart != null) {
55+
withLoc(file, newName, nameStart, nameStart + into.node.value.length);
5656
}
5757

5858
diagnosticDeprecate(tag, {

0 commit comments

Comments
 (0)