MCPcopy
hub / github.com/sveltejs/svelte / attributes

Function attributes

packages/svelte/src/compiler/print/index.js:68–131  ·  view source on GitHub ↗

* @param {AST.BaseNode} node * @param {AST.BaseElement['attributes']} attributes * @param {Context} context * @param {AST.JSComment[]} comments * @returns {boolean} true if attributes were formatted on multiple lines

(node, attributes, context, comments)

Source from the content-addressed store, hash-verified

66 * @returns {boolean} true if attributes were formatted on multiple lines
67 */
68function attributes(node, attributes, context, comments) {
69 if (attributes.length === 0) {
70 return false;
71 }
72
73 let length = -1;
74
75 let comment_index = comments.findIndex((comment) => comment.start > node.start);
76
77 if (comment_index === -1) {
78 comment_index = comments.length;
79 }
80
81 const separator = context.new();
82
83 const children = attributes.map((attribute) => {
84 const child_context = context.new();
85
86 while (comment_index < comments.length) {
87 const comment = comments[comment_index];
88
89 if (comment.start < attribute.start) {
90 if (comment.type === 'Line') {
91 child_context.write('//' + comment.value);
92 child_context.newline();
93 } else {
94 child_context.write('/*' + comment.value + '*/'); // TODO match indentation?
95 child_context.append(separator);
96 }
97
98 comment_index += 1;
99 } else {
100 break;
101 }
102 }
103
104 child_context.visit(attribute);
105
106 length += child_context.measure() + 1;
107
108 return child_context;
109 });
110
111 let multiline = context.multiline || length > LINE_BREAK_THRESHOLD;
112
113 if (multiline) {
114 separator.newline();
115 context.indent();
116 for (const child of children) {
117 context.newline();
118 context.append(child);
119 }
120 context.dedent();
121 context.newline();
122 } else {
123 separator.write(' ');
124 for (const child of children) {
125 context.write(' ');

Callers 5

base_elementFunction · 0.70
ScriptFunction · 0.70
StyleSheetFunction · 0.70
SvelteComponentFunction · 0.70
SvelteElementFunction · 0.70

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected