Rich Harris 3 months ago
parent c474d679e9
commit e904753ecc

@ -171,7 +171,7 @@
"axobject-query": "^4.1.0",
"clsx": "^2.1.1",
"esm-env": "^1.2.1",
"esrap": "https://pkg.pr.new/sveltejs/esrap@ef4051a",
"esrap": "https://pkg.pr.new/sveltejs/esrap@17c22f5",
"is-reference": "^3.0.3",
"locate-character": "^3.0.0",
"magic-string": "^0.30.11",

@ -147,7 +147,6 @@ function run() {
const printed = esrap.print(
ast,
// @ts-expect-error
ts({
comments: comments.filter((comment) => comment !== jsdoc)
})
@ -358,7 +357,6 @@ function run() {
.join('\n')
};
// @ts-expect-error
const block = esrap.print({ ...ast, body: [clone] }, ts({ comments: [jsdoc_clone] })).code;
printed.code += `\n\n${block}`;

@ -107,6 +107,8 @@ function get_comment_handlers(source, comments, index = 0) {
* @param {string} value
* @param {number} start
* @param {number} end
* @param {import('acorn').Position} [start_loc]
* @param {import('acorn').Position} [end_loc]
*/
onComment: (block, value, start, end, start_loc, end_loc) => {
if (block && /\n/.test(value)) {
@ -125,7 +127,10 @@ function get_comment_handlers(source, comments, index = 0) {
value,
start,
end,
loc: { start: start_loc, end: end_loc }
loc: {
start: /** @type {import('acorn').Position} */ (start_loc),
end: /** @type {import('acorn').Position} */ (end_loc)
}
});
},

@ -10,7 +10,6 @@ import { is_void } from '../../utils.js';
export function print(ast) {
// @ts-expect-error some bullshit
return esrap.print(ast, {
// @ts-expect-error some bullshit
...ts({ comments: ast.type === 'Root' ? ast.comments : [] }),
...visitors
});
@ -641,13 +640,23 @@ const visitors = {
for (const modifier of node.modifiers) {
context.write(`|${modifier}`);
}
if (
node.expression !== null &&
!(node.expression.type === 'Identifier' && node.expression.name === node.name)
) {
context.write('={');
context.visit(node.expression);
context.write('}');
if (node.value === true) {
return;
}
context.write('=');
if (Array.isArray(node.value)) {
context.write('"');
for (const tag of node.value) {
context.visit(tag);
}
context.write('"');
} else {
context.visit(node.value);
}
},
@ -746,7 +755,7 @@ const visitors = {
context.write('<svelte:element');
context.write('this={');
context.visit(node.expression);
context.visit(node.tag);
context.write('} ');
for (const attribute of node.attributes) {

@ -73,7 +73,7 @@ export namespace AST {
/** The parsed `<script module>` element, if exists */
module: Script | null;
/** Comments found in <script> and {expressions} */
comments: import('estree').Comment[];
comments: Array<import('estree').Comment & { start: number; end: number }>;
/** @internal */
metadata: {
/** Whether the component was parsed with typescript */

@ -87,8 +87,8 @@ importers:
specifier: ^1.2.1
version: 1.2.1
esrap:
specifier: https://pkg.pr.new/sveltejs/esrap@ef4051a
version: https://pkg.pr.new/sveltejs/esrap@ef4051a
specifier: https://pkg.pr.new/sveltejs/esrap@17c22f5
version: https://pkg.pr.new/sveltejs/esrap@17c22f5
is-reference:
specifier: ^3.0.3
version: 3.0.3
@ -1261,8 +1261,8 @@ packages:
resolution: {integrity: sha512-YQLXUplAwJgCydQ78IMJywZCceoqk1oH01OERdSAJc/7U2AylwjhSCLDEtqwg811idIS/9fIU5GjG73IgjKMVg==}
engines: {node: '>=0.10'}
esrap@https://pkg.pr.new/sveltejs/esrap@ef4051a:
resolution: {tarball: https://pkg.pr.new/sveltejs/esrap@ef4051a}
esrap@https://pkg.pr.new/sveltejs/esrap@17c22f5:
resolution: {tarball: https://pkg.pr.new/sveltejs/esrap@17c22f5}
version: 1.4.9
esrecurse@4.3.0:
@ -3623,7 +3623,7 @@ snapshots:
dependencies:
estraverse: 5.3.0
esrap@https://pkg.pr.new/sveltejs/esrap@ef4051a:
esrap@https://pkg.pr.new/sveltejs/esrap@17c22f5:
dependencies:
'@jridgewell/sourcemap-codec': 1.5.0

Loading…
Cancel
Save