Skip to content

Commit 8c40f42

Browse files
committed
Extract parser into new @marko/parse package
1 parent e02d004 commit 8c40f42

60 files changed

Lines changed: 938 additions & 637 deletions

File tree

Some content is hidden

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

.changeset/language-tools-parse.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@marko/language-tools": major
3+
---
4+
5+
The parser now lives in (and is re-exported from) the new `@marko/parse` package. Breaking changes for consumers of the parser API: `NodeType` values are now strings rather than numbers, `program.body` now includes comment and static statement nodes in document order (`Node.ChildNode` includes `Comment`, and `program.body` is typed as `Node.RootBodyNode[]`), `Comment` nodes carry a `commentType`, and `Static` nodes carry `target`/`name`. Additions: `parse` accepts an options argument with a `getTagType` hook, the parse result exposes `errors` and a flat `comments` list, and the full `htmljs-parser` surface is re-exported.

.changeset/parse-package.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@marko/parse": major
3+
---
4+
5+
New package: the Marko CST parser previously embedded in `@marko/language-tools`, extracted so it can be shared by other tooling. Node types are strings, syntax errors and comments are exposed on the parse result, comments and static statements are part of `program.body`, and a `getTagType` option allows overriding how tag bodies parse.

packages/language-server/src/__tests__/fixtures/script/attr-tags-dynamic-for-typed/__snapshots__/attr-tags-dynamic-for-typed.expected/index.ts

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,22 @@ export { type Component };
4848
Marko._.attrTagNames(__marko_internal_tag_2, (input) => {
4949
input["@menuitem"];
5050
});
51-
Marko._.renderTemplate(__marko_internal_tag_2)()()(
52-
// ^?
53-
{
54-
["menuitem"]: {
55-
[Marko._.contentFor(__marko_internal_tag_2)]: ({ foo }) => {
56-
Marko._.renderNativeTag("div")()()({
57-
[Marko._.content]: (() => {
58-
foo;
59-
return () => {
60-
return Marko._.voidReturn;
61-
};
62-
})(),
63-
});
64-
return Marko._.voidReturn;
65-
},
66-
[Symbol.iterator]: Marko._.any,
51+
Marko._.renderTemplate(__marko_internal_tag_2)()()({
52+
["menuitem"]: {
53+
[Marko._.contentFor(__marko_internal_tag_2)]: ({ foo }) => {
54+
Marko._.renderNativeTag("div")()()({
55+
[Marko._.content]: (() => {
56+
foo;
57+
return () => {
58+
return Marko._.voidReturn;
59+
};
60+
})(),
61+
});
62+
return Marko._.voidReturn;
6763
},
64+
[Symbol.iterator]: Marko._.any,
6865
},
69-
);
66+
});
7067
Marko._.noop({ component, state, out, input, $global, $signal });
7168
return;
7269
})();
@@ -107,4 +104,3 @@ export default new (class Template extends Marko._.Template<{
107104
Marko._.Relate<__marko_internal_input, Marko.Directives & Input>,
108105
) => Marko._.ReturnWithScope<__marko_internal_input, void>;
109106
}> {})();
110-
// ^?

0 commit comments

Comments
 (0)