diff --git a/packages/svelte/src/compiler/index.js b/packages/svelte/src/compiler/index.js index eee35bf2a8..c2516a2e5f 100644 --- a/packages/svelte/src/compiler/index.js +++ b/packages/svelte/src/compiler/index.js @@ -8,6 +8,7 @@ import { remove_typescript_nodes } from './phases/1-parse/remove_typescript_node import { analyze_component, analyze_module } from './phases/2-analyze/index.js'; import { transform_component, transform_module } from './phases/3-transform/index.js'; import { validate_component_options, validate_module_options } from './validate-options.js'; +import { reset_warnings } from './warnings.js'; export { default as preprocess } from './preprocess/index.js'; /** @@ -20,6 +21,7 @@ export { default as preprocess } from './preprocess/index.js'; */ export function compile(source, options) { try { + const warnings = reset_warnings({ source, filename: options.filename }); const validated = validate_component_options(options, ''); let parsed = _parse(source); @@ -44,6 +46,7 @@ export function compile(source, options) { const analysis = analyze_component(parsed, source, combined_options); const result = transform_component(analysis, source, combined_options); + result.warnings = warnings; result.ast = to_public_ast(source, parsed, options.modernAst); return result; } catch (e) { @@ -65,9 +68,12 @@ export function compile(source, options) { */ export function compileModule(source, options) { try { + const warnings = reset_warnings({ source, filename: options.filename }); const validated = validate_module_options(options, ''); const analysis = analyze_module(parse_acorn(source, false), validated); - return transform_module(analysis, source, validated); + const result = transform_module(analysis, source, validated); + result.warnings = warnings; + return result; } catch (e) { if (e instanceof CompileError) { handle_compile_error(e, options.filename, source); diff --git a/packages/svelte/src/compiler/phases/2-analyze/a11y.js b/packages/svelte/src/compiler/phases/2-analyze/a11y.js index c31f20af40..17b4a94eba 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/a11y.js +++ b/packages/svelte/src/compiler/phases/2-analyze/a11y.js @@ -672,15 +672,6 @@ function check_element(node, state) { // foreign namespace means elements can have completely different meanings, therefore we don't check them if (state.options.namespace === 'foreign') return; - /** - * @template {keyof import('../../warnings-tmp.js').AllWarnings} T - * @param {{ start?: number, end?: number }} node - * @param {T} code - * @param {Parameters} args - * @returns {void} - */ - const push_warning = (node, code, ...args) => warn(state.analysis.warnings, node, code, ...args); - /** @type {Map} */ const attribute_map = new Map(); @@ -727,17 +718,17 @@ function check_element(node, state) { if (name.startsWith('aria-')) { if (invisible_elements.includes(node.name)) { // aria-unsupported-elements - push_warning(attribute, 'a11y-aria-attributes', node.name); + warn(attribute, 'a11y-aria-attributes', node.name); } const type = name.slice(5); if (!aria_attributes.includes(type)) { const match = fuzzymatch(type, aria_attributes); - push_warning(attribute, 'a11y-unknown-aria-attribute', type, match); + warn(attribute, 'a11y-unknown-aria-attribute', type, match); } if (name === 'aria-hidden' && regex_heading_tags.test(node.name)) { - push_warning(attribute, 'a11y-hidden', node.name); + warn(attribute, 'a11y-hidden', node.name); } // aria-proptypes @@ -747,7 +738,7 @@ function check_element(node, state) { if (value !== null && value !== undefined) { const schema = aria.get(/** @type {import('aria-query').ARIAProperty} */ (name)); if (schema !== undefined && !is_valid_aria_attribute_value(schema, value)) { - push_warning(attribute, 'a11y-incorrect-aria-attribute-type', schema, name); + warn(attribute, 'a11y-incorrect-aria-attribute-type', schema, name); } } @@ -758,7 +749,7 @@ function check_element(node, state) { !is_interactive_element(node.name, attribute_map) && !attribute_map.has('tabindex') ) { - push_warning(attribute, 'a11y-aria-activedescendant-has-tabindex'); + warn(attribute, 'a11y-aria-activedescendant-has-tabindex'); } } @@ -766,7 +757,7 @@ function check_element(node, state) { if (name === 'role') { if (invisible_elements.includes(node.name)) { // aria-unsupported-elements - push_warning(attribute, 'a11y-misplaced-role', node.name); + warn(attribute, 'a11y-misplaced-role', node.name); } const value = get_static_value(attribute); @@ -776,10 +767,10 @@ function check_element(node, state) { /** @type {import('aria-query').ARIARoleDefinitionKey} current_role */ (c_r); if (current_role && is_abstract_role(current_role)) { - push_warning(attribute, 'a11y-no-abstract-role', current_role); + warn(attribute, 'a11y-no-abstract-role', current_role); } else if (current_role && !aria_roles.includes(current_role)) { const match = fuzzymatch(current_role, aria_roles); - push_warning(attribute, 'a11y-unknown-role', current_role, match); + warn(attribute, 'a11y-unknown-role', current_role, match); } // no-redundant-roles @@ -788,7 +779,7 @@ function check_element(node, state) { //