Rich Harris 3 months ago
parent c474d679e9
commit e904753ecc

@ -171,7 +171,7 @@
"axobject-query": "^4.1.0", "axobject-query": "^4.1.0",
"clsx": "^2.1.1", "clsx": "^2.1.1",
"esm-env": "^1.2.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", "is-reference": "^3.0.3",
"locate-character": "^3.0.0", "locate-character": "^3.0.0",
"magic-string": "^0.30.11", "magic-string": "^0.30.11",

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

@ -107,6 +107,8 @@ function get_comment_handlers(source, comments, index = 0) {
* @param {string} value * @param {string} value
* @param {number} start * @param {number} start
* @param {number} end * @param {number} end
* @param {import('acorn').Position} [start_loc]
* @param {import('acorn').Position} [end_loc]
*/ */
onComment: (block, value, start, end, start_loc, end_loc) => { onComment: (block, value, start, end, start_loc, end_loc) => {
if (block && /\n/.test(value)) { if (block && /\n/.test(value)) {
@ -125,7 +127,10 @@ function get_comment_handlers(source, comments, index = 0) {
value, value,
start, start,
end, 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) { export function print(ast) {
// @ts-expect-error some bullshit // @ts-expect-error some bullshit
return esrap.print(ast, { return esrap.print(ast, {
// @ts-expect-error some bullshit
...ts({ comments: ast.type === 'Root' ? ast.comments : [] }), ...ts({ comments: ast.type === 'Root' ? ast.comments : [] }),
...visitors ...visitors
}); });
@ -641,13 +640,23 @@ const visitors = {
for (const modifier of node.modifiers) { for (const modifier of node.modifiers) {
context.write(`|${modifier}`); context.write(`|${modifier}`);
} }
if (
node.expression !== null && if (node.value === true) {
!(node.expression.type === 'Identifier' && node.expression.name === node.name) return;
) { }
context.write('={');
context.visit(node.expression); context.write('=');
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('<svelte:element');
context.write('this={'); context.write('this={');
context.visit(node.expression); context.visit(node.tag);
context.write('} '); context.write('} ');
for (const attribute of node.attributes) { for (const attribute of node.attributes) {

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

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

Loading…
Cancel
Save