Skip to content

chore: upgrade prettier to 3.1 #10134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 11, 2024
Merged
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
2 changes: 1 addition & 1 deletion documentation/examples/20-7guis/05-7guis-crud/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
? people.filter((person) => {
const name = `${person.last}, ${person.first}`;
return name.toLowerCase().startsWith(prefix.toLowerCase());
})
})
: people;

$: selected = filteredPeople[i];
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"build:sites": "pnpm -r --filter=./sites/* build",
"preview-site": "npm run build --prefix sites/svelte-5-preview",
"check": "cd packages/svelte && pnpm build && cd ../../ && pnpm -r check",
"format": "prettier --write --plugin prettier-plugin-svelte .",
"lint": "prettier --check --plugin prettier-plugin-svelte . && eslint ./",
"format": "prettier --write .",
"lint": "prettier --check . && eslint ./",
"test": "vitest run --coverage",
"test-output": "vitest run --reporter=json --outputFile=sites/svelte-5-preview/src/routes/status/results.json",
"changeset:version": "changeset version && pnpm -r generate:version && git add --all",
Expand All @@ -38,8 +38,8 @@
"eslint-plugin-lube": "^0.1.7",
"jsdom": "22.0.0",
"playwright": "^1.35.1",
"prettier": "^3.0.1",
"prettier-plugin-svelte": "^3.0.3",
"prettier": "^3.1.1",
"prettier-plugin-svelte": "^3.1.2",
"typescript": "^5.2.2",
"vitest": "^0.34.6"
}
Expand Down
6 changes: 3 additions & 3 deletions packages/svelte/src/compiler/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ const attributes = {
type === 'no-each'
? `An element that uses the animate directive must be the immediate child of a keyed each block`
: type === 'each-key'
? `An element that uses the animate directive must be used inside a keyed each block. Did you forget to add a key to your each block?`
: `An element that uses the animate directive must be the sole child of a keyed each block`,
? `An element that uses the animate directive must be used inside a keyed each block. Did you forget to add a key to your each block?`
: `An element that uses the animate directive must be the sole child of a keyed each block`,
'duplicate-animation': () => `An element can only have one 'animate' directive`,
/** @param {string[] | undefined} [modifiers] */
'invalid-event-modifier': (modifiers) =>
Expand All @@ -262,7 +262,7 @@ const attributes = {
? `An element can only have one '${directive1}' directive`
: `An element cannot have both ${describe(directive1)} directive and ${describe(
directive2
)} directive`;
)} directive`;
},
'invalid-let-directive-placement': () => 'let directive at invalid position'
};
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/src/compiler/legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export function convert(source, ast) {
// @ts-ignore
delete node.parent;
}
})
})
: undefined
};
},
Expand Down
16 changes: 8 additions & 8 deletions packages/svelte/src/compiler/phases/1-parse/state/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ export default function tag(parser) {
const type = meta_tags.has(name)
? meta_tags.get(name)
: regex_capital_letter.test(name[0]) || name === 'svelte:self' || name === 'svelte:component'
? 'Component'
: name === 'title' && parent_is_head(parser.stack)
? 'TitleElement'
: name === 'slot'
? 'SlotElement'
: 'RegularElement';
? 'Component'
: name === 'title' && parent_is_head(parser.stack)
? 'TitleElement'
: name === 'slot'
? 'SlotElement'
: 'RegularElement';

/** @type {import('#compiler').ElementLike} */
// @ts-expect-error TODO can't figure out this error
Expand All @@ -132,7 +132,7 @@ export default function tag(parser) {
can_delegate_events: null
},
parent: null
}
}
: {
type: /** @type {import('#compiler').ElementLike['type']} */ (type),
start,
Expand All @@ -141,7 +141,7 @@ export default function tag(parser) {
attributes: [],
fragment: create_fragment(true),
parent: null
};
};

parser.allow_whitespace();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export function combine_sourcemaps(filename, sourcemap_list) {
sourcemap_list,
() => null,
true // skip optional field `sourcesContent`
)
)
: remapping(
// use loader interface
sourcemap_list[0], // last map
Expand All @@ -291,7 +291,7 @@ export function combine_sourcemaps(filename, sourcemap_list) {
}
),
true
);
);

if (!map.file) delete map.file; // skip optional field `file`

Expand Down
12 changes: 6 additions & 6 deletions packages/svelte/src/compiler/phases/2-analyze/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -713,12 +713,12 @@ const runes_scope_tweaker = {
rune === '$state'
? 'state'
: rune === '$state.frozen'
? 'frozen_state'
: rune === '$derived'
? 'derived'
: path.is_rest
? 'rest_prop'
: 'prop';
? 'frozen_state'
: rune === '$derived'
? 'derived'
: path.is_rest
? 'rest_prop'
: 'prop';
}

if (rune === '$props') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export function client_component(source, analysis, options) {
b.call('$.validate_store', store_reference, b.literal(name.slice(1))),
store_get
])
)
)
: b.thunk(store_get)
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ export function get_assignment_value(node, { state, visit }) {
return operator === '='
? /** @type {import('estree').Expression} */ (visit(node.right))
: // turn something like x += 1 into x = x + 1
b.binary(
b.binary(
/** @type {import('estree').BinaryOperator} */ (operator.slice(0, -1)),
serialize_get_binding(node.left, state),
/** @type {import('estree').Expression} */ (visit(node.right))
);
);
} else if (
node.left.type === 'MemberExpression' &&
node.left.object.type === 'ThisExpression' &&
Expand All @@ -35,11 +35,11 @@ export function get_assignment_value(node, { state, visit }) {
return operator === '='
? /** @type {import('estree').Expression} */ (visit(node.right))
: // turn something like x += 1 into x = x + 1
b.binary(
b.binary(
/** @type {import('estree').BinaryOperator} */ (operator.slice(0, -1)),
/** @type {import('estree').Expression} */ (visit(node.left)),
/** @type {import('estree').Expression} */ (visit(node.right))
);
);
} else {
return /** @type {import('estree').Expression} */ (visit(node.right));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,11 @@ export const javascript_visitors_runes = {
field.kind === 'state'
? b.call('$.source', should_proxy_or_freeze(init) ? b.call('$.proxy', init) : init)
: field.kind === 'frozen_state'
? b.call('$.source', should_proxy_or_freeze(init) ? b.call('$.freeze', init) : init)
: b.call('$.derived', b.thunk(init));
? b.call(
'$.source',
should_proxy_or_freeze(init) ? b.call('$.freeze', init) : init
)
: b.call('$.derived', b.thunk(init));
} else {
// if no arguments, we know it's state as `$derived()` is a compile error
value = b.call('$.source');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,15 +655,15 @@ function serialize_element_special_value_attribute(element, node_id, attribute,
// This ensures things stay in sync with the select binding
// in case of updates to the option value or new values appearing
b.call('$.selected', node_id)
])
])
: needs_option_call
? b.sequence([
inner_assignment,
// This ensures a one-way street to the DOM in case it's <select {value}>
// and not <select bind:value>
b.call('$.select_option', node_id, value)
])
: inner_assignment
? b.sequence([
inner_assignment,
// This ensures a one-way street to the DOM in case it's <select {value}>
// and not <select bind:value>
b.call('$.select_option', node_id, value)
])
: inner_assignment
);

if (is_reactive) {
Expand Down Expand Up @@ -953,7 +953,7 @@ function serialize_inline_component(node, component_name, context) {
: b.call(
'$.spread_props',
...props_and_spreads.map((p) => (Array.isArray(p) ? b.object(p) : p))
);
);
/** @param {import('estree').Identifier} node_id */
let fn = (node_id) =>
b.call(
Expand Down Expand Up @@ -2340,7 +2340,7 @@ export const template_visitors = {
? b.arrow(
[b.id('$$anchor')],
/** @type {import('estree').BlockStatement} */ (context.visit(node.fallback))
)
)
: b.literal(null);
const key_function =
node.key && ((each_type & EACH_ITEM_REACTIVE) !== 0 || context.state.options.dev)
Expand All @@ -2351,7 +2351,7 @@ export const template_visitors = {
b.return(/** @type {import('estree').Expression} */ (context.visit(node.key)))
)
)
)
)
: b.literal(null);

if (node.index && each_node_meta.contains_group_binding) {
Expand Down Expand Up @@ -2413,7 +2413,7 @@ export const template_visitors = {
? b.arrow(
[b.id('$$anchor')],
/** @type {import('estree').BlockStatement} */ (context.visit(node.alternate))
)
)
: b.literal(null)
)
)
Expand All @@ -2432,29 +2432,29 @@ export const template_visitors = {
? b.arrow(
[b.id('$$anchor')],
/** @type {import('estree').BlockStatement} */ (context.visit(node.pending))
)
)
: b.literal(null),
node.then
? b.arrow(
node.value
? [
b.id('$$anchor'),
/** @type {import('estree').Pattern} */ (context.visit(node.value))
]
]
: [b.id('$$anchor')],
/** @type {import('estree').BlockStatement} */ (context.visit(node.then))
)
)
: b.literal(null),
node.catch
? b.arrow(
node.error
? [
b.id('$$anchor'),
/** @type {import('estree').Pattern} */ (context.visit(node.error))
]
]
: [b.id('$$anchor')],
/** @type {import('estree').BlockStatement} */ (context.visit(node.catch))
)
)
: b.literal(null)
)
)
Expand Down Expand Up @@ -2868,9 +2868,9 @@ export const template_visitors = {
/** @type {import('estree').Expression} */ (node.expression).type ===
'ObjectExpression'
? // @ts-expect-error types don't match, but it can't contain spread elements and the structure is otherwise fine
b.object_pattern(node.expression.properties)
b.object_pattern(node.expression.properties)
: // @ts-expect-error types don't match, but it can't contain spread elements and the structure is otherwise fine
b.array_pattern(node.expression.elements),
b.array_pattern(node.expression.elements),
b.member(b.id('$$slotProps'), b.id(node.name))
),
b.return(b.object(bindings.map((binding) => b.init(binding.node.name, binding.node))))
Expand Down Expand Up @@ -2963,7 +2963,7 @@ export const template_visitors = {
: b.arrow(
[b.id('$$anchor')],
b.block(create_block(node, 'fallback', node.fragment.nodes, context))
);
);

const expression = is_default
? b.member(b.id('$$props'), b.id('children'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,11 @@ function get_assignment_value(node, { state, visit }) {
return operator === '='
? /** @type {import('estree').Expression} */ (visit(node.right))
: // turn something like x += 1 into x = x + 1
b.binary(
b.binary(
/** @type {import('estree').BinaryOperator} */ (operator.slice(0, -1)),
serialize_get_binding(node.left, state),
/** @type {import('estree').Expression} */ (visit(node.right))
);
);
} else {
return /** @type {import('estree').Expression} */ (visit(node.right));
}
Expand Down Expand Up @@ -778,7 +778,7 @@ function serialize_element_spread_attributes(
b.id('join')
),
b.literal(' ')
)
)
: b.literal('');
args.push(
b.object([
Expand Down Expand Up @@ -931,7 +931,7 @@ function serialize_inline_component(node, component_name, context) {
: b.call(
'$.spread_props',
b.array(props_and_spreads.map((p) => (Array.isArray(p) ? b.object(p) : p)))
);
);

/** @type {import('estree').Statement} */
let statement = b.stmt(
Expand All @@ -940,7 +940,7 @@ function serialize_inline_component(node, component_name, context) {
? b.call(
'$.validate_component',
typeof component_name === 'string' ? b.id(component_name) : component_name
)
)
: component_name,
b.id('$$payload'),
props_expression
Expand Down Expand Up @@ -1032,7 +1032,7 @@ const javascript_visitors_legacy = {
'$.value_or_fallback',
prop,
/** @type {import('estree').Expression} */ (visit(declarator.init))
)
)
: prop;

declarations.push(b.declarator(declarator.id, init));
Expand Down Expand Up @@ -1177,7 +1177,7 @@ const template_visitors = {
template: [],
init: []
}
}
}
: { ...context, state };

const { hoisted, trimmed } = clean_nodes(
Expand Down Expand Up @@ -1501,9 +1501,9 @@ const template_visitors = {
b.let(
node.expression.type === 'ObjectExpression'
? // @ts-expect-error types don't match, but it can't contain spread elements and the structure is otherwise fine
b.object_pattern(node.expression.properties)
b.object_pattern(node.expression.properties)
: // @ts-expect-error types don't match, but it can't contain spread elements and the structure is otherwise fine
b.array_pattern(node.expression.elements),
b.array_pattern(node.expression.elements),
b.member(b.id('$$slotProps'), b.id(node.name))
),
b.return(b.object(bindings.map((binding) => b.init(binding.node.name, binding.node))))
Expand Down Expand Up @@ -1719,12 +1719,12 @@ function serialize_element_attributes(node, context) {
? b.call(
b.member(attribute.expression, b.id('includes')),
serialize_attribute_value(value_attribute.value, context)
)
)
: b.binary(
'===',
attribute.expression,
serialize_attribute_value(value_attribute.value, context)
),
),
metadata: {
contains_call_expression: false,
dynamic: false
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/src/compiler/phases/3-transform/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export function infer_namespace(namespace, parent, nodes, path) {
const parent_node =
parent.type === 'Fragment'
? // Messy: We know that Fragment calls create_block directly, so we can do this here
path.at(-1)
path.at(-1)
: parent;

if (
Expand Down
Loading