Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/use-marko-parse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"prettier-plugin-marko": minor
---

Use the new shared `@marko/parse` package for parsing instead of a vendored syntax tree builder.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"test:update": "vitest run --update"
},
"dependencies": {
"htmljs-parser": "^5.12.1"
"@marko/parse": "link:../language-server/packages/parse"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/sh
set -eu

node <<'NODE'
const fs = require("node:fs");
const pkg = JSON.parse(fs.readFileSync("package.json", "utf8"));
const dependency = pkg.dependencies?.["`@marko/parse`"];

if (!dependency || dependency.startsWith("link:")) {
  throw new Error(
    `Expected a published `@marko/parse` version range, got ${dependency}`,
  );
}
NODE

Repository: marko-js/prettier

Length of output: 793


🏁 Script executed:

#!/bin/sh
set -eu

printf '%s\n' '--- package.json dependency and scripts ---'
node <<'NODE'
const fs = require("node:fs");
const pkg = JSON.parse(fs.readFileSync("package.json", "utf8"));
console.log(JSON.stringify({
  name: pkg.name,
  version: pkg.version,
  dependencies: pkg.dependencies,
  devDependencies: pkg.devDependencies,
  scripts: pkg.scripts,
  files: pkg.files
}, null, 2));
NODE

printf '%s\n' '--- repository references to `@marko/parse` and link: ---'
rg -n --glob '!node_modules' --glob '!dist' --glob '!build' '`@marko/parse`|link:../language-server/packages/parse|language-server/packages/parse' . || true

printf '%s\n' '--- workspace and package metadata files ---'
git ls-files | rg '(^|/)(package\.json|yarn\.lock|package-lock\.json|pnpm-lock\.yaml|\.yarnrc|\.npmrc)$' | head -200

Repository: marko-js/prettier

Length of output: 2416


🏁 Script executed:

#!/bin/sh
set -eu

printf '%s\n' '--- imported `@marko/parse` exports ---'
rg -n -C 2 'from ["'\'']`@marko/parse`["'\'']' src

printf '%s\n' '--- lockfile entry ---'
sed -n '1,35p' pnpm-lock.yaml

printf '%s\n' '--- published `@marko/parse` metadata ---'
python3 - <<'PY'
import json
import urllib.request

url = "https://registry.npmjs.org/@marko%2Fparse"
with urllib.request.urlopen(url, timeout=10) as response:
    data = json.load(response)

print("latest:", data.get("dist-tags", {}).get("latest"))
print("versions:", list(data.get("versions", {}))[-10:])
for version in list(data.get("versions", {}))[-3:]:
    package = data["versions"][version]
    print(version, {
        "exports": package.get("exports"),
        "types": package.get("types"),
        "main": package.get("main"),
        "module": package.get("module"),
    })
PY

Repository: marko-js/prettier

Length of output: 4459


Replace the temporary link before publishing.

Update package.json and pnpm-lock.yaml to use a semver range for a published @marko/parse release that provides the imports used by src/. Validate a clean install from the packed plugin.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@package.json` at line 46, Replace the temporary local link for `@marko/parse`
in package.json with the appropriate semver range for its published release, and
regenerate pnpm-lock.yaml accordingly. Confirm the selected release provides the
imports used by src/ and validate installation from the packed plugin.

},
"devDependencies": {
"@changesets/changelog-github": "^0.7.0",
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 17 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import {
CommentType,
type Node,
NodeType,
parse as parseMarko,
type Parsed,
type Range,
TagType,
} from "@marko/parse";
import {
type AstPath,
type Doc,
Expand All @@ -10,15 +19,6 @@ import {
type SupportOptions,
} from "prettier";

import {
CommentType,
type Node,
NodeType,
parse as parseMarko,
type Parsed,
type Range,
TagType,
} from "./parser";
import { getFormattedBody } from "./utils/get-formatted-body";
import {
getParserFromExt,
Expand Down Expand Up @@ -152,6 +152,11 @@ export const parsers: Record<string, Parser<AnyNode>> = {
parse(text, opts) {
const { program } = (opts._markoParsed = parseMarko(text, opts.filepath));

// Comments are printed as part of the body; prettier core registers
// anything on the root's `comments` and would throw in its
// ensureAllCommentsPrinted check since we print them ourselves.
program.comments = undefined;

if (opts.markoSyntax === "auto") {
opts.markoSyntax = "html";

Expand Down Expand Up @@ -303,12 +308,13 @@ const embedHandlers: EmbedHandlers = {

[NodeType.Static]: async (toDoc, _print, path, opts) => {
const { node } = path;
const target = node.target || "static";
const code = opts
._markoParsed!.code.slice(node.start + node.target.length + 1, node.end)
._markoParsed!.code.slice(node.start + target.length + 1, node.end)
.replace(/^\s*\{([\s\S]*)\}\s*$/, "$1")
.trim();
return code
? [`${node.target} `, toValidStatement(await toDoc(code, stmtParse))]
? [`${target} `, toValidStatement(await toDoc(code, stmtParse))]
: [];
},

Expand Down
Loading